wiring digital speed optimization
Уменьшено время выполнения функций digitalRead/Write/Toggle для всех плат
This commit was merged in pull request #15.
This commit is contained in:
1 parent
0adc8293d7
commit
1aaf8c59ae
11 files changed
+146
-160
No files matched your search
@@ -36,6 +36,7 @@ extern "C" {
|
||||
*/
|
||||
typedef enum __HAL_PinsTypeDef
|
||||
{
|
||||
NOT_A_PIN = (0 << 0), /**< Не выбран пин. */
|
||||
GPIO_PIN_0 = (1 << 0), /**< Выбран пин 0. */
|
||||
GPIO_PIN_1 = (1 << 1), /**< Выбран пин 1. */
|
||||
GPIO_PIN_2 = (1 << 2), /**< Выбран пин 2. */
|
||||
|
||||
@@ -95,50 +95,54 @@ void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
}
|
||||
|
||||
// write pin
|
||||
void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
||||
__attribute__((noinline, section(".ram_text"))) void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalWrite(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
|
||||
if (Val == HIGH)
|
||||
GPIO_SET_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
else
|
||||
GPIO_CLEAR_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
// read pin
|
||||
int digitalRead(uint32_t PinNumber)
|
||||
__attribute__((noinline, section(".ram_text"))) int digitalRead(uint32_t PinNumber)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalRead(): pin number exceeds the total number of pins");
|
||||
return -1;
|
||||
}
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||
return GPIO_READ_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
// toggle pin
|
||||
void digitalToggle(uint32_t PinNumber)
|
||||
__attribute__((noinline, section(".ram_text"))) void digitalToggle(uint32_t PinNumber)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalToggle(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
|
||||
GPIO_TOGGLE_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in new issue
Block a user