функции заменила на макросы

This commit is contained in:
KLASSENTS 2025-03-12 15:47:15 +07:00
parent d75ecbfd5d
commit d3b93e55bd

View File

@ -102,12 +102,18 @@ void digitalWrite(uint32_t PinNumber, uint32_t Val)
ErrorMsgHandler("digitalWrite(): pin number exceeds the total number of pins"); ErrorMsgHandler("digitalWrite(): pin number exceeds the total number of pins");
return; return;
} }
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef pin = digitalPinToBitMask(PinNumber);
if (digitalPinHasPWM(PinNumber)) if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM // if the pin can use PWM, disable PWM
analogWriteStop(PinNumber); analogWriteStop(PinNumber);
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW); if (Val == HIGH)
GPIO_SET_PIN(port, pin);
else
GPIO_CLEAR_PIN(port, pin);
} }
// read pin // read pin
@ -118,12 +124,14 @@ int digitalRead(uint32_t PinNumber)
ErrorMsgHandler("digitalRead(): pin number exceeds the total number of pins"); ErrorMsgHandler("digitalRead(): pin number exceeds the total number of pins");
return -1; return -1;
} }
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef pin = digitalPinToBitMask(PinNumber);
if (digitalPinHasPWM(PinNumber)) if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM // if the pin can use PWM, disable PWM
analogWriteStop(PinNumber); analogWriteStop(PinNumber);
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber)); return GPIO_READ_PIN(port, pin);
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
} }
// toggle pin // toggle pin