Command Macro Definitions for XU316 and MCU Communication Protocol¶
Document Instructions¶
This document provides the command macro definitions related to the communication protocol between XU316 and MCU, mainly including the following contents:
- Definition of communication frame format
- Definition of MCU command data length
- Enumeration of communication protocol command words
- Definitions of audio formats and types
- Definition of command data structure
These macro definitions and data structures are the basis for the communication between XU316 and MCU. Developers need to correctly understand and use these definitions to implement the communication function.
Communication Frame Format¶
Definition of Basic Frame Format¶
#define FRAME_HEADER_H 0x55
#define FRAME_HEADER_L 0xAA
#define PROTOCOL_VERSION 0x01
#define PROTOCOL_VERSION_RX 0x03
Definition of Command Data Length¶
XU316 Command Data Length¶
#define CMD00_XU316_DATA_LEN 0x11 // Command 0x00: Start-up (Startup options)
#define CMD01_XU316_DATA_LEN 0x00 // Command 0x01: Read product information (60-byte firmware information)
#define CMD02_XU316_DATA_LEN 0x00 // Command 0x02: Read power-on configuration (14-byte configuration parameters)
#define CMD03_XU316_DATA_LEN 0x00 // Command 0x03: Get audio mode (5-byte mode parameters)
#define CMD04_XU316_DATA_LEN 0x00 // Command 0x04: Get user configuration (14-byte user settings)
#define CMD05_XU316_DATA_LEN 0x15 // Command 0x05: Startup completed (No data field)
#define CMDF1_XU316_DATA_LEN 0x03 // Command 0xF1: Version number query (3-byte version information)
#define CMD20_XU316_DATA_LEN 0x14 // Command 0x20: Set volume
#define CMD21_XU316_DATA_LEN 0x00 // Command 0x21: Sound effect mode
#define CMD22_XU316_DATA_LEN 0x02 // Command 0x22: Device status query
#define CMD23_XU316_DATA_LEN 0x00 // Command 0x23: Bluetooth control
#define CMD24_XU316_DATA_LEN 0x02 // Command 0x24: Send playback volume
#define CMD25_XU316_DATA_LEN 0x01 // Command 0x25: Send recording volume
#define CMD27_XU316_DATA_LEN 0x00 // Command 0x27: Special unmute (No data field)
#define CMD28_XU316_DATA_LEN 0x01 // Command 0x28: Audio format delay setting (1-byte parameter)
#define CMD_HID_TRANSPARENT_DATA_LEN 0x39 // Command 0xEE: HID passthrough/OTA upgrade (57 bytes)
MCU Command Data Length¶
#define CMD00_MCU_DATA_LEN 0x01 // Command 0x00: Start-up (Startup options)
#define CMD01_MCU_DATA_LEN 0x3C // Command 0x01: Read product information (60-byte firmware information)
#define CMD02_MCU_DATA_LEN 0x0E // Command 0x02: Read power-on configuration (14-byte configuration parameters)
#define CMD03_MCU_DATA_LEN 0x05 // Command 0x03: Get audio mode (5-byte mode parameters)
#define CMD04_MCU_DATA_LEN 0x0E // Command 0x04: Get user configuration (14-byte user settings)
#define CMD05_MCU_DATA_LEN 0x00 // Command 0x05: Startup completed (No data field)
#define CMDF1_MCU_DATA_LEN 0x00 // Command 0xF1: Version number query (No data field)
#define CMD20_MCU_DATA_LEN 0x00 // Command 0x20: Set volume
#define CMD21_MCU_DATA_LEN 0x01 // Command 0x21: Sound effect mode
#define CMD22_MCU_DATA_LEN 0x00 // Command 0x22: Device status query
#define CMD23_MCU_DATA_LEN 0x05 // Command 0x23: Set audio mode
#define CMD24_MCU_DATA_LEN 0x00 // Command 0x24: Send playback volume
#define CMD25_MCU_DATA_LEN 0x00 // Command 0x25: Send recording volume
#define CMD27_MCU_DATA_LEN 0x00 // Command 0x27: Special unmute (No data field)
#define CMD28_MCU_DATA_LEN 0x00 // Command 0x28: Audio format delay setting (No data field)
#define CMD_HID_TRANSPARENT_MCU_DATA_LEN 0x39 // Command 0xEE: HID passthrough/OTA upgrade (57 bytes)
Definition of Communication Protocol Commands¶
Enumeration of Command Words¶
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, // Read power-on configuration
CMD_GET_AUD_MODE = 0x03, // Get audio mode
CMD_GET_USER_CFG = 0x04, // Get user configuration
CMD_STARTUP_COMPLETE = 0x05, // Startup completion notification
CMD_GET_VERSION = 0xF1, // Version number query
/****** Service control commands (0x20 - 0x2F) ******/
CMD_REPORT_STATUS = 0x20, // Status report
CMD_MEDIA_CONTROL = 0x21, // Media control
CMD_SET_PLAY_FORMAT = 0x22, // Set audio format
CMD_SET_AUDIO_MODE = 0x23, // Set audio mode
CMD_SET_PLAY_VOL = 0x24, // Set playback volume
CMD_SET_REC_VOL = 0x25, // Set recording volume
CMD_SPECIAL_UNMUTE = 0x27, // Special unmute
CMD_SET_AUDIO_FORMAT_DELAY = 0x28, // Set audio format delay
CMD_HID_TRANSPARENT = 0xEE, // HID passthrough/OTA upgrade command
CMD_COUNT = CMD_SET_REC_VOL + 1 // Total number of currently supported commands
} mcu_command_t;
Enumeration of Startup Options (Bitmask mode)¶
Note
Enumeration of Startup Options (Bitmask mode) Use uint8_t to ensure single-byte storage and support multiple option combinations
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;
Enumeration of Media Control¶
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 bits (0x08 - 0xFF is the reserved area for the protocol)
} media_control_t;
Definition of Audio Formats¶
Note
Enumeration of Audio Stream Formats (Compatible with AES67 - 2020 Standard) Explicitly specify the underlying type as uint8_t to ensure 1-byte storage
Enumeration of Audio Stream Formats¶
typedef enum
{
// PCM sampling 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,
// -- Based on 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;
Enumeration of Audio Types¶
Note
Enumeration of Audio Types (Compatible with AES67 - 2020 Standard) Explicitly specify the underlying type as uint8_t to ensure 1-byte storage
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 level
AUDIO_TYPE_DSD = 0x05 // Direct Stream Digital
// 0x06 - 0xFF is reserved for future expansion
} audio_type_t;
Command Data Structure¶
Definition of Data Structure¶
typedef uint8_t byte_pair[2];
// Command data structure
typedef struct __attribute__((packed))
{
uint8_t boot_option; // 0x00: Startup option data
// Basic product 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]; // CRC32 of basic information
// User configuration is the power-on configuration information and also the application running parameters
uint8_t startup_status; // Startup status
uint8_t audio_mode[5];
uint8_t mute_duration[2]; // Mute time (ms)
uint8_t mic_volume; // Microphone volume is also the 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]; // CRC32 of power-on configuration
// Application running 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;