解决中性光写flash闪烁问题

This commit is contained in:
2026-07-29 11:27:02 +08:00
parent 7b0bf78309
commit 46e9db0796
7 changed files with 181 additions and 16 deletions
@@ -121,6 +121,17 @@ void set_mode(){
{
Light_Transition_BeginModeChange();
}
else if(choose_mode_falsg == CUSTOM_TEMPERATURE_MODE)
{
/*
* APP CCT packets can arrive continuously while the color
* ring is dragged. Restart the same 200 ms linear transition
* used by static mode changes from the current visible
* output, so the latest W/C target is followed without a
* discontinuity.
*/
Light_Transition_BeginModeChange();
}
else
{
Light_Transition_ModeActive=0U;
@@ -147,6 +147,9 @@ void Bridge_Init(void);
void Bridge_Off(void);
void Bridge_Service_1ms(void);
void Bridge_Deadtime_Expired(void);
void Bridge_FlashBlank_Request(void);
uint8_t Bridge_FlashBlank_Ready(void);
void Bridge_FlashBlank_Resume(void);
#ifdef __cplusplus
}
#endif
@@ -54,9 +54,14 @@
#define BRIDGE_STAGE_START_C 4U
#define BRIDGE_STAGE_END_C 5U
#define BRIDGE_FLASH_BLANK_IDLE 0U
#define BRIDGE_FLASH_BLANK_REQUEST 1U
#define BRIDGE_FLASH_BLANK_READY 2U
static volatile uint8_t active_state;
static volatile uint8_t output_mode;
static volatile uint8_t timer_stage;
static volatile uint8_t flash_blank_state;
static volatile uint8_t pending_single_state;
static volatile uint16_t pending_single_duty;
static volatile uint16_t frame_w_us;
@@ -212,6 +217,7 @@ void Bridge_Init(void)
NVIC_SetPriority((IRQn_Type)TIMER3_IRQn, 0);
NVIC_EnableIRQ(TIMER3_IRQn);
flash_blank_state = BRIDGE_FLASH_BLANK_IDLE;
bridge_ready = 1U;
Bridge_Off();
}
@@ -244,6 +250,57 @@ void Bridge_Off(void)
cached_c_mix = 0xFFFFU;
bridge_force_off();
output_mode = BRIDGE_MODE_OFF;
if (flash_blank_state == BRIDGE_FLASH_BLANK_REQUEST)
flash_blank_state = BRIDGE_FLASH_BLANK_READY;
}
void Bridge_FlashBlank_Request(void)
{
if (!bridge_ready ||
flash_blank_state != BRIDGE_FLASH_BLANK_IDLE)
return;
if (output_mode == BRIDGE_MODE_DUAL &&
timer_stage != BRIDGE_STAGE_IDLE) {
flash_blank_state = BRIDGE_FLASH_BLANK_REQUEST;
return;
}
flash_blank_state = BRIDGE_FLASH_BLANK_READY;
}
uint8_t Bridge_FlashBlank_Ready(void)
{
return (flash_blank_state == BRIDGE_FLASH_BLANK_READY) ? 1U : 0U;
}
void Bridge_FlashBlank_Resume(void)
{
if (flash_blank_state != BRIDGE_FLASH_BLANK_READY)
return;
flash_blank_state = BRIDGE_FLASH_BLANK_IDLE;
}
/*
* Flash page-program keeps global interrupts disabled. Poll Timer3 from the
* RAM-resident Flash busy loop so the software H-bridge frame continues.
*/
__RAM_CODE void xc_fmc_spi_flash_busy_hook(void)
{
if (!bridge_ready ||
(deviceStatus == POWEROFF && !Light_Transition_FadeActive) ||
output_mode != BRIDGE_MODE_DUAL ||
timer_stage < BRIDGE_STAGE_START_W ||
timer_stage > BRIDGE_STAGE_END_C)
return;
if (timer_tis_get(TIMER3_IDX) != 0U) {
NVIC_ClearPendingIRQ((IRQn_Type)TIMER3_IRQn);
(void)timer_tic_get(TIMER3_IDX);
Bridge_Deadtime_Expired();
}
}
__RAM_CODE void Bridge_Deadtime_Expired(void)
@@ -260,6 +317,10 @@ __RAM_CODE void Bridge_Deadtime_Expired(void)
}
if (timer_stage == BRIDGE_STAGE_START_W) {
if (flash_blank_state == BRIDGE_FLASH_BLANK_REQUEST) {
flash_blank_state = BRIDGE_FLASH_BLANK_READY;
}
/*
* Latch all four durations together at the W boundary. A brightness
* update can then never mix old and new timings inside one frame.
@@ -355,6 +416,9 @@ __RAM_CODE void Bridge_Service_1ms(void)
uint16_t pwm_duty;
uint8_t single_state;
if (flash_blank_state != BRIDGE_FLASH_BLANK_IDLE)
return;
if (!bridge_ready ||
(deviceStatus == POWEROFF && !Light_Transition_FadeActive)) {
if (output_mode != BRIDGE_MODE_OFF || timer_stage != BRIDGE_STAGE_IDLE) {
@@ -4,6 +4,14 @@
// extern uint8_t ble_flash_operation_can_check(void);
#include "ota_protocol.h"
#include "fmc_spi.h"
#include "PWM.h"
#define USER_DATA_FLASH_ADDR 0x1E000UL
#define USER_FLASH_WRITE_CHUNKS 16U
#define USER_FLASH_CHUNK_GAP_MS 20U
static uint8_t user_flash_write_chunk;
static uint8_t user_flash_chunk_gap_ms;
op_flash_t op_flash = {
OP_IDEL,
};
@@ -62,9 +70,43 @@ void ble_flash_handle(void)
{
// LOGI("FMC_SPI_Flash_WritePage: op_flash.op_addr=%x\n",
// op_flash.op_addr);
GLOBAL_INT_DISABLE();
FMC_SPI_Flash_WritePage(op_flash.op_addr, op_flash.op_buff, 256);
GLOBAL_INT_RESTORE();
if(op_flash.op_addr == USER_DATA_FLASH_ADDR)
{
if(user_flash_chunk_gap_ms != 0U)
{
user_flash_chunk_gap_ms--;
return;
}
uint32_t chunk_offset =
(uint32_t)user_flash_write_chunk * 16U;
Bridge_FlashBlank_Request();
if(Bridge_FlashBlank_Ready() == 0U)
return;
GLOBAL_INT_DISABLE();
FMC_SPI_Flash_Write16Bytes(
op_flash.op_addr + chunk_offset,
&op_flash.op_buff[chunk_offset]);
GLOBAL_INT_RESTORE();
Bridge_FlashBlank_Resume();
user_flash_write_chunk++;
if(user_flash_write_chunk < USER_FLASH_WRITE_CHUNKS) {
user_flash_chunk_gap_ms = USER_FLASH_CHUNK_GAP_MS;
return;
}
user_flash_write_chunk = 0U;
user_flash_chunk_gap_ms = 0U;
}
else
{
GLOBAL_INT_DISABLE();
FMC_SPI_Flash_WritePage(op_flash.op_addr, op_flash.op_buff, 256);
GLOBAL_INT_RESTORE();
}
op_flash.op_state = OP_IDEL;
app_op_flash_flag = 2;
@@ -83,9 +125,20 @@ void ble_flash_handle(void)
}
} else if (op_flash.op_state == OP_WIAT_PAGE_ERASE) {
{
if(op_flash.op_addr == USER_DATA_FLASH_ADDR) {
Bridge_FlashBlank_Request();
if(Bridge_FlashBlank_Ready() == 0U)
return;
}
GLOBAL_INT_DISABLE();
FMC_SPI_Flash_Erase_Page(op_flash.op_addr);
GLOBAL_INT_RESTORE();
if(op_flash.op_addr == USER_DATA_FLASH_ADDR) {
Bridge_FlashBlank_Resume();
user_flash_write_chunk = 0U;
user_flash_chunk_gap_ms = 0U;
}
op_flash.op_state = OP_IDEL;
app_op_flash_flag = 1;
}
@@ -98,15 +151,14 @@ uint8_t app_data[FLASH_PAGE_SIZE] = {0};
void app_op_flash(void)
{
if(op_flash.op_state == OP_IDEL&&app_op_flash_flag ==0)
{
ble_flash_later_page_erase(0x1E000);
}
else if(op_flash.op_state == OP_IDEL &&app_op_flash_flag ==1)
{
ble_flash_later_write_page(app_data,0x1E000);
}
if(op_flash.op_state == OP_IDEL && app_op_flash_flag == 0U)
{
ble_flash_later_page_erase(USER_DATA_FLASH_ADDR);
}
else if(op_flash.op_state == OP_IDEL && app_op_flash_flag == 1U)
{
ble_flash_later_write_page(app_data, USER_DATA_FLASH_ADDR);
}
}
extern uint8_t aa;
@@ -7,7 +7,9 @@
#endif // (USE_ROM_FLASH)
#endif // !(USE_XIP)
#include <stdint.h>
void xc_fmc_spi_flash_write_16bytes(uint32_t addr, uint8_t *data);
#define FMC_SPI_Flash_WritePage xc_fmc_spi_flash_write_page
#define FMC_SPI_Flash_Write16Bytes xc_fmc_spi_flash_write_16bytes
#define FMC_SPI_Flash_ReadPage xc_fmc_spi_flash_read_page
#define FMC_SPI_Flash_Erase_Sector FMC_SPI_Flash_Erase_Sector
#define FMC_SPI_Flash_Erase_Page xc_fmc_spi_flash_erase_page
@@ -42,5 +44,3 @@ int ble_flash_later_write_page(uint8_t *buff, uint32_t PageAddR);
int ble_flash_later_sector_erase(uint32_t addr);
#endif // __OTA_FLASH_INTERFACE_H_