26 #include <libopencmsis/core_cm3.h> 27 #include <libopencm3/cm3/nvic.h> 28 #include <libopencm3/cm3/systick.h> 29 #include <libopencm3/stm32/rcc.h> 30 #include <libopencm3/stm32/gpio.h> 31 #include <libopencm3/stm32/exti.h> 44 char*
b2s(uint64_t binary, uint8_t rjust)
46 static char string[64+1] = {0};
47 uint8_t bit =
LENGTH(
string)-1;
59 while (64-bit-1<rjust && bit>0) {
69 #if defined(BUSVOODOO) 70 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO(LED_PIN));
72 #if defined(LED_ON) && LED_ON 73 gpio_set(
GPIO(LED_PORT),
GPIO(LED_PIN));
75 gpio_clear(
GPIO(LED_PORT),
GPIO(LED_PIN));
82 #if defined(BUSVOODOO) 83 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(LED_PIN));
85 #if defined(LED_ON) && LED_ON 86 gpio_clear(
GPIO(LED_PORT),
GPIO(LED_PIN));
88 gpio_set(
GPIO(LED_PORT),
GPIO(LED_PIN));
96 #if defined(BUSVOODOO) 97 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO(LED_PIN));
99 gpio_toggle(
GPIO(LED_PORT),
GPIO(LED_PIN));
104 systick_counter_disable();
105 if (!systick_set_frequency(1000000,rcc_ahb_frequency)) {
109 systick_interrupt_enable();
111 systick_counter_enable();
119 systick_counter_disable();
120 if (!systick_set_frequency(1000,rcc_ahb_frequency)) {
124 systick_interrupt_enable();
126 systick_counter_enable();
139 systick_counter_disable();
140 systick_interrupt_disable();
172 rcc_periph_clock_enable(
RCC_GPIO(LED_PORT));
173 #if defined(BUSVOODOO) 174 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(LED_PIN));
176 gpio_set_mode(
GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO(LED_PIN));
181 #if defined(BUTTON_PORT) && defined(BUTTON_PIN) 182 rcc_periph_clock_enable(
RCC_GPIO(BUTTON_PORT));
183 gpio_set_mode(
GPIO(BUTTON_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN,
GPIO(BUTTON_PIN));
184 rcc_periph_clock_enable(RCC_AFIO);
185 exti_select_source(
EXTI(BUTTON_PIN),
GPIO(BUTTON_PORT));
186 #if defined(BUTTON_PRESSED) && BUTTON_PRESSED 187 gpio_clear(
GPIO(BUTTON_PORT),
GPIO(BUTTON_PIN));
188 exti_set_trigger(
EXTI(BUTTON_PIN), EXTI_TRIGGER_RISING);
190 gpio_set(
GPIO(BUTTON_PORT),
GPIO(BUTTON_PIN));
191 exti_set_trigger(
EXTI(BUTTON_PIN), EXTI_TRIGGER_FALLING);
193 exti_enable_request(
EXTI(BUTTON_PIN));
203 #if defined(BUTTON_PIN) 207 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
void user_input_store(char c)
store user input
#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
static volatile uint8_t user_input_buffer[64]
ring buffer for received data
void sleep_us(uint32_t duration)
go to sleep for some microseconds
void sys_tick_handler(void)
SysTick interrupt handler.
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
char user_input_get(void)
get user input
#define EXTI_ISR(x)
get interrupt service routine for timer base on external interrupt/pin
static volatile uint8_t user_input_i
current position of read received data
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
#define LENGTH(x)
get the length of an array
void led_toggle(void)
toggle board LED
static volatile uint32_t sleep_duration
sleep duration count down (in SysTick interrupts)
volatile bool user_input_available
flag set when user input is available
void led_on(void)
switch on board LED
static volatile uint8_t user_input_used
how much data has been received and not red