Fix serial commands handling

This commit is contained in:
muzkr committed 2025-11-06 23:26:09 +08:00
1 parent aa5f7c0092
commit 6d4324ef16
4 files changed
+50 -13

No files matched your search

+5 -2
View File
@@ -39,6 +39,7 @@
#include "app/scanner.h" #include "app/scanner.h"
#ifdef ENABLE_UART #ifdef ENABLE_UART
#include "app/uart.h" #include "app/uart.h"
#include "scheduler.h"
#endif #endif
#include "py32f0xx.h" #include "py32f0xx.h"
#include "audio.h" #include "audio.h"
@@ -1364,9 +1365,11 @@ void APP_TimeSlice10ms(void)
#ifdef ENABLE_UART #ifdef ENABLE_UART
if (UART_IsCommandAvailable()) { if (UART_IsCommandAvailable()) {
__disable_irq(); // __disable_irq();
SCHEDULER_Disable();
UART_HandleCommand(); UART_HandleCommand();
__enable_irq(); // __enable_irq();
SCHEDULER_Enable();
} }
#endif #endif
+13 -11
View File
@@ -29,7 +29,7 @@
#include "driver/backlight.h" #include "driver/backlight.h"
#include "driver/bk4819.h" #include "driver/bk4819.h"
#include "driver/crc.h" #include "driver/crc.h"
#include "driver/py25q16.h" #include "driver/eeprom.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/uart.h" #include "driver/uart.h"
#include "functions.h" #include "functions.h"
@@ -45,6 +45,8 @@
#define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer)) #define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer))
#define DMA_CHANNEL LL_DMA_CHANNEL_2
typedef struct { typedef struct {
uint16_t ID; uint16_t ID;
uint16_t Size; uint16_t Size;
@@ -162,7 +164,8 @@ static union
static uint32_t Timestamp; static uint32_t Timestamp;
static uint16_t gUART_WriteIndex; static uint16_t gUART_WriteIndex;
static bool bIsEncrypted = true; // static bool bIsEncrypted = true;
#define bIsEncrypted true
static void SendReply(void *pReply, uint16_t Size) static void SendReply(void *pReply, uint16_t Size)
{ {
@@ -285,7 +288,7 @@ static void CMD_051B(const uint8_t *pBuffer)
if (!bLocked) if (!bLocked)
{ {
PY25Q16_ReadBuffer(pCmd->Offset, Reply.Data.Data, pCmd->Size); EEPROM_ReadBuffer(pCmd->Offset, Reply.Data.Data, pCmd->Size);
} }
SendReply(&Reply, pCmd->Size + 8); SendReply(&Reply, pCmd->Size + 8);
@@ -314,7 +317,7 @@ static void CMD_051D(const uint8_t *pBuffer)
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
Reply.Data.Offset = pCmd->Offset; Reply.Data.Offset = pCmd->Offset;
bIsLocked = bHasCustomAesKey ? gIsLocked : bHasCustomAesKey; bIsLocked = bHasCustomAesKey ? gIsLocked : false;
if (!bIsLocked) if (!bIsLocked)
{ {
@@ -329,8 +332,7 @@ static void CMD_051D(const uint8_t *pBuffer)
if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !bIsInLockScreen || pCmd->bAllowPassword) if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !bIsInLockScreen || pCmd->bAllowPassword)
{ {
// EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U]); EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U]);
// TODO: To be implemented
} }
} }
@@ -498,7 +500,7 @@ bool UART_IsCommandAvailable(void)
uint16_t Size; uint16_t Size;
uint16_t Crc; uint16_t Crc;
uint16_t CommandLength; uint16_t CommandLength;
uint16_t DmaLength = sizeof(UART_DMA_Buffer) - LL_DMA_GetDataLength(DMA1, LL_DMA_CHANNEL_2); uint16_t DmaLength = sizeof(UART_DMA_Buffer) - LL_DMA_GetDataLength(DMA1, DMA_CHANNEL);
while (1) while (1)
{ {
@@ -566,11 +568,11 @@ bool UART_IsCommandAvailable(void)
gUART_WriteIndex = TailIndex; gUART_WriteIndex = TailIndex;
if (UART_Command.Header.ID == 0x0514) // if (UART_Command.Header.ID == 0x0514)
bIsEncrypted = false; // bIsEncrypted = false;
if (UART_Command.Header.ID == 0x6902) // if (UART_Command.Header.ID == 0x6902)
bIsEncrypted = true; // bIsEncrypted = true;
if (bIsEncrypted) if (bIsEncrypted)
{ {
+1
View File
@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "scheduler.h"
#include "app/chFrScanner.h" #include "app/chFrScanner.h"
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
#include "app/fm.h" #include "app/fm.h"
+31
View File
@@ -0,0 +1,31 @@
/* Copyright 2025 muzkr https://github.com/muzkr
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _SCHEDULER_H
#define _SCHEDULER_H
#include "py32f0xx.h"
static void inline SCHEDULER_Enable()
{
NVIC_EnableIRQ(SysTick_IRQn);
}
static void inline SCHEDULER_Disable()
{
NVIC_DisableIRQ(SysTick_IRQn);
}
#endif