убрала проверку пинов на кнопку - теперь можно и писать, и тугглить и на выход настраивать пин кнопки - все на совести пользователя
This commit is contained in:
parent
72348bba6d
commit
76e235a23b
@ -40,42 +40,30 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
|
|||||||
// if the pin can use PWM, disable PWM
|
// if the pin can use PWM, disable PWM
|
||||||
analogWriteStop(PinNumber);
|
analogWriteStop(PinNumber);
|
||||||
|
|
||||||
// adjusting pins
|
// determine the port and the pin number in the port
|
||||||
if (PinNumber == BTN_BUILTIN)
|
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
|
||||||
{
|
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
|
||||||
// always set the button to input, otherwise the controller may burn out when pressed
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
|
||||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
|
||||||
HAL_GPIO_Init(GPIO_2, &GPIO_InitStruct);
|
|
||||||
}
|
|
||||||
else // other pins
|
|
||||||
{
|
|
||||||
// determine the port and the pin number in the port
|
|
||||||
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
|
|
||||||
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
|
|
||||||
|
|
||||||
// set up direction and pull up/down
|
// set up direction and pull up/down
|
||||||
switch (PinMode)
|
switch (PinMode)
|
||||||
{
|
{
|
||||||
case INPUT:
|
case INPUT:
|
||||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||||
break;
|
break;
|
||||||
case INPUT_PULLUP:
|
case INPUT_PULLUP:
|
||||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
|
||||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
|
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
|
||||||
break;
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
|
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
|
||||||
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// init pin
|
|
||||||
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
|
|
||||||
additionalPinsInit(PinNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init pin
|
||||||
|
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
|
||||||
|
additionalPinsInit(PinNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write pin
|
// write pin
|
||||||
@ -91,11 +79,7 @@ void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
|||||||
// if the pin can use PWM, disable PWM
|
// if the pin can use PWM, disable PWM
|
||||||
analogWriteStop(PinNumber);
|
analogWriteStop(PinNumber);
|
||||||
|
|
||||||
// just in case let's move on to the hal library state terms
|
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
|
||||||
GPIO_PinState pinState = (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
|
|
||||||
|
|
||||||
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
|
|
||||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), pinState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read pin
|
// read pin
|
||||||
@ -111,8 +95,7 @@ int digitalRead(uint32_t PinNumber)
|
|||||||
analogWriteStop(PinNumber);
|
analogWriteStop(PinNumber);
|
||||||
|
|
||||||
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||||
int state = (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// toggle pin
|
// toggle pin
|
||||||
@ -127,8 +110,7 @@ void digitalToggle(uint32_t PinNumber)
|
|||||||
// if the pin can use PWM, disable PWM
|
// if the pin can use PWM, disable PWM
|
||||||
analogWriteStop(PinNumber);
|
analogWriteStop(PinNumber);
|
||||||
|
|
||||||
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
|
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user