gpio-config by claudius-ars/embedded-agent-skills
npx skills add https://github.com/claudius-ars/embedded-agent-skills --skill gpio-config| 关键词/模式 | 平台 |
|---|---|
| Raspberry Pi, RPi, BCM2835, BCM2711, BCM2712, config.txt, dtoverlay, gpiozero, RPi.GPIO, pigpio, /boot/firmware/ | RPi |
| ESP32, ESP-IDF, WROOM, WROVER, menuconfig, sdkconfig, Arduino (with ESP context), esp_err_t, gpio_config(), ESP32-S2, S3, C3, C6 | ESP32 |
RPi 变体:
| 标识符 | 涵盖的型号 | 关键差异 |
|---|---|---|
| rpi3 | Pi 3B/3B+ | 迷你 UART 上的 UART/BT 冲突,2× PWM 通道,配置文件位于 /boot/config.txt |
| rpi4 | Pi 4B | 4× PWM 通道,双 SPI,配置文件位于 /boot/firmware/config.txt |
| rpi5 | Pi 5 | RP1 南桥(不同的外设基址),4× PWM,配置文件位于 /boot/firmware/config.txt |
| rpi_zero2w |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| Zero 2W |
| 与 Pi 3 相同的 SoC,UART/BT 冲突,有限的电流预算 |
ESP32 变体:
| 标识符 | 关键差异 |
|---|---|
| esp32 | 34 个 GPIO,双核,ADC2 与 WiFi 冲突,GPIO36/39 上的霍尔传感器 |
| esp32s2 | 43 个 GPIO,单核,无蓝牙,原生 USB,无 ADC2/WiFi 冲突 |
| esp32s3 | 45 个 GPIO,双核,BLE5,原生 USB,无 ADC2/WiFi 冲突 |
| esp32c3 | 22 个 GPIO,单核 RISC-V,仅 BLE5,无 ADC2/WiFi 冲突 |
| esp32c6 | 30 个 GPIO,RISC-V,WiFi 6,802.15.4,无 ADC2/WiFi 冲突 |
ESP32 模块:
| 模块 | 额外保留的引脚 |
|---|---|
| WROOM | GPIO6–11 (闪存 SPI) |
| WROVER | GPIO6–11 (闪存 SPI) + GPIO16–17 (PSRAM) |
始终加载平台引脚数据库。仅当满足触发条件时才加载其他文件。
| 文件 | 触发条件 |
|---|---|
| references/platforms/rpi-pins.md | 平台是 RPi(任何变体) |
| references/platforms/esp32-pins.md | 平台是 ESP32(任何变体) |
| references/platforms/esp32-specifics.md | 检测到 ESP32 且涉及以下任何一项:strap 引脚、深度睡眠、闪存/PSRAM、ADC2、启动问题 |
| references/platforms/rpi-overlays.md | 检测到 RPi 且涉及以下任何一项:设备树、dtoverlay、overlay、内核模块、/boot/ 配置 |
| references/protocol-quick-ref.md | 提及任何协议:I2C, SPI, UART, PWM, 1-Wire, CAN, Modbus, ADC, DAC |
| references/electrical-constraints.md | 提及电流限制、电压电平、上拉/下拉电阻、电源供应、电平转换 |
| references/common-devices.md | 提及特定传感器、模块、显示屏或分线板的名称或零件号 |
从用户请求中提取:
应用第 1 节的规则。结果:确认的平台 + 变体 + 模块类型,或者询问用户。
应用第 2 节的表格。在继续之前加载所有触发的参考文件。
如果缺少任何关键信息(平台、协议数量或设备身份),提出一个简洁的后续问题,涵盖所有缺失点。如果信息仅仅是模糊不清但存在合理的默认值,则继续并在输出中列出假设。后续消息最多只问一次。
使用平台特定策略分配引脚:
RPi 策略:
ESP32 策略:
调用验证脚本:
python scripts/validate_pinmap.py --format json <<'EOF'
<input JSON>
EOF
如果验证返回错误:重新分配冲突的引脚并重新验证。最多循环 3 次。如果 3 次尝试后仍然失败,则呈现最佳结果并解释剩余的警告。
如果验证仅返回警告:在输出中包含警告,继续。
使用第 4 节的格式生成响应。然后调用生成脚本:
python scripts/generate_config.py --format json --framework <framework> <<'EOF'
<input JSON>
EOF
在结构化响应中包含所有脚本输出。
位置:scripts/validate_pinmap.py
CLI 用法:
python scripts/validate_pinmap.py --format json [--verbose] < input.json
python scripts/validate_pinmap.py --help
输入 JSON 模式:
{
"platform": "rpi | esp32",
"variant": "rpi3 | rpi4 | rpi5 | rpi_zero2w | esp32 | esp32s2 | esp32s3 | esp32c3 | esp32c6",
"module": "WROOM | WROVER | null",
"wifi_enabled": true,
"pins": [
{
"gpio": 17,
"function": "I2C_SDA | I2C_SCL | SPI_MOSI | SPI_MISO | SPI_SCLK | SPI_CS | UART_TX | UART_RX | PWM | DIGITAL_IN | DIGITAL_OUT | ANALOG_IN | 1WIRE | CAN_TX | CAN_RX",
"protocol_bus": 0,
"device": "BME280",
"pull": "up | down | none",
"notes": ""
}
]
}
输出 JSON 模式:
{
"valid": true,
"errors": [
{
"gpio": 6,
"code": "RESERVED_PIN | CONFLICT | INPUT_ONLY_AS_OUTPUT | STRAPPING_UNACKNOWLEDGED | ADC2_WIFI | CURRENT_EXCEEDED",
"message": "人类可读的错误信息",
"severity": "error"
}
],
"warnings": [
{
"gpio": 12,
"code": "STRAPPING_PIN | UART_BT_CONFLICT | PWM_AUDIO_CONFLICT | DEPRECATED_LIB | CURRENT_WARNING | BOOT_STATE",
"message": "人类可读的警告信息",
"severity": "warning"
}
],
"summary": {
"total_pins": 8,
"errors": 0,
"warnings": 2,
"current_draw_ma": 32
}
}
退出代码:0 = 有效(警告可以),1 = 发现错误,2 = 输入无效
位置:scripts/generate_config.py
CLI 用法:
python scripts/generate_config.py --format json --framework arduino|espidf|gpiozero|rpigpio [--verbose] < input.json
python scripts/generate_config.py --help
输入 JSON 模式:与 validate_pinmap.py 输入相同,外加:
{
"platform": "rpi | esp32",
"variant": "rpi3 | rpi4 | rpi5 | rpi_zero2w | esp32 | esp32s2 | esp32s3 | esp32c3 | esp32c6",
"module": "WROOM | WROVER | null",
"wifi_enabled": true,
"pins": [],
"framework": "arduino | espidf | gpiozero | rpigpio"
}
输出 JSON 模式:
{
"config_lines": ["dtoverlay=i2c1", "dtparam=spi=on"],
"init_code": "# 完整的初始化代码,作为带有换行符的单个字符串",
"wiring_notes": [
"将 BME280 SDA 连接到 GPIO2(物理引脚 3)。添加 4.7kΩ 上拉电阻至 3.3V。"
],
"warnings": ["GPIO12 是一个 strap 引脚 — 请参阅启动状态说明"],
"alternatives": [
{
"original_gpio": 12,
"alternative_gpio": 17,
"reason": "避免 MTDI strap 引脚风险"
}
]
}
退出代码:0 = 成功,1 = 生成错误,2 = 输入无效
用户请求: "在 Raspberry Pi 4 上设置一个带有 BME280 温度传感器和 SSD1306 OLED 显示屏的气象站"
生成的引脚映射(节选):
{
"platform": "rpi",
"variant": "rpi4",
"pins": [
{"gpio": 2, "function": "I2C_SDA", "protocol_bus": 1, "device": "BME280+SSD1306", "pull": "external_up"},
{"gpio": 3, "function": "I2C_SCL", "protocol_bus": 1, "device": "BME280+SSD1306", "pull": "external_up"},
{"gpio": 17, "function": "DIGITAL_OUT", "device": "Status LED", "pull": "none"}
]
}
生成的初始化代码(gpiozero,节选):
from gpiozero import LED
import smbus2
bus = smbus2.SMBus(1) # I2C 总线 1: SDA=GPIO2, SCL=GPIO3
# BME280 在地址 0x76,SSD1306 在地址 0x3C — 共享 I2C 总线,无冲突
status_led = LED(17)
每周安装数
1
代码仓库
GitHub 星标数
5
首次出现
1 天前
安全审计
安装在
amp1
cline1
openclaw1
opencode1
cursor1
kimi-cli1
| Keywords/Patterns | Platform |
|---|---|
| Raspberry Pi, RPi, BCM2835, BCM2711, BCM2712, config.txt, dtoverlay, gpiozero, RPi.GPIO, pigpio, /boot/firmware/ | RPi |
| ESP32, ESP-IDF, WROOM, WROVER, menuconfig, sdkconfig, Arduino (with ESP context), esp_err_t, gpio_config(), ESP32-S2, S3, C3, C6 | ESP32 |
RPi Variants:
| Identifier | Models Covered | Key Differences |
|---|---|---|
| rpi3 | Pi 3B/3B+ | UART/BT conflict on mini-UART, 2× PWM channels, config at /boot/config.txt |
| rpi4 | Pi 4B | 4× PWM channels, dual SPI, config at /boot/firmware/config.txt |
| rpi5 | Pi 5 | RP1 southbridge (different peripheral base), 4× PWM, config at /boot/firmware/config.txt |
| rpi_zero2w | Zero 2W | Same SoC as Pi 3, UART/BT conflict, limited current budget |
ESP32 Variants:
| Identifier | Key Differences |
|---|---|
| esp32 | 34 GPIO, dual-core, ADC2 conflicts with WiFi, Hall sensor on GPIO36/39 |
| esp32s2 | 43 GPIO, single-core, no Bluetooth, native USB, no ADC2/WiFi conflict |
| esp32s3 | 45 GPIO, dual-core, BLE5, native USB, no ADC2/WiFi conflict |
| esp32c3 | 22 GPIO, single-core RISC-V, BLE5 only, no ADC2/WiFi conflict |
| esp32c6 | 30 GPIO, RISC-V, WiFi 6, 802.15.4, no ADC2/WiFi conflict |
ESP32 Modules:
| Module | Additional Reserved Pins |
|---|---|
| WROOM | GPIO6–11 (flash SPI) |
| WROVER | GPIO6–11 (flash SPI) + GPIO16–17 (PSRAM) |
ALWAYS load the platform pin database. Load other files only when their trigger condition is met.
| File | Trigger |
|---|---|
| references/platforms/rpi-pins.md | Platform is RPi (any variant) |
| references/platforms/esp32-pins.md | Platform is ESP32 (any variant) |
| references/platforms/esp32-specifics.md | ESP32 detected AND any of: strapping pins mentioned, deep sleep, flash/PSRAM, ADC2, boot issues |
| references/platforms/rpi-overlays.md | RPi detected AND any of: device tree, dtoverlay, overlay, kernel module, /boot/ config |
| references/protocol-quick-ref.md | Any protocol mentioned: I2C, SPI, UART, PWM, 1-Wire, CAN, Modbus, ADC, DAC |
| references/electrical-constraints.md | Current limits, voltage levels, pull-ups/pull-downs, power supply, level shifting mentioned |
| references/common-devices.md | Specific sensor, module, display, or breakout board mentioned by name or part number |
Extract from the user's request:
Apply Section 1 rules. Result: confirmed platform + variant + module type, OR ask the user.
Apply Section 2 table. Load all triggered reference files before proceeding.
If any critical information is missing (platform, protocol count, or device identity), ask ONE concise follow-up question covering all gaps. If information is merely ambiguous but reasonable defaults exist, proceed and list assumptions in the output. Never ask more than one follow-up message.
Assign pins using platform-specific strategy:
RPi strategy:
ESP32 strategy:
Invoke the validation script:
python scripts/validate_pinmap.py --format json <<'EOF'
<input JSON>
EOF
If validation returns errors: reassign conflicting pins and re-validate. Loop a maximum of 3 times. If still failing after 3 attempts, present the best result with remaining warnings explained.
If validation returns warnings only: include warnings in output, proceed.
Generate the response using Section 4 format. Then invoke the generation script:
python scripts/generate_config.py --format json --framework <framework> <<'EOF'
<input JSON>
EOF
Include all script outputs in the structured response.
Location: scripts/validate_pinmap.py
CLI usage:
python scripts/validate_pinmap.py --format json [--verbose] < input.json
python scripts/validate_pinmap.py --help
Input JSON schema:
{
"platform": "rpi | esp32",
"variant": "rpi3 | rpi4 | rpi5 | rpi_zero2w | esp32 | esp32s2 | esp32s3 | esp32c3 | esp32c6",
"module": "WROOM | WROVER | null",
"wifi_enabled": true,
"pins": [
{
"gpio": 17,
"function": "I2C_SDA | I2C_SCL | SPI_MOSI | SPI_MISO | SPI_SCLK | SPI_CS | UART_TX | UART_RX | PWM | DIGITAL_IN | DIGITAL_OUT | ANALOG_IN | 1WIRE | CAN_TX | CAN_RX",
"protocol_bus": 0,
"device": "BME280",
"pull": "up | down | none",
"notes": ""
}
]
}
Output JSON schema:
{
"valid": true,
"errors": [
{
"gpio": 6,
"code": "RESERVED_PIN | CONFLICT | INPUT_ONLY_AS_OUTPUT | STRAPPING_UNACKNOWLEDGED | ADC2_WIFI | CURRENT_EXCEEDED",
"message": "Human-readable error",
"severity": "error"
}
],
"warnings": [
{
"gpio": 12,
"code": "STRAPPING_PIN | UART_BT_CONFLICT | PWM_AUDIO_CONFLICT | DEPRECATED_LIB | CURRENT_WARNING | BOOT_STATE",
"message": "Human-readable warning",
"severity": "warning"
}
],
"summary": {
"total_pins": 8,
"errors": 0,
"warnings": 2,
"current_draw_ma": 32
}
}
Exit codes: 0 = valid (warnings ok), 1 = errors found, 2 = invalid input
Location: scripts/generate_config.py
CLI usage:
python scripts/generate_config.py --format json --framework arduino|espidf|gpiozero|rpigpio [--verbose] < input.json
python scripts/generate_config.py --help
Input JSON schema: same as validate_pinmap.py input, plus:
{
"platform": "rpi | esp32",
"variant": "rpi3 | rpi4 | rpi5 | rpi_zero2w | esp32 | esp32s2 | esp32s3 | esp32c3 | esp32c6",
"module": "WROOM | WROVER | null",
"wifi_enabled": true,
"pins": [],
"framework": "arduino | espidf | gpiozero | rpigpio"
}
Output JSON schema:
{
"config_lines": ["dtoverlay=i2c1", "dtparam=spi=on"],
"init_code": "# Full initialization code as a single string with newlines",
"wiring_notes": [
"Connect BME280 SDA to GPIO2 (physical pin 3). Add 4.7kΩ pull-up to 3.3V."
],
"warnings": ["GPIO12 is a strapping pin — see boot state notes"],
"alternatives": [
{
"original_gpio": 12,
"alternative_gpio": 17,
"reason": "Avoids MTDI strapping pin risk"
}
]
}
Exit codes: 0 = success, 1 = generation error, 2 = invalid input
User request: "Set up a weather station with BME280 temperature sensor and SSD1306 OLED display on Raspberry Pi 4"
Generated pinmap (excerpt):
{
"platform": "rpi",
"variant": "rpi4",
"pins": [
{"gpio": 2, "function": "I2C_SDA", "protocol_bus": 1, "device": "BME280+SSD1306", "pull": "external_up"},
{"gpio": 3, "function": "I2C_SCL", "protocol_bus": 1, "device": "BME280+SSD1306", "pull": "external_up"},
{"gpio": 17, "function": "DIGITAL_OUT", "device": "Status LED", "pull": "none"}
]
}
Generated initialization code (gpiozero, excerpt):
from gpiozero import LED
import smbus2
bus = smbus2.SMBus(1) # I2C bus 1: SDA=GPIO2, SCL=GPIO3
# BME280 at 0x76, SSD1306 at 0x3C — shared I2C bus, no conflict
status_led = LED(17)
Weekly Installs
1
Repository
GitHub Stars
5
First Seen
1 day ago
Security Audits
Gen Agent Trust HubPassSocketFailSnykPass
Installed on
amp1
cline1
openclaw1
opencode1
cursor1
kimi-cli1
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
147,400 周安装