diff --git a/Global/Global.c b/Global/Global.c index ad17158..b156b35 100644 --- a/Global/Global.c +++ b/Global/Global.c @@ -196,6 +196,9 @@ void System_PowerOn(void) app_tm1617_init(); XPT2046_Init(); App_Auto_Init(); + /* Dream boot settle, then set unique BLE/BT Audio ADV name via SysEx */ + rt_thread_mdelay(500); + Dream_ApplyUniqueBtNames(); LOG_I("PWR", "periph ready"); } diff --git a/midi/midi_send.c b/midi/midi_send.c index 8d8e2ac..ef32c28 100644 --- a/midi/midi_send.c +++ b/midi/midi_send.c @@ -37,3 +37,51 @@ void SendMidiDataToDreamDSP(uint8_t* buff, uint16_t cnt) { USART2_SendData(buff,cnt); } + +#define AT32_UID_BASE 0x1FFFF7E8UL + +void BleBuildDeviceName(char *out) +{ + static const char hex[] = "0123456789ABCDEF"; + const uint32_t *uid = (const uint32_t *)AT32_UID_BASE; + uint32_t tail = uid[2] & 0x00FFFFFFu; + unsigned i; + + out[0] = 'P'; + out[1] = 'H'; + out[2] = 'O'; + out[3] = 'N'; + out[4] = '_'; + for (i = 0; i < 6; i++) + out[5 + i] = hex[(tail >> (4 * (5 - i))) & 0xFu]; + out[BLE_DEVICE_NAME_LEN] = '\0'; +} + +/* + * Dream BT rename SysEx — reconstructed from factory tool + * 升级/.../bluetooth_set/set_bl_name.exe + * prefixes: f0554c45 (BLE), f0555441 (BT Audio) + * Format: F0 55 4C 45 F7 / F0 55 54 41 F7 + * Needs hardware confirmation after first flash. + */ +static void dream_send_name_sysex(uint8_t b1, uint8_t b2, uint8_t b3, const char *name) +{ + uint8_t msg[4 + BLE_DEVICE_NAME_LEN + 1]; + uint8_t n = BLE_DEVICE_NAME_LEN; + msg[0] = 0xF0; + msg[1] = b1; + msg[2] = b2; + msg[3] = b3; + memcpy(&msg[4], name, n); + msg[4 + n] = 0xF7; + SendMidiDataToDreamDSP(msg, (uint16_t)(5 + n)); +} + +void Dream_ApplyUniqueBtNames(void) +{ + char name[BLE_DEVICE_NAME_LEN + 1]; + BleBuildDeviceName(name); + dream_send_name_sysex(0x55, 0x4C, 0x45, name); /* BLE */ + dream_send_name_sysex(0x55, 0x54, 0x41, name); /* BT Audio */ + LOG_I("BT", "dream name set %s", name); +} diff --git a/midi/midi_send.h b/midi/midi_send.h index bc5ab40..ef12d7b 100644 --- a/midi/midi_send.h +++ b/midi/midi_send.h @@ -11,4 +11,11 @@ void SendVolumeChangeMidiEvent(uint8_t channel, uint8_t CC); void SendMidiDataToDreamDSP(uint8_t* buff, uint16_t cnt); void DefaultTask_SendMsg(uint16_t Data1, uint16_t Data2, uint16_t Data3, uint16_t Data4); +/* Unique BLE/BT name from AT32 UID: "PHON_" + 6 hex (last 3 UID bytes). out >= 12. */ +#define BLE_DEVICE_NAME_LEN 11 +void BleBuildDeviceName(char *out); + +/* Push name to Dream (BLE + BT Audio) via proprietary SysEx on USART2. */ +void Dream_ApplyUniqueBtNames(void); + #endif /* __MIDI_SEND_H__ */ diff --git a/protocol/bl_uart_parse.c b/protocol/bl_uart_parse.c index 473c46a..4334e51 100644 --- a/protocol/bl_uart_parse.c +++ b/protocol/bl_uart_parse.c @@ -579,10 +579,9 @@ static void BL_Sendmsg(uint16_t Data1, uint16_t Data2, uint16_t Data3, uint16_t * ==================================================================== */ /*-------- 1. device info 0x01 --------*/ -#define BLE_DEVICE_NAME "PHON_145" /* must match BLE module broadcast name */ #define AT32_UID_BASE 0x1FFFF7E8UL /* 96-bit unique device ID */ -/* placeholders: sound fw lives on Dream DSP side, UI/user-fw ver bumped per release */ +/* placeholders: 01 04/05/0C — bump manually at each release (Dream has no ver query) */ static const uint8_t SOUND_VER[4] = {0x4D, 0x06, 0x7F, 0x01}; static const uint8_t UI_VER[4] = {0x21, 0x05, 0x7F, 0x01}; static const uint8_t USER_FW_VER[4] = {0x4D, 0x06, 0x7F, 0x01}; @@ -604,12 +603,14 @@ static void handleDevConnect(uint8_t *data) static void handleDevName(uint8_t *data) { - uint8_t resp[4 + sizeof(BLE_DEVICE_NAME)]; /* head4 + name + tail1 */ + char name[BLE_DEVICE_NAME_LEN + 1]; + uint8_t resp[4 + BLE_DEVICE_NAME_LEN + 1]; /* head4 + name + F7 */ (void)data; + BleBuildDeviceName(name); resp[0] = 0xF0; resp[1] = 0x60; resp[2] = 0x01; resp[3] = 0x02; - memcpy(&resp[4], BLE_DEVICE_NAME, sizeof(BLE_DEVICE_NAME) - 1); - resp[sizeof(resp) - 1] = 0xF7; - USART4_SendData(resp, sizeof(resp)); + memcpy(&resp[4], name, BLE_DEVICE_NAME_LEN); + resp[4 + BLE_DEVICE_NAME_LEN] = 0xF7; + USART4_SendData(resp, (uint16_t)sizeof(resp)); } static void handleFwMainVer(uint8_t *data) @@ -635,6 +636,7 @@ static void handleUIVer(uint8_t *data) static void handleOtherInfo(uint8_t *data) { + /* 01 06: reserved — keep 8 zero bytes until product defines fields */ uint8_t resp[13] = {0xF0, 0x60, 0x01, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0xF7}; (void)data; USART4_SendData(resp, sizeof(resp)); @@ -682,8 +684,9 @@ static void handleAutoPowerOffSet(uint8_t *data) static void handleFwCode(uint8_t *data) { + /* 01 FF 固件编码: product string TBD; interim reply uses NVM fwname ("BRS08L") */ uint8_t resp[16]; - uint8_t len = (uint8_t)strlen(fwname); /* "BRS08L" */ + uint8_t len = (uint8_t)strlen(fwname); (void)data; resp[0] = 0xF0; resp[1] = 0x60; resp[2] = 0x01; resp[3] = 0xFF; memcpy(&resp[4], fwname, len);