diff --git a/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/audiohw.xc b/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/audiohw.xc index 972d1ee..2ab82c2 100644 --- a/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/audiohw.xc +++ b/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/audiohw.xc @@ -83,11 +83,12 @@ unsigned g_update_led = 0x0; // CODEC I2C lines on tile[0]: port p_scl = PORT_I2C_SCL; on tile[0]: port p_sda = PORT_I2C_SDA; -on tile[0]: in port p_button = XS1_PORT_8D; //bit 4: mode button, bit 5: volume down button, bit 6: mic mute button, bit 7: volume up button +// 改动原因:硬件上 mic mute 与 mode 按键对调,bit4=mic mute、bit6=mode(与 C1_KEY_*_MASK 一致)。 +on tile[0]: in port p_button = XS1_PORT_8D; //bit 4: mic mute button, bit 5: volume down button, bit 6: mode button, bit 7: volume up button -on tile[1]: out port p_mode_led_red = XS1_PORT_1F; -on tile[1]: out port p_leds = XS1_PORT_4D; //bit 0: mode led green, bit 1: mode led blue, bit 2: mic mute led red, bit 3: mic mute led green -on tile[1]: out port p_mic_mute_led_blue = XS1_PORT_1G; +on tile[1]: out port p_mic_mute_led_red = XS1_PORT_1F; +on tile[1]: out port p_leds = XS1_PORT_4D; //bit 0: mic mute led green, bit 1: mic mute led blue, bit 2: mode led red, bit 3: mode led green +on tile[1]: out port p_mode_led_blue = XS1_PORT_1G; timer tm; #define SE_DELAY (2000000000) //20s delay @@ -99,9 +100,9 @@ timer tm; #define EQ_SYNC_DELAY (50000000) //500ms delay for EQ parameter sync // 改动原因:C1四个实体按键全部接在XS1_PORT_8D的bit4-bit7,统一定义位掩码,避免在按键状态机中直接使用魔数。 -#define C1_KEY_MODE_MASK 0x10 +#define C1_KEY_MODE_MASK 0x40 #define C1_KEY_VOL_DOWN_MASK 0x20 -#define C1_KEY_MIC_MUTE_MASK 0x40 +#define C1_KEY_MIC_MUTE_MASK 0x10 #define C1_KEY_VOL_UP_MASK 0x80 // 改动原因:g_dac_vol在C1中按NAU88C22 DAC音量寄存器值保存,限制在现有dac_volume注释对应的-66dB~0dB范围内。 @@ -1968,16 +1969,16 @@ void send_eq_data(uint8_t data[]) } } -// 改动原因:tile1 上电瞬间尚未收到 tile0 的 mode/mic,先把 mode 红脚与 PORT_4D 各 bit 拉到熄灭电平(低有效灯:输出 1 为灭),与 apply 中无混色时 mode 红通道熄灭写法一致。 +// 改动原因:硬件 mic/mode RGB 对调后,上电先把 mic 红脚(p_mic_mute_led_red)、mode 蓝脚(p_mode_led_blue) 与 PORT_4D 各 bit 拉到熄灭电平(低有效灯:输出 1 为灭)。 static inline void c1_panel_leds_force_all_off_hw(void) { - p_mode_led_red <: 1; + p_mic_mute_led_red <: 1; p_leds <: 0xF; - p_mic_mute_led_blue <: 1; + p_mode_led_blue <: 1; } -// 改动原因:c1_mode 与灯索引一致:1=灯 2=蓝 3=绿 4=橙(R+G) 5=紫(R+B);仅驱动 mode 区(p_mode_led_red + p_leds bit0/1),不受 mic 变声影响。 -// 改动原因:mic 区灯优先级:静音=只亮红灯(覆盖变声/DNR);非静音时变声=橙(R+G),DNR=蓝(p_mic_mute_led_blue), +// 改动原因:c1_mode 与灯索引一致:1=灯 2=蓝 3=绿 4=橙(R+G) 5=紫(R+B);仅驱动 mode 区(p_leds bit2/3 + p_mode_led_blue),不受 mic 变声影响。 +// 改动原因:mic 区灯优先级:静音=只亮红灯(覆盖变声/DNR);非静音时变声=橙(p_mic_mute_led_red+R+bit0绿),DNR=蓝(p_leds bit1), // 两者同开=橙+蓝混合,两者均关=全灯。 static inline void apply_c1_panel_leds(unsigned mode_led_color_idx, unsigned mic_mute_switch, unsigned mic_voice_fx_on, unsigned mic_dnr_on, unsigned &led_shadow) { @@ -2021,16 +2022,16 @@ static inline void apply_c1_panel_leds(unsigned mode_led_color_idx, unsigned mic mode_blue = 0; } - // 改动原因:硬件LED为低电平点亮(1灯/0亮);低四位 bit0~3 分别为 mode绿、mode蓝、mic红、mic绿,统一刷新。 - // 改动原因:p_mic_mute_led_blue 由 mic_blue 驱动,DNR开且非静音时亮蓝灯(输出0=亮)。 - p_mode_led_red <: (mode_red ? 0 : 1); + // 改动原因:硬件 mic/mode RGB 对调后,低四位 bit0~3 分别为 mic mute绿、mic mute蓝、mode红、mode绿,统一刷新。 + // 改动原因:p_mic_mute_led_red 由 mic_red 驱动,静音/变声时亮红灯(输出0=亮);DNR 蓝灯改由 p_leds bit1 驱动。 + p_mic_mute_led_red <: (mic_red ? 0 : 1); led_shadow &= ~0xF; - led_shadow |= (mode_green ? 0x0 : 0x1); - led_shadow |= (mode_blue ? 0x0 : 0x2); - led_shadow |= (mic_red ? 0x0 : 0x4); - led_shadow |= (mic_green ? 0x0 : 0x8); + led_shadow |= (mic_green ? 0x0 : 0x1); + led_shadow |= (mic_blue ? 0x0 : 0x2); + led_shadow |= (mode_red ? 0x0 : 0x4); + led_shadow |= (mode_green ? 0x0 : 0x8); p_leds <: led_shadow; - p_mic_mute_led_blue <: (mic_blue ? 0 : 1); + p_mode_led_blue <: (mode_blue ? 0 : 1); } void app_control_slave(server interface c1_led_ctrl_if i_c1_led_ctrl) @@ -2039,9 +2040,9 @@ void app_control_slave(server interface c1_led_ctrl_if i_c1_led_ctrl) unsigned led_shadow = 0xF; unsigned mode_led_color_idx = 1; unsigned mic_mute_switch = 1; - // 改动原因:变声/美声开时仅 p_leds bit2/bit3 显橙,与 set_mode_led_color 下发的 mode 灯独立;此处状态与 tile0 set_mic_voice_fx 同步。 + // 改动原因:变声/美声开时 p_mic_mute_led_red + p_leds bit0 显橙,与 set_mode_led_color 下发的 mode 灯独立;此处状态与 tile0 set_mic_voice_fx 同步。 unsigned mic_voice_fx_on = 0; - // 改动原因:AI通话降噪DNR开时点亮p_mic_mute_led_blue蓝灯;与变声同时开时橙+蓝混合;静音优先在 apply 内部处理。 + // 改动原因:AI通话降噪DNR开时点亮 p_leds bit1 mic mute 蓝灯;与变声同时开时橙+蓝混合;静音优先在 apply 内部处理。 unsigned mic_dnr_on = 0; c1_panel_leds_force_all_off_hw(); diff --git a/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/user_main.h b/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/user_main.h index 59edb91..b71fbda 100644 --- a/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/user_main.h +++ b/sw_usb_audio/app_usb_aud_fosi_c1/src/extensions/user_main.h @@ -11,10 +11,10 @@ interface c1_led_ctrl_if { // 改动原因:与 c1_mode 同值下发 tile1:1=灭 2=蓝 3=绿 4=橙 5=紫(灯索引即 mode)。 void set_mode_led_color(unsigned color_idx); void set_mic_mute_state(unsigned mute_switch); // mute_switch: 0=静音(亮红), 1=非静音(灭红) - // 改动原因:麦克风键双击“变声/美声”仅改灯效时,在 tile1 点亮 p_leds 的 mic 区:非0=bit2 红 + bit3 绿(橙),0=仅按静音规则驱动 bit2、bit3 熄灭。 + // 改动原因:硬件 mic/mode RGB 对调后,变声/美声开时 tile1 点亮 mic 区:p_mic_mute_led_red 红 + p_leds bit0 绿(橙);关时仅按静音规则驱动 mic 区熄灭。 // 改动原因:参数名不能用 xC 保留字 on(on tile[:]: 语法),否则编译器在解析 interface 时报 parse error before "on"。 void set_mic_voice_fx(unsigned voice_fx_enabled); - // 改动原因:麦克风键长按1.5s切换AI通话降噪(DNR),开时点亮p_mic_mute_led_blue蓝灯; + // 改动原因:麦克风键长按1.5s切换AI通话降噪(DNR),开时点亮 p_leds bit1 mic mute 蓝灯; // 与变声同时开时橙+蓝混合;静音优先(静音时所有mic灯被红灯取代)。断电需保存。 void set_mic_dnr_state(unsigned dnr_enabled); }; diff --git a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/audiohw.xc b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/audiohw.xc index 9d4325c..35e2305 100644 --- a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/audiohw.xc +++ b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/audiohw.xc @@ -83,11 +83,12 @@ unsigned g_update_led = 0x0; // CODEC I2C lines on tile[0]: port p_scl = PORT_I2C_SCL; on tile[0]: port p_sda = PORT_I2C_SDA; -on tile[0]: in port p_button = XS1_PORT_8D; //bit 4: mode button, bit 5: volume down button, bit 6: mic mute button, bit 7: volume up button +// 改动原因:硬件上 mic mute 与 mode 按键对调,bit4=mic mute、bit6=mode(与 C1_KEY_*_MASK 一致)。 +on tile[0]: in port p_button = XS1_PORT_8D; //bit 4: mic mute button, bit 5: volume down button, bit 6: mode button, bit 7: volume up button -on tile[1]: out port p_mode_led_red = XS1_PORT_1F; -on tile[1]: out port p_leds = XS1_PORT_4D; //bit 0: mode led green, bit 1: mode led blue, bit 2: mic mute led red, bit 3: mic mute led green -on tile[1]: out port p_mic_mute_led_blue = XS1_PORT_1G; +on tile[1]: out port p_mic_mute_led_red = XS1_PORT_1F; +on tile[1]: out port p_leds = XS1_PORT_4D; //bit 0: mic mute led green, bit 1: mic mute led blue, bit 2: mode led red, bit 3: mode led green +on tile[1]: out port p_mode_led_blue = XS1_PORT_1G; timer tm; #define SE_DELAY (2000000000) //20s delay @@ -99,9 +100,10 @@ timer tm; #define EQ_SYNC_DELAY (50000000) //500ms delay for EQ parameter sync // 改动原因:C1四个实体按键全部接在XS1_PORT_8D的bit4-bit7,统一定义位掩码,避免在按键状态机中直接使用魔数。 -#define C1_KEY_MODE_MASK 0x10 +// 改动原因:硬件 mic mute 与 mode 按键对调,掩码与 bit4/bit6 接线一致。 +#define C1_KEY_MODE_MASK 0x40 #define C1_KEY_VOL_DOWN_MASK 0x20 -#define C1_KEY_MIC_MUTE_MASK 0x40 +#define C1_KEY_MIC_MUTE_MASK 0x10 #define C1_KEY_VOL_UP_MASK 0x80 // 改动原因:g_dac_vol在C1中按NAU88C22 DAC音量寄存器值保存,限制在现有dac_volume注释对应的-66dB~0dB范围内。 @@ -1971,16 +1973,16 @@ void send_eq_data(uint8_t data[]) } } -// 改动原因:tile1 上电瞬间尚未收到 tile0 的 mode/mic,先把 mode 红脚与 PORT_4D 各 bit 拉到熄灭电平(低有效灯:输出 1 为灭),与 apply 中无混色时 mode 红通道熄灭写法一致。 +// 改动原因:硬件 mic/mode RGB 对调后,上电先把 mic 红脚(p_mic_mute_led_red)、mode 蓝脚(p_mode_led_blue) 与 PORT_4D 各 bit 拉到熄灭电平(低有效灯:输出 1 为灭)。 static inline void c1_panel_leds_force_all_off_hw(void) { - p_mode_led_red <: 1; + p_mic_mute_led_red <: 1; p_leds <: 0xF; - p_mic_mute_led_blue <: 1; + p_mode_led_blue <: 1; } -// 改动原因:c1_mode 与灯索引一致:1=灯 2=蓝 3=绿 4=橙(R+G) 5=紫(R+B);仅驱动 mode 区(p_mode_led_red + p_leds bit0/1),不受 mic 变声影响。 -// 改动原因:mic 区灯优先级:静音=只亮红灯(覆盖变声/DNR);非静音时变声=橙(R+G),DNR=蓝(p_mic_mute_led_blue), +// 改动原因:c1_mode 与灯索引一致:1=灯 2=蓝 3=绿 4=橙(R+G) 5=紫(R+B);仅驱动 mode 区(p_leds bit2/3 + p_mode_led_blue),不受 mic 变声影响。 +// 改动原因:mic 区灯优先级:静音=只亮红灯(覆盖变声/DNR);非静音时变声=橙(p_mic_mute_led_red+R+bit0绿),DNR=蓝(p_leds bit1), // 两者同开=橙+蓝混合,两者均关=全灯。 static inline void apply_c1_panel_leds(unsigned mode_led_color_idx, unsigned mic_mute_switch, unsigned mic_voice_fx_on, unsigned mic_dnr_on, unsigned &led_shadow) { @@ -2024,16 +2026,16 @@ static inline void apply_c1_panel_leds(unsigned mode_led_color_idx, unsigned mic mode_blue = 0; } - // 改动原因:硬件LED为低电平点亮(1灯/0亮);低四位 bit0~3 分别为 mode绿、mode蓝、mic红、mic绿,统一刷新。 - // 改动原因:p_mic_mute_led_blue 由 mic_blue 驱动,DNR开且非静音时亮蓝灯(输出0=亮)。 - p_mode_led_red <: (mode_red ? 0 : 1); + // 改动原因:硬件 mic/mode RGB 对调后,低四位 bit0~3 分别为 mic mute绿、mic mute蓝、mode红、mode绿,统一刷新。 + // 改动原因:p_mic_mute_led_red 由 mic_red 驱动,静音/变声时亮红灯(输出0=亮);DNR 蓝灯改由 p_leds bit1 驱动。 + p_mic_mute_led_red <: (mic_red ? 0 : 1); led_shadow &= ~0xF; - led_shadow |= (mode_green ? 0x0 : 0x1); - led_shadow |= (mode_blue ? 0x0 : 0x2); - led_shadow |= (mic_red ? 0x0 : 0x4); - led_shadow |= (mic_green ? 0x0 : 0x8); + led_shadow |= (mic_green ? 0x0 : 0x1); + led_shadow |= (mic_blue ? 0x0 : 0x2); + led_shadow |= (mode_red ? 0x0 : 0x4); + led_shadow |= (mode_green ? 0x0 : 0x8); p_leds <: led_shadow; - p_mic_mute_led_blue <: (mic_blue ? 0 : 1); + p_mode_led_blue <: (mode_blue ? 0 : 1); } void app_control_slave(server interface c1_led_ctrl_if i_c1_led_ctrl, chanend c_eq_data) @@ -2042,9 +2044,9 @@ void app_control_slave(server interface c1_led_ctrl_if i_c1_led_ctrl, chanend c_ unsigned led_shadow = 0xF; unsigned mode_led_color_idx = 1; unsigned mic_mute_switch = 1; - // 改动原因:变声/美声开时仅 p_leds bit2/bit3 显橙,与 set_mode_led_color 下发的 mode 灯独立;此处状态与 tile0 set_mic_voice_fx 同步。 + // 改动原因:变声/美声开时 p_mic_mute_led_red + p_leds bit0 显橙,与 set_mode_led_color 下发的 mode 灯独立;此处状态与 tile0 set_mic_voice_fx 同步。 unsigned mic_voice_fx_on = 0; - // 改动原因:AI通话降噪DNR开时点亮p_mic_mute_led_blue蓝灯;与变声同时开时橙+蓝混合;静音优先在 apply 内部处理。 + // 改动原因:AI通话降噪DNR开时点亮 p_leds bit1 mic mute 蓝灯;与变声同时开时橙+蓝混合;静音优先在 apply 内部处理。 unsigned mic_dnr_on = 0; c1_panel_leds_force_all_off_hw(); diff --git a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/program_key.c b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/program_key.c index 065e6b2..78bf91d 100644 --- a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/program_key.c +++ b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/program_key.c @@ -180,6 +180,7 @@ void flash_opt_unlock(void) { debug_printf("Not Winbond flash (DID: %02x), skip unlock\n", did[0]); flash_opt_disable_ports(); + swlock_release(&flash_lock); return; } @@ -190,11 +191,11 @@ void flash_opt_unlock(void) Mask: 0x7C (0111 1100) */ flash_cmd_opt(READ_STATUS_REG_COMMAND, cmd, 0, data, 1); sr1 = data[0]; - if (sr1 & 0x7C) + if (sr1 != 0) { - debug_printf("Unlock SR1: %02x -> %02x\n", sr1, sr1 & ~0x7C); - flash_cmd_opt(WRITE_ENABLE_STATUS_COMMAND, cmd, 0, data, 0); - data[0] = sr1 & ~0x7C; + debug_printf("Unlock SR1: %02x -> %02x\n", sr1, 0); + flash_cmd_opt(WRITE_ENABLE_COMMAND, cmd, 0, data, 0); + data[0] = 0; flash_cmd_opt(WRITE_STATUS_REG1_COMMAND, data, 1, cmd, 0); delay_milliseconds(10); /* 等待写入完成 */ } @@ -204,25 +205,54 @@ void flash_opt_unlock(void) Mask: 0x40 (0100 0000) */ flash_cmd_opt(READ_STATUS_REG2_COMMAND, cmd, 0, data, 1); sr2 = data[0]; - if ((sr2 & 0x40) || ((sr2 & 0x2) == 0)) + if (sr2 != 0x2) { - debug_printf("Unlock SR2: %02x -> %02x\n", sr2, (sr2 & ~0x40) | 0x2); + debug_printf("Unlock SR2: %02x -> %02x\n", sr2, 0x2); flash_cmd_opt(WRITE_ENABLE_STATUS_COMMAND, cmd, 0, data, 0); - data[0] = (sr2 & ~0x40) | 0x2; + data[0] = 0x2; flash_cmd_opt(WRITE_STATUS_REG2_COMMAND, data, 1, cmd, 0); delay_milliseconds(10); } - /* Reason: 解锁 Status Register 3。 - 参考 flash_api_ext.c 逻辑,清除 Bit 2 (WPS) - Mask: 0x04 (0000 0100) */ + /* Reason: 解锁 Status Register 3。*/ + unsigned write_sr3 = 0; flash_cmd_opt(READ_STATUS_REG3_COMMAND, cmd, 0, data, 1); sr3 = data[0]; - if (sr3 & 0x04) + + if ((did[0] == 0xEF) && (sr3 != 0x60)) { - debug_printf("Unlock SR3: %02x -> %02x\n", sr3, sr3 & ~0x04); - flash_cmd_opt(WRITE_ENABLE_STATUS_COMMAND, cmd, 0, data, 0); - data[0] = sr3 & ~0x04; + data[0] = 0x60; + write_sr3 = 1; + } + else if (((did[0] == 0xC8) || ((did[0] == 0x85) && (did[1] == 0x60))) && (sr3 != 0x20)) + { + data[0] = 0x20; + } + else if ((did[0] == 0x0b) && (did[1] == 0x40) && (sr3 != 0x40)) + { + data[0] = 0x40; + write_sr3 = 1; + } + else if ((did[0] == 0x5e) && (sr3 != 0x10)) + { + data[0] = 0x10; + write_sr3 = 1; + } + else if ((did[0] == 0x85) && (did[1] == 0x20) && (sr3 != 0x0)) + { + data[0] = 0x00; + write_sr3 = 1; + } + else if (sr3 != 0) + { + data[0] = 0; + write_sr3 = 1; + } + + if (write_sr3 == 1) + { + debug_printf("Unlock SR3: %02x -> %02x\n", sr3, data[0]); + flash_cmd_opt(WRITE_ENABLE_COMMAND, cmd, 0, data, 0); flash_cmd_opt(WRITE_STATUS_REG3_COMMAND, data, 1, cmd, 0); delay_milliseconds(10); } diff --git a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/user_main.h b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/user_main.h index 65160cd..cddc77e 100644 --- a/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/user_main.h +++ b/sw_usb_audio/app_usb_aud_fosi_c1_lp/src/extensions/user_main.h @@ -10,10 +10,10 @@ interface c1_led_ctrl_if { // 改动原因:与 c1_mode 同值下发 tile1:1=灭 2=蓝 3=绿 4=橙 5=紫(灯索引即 mode)。 void set_mode_led_color(unsigned color_idx); void set_mic_mute_state(unsigned mute_switch); // mute_switch: 0=静音(亮红), 1=非静音(灭红) - // 改动原因:麦克风键双击“变声/美声”仅改灯效时,在 tile1 点亮 p_leds 的 mic 区:非0=bit2 红 + bit3 绿(橙),0=仅按静音规则驱动 bit2、bit3 熄灭。 + // 改动原因:硬件 mic/mode RGB 对调后,变声/美声开时 tile1 点亮 mic 区:p_mic_mute_led_red 红 + p_leds bit0 绿(橙);关时仅按静音规则驱动 mic 区熄灭。 // 改动原因:参数名不能用 xC 保留字 on(on tile[:]: 语法),否则编译器在解析 interface 时报 parse error before "on"。 void set_mic_voice_fx(unsigned voice_fx_enabled); - // 改动原因:麦克风键长按1.5s切换AI通话降噪(DNR),开时点亮p_mic_mute_led_blue蓝灯; + // 改动原因:麦克风键长按1.5s切换AI通话降噪(DNR),开时点亮 p_leds bit1 mic mute 蓝灯; // 与变声同时开时橙+蓝混合;静音优先(静音时所有mic灯被红灯取代)。断电需保存。 void set_mic_dnr_state(unsigned dnr_enabled); };