25 #include <libopencm3/stm32/rcc.h> 26 #include <libopencm3/stm32/gpio.h> 27 #include <libopencm3/stm32/timer.h> 28 #include <libopencm3/cm3/nvic.h> 29 #include <libopencm3/stm32/exti.h> 36 char*
b2s(uint64_t binary, uint8_t rjust)
38 static char string[64+1] = {0};
39 uint8_t bit =
LENGTH(
string)-1;
51 while (64-bit-1<rjust && bit>0) {
61 #if defined(SYSTEM_BOARD) || defined(BLUE_PILL) || defined(CORE_BOARD) 62 gpio_clear(
GPIO(LED_PORT),
GPIO(LED_PIN));
63 #elif defined(MAPLE_MINI) 64 gpio_set(
GPIO(LED_PORT),
GPIO(LED_PIN));
70 #if defined(SYSTEM_BOARD) || defined(BLUE_PILL) || defined(CORE_BOARD) 71 gpio_set(
GPIO(LED_PORT),
GPIO(LED_PIN));
72 #elif defined(MAPLE_MINI) 73 gpio_clear(
GPIO(LED_PORT),
GPIO(LED_PIN));
79 gpio_toggle(
GPIO(LED_PORT),
GPIO(LED_PIN));
85 rcc_periph_clock_enable(
RCC_GPIO(LED_PORT));
86 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO(LED_PIN));
90 #if defined(BUTTON_PORT) && defined(BUTTON_PIN) 91 rcc_periph_clock_enable(
RCC_GPIO(BUTTON_PORT));
92 gpio_set_mode(
GPIO(BUTTON_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN,
GPIO(BUTTON_PIN));
93 rcc_periph_clock_enable(RCC_AFIO);
94 exti_select_source(
EXTI(BUTTON_PIN),
GPIO(BUTTON_PORT));
95 #if defined(MAPLE_MINI) 96 gpio_clear(
GPIO(BUTTON_PORT),
GPIO(BUTTON_PIN));
97 exti_set_trigger(
EXTI(BUTTON_PIN), EXTI_TRIGGER_RISING);
98 #elif defined(CORE_BOARD) 99 gpio_set(
GPIO(BUTTON_PORT),
GPIO(BUTTON_PIN));
100 exti_set_trigger(
EXTI(BUTTON_PIN), EXTI_TRIGGER_FALLING);
102 exti_enable_request(
EXTI(BUTTON_PIN));
107 #if defined(BUTTON_PIN) 111 exti_reset_request(
EXTI(BUTTON_PIN));
void board_setup(void)
setup board peripherals
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
void led_off(void)
switch off board LED
#define NVIC_EXTI_IRQ(x)
get NVIC IRQ for external interrupt base on external interrupt/pin
global definitions and methods (API)
#define GPIO(x)
get GPIO based on GPIO identifier
char * b2s(uint64_t binary, uint8_t rjust)
get binary representation of a number
#define EXTI(x)
get external interrupt based on pin identifier
volatile bool button_flag
flag set when board user button has been pressed/released
#define EXTI_ISR(x)
get interrupt service routine for timer base on external interrupt/pin
#define LENGTH(x)
get the length of an array
void led_toggle(void)
toggle board LED
void led_on(void)
switch on board LED