added leds light
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "usart_if.h"
|
||||
#include "usart.h"
|
||||
#include "main.h"
|
||||
#include "timer.h"
|
||||
|
||||
#include "config/config_consts.h"
|
||||
#include "config/config_types.h"
|
||||
@@ -49,9 +50,9 @@ static volatile uint8_t g_radio_rx_error = 0;
|
||||
static volatile int16_t g_last_rx_rssi = 0;
|
||||
static volatile int8_t g_last_rx_cfo = 0;
|
||||
|
||||
static volatile uint8_t g_led_tx_ticks = 0U;
|
||||
static volatile uint8_t g_led_rx_ticks = 0U;
|
||||
static volatile uint8_t g_led_err_ticks = 0U;
|
||||
static TimerEvent_t g_led_tx_timer;
|
||||
static TimerEvent_t g_led_rx_timer;
|
||||
static TimerEvent_t g_led_err_timer;
|
||||
|
||||
static volatile uint8_t g_radio_busy = 0;
|
||||
static volatile uint8_t g_radio_needs_rx_restart = 0;
|
||||
@@ -90,6 +91,10 @@ static void App_LedTxPulse(void);
|
||||
static void App_LedRxPulse(void);
|
||||
static void App_LedErrPulse(void);
|
||||
|
||||
static void App_LedTxOff(void *context);
|
||||
static void App_LedRxOff(void *context);
|
||||
static void App_LedErrOff(void *context);
|
||||
|
||||
static void UartRxByteCallback(uint8_t *rxChar, uint16_t size, uint8_t error);
|
||||
static void App_ProcessRadioEvents(void);
|
||||
static void App_ProcessUartPacketizer(void);
|
||||
@@ -132,6 +137,10 @@ void SubghzApp_Init(void)
|
||||
|
||||
Radio.Init(&RadioEvents);
|
||||
|
||||
TimerInit(&g_led_tx_timer, App_LedTxOff);
|
||||
TimerInit(&g_led_rx_timer, App_LedRxOff);
|
||||
TimerInit(&g_led_err_timer, App_LedErrOff);
|
||||
|
||||
App_RadioApplyConfig();
|
||||
App_ReconfigureUart(g_cfg.uart_baudrate);
|
||||
App_RadioEnterRx();
|
||||
@@ -140,10 +149,6 @@ void SubghzApp_Init(void)
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
|
||||
|
||||
g_led_tx_ticks = 0U;
|
||||
g_led_rx_ticks = 0U;
|
||||
g_led_err_ticks = 0U;
|
||||
|
||||
g_uart_last_data_tick = HAL_GetTick();
|
||||
(void)vcom_ReceiveInit(UartRxByteCallback);
|
||||
|
||||
@@ -862,67 +867,53 @@ static char *App_SkipSpaces(char *s)
|
||||
}
|
||||
return s;
|
||||
}
|
||||
void SubghzApp_Timer1msIrq(void)
|
||||
{
|
||||
if (g_led_tx_ticks > 0U)
|
||||
{
|
||||
g_led_tx_ticks--;
|
||||
if (g_led_tx_ticks == 0U)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_led_rx_ticks > 0U)
|
||||
{
|
||||
g_led_rx_ticks--;
|
||||
if (g_led_rx_ticks == 0U)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_led_err_ticks > 0U)
|
||||
{
|
||||
g_led_err_ticks--;
|
||||
if (g_led_err_ticks == 0U)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
if (htim->Instance == TIM2) // замени на свой таймер
|
||||
{
|
||||
SubghzApp_Timer1msIrq();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_LedTxPulse(void)
|
||||
{
|
||||
TimerStop(&g_led_tx_timer);
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
|
||||
g_led_tx_ticks = LED_PULSE_MS;
|
||||
TimerSetValue(&g_led_tx_timer, LED_PULSE_MS);
|
||||
TimerStart(&g_led_tx_timer);
|
||||
}
|
||||
|
||||
static void App_LedRxPulse(void)
|
||||
{
|
||||
TimerStop(&g_led_rx_timer);
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
|
||||
g_led_rx_ticks = LED_PULSE_MS;
|
||||
TimerSetValue(&g_led_rx_timer, LED_PULSE_MS);
|
||||
TimerStart(&g_led_rx_timer);
|
||||
}
|
||||
|
||||
static void App_LedErrPulse(void)
|
||||
{
|
||||
TimerStop(&g_led_err_timer);
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
|
||||
g_led_err_ticks = LED_PULSE_MS;
|
||||
TimerSetValue(&g_led_err_timer, LED_PULSE_MS);
|
||||
TimerStart(&g_led_err_timer);
|
||||
}
|
||||
|
||||
static void OnTxDone(void)
|
||||
{
|
||||
g_radio_tx_done = 1U;
|
||||
}
|
||||
|
||||
static void App_LedTxOff(void *context)
|
||||
{
|
||||
(void)context;
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
static void App_LedRxOff(void *context)
|
||||
{
|
||||
(void)context;
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
static void App_LedErrOff(void *context)
|
||||
{
|
||||
(void)context;
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
|
||||
static void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t cfo)
|
||||
{
|
||||
g_last_rx_rssi = rssi;
|
||||
|
||||
Reference in New Issue
Block a user