mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
bootloaders: fix bootloader button logic
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
This commit is contained in:
parent
777857ae4c
commit
48b07eb991
@ -36,9 +36,19 @@
|
||||
|
||||
static bool _bootloader_alternative_mode(void)
|
||||
{
|
||||
#ifdef BTN_BOOTLOADER_PIN
|
||||
#if defined (BTN_BOOTLOADER_PIN) && defined (BTN_BOOTLOADER_MODE)
|
||||
bool state;
|
||||
|
||||
gpio_init(BTN_BOOTLOADER_PIN, BTN_BOOTLOADER_MODE);
|
||||
return (bool)gpio_read(BTN_BOOTLOADER_PIN) != BTN_BOOTLOADER_INVERTED;
|
||||
state = gpio_read(BTN_BOOTLOADER_PIN);
|
||||
/* If button configures w/ internal or external pullup, then it is an
|
||||
active-low, thus reverts the logic */
|
||||
if (BTN_BOOTLOADER_EXT_PULLUP || BTN_BOOTLOADER_MODE == GPIO_IN_PU ||
|
||||
BTN_BOOTLOADER_MODE == GPIO_OD_PU ) {
|
||||
return !state;
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -36,9 +36,19 @@
|
||||
|
||||
static bool _bootloader_alternative_mode(void)
|
||||
{
|
||||
#ifdef BTN_BOOTLOADER_PIN
|
||||
#if defined (BTN_BOOTLOADER_PIN) && defined (BTN_BOOTLOADER_MODE)
|
||||
bool state;
|
||||
|
||||
gpio_init(BTN_BOOTLOADER_PIN, BTN_BOOTLOADER_MODE);
|
||||
return (bool)gpio_read(BTN_BOOTLOADER_PIN) != BTN_BOOTLOADER_INVERTED;
|
||||
state = gpio_read(BTN_BOOTLOADER_PIN);
|
||||
/* If button configures w/ internal or external pullup, then it is an
|
||||
active-low, thus reverts the logic */
|
||||
if (BTN_BOOTLOADER_EXT_PULLUP || BTN_BOOTLOADER_MODE == GPIO_IN_PU ||
|
||||
BTN_BOOTLOADER_MODE == GPIO_OD_PU ) {
|
||||
return !state;
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -58,19 +58,12 @@ extern "C" {
|
||||
|
||||
/** @brief Interpretation of @ref BTN_BOOTLOADER_PIN.
|
||||
*
|
||||
* Set to true for active-low buttons (go to DFU if the pin is low), otherwise
|
||||
* to false (go to DFU if the pin is high).
|
||||
*
|
||||
* The default value for all boards is inverted (active-low), except if
|
||||
* BTN0_MODE is defined as GPIO_IN_PD. In this case the value is not
|
||||
* inverted (high-active).
|
||||
* This value should be set to true if the button has an *external* pull-up and
|
||||
* thus, works as an active-low button.
|
||||
* If the button has an internal pull-up, the default value should remains false
|
||||
*/
|
||||
#ifndef BTN_BOOTLOADER_INVERTED
|
||||
#if (BTN0_MODE == GPIO_IN_PD)
|
||||
#define BTN_BOOTLOADER_INVERTED false
|
||||
#else
|
||||
#define BTN_BOOTLOADER_INVERTED true
|
||||
#endif
|
||||
#ifndef BTN_BOOTLOADER_EXT_PULLUP
|
||||
#define BTN_BOOTLOADER_EXT_PULLUP false
|
||||
#endif
|
||||
|
||||
/** @brief LED pin for bootloader indication
|
||||
|
@ -57,8 +57,11 @@ static inline void uart_write_byte(uart_t uart, uint8_t data)
|
||||
|
||||
static inline bool _boot_pin(void)
|
||||
{
|
||||
#ifdef BTN_BOOTLOADER_PIN
|
||||
if (BTN_BOOTLOADER_INVERTED) {
|
||||
#if defined (BTN_BOOTLOADER_PIN) && defined(BTN_BOOTLOADER_MODE)
|
||||
/* Reverts the logic if the button has an internal or external pullup and
|
||||
thus, is an active-low button */
|
||||
if (BTN_BOOTLOADER_EXT_PULLUP || BTN_BOOTLOADER_MODE == GPIO_IN_PU ||
|
||||
BTN_BOOTLOADER_MODE == GPIO_OD_PU ) {
|
||||
return !gpio_read(BTN_BOOTLOADER_PIN);
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user