feat: add GPIO policy module and tool header

This commit is contained in:
Asklv
2026-03-07 16:15:28 +08:00
parent b6e11d837b
commit e278264133
3 changed files with 156 additions and 0 deletions

22
main/tools/gpio_policy.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
/* GPIO pin range defaults for ESP32-S3 (safe user-accessible pins) */
#define MIMI_GPIO_MIN_PIN 1
#define MIMI_GPIO_MAX_PIN 21
#define MIMI_GPIO_ALLOWED_CSV "" /* empty = use min/max range */
/**
* Check if a pin is allowed for user GPIO operations.
* Validates against the allowlist or default range, and blocks
* pins reserved for flash/PSRAM on ESP32.
*/
bool gpio_policy_pin_is_allowed(int pin);
/**
* Write a human-readable hint if the pin is forbidden for a known reason.
* Returns true if a hint was written (and the caller should return the error).
*/
bool gpio_policy_pin_forbidden_hint(int pin, char *result, size_t result_len);