Add saving cnf in ROM, workink with leds
This commit is contained in:
46
SubGHz_Phy/App/config/config_consts.h
Normal file
46
SubGHz_Phy/App/config/config_consts.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef CONFIG_CONSTS_H
|
||||
#define CONFIG_CONSTS_H
|
||||
|
||||
#define RX_TIMEOUT_VALUE_MS 0U
|
||||
#define TX_TIMEOUT_VALUE_MS 3000U
|
||||
#define RX_CONTINUOUS_ON 1U
|
||||
#define RADIO_SYNCWORD_LEN 3U
|
||||
#define RADIO_WHITENING_SEED 0x01FFU
|
||||
#define RADIO_CRC_POLY 0x8005U
|
||||
#define RADIO_CRC_SEED 0xFFFFU
|
||||
|
||||
#define UART_DATA_BUFFER_SIZE 220U
|
||||
#define RADIO_MAX_PAYLOAD_SIZE 220U
|
||||
#define TX_QUEUE_DEPTH 4U
|
||||
#define CONFIG_LINE_SIZE 96U
|
||||
#define CONFIG_ESCAPE_GUARD_MS 800U
|
||||
|
||||
// Reserved addresses for configuration
|
||||
|
||||
#define FLASH_BASE_ADDR 0x08000000U
|
||||
#define FLASH_TOTAL_SIZE 0x00040000U // 256 KB
|
||||
#define FLASH_PAGE_SIZE 0x00000800U // 2 KB
|
||||
#define CONFIG_FLASH_ADDR (FLASH_BASE_ADDR + FLASH_TOTAL_SIZE - FLASH_PAGE_SIZE)
|
||||
|
||||
#define CONFIG_MAGIC 0x43464731UL // "CFG1"
|
||||
|
||||
|
||||
#define LED_PULSE_MS 50U
|
||||
|
||||
// Default config values
|
||||
|
||||
#define DEFAULT_RF_FREQUENCY 433100000UL
|
||||
#define DEFAULT_TX_OUTPUT_POWER 14
|
||||
#define DEFAULT_FSK_FDEV 25000UL
|
||||
#define DEFAULT_FSK_BITRATE 50000UL
|
||||
#define DEFAULT_FSK_BANDWIDTH 50000UL
|
||||
#define DEFAULT_FSK_PREAMBLE_LENGTH 4U
|
||||
#define DEFAULT_UART_PACKET_TIMEOUT_MS 20U
|
||||
#define DEFAULT_UART_BAUDRATE 115200U
|
||||
#define DEFAULT_SYNCWORD {0x91, 0xC4, 0x91}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
21
SubGHz_Phy/App/config/config_defaults.c
Normal file
21
SubGHz_Phy/App/config/config_defaults.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "config_defaults.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void Config_LoadDefaults(BridgeConfig_t *cfg)
|
||||
{
|
||||
if (cfg == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
cfg->rf_frequency = DEFAULT_RF_FREQUENCY;
|
||||
cfg->tx_power = DEFAULT_TX_OUTPUT_POWER;
|
||||
cfg->fsk_bitrate = DEFAULT_FSK_BITRATE;
|
||||
cfg->fsk_bandwidth = DEFAULT_FSK_BANDWIDTH;
|
||||
cfg->fsk_fdev = DEFAULT_FSK_FDEV;
|
||||
cfg->fsk_preamble_len = DEFAULT_FSK_PREAMBLE_LENGTH;
|
||||
static const uint8_t default_syncword[3] = DEFAULT_SYNCWORD;
|
||||
memcpy(cfg->syncword, default_syncword, sizeof(cfg->syncword));
|
||||
cfg->uart_packet_timeout_ms = DEFAULT_UART_PACKET_TIMEOUT_MS;
|
||||
cfg->uart_baudrate = DEFAULT_UART_BAUDRATE;
|
||||
}
|
||||
9
SubGHz_Phy/App/config/config_defaults.h
Normal file
9
SubGHz_Phy/App/config/config_defaults.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef CONFIG_DEFAULTS_H
|
||||
#define CONFIG_DEFAULTS_H
|
||||
|
||||
#include "config_types.h"
|
||||
#include "config_consts.h"
|
||||
|
||||
void Config_LoadDefaults(BridgeConfig_t *cfg);
|
||||
|
||||
#endif
|
||||
110
SubGHz_Phy/App/config/config_store.c
Normal file
110
SubGHz_Phy/App/config/config_store.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "config_store.h"
|
||||
#include "config_defaults.h"
|
||||
#include "stm32wlxx_hal.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic;
|
||||
uint32_t checksum;
|
||||
BridgeConfig_t cfg;
|
||||
} FlashConfig_t;
|
||||
|
||||
static uint32_t Config_CalcChecksum(const uint8_t *data, uint32_t len)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
sum += data[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool Config_Load(BridgeConfig_t *cfg)
|
||||
{
|
||||
const FlashConfig_t *stored;
|
||||
uint32_t calc;
|
||||
|
||||
if (cfg == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
stored = (const FlashConfig_t *)CONFIG_FLASH_ADDR;
|
||||
|
||||
if (stored->magic != CONFIG_MAGIC)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
calc = Config_CalcChecksum((const uint8_t *)&stored->cfg, sizeof(BridgeConfig_t));
|
||||
|
||||
if (calc != stored->checksum)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(cfg, &stored->cfg, sizeof(BridgeConfig_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config_Save(const BridgeConfig_t *cfg)
|
||||
{
|
||||
FlashConfig_t temp;
|
||||
FLASH_EraseInitTypeDef erase;
|
||||
uint32_t page_error = 0;
|
||||
uint32_t addr;
|
||||
uint32_t i;
|
||||
const uint64_t *src64;
|
||||
uint32_t words64_count;
|
||||
|
||||
if (cfg == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(&temp, 0xFF, sizeof(temp));
|
||||
|
||||
temp.magic = CONFIG_MAGIC;
|
||||
memcpy(&temp.cfg, cfg, sizeof(BridgeConfig_t));
|
||||
temp.checksum = Config_CalcChecksum((const uint8_t *)&temp.cfg, sizeof(BridgeConfig_t));
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
memset(&erase, 0, sizeof(erase));
|
||||
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
erase.Page = (CONFIG_FLASH_ADDR - FLASH_BASE_ADDR) / FLASH_PAGE_SIZE;
|
||||
erase.NbPages = 1;
|
||||
|
||||
if (HAL_FLASHEx_Erase(&erase, &page_error) != HAL_OK)
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return false;
|
||||
}
|
||||
|
||||
addr = CONFIG_FLASH_ADDR;
|
||||
src64 = (const uint64_t *)&temp;
|
||||
words64_count = (sizeof(FlashConfig_t) + 7U) / 8U;
|
||||
|
||||
for (i = 0; i < words64_count; i++)
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, addr, src64[i]) != HAL_OK)
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return false;
|
||||
}
|
||||
|
||||
addr += 8U;
|
||||
}
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
return true;
|
||||
}
|
||||
21
SubGHz_Phy/App/config/config_store.h
Normal file
21
SubGHz_Phy/App/config/config_store.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef CONFIG_STORE_H
|
||||
#define CONFIG_STORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "config_types.h"
|
||||
#include "config_consts.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool Config_Load(BridgeConfig_t *cfg);
|
||||
bool Config_Save(const BridgeConfig_t *cfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
25
SubGHz_Phy/App/config/config_types.h
Normal file
25
SubGHz_Phy/App/config/config_types.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef CONFIG_TYPES_H
|
||||
#define CONFIG_TYPES_H
|
||||
|
||||
#include "config_consts.h"
|
||||
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t rf_frequency;
|
||||
int8_t tx_power;
|
||||
uint32_t fsk_bitrate;
|
||||
uint32_t fsk_bandwidth;
|
||||
uint32_t fsk_fdev;
|
||||
uint16_t fsk_preamble_len;
|
||||
uint8_t syncword[RADIO_SYNCWORD_LEN];
|
||||
uint16_t uart_packet_timeout_ms;
|
||||
uint32_t uart_baudrate;
|
||||
} BridgeConfig_t;
|
||||
|
||||
#endif
|
||||
@@ -5,6 +5,11 @@
|
||||
#include "usart.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "config/config_consts.h"
|
||||
#include "config/config_types.h"
|
||||
#include "config/config_defaults.h"
|
||||
#include "config/config_store.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
@@ -12,20 +17,6 @@
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RX_TIMEOUT_VALUE_MS 0U
|
||||
#define TX_TIMEOUT_VALUE_MS 3000U
|
||||
#define RX_CONTINUOUS_ON 1U
|
||||
#define RADIO_SYNCWORD_LEN 3U
|
||||
#define RADIO_WHITENING_SEED 0x01FFU
|
||||
#define RADIO_CRC_POLY 0x8005U
|
||||
#define RADIO_CRC_SEED 0xFFFFU
|
||||
|
||||
#define UART_DATA_BUFFER_SIZE 220U
|
||||
#define RADIO_MAX_PAYLOAD_SIZE 220U
|
||||
#define TX_QUEUE_DEPTH 4U
|
||||
#define CONFIG_LINE_SIZE 96U
|
||||
#define CONFIG_ESCAPE_GUARD_MS 800U
|
||||
#define DEFAULT_UART_PACKET_TIMEOUT_MS 20U
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -33,19 +24,6 @@ typedef enum
|
||||
APP_MODE_CONFIG
|
||||
} AppMode_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t rf_frequency;
|
||||
int8_t tx_power;
|
||||
uint32_t fsk_bitrate;
|
||||
uint32_t fsk_bandwidth;
|
||||
uint32_t fsk_fdev;
|
||||
uint16_t fsk_preamble_len;
|
||||
uint8_t syncword[RADIO_SYNCWORD_LEN];
|
||||
uint16_t uart_packet_timeout_ms;
|
||||
uint32_t uart_baudrate;
|
||||
} BridgeConfig_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t data[RADIO_MAX_PAYLOAD_SIZE];
|
||||
@@ -62,19 +40,7 @@ typedef struct
|
||||
} EscapeDetector_t;
|
||||
|
||||
static RadioEvents_t RadioEvents;
|
||||
static BridgeConfig_t g_cfg =
|
||||
{
|
||||
.rf_frequency = RF_FREQUENCY_DEFAULT,
|
||||
.tx_power = TX_OUTPUT_POWER_DEFAULT,
|
||||
.fsk_bitrate = FSK_DATARATE_DEFAULT,
|
||||
.fsk_bandwidth = FSK_BANDWIDTH_DEFAULT,
|
||||
.fsk_fdev = FSK_FDEV_DEFAULT,
|
||||
.fsk_preamble_len = FSK_PREAMBLE_LENGTH_DEFAULT,
|
||||
.syncword = {0xC1, 0x94, 0xC1},
|
||||
.uart_packet_timeout_ms = DEFAULT_UART_PACKET_TIMEOUT_MS,
|
||||
.uart_baudrate = 115200UL,
|
||||
};
|
||||
|
||||
static BridgeConfig_t g_cfg;
|
||||
static volatile uint8_t g_radio_tx_done = 0;
|
||||
static volatile uint8_t g_radio_tx_timeout = 0;
|
||||
static volatile uint8_t g_radio_rx_done = 0;
|
||||
@@ -83,6 +49,10 @@ 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 volatile uint8_t g_radio_busy = 0;
|
||||
static volatile uint8_t g_radio_needs_rx_restart = 0;
|
||||
|
||||
@@ -116,6 +86,10 @@ static void OnTxTimeout(void);
|
||||
static void OnRxTimeout(void);
|
||||
static void OnRxError(void);
|
||||
|
||||
static void App_LedTxPulse(void);
|
||||
static void App_LedRxPulse(void);
|
||||
static void App_LedErrPulse(void);
|
||||
|
||||
static void UartRxByteCallback(uint8_t *rxChar, uint16_t size, uint8_t error);
|
||||
static void App_ProcessRadioEvents(void);
|
||||
static void App_ProcessUartPacketizer(void);
|
||||
@@ -145,6 +119,11 @@ static char *App_SkipSpaces(char *s);
|
||||
|
||||
void SubghzApp_Init(void)
|
||||
{
|
||||
if (!Config_Load(&g_cfg))
|
||||
{
|
||||
Config_LoadDefaults(&g_cfg);
|
||||
}
|
||||
|
||||
RadioEvents.TxDone = OnTxDone;
|
||||
RadioEvents.RxDone = OnRxDone;
|
||||
RadioEvents.TxTimeout = OnTxTimeout;
|
||||
@@ -152,9 +131,19 @@ void SubghzApp_Init(void)
|
||||
RadioEvents.RxError = OnRxError;
|
||||
|
||||
Radio.Init(&RadioEvents);
|
||||
|
||||
App_RadioApplyConfig();
|
||||
App_ReconfigureUart(g_cfg.uart_baudrate);
|
||||
App_RadioEnterRx();
|
||||
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
|
||||
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);
|
||||
|
||||
@@ -185,6 +174,7 @@ static void App_ProcessRadioEvents(void)
|
||||
{
|
||||
g_radio_tx_timeout = 0U;
|
||||
g_radio_busy = 0U;
|
||||
App_LedErrPulse();
|
||||
App_QueuePop();
|
||||
App_Printf("\r\n[WARN] radio tx timeout\r\n");
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
@@ -193,6 +183,7 @@ static void App_ProcessRadioEvents(void)
|
||||
if (g_radio_rx_done != 0U)
|
||||
{
|
||||
g_radio_rx_done = 0U;
|
||||
App_LedRxPulse();
|
||||
g_stat_radio_packets_rx++;
|
||||
g_stat_radio_bytes_rx += g_rx_payload_len;
|
||||
|
||||
@@ -208,6 +199,7 @@ static void App_ProcessRadioEvents(void)
|
||||
{
|
||||
g_radio_rx_timeout = 0U;
|
||||
g_radio_rx_error = 0U;
|
||||
App_LedErrPulse();
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
@@ -273,8 +265,19 @@ static void App_StartNextTxIfPossible(void)
|
||||
|
||||
App_RadioConfigureTx();
|
||||
g_radio_busy = 1U;
|
||||
App_LedTxPulse();
|
||||
(void)Radio.Send(g_tx_queue[g_tx_q_head].data, g_tx_queue[g_tx_q_head].len);
|
||||
}
|
||||
static void App_ApplyConfig(void)
|
||||
{
|
||||
App_RadioApplyConfig();
|
||||
App_RadioConfigureRx();
|
||||
App_RadioConfigureTx();
|
||||
if (!Config_Save(&g_cfg)) {
|
||||
App_Printf("Error while saving cnf\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void App_RadioApplyConfig(void)
|
||||
{
|
||||
@@ -350,6 +353,13 @@ static void App_EnterConfigMode(void)
|
||||
g_mode = APP_MODE_CONFIG;
|
||||
App_Printf("\r\n\r\n[CONFIG MODE]\r\n");
|
||||
App_Printf("type 'help' for commands\r\n");
|
||||
if (!Config_Load(&g_cfg))
|
||||
{
|
||||
App_Printf("Error while loading cnf\r\n");
|
||||
App_Printf("Cnf was reset to defaults\r\n");
|
||||
Config_LoadDefaults(&g_cfg);
|
||||
|
||||
}
|
||||
App_PrintConfigPrompt();
|
||||
}
|
||||
|
||||
@@ -555,20 +565,14 @@ static void App_ConfigExecuteLine(char *line)
|
||||
App_ExitConfigMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(line, "save") == 0)
|
||||
{
|
||||
App_ApplyConfig();
|
||||
return;
|
||||
}
|
||||
if (strcmp(line, "defaults") == 0)
|
||||
{
|
||||
g_cfg.rf_frequency = RF_FREQUENCY_DEFAULT;
|
||||
g_cfg.tx_power = TX_OUTPUT_POWER_DEFAULT;
|
||||
g_cfg.fsk_bitrate = FSK_DATARATE_DEFAULT;
|
||||
g_cfg.fsk_bandwidth = FSK_BANDWIDTH_DEFAULT;
|
||||
g_cfg.fsk_fdev = FSK_FDEV_DEFAULT;
|
||||
g_cfg.fsk_preamble_len = FSK_PREAMBLE_LENGTH_DEFAULT;
|
||||
g_cfg.syncword[0] = 0xC1U;
|
||||
g_cfg.syncword[1] = 0x94U;
|
||||
g_cfg.syncword[2] = 0xC1U;
|
||||
g_cfg.uart_packet_timeout_ms = DEFAULT_UART_PACKET_TIMEOUT_MS;
|
||||
App_RadioApplyConfig();
|
||||
Config_LoadDefaults(&g_cfg);
|
||||
App_Printf("defaults restored\r\n");
|
||||
return;
|
||||
}
|
||||
@@ -582,7 +586,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.rf_frequency = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("freq=%lu\r\n", (unsigned long)g_cfg.rf_frequency);
|
||||
return;
|
||||
}
|
||||
@@ -596,7 +599,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.tx_power = (int8_t)pwr;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("power=%d\r\n", g_cfg.tx_power);
|
||||
return;
|
||||
}
|
||||
@@ -610,7 +612,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_bitrate = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("bitrate=%lu\r\n", (unsigned long)g_cfg.fsk_bitrate);
|
||||
return;
|
||||
}
|
||||
@@ -624,7 +625,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_bandwidth = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("bandwidth=%lu\r\n", (unsigned long)g_cfg.fsk_bandwidth);
|
||||
return;
|
||||
}
|
||||
@@ -638,7 +638,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_fdev = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("fdev=%lu\r\n", (unsigned long)g_cfg.fsk_fdev);
|
||||
return;
|
||||
}
|
||||
@@ -652,7 +651,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_preamble_len = (uint16_t)u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("preamble=%u\r\n", g_cfg.fsk_preamble_len);
|
||||
return;
|
||||
}
|
||||
@@ -693,7 +691,6 @@ static void App_ConfigExecuteLine(char *line)
|
||||
return;
|
||||
}
|
||||
memcpy(g_cfg.syncword, sync, sizeof(sync));
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("sync=%02X%02X%02X\r\n", g_cfg.syncword[0], g_cfg.syncword[1], g_cfg.syncword[2]);
|
||||
return;
|
||||
}
|
||||
@@ -722,7 +719,8 @@ static void App_PrintHelp(void)
|
||||
App_Printf(" preamble <bytes> - fsk preamble length\r\n");
|
||||
App_Printf(" sync <hex6> - 3-byte syncword, example C194C1\r\n");
|
||||
App_Printf(" timeout <ms> - uart silence before rf packet send\r\n");
|
||||
App_Printf(" uart <baud> - change uart baudrate immediately\r\n");
|
||||
App_Printf(" uart <baud> - change uart baudrate\r\n");
|
||||
App_Printf(" save - save and apply changes\r\n");
|
||||
App_Printf(" defaults - restore default config\r\n");
|
||||
App_Printf(" exit - return to transparent bridge mode\r\n");
|
||||
}
|
||||
@@ -864,6 +862,61 @@ 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)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
|
||||
g_led_tx_ticks = LED_PULSE_MS;
|
||||
}
|
||||
|
||||
static void App_LedRxPulse(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
|
||||
g_led_rx_ticks = LED_PULSE_MS;
|
||||
}
|
||||
|
||||
static void App_LedErrPulse(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
|
||||
g_led_err_ticks = LED_PULSE_MS;
|
||||
}
|
||||
|
||||
static void OnTxDone(void)
|
||||
{
|
||||
|
||||
@@ -7,18 +7,14 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RF_FREQUENCY_DEFAULT 433100000UL
|
||||
#define TX_OUTPUT_POWER_DEFAULT 14
|
||||
#define FSK_FDEV_DEFAULT 25000UL
|
||||
#define FSK_DATARATE_DEFAULT 50000UL
|
||||
#define FSK_BANDWIDTH_DEFAULT 50000UL
|
||||
#define FSK_PREAMBLE_LENGTH_DEFAULT 4U
|
||||
|
||||
void SubghzApp_Init(void);
|
||||
void SubghzApp_Process(void);
|
||||
|
||||
/* вызывать из IRQ таймера 1 раз в 1 мс */
|
||||
void SubghzApp_Timer1msIrq(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SUBGHZ_PHY_APP_H__ */
|
||||
#endif /* __SUBGHZ_PHY_APP_H__ */
|
||||
Reference in New Issue
Block a user