|
|
|
@ -15,23 +15,26 @@ |
|
|
|
|
/** global definitions and methods (code)
|
|
|
|
|
* @file global.c |
|
|
|
|
* @author King Kévin <kingkevin@cuvoodoo.info> |
|
|
|
|
* @date 2016 |
|
|
|
|
* @date 2016-2017 |
|
|
|
|
*/ |
|
|
|
|
/* standard libraries */ |
|
|
|
|
#include <stdint.h> // standard integer types |
|
|
|
|
#include <stdlib.h> // general utilities |
|
|
|
|
|
|
|
|
|
/* STM32 (including CM3) libraries */ |
|
|
|
|
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities |
|
|
|
|
#include <libopencm3/cm3/nvic.h> // interrupt handler |
|
|
|
|
#include <libopencm3/cm3/systick.h> // SysTick library |
|
|
|
|
#include <libopencm3/stm32/rcc.h> // real-time control clock library |
|
|
|
|
#include <libopencm3/stm32/gpio.h> // general purpose input output library |
|
|
|
|
#include <libopencm3/stm32/timer.h> // timer library |
|
|
|
|
#include <libopencm3/cm3/nvic.h> // interrupt handler |
|
|
|
|
#include <libopencm3/stm32/exti.h> // external interrupt defines |
|
|
|
|
|
|
|
|
|
#include "global.h" // common methods |
|
|
|
|
#include "string.h" // memory utilities |
|
|
|
|
|
|
|
|
|
volatile bool button_flag = false; |
|
|
|
|
volatile uint32_t sleep_duration = 0; /**< sleep duration count down (in SysTick interrupts) */ |
|
|
|
|
|
|
|
|
|
char* b2s(uint64_t binary, uint8_t rjust) |
|
|
|
|
{ |
|
|
|
@ -79,6 +82,44 @@ void led_toggle(void) |
|
|
|
|
gpio_toggle(GPIO(LED_PORT), GPIO(LED_PIN)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void sleep_us(uint32_t duration) |
|
|
|
|
{ |
|
|
|
|
systick_counter_disable(); // disable SysTick to reconfigure it
|
|
|
|
|
systick_clear(); // reset SysTick
|
|
|
|
|
systick_set_frequency(1000000,rcc_ahb_frequency); // set SysTick frequency to microseconds
|
|
|
|
|
systick_interrupt_enable(); // enable interrupt to count duration
|
|
|
|
|
sleep_duration = duration; // save sleep duration for count down
|
|
|
|
|
systick_counter_enable(); // start counting
|
|
|
|
|
while (sleep_duration) { // wait for count down to complete
|
|
|
|
|
__WFI(); // go to sleep
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void sleep_ms(uint32_t duration) |
|
|
|
|
{ |
|
|
|
|
systick_counter_disable(); // disable SysTick to reconfigure it
|
|
|
|
|
systick_clear(); // reset SysTick
|
|
|
|
|
systick_set_frequency(1000,rcc_ahb_frequency); // set SysTick frequency to milliseconds
|
|
|
|
|
systick_interrupt_enable(); // enable interrupt to count duration
|
|
|
|
|
sleep_duration = duration; // save sleep duration for count down
|
|
|
|
|
systick_counter_enable(); // start counting
|
|
|
|
|
while (sleep_duration) { // wait for count down to complete
|
|
|
|
|
__WFI(); // go to sleep
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** SysTick interrupt handler */ |
|
|
|
|
void sys_tick_handler(void) |
|
|
|
|
{ |
|
|
|
|
if (sleep_duration) { |
|
|
|
|
sleep_duration--; // decrement duration
|
|
|
|
|
} |
|
|
|
|
if (0==sleep_duration) { // sleep complete
|
|
|
|
|
systick_counter_disable(); // stop systick
|
|
|
|
|
systick_interrupt_disable(); // stop interrupting
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void board_setup(void) |
|
|
|
|
{ |
|
|
|
|
// setup LED
|
|
|
|
|