diff --git a/.DS_Store b/.DS_Store
index 5654bf6..c44617c 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/en/docs/dev_doc/protocols/xu316_zerocode_protocol.md b/en/docs/dev_doc/protocols/xu316_zerocode_protocol.md
index 4319443..4a4115a 100644
--- a/en/docs/dev_doc/protocols/xu316_zerocode_protocol.md
+++ b/en/docs/dev_doc/protocols/xu316_zerocode_protocol.md
@@ -225,6 +225,8 @@ sequenceDiagram
| 0x24 | XU316 send playback volume | XU316→MCU |
| 0x25 | Send recording volume | XU316→MCU |
| 0x26 | Switch MCLK | MCU→XU316 |
+ | 0x27 | Set unmute | MCU→XU316 |
+ | 0x28 | Send audio format time delay | MCU→XU316 |
| 0x29 | Report USB connection status | XU316→MCU |
=== "HID-MCU Passthrough Commands (0xEE-0xEF)"
@@ -237,6 +239,7 @@ sequenceDiagram
| Command | Command Description | Direction |
|:--------:|:---------------------------------------------|:----------:|
| 0xF0 | DAC configuration selection command | MCU→XU316 |
+ | 0xF1 | Get firmware version command | MCU→XU316 |
!!! note "Command Usage Instructions"
1. All commands must follow basic frame format specification
@@ -307,6 +310,24 @@ sequenceDiagram
* Restart reason field can be used by MCU to identify specific reason for XU316 restart for different handling
* When multiple info items need updating, MCU can combine multiple options through bit operations
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 00 01 03 06
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is returned by MCU to XU316 |
+ | Command | 1 byte | `00` | Current command is “Start-up” |
+ | Data Length | 1 byte | `01` | One data byte follows |
+ | Startup options | 1 byte | `03` | `0x01` + `0x02` are both set: update basic product info and power-on config info |
+ | Checksum | 1 byte | `06` | Sum of all bytes from `55` to `03`, modulo 256 |
+
#### 3.2.2 Read Product Info (0x01)
=== "Command Format"
@@ -348,6 +369,31 @@ sequenceDiagram
CRC: 4 bytes (32-bit CRC checksum)
```
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 01 3C 20 B1 00 17 20 B1 00 16 50 48 41 54 45 4E 00 00 00 00 00 00 00 00 00 00 58 55 33 31 36 20 44 41 43 00 00 00 00 00 00 00 53 4E 32 34 30 30 30 31 00 00 00 00 00 00 00 00 12 34 56 78 D9
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is returned by MCU to XU316 |
+ | Command | 1 byte | `01` | Current command is “Read Product Info” |
+ | Data Length | 1 byte | `3C` | 60 data bytes follow |
+ | VID1 | 2 bytes | `20 B1` | USB VID for UAC1.0 |
+ | PID1 | 2 bytes | `00 17` | USB PID for UAC1.0 |
+ | VID2 | 2 bytes | `20 B1` | USB VID for UAC2.0 |
+ | PID2 | 2 bytes | `00 16` | USB PID for UAC2.0 |
+ | ManufactureName | 16 bytes | `50 48 41 54 45 4E 00 00 00 00 00 00 00 00 00 00` | ASCII string `PHATEN`, padded with `00` to 16 bytes |
+ | ProductName | 16 bytes | `58 55 33 31 36 20 44 41 43 00 00 00 00 00 00 00` | ASCII string `XU316 DAC`, padded with `00` to 16 bytes |
+ | SerialNumber | 16 bytes | `53 4E 32 34 30 30 30 31 00 00 00 00 00 00 00 00` | ASCII string `SN240001`, padded with `00` to 16 bytes |
+ | CRC | 4 bytes | `12 34 56 78` | 32-bit CRC for product basic info (example only) |
+ | Checksum | 1 byte | `D9` | Sum of all bytes from `55` to `78`, modulo 256 |
+
#### 3.2.3 Read Power-On Config Info (0x02)
=== "Command Format"
@@ -387,6 +433,29 @@ sequenceDiagram
CRC: 4 bytes (32-bit CRC checksum)
```
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 02 0E 01 00 00 00 00 01 2C 20 30 30 11 22 33 44 6A
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is returned by MCU to XU316 |
+ | Command | 1 byte | `02` | Current command is “Read Power-On Config Info” |
+ | Data Length | 1 byte | `0E` | 14 data bytes follow |
+ | Default input/output mode | 5 bytes | `01 00 00 00 00` | Example mode data; each byte definition depends on product specification |
+ | Mute time | 2 bytes | `01 2C` | `300ms` in big-endian encoding |
+ | Microphone default volume | 1 byte | `20` | Example default microphone volume |
+ | DAC left channel default volume | 1 byte | `30` | Example default left channel volume |
+ | DAC right channel default volume | 1 byte | `30` | Example default right channel volume |
+ | CRC | 4 bytes | `11 22 33 44` | 32-bit CRC for power-on config (example only) |
+ | Checksum | 1 byte | `6A` | Sum of all bytes from `55` to `44`, modulo 256 |
+
#### 3.2.4 Get Current Input/Output Mode (0x03)
=== "Command Format"
@@ -415,6 +484,24 @@ sequenceDiagram
- XU316 will load corresponding application firmware based on returned mode
- This command is used for mode matching and confirmation during device startup
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 03 05 01 00 00 00 00 0B
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is returned by MCU to XU316 |
+ | Command | 1 byte | `03` | Current command is “Get Current Input/Output Mode” |
+ | Data Length | 1 byte | `05` | 5 data bytes follow |
+ | Input/output mode | 5 bytes | `01 00 00 00 00` | Example mode data; definitions depend on product specification |
+ | Checksum | 1 byte | `0B` | Sum of all bytes from `55` to the last mode byte, modulo 256 |
+
#### 3.2.5 Get Current User Configuration (0x04)
=== "Command Format"
@@ -443,6 +530,29 @@ sequenceDiagram
- Executed after application firmware loaded, before application startup
- Application will initialize corresponding parameters based on returned info
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 04 0E 02 00 00 00 00 00 C8 18 28 28 55 66 77 88 00
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is returned by MCU to XU316 |
+ | Command | 1 byte | `04` | Current command is “Get Current User Configuration” |
+ | Data Length | 1 byte | `0E` | 14 data bytes follow |
+ | Input/output mode | 5 bytes | `02 00 00 00 00` | Example current user-selected mode data; definitions depend on product specification |
+ | Mute time | 2 bytes | `00 C8` | `200ms` in big-endian encoding |
+ | Microphone volume | 1 byte | `18` | Example current microphone volume |
+ | DAC left channel volume | 1 byte | `28` | Example current left channel volume |
+ | DAC right channel volume | 1 byte | `28` | Example current right channel volume |
+ | CRC | 4 bytes | `55 66 77 88` | 32-bit CRC for user configuration (example only) |
+ | Checksum | 1 byte | `00` | Sum of all bytes from `55` to `88`, modulo 256 |
+
#### 3.2.6 Startup Complete Command (0x05)
=== "Command Format"
@@ -473,6 +583,23 @@ sequenceDiagram
- Contains startup status info to notify MCU if startup succeeded or encountered problems
- All subsequent business commands can only be used after this command is successfully sent
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 05 00 07
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `05` | Acknowledges “Startup Complete Command” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `07` | Sum of all bytes from `55` to `00`, modulo 256 |
+
### 3.3 Business Control Command Details
!!! warning "Usage Prerequisites"
@@ -506,6 +633,23 @@ sequenceDiagram
- Typically sent when status changes, such as volume change, mode switch, etc.
- MCU can update UI display or adjust related functions based on this info
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 20 00 22
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `20` | Acknowledges “Report Application Status” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `22` | Sum of all bytes from `55` to `00`, modulo 256 |
+
#### 3.3.2 Media Control (0x21)
=== "Command Format"
@@ -582,6 +726,23 @@ sequenceDiagram
- Typically sent when playback starts or format changes
- MCU can update display based on this info, such as showing PCM/DSD/MQA/DOP status
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 22 00 24
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `22` | Acknowledges “Report Playback Audio Stream Format and Type” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `24` | Sum of all bytes from `55` to `00`, modulo 256 |
+
#### 3.3.4 Set Input/Output Mode (0x23)
=== "Command Format"
@@ -638,6 +799,23 @@ sequenceDiagram
=== "Function Description"
- This command is used by XU316 to report current playback volume to MCU
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 24 00 26
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `24` | Acknowledges “Send Playback Volume” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `26` | Sum of all bytes from `55` to `00`, modulo 256 |
+
#### 3.3.6 Send Recording Volume (0x25)
@@ -666,6 +844,23 @@ sequenceDiagram
- This command is used by XU316 to report current microphone recording volume to MCU
- Reserved command, currently not used
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 25 00 27
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `25` | Acknowledges “Send Recording Volume” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `27` | Sum of all bytes from `55` to `00`, modulo 256 |
+
#### 3.3.7 Switch MCLK (0x26)
=== "Command Format"
@@ -776,6 +971,23 @@ sequenceDiagram
- When the USB connection status changes (connect or disconnect), XU316 proactively sends this command
- The MCU can use this information to update the UI or adjust related functions
+=== "MCU Return Example"
+
+ **Command Example**
+ ```
+ 55 AA 03 29 00 2B
+ ```
+
+ **Field Breakdown**
+
+ | Byte Segment | Length | Example | Description |
+ |:-------|:-----|:-------|:-----|
+ | Frame Header | 2 bytes | `55 AA` | Fixed frame header indicating start of a protocol frame |
+ | Version | 1 byte | `03` | Indicates this frame is an acknowledgment returned by MCU to XU316 |
+ | Command | 1 byte | `29` | Acknowledges “Report USB Connection Status” |
+ | Data Length | 1 byte | `00` | Pure acknowledgment frame with no data |
+ | Checksum | 1 byte | `2B` | Sum of all bytes from `55` to `00`, modulo 256 |
+
#### 3.3.11 Get Firmware Version Command (0xF1)
=== "Command Format"
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md
deleted file mode 100644
index 432be97..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md
+++ /dev/null
@@ -1,286 +0,0 @@
----
-title: XU316-MCU Communication Protocol Command Macro Definitions
-description: This document provides command macro definitions for the XU316-MCU communication protocol, including frame formats, command lengths, communication protocols, and more to help developers implement XU316-MCU communication functionality.
-keywords: XU316 communication protocol, MCU command macros, audio format definitions, communication frame format, command data structures, audio type definitions
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316-MCU Communication Protocol Command Macro Definitions
-
-## Document Overview
-
-This document provides command macro definitions for the XU316-MCU communication protocol, including:
-
-1. Communication frame format definitions
-2. MCU command data length definitions
-3. Communication protocol command word enumerations
-4. Audio format and type definitions
-5. Command data structure definitions
-
-These macro definitions and data structures are the foundation of XU316-MCU communication. Developers need to correctly understand and use these definitions to implement communication functionality.
-
-## Communication Frame Format
-
-### Basic Frame Format Definitions
-```c
-#define FRAME_HEADER_H 0x55
-#define FRAME_HEADER_L 0xAA
-#define PROTOCOL_VERSION 0x01
-#define PROTOCOL_VERSION_RX 0x03
-```
-
-## Command Data Length Definitions
-
-### XU316 Command Data Length
-```c
-#define CMD00_XU316_DATA_LEN 0x11 // 0x00 Command: Start boot (boot options)
-#define CMD01_XU316_DATA_LEN 0x00 // 0x01 Command: Read product information (60-byte firmware info)
-#define CMD02_XU316_DATA_LEN 0x00 // 0x02 Command: Read power-on configuration (14-byte config parameters)
-#define CMD03_XU316_DATA_LEN 0x00 // 0x03 Command: Get audio mode (5-byte mode parameters)
-#define CMD04_XU316_DATA_LEN 0x00 // 0x04 Command: Get user configuration (14-byte user settings)
-#define CMD05_XU316_DATA_LEN 0x15 // 0x05 Command: Boot complete (no data field)
-
-#define CMDF1_XU316_DATA_LEN 0x03 // 0xF1 Command: Version query (3-byte version info)
-
-#define CMD20_XU316_DATA_LEN 0x14 // 0x20 Command: Set volume
-#define CMD21_XU316_DATA_LEN 0x00 // 0x21 Command: Audio effect mode
-#define CMD22_XU316_DATA_LEN 0x02 // 0x22 Command: Device status query
-#define CMD23_XU316_DATA_LEN 0x00 // 0x23 Command: Bluetooth control
-#define CMD24_XU316_DATA_LEN 0x02 // 0x24 Command: Send playback volume
-#define CMD25_XU316_DATA_LEN 0x01 // 0x25 Command: Send recording volume
-#define CMD27_XU316_DATA_LEN 0x00 // 0x27 Command: Special unmute (no data field)
-#define CMD28_XU316_DATA_LEN 0x01 // 0x28 Command: Audio format delay setting (1-byte parameter)
-
-#define CMD_HID_TRANSPARENT_DATA_LEN 0x39 // 0xEE Command: HID transparent/OTA upgrade (57 bytes)
-```
-
-### MCU Command Data Length
-```c
-#define CMD00_MCU_DATA_LEN 0x01 // 0x00 Command: Start boot (boot options)
-#define CMD01_MCU_DATA_LEN 0x3C // 0x01 Command: Read product information (60-byte firmware info)
-#define CMD02_MCU_DATA_LEN 0x0E // 0x02 Command: Read power-on configuration (14-byte config parameters)
-#define CMD03_MCU_DATA_LEN 0x05 // 0x03 Command: Get audio mode (5-byte mode parameters)
-#define CMD04_MCU_DATA_LEN 0x0E // 0x04 Command: Get user configuration (14-byte user settings)
-#define CMD05_MCU_DATA_LEN 0x00 // 0x05 Command: Boot complete (no data field)
-
-#define CMDF1_MCU_DATA_LEN 0x00 // 0xF1 Command: Version query (no data field)
-
-#define CMD20_MCU_DATA_LEN 0x00 // 0x20 Command: Set volume
-#define CMD21_MCU_DATA_LEN 0x01 // 0x21 Command: Audio effect mode
-#define CMD22_MCU_DATA_LEN 0x00 // 0x22 Command: Device status query
-#define CMD23_MCU_DATA_LEN 0x05 // 0x23 Command: Set audio mode
-#define CMD24_MCU_DATA_LEN 0x00 // 0x24 Command: Send playback volume
-#define CMD25_MCU_DATA_LEN 0x00 // 0x25 Command: Send recording volume
-#define CMD27_MCU_DATA_LEN 0x00 // 0x27 Command: Special unmute (no data field)
-#define CMD28_MCU_DATA_LEN 0x00 // 0x28 Command: Audio format delay setting (no data field)
-
-#define CMD_HID_TRANSPARENT_MCU_DATA_LEN 0x39 // 0xEE Command: HID transparent/OTA upgrade (57 bytes)
-```
-
-## Communication Protocol Command Definitions
-
-### Command Word Enumeration
-```c
-typedef enum
-{
- /****** Basic Control Commands (0x00-0x05) ******/
- CMD_STARTUP = 0x00, // System startup
- CMD_GET_PRODUCT_INFO = 0x01, // Product information query
- CMD_GET_BOOT_CFG = 0x02, // Power-on configuration read
- CMD_GET_AUD_MODE = 0x03, // Audio mode get
- CMD_GET_USER_CFG = 0x04, // User configuration get
- CMD_STARTUP_COMPLETE = 0x05, // Boot complete notification
-
- CMD_GET_VERSION = 0xF1, // Version query
-
- /****** Business Control Commands (0x20-0x2F) ******/
- CMD_REPORT_STATUS = 0x20, // Status report
- CMD_MEDIA_CONTROL = 0x21, // Media control
- CMD_SET_PLAY_FORMAT = 0x22, // Audio format setting
- CMD_SET_AUDIO_MODE = 0x23, // Audio mode setting
- CMD_SET_PLAY_VOL = 0x24, // Playback volume setting
- CMD_SET_REC_VOL = 0x25, // Recording volume setting
- CMD_SPECIAL_UNMUTE = 0x27, // Special unmute
- CMD_SET_AUDIO_FORMAT_DELAY = 0x28, // Audio format delay setting
-
- CMD_HID_TRANSPARENT = 0xEE, // HID transparent/OTA upgrade command
-
- CMD_COUNT = CMD_SET_REC_VOL + 1 // Total number of currently supported commands
-
-} mcu_command_t;
-```
-
-### Boot Option Enumeration (Bitmask Mode)
-
-!!! note
- **Boot Option Enumeration (Bitmask Mode)**
- **Uses uint8_t to ensure single-byte storage, supports multiple option combinations**
-
-```c
-typedef enum
-{
- BOOT_OPTION_USE_DEFAULTS = 0x00, // Use all default configurations
- BOOT_OPTION_UPDATE_BASIC_INFO = 0x01, // Update basic product information (bit0)
- BOOT_OPTION_UPDATE_POWER_CFG = 0x02, // Update power-on configuration information (bit1)
- BOOT_OPTION_UPDATE_OTHER_CFG = 0x04 // Reserved configuration, currently unused (bit2)
-} boot_option_t;
-```
-
-### Media Control Enumeration
-```c
-typedef enum
-{
- MEDIA_KEY_VOLUME_UP = 0x00, // Volume increase
- MEDIA_KEY_VOLUME_DOWN = 0x01, // Volume decrease
- MEDIA_KEY_PLAY_PAUSE = 0x02, // Play/Pause
- MEDIA_KEY_NEXT_TRACK = 0x03, // Next track
- MEDIA_KEY_PREV_TRACK = 0x04, // Previous track
- MEDIA_KEY_FAST_FORWARD = 0x05, // Fast forward
- MEDIA_KEY_REWIND = 0x06, // Rewind
- MEDIA_KEY_MUTE = 0x07 // Mute toggle
-
- // Reserved for expansion (0x08-0xFF reserved for protocol)
-
-} media_control_t;
-```
-
-## Audio Format Definitions
-
-!!! note
- **Audio Stream Format Enumeration (Compatible with AES67-2020 Standard)**
- **Explicitly specifies underlying type as uint8_t to ensure 1-byte storage**
-
-### Audio Stream Format Enumeration
-```c
-typedef enum
-{
- // PCM Sample Rate Formats (0x00-0x10)
- AUDIO_PCM_44100 = 0x00,
- AUDIO_PCM_48000 = 0x01,
- AUDIO_PCM_88200 = 0x02,
- AUDIO_PCM_96000 = 0x03,
- AUDIO_PCM_176400 = 0x04,
- AUDIO_PCM_192000 = 0x05,
- AUDIO_PCM_352800 = 0x06,
- AUDIO_PCM_384000 = 0x07,
- AUDIO_PCM_705600 = 0x08,
- AUDIO_PCM_768000 = 0x09,
- AUDIO_PCM_1441200 = 0x0A,
- AUDIO_PCM_1536000 = 0x0B,
- AUDIO_PCM_32000 = 0x0C,
- AUDIO_PCM_64000 = 0x0D,
- AUDIO_PCM_128000 = 0x0E,
- AUDIO_PCM_256000 = 0x0F,
- AUDIO_PCM_512000 = 0x10,
-
- // DSD Formats (0x11-0x15)
- AUDIO_DSD_64 = 0x11,
- AUDIO_DSD_128 = 0x12,
- AUDIO_DSD_256 = 0x13,
- AUDIO_DSD_512 = 0x14,
- AUDIO_DSD_1024 = 0x15,
-
- // MQA Formats (0x16-0x2D)
- AUDIO_MQA_44100 = 0x16,
- AUDIO_MQA_88200 = 0x17,
- AUDIO_MQA_176400 = 0x18,
- AUDIO_MQA_352800 = 0x19,
- AUDIO_MQA_705600 = 0x1A,
- AUDIO_MQA_1411200 = 0x1B,
- AUDIO_MQA_2822400 = 0x1C,
- AUDIO_MQA_5644800 = 0x1D,
-
- // -- 48kHz Base Series --
- AUDIO_MQA_48000 = 0x1E,
- AUDIO_MQA_96000 = 0x1F,
- AUDIO_MQA_192000 = 0x20,
- AUDIO_MQA_384000 = 0x21,
- AUDIO_MQA_768000 = 0x22,
- AUDIO_MQA_1536000 = 0x23,
- AUDIO_MQA_3072000 = 0x24,
- AUDIO_MQA_6144000 = 0x25,
-
- // -- Other Base Frequency Series --
- AUDIO_MQA_64000 = 0x26,
- AUDIO_MQA_128000 = 0x27,
- AUDIO_MQA_256000 = 0x28,
- AUDIO_MQA_512000 = 0x29,
- AUDIO_MQA_1024000 = 0x2A,
- AUDIO_MQA_2048000 = 0x2B,
- AUDIO_MQA_4096000 = 0x2C,
- AUDIO_MQA_8192000 = 0x2D,
-
- // Special Reserved Value
- AUDIO_NO_USED = 0xFF
-
-} audio_format_t;
-```
-
-### Audio Type Enumeration
-!!! note
- **Audio Type Enumeration (Compatible with AES67-2020 Standard)**
- **Explicitly specifies underlying type as uint8_t to ensure 1-byte storage**
-
-```c
-typedef enum
-{
- AUDIO_TYPE_PCM = 0x00, // PCM standard audio
- AUDIO_TYPE_RESERVE = 0x01, // Protocol reserved field
- AUDIO_TYPE_MQA = 0x02, // MQA encoded audio
- AUDIO_TYPE_MQB = 0x03, // MQB encoded audio (secondary extension)
- AUDIO_TYPE_MQA_STUDIO = 0x04, // MQA Studio master quality
- AUDIO_TYPE_DSD = 0x05 // Direct Stream Digital
-
- // 0x06-0xFF reserved for future expansion
-
-} audio_type_t;
-```
-
-## Command Data Structures
-
-### Data Structure Definitions
-```c
-typedef uint8_t byte_pair[2];
-// Command data structure
-typedef struct __attribute__((packed))
-{
- uint8_t boot_option; // 0x00: Boot option data
- // Product basic information
- uint8_t vid_uac1[2]; // UAC1.0 vendor ID
- uint8_t pid_uac1[2]; // UAC1.0 product ID
- uint8_t vid_uac2[2]; // UAC2.0 vendor ID
- uint8_t pid_uac2[2]; // UAC2.0 product ID
- uint8_t product_manufacturer[16]; // Manufacturer name
- uint8_t product_name[16]; // Product name
- uint8_t product_serial[16]; // Serial number
- uint8_t basic_info_crc[4]; // Basic information CRC32
- // User configuration is power-on configuration information and also application runtime parameters
- uint8_t startup_status; // Startup status
- uint8_t audio_mode[5];
- uint8_t mute_duration[2]; // Mute duration (ms)
- uint8_t mic_volume; // Microphone volume, also recording volume
- uint8_t dac_l_volume; // Left channel volume (0-255)
- uint8_t dac_r_volume; // Right channel volume (0-255)
- uint8_t power_cfg_crc[4]; // Power-on configuration CRC32
- // Application runtime parameters
- uint8_t media_control; // Media control command
- uint8_t audio_format; // Audio format code
- uint8_t audio_type; // Audio type code
-} mcu_data_t;
-```
-
-
-
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros_part1.txt b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros_part1.txt
deleted file mode 100644
index 1cc9b69..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros_part1.txt
+++ /dev/null
@@ -1,25 +0,0 @@
----
-title: XU316 and MCU Communication Protocol Command Macro Definitions
-description: This document provides command macro definitions for XU316 and MCU communication protocol, including frame format, command length, communication protocol, etc., to help developers implement communication functions between XU316 and MCU.
-keywords: XU316 communication protocol, MCU command macros, audio format definition, communication frame format, command data structure, audio type definition
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316 and MCU Communication Protocol Command Macro Definitions
-
-## Document Description
-
-This document provides command macro definitions related to the XU316 and MCU communication protocol, mainly including the following contents:
-
-1. Communication frame format definition
-2. MCU command data length definition
-3. Communication protocol command enumeration
-4. Audio format and type definition
-5. Command data structure definition
-
-These macro definitions and data structures are the foundation of XU316 and MCU communication. Developers need to correctly understand and use these definitions to implement communication functions.
-
-## Communication Frame Format
-
-### Basic Frame Format Definition
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md
deleted file mode 100644
index 832307e..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md
+++ /dev/null
@@ -1,407 +0,0 @@
----
-title: XU316-MCU Communication Protocol Reference
-description: Detailed description of the communication protocol between XU316 and MCU, including data structures, command formats, and processing flows
-keywords: XU316, MCU, communication protocol, command reference
-hide:
- -toc
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316-MCU Communication Protocol Reference
-
-## 1. Basic Data Structures
-
-### 1.1 Ring Buffer
-```c
-#define RING_BUFFER_SIZE 256 // Ring buffer size for UART communication buffering
-
-typedef struct {
- uint8_t buffer[RING_BUFFER_SIZE]; // Data storage area
- volatile uint16_t head; // Write position pointer
- volatile uint16_t tail; // Read position pointer
- volatile uint16_t count; // Current data count
-} ring_buffer_t;
-```
-
-### 1.2 Audio Mode Definitions
-```c
-// Audio mode configuration array, each mode contains 5 bytes of configuration data
-static const uint8_t audio_modes[][5] = {
- {0x00, 0x80, 0xa9, 0x00, 0x01}, // USB-no-mqa mode
- {0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1 mode
- {0x10, 0x80, 0x65, 0x10, 0x03}, // COAX mode
- {0x00, 0x80, 0x65, 0x10, 0x04}, // OPT mode
- {0x00, 0x80, 0xc5, 0x08, 0x05}, // SPDIF OUT mode
- {0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN mode
- {0x20, 0x80, 0x65, 0x10, 0x07} // HDMI mode
-};
-
-// Corresponding mode name array
-static const char *mode_names[] = {
- "USB-no-mqa",
- "UAC1",
- "COAX",
- "OPT",
- "SPDIF OUT",
- "I2S IN",
- "HDMI"
-};
-```
-
-## 2. Initialization and Configuration
-
-### 2.1 Device Initialization Information Print
-```c
-#define AUDIO_MODE_COUNT (sizeof(audio_modes) / sizeof(audio_modes[0]))
-
-void print_init_info(void)
-{
- log_data(LOG_USER, "----------Device initialized----------\n");
- // Print UAC1.0 device information
- log_data(LOG_USER, "VID1: %02X%02X", mcu_data.vid_uac1[0], mcu_data.vid_uac1[1]);
- log_data(LOG_USER, "PID1: %02X%02X", mcu_data.pid_uac1[0], mcu_data.pid_uac1[1]);
- // Print UAC2.0 device information
- log_data(LOG_USER, "VID2: %02X%02X", mcu_data.vid_uac2[0], mcu_data.vid_uac2[1]);
- log_data(LOG_USER, "PID2: %02X%02X", mcu_data.pid_uac2[0], mcu_data.pid_uac2[1]);
- // Print product information
- log_data(LOG_USER, "Manufacturer: %s", mcu_data.product_manufacturer);
- log_data(LOG_USER, "Name: %s", mcu_data.product_name);
- log_data(LOG_USER, "Serial: %s", mcu_data.product_serial);
- // Print CRC checksum information
- log_data(LOG_USER, "Basic Info CRC: %02X%02X%02X%02X",
- mcu_data.basic_info_crc[0], mcu_data.basic_info_crc[1],
- mcu_data.basic_info_crc[2], mcu_data.basic_info_crc[3]);
- log_data(LOG_USER, "Power Config CRC: %02X%02X%02X%02X",
- mcu_data.power_cfg_crc[0], mcu_data.power_cfg_crc[1],
- mcu_data.power_cfg_crc[2], mcu_data.power_cfg_crc[3]);
-}
-```
-
-### 2.2 Ring Buffer Initialization
-```c
-void ring_buffer_init(void) {
- uart_ring_buffer.head = 0; // Initialize write position
- uart_ring_buffer.tail = 0; // Initialize read position
- uart_ring_buffer.count = 0; // Initialize data count
-}
-```
-
-### 2.3 Product Information Initialization
-```c
-void xu316_init(void)
-{
- // Default audio mode configuration (USB UAC2.0)
- uint8_t audio_mode[5] = {0x00, 0x80, 0xa9, 0x00, 0x01};
-
- // Configure UAC1.0 device information
- mcu_data.vid_uac1[0] = 0x20;
- mcu_data.vid_uac1[1] = 0xB1; // VID = 0x20B1
- mcu_data.pid_uac1[0] = 0x00;
- mcu_data.pid_uac1[1] = 0x17; // PID = 0x0017
-
- // Configure UAC2.0 device information
- mcu_data.vid_uac2[0] = 0x20;
- mcu_data.vid_uac2[1] = 0xB1; // VID = 0x20B1
- mcu_data.pid_uac2[0] = 0x00;
- mcu_data.pid_uac2[1] = 0x16; // PID = 0x0016
-
- // Configure product information
- memcpy(mcu_data.product_manufacturer, "Phaten", 6);
- // Set product name
- memcpy(mcu_data.product_name, "XMOS XU316", 11);
- // Set product serial number
- memcpy(mcu_data.product_serial, "123456789ABCDEF", 15);
-
- // Calculate and store basic information CRC32 checksum (56 bytes)
- crc = calculate_crc32(mcu_data.vid_uac1, 56);
- mcu_data.basic_info_crc[0] = (crc >> 24) & 0xFF;
- mcu_data.basic_info_crc[1] = (crc >> 16) & 0xFF;
- mcu_data.basic_info_crc[2] = (crc >> 8) & 0xFF;
- mcu_data.basic_info_crc[3] = crc & 0xFF;
-
- // Initialize device status and audio configuration
- mcu_data.startup_status = 0x00;
- memcpy(&mcu_data.audio_mode, audio_mode, 5);
-
- // Configure mute duration (400ms)
- mcu_data.mute_duration[0] = MUTE_DURATION_CONFIG >> 8;
- mcu_data.mute_duration[1] = MUTE_DURATION_CONFIG;
-
- // Initialize volume settings
- mcu_data.mic_volume = MIC_VOLUME_CONFIG;
- // Initialize left and right channel DAC volume
- mcu_data.dac_l_volume = DAC_L_VOLUME_CONFIG;
- mcu_data.dac_r_volume = DAC_R_VOLUME_CONFIG;
-
- // Calculate and store power configuration CRC32 checksum (10 bytes)
- crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
- mcu_data.power_cfg_crc[0] = (crc >> 24) & 0xFF;
- mcu_data.power_cfg_crc[1] = (crc >> 16) & 0xFF;
- mcu_data.power_cfg_crc[2] = (crc >> 8) & 0xFF;
- mcu_data.power_cfg_crc[3] = crc & 0xFF;
-
- // Initialize communication buffer
- ring_buffer_init();
-}
-```
-
-## 3. Communication Buffer Operations
-
-### 3.1 Ring Buffer Operation Functions
-```c
-// Write data to ring buffer
-uint8_t ring_buffer_write(uint8_t *data, uint16_t len) {
- uint16_t i;
- for(i = 0; i < len; i++) {
- if(uart_ring_buffer.count >= RING_BUFFER_SIZE) {
- return 0; // Buffer full, write failed
- }
- uart_ring_buffer.buffer[uart_ring_buffer.head] = data[i];
- uart_ring_buffer.head = (uart_ring_buffer.head + 1) % RING_BUFFER_SIZE;
- uart_ring_buffer.count++;
- }
- return 1; // Write successful
-}
-
-// Read data from ring buffer
-uint8_t ring_buffer_read(uint8_t *data, uint16_t len) {
- uint16_t i;
- if(uart_ring_buffer.count < len) {
- return 0; // Insufficient data
- }
- for(i = 0; i < len; i++) {
- data[i] = uart_ring_buffer.buffer[uart_ring_buffer.tail];
- uart_ring_buffer.tail = (uart_ring_buffer.tail + 1) % RING_BUFFER_SIZE;
- uart_ring_buffer.count--;
- }
- return 1; // Read successful
-}
-
-// Peek data (does not move read pointer)
-uint8_t ring_buffer_peek(uint8_t *data, uint16_t len) {
- uint16_t i;
- uint16_t temp_tail = uart_ring_buffer.tail;
- for(i = 0; i < len; i++) {
- data[i] = uart_ring_buffer.buffer[temp_tail];
- temp_tail = (temp_tail + 1) % RING_BUFFER_SIZE;
- }
- return 0; // Peek successful
-}
-```
-
-## 4. Checksum Calculation
-
-### 4.1 CRC32 Calculation
-```c
-uint32_t calculate_crc32(const uint8_t *buffer, uint32_t length)
-{
- uint32_t crc = 0xFFFFFFFF;
- const uint32_t poly = 0xEDB88320; // CRC32 polynomial
-
- for (size_t i = 0; i < length; i++) {
- crc ^= buffer[i];
- for (int j = 0; j < 8; j++) {
- if (crc & 1) {
- crc = (crc >> 1) ^ poly;
- } else {
- crc >>= 1;
- }
- }
- }
- return ~crc; // Return CRC32 checksum value
-}
-
-// Calculate simple checksum
-uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len)
-{
- uint8_t sum = 0;
- for (uint8_t i = 0; i < len; i++) {
- sum += data[i];
- }
- return sum;
-}
-```
-
-## 5. Communication Protocol Processing
-
-### 5.1 Frame Validation
-```c
-// Validate frame data integrity
-uint8_t uart_frame_check(uint8_t *buf, uint8_t len)
-{
- // Check minimum length requirement
- if (len < 6) { // Frame header(2) + version(1) + command(1) + length(2) + checksum(1)
- return 0;
- }
-
- // Verify frame header
- if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
- return 0;
- }
-
- // Get data length (big-endian)
- uint16_t data_len = buf[4];
-
- // Verify data length validity
- if (data_len > 256 || len < (data_len + 6)) {
- return 0;
- }
-
- // Calculate and verify checksum
- uint8_t sum = xu316_calc_checksum(buf, data_len + 5);
- if (sum != buf[data_len + 5]) {
- return 0;
- }
-
- LOG_TEMP(LOG_RECV, "", buf, len);
- return 1;
-}
-```
-
-### 5.2 Data Frame Encapsulation
-```c
-int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len)
-{
- uint8_t tx_data[256] = {0};
- if (len >= 255) {
- return 0;
- }
-
- // Build frame header
- tx_data[0] = FRAME_HEADER_H;
- tx_data[1] = FRAME_HEADER_L;
- tx_data[2] = PROTOCOL_VERSION_RX;
- tx_data[3] = cmd;
- tx_data[4] = len;
-
- // Copy data payload
- if (data && len > 0) {
- memcpy(tx_data + 5, data, len);
- }
-
- // Calculate and add checksum
- tx_data[len + 5] = xu316_calc_checksum(tx_data, len + 5);
- len += 6;
-
- // Send data
- usart_dma_send(tx_data, len);
- LOG_INFO("Sending frame: cmd=0x%02X, len=%d", cmd, len);
- LOG_TEMP(LOG_SEND, "", tx_data, len);
- return len;
-}
-```
-
-### 5.3 Frame Length Check
-```c
-int check_frame_length(uint8_t *buf, uint16_t len) {
- // Verify frame header
- if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
- LOG_DEBUG("Frame header check failed %02x %02x", buf[0], buf[1]);
- return -1;
- }
- // Get data length (big-endian)
- int data_len = buf[4];
- // Return complete frame length
- return data_len + 6;
-}
-```
-
-### 5.4 Data Reception Processing
-```c
-void uart_data_process(void)
-{
- uint8_t peek_buffer[8]; // Peek buffer
- uint8_t process_buffer[256]; // Process buffer
- int frame_length;
-
- while(uart_ring_buffer.count >= 6) { // At least 6 bytes needed to start checking
- // Peek frame header information
- ring_buffer_peek(peek_buffer, 6);
-
- // Debug output
- for(int i = 0; i < 6; i++) {
- LOG_DEBUG("peek_buffer[%d]: %02x", i, peek_buffer[i]);
- }
-
- // Check frame length
- frame_length = check_frame_length(peek_buffer, 6);
- if(frame_length < 0) {
- // Invalid frame, discard one byte
- uint8_t dummy;
- ring_buffer_read(&dummy, 1);
- LOG_ERROR("Frame length check failed %02x", dummy);
- continue;
- }
-
- // Check if there is enough data
- if(uart_ring_buffer.count < frame_length) {
- LOG_ERROR("Not enough data");
- break; // Wait for more data
- }
-
- // Read and process complete frame
- if(ring_buffer_read(process_buffer, frame_length)) {
- uart_data_parse();
- }
- }
-}
-```
-
-### 5.5 Data Parsing Processing
-```c
-int uart_data_parse(void)
-{
- int ret = 0;
- uint8_t cmd = 0;
- uint16_t data_len = 0;
- uint16_t rx_len = 0;
- uint8_t tmp;
- static uint8_t buffer[256] = {0};
- rx_len = g_rx_count;
-
- // Verify frame integrity
- ret = uart_frame_check((uint8_t *)g_rx_data, rx_len);
- if (ret == 0) {
- LOG_ERROR("Frame check failed %d", rx_len);
- LOG_TEMP(LOG_RECV, "", g_rx_data, rx_len);
- return -1;
- }
-
- // Parse frame information
- data_len = rx_len - 6;
- cmd = g_rx_data[3];
- if (g_rx_data[4] != data_len) {
- LOG_ERROR("Data length mismatch: expected %d, got %d", g_rx_data[4], data_len);
- return -1;
- }
-
- LOG_DEBUG("Received frame: cmd=0x%02X, len=%d", cmd, data_len);
- LOG_VERBOSE("--------------------------------");
- LOG_VERBOSE("cmd : %02X", cmd);
- memcpy(buffer, g_rx_data + 5, data_len);
-
- // Process data based on command type
- switch (cmd) {
- case 0x00: // Startup information
- // ... Process startup information ...
- break;
-
- case 0x01: // Basic information
- // ... Process basic information ...
- break;
-
- case 0x02: // Power configuration
- // ... Process power configuration ...
- break;
-
- // ... Other command processing ...
-
- default:
- LOG_ERROR("Unknown command: 0x%02X", cmd);
- break;
- }
-
- return ret;
-}
-```
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
new file mode 100644
index 0000000..265ce1d
--- /dev/null
+++ b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
@@ -0,0 +1,492 @@
+---
+title: XU316 MCU Development Example
+description: Detailed explanation of the communication protocol between XU316 and MCU, including data structures, command formats, and processing flow
+keywords: XU316, MCU, communication protocol, command reference
+---
+
+# XU316 MCU Development Example
+
+--8<-- "common/phaten_xmos_support_img.md"
+
+This example is based on the GD32 platform. For other platforms, please adapt accordingly.
+
+## Minimal Usage Example
+
+This code demonstrates how to initialize the protocol layer and process data in the main loop. Users need to implement their own UART send function and call `ring_buffer_write` in the UART receive interrupt to write data into the ring buffer.
+
+```c
+#include "xu316_protocol.h"
+
+// Send callback: transmit data to XU316 via UART
+// Users need to implement uart_send based on their hardware
+void my_send(const uint8_t *data, uint16_t len) {
+ uart_send(data, len);
+}
+
+// Log callback: output debug information (optional)
+void my_log(const char *tag, const char *msg) {
+ printf("[%s] %s\n", tag, msg);
+}
+
+// Initialization
+void init(void) {
+ xu316_port_t port = {
+ .send = my_send,
+ .log = my_log
+ };
+ xu316_register_port(&port);
+ xu316_init();
+}
+
+// Called in UART receive interrupt, writes received data to ring buffer
+void uart_rx_isr(uint8_t *data, uint16_t len) {
+ ring_buffer_write(data, len);
+}
+
+// Called periodically in main loop to process received commands
+void main_loop(void) {
+ uart_data_process();
+}
+```
+
+## Protocol Layer Functions
+
+### Checksum Calculation
+
+Calculates the cumulative sum of all bytes from the frame header to the data area, then takes the result modulo 256. This checksum is used to verify data frame integrity.
+
+```c
+uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len) {
+ uint8_t sum = 0;
+ for (uint8_t i = 0; i < len; i++) {
+ sum += data[i];
+ }
+ return sum;
+}
+```
+
+### Frame Packing
+
+Encapsulates the command and data into a protocol-compliant frame and sends it through the registered `send` callback.
+
+Frame format: `Header(0x55AA) + Version(0x03) + Command + Data Length + Data + Checksum`
+
+```c
+int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len) {
+ memset(g_tx_buffer, 0, sizeof(g_tx_buffer));
+ g_tx_buffer[0] = FRAME_HEADER_H; // 0x55
+ g_tx_buffer[1] = FRAME_HEADER_L; // 0xAA
+ g_tx_buffer[2] = PROTOCOL_VERSION_RX; // 0x03 (MCU version)
+ g_tx_buffer[3] = cmd; // Command
+ g_tx_buffer[4] = len; // Data length
+
+ if (data && len > 0) {
+ memcpy(g_tx_buffer + 5, data, len);
+ }
+
+ // Calculate checksum (header + version + command + length + data)
+ g_tx_buffer[len + 5] = xu316_calc_checksum(g_tx_buffer, len + 5);
+
+ // Send via registered callback
+ if (g_xu316_port.send) {
+ g_xu316_port.send(g_tx_buffer, len + 6);
+ }
+ return len + 6;
+}
+```
+
+### Frame Extraction
+
+Pre-reads data from the ring buffer and checks if the frame header is valid. Returns the complete frame length if valid, or `-1` if bytes need to be discarded.
+
+```c
+static int check_frame_length(uint8_t *buf, uint16_t len) {
+ // Check if header is 0x55AA
+ if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
+ return -1; // Invalid header
+ }
+ // Return complete frame length = data length + 6 (header2 + version1 + cmd1 + len1 + checksum1)
+ return buf[4] + 6;
+}
+```
+
+### Data Processing Main Function
+
+Called periodically in the main loop. Extracts complete data frames from the ring buffer, verifies frame header validity, confirms sufficient data length, copies the complete frame to the receive buffer, and then calls `uart_data_parse` for command parsing. If the frame header is invalid, bytes are discarded one by one until a valid header is found.
+
+```c
+void uart_data_process(void) {
+ uint8_t peek_buffer[8]; // Peek buffer
+ uint8_t process_buffer[256]; // Frame data buffer
+ int frame_length;
+
+ // Need at least 6 bytes to start checking header
+ while (uart_ring_buffer.count >= 6) {
+ // Peek 6 bytes to check header
+ ring_buffer_peek(peek_buffer, 6);
+
+ // Check frame length
+ frame_length = check_frame_length(peek_buffer, 6);
+ if (frame_length < 0) {
+ // Invalid header, discard 1 byte and continue searching
+ uint8_t dummy;
+ ring_buffer_read(&dummy, 1);
+ continue;
+ }
+
+ // Check if ring buffer has enough data for complete frame
+ if (uart_ring_buffer.count < (uint16_t)frame_length) {
+ break; // Insufficient data, wait for more
+ }
+
+ // Read complete frame to processing buffer
+ if (ring_buffer_read(process_buffer, (uint16_t)frame_length)) {
+ // Copy complete frame to global receive buffer
+ memcpy(g_rx_buffer, process_buffer, frame_length);
+ g_rx_count = frame_length;
+ g_rx_data = g_rx_buffer;
+ // Call parse function to process command
+ uart_data_parse();
+ }
+ }
+}
+```
+
+## Command Parsing
+
+### Parse Entry
+
+The core function of protocol processing. Verifies the received data frame, extracts the command and data area, then dispatches to the corresponding handler based on the command.
+
+```c
+int uart_data_parse(void) {
+ int ret = 0;
+ uint8_t cmd = 0;
+ uint16_t data_len = 0;
+ uint16_t rx_len = (uint16_t)g_rx_count;
+ static uint8_t buffer[256] = {0};
+
+ // Frame verification: check frame format and checksum
+ ret = uart_frame_check((uint8_t *)g_rx_data, (uint8_t)rx_len);
+ if (ret == 0) {
+ return -1; // Frame verification failed
+ }
+
+ // Calculate data area length: total length - 6 (header2 + version1 + cmd1 + len1 + checksum1)
+ data_len = rx_len - 6;
+ // Extract command (4th byte, index 3)
+ cmd = g_rx_data[3];
+ // Copy data area to buffer (from 6th byte, index 5)
+ memcpy(buffer, g_rx_data + 5, data_len);
+
+ // Dispatch based on command
+ switch (cmd) {
+ case 0x00: /* Boot command */ break;
+ case 0x01: /* Read product info */ break;
+ case 0x02: /* Read power-on config */ break;
+ case 0x03: /* Get audio mode */ break;
+ case 0x04: /* Get user config */ break;
+ case 0x05: /* Startup complete */ break;
+ case 0x20: /* Status report */ break;
+ case 0x22: /* Audio format set */ break;
+ case 0x24: /* Playback volume */ break;
+ case 0x25: /* Recording volume */ break;
+ case 0x27: /* Unmute response */ break;
+ case 0x28: /* Audio format delay */ break;
+ case 0xEE: /* HID passthrough */ break;
+ default: /* Unknown command */ break;
+ }
+ return ret;
+}
+```
+
+### Command Reference
+
+#### Boot Command (0x00)
+
+XU316 sends this command first after power-on or reboot. XU316 sends 17 bytes of data including VID/PID and CRC values. MCU compares CRC to determine if configuration needs updating, then replies with 1 byte of boot options.
+
+```c
+case 0x00: {
+ // XU316 data format:
+ // Reboot reason(1B) + VID1(2B) + PID1(2B) + VID2(2B) + PID2(2B) + CRC1(4B) + CRC2(4B) = 17 bytes
+ // MCU reply: Boot option(1B)
+
+ // Parse XU316 data
+ uint8_t reboot_reason = buffer[0]; // 0x00=power-on, 0x01=mode switch, 0xFF=other
+ uint8_t *vid_uac1 = buffer + 1; // UAC1.0 VID
+ uint8_t *pid_uac1 = buffer + 3; // UAC1.0 PID
+ uint8_t *vid_uac2 = buffer + 5; // UAC2.0 VID
+ uint8_t *pid_uac2 = buffer + 7; // UAC2.0 PID
+ uint8_t *basic_crc = buffer + 9; // Basic info CRC
+ uint8_t *power_crc = buffer + 13; // Power config CRC
+
+ // Check if config update is needed: compare XU316 CRC with local stored CRC
+ mcu_data.boot_option = 0;
+ if (memcmp(basic_crc, mcu_data.basic_info_crc, 4) != 0) {
+ mcu_data.boot_option |= BOOT_OPTION_UPDATE_BASIC_INFO; // Need to update basic info
+ }
+ if (memcmp(power_crc, mcu_data.power_cfg_crc, 4) != 0) {
+ mcu_data.boot_option |= BOOT_OPTION_UPDATE_POWER_CFG; // Need to update power config
+ }
+
+ // Send reply: boot option
+ ret = xu316_pack_frame(cmd, &mcu_data.boot_option, CMD00_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Read Product Info (0x01)
+
+XU316 requests product basic information. MCU replies with 60 bytes of data including VID, PID, manufacturer name, product name, serial number, and CRC.
+
+```c
+case 0x01: {
+ // XU316 sends: no data
+ // MCU reply: 60 bytes product info
+ // VID1(2B) + PID1(2B) + VID2(2B) + PID2(2B) +
+ // Manufacturer(16B) + Product(16B) + Serial(16B) + CRC(4B)
+
+ // Recalculate CRC32 for basic info (first 56 bytes)
+ crc = calculate_crc32(mcu_data.vid_uac1, 56);
+ // Store CRC in big-endian
+ mcu_data.basic_info_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.basic_info_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.basic_info_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.basic_info_crc[3] = (uint8_t)(crc & 0xFF);
+
+ // Send product info (60 bytes starting from vid_uac1)
+ ret = xu316_pack_frame(cmd, mcu_data.vid_uac1, CMD01_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Read Power-On Config (0x02)
+
+XU316 requests power-on configuration parameters. MCU replies with 14 bytes including boot status, audio mode, mute time, volume settings, and CRC.
+
+```c
+case 0x02: {
+ // XU316 sends: no data
+ // MCU reply: 14 bytes config info
+ // Boot status(1B) + Audio mode(5B) + Mute time(2B) +
+ // Mic volume(1B) + Left vol(1B) + Right vol(1B) + CRC(4B)
+
+ // Recalculate CRC32 for power config (10 bytes starting from audio_mode)
+ crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
+ // Store in big-endian
+ mcu_data.power_cfg_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.power_cfg_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.power_cfg_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.power_cfg_crc[3] = (uint8_t)(crc & 0xFF);
+
+ // Send power config (14 bytes starting from audio_mode)
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD02_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Get Audio Mode (0x03)
+
+XU316 requests current input/output mode. MCU replies with 5 bytes of audio mode configuration.
+
+```c
+case 0x03: {
+ // XU316 sends: no data
+ // MCU reply: 5 bytes audio mode
+
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD03_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Get User Config (0x04)
+
+XU316 requests user configuration parameters. MCU replies with 14 bytes, same format as 0x02 command. Sets the currently selected audio mode and recalculates CRC.
+
+```c
+case 0x04: {
+ // XU316 sends: no data
+ // MCU reply: 14 bytes user config (same format as 0x02)
+
+ // Set currently selected audio mode
+ memcpy((uint8_t *)&mcu_data.audio_mode, audio_modes[g_current_mode], 5);
+
+ // Calculate CRC
+ crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 10);
+ mcu_data.power_cfg_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.power_cfg_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.power_cfg_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.power_cfg_crc[3] = (uint8_t)(crc & 0xFF);
+
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD04_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Startup Complete (0x05)
+
+XU316 notifies MCU that startup is complete and sends current status data. MCU only needs to reply with acknowledgment (no data).
+
+```c
+case 0x05: {
+ // XU316 sends: 21 bytes status data
+ // MCU reply: no data
+
+ // Save XU316 status to mcu_data structure
+ memcpy(&mcu_data.startup_status, buffer, 15);
+
+ // Reply acknowledgment
+ ret = xu316_pack_frame(cmd, NULL, CMD05_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Status Report (0x20)
+
+XU316 proactively reports status changes. MCU saves status data and replies with acknowledgment.
+
+```c
+case 0x20: {
+ // XU316 sends: 20 bytes status data
+ // Audio mode(5B) + Mute time(2B) + Mic vol(1B) + Left vol(1B) + Right vol(1B) + CRC(4B)
+ // MCU reply: no data
+
+ // Save status data
+ memcpy(&mcu_data.audio_mode, buffer, 14);
+
+ // Reply acknowledgment
+ ret = xu316_pack_frame(cmd, NULL, CMD20_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Audio Format Setting (0x22)
+
+XU316 notifies current playback audio format and type. MCU saves this information and replies with acknowledgment.
+
+```c
+case 0x22: {
+ // XU316 sends: 2 bytes (audio format + audio type)
+ // MCU reply: no data
+
+ // Save audio format and type
+ memcpy(&mcu_data.audio_format, buffer, 2);
+
+ // Reply acknowledgment
+ ret = xu316_pack_frame(cmd, NULL, CMD22_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### Playback Volume (0x24)
+
+XU316 sends current playback volume. MCU saves left/right channel volume values and replies with acknowledgment.
+
+```c
+case 0x24: {
+ // XU316 sends: 2 bytes (left volume + right volume)
+ // MCU reply: no data
+
+ // Save volume values
+ memcpy(&mcu_data.dac_l_volume, buffer, 2);
+
+ // Reply acknowledgment
+ ret = xu316_pack_frame(cmd, NULL, CMD24_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### HID Passthrough (0xEE)
+
+HID data passthrough or OTA upgrade data. XU316 sends 57 bytes, MCU replies with 57 bytes (echo mode).
+
+```c
+case 0xEE: {
+ // XU316 sends: 57 bytes HID/OTA data
+ // MCU reply: 57 bytes (echo mode)
+
+ // Check version and data length
+ if (g_rx_data[2] == 0x00 && g_rx_data[4] == CMD_HID_TRANSPARENT_DATA_LEN) {
+ // Simple echo reply: return received data as-is
+ ret = xu316_pack_frame(0xEE, buffer, CMD_HID_TRANSPARENT_MCU_DATA_LEN);
+ }
+ break;
+}
+```
+
+## MCU-Initiated Commands
+
+The following commands are sent proactively by MCU to XU316.
+
+### Unmute Command
+
+Command `0x27`, data is 2 bytes of `0x00`.
+
+```c
+void send_unmute_cmd(void) {
+ uint8_t data[2] = {0x00, 0x00};
+ xu316_pack_frame(0x27, data, 2);
+}
+```
+
+### Audio Format Delay Command
+
+Command `0x28`, data is 2 bytes of `0x00`.
+
+```c
+void send_audio_format_delay_cmd(void) {
+ uint8_t data[2] = {0x00, 0x00};
+ xu316_pack_frame(0x28, data, 2);
+}
+```
+
+### Media Control Command
+
+Command `0x21`, data is 1 byte media control code.
+
+```c
+void send_media_control(media_control_t cmd) {
+ uint8_t data = (uint8_t)cmd;
+ xu316_pack_frame(0x21, &data, 1);
+}
+
+// Usage examples
+send_media_control(MEDIA_KEY_PLAY_PAUSE); // Play/Pause
+send_media_control(MEDIA_KEY_VOLUME_UP); // Volume up
+send_media_control(MEDIA_KEY_VOLUME_DOWN); // Volume down
+```
+
+### Set Audio Mode
+
+Command `0x23`, data is 5 bytes of audio mode configuration.
+
+```c
+void set_audio_mode(uint8_t mode_index) {
+ // audio_modes is a predefined array of 8 modes
+ xu316_pack_frame(0x23, (uint8_t *)audio_modes[mode_index], 5);
+}
+
+// 8 predefined audio modes
+static const uint8_t audio_modes[][5] = {
+ {0x00, 0x80, 0xa9, 0x00, 0x01}, // UAC2.0->I2S
+ {0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1.0-I2S
+ {0x10, 0x80, 0x65, 0x10, 0x03}, // S/PDIF1 IN-I2S OUT (COAX)
+ {0x00, 0x80, 0x65, 0x10, 0x04}, // S/PDIF2 IN-I2S OUT (OPT)
+ {0x00, 0x80, 0xc5, 0x08, 0x05}, // UAC2.0-SPDIF OUT
+ {0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN-I2S OUT
+ {0x20, 0x80, 0x65, 0x10, 0x07}, // S/PDIF3 IN-I2S OUT (HDMI)
+ {0x30, 0x80, 0x65, 0x10, 0x08} // S/PDIF4 IN-I2S OUT
+};
+```
+
+---
+
+## Consultation and Feedback
+
+
+Click to expand consultation and feedback form
+
+--8<-- "common/customer_form.md"
+
+
\ No newline at end of file
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md
deleted file mode 100644
index b1c4f2a..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md
+++ /dev/null
@@ -1,136 +0,0 @@
----
-title: XU316 Audio Interface Control Code Examples
-description: This document provides code examples for XU316 audio interface control, including serial communication protocols, audio interface configuration, etc., to help developers quickly implement communication functions between XU316 and MCU.
-keywords: XU316 development, audio interface control, MCU communication, I2S configuration, serial protocol, audio sample rate, DSD configuration
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316 Audio Interface Control Code Examples
-
-## Document Description
-
-This document provides code examples for XU316 audio interface control, mainly including the following content:
-
-1. Serial communication protocol definition
-2. Audio interface configuration parameters
-3. Audio sample rate and channel configuration
-4. Volume control parameter settings
-
-These code examples can help developers quickly implement communication functions between XU316 and MCU, as well as configure various audio interface parameters.
-
-## Serial Communication Protocol
-
-### Protocol Definition
-```c
-#define SWAP16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
-#define SWAP32(x) ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
-/* Protocol parsing */
-#define UART_FRAME_HEAD 0xAA
-#define UART_FRAME_TAIL 0x55
-#define HEX_UPPERCASE 0
-#define HEX_LOWERCASE 1
-#define HEX_TABLE HEX_UPPERCASE
-// Data frame structure
-typedef struct
-{
- uint8_t head; // Frame header 0xAA
- uint8_t cmd; // Command byte
- uint8_t len; // Data length
- uint8_t data[32]; // Data field
- uint8_t check; // Checksum
- uint8_t tail; // Frame tail 0x55
-} uart_frame_t;
-```
-
-### Serial Buffer Management
-```c
-/* Serial port */
-/* buffer sizes */
-#define RX_BUFFER_SIZE 256
-#define TX_BUFFER_SIZE 256
-#define TX_BUFFER_NUM 2 // Double buffering
-
-typedef struct
-{
- uint8_t buffer[TX_BUFFER_SIZE];
- uint16_t size;
- uint8_t busy;
-} TX_BUFFER;
-
-typedef struct
-{
- TX_BUFFER tx_buf[TX_BUFFER_NUM];
- uint8_t curr_buf;
- uint8_t next_buf;
- uint8_t dma_sending;
-} UART_TX_MANAGER;
-typedef enum
-{
- LOG_SEND,
- LOG_RECV,
- LOG_USER,
- LOG_ERR
-} log_dir_t;
-```
-
-## Audio Interface Configuration
-
-### Interface Mode Configuration
-```c
-// I2S master/slave mode configuration
-#define I2S_MODE I2S_MODE_MASTER // I2S master mode, XU316 as I2S master device
-// Synchronization mode configuration
-#define SYNC_MODE SYNC // Synchronous mode for audio clock synchronization
-// MIDI interface configuration
-#define MIDI_MODE MIDI_MODE_ENABLE // MIDI function enabled
-// SPDIF input interface configuration
-#define SPDIF_IN_MODE SPDIF_IN_MODE_ENABLE // SPDIF input function enabled
-// SPDIF output interface configuration
-#define SPDIF_OUT_MODE SPDIF_OUT_MODE_ENABLE // SPDIF output function enabled
-// ADAT input interface configuration (ADAT is an 8-channel digital audio transmission format)
-#define ADAT_IN_MODE ADAT_IN_MODE_ENABLE // ADAT input function enabled
-// ADAT output interface configuration
-#define ADAT_OUT_MODE ADAT_OUT_MODE_ENABLE // ADAT output function enabled
-// DSD output interface configuration (DSD is Direct Stream Digital for high-resolution audio)
-#define DSD_OUT_MODE DSD_OUT_MODE_ENABLE // DSD output function enabled
-```
-
-### Audio Parameter Configuration
-```c
-// Initialize audio sample rate
-#define AUDIO_SAMPLE_RATE (uint8_t)AUDIO_SAMPLE_RATE_44100
-#define MQA_MODE MQA_MODE_DISABLE
-#define AUDIO_CLASS AUDIO_CLASS_UAC1
-#define AUDIO_WIDTH AUDIO_WIDTH_24
-// Initialize audio channels
-#define AUDIO_INPUT_CHANNEL 9
-#define AUDIO_OUTPUT_CHANNEL 3
-// Initialize audio type
-#define AUDIO_MODE USB_MODE
-// Mute duration 2 0-65535 (ms)
-#define MUTE_DURATION 100
-// Microphone default volume
-#define MIC_VOLUME 10
-// DAC left channel default volume 1 See DAC volume field description
-#define DAC_L_VOLUME 30
-// DAC right channel default volume 1 See DAC volume field description
-#define DAC_R_VOLUME 20
-```
-
-
-
-
-```
diff --git a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
index 3abb6d5..131a1fd 100644
--- a/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
+++ b/en/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
@@ -1,67 +1,43 @@
---
-title: A316 No-Development Firmware MCU Development Guide
-description: This document provides comprehensive guidance for XU316-to-MCU communication development, including development steps, reference documentation, and frequently asked questions to help developers quickly implement communication functionality between XU316 and MCU.
-keywords: XU316 development, MCU communication development, audio interface control, communication protocol, development guidance, FAQ
+title: A316 Zero-Code Firmware MCU Development Guide
+description: Entry-level guidance for XU316-MCU communication development, helping developers understand the protocol, implement communication, and run example code step by step.
+keywords: XU316 development, MCU communication development, communication protocol, development guide, code examples
---
--8<-- "common/phaten_xmos_support_img.md"
-# A316 No-Development Firmware MCU Development Guide
+# A316 Zero-Code Firmware MCU Development Guide
## Development Overview
-This document provides comprehensive guidance for XU316-to-MCU communication development, helping developers implement communication functionality between XU316 and MCU in the correct sequence. The development process is divided into the following main steps, each with corresponding reference documentation and detailed instructions.
+This document helps developers implement serial communication between XU316 and MCU in the correct sequence. The development process is divided into the following steps, each with corresponding reference documentation.
## Development Steps
-=== "Step 1: Understanding Basic Concepts and Protocol Structure"
- **Objective**: Understand the basic concepts and protocol structure of XU316-MCU communication
+=== "Step 1: Understand Protocol Structure"
+ **Objective**: Understand the frame format and command definitions for XU316-MCU communication
- **Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Command Macro Definitions](Command_Macros.md)
+ **Reference Documentation**: [:material-file-document-outline: XU316 MCU Communication Protocol](../../protocols/xu316_zerocode_protocol.md)
**Key Learning Points**:
- - Master the basic structure of frame format (frame header, command, data length, checksum, frame tail)
- - Understand data length definitions for various commands
+ - Master the frame format (header `0x55AA`, version, command, data length, checksum)
+ - Understand data length definitions for each command
- Familiarize with audio format enumerations and type definitions
- - Learn the composition of command data structures
-=== "Step 2: Implementing Basic Communication Functions"
- **Objective**: Implement basic communication functions between XU316 and MCU
+=== "Step 2: Run Example Code"
+ **Objective**: Run the complete protocol communication example based on GD32 platform
- **Reference Documentation**: [:material-file-document-outline: XU316 and MCU Communication Protocol Reference](Command_Reference.md)
+ **Reference Documentation**: [:material-file-document-outline: XU316 MCU Development Example](./Development_Guide.md)
- **Development Tasks**:
+ **Example Contents**:
- - Implement ring buffer initialization and management
- - Implement data frame encapsulation and transmission
- - Implement data frame reception and parsing
- - Implement CRC32 and simple checksum calculation
- - Implement basic communication protocol processing flow
-
-=== "Step 3: Configuring Audio Interfaces and Parameters"
- **Objective**: Configure XU316 audio interfaces and related parameters
-
- **Reference Documentation**: [:material-file-document-outline: XU316 Audio Interface Control Code Examples](Product_Content.md)
-
- **Development Tasks**:
-
- - Configure I2S master/slave mode
- - Set audio sampling rate and bit depth
- - Configure audio channel count
- - Set volume control parameters
- - Configure various audio interfaces (SPDIF, ADAT, DSD, etc.)
-
-
+ - Minimal usage example (initialization, interrupt reception, main loop processing)
+ - Protocol layer functions (checksum calculation, frame packing, frame extraction, data processing)
+ - Complete command parsing code (0x00 ~ 0xEE)
+ - MCU-initiated commands (unmute, media control, audio mode setting, etc.)
@@ -74,125 +50,17 @@ This document provides comprehensive guidance for XU316-to-MCU communication dev
-
-
-
-
-
+
\ No newline at end of file
diff --git a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/index.md b/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/index.md
deleted file mode 100644
index f1dd9ea..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/index.md
+++ /dev/null
@@ -1,198 +0,0 @@
----
-title: A316 Firmware-Free MCU Development Guide
-description: This document provides comprehensive guidance on XU316 and MCU communication development, including development steps, reference documentation, and FAQ, helping developers quickly implement communication functions between XU316 and MCU.
-keywords: XU316 development, MCU communication development, audio interface control, communication protocol, development guide, FAQ
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# A316 Firmware-Free MCU Development Guide
-
-## Development Overview
-
-This document provides comprehensive guidance on XU316 and MCU communication development, helping developers implement communication functions between XU316 and MCU in the correct sequence. The development process is divided into the following main steps, each with corresponding reference documentation and detailed instructions.
-
-## Development Steps
-
-
-
-=== "Step 1: Understanding Basic Concepts and Protocol Structure"
- **Objective**: Understand the basic concepts and protocol structure of XU316 and MCU communication
-
- **Reference Document**: [:material-file-document-outline: XU316 and MCU Communication Protocol Command Macro Definitions](命令的相关宏.md)
-
- **Key Learning Points**:
-
- - Master the basic structure of frame format (frame header, command, data length, checksum, frame tail)
- - Understand data length definitions for various commands
- - Familiarize with audio format enumerations and type definitions
- - Understand the composition of command data structures
-
-=== "Step 2: Implementing Basic Communication Functions"
- **Objective**: Implement basic communication functions between XU316 and MCU
-
- **Reference Document**: [:material-file-document-outline: XU316 and MCU Communication Protocol Reference](命令相关.md)
-
- **Development Tasks**:
-
- - Implement ring buffer initialization and management
- - Implement data frame encapsulation and transmission
- - Implement data frame reception and parsing
- - Implement CRC32 and simple checksum calculation
- - Implement basic communication protocol processing flow
-
-=== "Step 3: Configuring Audio Interfaces and Parameters"
- **Objective**: Configure XU316 audio interfaces and related parameters
-
- **Reference Document**: [:material-file-document-outline: XU316 Audio Interface Control Code Examples](产品内容相关.md)
-
- **Development Tasks**:
-
- - Configure I2S master/slave mode
- - Set audio sampling rate and bit depth
- - Configure audio channel count
- - Set volume control parameters
- - Configure various audio interfaces (SPDIF, ADAT, DSD, etc.)
-
-
-
-
-
-## Inquiry and Feedback
-
-
-Click to expand inquiry and feedback form
-
---8<-- "common/customer_form.md"
-
-
-
-
-
-
-
-
-
-
diff --git a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/产品内容相关.md b/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/产品内容相关.md
deleted file mode 100644
index 6e30e9a..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/产品内容相关.md
+++ /dev/null
@@ -1,138 +0,0 @@
----
-title: XU316 Audio Interface Control Code Examples
-description: This document provides code examples for XU316 audio interface control, including serial communication protocols, audio interface configuration, etc., to help developers quickly implement communication between XU316 and MCU.
-keywords: XU316 development, audio interface control, MCU communication, I2S configuration, serial protocol, audio sample rate, DSD configuration
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316 Audio Interface Control Code Examples
-
-## Document Overview
-
-This document provides code examples for XU316 audio interface control, mainly covering the following content:
-
-1. Serial communication protocol definitions
-2. Audio interface configuration parameters
-3. Audio sample rate and channel configuration
-4. Volume control parameter settings
-
-These code examples help developers quickly implement communication between XU316 and MCU, as well as configure various audio interface parameters.
-
-## Serial Communication Protocol
-
-### Protocol Definitions
-```c
-#define SWAP16(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
-#define SWAP32(x) ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
-/* Protocol parsing */
-#define UART_FRAME_HEAD 0xAA
-#define UART_FRAME_TAIL 0x55
-#define HEX_UPPERCASE 0
-#define HEX_LOWERCASE 1
-#define HEX_TABLE HEX_UPPERCASE
-// Data frame structure
-typedef struct
-{
- uint8_t head; // Frame header 0xAA
- uint8_t cmd; // Command byte
- uint8_t len; // Data length
- uint8_t data[32]; // Data area
- uint8_t check; // Checksum
- uint8_t tail; // Frame tail 0x55
-} uart_frame_t;
-```
-
-### Serial Buffer Management
-```c
-/* UART */
-/* buffer sizes */
-#define RX_BUFFER_SIZE 256
-#define TX_BUFFER_SIZE 256
-#define TX_BUFFER_NUM 2 // Double buffering
-
-typedef struct
-{
- uint8_t buffer[TX_BUFFER_SIZE];
- uint16_t size;
- uint8_t busy;
-} TX_BUFFER;
-
-typedef struct
-{
- TX_BUFFER tx_buf[TX_BUFFER_NUM];
- uint8_t curr_buf;
- uint8_t next_buf;
- uint8_t dma_sending;
-} UART_TX_MANAGER;
-typedef enum
-{
- LOG_SEND,
- LOG_RECV,
- LOG_USER,
- LOG_ERR
-} log_dir_t;
-```
-
-## Audio Interface Configuration
-
-### Interface Mode Configuration
-```c
-// I2S master/slave mode configuration
-#define I2S_MODE I2S_MODE_MASTER // I2S master mode, XU316 acts as I2S master device
-// Synchronization mode configuration
-#define SYNC_MODE SYNC // Synchronization mode for audio clock synchronization
-// MIDI interface configuration
-#define MIDI_MODE MIDI_MODE_ENABLE // MIDI functionality enabled
-// SPDIF input interface configuration
-#define SPDIF_IN_MODE SPDIF_IN_MODE_ENABLE // SPDIF input functionality enabled
-// SPDIF output interface configuration
-#define SPDIF_OUT_MODE SPDIF_OUT_MODE_ENABLE // SPDIF output functionality enabled
-// ADAT input interface configuration (ADAT is an 8-channel digital audio transmission format)
-#define ADAT_IN_MODE ADAT_IN_MODE_ENABLE // ADAT input functionality enabled
-// ADAT output interface configuration
-#define ADAT_OUT_MODE ADAT_OUT_MODE_ENABLE // ADAT output functionality enabled
-// DSD output interface configuration (DSD is Direct Stream Digital for high-resolution audio)
-#define DSD_OUT_MODE DSD_OUT_MODE_ENABLE // DSD output functionality enabled
-```
-
-### Audio Parameter Configuration
-```c
-// Initialize audio sample rate
-#define AUDIO_SAMPLE_RATE (uint8_t)AUDIO_SAMPLE_RATE_44100
-#define MQA_MODE MQA_MODE_DISABLE
-#define AUDIO_CLASS AUDIO_CLASS_UAC1
-#define AUDIO_WIDTH AUDIO_WIDTH_24
-// Initialize audio channels
-#define AUDIO_INPUT_CHANNEL 9
-#define AUDIO_OUTPUT_CHANNEL 3
-// Initialize audio type
-#define AUDIO_MODE USB_MODE
-// Mute duration 2 0-65535 (ms)
-#define MUTE_DURATION 100
-// Microphone default volume
-#define MIC_VOLUME 10
-// DAC left channel default volume 1 See DAC volume field description
-#define DAC_L_VOLUME 30
-// DAC right channel default volume 1 See DAC volume field description
-#define DAC_R_VOLUME 20
-```
-
-
-
-
-```
-
-
diff --git a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令的相关宏.md b/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令的相关宏.md
deleted file mode 100644
index 170c994..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令的相关宏.md
+++ /dev/null
@@ -1,286 +0,0 @@
----
-title: XU316 and MCU Communication Protocol Command Macro Definitions
-description: This document provides command macro definitions for XU316 and MCU communication protocol, including frame format, command length, communication protocol, etc., to help developers implement communication functions between XU316 and MCU.
-keywords: XU316 communication protocol, MCU command macro definitions, audio format definitions, communication frame format, command data structure, audio type definitions
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316 and MCU Communication Protocol Command Macro Definitions
-
-## Document Overview
-
-This document provides command macro definitions related to the XU316 and MCU communication protocol, including the following content:
-
-1. Communication frame format definitions
-2. MCU command data length definitions
-3. Communication protocol command enumerations
-4. Audio format and type definitions
-5. Command data structure definitions
-
-These macro definitions and data structures form the foundation of XU316 and MCU communication. Developers need to correctly understand and use these definitions to implement communication functions.
-
-## Communication Frame Format
-
-### Basic Frame Format Definitions
-```c
-#define FRAME_HEADER_H 0x55
-#define FRAME_HEADER_L 0xAA
-#define PROTOCOL_VERSION 0x01
-#define PROTOCOL_VERSION_RX 0x03
-```
-
-## Command Data Length Definitions
-
-### XU316 Command Data Length
-```c
-#define CMD00_XU316_DATA_LEN 0x11 // 0x00 command: Start boot (startup options)
-#define CMD01_XU316_DATA_LEN 0x00 // 0x01 command: Read product information (60-byte firmware info)
-#define CMD02_XU316_DATA_LEN 0x00 // 0x02 command: Read power-on configuration (14-byte config parameters)
-#define CMD03_XU316_DATA_LEN 0x00 // 0x03 command: Get audio mode (5-byte mode parameters)
-#define CMD04_XU316_DATA_LEN 0x00 // 0x04 command: Get user configuration (14-byte user settings)
-#define CMD05_XU316_DATA_LEN 0x15 // 0x05 command: Startup complete (no data field)
-
-#define CMDF1_XU316_DATA_LEN 0x03 // 0xF1 command: Version query (3-byte version info)
-
-#define CMD20_XU316_DATA_LEN 0x14 // 0x20 command: Set volume
-#define CMD21_XU316_DATA_LEN 0x00 // 0x21 command: Audio effect mode
-#define CMD22_XU316_DATA_LEN 0x02 // 0x22 command: Device status query
-#define CMD23_XU316_DATA_LEN 0x00 // 0x23 command: Bluetooth control
-#define CMD24_XU316_DATA_LEN 0x02 // 0x24 command: Send playback volume
-#define CMD25_XU316_DATA_LEN 0x01 // 0x25 command: Send recording volume
-#define CMD27_XU316_DATA_LEN 0x00 // 0x27 command: Special unmute (no data field)
-#define CMD28_XU316_DATA_LEN 0x01 // 0x28 command: Audio format delay setting (1-byte parameter)
-
-#define CMD_HID_TRANSPARENT_DATA_LEN 0x39 // 0xEE command: HID transparent transmission/OTA upgrade (57 bytes)
-```
-
-### MCU Command Data Length
-```c
-#define CMD00_MCU_DATA_LEN 0x01 // 0x00 command: Start boot (startup options)
-#define CMD01_MCU_DATA_LEN 0x3C // 0x01 command: Read product information (60-byte firmware info)
-#define CMD02_MCU_DATA_LEN 0x0E // 0x02 command: Read power-on configuration (14-byte config parameters)
-#define CMD03_MCU_DATA_LEN 0x05 // 0x03 command: Get audio mode (5-byte mode parameters)
-#define CMD04_MCU_DATA_LEN 0x0E // 0x04 command: Get user configuration (14-byte user settings)
-#define CMD05_MCU_DATA_LEN 0x00 // 0x05 command: Startup complete (no data field)
-
-#define CMDF1_MCU_DATA_LEN 0x00 // 0xF1 command: Version query (no data field)
-
-#define CMD20_MCU_DATA_LEN 0x00 // 0x20 command: Set volume
-#define CMD21_MCU_DATA_LEN 0x01 // 0x21 command: Audio effect mode
-#define CMD22_MCU_DATA_LEN 0x00 // 0x22 command: Device status query
-#define CMD23_MCU_DATA_LEN 0x05 // 0x23 command: Set audio mode
-#define CMD24_MCU_DATA_LEN 0x00 // 0x24 command: Send playback volume
-#define CMD25_MCU_DATA_LEN 0x00 // 0x25 command: Send recording volume
-#define CMD27_MCU_DATA_LEN 0x00 // 0x27 command: Special unmute (no data field)
-#define CMD28_MCU_DATA_LEN 0x00 // 0x28 command: Audio format delay setting (no data field)
-
-#define CMD_HID_TRANSPARENT_MCU_DATA_LEN 0x39 // 0xEE command: HID transparent transmission/OTA upgrade (57 bytes)
-```
-
-## Communication Protocol Command Definitions
-
-### Command Enumeration
-```c
-typedef enum
-{
- /****** Basic Control Commands (0x00-0x05) ******/
- CMD_STARTUP = 0x00, // System startup
- CMD_GET_PRODUCT_INFO = 0x01, // Product information query
- CMD_GET_BOOT_CFG = 0x02, // Power-on configuration read
- CMD_GET_AUD_MODE = 0x03, // Audio mode get
- CMD_GET_USER_CFG = 0x04, // User configuration get
- CMD_STARTUP_COMPLETE = 0x05, // Startup complete notification
-
- CMD_GET_VERSION = 0xF1, // Version query
-
- /****** Business Control Commands (0x20-0x2F) ******/
- CMD_REPORT_STATUS = 0x20, // Status report
- CMD_MEDIA_CONTROL = 0x21, // Media control
- CMD_SET_PLAY_FORMAT = 0x22, // Audio format setting
- CMD_SET_AUDIO_MODE = 0x23, // Audio mode setting
- CMD_SET_PLAY_VOL = 0x24, // Playback volume setting
- CMD_SET_REC_VOL = 0x25, // Recording volume setting
- CMD_SPECIAL_UNMUTE = 0x27, // Special unmute
- CMD_SET_AUDIO_FORMAT_DELAY = 0x28, // Audio format delay setting
-
- CMD_HID_TRANSPARENT = 0xEE, // HID transparent transmission/OTA upgrade command
-
- CMD_COUNT = CMD_SET_REC_VOL + 1 // Total number of currently supported commands
-
-} mcu_command_t;
-```
-
-### Boot Option Enumeration (Bitmask Mode)
-
-!!! note
- **Boot Option Enumeration (Bitmask Mode)**
- **Uses uint8_t to ensure single-byte storage, supports multiple option combinations**
-
-```c
-typedef enum
-{
- BOOT_OPTION_USE_DEFAULTS = 0x00, // Use all default configurations
- BOOT_OPTION_UPDATE_BASIC_INFO = 0x01, // Update basic product information (bit0)
- BOOT_OPTION_UPDATE_POWER_CFG = 0x02, // Update power-on configuration information (bit1)
- BOOT_OPTION_UPDATE_OTHER_CFG = 0x04 // Reserved configuration, currently unused (bit2)
-} boot_option_t;
-```
-
-### Media Control Enumeration
-```c
-typedef enum
-{
- MEDIA_KEY_VOLUME_UP = 0x00, // Volume up
- MEDIA_KEY_VOLUME_DOWN = 0x01, // Volume down
- MEDIA_KEY_PLAY_PAUSE = 0x02, // Play/pause
- MEDIA_KEY_NEXT_TRACK = 0x03, // Next track
- MEDIA_KEY_PREV_TRACK = 0x04, // Previous track
- MEDIA_KEY_FAST_FORWARD = 0x05, // Fast forward
- MEDIA_KEY_REWIND = 0x06, // Rewind
- MEDIA_KEY_MUTE = 0x07 // Mute toggle
-
- // Reserved extension space (0x08-0xFF reserved for protocol)
-
-} media_control_t;
-```
-
-## Audio Format Definitions
-
-!!! note
- **Audio Stream Format Enumeration (AES67-2020 Standard Compatible)**
- **Explicitly specifies uint8_t as underlying type to ensure 1-byte storage**
-
-### Audio Stream Format Enumeration
-```c
-typedef enum
-{
- // PCM sample rate formats (0x00-0x10)
- AUDIO_PCM_44100 = 0x00,
- AUDIO_PCM_48000 = 0x01,
- AUDIO_PCM_88200 = 0x02,
- AUDIO_PCM_96000 = 0x03,
- AUDIO_PCM_176400 = 0x04,
- AUDIO_PCM_192000 = 0x05,
- AUDIO_PCM_352800 = 0x06,
- AUDIO_PCM_384000 = 0x07,
- AUDIO_PCM_705600 = 0x08,
- AUDIO_PCM_768000 = 0x09,
- AUDIO_PCM_1441200 = 0x0A,
- AUDIO_PCM_1536000 = 0x0B,
- AUDIO_PCM_32000 = 0x0C,
- AUDIO_PCM_64000 = 0x0D,
- AUDIO_PCM_128000 = 0x0E,
- AUDIO_PCM_256000 = 0x0F,
- AUDIO_PCM_512000 = 0x10,
-
- // DSD formats (0x11-0x15)
- AUDIO_DSD_64 = 0x11,
- AUDIO_DSD_128 = 0x12,
- AUDIO_DSD_256 = 0x13,
- AUDIO_DSD_512 = 0x14,
- AUDIO_DSD_1024 = 0x15,
-
- // MQA formats (0x16-0x2D)
- AUDIO_MQA_44100 = 0x16,
- AUDIO_MQA_88200 = 0x17,
- AUDIO_MQA_176400 = 0x18,
- AUDIO_MQA_352800 = 0x19,
- AUDIO_MQA_705600 = 0x1A,
- AUDIO_MQA_1411200 = 0x1B,
- AUDIO_MQA_2822400 = 0x1C,
- AUDIO_MQA_5644800 = 0x1D,
-
- // -- 48kHz series --
- AUDIO_MQA_48000 = 0x1E,
- AUDIO_MQA_96000 = 0x1F,
- AUDIO_MQA_192000 = 0x20,
- AUDIO_MQA_384000 = 0x21,
- AUDIO_MQA_768000 = 0x22,
- AUDIO_MQA_1536000 = 0x23,
- AUDIO_MQA_3072000 = 0x24,
- AUDIO_MQA_6144000 = 0x25,
-
- // -- Other base frequency series --
- AUDIO_MQA_64000 = 0x26,
- AUDIO_MQA_128000 = 0x27,
- AUDIO_MQA_256000 = 0x28,
- AUDIO_MQA_512000 = 0x29,
- AUDIO_MQA_1024000 = 0x2A,
- AUDIO_MQA_2048000 = 0x2B,
- AUDIO_MQA_4096000 = 0x2C,
- AUDIO_MQA_8192000 = 0x2D,
-
- // Special reserved value
- AUDIO_NO_USED = 0xFF
-
-} audio_format_t;
-```
-
-### Audio Type Enumeration
-!!! note
- **Audio Type Enumeration (AES67-2020 Standard Compatible)**
- **Explicitly specifies uint8_t as underlying type to ensure 1-byte storage**
-
-```c
-typedef enum
-{
- AUDIO_TYPE_PCM = 0x00, // PCM standard audio
- AUDIO_TYPE_RESERVE = 0x01, // Protocol reserved field
- AUDIO_TYPE_MQA = 0x02, // MQA encoded audio
- AUDIO_TYPE_MQB = 0x03, // MQB encoded audio (secondary extension)
- AUDIO_TYPE_MQA_STUDIO = 0x04, // MQA Studio master quality
- AUDIO_TYPE_DSD = 0x05 // Direct Stream Digital
-
- // 0x06-0xFF reserved for future expansion
-
-} audio_type_t;
-```
-
-## Command Data Structure
-
-### Data Structure Definition
-```c
-typedef uint8_t byte_pair[2];
-// Command data structure
-typedef struct __attribute__((packed))
-{
- uint8_t boot_option; // 0x00: Boot option data
- // Product basic information
- uint8_t vid_uac1[2]; // UAC1.0 vendor ID
- uint8_t pid_uac1[2]; // UAC1.0 product ID
- uint8_t vid_uac2[2]; // UAC2.0 vendor ID
- uint8_t pid_uac2[2]; // UAC2.0 product ID
- uint8_t product_manufacturer[16]; // Manufacturer name
- uint8_t product_name[16]; // Product name
- uint8_t product_serial[16]; // Serial number
- uint8_t basic_info_crc[4]; // Basic information CRC32
- // User configuration is power-on configuration and also application runtime parameters
- uint8_t startup_status; // Startup status
- uint8_t audio_mode[5];
- uint8_t mute_duration[2]; // Mute duration (ms)
- uint8_t mic_volume; // Microphone volume (recording volume)
- uint8_t dac_l_volume; // Left channel volume (0-255)
- uint8_t dac_r_volume; // Right channel volume (0-255)
- uint8_t power_cfg_crc[4]; // Power-on configuration CRC32
- // Application runtime parameters
- uint8_t media_control; // Media control command
- uint8_t audio_format; // Audio format code
- uint8_t audio_type; // Audio type code
-} mcu_data_t;
-```
-
-
-
diff --git a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令相关.md b/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令相关.md
deleted file mode 100644
index e1546e6..0000000
--- a/en/docs/dev_doc/sdk_examples/XU316和MCU通讯的示例代码/命令相关.md
+++ /dev/null
@@ -1,407 +0,0 @@
----
-title: XU316 and MCU Communication Protocol Reference
-description: Detailed description of the communication protocol between XU316 and MCU, including data structures, command formats, and processing flows
-keywords: XU316, MCU, communication protocol, command reference
-hide:
- -toc
----
-
---8<-- "common/phaten_xmos_support_img.md"
-
-# XU316 and MCU Communication Protocol Reference
-
-## 1. Basic Data Structures
-
-### 1.1 Ring Buffer
-```c
-#define RING_BUFFER_SIZE 256 // Ring buffer size for UART communication buffering
-
-typedef struct {
- uint8_t buffer[RING_BUFFER_SIZE]; // Data storage area
- volatile uint16_t head; // Write position pointer
- volatile uint16_t tail; // Read position pointer
- volatile uint16_t count; // Current data count
-} ring_buffer_t;
-```
-
-### 1.2 Audio Mode Definitions
-```c
-// Audio mode configuration array, each mode contains 5-byte configuration data
-static const uint8_t audio_modes[][5] = {
- {0x00, 0x80, 0xa9, 0x00, 0x01}, // USB-no-mqa mode
- {0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1 mode
- {0x10, 0x80, 0x65, 0x10, 0x03}, // COAX mode
- {0x00, 0x80, 0x65, 0x10, 0x04}, // OPT mode
- {0x00, 0x80, 0xc5, 0x08, 0x05}, // SPDIF OUT mode
- {0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN mode
- {0x20, 0x80, 0x65, 0x10, 0x07} // HDMI mode
-};
-
-// Corresponding mode name array
-static const char *mode_names[] = {
- "USB-no-mqa",
- "UAC1",
- "COAX",
- "OPT",
- "SPDIF OUT",
- "I2S IN",
- "HDMI"
-};
-```
-
-## 2. Initialization and Configuration
-
-### 2.1 Device Initialization Information Print
-```c
-#define AUDIO_MODE_COUNT (sizeof(audio_modes) / sizeof(audio_modes[0]))
-
-void print_init_info(void)
-{
- log_data(LOG_USER, "----------Device initialized----------\n");
- // Print UAC1.0 device information
- log_data(LOG_USER, "VID1: %02X%02X", mcu_data.vid_uac1[0], mcu_data.vid_uac1[1]);
- log_data(LOG_USER, "PID1: %02X%02X", mcu_data.pid_uac1[0], mcu_data.pid_uac1[1]);
- // Print UAC2.0 device information
- log_data(LOG_USER, "VID2: %02X%02X", mcu_data.vid_uac2[0], mcu_data.vid_uac2[1]);
- log_data(LOG_USER, "PID2: %02X%02X", mcu_data.pid_uac2[0], mcu_data.pid_uac2[1]);
- // Print product information
- log_data(LOG_USER, "Manufacturer: %s", mcu_data.product_manufacturer);
- log_data(LOG_USER, "Name: %s", mcu_data.product_name);
- log_data(LOG_USER, "Serial: %s", mcu_data.product_serial);
- // Print CRC checksum information
- log_data(LOG_USER, "Basic Info CRC: %02X%02X%02X%02X",
- mcu_data.basic_info_crc[0], mcu_data.basic_info_crc[1],
- mcu_data.basic_info_crc[2], mcu_data.basic_info_crc[3]);
- log_data(LOG_USER, "Power Config CRC: %02X%02X%02X%02X",
- mcu_data.power_cfg_crc[0], mcu_data.power_cfg_crc[1],
- mcu_data.power_cfg_crc[2], mcu_data.power_cfg_crc[3]);
-}
-```
-
-### 2.2 Ring Buffer Initialization
-```c
-void ring_buffer_init(void) {
- uart_ring_buffer.head = 0; // Initialize write position
- uart_ring_buffer.tail = 0; // Initialize read position
- uart_ring_buffer.count = 0; // Initialize data count
-}
-```
-
-### 2.3 Product Information Initialization
-```c
-void xu316_init(void)
-{
- // Default audio mode configuration (USB UAC2.0)
- uint8_t audio_mode[5] = {0x00, 0x80, 0xa9, 0x00, 0x01};
-
- // Configure UAC1.0 device information
- mcu_data.vid_uac1[0] = 0x20;
- mcu_data.vid_uac1[1] = 0xB1; // VID = 0x20B1
- mcu_data.pid_uac1[0] = 0x00;
- mcu_data.pid_uac1[1] = 0x17; // PID = 0x0017
-
- // Configure UAC2.0 device information
- mcu_data.vid_uac2[0] = 0x20;
- mcu_data.vid_uac2[1] = 0xB1; // VID = 0x20B1
- mcu_data.pid_uac2[0] = 0x00;
- mcu_data.pid_uac2[1] = 0x16; // PID = 0x0016
-
- // Configure product information
- memcpy(mcu_data.product_manufacturer, "Phaten", 6);
- // Set product name
- memcpy(mcu_data.product_name, "XMOS XU316", 11);
- // Set product serial number
- memcpy(mcu_data.product_serial, "123456789ABCDEF", 15);
-
- // Calculate and store basic information CRC32 checksum (56 bytes)
- crc = calculate_crc32(mcu_data.vid_uac1, 56);
- mcu_data.basic_info_crc[0] = (crc >> 24) & 0xFF;
- mcu_data.basic_info_crc[1] = (crc >> 16) & 0xFF;
- mcu_data.basic_info_crc[2] = (crc >> 8) & 0xFF;
- mcu_data.basic_info_crc[3] = crc & 0xFF;
-
- // Initialize device status and audio configuration
- mcu_data.startup_status = 0x00;
- memcpy(&mcu_data.audio_mode, audio_mode, 5);
-
- // Configure mute duration (400ms)
- mcu_data.mute_duration[0] = MUTE_DURATION_CONFIG >> 8;
- mcu_data.mute_duration[1] = MUTE_DURATION_CONFIG;
-
- // Initialize volume settings
- mcu_data.mic_volume = MIC_VOLUME_CONFIG;
- // Initialize left and right channel DAC volume
- mcu_data.dac_l_volume = DAC_L_VOLUME_CONFIG;
- mcu_data.dac_r_volume = DAC_R_VOLUME_CONFIG;
-
- // Calculate and store power configuration CRC32 checksum (10 bytes)
- crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
- mcu_data.power_cfg_crc[0] = (crc >> 24) & 0xFF;
- mcu_data.power_cfg_crc[1] = (crc >> 16) & 0xFF;
- mcu_data.power_cfg_crc[2] = (crc >> 8) & 0xFF;
- mcu_data.power_cfg_crc[3] = crc & 0xFF;
-
- // Initialize communication buffer
- ring_buffer_init();
-}
-```
-
-## 3. Communication Buffer Operations
-
-### 3.1 Ring Buffer Operation Functions
-```c
-// Write data to ring buffer
-uint8_t ring_buffer_write(uint8_t *data, uint16_t len) {
- uint16_t i;
- for(i = 0; i < len; i++) {
- if(uart_ring_buffer.count >= RING_BUFFER_SIZE) {
- return 0; // Buffer full, write failed
- }
- uart_ring_buffer.buffer[uart_ring_buffer.head] = data[i];
- uart_ring_buffer.head = (uart_ring_buffer.head + 1) % RING_BUFFER_SIZE;
- uart_ring_buffer.count++;
- }
- return 1; // Write successful
-}
-
-// Read data from ring buffer
-uint8_t ring_buffer_read(uint8_t *data, uint16_t len) {
- uint16_t i;
- if(uart_ring_buffer.count < len) {
- return 0; // Insufficient data
- }
- for(i = 0; i < len; i++) {
- data[i] = uart_ring_buffer.buffer[uart_ring_buffer.tail];
- uart_ring_buffer.tail = (uart_ring_buffer.tail + 1) % RING_BUFFER_SIZE;
- uart_ring_buffer.count--;
- }
- return 1; // Read successful
-}
-
-// Peek data (without moving read pointer)
-uint8_t ring_buffer_peek(uint8_t *data, uint16_t len) {
- uint16_t i;
- uint16_t temp_tail = uart_ring_buffer.tail;
- for(i = 0; i < len; i++) {
- data[i] = uart_ring_buffer.buffer[temp_tail];
- temp_tail = (temp_tail + 1) % RING_BUFFER_SIZE;
- }
- return 0; // Peek successful
-}
-```
-
-## 4. Checksum Calculation
-
-### 4.1 CRC32 Calculation
-```c
-uint32_t calculate_crc32(const uint8_t *buffer, uint32_t length)
-{
- uint32_t crc = 0xFFFFFFFF;
- const uint32_t poly = 0xEDB88320; // CRC32 polynomial
-
- for (size_t i = 0; i < length; i++) {
- crc ^= buffer[i];
- for (int j = 0; j < 8; j++) {
- if (crc & 1) {
- crc = (crc >> 1) ^ poly;
- } else {
- crc >>= 1;
- }
- }
- }
- return ~crc; // Return CRC32 checksum value
-}
-
-// Calculate simple checksum
-uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len)
-{
- uint8_t sum = 0;
- for (uint8_t i = 0; i < len; i++) {
- sum += data[i];
- }
- return sum;
-}
-```
-
-## 5. Communication Protocol Processing
-
-### 5.1 Frame Validation
-```c
-// Validate frame data integrity
-uint8_t uart_frame_check(uint8_t *buf, uint8_t len)
-{
- // Check minimum length requirement
- if (len < 6) { // Header(2) + Version(1) + Command(1) + Length(2) + Checksum(1)
- return 0;
- }
-
- // Verify frame header
- if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
- return 0;
- }
-
- // Get data length (big-endian)
- uint16_t data_len = buf[4];
-
- // Verify data length validity
- if (data_len > 256 || len < (data_len + 6)) {
- return 0;
- }
-
- // Calculate and verify checksum
- uint8_t sum = xu316_calc_checksum(buf, data_len + 5);
- if (sum != buf[data_len + 5]) {
- return 0;
- }
-
- LOG_TEMP(LOG_RECV, "", buf, len);
- return 1;
-}
-```
-
-### 5.2 Data Frame Encapsulation
-```c
-int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len)
-{
- uint8_t tx_data[256] = {0};
- if (len >= 255) {
- return 0;
- }
-
- // Construct frame header
- tx_data[0] = FRAME_HEADER_H;
- tx_data[1] = FRAME_HEADER_L;
- tx_data[2] = PROTOCOL_VERSION_RX;
- tx_data[3] = cmd;
- tx_data[4] = len;
-
- // Copy data payload
- if (data && len > 0) {
- memcpy(tx_data + 5, data, len);
- }
-
- // Calculate and append checksum
- tx_data[len + 5] = xu316_calc_checksum(tx_data, len + 5);
- len += 6;
-
- // Send data
- usart_dma_send(tx_data, len);
- LOG_INFO("Sending frame: cmd=0x%02X, len=%d", cmd, len);
- LOG_TEMP(LOG_SEND, "", tx_data, len);
- return len;
-}
-```
-
-### 5.3 Frame Length Check
-```c
-int check_frame_length(uint8_t *buf, uint16_t len) {
- // Verify frame header
- if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
- LOG_DEBUG("Frame header check failed %02x %02x", buf[0], buf[1]);
- return -1;
- }
- // Get data length (big-endian)
- int data_len = buf[4];
- // Return complete frame length
- return data_len + 6;
-}
-```
-
-### 5.4 Data Reception Processing
-```c
-void uart_data_process(void)
-{
- uint8_t peek_buffer[8]; // Peek buffer
- uint8_t process_buffer[256]; // Processing buffer
- int frame_length;
-
- while(uart_ring_buffer.count >= 6) { // At least 6 bytes needed to start checking
- // Peek frame header information
- ring_buffer_peek(peek_buffer, 6);
-
- // Debug output
- for(int i = 0; i < 6; i++) {
- LOG_DEBUG("peek_buffer[%d]: %02x", i, peek_buffer[i]);
- }
-
- // Check frame length
- frame_length = check_frame_length(peek_buffer, 6);
- if(frame_length < 0) {
- // Invalid frame, discard one byte
- uint8_t dummy;
- ring_buffer_read(&dummy, 1);
- LOG_ERROR("Frame length check failed %02x", dummy);
- continue;
- }
-
- // Check if enough data is available
- if(uart_ring_buffer.count < frame_length) {
- LOG_ERROR("Not enough data");
- break; // Wait for more data
- }
-
- // Read and process complete frame
- if(ring_buffer_read(process_buffer, frame_length)) {
- uart_data_parse();
- }
- }
-}
-```
-
-### 5.5 Data Parsing and Processing
-```c
-int uart_data_parse(void)
-{
- int ret = 0;
- uint8_t cmd = 0;
- uint16_t data_len = 0;
- uint16_t rx_len = 0;
- uint8_t tmp;
- static uint8_t buffer[256] = {0};
- rx_len = g_rx_count;
-
- // Verify frame integrity
- ret = uart_frame_check((uint8_t *)g_rx_data, rx_len);
- if (ret == 0) {
- LOG_ERROR("Frame check failed %d", rx_len);
- LOG_TEMP(LOG_RECV, "", g_rx_data, rx_len);
- return -1;
- }
-
- // Parse frame information
- data_len = rx_len - 6;
- cmd = g_rx_data[3];
- if (g_rx_data[4] != data_len) {
- LOG_ERROR("Data length mismatch: expected %d, got %d", g_rx_data[4], data_len);
- return -1;
- }
-
- LOG_DEBUG("Received frame: cmd=0x%02X, len=%d", cmd, data_len);
- LOG_VERBOSE("--------------------------------");
- LOG_VERBOSE("cmd : %02X", cmd);
- memcpy(buffer, g_rx_data + 5, data_len);
-
- // Process data based on command type
- switch (cmd) {
- case 0x00: // Startup information
- // ... Process startup information ...
- break;
-
- case 0x01: // Basic information
- // ... Process basic information ...
- break;
-
- case 0x02: // Power configuration
- // ... Process power configuration ...
- break;
-
- // ... Other command processing ...
-
- default:
- LOG_ERROR("Unknown command: 0x%02X", cmd);
- break;
- }
-
- return ret;
-}
-```
diff --git a/en/mkdocs.yml b/en/mkdocs.yml
index 2e4de79..c97d95c 100644
--- a/en/mkdocs.yml
+++ b/en/mkdocs.yml
@@ -293,11 +293,11 @@ nav:
- dev_doc/sdk_examples/index.md
- A316 Zero-Code Firmware MCU Development Guide:
- dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
+ - Code Examples:
+ - XU316 MCU Development Example: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
- Zero-Code Test Script: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/ZeroCode_Test_Script.md
- Zero-Code Firmware Development FAQ: dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
- - XU316 and MCU Communication Protocol Command Macro Definitions: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md
- - XU316 and MCU Communication Protocol Reference: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md
- - XU316 Audio Interface Control Code Examples: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md
+
# - 5.1 Standard Firmware Usage Examples:
# - 8711 Development Board Connection Guide: dev_doc/hifi_audio/a316_1926v1/RTL8711dome.md
# - Development Board Hardware Connection Guide: dev_doc/hifi_audio/a316_1926v1/A316-8711-5.1解码无线音频套装制作说明.md
diff --git a/zh/docs/dev_doc/faq/technical_faq/a316_firmware_dev_faq.md b/zh/docs/dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
index 4bea78d..bdb75dc 100644
--- a/zh/docs/dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
+++ b/zh/docs/dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
@@ -277,6 +277,329 @@ keywords: A316固件开发, XU316通信问题, USB设备供电, 固件开发FAQ,
+## 音频输出问题
+
+### Q1: I2S/DSD 数据引脚连接后没有声音输出
+
+
+
+=== "排查步骤"
+ 1. **确认引脚定义**
+ - 不同模式(USB-I2S、SPDIF-IN、ADAT等)的 DATA0/1/2、BCLK、LRCLK 引脚位置可能不同
+ - 对照网站固件介绍确认引脚连接
+ 2. **检查 I2S 格式**
+ - 确认是 I2S 格式、左对齐还是右对齐
+ - 与 DAC 芯片要求是否匹配
+ 3. **确认 MCLK 连接**
+ - 某些 DAC 需要 MCLK 才能正常工作
+ - 检查是否已连接 MCLK 信号线
+ 4. **测量信号波形**
+ - 用示波器检查 BCLK、LRCLK、DATA 线上是否有信号输出
+
+
+
+### Q2: SPDIF 输入(光纤/同轴)没有声音或断断续续
+
+
+
+=== "排查步骤"
+ 1. **时钟限制**
+ - SPDIF-IN 模式只能使用内部时钟
+ - 不要发送 0x26 切换外部时钟命令
+ 2. **检查接收电路**
+ - 光纤接收头或同轴接收电路是否正常
+ - 信号质量是否良好
+ 3. **确认模式匹配**
+ - 发送的 0x23 命令中的模式必须与固件支持的 SPDIF 模式一致
+ 4. **检查信号质量**
+ - SPDIF 信号质量差会导致解码失败
+ - 尝试更换线材或检查接口接触
+
+
+
+### Q3: 切换模式时有爆音(POP Noise)
+
+
+
+=== "解决方案"
+ 1. **使用 MUTE 引脚控制**
+ - 切换模式前将 MUTE 引脚拉低
+ - 切换完成并确认成功后再拉高
+ 2. **配置上电静音时间**
+ - 通过 0x02 命令配置合适的静音时间(0-65535ms)
+ - 给 DAC 足够的稳定时间
+ 3. **DAC 侧配合静音**
+ - MCU 同时控制 DAC 的静音引脚
+ - 实现双重静音保护
+ 4. **检查电源时序**
+ - 确保 DAC 电源稳定后再取消静音
+
+
+
+### Q4: 外部时钟(MCLK)如何正确接入和切换
+
+
+
+=== "操作要点"
+ 1. **确认时钟频率**
+ - 22.5792MHz 对应 44.1kHz 系列
+ - 24.576MHz 对应 48kHz 系列
+ 2. **切换时机**
+ - 在音频流传输前完成时钟切换
+ - 使用 0x26 命令进行切换
+ 3. **SPDIF-IN 限制**
+ - SPDIF 输入模式只能使用内部时钟
+ - 不能切换外部时钟
+ 4. **时钟质量**
+ - 外部时钟的抖动(Jitter)会直接影响音质
+ - 需使用低抖动晶振
+
+
+
+### Q5: 不同采样率切换时有卡顿或爆音
+
+
+
+=== "解决方案"
+ 1. **使用 ASRC 功能**
+ - 特定固件支持 ASRC(异步采样率转换)
+ - 可平滑切换不同采样率
+ 2. **时钟锁定时间**
+ - 采样率切换后 PLL 需要锁定时间
+ - 期间 XU316 会自动静音,属正常现象
+ 3. **DAC 复位**
+ - 某些 DAC 在采样率变化时需要复位
+ - 可在切换后重新初始化 DAC
+ 4. **缓存设置**
+ - 适当增加音频缓冲可减少卡顿
+ - 但会增加延迟
+
+
+
+### Q6: 音频输出有杂音、底噪,如何排查 EMC/EMI 问题
+
+
+
+=== "排查要点"
+ 1. **电源隔离**
+ - 数字电源和模拟电源分开
+ - 使用 LDO 给音频电路供电
+ 2. **地线设计**
+ - 采用单点接地,避免地环路
+ - 数字地和模拟地在一点连接
+ 3. **I2S 走线**
+ - I2S 信号线等长走线
+ - 远离高速数字信号(USB、SPI)
+ - 必要时包地处理
+ 4. **屏蔽处理**
+ - 对敏感模拟信号进行屏蔽
+ - 光纤接收头做好屏蔽罩接地
+ 5. **晶振布局**
+ - MCLK 晶振靠近 XU316 和 DAC 布局
+ - 减少时钟线长度
+
+
+
+## 音频格式支持
+
+### Q1: MQA 音频播放需要注意什么
+
+
+
+=== "注意事项"
+ 1. **选择正确固件**
+ - 需要 MQA 支持必须下载带 Q 的固件(如 XXX_Q.bin)
+ - 不带 Q 的固件不支持 MQA 解码
+ 2. **MQA 渲染器**
+ - XU316 作为 MQA Renderer
+ - 需配合 MQA Core Decoder(如 Tidal 软件解码)使用
+ 3. **软件支持**
+ - 播放端软件需支持 MQA(Tidal、Audirvana 等)
+ 4. **授权问题**
+ - MQA 固件涉及授权,请确保使用正版固件
+ - 未授权会自动重启
+
+
+
+### Q2: DSD 音频播放没有声音或变成噪音
+
+
+
+=== "排查步骤"
+ 1. **确认固件支持**
+ - 查看固件名称是否带 DSD 标识
+ 2. **DSD 格式设置**
+ - 确认是 Native DSD 还是 DoP(DSD over PCM)
+ - 两种格式数据传输方式不同
+ 3. **I2S 数据线连接**
+ - DSD 通常使用 DATA0 或 DATA1 传输
+ - 与 PCM 模式可能使用不同引脚
+ 4. **DAC 支持**
+ - 确认 DAC 芯片支持 DSD 解码
+ - 已正确配置为 DSD 模式
+
+
+
+## 协议命令详解
+
+### Q1: 0x22 报告音频流格式命令的数据如何解析和使用
+
+
+
+=== "使用说明"
+ 1. **触发时机**
+ - XU316 启动成功后 1 秒自动发送
+ - 切换输入/输出模式后 1 秒也会自动发送
+ 2. **数据解析**
+ - 根据固件规格书解析采样率、位深、音频格式(PCM/DSD/DoP)
+ 3. **显示用途**
+ - 用于显示屏显示当前音频格式,如 "PCM 96kHz/24bit" 或 "DSD64"
+ 4. **配合命令**
+ - 获取音频格式后,可用 0x28 命令设置音频延迟时间
+
+
+
+### Q2: 0x24 音量命令的数值范围及 DAC 映射
+
+
+
+=== "使用说明"
+ 1. **音量范围**
+ - 通常为 0-100 或 0-255
+ - 具体范围参考固件规格书
+ 2. **对数映射**
+ - 人耳对音量感知是对数的
+ - 建议将线性值映射为对数曲线后控制 DAC
+ 3. **左右声道处理**
+ - 注意处理左右声道音量是否一致
+ - 部分 DAC 需分别设置左右声道音量
+ 4. **与 0x21 的区别**
+ - 0x21:MCU → XU316 → PC(发送方向)
+ - 0x24:PC → XU316 → MCU(接收方向)
+
+
+
+### Q3: 0x29 USB 连接状态检测有什么用途
+
+
+
+=== "用途说明"
+ - 用于在显示屏上显示 USB 是否连接
+ - 提升用户体验
+
+
+
+### Q4: 录音功能(Microphone)如何配置和使用
+
+
+
+=== "配置说明"
+ - 不是所有固件都支持录音功能
+ - 需查看固件说明确认是否支持
+
+
+
+## 驱动问题
+
+### Q1: 使用不同配置固件后,设备无法正确识别
+
+
+
+=== "问题现象"
+ - 开发或调试中使用不同配置、不同声道的固件后
+ - 设备无法正确识别当前配置
+
+=== "原因"
+ - 改了录音声道数后,Windows 缓存与实际不一致
+
+=== "解决方法"
+ 1. 进入设备管理器
+ 2. 删除音频设备下识别的音频设备,右键卸载
+ 3. 同时删除驱动,然后重新安装驱动
+ 4. 重新插上设备并成功识别
+
+
+
+## 二次开发高频问题
+
+以下内容整理自 XMOS 常见问题,从二次开发/硬件集成开发者视角出发。
+
+### 接口与模式类
+
+#### Q1: I²S 输入只能是 Slave、输出只能是 Master 吗?能不能反向?
+
+
+
+=== "回答"
+ - **不能反向**
+ - 输入:I²S Slave
+ - 输出:I²S Master
+ - 模式 6 也是:I²S(slave) in → I²S(master) out
+ - 二次开发时必须按此时钟关系设计,否则无音频
+
+
+
+#### Q2: S/PDIF 1 和 2 两个输入怎么切换?
+
+
+
+=== "回答"
+ - 由模式编号区分:
+ - 模式 3 = SPDIF1 输入
+ - 模式 4 = SPDIF2 输入
+ - 切换靠 UART 配置或上位机工具,不是自动识别
+
+
+
+### 时钟与采样率转换
+
+#### Q1: 支持 768kHz / DSD512,macOS/Windows 能直接跑吗?
+
+
+
+=== "回答"
+ - **Windows**:需官方 USB 驱动 + UAC2.0
+ - **macOS**:原生免驱 UAC2.0,可直接到 768kHz
+ - **DSD512**:需播放器支持 DoP 或原生 DSD
+ - 限制不在模块,而在系统与播放器
+
+
+
+#### Q2: 多通道能输出到几通道?
+
+
+
+=== "回答"
+ - 属于标准多通道 USB Audio 2.0 架构
+ - 实际为 2~8 通道区间(需看模组手册)
+ - 二次开发按 UAC2.0 通道映射即可
+
+
+
+### 硬件集成
+
+#### Q1: 模块尺寸 19.5×26×0.8mm,是贴片还是插针?
+
+
+
+=== "回答"
+ - 属于超薄模组
+ - 板对板或焊盘式集成,不是插针模块
+ - 二次开发需做 PCB 封装匹配
+
+
+
+#### Q2: 供电 3.0–3.6V,典型 3.3V,能不能 5V 直接供电?
+
+
+
+=== "回答"
+ - **不能**
+ - 必须 3.3V,且要低噪声 LDO
+ - 否则影响 THD+N
+
+
+
## 咨询反馈
点击展开咨询反馈表单
@@ -306,4 +629,3 @@ keywords: A316固件开发, XU316通信问题, USB设备供电, 固件开发FAQ,
}]
}
-
diff --git a/zh/docs/dev_doc/protocols/xu316_zerocode_protocol.md b/zh/docs/dev_doc/protocols/xu316_zerocode_protocol.md
index 240865c..eba2a81 100755
--- a/zh/docs/dev_doc/protocols/xu316_zerocode_protocol.md
+++ b/zh/docs/dev_doc/protocols/xu316_zerocode_protocol.md
@@ -26,7 +26,7 @@ search:
## 一、协议基础规范 :material-connection:
### 1.1 底层通信协议
-
+
**基于UART (Universal Asynchronous Receiver/Transmitter) 协议**
| 参数 | 值 |
@@ -170,7 +170,7 @@ sequenceDiagram
**执行条件**: 启动选项包含0x01(更新基础产品信息)
**步骤**:
-
+
1. XU316发送0x01命令请求读取基础产品信息
2. MCU返回新基础产品信息给XU316
3. XU316更新并保存配置到内部存储
@@ -187,7 +187,7 @@ sequenceDiagram
=== "应用固件加载阶段"
**步骤**:
-
+
1. XU316发送0x03命令获取当前输入输出模式
2. MCU返回当前模式信息给XU316
3. XU316根据返回模式加载对应输入输出模式
@@ -225,7 +225,9 @@ sequenceDiagram
| 0x24 | xu316发送播放音量 | XU316→MCU |
| 0x25 | 发送录音音量 | XU316→MCU |
| 0x26 | 切换MCLK | MCU→XU316 |
-| 0x29 | 报告USB连接状态 | XU316→MCU |
+ | 0x27 | 设置 unmute | MCU→XU316 |
+ | 0x28 | 发送音频格式的时间延迟 | MCU→XU316 |
+ | 0x29 | 报告USB连接状态 | XU316→MCU |
=== "HID-MCU互相透传命令(0xEE-0xEF)"
| 命令字 | 命令描述 | 发送方向 |
@@ -237,6 +239,7 @@ sequenceDiagram
| 命令字 | 命令描述 | 发送方向 |
|:--------:|:---------------------------------------------|:----------:|
| 0xF0 | DAC配置选择命令 | MCU→XU316 |
+ | 0xF1 | 获取固件版本命令 | MCU→XU316 |
!!! note "命令使用说明"
1. 所有命令必须遵循基本帧格式规范
@@ -307,6 +310,24 @@ sequenceDiagram
* 重启原因字段可用于MCU识别XU316重启的具体原因,以便进行不同处理
* 当需要更新多项信息时,MCU可将多个选项通过位操作组合在一起
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 00 01 03 06
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的数据 |
+ | 命令字 | 1字节 | `00` | 表示当前命令是“开始启动” |
+ | 数据长度 | 1字节 | `01` | 表示后面紧跟着 1 字节的数据区 |
+ | 启动选项 | 1字节 | `03` | 表示 `0x01` 和 `0x02` 同时生效,也就是既要更新产品基础信息,也要更新上电配置信息 |
+ | 校验和 | 1字节 | `06` | 从 `55` 开始到 `03` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.2.2 读取产品信息(0x01)
=== "命令格式"
@@ -348,6 +369,31 @@ sequenceDiagram
CRC: 4字节 (32位CRC校验)
```
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 01 3C 20 B1 00 17 20 B1 00 16 50 48 41 54 45 4E 00 00 00 00 00 00 00 00 00 00 58 55 33 31 36 20 44 41 43 00 00 00 00 00 00 00 53 4E 32 34 30 30 30 31 00 00 00 00 00 00 00 00 12 34 56 78 D9
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的数据 |
+ | 命令字 | 1字节 | `01` | 表示当前命令是“读取产品信息” |
+ | 数据长度 | 1字节 | `3C` | 表示后面紧跟着 60 字节的数据区 |
+ | VID1 | 2字节 | `20 B1` | UAC1.0 的 USB VID |
+ | PID1 | 2字节 | `00 17` | UAC1.0 的 USB PID |
+ | VID2 | 2字节 | `20 B1` | UAC2.0 的 USB VID |
+ | PID2 | 2字节 | `00 16` | UAC2.0 的 USB PID |
+ | ManufactureName | 16字节 | `50 48 41 54 45 4E 00 00 00 00 00 00 00 00 00 00` | ASCII 字符串 `PHATEN`,后面不足 16 字节的部分用 `00` 补齐 |
+ | ProductName | 16字节 | `58 55 33 31 36 20 44 41 43 00 00 00 00 00 00 00` | ASCII 字符串 `XU316 DAC`,后面用 `00` 补齐到 16 字节 |
+ | SerialNumber | 16字节 | `53 4E 32 34 30 30 30 31 00 00 00 00 00 00 00 00` | ASCII 字符串 `SN240001`,后面用 `00` 补齐到 16 字节 |
+ | CRC | 4字节 | `12 34 56 78` | 产品基础信息的 32 位 CRC 校验值,这里仅作为示例演示 |
+ | 校验和 | 1字节 | `D9` | 从 `55` 开始到 `78` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.2.3 读取上电配置信息(0x02)
=== "命令格式"
@@ -387,6 +433,29 @@ sequenceDiagram
CRC: 4字节 (32位CRC校验)
```
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 02 0E 01 00 00 00 00 01 2C 20 30 30 11 22 33 44 6A
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的数据 |
+ | 命令字 | 1字节 | `02` | 表示当前命令是“读取上电配置信息” |
+ | 数据长度 | 1字节 | `0E` | 表示后面紧跟着 14 字节的数据区 |
+ | 默认输入输出模式 | 5字节 | `01 00 00 00 00` | 示例模式数据,具体每个字节的含义由产品规格书定义 |
+ | 静音时间 | 2字节 | `01 2C` | 按大端模式表示 `300ms` |
+ | 麦克风默认音量 | 1字节 | `20` | 示例默认麦克风音量 |
+ | DAC左声道默认音量 | 1字节 | `30` | 示例默认左声道音量 |
+ | DAC右声道默认音量 | 1字节 | `30` | 示例默认右声道音量 |
+ | CRC | 4字节 | `11 22 33 44` | 上电配置的 32 位 CRC 校验值,这里仅作为示例演示 |
+ | 校验和 | 1字节 | `6A` | 从 `55` 开始到 `44` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.2.4 获取当前输入输出模式(0x03)
=== "命令格式"
@@ -415,6 +484,24 @@ sequenceDiagram
- XU316会根据返回的模式加载相应的应用固件
- 此命令用于设备启动过程中的模式匹配与确认
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 03 05 01 00 00 00 00 0B
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的数据 |
+ | 命令字 | 1字节 | `03` | 表示当前命令是“获取当前输入输出模式” |
+ | 数据长度 | 1字节 | `05` | 表示后面紧跟着 5 字节的模式数据 |
+ | 输入输出模式 | 5字节 | `01 00 00 00 00` | 示例模式数据,具体每个字节的定义由产品规格书决定 |
+ | 校验和 | 1字节 | `0B` | 从 `55` 开始到最后一个模式字节结束,所有字节相加后对 256 取余的结果 |
+
#### 3.2.5 获取当前用户配置(0x04)
=== "命令格式"
@@ -443,6 +530,29 @@ sequenceDiagram
- 在应用固件加载后、应用启动前执行
- 应用会根据返回的信息初始化相应参数
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 04 0E 02 00 00 00 00 00 C8 18 28 28 55 66 77 88 00
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的数据 |
+ | 命令字 | 1字节 | `04` | 表示当前命令是“获取当前用户配置” |
+ | 数据长度 | 1字节 | `0E` | 表示后面紧跟着 14 字节的数据区 |
+ | 输入输出模式 | 5字节 | `02 00 00 00 00` | 示例用户当前选择的模式数据,具体每个字节的定义由产品规格书决定 |
+ | 静音时间 | 2字节 | `00 C8` | 按大端模式表示 `200ms` |
+ | 麦克风音量 | 1字节 | `18` | 示例当前麦克风音量 |
+ | DAC左声道音量 | 1字节 | `28` | 示例当前左声道音量 |
+ | DAC右声道音量 | 1字节 | `28` | 示例当前右声道音量 |
+ | CRC | 4字节 | `55 66 77 88` | 用户配置的 32 位 CRC 校验值,这里仅作为示例演示 |
+ | 校验和 | 1字节 | `00` | 从 `55` 开始到 `88` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.2.6 启动完成命令(0x05)
=== "命令格式"
@@ -473,6 +583,23 @@ sequenceDiagram
- 包含启动状态信息,告知MCU启动是否成功或遇到问题
- 所有后续业务命令只能在此命令发送成功后使用
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 05 00 07
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `05` | 表示当前确认的是“启动完成命令” |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `07` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
### 3.3 业务控制命令详解
!!! warning "使用前提"
@@ -506,6 +633,23 @@ sequenceDiagram
- 通常在状态发生变化时发送,例如音量变化、模式切换等
- MCU可根据此信息更新UI显示或调整相关功能
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 20 00 22
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `20` | 表示当前确认的是“报告应用状态”命令 |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `22` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.2 媒体控制(0x21)
=== "命令格式"
@@ -554,6 +698,23 @@ sequenceDiagram
| 0x06 | 快退 | 在当前曲目中快退 |
| 0x07 | 静音 | 切换系统静音状态 |
+=== "MCU发送示例"
+
+ ```
+ 55 AA 03 21 01 02 26
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 发送给 XU316 的命令 |
+ | 命令字 | 1字节 | `21` | 表示当前命令是“媒体控制” |
+ | 数据长度 | 1字节 | `01` | 表示后面紧跟着 1 字节的控制码 |
+ | 控制码 | 1字节 | `02` | 表示“播放/暂停”命令 |
+ | 校验和 | 1字节 | `26` | 从 `55` 开始到控制码结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.3 报告播放音频流格式和类型(0x22)
=== "命令格式"
@@ -582,6 +743,23 @@ sequenceDiagram
- 通常在播放开始或格式变化时发送
- MCU可根据此信息更新显示,如显示PCM/DSD/MQA/DOP等状态
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 22 00 24
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `22` | 表示当前确认的是“报告播放音频流格式和类型”命令 |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `24` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.4 设置输入输出模式(0x23)
=== "命令格式"
@@ -610,13 +788,30 @@ sequenceDiagram
- 通常由用户操作触发,如按下模式选择按钮
- XU316可能需要重启以加载新模式的固件
+=== "MCU发送示例"
+
+ ```
+ 55 AA 03 23 05 02 00 00 00 00 2C
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 发送给 XU316 的命令 |
+ | 命令字 | 1字节 | `23` | 表示当前命令是“设置输入输出模式” |
+ | 数据长度 | 1字节 | `05` | 表示后面紧跟着 5 字节的模式数据 |
+ | 输入输出模式 | 5字节 | `02 00 00 00 00` | 示例目标模式数据,具体每个字节的定义由产品规格书决定 |
+ | 校验和 | 1字节 | `2C` | 从 `55` 开始到最后一个模式字节结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.5 发送播放音量(0x24)
=== "命令格式"
- **XU316返回**
+ **XU316发送**
```
帧头: 2字节 - 0x55aa
- 版本: 1字节 - 0x03
+ 版本: 1字节 - 0x00
命令字: 1字节 - 0x24
数据长度: 1字节 - 0x02 (即2字节)
数据: 2字节
@@ -625,10 +820,10 @@ sequenceDiagram
校验和: 1字节 - 从帧头开始按字节求和,结果对256求余
```
- **MCU发送**
+ **MCU返回**
```
帧头: 2字节 - 0x55aa
- 版本: 1字节 - 0x00
+ 版本: 1字节 - 0x03
命令字: 1字节 - 0x24
数据长度: 1字节 - 0x00
数据: 0字节
@@ -638,24 +833,41 @@ sequenceDiagram
=== "功能说明"
- 该命令用于XU316向MCU报告当前播放音量
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 24 00 26
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `24` | 表示当前确认的是“发送播放音量”命令 |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `26` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.6 发送录音音量(0x25)
=== "命令格式"
- **MCU发送**
+ **XU316发送**
```
帧头: 2字节 - 0x55aa
- 版本: 1字节 - 0x03
+ 版本: 1字节 - 0x00
命令字: 1字节 - 0x25
数据长度: 1字节 - 0x01 (即1字节)
数据: 1字节 - 0xFF Mute,0-0dB -127:-127dB
校验和: 1字节 - 从帧头开始按字节求和,结果对256求余
```
- **XU316返回**
+ **MCU返回**
```
帧头: 2字节 - 0x55aa
- 版本: 1字节 - 0x00
+ 版本: 1字节 - 0x03
命令字: 1字节 - 0x25
数据长度: 1字节 - 0x00
数据: 0字节
@@ -666,6 +878,23 @@ sequenceDiagram
- 该命令用于XU316向MCU报告当前麦克风录音音量
- 是预留命令,当前未使用
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 25 00 27
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `25` | 表示当前确认的是“发送录音音量”命令 |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `27` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.7 切换MCLK(0x26)
=== "命令格式"
@@ -694,6 +923,23 @@ sequenceDiagram
- 可切换使用内部时钟或外部时钟
- 对于某些需要精确同步的音频应用场景很重要
+=== "MCU发送示例"
+
+ ```
+ 55 AA 03 26 01 01 2A
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 发送给 XU316 的命令 |
+ | 命令字 | 1字节 | `26` | 表示当前命令是“切换MCLK” |
+ | 数据长度 | 1字节 | `01` | 表示后面紧跟着 1 字节的数据区 |
+ | 数据 | 1字节 | `01` | 表示切换到外部 MCLK;如果是 `00`,则表示切换到内部 MCLK |
+ | 校验和 | 1字节 | `2A` | 从 `55` 开始到最后一个数据字节结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.8 设置 unmute(0x27)
=== "命令格式"
@@ -776,6 +1022,23 @@ sequenceDiagram
- 当USB连接状态发生变化时(连接或断开),XU316主动发送此命令
- MCU可根据此信息更新UI显示或调整相关功能
+=== "MCU返回示例"
+
+ **命令示例**
+ ```
+ 55 AA 03 29 00 2B
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 返回给 XU316 的确认数据 |
+ | 命令字 | 1字节 | `29` | 表示当前确认的是“报告USB连接状态”命令 |
+ | 数据长度 | 1字节 | `00` | 表示这是一条纯确认帧,不携带额外数据 |
+ | 校验和 | 1字节 | `2B` | 从 `55` 开始到 `00` 结束,所有字节相加后对 256 取余的结果 |
+
#### 3.3.11 获取固件版本命令(0xF1)
=== "命令格式"
@@ -802,6 +1065,23 @@ sequenceDiagram
=== "功能说明"
- 获取固件版本
+=== "MCU发送示例"
+
+ ```
+ 55 AA 03 F1 02 00 00 F5
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 发送给 XU316 的命令 |
+ | 命令字 | 1字节 | `F1` | 表示当前命令是“获取固件版本命令” |
+ | 数据长度 | 1字节 | `02` | 表示后面紧跟着 2 字节的数据区 |
+ | 数据 | 2字节 | `00 00` | 示例中的两个字节保留为 `00`,用于占位 |
+ | 校验和 | 1字节 | `F5` | 从 `55` 开始到最后一个数据字节结束,所有字节相加后对 256 取余的结果 |
+
### 3.4 DAC配置选择(0xF0)
@@ -818,7 +1098,7 @@ sequenceDiagram
Byte 1 - 3: reserved
校验和: 1字节 - 从帧头开始按字节求和,结果对256求余
```
-
+
**XU316返回**
```
帧头: 2字节 - 0x55aa
@@ -833,6 +1113,24 @@ sequenceDiagram
- 测试命令用于MCU想XU316设置DAC配置选择。让XU316通过DAC I2C配置DAC还是MCU自己配置DAC
- 此命令为产品特定命令,不是所有产品都支持。具体支持情况请参考产品规格书说明。
+=== "MCU发送示例"
+
+ ```
+ 55 AA 03 F0 04 00 00 00 00 F6
+ ```
+
+ **逐段解析**
+
+ | 字节段 | 长度 | 示例值 | 说明 |
+ |:-------|:-----|:-------|:-----|
+ | 帧头 | 2字节 | `55 AA` | 固定帧头,表示一帧协议数据开始 |
+ | 版本 | 1字节 | `03` | 表示这是 MCU 发送给 XU316 的命令 |
+ | 命令字 | 1字节 | `F0` | 表示当前命令是“DAC配置选择命令” |
+ | 数据长度 | 1字节 | `04` | 表示后面紧跟着 4 字节的数据区 |
+ | Byte 0 | 1字节 | `00` | 表示使能 XU316 通过 I2C 配置 DAC |
+ | Byte 1-3 | 3字节 | `00 00 00` | 预留字节,示例中全部填 `00` |
+ | 校验和 | 1字节 | `F6` | 从 `55` 开始到最后一个数据字节结束,所有字节相加后对 256 取余的结果 |
+
### 3.5 HID和MCU通过XU316数据透传命令
#### 3.5.1 HID通过XU316透传数据给MCU(0xEE)
@@ -848,7 +1146,7 @@ sequenceDiagram
数据: 57字节 - 由于HID协议限制,必须是57字节透传数据
校验和: 1字节 - 从帧头开始按字节求和,结果对256求余
```
-
+
**MCU返回(可以返回多帧)**
```
帧头: 2字节 - 0x55aa
@@ -946,7 +1244,7 @@ sequenceDiagram
|-------|----------------------------------------|
| 0xFF | 静音(Mute) |
| 0x00-0xFE | 音量值,具体映射由应用定义 |
-
+
**DAC音量**
| 值 | 说明 |
diff --git a/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md b/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
new file mode 100644
index 0000000..a3dad31
--- /dev/null
+++ b/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
@@ -0,0 +1,492 @@
+---
+title: XU316 MCU开发示例
+description: XU316与MCU之间的通信协议详细说明,包括数据结构、命令格式和处理流程
+keywords: XU316, MCU, 通信协议, 命令参考
+---
+
+# XU316 MCU开发示例
+
+--8<-- "common/phaten_xmos_support_img.md"
+
+本示例基于 GD32 平台,其他平台请自行适配。
+
+## 最小使用示例
+
+这段代码展示了如何初始化协议层并在主循环中处理数据。用户需要实现自己的 UART 发送函数,并在串口接收中断中调用 `ring_buffer_write` 将数据写入环形缓冲区。
+
+```c
+#include "xu316_protocol.h"
+
+// 发送回调:将数据通过UART发送给XU316
+// 用户需要根据自己的硬件实现uart_send函数
+void my_send(const uint8_t *data, uint16_t len) {
+ uart_send(data, len);
+}
+
+// 日志回调:输出调试信息(可选)
+void my_log(const char *tag, const char *msg) {
+ printf("[%s] %s\n", tag, msg);
+}
+
+// 初始化
+void init(void) {
+ xu316_port_t port = {
+ .send = my_send,
+ .log = my_log
+ };
+ xu316_register_port(&port);
+ xu316_init();
+}
+
+// 串口接收中断中调用,将接收到的数据写入环形缓冲区
+void uart_rx_isr(uint8_t *data, uint16_t len) {
+ ring_buffer_write(data, len);
+}
+
+// 主循环中周期性调用,处理接收到的命令
+void main_loop(void) {
+ uart_data_process();
+}
+```
+
+## 协议层函数
+
+### 校验和计算
+
+计算从帧头到数据区所有字节的累加和,结果对 256 取余。该校验和用于验证数据帧的完整性。
+
+```c
+uint8_t xu316_calc_checksum(uint8_t *data, uint8_t len) {
+ uint8_t sum = 0;
+ for (uint8_t i = 0; i < len; i++) {
+ sum += data[i];
+ }
+ return sum;
+}
+```
+
+### 帧封装函数
+
+将命令字和数据封装成符合协议格式的数据帧,并通过注册的 `send` 回调发送出去。
+
+帧格式:`帧头(0x55AA) + 版本(0x03) + 命令字 + 数据长度 + 数据区 + 校验和`
+
+```c
+int xu316_pack_frame(uint8_t cmd, uint8_t *data, uint8_t len) {
+ memset(g_tx_buffer, 0, sizeof(g_tx_buffer));
+ g_tx_buffer[0] = FRAME_HEADER_H; // 0x55
+ g_tx_buffer[1] = FRAME_HEADER_L; // 0xAA
+ g_tx_buffer[2] = PROTOCOL_VERSION_RX; // 0x03 (MCU版本)
+ g_tx_buffer[3] = cmd; // 命令字
+ g_tx_buffer[4] = len; // 数据长度
+
+ if (data && len > 0) {
+ memcpy(g_tx_buffer + 5, data, len);
+ }
+
+ // 计算校验和(帧头+版本+命令字+数据长度+数据区)
+ g_tx_buffer[len + 5] = xu316_calc_checksum(g_tx_buffer, len + 5);
+
+ // 通过注册的回调发送
+ if (g_xu316_port.send) {
+ g_xu316_port.send(g_tx_buffer, len + 6);
+ }
+ return len + 6;
+}
+```
+
+### 数据帧提取
+
+从环形缓冲区中预读数据,检查帧头是否有效。如果帧头有效,返回完整帧的长度;如果无效,返回 `-1` 表示需要丢弃字节。
+
+```c
+static int check_frame_length(uint8_t *buf, uint16_t len) {
+ // 检查帧头是否为0x55AA
+ if (buf[0] != FRAME_HEADER_H || buf[1] != FRAME_HEADER_L) {
+ return -1; // 帧头错误
+ }
+ // 返回完整帧长度 = 数据长度 + 6(帧头2+版本1+命令1+长度1+校验1)
+ return buf[4] + 6;
+}
+```
+
+### 数据处理主函数
+
+在主循环中周期性调用。从环形缓冲区中提取完整的数据帧,检查帧头有效性,确认数据长度足够后,将完整帧复制到接收缓冲区,然后调用 `uart_data_parse` 进行命令解析。如果帧头无效,会逐字节丢弃直到找到有效帧头。
+
+```c
+void uart_data_process(void) {
+ uint8_t peek_buffer[8]; // 预读缓冲区
+ uint8_t process_buffer[256]; // 帧数据缓冲区
+ int frame_length;
+
+ // 至少需要6字节才能开始检查帧头
+ while (uart_ring_buffer.count >= 6) {
+ // 预读6字节检查帧头
+ ring_buffer_peek(peek_buffer, 6);
+
+ // 检查帧长度
+ frame_length = check_frame_length(peek_buffer, 6);
+ if (frame_length < 0) {
+ // 帧头无效,丢弃1字节继续查找
+ uint8_t dummy;
+ ring_buffer_read(&dummy, 1);
+ continue;
+ }
+
+ // 检查环形缓冲区中是否有足够的数据组成完整帧
+ if (uart_ring_buffer.count < (uint16_t)frame_length) {
+ break; // 数据不足,等待更多数据
+ }
+
+ // 读取完整帧到处理缓冲区
+ if (ring_buffer_read(process_buffer, (uint16_t)frame_length)) {
+ // 将完整帧复制到全局接收缓冲区
+ memcpy(g_rx_buffer, process_buffer, frame_length);
+ g_rx_count = frame_length;
+ g_rx_data = g_rx_buffer;
+ // 调用解析函数处理命令
+ uart_data_parse();
+ }
+ }
+}
+```
+
+## 命令解析
+
+### 解析入口
+
+协议处理的核心函数。对接收到的数据帧进行校验,提取命令字和数据区,然后根据命令字分发到对应的处理逻辑。
+
+```c
+int uart_data_parse(void) {
+ int ret = 0;
+ uint8_t cmd = 0;
+ uint16_t data_len = 0;
+ uint16_t rx_len = (uint16_t)g_rx_count;
+ static uint8_t buffer[256] = {0};
+
+ // 帧校验:检查帧格式和校验和
+ ret = uart_frame_check((uint8_t *)g_rx_data, (uint8_t)rx_len);
+ if (ret == 0) {
+ return -1; // 帧校验失败
+ }
+
+ // 计算数据区长度:总长度 - 6(帧头2+版本1+命令1+长度1+校验1)
+ data_len = rx_len - 6;
+ // 提取命令字(第4个字节,索引3)
+ cmd = g_rx_data[3];
+ // 复制数据区到缓冲区(从第6个字节开始,索引5)
+ memcpy(buffer, g_rx_data + 5, data_len);
+
+ // 根据命令字分发处理
+ switch (cmd) {
+ case 0x00: /* 启动命令处理 */ break;
+ case 0x01: /* 读取产品信息 */ break;
+ case 0x02: /* 读取上电配置 */ break;
+ case 0x03: /* 获取音频模式 */ break;
+ case 0x04: /* 获取用户配置 */ break;
+ case 0x05: /* 启动完成 */ break;
+ case 0x20: /* 状态报告 */ break;
+ case 0x22: /* 音频格式设置 */ break;
+ case 0x24: /* 播放音量 */ break;
+ case 0x25: /* 录音音量 */ break;
+ case 0x27: /* 静音解除响应 */ break;
+ case 0x28: /* 音频格式延迟响应 */ break;
+ case 0xEE: /* HID透传 */ break;
+ default: /* 未知命令处理 */ break;
+ }
+ return ret;
+}
+```
+
+### 命令参考
+
+#### 启动命令 (0x00)
+
+XU316 上电或重启后首先发送此命令。XU316 发送 17 字节数据,包含 VID/PID 和 CRC 校验值。MCU 需要比较 CRC 判断是否需要更新配置,然后回复 1 字节的启动选项。
+
+```c
+case 0x00: {
+ // XU316发送数据格式:
+ // 重启原因(1B) + VID1(2B) + PID1(2B) + VID2(2B) + PID2(2B) + CRC1(4B) + CRC2(4B) = 17字节
+ // MCU回复:启动选项(1B)
+
+ // 解析XU316发送的数据
+ uint8_t reboot_reason = buffer[0]; // 0x00=上电重启, 0x01=切换模式, 0xFF=其他
+ uint8_t *vid_uac1 = buffer + 1; // UAC1.0 VID
+ uint8_t *pid_uac1 = buffer + 3; // UAC1.0 PID
+ uint8_t *vid_uac2 = buffer + 5; // UAC2.0 VID
+ uint8_t *pid_uac2 = buffer + 7; // UAC2.0 PID
+ uint8_t *basic_crc = buffer + 9; // 基础信息CRC
+ uint8_t *power_crc = buffer + 13; // 上电配置CRC
+
+ // 判断是否需要更新配置:比较XU316发送的CRC与本地存储的CRC
+ mcu_data.boot_option = 0;
+ if (memcmp(basic_crc, mcu_data.basic_info_crc, 4) != 0) {
+ mcu_data.boot_option |= BOOT_OPTION_UPDATE_BASIC_INFO; // 需要更新基础信息
+ }
+ if (memcmp(power_crc, mcu_data.power_cfg_crc, 4) != 0) {
+ mcu_data.boot_option |= BOOT_OPTION_UPDATE_POWER_CFG; // 需要更新上电配置
+ }
+
+ // 发送回复:启动选项
+ ret = xu316_pack_frame(cmd, &mcu_data.boot_option, CMD00_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 读取产品信息 (0x01)
+
+XU316 请求获取产品基础信息。MCU 需要回复 60 字节数据,包含 VID、PID、制造商名称、产品名称、序列号和 CRC 校验值。
+
+```c
+case 0x01: {
+ // XU316发送:无数据
+ // MCU回复:60字节产品信息
+ // VID1(2B) + PID1(2B) + VID2(2B) + PID2(2B) +
+ // 制造商(16B) + 产品名(16B) + 序列号(16B) + CRC(4B)
+
+ // 重新计算基础信息的CRC32校验值(前56字节)
+ crc = calculate_crc32(mcu_data.vid_uac1, 56);
+ // 将CRC存储为大端序
+ mcu_data.basic_info_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.basic_info_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.basic_info_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.basic_info_crc[3] = (uint8_t)(crc & 0xFF);
+
+ // 发送产品信息(从vid_uac1开始的60字节)
+ ret = xu316_pack_frame(cmd, mcu_data.vid_uac1, CMD01_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 读取上电配置 (0x02)
+
+XU316 请求获取上电配置参数。MCU 回复 14 字节数据,包含启动状态、音频模式、静音时间、音量设置和 CRC 校验值。
+
+```c
+case 0x02: {
+ // XU316发送:无数据
+ // MCU回复:14字节配置信息
+ // 启动状态(1B) + 音频模式(5B) + 静音时间(2B) +
+ // 麦克风音量(1B) + 左音量(1B) + 右音量(1B) + CRC(4B)
+
+ // 重新计算上电配置的CRC32校验值(audio_mode开始的10字节)
+ crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 0x0a);
+ // 存储为大端序
+ mcu_data.power_cfg_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.power_cfg_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.power_cfg_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.power_cfg_crc[3] = (uint8_t)(crc & 0xFF);
+
+ // 发送上电配置(从audio_mode开始的14字节)
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD02_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 获取音频模式 (0x03)
+
+XU316 请求获取当前输入输出模式。MCU 回复 5 字节的音频模式配置。
+
+```c
+case 0x03: {
+ // XU316发送:无数据
+ // MCU回复:5字节音频模式
+
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD03_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 获取用户配置 (0x04)
+
+XU316 请求获取用户配置参数。MCU 回复 14 字节,格式与 0x02 命令相同。会设置当前选中的音频模式并重新计算 CRC。
+
+```c
+case 0x04: {
+ // XU316发送:无数据
+ // MCU回复:14字节用户配置(格式同0x02)
+
+ // 设置当前选中的音频模式
+ memcpy((uint8_t *)&mcu_data.audio_mode, audio_modes[g_current_mode], 5);
+
+ // 计算CRC
+ crc = calculate_crc32((uint8_t *)&mcu_data.audio_mode, 10);
+ mcu_data.power_cfg_crc[0] = (uint8_t)((crc >> 24) & 0xFF);
+ mcu_data.power_cfg_crc[1] = (uint8_t)((crc >> 16) & 0xFF);
+ mcu_data.power_cfg_crc[2] = (uint8_t)((crc >> 8) & 0xFF);
+ mcu_data.power_cfg_crc[3] = (uint8_t)(crc & 0xFF);
+
+ ret = xu316_pack_frame(cmd, (uint8_t *)&mcu_data.audio_mode, CMD04_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 启动完成 (0x05)
+
+XU316 通知 MCU 启动完成,并发送当前状态数据。MCU 只需回复确认(无数据)。
+
+```c
+case 0x05: {
+ // XU316发送:21字节状态数据
+ // MCU回复:无数据
+
+ // 保存XU316发送的状态到mcu_data结构体
+ memcpy(&mcu_data.startup_status, buffer, 15);
+
+ // 回复确认
+ ret = xu316_pack_frame(cmd, NULL, CMD05_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 状态报告 (0x20)
+
+XU316 在状态变化时主动上报。MCU 保存状态数据并回复确认。
+
+```c
+case 0x20: {
+ // XU316发送:20字节状态数据
+ // 音频模式(5B) + 静音时间(2B) + 麦克风音量(1B) + 左音量(1B) + 右音量(1B) + CRC(4B)
+ // MCU回复:无数据
+
+ // 保存状态数据
+ memcpy(&mcu_data.audio_mode, buffer, 14);
+
+ // 回复确认
+ ret = xu316_pack_frame(cmd, NULL, CMD20_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 音频格式设置 (0x22)
+
+XU316 通知当前播放的音频格式和类型。MCU 保存这些信息并回复确认。
+
+```c
+case 0x22: {
+ // XU316发送:2字节(音频格式 + 音频类型)
+ // MCU回复:无数据
+
+ // 保存音频格式和类型
+ memcpy(&mcu_data.audio_format, buffer, 2);
+
+ // 回复确认
+ ret = xu316_pack_frame(cmd, NULL, CMD22_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### 播放音量 (0x24)
+
+XU316 发送当前播放音量。MCU 保存左右声道音量值并回复确认。
+
+```c
+case 0x24: {
+ // XU316发送:2字节(左音量 + 右音量)
+ // MCU回复:无数据
+
+ // 保存音量值
+ memcpy(&mcu_data.dac_l_volume, buffer, 2);
+
+ // 回复确认
+ ret = xu316_pack_frame(cmd, NULL, CMD24_MCU_DATA_LEN);
+ break;
+}
+```
+
+#### HID 透传 (0xEE)
+
+HID 数据透传或 OTA 升级数据。XU316 发送 57 字节数据,MCU 需要回复 57 字节(Echo 模式)。
+
+```c
+case 0xEE: {
+ // XU316发送:57字节HID/OTA数据
+ // MCU回复:57字节(Echo模式)
+
+ // 检查版本号和数据长度
+ if (g_rx_data[2] == 0x00 && g_rx_data[4] == CMD_HID_TRANSPARENT_DATA_LEN) {
+ // 简单Echo回复:将接收到的数据原样返回
+ ret = xu316_pack_frame(0xEE, buffer, CMD_HID_TRANSPARENT_MCU_DATA_LEN);
+ }
+ break;
+}
+```
+
+## MCU 主动发送命令
+
+以下命令由 MCU 主动发送给 XU316。
+
+### 静音解除命令
+
+命令字 `0x27`,数据为 2 字节 `0x00`。
+
+```c
+void send_unmute_cmd(void) {
+ uint8_t data[2] = {0x00, 0x00};
+ xu316_pack_frame(0x27, data, 2);
+}
+```
+
+### 音频格式延迟命令
+
+命令字 `0x28`,数据为 2 字节 `0x00`。
+
+```c
+void send_audio_format_delay_cmd(void) {
+ uint8_t data[2] = {0x00, 0x00};
+ xu316_pack_frame(0x28, data, 2);
+}
+```
+
+### 媒体控制命令
+
+命令字 `0x21`,数据为 1 字节的媒体控制码。
+
+```c
+void send_media_control(media_control_t cmd) {
+ uint8_t data = (uint8_t)cmd;
+ xu316_pack_frame(0x21, &data, 1);
+}
+
+// 使用示例
+send_media_control(MEDIA_KEY_PLAY_PAUSE); // 播放/暂停
+send_media_control(MEDIA_KEY_VOLUME_UP); // 音量增加
+send_media_control(MEDIA_KEY_VOLUME_DOWN); // 音量减小
+```
+
+### 设置音频模式
+
+命令字 `0x23`,数据为 5 字节音频模式配置。
+
+```c
+void set_audio_mode(uint8_t mode_index) {
+ // audio_modes是预定义的8种模式数组
+ xu316_pack_frame(0x23, (uint8_t *)audio_modes[mode_index], 5);
+}
+
+// 8种预定义音频模式
+static const uint8_t audio_modes[][5] = {
+ {0x00, 0x80, 0xa9, 0x00, 0x01}, // UAC2.0->I2S
+ {0x00, 0x80, 0x01, 0x00, 0x02}, // UAC1.0-I2S
+ {0x10, 0x80, 0x65, 0x10, 0x03}, // S/PDIF1 IN-I2S OUT (COAX)
+ {0x00, 0x80, 0x65, 0x10, 0x04}, // S/PDIF2 IN-I2S OUT (OPT)
+ {0x00, 0x80, 0xc5, 0x08, 0x05}, // UAC2.0-SPDIF OUT
+ {0x00, 0x82, 0xd5, 0x81, 0x06}, // I2S IN-I2S OUT
+ {0x20, 0x80, 0x65, 0x10, 0x07}, // S/PDIF3 IN-I2S OUT (HDMI)
+ {0x30, 0x80, 0x65, 0x10, 0x08} // S/PDIF4 IN-I2S OUT
+};
+```
+
+---
+
+## 咨询反馈
+
+
+点击展开咨询反馈表单
+
+--8<-- "common/customer_form.md"
+
+
diff --git a/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md b/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
index 2f6b354..8a4037a 100644
--- a/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
+++ b/zh/docs/dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
@@ -1,7 +1,7 @@
---
title: A316免开发固件MCU开发指南
-description: 本文档提供了XU316与MCU通信开发的完整指导,包括开发步骤、参考文档和常见问题解答,帮助开发者快速实现XU316与MCU的通信功能。
-keywords: XU316开发, MCU通信开发, 音频接口控制, 通信协议, 开发指导, 常见问题解答
+description: XU316与MCU通信开发入门指导,帮助开发者按步骤理解协议、实现通信、运行示例代码。
+keywords: XU316开发, MCU通信开发, 通信协议, 开发指导, 代码示例
---
--8<-- "common/phaten_xmos_support_img.md"
@@ -10,58 +10,34 @@ keywords: XU316开发, MCU通信开发, 音频接口控制, 通信协议, 开发
## 开发概述
-本文档提供了XU316与MCU通信开发的完整指导,帮助开发者按照正确的顺序实现XU316与MCU的通信功能。开发过程分为以下几个主要步骤,每个步骤都有对应的参考文档和详细说明。
+本文档帮助开发者按正确顺序实现 XU316 与 MCU 的串口通信功能。开发过程分为以下步骤,每步都有对应的参考文档。
## 开发步骤
-=== "第一步:了解基础概念和协议结构"
- **目标**:理解XU316与MCU通信的基本概念和协议结构
-
- **参考文档**:[:material-file-document-outline: XU316与MCU通信协议命令宏定义](./Command_Macros.md)
-
+=== "第一步:了解协议结构"
+ **目标**:理解 XU316 与 MCU 通信的帧格式与命令定义
+
+ **参考文档**:[:material-file-document-outline: XU316与MCU通信协议](../../protocols/xu316_zerocode_protocol.md)
+
**学习要点**:
- - 掌握帧格式的基本结构(帧头、命令、数据长度、校验和、帧尾)
- - 理解各种命令的数据长度定义
+ - 掌握帧格式(帧头 `0x55AA`、版本、命令字、数据长度、校验和)
+ - 理解各命令的数据长度定义
- 熟悉音频格式枚举和类型定义
- - 了解命令数据结构体的组成
-=== "第二步:实现基础通信功能"
- **目标**:实现XU316与MCU的基础通信功能
-
- **参考文档**:[:material-file-document-outline: XU316与MCU通信协议参考](./Command_Reference.md)
-
- **开发任务**:
+=== "第二步:运行示例代码"
+ **目标**:基于 GD32 平台运行完整的协议通信示例
- - 实现环形缓冲区初始化和管理
- - 实现数据帧的封装和发送
- - 实现数据帧的接收和解析
- - 实现CRC32和简单校验和计算
- - 实现基本的通信协议处理流程
+ **参考文档**:[:material-file-document-outline: XU316 MCU开发示例](./Development_Guide.md)
-=== "第三步:配置音频接口和参数"
- **目标**:配置XU316的音频接口和相关参数
-
- **参考文档**:[:material-file-document-outline: XU316音频接口控制代码示例](./Product_Content.md)
-
- **开发任务**:
-
- - 配置I2S主从模式
- - 设置音频采样率和位深度
- - 配置音频通道数量
- - 设置音量控制参数
- - 配置各种音频接口(SPDIF、ADAT、DSD等)
+ **示例内容**:
-
+ - 最小使用示例(初始化、中断接收、主循环处理)
+ - 协议层函数(校验和计算、帧封装、帧提取、数据处理)
+ - 全部命令的解析代码(0x00 ~ 0xEE)
+ - MCU 主动发送命令(静音解除、媒体控制、音频模式设置等)
diff --git a/zh/mkdocs.yml b/zh/mkdocs.yml
index 7c7b3a9..db643c1 100644
--- a/zh/mkdocs.yml
+++ b/zh/mkdocs.yml
@@ -305,11 +305,12 @@ nav:
- A316免开发固件MCU开发指南:
- dev_doc/sdk_examples/XU316_MCU_Communication_Examples/index.md
- 代码示例:
- - XU316与MCU通信协议命令宏定义: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md
- - XU316与MCU通信协议参考: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md
- - XU316音频接口控制: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md
+ # - XU316与MCU通信协议命令宏定义: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Macros.md
+ # - XU316与MCU通信协议参考: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Command_Reference.md
+ # - XU316音频接口控制: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Product_Content.md
+ - XU316_MCU开发示例: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/Development_Guide.md
- 免开发串口协议测试脚本说明: dev_doc/sdk_examples/XU316_MCU_Communication_Examples/ZeroCode_Test_Script.md
- - 免开发固件开发问题指南: dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
+ - 免开发固件常见开发问题: dev_doc/faq/technical_faq/a316_firmware_dev_faq.md
# - 5.1标准固件使用示例:
# - 8711开发板连接说明: dev_doc/hifi_audio/a316_1926v1/RTL8711dome.md
# - 开发板硬件连接说明: dev_doc/hifi_audio/a316_1926v1/A316-8711-5.1解码无线音频套装制作说明.md