Implementation:78 Xiaozhi esp32 config h
| Knowledge Sources | |
|---|---|
| Domains | Hardware_Configuration, Build_Systems |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Concrete tool for board pin configuration provided by the XiaoZhi firmware, defining a C preprocessor header pattern with #define macros for GPIO pins, I2S ports, I2C addresses, and display parameters that board source files and audio drivers consume.
Description
config.h is a Pattern Doc — it documents a file convention, not a library API. Each board directory contains a config.h that defines hardware-specific pin assignments and parameters via C preprocessor macros. The file is included by the board's .cc source and by audio codec/display drivers.
Key configuration categories:
- I2S audio:
CONFIG_I2S_*_BCLK,CONFIG_I2S_*_DIN,CONFIG_I2S_*_DOUT,CONFIG_I2S_*_MCLK(input/output pin assignments) - Audio parameters:
CONFIG_INPUT_*_SAMPLE_RATE,CONFIG_OUTPUT_*_SAMPLE_RATE,CONFIG_INPUT_*_CHANNELS - Display:
CONFIG_DISPLAY_*(SPI pins, reset, DC, CS, backlight, width, height) - I2C:
CONFIG_I2C_*_SDA,CONFIG_I2C_*_SCL - Battery:
CONFIG_BATTERY_*(ADC channel, charging pin) - LED:
CONFIG_LED_*(GPIO pin, type)
Critical rule: Never modify an existing board's config.h to support different hardware. Board identity affects OTA compatibility. Create a new board with a unique config.h instead.
Usage
Reference this implementation when:
- Adding a new board's pin configuration
- Understanding which pins a board uses for audio, display, or I2C
- Debugging hardware pin conflicts
- Understanding the relationship between config.h and board source
Code Reference
Source Location
- Repository: XiaoZhi ESP32
- Files:
main/boards/*/config.h(one per board),docs/custom-board.md(template)
Signature
// Example config.h for a hypothetical board
#pragma once
// I2S Audio (input/microphone)
#define CONFIG_I2S_INPUT_BCLK 4
#define CONFIG_I2S_INPUT_DIN 5
#define CONFIG_I2S_INPUT_DOUT 6
#define CONFIG_I2S_INPUT_MCLK 3
#define CONFIG_INPUT_SAMPLE_RATE 16000
#define CONFIG_INPUT_CHANNELS 1
// I2S Audio (output/speaker)
#define CONFIG_I2S_OUTPUT_BCLK 7
#define CONFIG_I2S_OUTPUT_DIN 8
#define CONFIG_I2S_OUTPUT_DOUT 9
#define CONFIG_I2S_OUTPUT_MCLK -1 // Not connected
#define CONFIG_OUTPUT_SAMPLE_RATE 16000
#define CONFIG_OUTPUT_CHANNELS 1
// Display (SPI LCD)
#define CONFIG_DISPLAY_SPI_HOST SPI2_HOST
#define CONFIG_DISPLAY_SPI_CLK 10
#define CONFIG_DISPLAY_SPI_MOSI 11
#define CONFIG_DISPLAY_SPI_MISO 12
#define CONFIG_DISPLAY_DC 13
#define CONFIG_DISPLAY_CS 14
#define CONFIG_DISPLAY_RESET 15
#define CONFIG_DISPLAY_WIDTH 240
#define CONFIG_DISPLAY_HEIGHT 240
// I2C
#define CONFIG_I2C_SDA 17
#define CONFIG_I2C_SCL 18
// Battery
#define CONFIG_BATTERY_ADC_CHANNEL ADC1_GPIO32_CHANNEL
#define CONFIG_BATTERY_CHARGING_PIN 19
// LED
#define CONFIG_LED_GPIO 20
Import
// In the board's .cc file:
#include "config.h"
// In audio codec drivers (via board class):
// config.h is included transitively through the board implementation
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Hardware schematic | Document | Pin assignments from the board's schematic |
Outputs
| Name | Type | Description |
|---|---|---|
| CONFIG_* macros | Pin numbers and parameters consumed by board source and drivers |
Usage Examples
Creating config.h for a New Board
// main/boards/my-board/config.h
#pragma once
// Audio codec: ES8311 on I2S0
#define CONFIG_I2S_INPUT_BCLK 41
#define CONFIG_I2S_INPUT_DIN 42
#define CONFIG_I2S_INPUT_DOUT 43
#define CONFIG_I2S_INPUT_MCLK 2
#define CONFIG_INPUT_SAMPLE_RATE 16000
#define CONFIG_I2S_OUTPUT_BCLK 41
#define CONFIG_I2S_OUTPUT_DIN 42
#define CONFIG_I2S_OUTPUT_DOUT 43
#define CONFIG_I2S_OUTPUT_MCLK 2
#define CONFIG_OUTPUT_SAMPLE_RATE 16000
// No display for this board (headless)
// (simply don't define CONFIG_DISPLAY_* macros)
// No battery
// (simply don't define CONFIG_BATTERY_* macros)
Related Pages
Implements Principle
- Principle:78_Xiaozhi_esp32_Board_Abstraction_Layer
- Principle:78_Xiaozhi_esp32_Build_System_Configuration