Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 46e9db0796 | |||
| 7b0bf78309 | |||
| eab8e1cc98 | |||
| d119f8cceb | |||
| 550d0987ea | |||
| 1676f4b3ad | |||
| b2e642366c | |||
| ee4b458933 | |||
| 55a26d7b18 | |||
| 2200a04f05 |
@@ -340,6 +340,10 @@ __RAM_CODE static uint8_t xc_fmc_spi_flash_status(void)
|
|||||||
return sta[1];
|
return sta[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__RAM_CODE __WEAK void xc_fmc_spi_flash_busy_hook(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
****************************************************************************************
|
****************************************************************************************
|
||||||
* @brief xc_fmc_spi_flash_wait_busy
|
* @brief xc_fmc_spi_flash_wait_busy
|
||||||
@@ -354,8 +358,14 @@ __RAM_CODE static uint8_t xc_fmc_spi_flash_status(void)
|
|||||||
*/
|
*/
|
||||||
__RAM_CODE static void xc_fmc_spi_flash_wait_busy(void)
|
__RAM_CODE static void xc_fmc_spi_flash_wait_busy(void)
|
||||||
{
|
{
|
||||||
while ((xc_fmc_spi_flash_status() & PUYA_FLASH_STATUS_WIP_SET))
|
for (;;) {
|
||||||
;
|
xc_fmc_spi_flash_busy_hook();
|
||||||
|
if ((xc_fmc_spi_flash_status() &
|
||||||
|
PUYA_FLASH_STATUS_WIP_SET) == 0U)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xc_fmc_spi_flash_busy_hook();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -472,6 +482,30 @@ __RAM_CODE void xc_fmc_spi_flash_erase_page(uint32_t addr)
|
|||||||
* @retval void
|
* @retval void
|
||||||
****************************************************************************************
|
****************************************************************************************
|
||||||
*/
|
*/
|
||||||
|
__RAM_CODE void xc_fmc_spi_flash_write_16bytes(uint32_t addr, uint8_t *data)
|
||||||
|
{
|
||||||
|
uint8_t cmd[16 + 4] = {0};
|
||||||
|
|
||||||
|
xc_fmc_spi_flash_wait_busy();
|
||||||
|
xc_fmc_spi_flash_write_enable();
|
||||||
|
xc_fmc_spi_flash_wait_busy();
|
||||||
|
|
||||||
|
cmd[0] = CMD_PAGE_PROGRAM;
|
||||||
|
cmd[1] = addr >> 16;
|
||||||
|
cmd[2] = addr >> 8;
|
||||||
|
cmd[3] = addr;
|
||||||
|
|
||||||
|
ram_memcpy_bytes(&cmd[4], data, 16);
|
||||||
|
|
||||||
|
xc_fmc_status_wait_idle();
|
||||||
|
|
||||||
|
xc_fmc_spi_enable(FMC_SSI_CTRL0_DFS_LEN_32BIT);
|
||||||
|
xc_fmc_spi_write_nbyte(cmd, sizeof(cmd));
|
||||||
|
|
||||||
|
xc_fmc_spi_flash_wait_busy();
|
||||||
|
xc_fmc_spi_disable();
|
||||||
|
}
|
||||||
|
|
||||||
__RAM_CODE void xc_fmc_spi_flash_write_page(uint32_t addr, uint8_t *data,
|
__RAM_CODE void xc_fmc_spi_flash_write_page(uint32_t addr, uint8_t *data,
|
||||||
uint16_t size)
|
uint16_t size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ void xc_fmc_spi_flash_wait_busy(void);
|
|||||||
void xc_fmc_spi_flash_write_enable(void);
|
void xc_fmc_spi_flash_write_enable(void);
|
||||||
void xc_fmc_spi_flash_erase_sector(uint32_t addr);
|
void xc_fmc_spi_flash_erase_sector(uint32_t addr);
|
||||||
void xc_fmc_spi_flash_erase_page(uint32_t addr);
|
void xc_fmc_spi_flash_erase_page(uint32_t addr);
|
||||||
|
void xc_fmc_spi_flash_write_16bytes(uint32_t addr, uint8_t *data);
|
||||||
void xc_fmc_spi_flash_write_page(uint32_t addr, uint8_t *buff,
|
void xc_fmc_spi_flash_write_page(uint32_t addr, uint8_t *buff,
|
||||||
uint16_t size);
|
uint16_t size);
|
||||||
void xc_fmc_spi_flash_read_page(uint32_t addr, uint8_t *buff,
|
void xc_fmc_spi_flash_read_page(uint32_t addr, uint8_t *buff,
|
||||||
|
|||||||
@@ -121,6 +121,17 @@ void set_mode(){
|
|||||||
{
|
{
|
||||||
Light_Transition_BeginModeChange();
|
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
|
else
|
||||||
{
|
{
|
||||||
Light_Transition_ModeActive=0U;
|
Light_Transition_ModeActive=0U;
|
||||||
|
|||||||
@@ -147,6 +147,9 @@ void Bridge_Init(void);
|
|||||||
void Bridge_Off(void);
|
void Bridge_Off(void);
|
||||||
void Bridge_Service_1ms(void);
|
void Bridge_Service_1ms(void);
|
||||||
void Bridge_Deadtime_Expired(void);
|
void Bridge_Deadtime_Expired(void);
|
||||||
|
void Bridge_FlashBlank_Request(void);
|
||||||
|
uint8_t Bridge_FlashBlank_Ready(void);
|
||||||
|
void Bridge_FlashBlank_Resume(void);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "light_transition.h"
|
#include "light_transition.h"
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "rf433_decoder.h"
|
#include "rf433_decoder.h"
|
||||||
|
#include "timeslice.h"
|
||||||
union rf433_flag rf_flag = {0};
|
union rf433_flag rf_flag = {0};
|
||||||
unsigned char high_level_time;
|
unsigned char high_level_time;
|
||||||
unsigned char low_level_time;
|
unsigned char low_level_time;
|
||||||
@@ -17,6 +18,8 @@ uint32_t receive_data;
|
|||||||
|
|
||||||
|
|
||||||
uint8_t res_data=255; //433返回的最后一个控制字节(低八位)
|
uint8_t res_data=255; //433返回的最后一个控制字节(低八位)
|
||||||
|
static uint16_t long_time=0; //表示长按短按 该值一定要大与68,68是指68ms通过逻辑分析仪测量一帧433的时间
|
||||||
|
static uint16_t time_300ms=1; //表示:当长按的时候要300ms执行一次
|
||||||
static uint8_t POWER_flag;
|
static uint8_t POWER_flag;
|
||||||
|
|
||||||
uint32_t flag_1h =0;
|
uint32_t flag_1h =0;
|
||||||
@@ -97,19 +100,10 @@ static uint8_t pair_command_replay;
|
|||||||
#define PAIR_HOLD_FRAME_COUNT 4U
|
#define PAIR_HOLD_FRAME_COUNT 4U
|
||||||
#define PAIR_FRAME_SILENCE_TICKS 100U
|
#define PAIR_FRAME_SILENCE_TICKS 100U
|
||||||
#define PAIRING_WINDOW_TICKS 50000UL
|
#define PAIRING_WINDOW_TICKS 50000UL
|
||||||
|
#define RF433_RELEASE_TIMEOUT_TICKS 1500U
|
||||||
#define RF433_MS_TO_SAMPLE_TICKS(ms) ((uint16_t)((ms) * (1000U / RF433_DECODER_SAMPLE_US)))
|
#define RF433_MS_TO_SAMPLE_TICKS(ms) ((uint16_t)((ms) * (1000U / RF433_DECODER_SAMPLE_US)))
|
||||||
#define RF433_HOLD_GAP_TICKS ((uint32_t)RF433_MS_TO_SAMPLE_TICKS(250U))
|
|
||||||
#define RF433_REPEAT_TICKS ((uint32_t)RF433_MS_TO_SAMPLE_TICKS(500U))
|
|
||||||
uint8_t long_flag_s=0;
|
uint8_t long_flag_s=0;
|
||||||
|
|
||||||
static volatile uint32_t rf_sample_ticks;
|
|
||||||
static uint16_t rf_dispatch_sequence;
|
|
||||||
static uint32_t rf_hold_code;
|
|
||||||
static uint32_t rf_hold_last_frame_tick;
|
|
||||||
static uint32_t rf_hold_next_repeat_tick;
|
|
||||||
static uint8_t rf_hold_key;
|
|
||||||
static uint8_t rf_hold_active;
|
|
||||||
|
|
||||||
void _433_fun(void);
|
void _433_fun(void);
|
||||||
|
|
||||||
// Keep paired addresses ordered from oldest to newest.
|
// Keep paired addresses ordered from oldest to newest.
|
||||||
@@ -378,6 +372,7 @@ static void Rf433_Decoder_Frame_Poll(void)
|
|||||||
res_data = frame.key;
|
res_data = frame.key;
|
||||||
rf_frame_sequence++;
|
rf_frame_sequence++;
|
||||||
rf_flag.rf_receive_flag.receive_finish = 1U;
|
rf_flag.rf_receive_flag.receive_finish = 1U;
|
||||||
|
long_time = RF433_RELEASE_TIMEOUT_TICKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Encoder_key(){
|
void Encoder_key(){
|
||||||
@@ -387,11 +382,54 @@ void Encoder_key(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t KEY_STATE_Click; // 单击
|
||||||
|
uint32_t KEY_STATE_LONG_PRESS; // 长按
|
||||||
|
} _Key_TypeDef;
|
||||||
|
_Key_TypeDef Key_TypeDef={0,0};
|
||||||
|
uint32_t KEY_STATE_re=0; // 长按
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//该函数选择那个按键为单击,哪个为长按按键
|
||||||
|
static void set_click(){
|
||||||
|
if(res_data==Mode_add||res_data==Mode_dow||res_data==F_ON_OFF||res_data==F_Mode_choose||res_data==ON||res_data==OFF){
|
||||||
|
Key_TypeDef.KEY_STATE_Click=1; //单击
|
||||||
|
}else{
|
||||||
|
Key_TypeDef.KEY_STATE_LONG_PRESS=1; //长按
|
||||||
|
KEY_STATE_re=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void rf433_receive(void)//RF433 sample, called every 100 us
|
void rf433_receive(void)//RF433 sample, called every 100 us
|
||||||
{
|
{
|
||||||
rf433_decoder_sample((RF_DATA == HIGH_LEVEL) ? 1U : 0U);
|
rf433_decoder_sample((RF_DATA == HIGH_LEVEL) ? 1U : 0U);
|
||||||
rf_sample_ticks++;
|
|
||||||
long_flag_s = 0U;
|
if(long_time > 0U)
|
||||||
|
{
|
||||||
|
long_time--;
|
||||||
|
long_flag_s = 0U;
|
||||||
|
if(KEY_STATE_re == 1U)
|
||||||
|
{
|
||||||
|
if(time_300ms == 0U)
|
||||||
|
{
|
||||||
|
time_300ms = RF433_MS_TO_SAMPLE_TICKS(Short_time);
|
||||||
|
long_flag_s = 1U;
|
||||||
|
KEY_STATE_re = 0U;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_300ms--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_300ms = RF433_MS_TO_SAMPLE_TICKS(LongPress_time);
|
||||||
|
long_flag_s = 0U;
|
||||||
|
Key_TypeDef.KEY_STATE_Click = 0U;
|
||||||
|
KEY_STATE_re = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
if(time_5s <= PAIRING_WINDOW_TICKS)
|
if(time_5s <= PAIRING_WINDOW_TICKS)
|
||||||
{
|
{
|
||||||
@@ -414,8 +452,8 @@ void _433_fun(){
|
|||||||
pair_deferred_receive_data = receive_data;
|
pair_deferred_receive_data = receive_data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(Key_TypeDef.KEY_STATE_Click==1||KEY_STATE_re==1) return;
|
||||||
sss=1;//记忆标志位
|
set_click();
|
||||||
switch(res_data){
|
switch(res_data){
|
||||||
//椭圆
|
//椭圆
|
||||||
case ON://单击
|
case ON://单击
|
||||||
@@ -496,91 +534,34 @@ void _433_fun(){
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
set_TaskComps_timer(2U, 1000U);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//3748
|
//3748
|
||||||
static uint8_t Rf433_Address_Matched(uint32_t code)
|
|
||||||
{
|
|
||||||
uint8_t high = (uint8_t)((code >> 16) & 0xffU);
|
|
||||||
uint8_t low = (uint8_t)((code >> 8) & 0xffU);
|
|
||||||
uint8_t i;
|
|
||||||
|
|
||||||
if(match_success == 0U) return 1U;
|
|
||||||
|
|
||||||
for(i = 0U; i < 5U; i++)
|
|
||||||
{
|
|
||||||
if(adress_H_array[i] == high && adress_L_array[i] == low)
|
|
||||||
return 1U;
|
|
||||||
}
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t Rf433_Time_Reached(uint32_t now, uint32_t deadline)
|
|
||||||
{
|
|
||||||
return ((int32_t)(now - deadline) >= 0) ? 1U : 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Rf433_Run_Command(uint32_t code, uint8_t key)
|
|
||||||
{
|
|
||||||
receive_data = code;
|
|
||||||
res_data = key;
|
|
||||||
_433_fun();
|
|
||||||
}
|
|
||||||
|
|
||||||
void scan_433(){
|
void scan_433(){
|
||||||
uint32_t now = rf_sample_ticks;
|
|
||||||
|
if(power==0){
|
||||||
if(power != 0U) return;
|
if(rf_flag.rf_receive_flag.receive_finish==1){
|
||||||
|
if(match_success==1){
|
||||||
if(rf_hold_active &&
|
if((adress_H_array[0]==((receive_data >> 16) & 0xff)&&adress_L_array[0]==((receive_data >> 8) & 0xff))||
|
||||||
(uint32_t)(now - rf_hold_last_frame_tick) > RF433_HOLD_GAP_TICKS)
|
(adress_H_array[1]==((receive_data >> 16) & 0xff)&&adress_L_array[1]==((receive_data >> 8) & 0xff))||
|
||||||
{
|
(adress_H_array[2]==((receive_data >> 16) & 0xff)&&adress_L_array[2]==((receive_data >> 8) & 0xff))||
|
||||||
rf_hold_active = 0U;
|
(adress_H_array[3]==((receive_data >> 16) & 0xff)&&adress_L_array[3]==((receive_data >> 8) & 0xff))||
|
||||||
}
|
(adress_H_array[4]==((receive_data >> 16) & 0xff)&&adress_L_array[4]==((receive_data >> 8) & 0xff))
|
||||||
|
){
|
||||||
if(rf_dispatch_sequence != rf_frame_sequence)
|
_433_fun();
|
||||||
{
|
}
|
||||||
uint32_t code = receive_data;
|
}else if(match_success==0){
|
||||||
uint8_t key = res_data;
|
_433_fun();
|
||||||
uint32_t frame_gap = (uint32_t)(now - rf_hold_last_frame_tick);
|
}
|
||||||
|
}
|
||||||
rf_dispatch_sequence = rf_frame_sequence;
|
rf_flag.rf_receive_flag.receive_finish=0;
|
||||||
rf_flag.rf_receive_flag.receive_finish = 0U;
|
}
|
||||||
|
|
||||||
if(!Rf433_Address_Matched(code))
|
|
||||||
{
|
|
||||||
rf_hold_active = 0U;
|
|
||||||
}
|
|
||||||
else if(key >= 16U)
|
|
||||||
{
|
|
||||||
/* Color-ring frames stay unthrottled for smooth sliding. */
|
|
||||||
rf_hold_active = 0U;
|
|
||||||
Rf433_Run_Command(code, key);
|
|
||||||
}
|
|
||||||
else if(!rf_hold_active || rf_hold_code != code ||
|
|
||||||
frame_gap > RF433_HOLD_GAP_TICKS)
|
|
||||||
{
|
|
||||||
/* The first valid frame is an immediate short-press action. */
|
|
||||||
rf_hold_active = 1U;
|
|
||||||
rf_hold_code = code;
|
|
||||||
rf_hold_key = key;
|
|
||||||
rf_hold_last_frame_tick = now;
|
|
||||||
rf_hold_next_repeat_tick = now + RF433_REPEAT_TICKS;
|
|
||||||
Rf433_Run_Command(code, key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rf_hold_last_frame_tick = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rf_hold_active &&
|
|
||||||
(uint32_t)(now - rf_hold_last_frame_tick) <= RF433_HOLD_GAP_TICKS &&
|
|
||||||
Rf433_Time_Reached(now, rf_hold_next_repeat_tick))
|
|
||||||
{
|
|
||||||
Rf433_Run_Command(rf_hold_code, rf_hold_key);
|
|
||||||
rf_hold_next_repeat_tick = now + RF433_REPEAT_TICKS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,14 @@
|
|||||||
#define BRIDGE_STAGE_START_C 4U
|
#define BRIDGE_STAGE_START_C 4U
|
||||||
#define BRIDGE_STAGE_END_C 5U
|
#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 active_state;
|
||||||
static volatile uint8_t output_mode;
|
static volatile uint8_t output_mode;
|
||||||
static volatile uint8_t timer_stage;
|
static volatile uint8_t timer_stage;
|
||||||
|
static volatile uint8_t flash_blank_state;
|
||||||
static volatile uint8_t pending_single_state;
|
static volatile uint8_t pending_single_state;
|
||||||
static volatile uint16_t pending_single_duty;
|
static volatile uint16_t pending_single_duty;
|
||||||
static volatile uint16_t frame_w_us;
|
static volatile uint16_t frame_w_us;
|
||||||
@@ -212,6 +217,7 @@ void Bridge_Init(void)
|
|||||||
NVIC_SetPriority((IRQn_Type)TIMER3_IRQn, 0);
|
NVIC_SetPriority((IRQn_Type)TIMER3_IRQn, 0);
|
||||||
NVIC_EnableIRQ(TIMER3_IRQn);
|
NVIC_EnableIRQ(TIMER3_IRQn);
|
||||||
|
|
||||||
|
flash_blank_state = BRIDGE_FLASH_BLANK_IDLE;
|
||||||
bridge_ready = 1U;
|
bridge_ready = 1U;
|
||||||
Bridge_Off();
|
Bridge_Off();
|
||||||
}
|
}
|
||||||
@@ -244,6 +250,57 @@ void Bridge_Off(void)
|
|||||||
cached_c_mix = 0xFFFFU;
|
cached_c_mix = 0xFFFFU;
|
||||||
bridge_force_off();
|
bridge_force_off();
|
||||||
output_mode = BRIDGE_MODE_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)
|
__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 (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
|
* Latch all four durations together at the W boundary. A brightness
|
||||||
* update can then never mix old and new timings inside one frame.
|
* 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;
|
uint16_t pwm_duty;
|
||||||
uint8_t single_state;
|
uint8_t single_state;
|
||||||
|
|
||||||
|
if (flash_blank_state != BRIDGE_FLASH_BLANK_IDLE)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!bridge_ready ||
|
if (!bridge_ready ||
|
||||||
(deviceStatus == POWEROFF && !Light_Transition_FadeActive)) {
|
(deviceStatus == POWEROFF && !Light_Transition_FadeActive)) {
|
||||||
if (output_mode != BRIDGE_MODE_OFF || timer_stage != BRIDGE_STAGE_IDLE) {
|
if (output_mode != BRIDGE_MODE_OFF || timer_stage != BRIDGE_STAGE_IDLE) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "PWM.h"
|
#include "PWM.h"
|
||||||
#include "RF433.h"
|
#include "RF433.h"
|
||||||
#include "xc60xx.h"
|
#include "xc60xx.h"
|
||||||
|
#include "timeslice.h"
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------------
|
||||||
Macros
|
Macros
|
||||||
@@ -77,9 +78,11 @@ unsigned char get_checksum(unsigned char *ptrdata, unsigned char length)
|
|||||||
#define FLASH_POWER_MODE_INDEX 28U
|
#define FLASH_POWER_MODE_INDEX 28U
|
||||||
#define FLASH_POWER_CYCLE_INDEX 29U
|
#define FLASH_POWER_CYCLE_INDEX 29U
|
||||||
#define FLASH_POWER_MODE_MARK 0xA7U
|
#define FLASH_POWER_MODE_MARK 0xA7U
|
||||||
|
#define POWER_POLICY_SAVE_DELAY_MS 100U
|
||||||
|
#define USER_DATA_FLASH_ADDR 0x1E000UL
|
||||||
|
|
||||||
uint8_t power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
uint8_t power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
||||||
static uint8_t power_cycle_next_color;
|
static uint8_t power_cycle_next_mode;
|
||||||
|
|
||||||
void read_user_data(void)
|
void read_user_data(void)
|
||||||
{
|
{
|
||||||
@@ -153,14 +156,14 @@ void read_user_data(void)
|
|||||||
power_restore_policy = r_data[FLASH_POWER_MODE_INDEX];
|
power_restore_policy = r_data[FLASH_POWER_MODE_INDEX];
|
||||||
if(power_restore_policy > POWER_RESTORE_CYCLE_STATIC)
|
if(power_restore_policy > POWER_RESTORE_CYCLE_STATIC)
|
||||||
power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
||||||
power_cycle_next_color = r_data[FLASH_POWER_CYCLE_INDEX];
|
power_cycle_next_mode = r_data[FLASH_POWER_CYCLE_INDEX];
|
||||||
if(power_cycle_next_color > 2U)
|
if(power_cycle_next_mode > 2U)
|
||||||
power_cycle_next_color = 0U;
|
power_cycle_next_mode = 0U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
power_restore_policy = POWER_RESTORE_CYCLE_STATIC;
|
||||||
power_cycle_next_color = 0U;
|
power_cycle_next_mode = 0U;
|
||||||
}
|
}
|
||||||
//choose_mode_bh=r_data[31];
|
//choose_mode_bh=r_data[31];
|
||||||
driveMode=r_data[32];
|
driveMode=r_data[32];
|
||||||
@@ -210,7 +213,7 @@ void wright_user_data(void)
|
|||||||
app_data[FLASH_MODE_LAYOUT_INDEX]=FLASH_MODE_LAYOUT_MARK;
|
app_data[FLASH_MODE_LAYOUT_INDEX]=FLASH_MODE_LAYOUT_MARK;
|
||||||
app_data[FLASH_POWER_MODE_MARK_INDEX]=FLASH_POWER_MODE_MARK;
|
app_data[FLASH_POWER_MODE_MARK_INDEX]=FLASH_POWER_MODE_MARK;
|
||||||
app_data[FLASH_POWER_MODE_INDEX]=power_restore_policy;
|
app_data[FLASH_POWER_MODE_INDEX]=power_restore_policy;
|
||||||
app_data[FLASH_POWER_CYCLE_INDEX]=power_cycle_next_color;
|
app_data[FLASH_POWER_CYCLE_INDEX]=power_cycle_next_mode;
|
||||||
app_data[30]=choose_mode_falsg;
|
app_data[30]=choose_mode_falsg;
|
||||||
app_data[31]=choose_mode_bh;
|
app_data[31]=choose_mode_bh;
|
||||||
app_data[32]=driveMode;
|
app_data[32]=driveMode;
|
||||||
@@ -240,33 +243,37 @@ void power_restore_policy_set(uint8_t policy)
|
|||||||
{
|
{
|
||||||
if(policy > POWER_RESTORE_CYCLE_STATIC) return;
|
if(policy > POWER_RESTORE_CYCLE_STATIC) return;
|
||||||
|
|
||||||
|
if(policy == POWER_RESTORE_CYCLE_STATIC &&
|
||||||
|
power_restore_policy != POWER_RESTORE_CYCLE_STATIC)
|
||||||
|
power_cycle_next_mode = 0U;
|
||||||
|
|
||||||
|
if(policy == power_restore_policy) return;
|
||||||
|
|
||||||
power_restore_policy = policy;
|
power_restore_policy = policy;
|
||||||
if(policy == POWER_RESTORE_CYCLE_STATIC)
|
set_TaskComps_timer(2U, POWER_POLICY_SAVE_DELAY_MS);
|
||||||
power_cycle_next_color = 0U;
|
|
||||||
sss = 1U;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void power_restore_apply_on_boot(void)
|
void power_restore_apply_on_boot(void)
|
||||||
{
|
{
|
||||||
uint8_t color;
|
uint8_t mode_index;
|
||||||
|
|
||||||
if(power_restore_policy != POWER_RESTORE_CYCLE_STATIC) return;
|
if(power_restore_policy != POWER_RESTORE_CYCLE_STATIC) return;
|
||||||
|
|
||||||
color = power_cycle_next_color;
|
mode_index = power_cycle_next_mode;
|
||||||
if(color > 2U) color = 0U;
|
if(mode_index > 2U) mode_index = 0U;
|
||||||
|
|
||||||
deviceStatus = POWERON;
|
deviceStatus = POWERON;
|
||||||
Mode = mode0;
|
Mode = mode0;
|
||||||
choose_mode_falsg = color;
|
choose_mode_falsg = mode_index;
|
||||||
choose_mode_bh = 0U;
|
choose_mode_bh = 0U;
|
||||||
|
|
||||||
if(color == 0U)
|
if(mode_index == 0U)
|
||||||
{
|
{
|
||||||
W_PWM = 100U;
|
W_PWM = 100U;
|
||||||
C_PWM = 0U;
|
C_PWM = 0U;
|
||||||
driveMode = 1U;
|
driveMode = 1U;
|
||||||
}
|
}
|
||||||
else if(color == 1U)
|
else if(mode_index == 1U)
|
||||||
{
|
{
|
||||||
W_PWM = 0U;
|
W_PWM = 0U;
|
||||||
C_PWM = 100U;
|
C_PWM = 100U;
|
||||||
@@ -279,6 +286,17 @@ void power_restore_apply_on_boot(void)
|
|||||||
driveMode = 0U;
|
driveMode = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
power_cycle_next_color = (uint8_t)((color + 1U) % 3U);
|
power_cycle_next_mode = (uint8_t)((mode_index + 1U) % 3U);
|
||||||
sss = 1U;
|
|
||||||
|
/*
|
||||||
|
* Save the next startup mode before timers, BLE and the H-bridge start.
|
||||||
|
* A deferred flash erase/write masks interrupts long enough to stretch
|
||||||
|
* one Timer3-controlled dual-color pulse and causes a visible flash.
|
||||||
|
*/
|
||||||
|
wright_user_data();
|
||||||
|
GLOBAL_INT_DISABLE();
|
||||||
|
xc_fmc_spi_flash_erase_page(USER_DATA_FLASH_ADDR);
|
||||||
|
xc_fmc_spi_flash_write_page(USER_DATA_FLASH_ADDR,
|
||||||
|
app_data, FLASH_PAGE_SIZE);
|
||||||
|
GLOBAL_INT_RESTORE();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,14 @@
|
|||||||
// extern uint8_t ble_flash_operation_can_check(void);
|
// extern uint8_t ble_flash_operation_can_check(void);
|
||||||
#include "ota_protocol.h"
|
#include "ota_protocol.h"
|
||||||
#include "fmc_spi.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_flash_t op_flash = {
|
||||||
OP_IDEL,
|
OP_IDEL,
|
||||||
};
|
};
|
||||||
@@ -62,9 +70,43 @@ void ble_flash_handle(void)
|
|||||||
{
|
{
|
||||||
// LOGI("FMC_SPI_Flash_WritePage: op_flash.op_addr=%x\n",
|
// LOGI("FMC_SPI_Flash_WritePage: op_flash.op_addr=%x\n",
|
||||||
// op_flash.op_addr);
|
// op_flash.op_addr);
|
||||||
GLOBAL_INT_DISABLE();
|
if(op_flash.op_addr == USER_DATA_FLASH_ADDR)
|
||||||
FMC_SPI_Flash_WritePage(op_flash.op_addr, op_flash.op_buff, 256);
|
{
|
||||||
GLOBAL_INT_RESTORE();
|
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;
|
op_flash.op_state = OP_IDEL;
|
||||||
|
|
||||||
app_op_flash_flag = 2;
|
app_op_flash_flag = 2;
|
||||||
@@ -83,30 +125,40 @@ void ble_flash_handle(void)
|
|||||||
}
|
}
|
||||||
} else if (op_flash.op_state == OP_WIAT_PAGE_ERASE) {
|
} 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();
|
GLOBAL_INT_DISABLE();
|
||||||
FMC_SPI_Flash_Erase_Page(op_flash.op_addr);
|
FMC_SPI_Flash_Erase_Page(op_flash.op_addr);
|
||||||
GLOBAL_INT_RESTORE();
|
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;
|
op_flash.op_state = OP_IDEL;
|
||||||
app_op_flash_flag = 1;
|
app_op_flash_flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t app_data[128] = {0};
|
uint8_t app_data[FLASH_PAGE_SIZE] = {0};
|
||||||
|
|
||||||
//uint16_t app_op_flash_start = 10000;
|
//uint16_t app_op_flash_start = 10000;
|
||||||
void app_op_flash(void)
|
void app_op_flash(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(op_flash.op_state == OP_IDEL&&app_op_flash_flag ==0)
|
if(op_flash.op_state == OP_IDEL && app_op_flash_flag == 0U)
|
||||||
{
|
{
|
||||||
ble_flash_later_page_erase(0x1E000);
|
ble_flash_later_page_erase(USER_DATA_FLASH_ADDR);
|
||||||
}
|
}
|
||||||
else if(op_flash.op_state == OP_IDEL &&app_op_flash_flag ==1)
|
else if(op_flash.op_state == OP_IDEL && app_op_flash_flag == 1U)
|
||||||
{
|
{
|
||||||
ble_flash_later_write_page(app_data,0x1E000);
|
ble_flash_later_write_page(app_data, USER_DATA_FLASH_ADDR);
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint8_t aa;
|
extern uint8_t aa;
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#endif // (USE_ROM_FLASH)
|
#endif // (USE_ROM_FLASH)
|
||||||
#endif // !(USE_XIP)
|
#endif // !(USE_XIP)
|
||||||
#include <stdint.h>
|
#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_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_ReadPage xc_fmc_spi_flash_read_page
|
||||||
#define FMC_SPI_Flash_Erase_Sector FMC_SPI_Flash_Erase_Sector
|
#define FMC_SPI_Flash_Erase_Sector FMC_SPI_Flash_Erase_Sector
|
||||||
#define FMC_SPI_Flash_Erase_Page xc_fmc_spi_flash_erase_page
|
#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);
|
int ble_flash_later_sector_erase(uint32_t addr);
|
||||||
|
|
||||||
#endif // __OTA_FLASH_INTERFACE_H_
|
#endif // __OTA_FLASH_INTERFACE_H_
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ TASK_COMPONENTS TaskComps[] =
|
|||||||
{0,1,1,choice_mode},
|
{0,1,1,choice_mode},
|
||||||
{0,5,5,set_mode},
|
{0,5,5,set_mode},
|
||||||
{0,1,1,Set_timing},
|
{0,1,1,Set_timing},
|
||||||
{0,10,10,scan_433},
|
{0,100,100,scan_433},
|
||||||
{0,3,3,Encoder_key},
|
{0, 100,3, Encoder_key},
|
||||||
{0,1,1,My_ADC_Get_Value},
|
{0,1,1,My_ADC_Get_Value},
|
||||||
{0,50,50,ble_state_sync_poll},
|
{0,50,50,ble_state_sync_poll},
|
||||||
{0, 311, 1, app_op_flash}, //用户数据持久化 fmc_spi_read9
|
{0, 311, 1, app_op_flash}, //用户数据持久化 fmc_spi_read9
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ void uart_receive_cb(uint8_t *buff, uint16_t len)
|
|||||||
void scan_uar_data(uint8_t *frame){
|
void scan_uar_data(uint8_t *frame){
|
||||||
|
|
||||||
}
|
}
|
||||||
extern uint8_t sss;
|
|
||||||
uint8_t rx_date;
|
uint8_t rx_date;
|
||||||
void scan_uart(uint8_t *arr)
|
void scan_uart(uint8_t *arr)
|
||||||
{
|
{
|
||||||
@@ -106,8 +105,7 @@ void scan_uart(uint8_t *arr)
|
|||||||
checksum += user_rx_buf[i];
|
checksum += user_rx_buf[i];
|
||||||
}
|
}
|
||||||
user_rx_buf[5] = checksum; // 校验位
|
user_rx_buf[5] = checksum; // 校验位
|
||||||
sss=1;
|
set_TaskComps_timer(2U, 1000U);
|
||||||
// printf("sss=%d\r\n",sss);
|
|
||||||
switch (user_rx_buf[4])
|
switch (user_rx_buf[4])
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -135,11 +133,13 @@ void scan_uart(uint8_t *arr)
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if(POWEROFF==deviceStatus)break;
|
if(POWEROFF==deviceStatus)break;
|
||||||
if(user_rx_buf[1] < BRIGHTNESS_MIN_PERCENT)
|
if(Mode==mode0){
|
||||||
user_rx_buf[1] = BRIGHTNESS_MIN_PERCENT;
|
if(user_rx_buf[1] < BRIGHTNESS_MIN_PERCENT)
|
||||||
else if(user_rx_buf[1] > BRIGHTNESS_MAX_PERCENT)
|
user_rx_buf[1] = BRIGHTNESS_MIN_PERCENT;
|
||||||
user_rx_buf[1] = BRIGHTNESS_MAX_PERCENT;
|
else if(user_rx_buf[1] > BRIGHTNESS_MAX_PERCENT)
|
||||||
Brightness = user_rx_buf[1];
|
user_rx_buf[1] = BRIGHTNESS_MAX_PERCENT;
|
||||||
|
Brightness = user_rx_buf[1];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if(POWEROFF==deviceStatus)break;
|
if(POWEROFF==deviceStatus)break;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
LOAD 0x1100E000
|
LOAD 0x1100E000
|
||||||
{
|
{
|
||||||
EXE 0x1100E000
|
EXE 0x1100E000
|
||||||
{
|
{
|
||||||
startup_xinc.o (RESET, +FIRST)
|
startup_xinc.o (RESET, +FIRST)
|
||||||
* (+RO)
|
* (+RO)
|
||||||
|
|||||||
Reference in New Issue
Block a user