CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
PluginGpioPolicy.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <cstddef>
15#include <cstdint>
16
18
19inline constexpr uint8_t BLOCKED[] = {
20 0, // FLASH_BTN (boot strapping + power button)
21 1, // EXP_IRQ (IO expander interrupt)
22 8, // EPD_LED (e-paper backlight)
23 10, // TR01_CS (TROPIC01 chip select)
24 11, // SPI_MISO (shared SPI bus)
25 12, // SPI_SCLK
26 13, // SPI_MOSI
27 17, // I2C0_SDA (charger + IO expander bus)
28 18, // I2C0_SCL
29 19, // USB D-
30 20, // USB D+
31 21, // CHG_DSEL (charger detection select)
32 26, 27, 28, 29, 30, 31, 32, // PSRAM/flash (not exposed via GPIO peripheral)
33 33, 34, 35, 36, 37, // Octal PSRAM data lines SPIIO4-7 + DQS (CONFIG_SPIRAM_MODE_OCT)
34 39, // CHG_IRQ
35 41, // EPD_CS
36 42, // EPD_BUSY
37 45, // EPD_DC
38 46, // EPD_RST
39 47, // I2C1_SDA (expansion bus - reachable via host_i2c_*, not as raw GPIO)
40 48, // I2C1_SCL
41};
42
43inline constexpr uint8_t ALLOWED[] = {
44 2, // Grove SIG0 (also RPi header)
45 3, // Grove SIG1 (also RPi header; ESP32-S3 strapping pin - boot mode)
46 4, // Header (ADC1_CH3)
47 5, // Header (ADC1_CH4)
48 6, // Header (ADC1_CH5)
49 7, // Header (ADC1_CH6)
50 9, // Header
51 14, // Header (ADC2)
52 15, // SAO GPIO1
53 16, // SAO GPIO2
54 38, // Header
55 40, // Header (JTAG TDO - safe unless USB-JTAG-Serial debugger is active)
56 43, // Header (UART0 TX - safe once serial console moves to CDC-only)
57 44, // Header (UART0 RX)
58};
59
60inline constexpr size_t BLOCKED_COUNT = sizeof(BLOCKED) / sizeof(BLOCKED[0]);
61inline constexpr size_t ALLOWED_COUNT = sizeof(ALLOWED) / sizeof(ALLOWED[0]);
62
63inline bool isBlocked(uint8_t pin)
64{
65 for (size_t i = 0; i < BLOCKED_COUNT; ++i) {
66 if (BLOCKED[i] == pin) return true;
67 }
68 return false;
69}
70
71inline bool isAllowed(uint8_t pin)
72{
73 if (isBlocked(pin)) return false;
74 for (size_t i = 0; i < ALLOWED_COUNT; ++i) {
75 if (ALLOWED[i] == pin) return true;
76 }
77 return false;
78}
79
80} // namespace cdc::plugin_manager::gpio_policy