From f18e967dc4d1674a79699b46b534f4297ac283d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 29 Dec 2015 11:29:42 +0100 Subject: [PATCH] blink.c --- Makefile | 1 + blink.c | 22 ++++++++++++++++++++++ blink.h | 12 ++++++++++++ main.c | 20 +++----------------- proj.pro | 6 ++++-- utils/timebase.c | 4 ++-- 6 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 blink.c create mode 100644 blink.h diff --git a/Makefile b/Makefile index e4ef6dd..58ea054 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ OBJS += utils/usart.o OBJS += utils/timebase.o OBJS += utils/debounce.o OBJS += init.o +OBJS += blink.o ################################################################ diff --git a/blink.c b/blink.c new file mode 100644 index 0000000..2aa5b20 --- /dev/null +++ b/blink.c @@ -0,0 +1,22 @@ +#include "blink.h" + +#include "utils/timebase.h" + +void green_toggle(void) { GPIOC_ODR ^= BIT9; } +void green_off(void) { GPIOC_ODR &= ~BIT9; } +void green_on(void) { GPIOC_ODR |= BIT9; } +void blue_toggle(void) { GPIOC_ODR ^= BIT8; } +void blue_on(void) { GPIOC_ODR |= BIT8; } +void blue_off(void) { GPIOC_ODR &= ~BIT8; } + +void blink_green(void) +{ + green_on(); + schedule_task(green_off, 250); +} + +void blink_blue(void) +{ + blue_on(); + schedule_task(blue_off, 250); +} diff --git a/blink.h b/blink.h new file mode 100644 index 0000000..6083c28 --- /dev/null +++ b/blink.h @@ -0,0 +1,12 @@ +#pragma once + +void green_toggle(void); +void green_on(void); +void green_off(void); + +void blue_toggle(void); +void blue_on(void); +void blue_off(void); + +void blink_green(void); +void blink_blue(void); diff --git a/main.c b/main.c index 2f4ed29..728051e 100644 --- a/main.c +++ b/main.c @@ -5,19 +5,8 @@ #include "utils/debounce.h" #include "init.h" +#include "blink.h" -void blink_green(void) -{ - GPIOC_ODR ^= BIT9; -} - -void blink_blue(void) -{ - GPIOC_ODR ^= BIT8; -} - -void blue_on(void) { GPIOC_ODR |= BIT8; } -void blue_off(void) { GPIOC_ODR &= ~BIT8; } // called every 1s @@ -35,11 +24,8 @@ void SystemInit(void) init_gpios(); init_usart(); - register_periodic_task(blink_green, 1000); - //register_periodic_task(blink_blue, 1000); - register_periodic_task(say_hello, 1000); - - register_debounced_pin(GPIOA, 0, blue_on, blue_off); + register_periodic_task(green_toggle, 1000); + register_periodic_task(blink_blue, 5000); } diff --git a/proj.pro b/proj.pro index 602fbb2..8822b7c 100644 --- a/proj.pro +++ b/proj.pro @@ -27,7 +27,8 @@ SOURCES += \ utils/gpio.c \ utils/timebase.c \ utils/usart.c \ - utils/debounce.c + utils/debounce.c \ + blink.c HEADERS += \ lib/common.h \ @@ -45,5 +46,6 @@ HEADERS += \ utils/gpio.h \ utils/timebase.h \ utils/usart.h \ - utils/debounce.h + utils/debounce.h \ + blink.h diff --git a/utils/timebase.c b/utils/timebase.c index 3f30d05..430e214 100644 --- a/utils/timebase.c +++ b/utils/timebase.c @@ -5,7 +5,7 @@ volatile uint32_t TIME_MS; // --- time scheduler --- -#define PERIODIC_TASK_COUNT 5 +#define PERIODIC_TASK_COUNT 10 typedef struct { /** User callback */ @@ -22,7 +22,7 @@ static periodic_task_t periodic_tasks[PERIODIC_TASK_COUNT]; // --- future calls --- -#define FUTURE_TASK_COUNT 5 +#define FUTURE_TASK_COUNT 10 typedef struct { /** 1 for active tasks */ bool active;