/* * My first project * * It blinks LEDs like counting in binary, when the button is pressed, it reverses the order * * Build on top of libopenocm3, blackbox parts of code (setup()) copied from * libopencm3-examples/examples/stm32/f1/stm32vl-discovery/button project * * Open source licence, let's say Artistic Licence, although it doesn't matter, as it is local only */ #include #include #include //#define DELAY 8000000 // Should be a second, or maybe not (second iff 8MHz clk, 1/3second if 24MHz clk) // Too long!! #define DELAY 400000 // This is bad -- it's a value that was found to be OK #define STM32F1 1 // Needed for libopencm3 void setup (void) { // All the blackbox code // Set up clock rcc_clock_setup_in_hse_8mhz_out_24mhz(); // Enable the two GPIOs rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_GPIOA); // GPIO C8 amd C9 are the two LEDs gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8 | GPIO9); // GPIO A0 is the push button gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0); } void initial_wait (void) { gpio_clear(GPIOC, GPIO8 | GPIO9); while (gpio_get(GPIOA, GPIO0) == 0); return; } int main (void) { setup(); initial_wait(); // Array of what leds should be on uint16_t states[4] = {0, GPIO9, GPIO8, GPIO9 | GPIO8}; enum {FORWARD, BACKWARD} direction = FORWARD; bool pressed = true; bool change = false; char state = 0; int i; while (true) { change = false; for (i=0 ; i