global: simplify board support

This commit is contained in:
King Kévin 2017-11-24 11:29:10 +01:00
parent d171e06337
commit c611911637
3 changed files with 26 additions and 18 deletions

View File

@ -51,12 +51,13 @@ void main(void)
rcc_periph_clock_enable(RCC_GPIO(DFU_FORCE_PORT)); // enable clock for GPIO domain
gpio_set_mode(GPIO(DFU_FORCE_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(DFU_FORCE_PIN)); // set GPIO to input
// pull on the opposite of the expected value
if (DFU_FORCE_VALUE) {
gpio_clear(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN)); // pull down to be able to detect when tied to high
} else {
gpio_set(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN)); // pull up to be able to detect when tied to low
}
if ((!DFU_FORCE_VALUE && 0==gpio_get(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN))) || (DFU_FORCE_VALUE && 0!=gpio_get(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN)))) { // check if output is set to the value to force DFU mode
#if (DFU_FORCE_VALUE==1)
gpio_clear(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN)); // pull down to be able to detect when tied to high
if (gpio_get(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN))) { // check if output is set to the value to force DFU mode
#else
gpio_set(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN)); // pull up to be able to detect when tied to low
if (0==gpio_get(GPIO(DFU_FORCE_PORT), GPIO(DFU_FORCE_PIN))) { // check if output is set to the value to force DFU mode
#endif
dfu_force = true; // DFU mode forced
}
}

View File

@ -61,21 +61,23 @@ char* b2s(uint64_t binary, uint8_t rjust)
/** switch on board LED */
void led_on(void)
{
#if defined(SYSTEM_BOARD) || defined(BLUE_PILL) || defined(CORE_BOARD)
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
#elif defined(MAPLE_MINI)
#if defined(LED_ON) && LED_ON
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
#else
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
#endif
}
/** switch off board LED */
void led_off(void)
{
#if defined(SYSTEM_BOARD) || defined(BLUE_PILL) || defined(CORE_BOARD)
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
#elif defined(MAPLE_MINI)
#if defined(LED_ON) && LED_ON
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
#else
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
#endif
}
/** toggle board LED */
void led_toggle(void)
{
@ -133,10 +135,10 @@ void board_setup(void)
gpio_set_mode(GPIO(BUTTON_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUTTON_PIN)); // set button pin to input
rcc_periph_clock_enable(RCC_AFIO); // enable alternate function clock for external interrupt
exti_select_source(EXTI(BUTTON_PIN), GPIO(BUTTON_PORT)); // mask external interrupt of this pin only for this port
#if defined(MAPLE_MINI)
#if defined(BUTTON_PRESSED) && BUTTON_PRESSED
gpio_clear(GPIO(BUTTON_PORT), GPIO(BUTTON_PIN)); // pull down to be able to detect button push (go high)
exti_set_trigger(EXTI(BUTTON_PIN), EXTI_TRIGGER_RISING); // trigger when button is pressed
#elif defined(CORE_BOARD)
#else
gpio_set(GPIO(BUTTON_PORT), GPIO(BUTTON_PIN)); // pull up to be able to detect button push (go low)
exti_set_trigger(EXTI(BUTTON_PIN), EXTI_TRIGGER_FALLING); // trigger when button is pressed
#endif

View File

@ -309,14 +309,17 @@
/* on system and core board LED is on pin 11/PA1 */
#define LED_PORT A /**< GPIO port (port A) */
#define LED_PIN 1 /**< GPIO pin (pin PA1) */
#define LED_ON 0 /**< LED is on when pin is low */
#elif defined(BLUE_PILL)
/* on minimum system LED is on pin 2/PC13 */
#define LED_PORT C /**< GPIO port (port C on blue pill) */
#define LED_PIN 13 /**< GPIO pin (pin PC13 on system board) */
#define LED_ON 0 /**< LED is on when pin is low */
#elif defined (MAPLE_MINI)
/* on maple mini LED is on pin 19/PB1 */
#define LED_PORT B /**< GPIO port (port B on maple mini) */
#define LED_PIN 1 /**< GPIO pin (pin PB1 on maple mini) */
#define LED_ON 1 /**< LED is on when pin is high */
#endif
/** @} */
@ -327,10 +330,12 @@
/* on maple mini user button is on 32/PB8 */
#define BUTTON_PORT B /**< GPIO port (port B on maple mini) */
#define BUTTON_PIN 8 /**< GPIO pin (pin PB8 on maple mini) */
#define BUTTON_PRESSED 1 /**< pin is high when button is pressed */
#elif defined(CORE_BOARD)
/* on core board user button is on PA8 */
#define BUTTON_PORT A /**< GPIO port (port A) */
#define BUTTON_PIN 8 /**< GPIO pin (pin PA8) */
#define BUTTON_PRESSED 0 /**< pin is low when button is pressed */
#endif
/** @} */
@ -341,17 +346,17 @@
/* use button */
#define DFU_FORCE_PORT BUTTON_PORT /**< button port */
#define DFU_FORCE_PIN BUTTON_PIN /**< button pin */
#define DFU_FORCE_VALUE true /**< button is pulled low unpressed, high pressed to force DFU mode */
#define DFU_FORCE_VALUE 1 /**< button is pulled low unpressed, high pressed to force DFU mode */
#elif defined(CORE_BOARD)
/* use button */
#define DFU_FORCE_PORT BUTTON_PORT /**< button port */
#define DFU_FORCE_PIN BUTTON_PIN /**< button pin */
#define DFU_FORCE_VALUE false /**< button floating unpressed, connected to ground pressed to force DFU mode */
#define DFU_FORCE_VALUE 0 /**< button floating unpressed, connected to ground pressed to force DFU mode */
#else
/* use the JNTRST pin as JPIO (this will disable the SWJ function, but we are not using it) */
/* use the JNTRST pin as GPIO (this will disable the SWJ function, but we are not using it) */
#define DFU_FORCE_PORT B /**< JNTRST port (needs to be remapped to become PB4) */
#define DFU_FORCE_PIN 4 /**< JNTRST pin (needs to be remapped to become PB4) */
#define DFU_FORCE_VALUE false /**< must be high to force DFU mode, since it's low after reset */
#define DFU_FORCE_VALUE 1 /**< must be high to force DFU mode, since it's low after reset */
#endif
/** @} */