From 995045006fda6581c8e75aac5220b14e1da4d5a0 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Sat, 9 Dec 2023 19:01:38 +0100 Subject: [PATCH] Read/write BK4819 regs through UART --- Makefile | 4 ++++ app/uart.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Makefile b/Makefile index 9de8dea..406f7e3 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,7 @@ ENABLE_SCAN_RANGES ?= 1 # ---- DEBUGGING ---- ENABLE_AM_FIX_SHOW_DATA ?= 0 ENABLE_AGC_SHOW_DATA ?= 0 +ENABLE_UART_RW_BK_REGS ?= 0 ############################################################# @@ -369,6 +370,9 @@ endif ifeq ($(ENABLE_FLASHLIGHT),1) CFLAGS += -DENABLE_FLASHLIGHT endif +ifeq ($(ENABLE_UART_RW_BK_REGS),1) + CFLAGS += -DENABLE_UART_RW_BK_REGS +endif LDFLAGS = LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections diff --git a/app/uart.c b/app/uart.c index 266652f..840b43a 100644 --- a/app/uart.c +++ b/app/uart.c @@ -395,6 +395,11 @@ static void CMD_052D(const uint8_t *pBuffer) SendReply(&Reply, sizeof(Reply)); } +// session init, sends back version info and state +// timestamp is a session id really +// this command also disables dual watch, crossband, +// DTMF side tones, freq reverse, PTT ID, DTMF decoding, frequency offset +// exits power save, sets main VFO to upper, static void CMD_052F(const uint8_t *pBuffer) { const CMD_052F_t *pCmd = (const CMD_052F_t *)pBuffer; @@ -429,6 +434,44 @@ static void CMD_052F(const uint8_t *pBuffer) SendVersion(); } +#ifdef ENABLE_UART_RW_BK_REGS +static void CMD_0601_ReadBK4819Reg(const uint8_t *pBuffer) +{ + typedef struct __attribute__((__packed__)) { + Header_t header; + uint8_t reg; + } CMD_0601_t; + + CMD_0601_t *cmd = (CMD_0601_t*) pBuffer; + + struct __attribute__((__packed__)) { + Header_t header; + struct { + uint8_t reg; + uint16_t value; + } data; + } reply; + + reply.header.ID = 0x0601; + reply.header.Size = sizeof(reply.data); + reply.data.reg = cmd->reg; + reply.data.value = BK4819_ReadRegister(cmd->reg); + SendReply(&reply, sizeof(reply)); +} + +static void CMD_0602_WriteBK4819Reg(const uint8_t *pBuffer) +{ + typedef struct __attribute__((__packed__)) { + Header_t header; + uint8_t reg; + uint16_t value; + } CMD_0602_t; + + CMD_0602_t *cmd = (CMD_0602_t*) pBuffer; + BK4819_WriteRegister(cmd->reg, cmd->value); +} +#endif + bool UART_IsCommandAvailable(void) { uint16_t Index; @@ -567,5 +610,15 @@ void UART_HandleCommand(void) NVIC_SystemReset(); #endif break; + +#ifdef ENABLE_UART_RW_BK_REGS + case 0x0601: + CMD_0601_ReadBK4819Reg(UART_Command.Buffer); + break; + + case 0x0602: + CMD_0602_WriteBK4819Reg(UART_Command.Buffer); + break; +#endif } }