From d6166170b007510b7adf553f018b0a8b3559505b Mon Sep 17 00:00:00 2001 From: Mateusz Lubecki Date: Mon, 13 Jul 2020 00:13:39 +0200 Subject: [PATCH] led blinking code unified --- include/LedConfig.h | 64 +++++++++++++++++++++++++- include/main.h | 4 +- src/LedConfig.c | 32 +++++++++++++ src/it_handlers.c | 25 +++++----- system/src/drivers/analog_anemometer.c | 12 +++++ system/src/drivers/tx20.c | 34 ++++---------- 6 files changed, 131 insertions(+), 40 deletions(-) diff --git a/include/LedConfig.h b/include/LedConfig.h index 38b7c32..6b08900 100644 --- a/include/LedConfig.h +++ b/include/LedConfig.h @@ -8,13 +8,75 @@ #ifndef LEDCONFIG_H_ #define LEDCONFIG_H_ +// PC8 - LED1 - upper +// PC9 - LED2 - lower + +#include +#include +#include + +#define BLINK_DURATION_MSEC 20 * BLINK_MSEC_PER_SVC_CALL +#define BLINK_MSEC_PER_SVC_CALL 10 /* C++ detection */ #ifdef __cplusplus extern "C" { #endif -void LedConfig(void); +extern uint8_t led_blinking_led2; +extern uint8_t led_blinking_led1; + +void led_config(void); +void led_service_blink(void); + +inline void led_control_led1_upper(bool _in) { + if (_in == true) { + GPIOC->BSRR |= GPIO_BSRR_BS8; + } + else { + GPIOC->BSRR |= GPIO_BSRR_BR8; + } +} + +inline void led_control_led2_bottom(bool _in) { + if (_in == true) { + GPIOC->BSRR |= GPIO_BSRR_BS9; + } + else { + GPIOC->BSRR |= GPIO_BSRR_BR9; + } +} + +inline void led_flip_led1_upper(void) { + if ((GPIOC->ODR & GPIO_ODR_ODR8) == GPIO_ODR_ODR8) { + GPIOC->BSRR |= GPIO_BSRR_BR8; + } + else { + GPIOC->BSRR |= GPIO_BSRR_BS8; + } +} + +inline void led_flip_led2_bottom(void) { + if ((GPIOC->ODR & GPIO_ODR_ODR9) == GPIO_ODR_ODR9) { + GPIOC->BSRR |= GPIO_BSRR_BR9; + } + else { + GPIOC->BSRR |= GPIO_BSRR_BS9; + } +} + +inline void led_blink_led1_upper(void) { + led_blinking_led1 = BLINK_DURATION_MSEC; + + led_flip_led1_upper(); +} + +inline void led_blink_led2_botoom(void) { + led_blinking_led2 = BLINK_DURATION_MSEC; + + led_flip_led2_bottom(); + +} #ifdef __cplusplus } diff --git a/include/main.h b/include/main.h index 9cb4bcf..8435f3a 100644 --- a/include/main.h +++ b/include/main.h @@ -4,8 +4,8 @@ #include "aprs/ax25.h" #include "drivers/serial.h" -#define SW_VER "DF03" -#define SW_DATE "25062020" +#define SW_VER "DF04" +#define SW_DATE "12072020" #define SYSTICK_TICKS_PER_SECONDS 100 #define SYSTICK_TICKS_PERIOD 10 diff --git a/src/LedConfig.c b/src/LedConfig.c index 80d1219..3a5bbcc 100644 --- a/src/LedConfig.c +++ b/src/LedConfig.c @@ -5,8 +5,14 @@ * Author: mateusz */ +#include "LedConfig.h" #include +// PC8 - LED1 - upper +// PC9 - LED2 - lower + +uint8_t led_blinking_led2; +uint8_t led_blinking_led1; void led_init(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -26,3 +32,29 @@ void led_init(void) { GPIO_Init(GPIOA, &GPIO_InitStructure); } + +void led_service_blink(void) { + + if (led_blinking_led1 > 0) { + led_blinking_led1 -= BLINK_MSEC_PER_SVC_CALL; + + } + + if (led_blinking_led2 > 0) { + led_blinking_led2 -= BLINK_MSEC_PER_SVC_CALL; + } + + + + if (led_blinking_led1 == BLINK_MSEC_PER_SVC_CALL) { + led_flip_led1_upper(); + } + + if (led_blinking_led2 == BLINK_MSEC_PER_SVC_CALL) { + led_flip_led2_bottom(); + } + + + +} + diff --git a/src/it_handlers.c b/src/it_handlers.c index a073550..a79f9f9 100644 --- a/src/it_handlers.c +++ b/src/it_handlers.c @@ -18,6 +18,7 @@ #include "aprs/telemetry.h" #include "aprs/beacon.h" #include "main.h" +#include "LedConfig.h" //#include "afsk.h" #include "diag/Trace.h" @@ -81,6 +82,8 @@ void SysTick_Handler(void) { main_ten_second_pool_decremenet_counter(); + led_service_blink(); + srl_keep_timeout(main_kiss_srl_ctx_ptr); srl_keep_timeout(main_wx_srl_ctx_ptr); @@ -147,12 +150,15 @@ void TIM4_IRQHandler( void ) { DAC->DHR8R1 = AFSK_DAC_ISR(&main_afsk); DAC->SWTRIGR |= 1; - if (main_afsk.sending) { - GPIO_SetBits(GPIOC, GPIO_Pin_9); - } - else { - GPIO_ResetBits(GPIOC, GPIO_Pin_9); - } +#ifndef _METEO + led_control_led2_bottom(main_afsk.sending); +#endif +// if (main_afsk.sending) { +// GPIO_SetBits(GPIOC, GPIO_Pin_9); +// } +// else { +// GPIO_ResetBits(GPIOC, GPIO_Pin_9); +// } } @@ -165,12 +171,7 @@ void TIM7_IRQHandler(void) { if(ASC == 3) { AdcValue = (short int)(( AdcBuffer[0] + AdcBuffer[1] + AdcBuffer[2] + AdcBuffer[3]) >> 1); AFSK_ADC_ISR(&main_afsk, (AdcValue - 4095) ); - if(main_ax25.dcd == true) { // niebieska dioda - GPIOC->BSRR |= GPIO_BSRR_BS8; - } - else { - GPIOC->BSRR |= GPIO_BSRR_BR8; - } + led_control_led1_upper(main_ax25.dcd); ASC = 0; if (ASC2++ == 2) { diff --git a/system/src/drivers/analog_anemometer.c b/system/src/drivers/analog_anemometer.c index 05ed345..b8d1d6f 100644 --- a/system/src/drivers/analog_anemometer.c +++ b/system/src/drivers/analog_anemometer.c @@ -22,6 +22,7 @@ #include "rte_wx.h" #include "main.h" #include "wx_handler.h" +#include "LedConfig.h" #define MINUM_PULSE_LN 15 #define MAXIMUM_PULSE_SLEW_RATE 4000 @@ -211,6 +212,9 @@ void analog_anemometer_dma_irq(void) { return; } + // blinking the led - led will blink every 10 pulses, so if wind is 1m/s it will blink every 10 seconds + led_blink_led2_botoom(); + // calculating time between pulses for (i = 0; i < ANALOG_ANEMOMETER_SPEED_PULSES_N - 1; i++) { pulse_ln = analog_anemometer_windspeed_pulses_time[i + 1] - @@ -424,6 +428,14 @@ int16_t analog_anemometer_direction_handler(void) { rte_wx_winddirection_last = downscaled_angle; + // set the led state + if (rte_wx_winddirection_last > 0 && rte_wx_winddirection_last < 180) { + led_control_led2_bottom(true); + } + else { + led_control_led2_bottom(false); + } + TIM_SetCounter(TIM3, 0); TIM_Cmd(TIM3, ENABLE); diff --git a/system/src/drivers/tx20.c b/system/src/drivers/tx20.c index d431241..da1aa2c 100644 --- a/system/src/drivers/tx20.c +++ b/system/src/drivers/tx20.c @@ -13,6 +13,8 @@ #include "main.h" #include "wx_handler.h" +#include "LedConfig.h" + #define BS TX20.BitSampler #define BQ TX20.BitQueue #define QL TX20.QueueLenght @@ -38,13 +40,7 @@ uint16_t tx20_current_direction; #ifdef _METEO void inline TX20BlinkLed(void) { - if ((GPIOC->ODR & GPIO_ODR_ODR9) == GPIO_ODR_ODR9) { - GPIOC->BSRR |= GPIO_BSRR_BR9; - } - else { - GPIOC->BSRR |= GPIO_BSRR_BS9; - } - + led_flip_led2_botoom(); } #endif @@ -266,12 +262,8 @@ void TIM1_UP_TIM16_IRQHandler( void ) { #elif TIMNUMBER == 2 void TIM2_IRQHandler( void ) { - if ((GPIOC->ODR & GPIO_ODR_ODR9) == GPIO_ODR_ODR9) { - GPIOC->BSRR |= GPIO_BSRR_BR9; - } - else if ((GPIOC->ODR & GPIO_ODR_ODR9) == 0) { - GPIOC->BSRR |= GPIO_BSRR_BS9; - } + led_flip_led2_botoom(); + TIM2->SR &= ~(1<<0); tx20_batch(); @@ -280,12 +272,8 @@ void TIM2_IRQHandler( void ) { #elif TIMNUMBER == 3 void TIM3_IRQHandler( void ) { - if ((GPIOC->ODR & GPIO_ODR_ODR9) == GPIO_ODR_ODR9) { - GPIOC->BSRR |= GPIO_BSRR_BR9; - } - else if ((GPIOC->ODR & GPIO_ODR_ODR9) == 0) { - GPIOC->BSRR |= GPIO_BSRR_BS9; - } + led_flip_led2_botoom(); + TIM3->SR &= ~(1<<0); tx20_batch(); @@ -294,12 +282,8 @@ void TIM3_IRQHandler( void ) { #elif TIMNUMBER == 4 void TIM4_IRQHandler( void ) { - if ((GPIOC->ODR & GPIO_ODR_ODR9) == GPIO_ODR_ODR9) { - GPIOC->BSRR |= GPIO_BSRR_BR9; - } - else if ((GPIOC->ODR & GPIO_ODR_ODR9) == 0) { - GPIOC->BSRR |= GPIO_BSRR_BS9; - } + led_flip_led2_botoom(); + TIM3->SR &= ~(1<<0); tx20_batch();