CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api_gpio.cpp File Reference

GPIO / PWM / ADC / I2C / SAO host API with capability + pin-lock. More...

#include "cdc_hal/hw_config.h"
#include "cdc_hal/II2cBus.h"
#include "plugin_manager/host_api.h"
#include "plugin_manager/Plugin.h"
#include "plugin_manager/PluginGpioPolicy.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "esp_adc/adc_oneshot.h"
#include "cdc_log.h"
#include <array>
#include <cstring>

Go to the source code of this file.

Functions

void * plg_get_active_plugin (void)
void plg_log_warn (const char *msg)
int host_gpio_set_direction (uint8_t pin, uint8_t direction)
 Configure pin direction (one of GPIO_DIR_*).
int host_gpio_set_pull (uint8_t pin, uint8_t pull)
 Configure internal pull resistor (one of GPIO_PULL_*).
int host_gpio_write (uint8_t pin, bool level)
 Drive a digital output high/low.
int host_gpio_read (uint8_t pin, bool *level)
 Sample a digital input.
int host_gpio_release (uint8_t pin)
 Release the pin claim so other plugins can use it.
void plg_gpio_on_unload (void *plugin)
int host_gpio_pwm_start (uint8_t pin, uint32_t freq_hz, uint16_t duty_per_mille)
 Start LEDC PWM on pin.
int host_gpio_pwm_set_duty (uint8_t pin, uint16_t duty_per_mille)
 Update PWM duty without restarting the timer.
int host_gpio_pwm_stop (uint8_t pin)
 Stop PWM and release the LEDC channel.
int host_adc_read (uint8_t pin, uint16_t *raw, uint16_t *millivolt)
 Single-shot ADC read.
int host_i2c_write (uint8_t bus, uint8_t addr, const uint8_t *data, size_t len)
 I2C write transaction.
int host_i2c_read (uint8_t bus, uint8_t addr, uint8_t *data, size_t len)
 I2C read transaction.
int host_i2c_write_read (uint8_t bus, uint8_t addr, const uint8_t *wr, size_t wr_len, uint8_t *rd, size_t rd_len)
 I2C write-then-read transaction with repeated start.
int host_i2c_scan (uint8_t bus, uint8_t *found_addrs, size_t *count)
 Scan the I2C bus for responding addresses.
int host_sao_eeprom_read (uint16_t off, uint8_t *buf, size_t len)
 Read from the SAO addon EEPROM at byte offset.
int host_sao_eeprom_write (uint16_t off, const uint8_t *buf, size_t len)
 Write to the SAO addon EEPROM at byte offset.

Detailed Description

GPIO / PWM / ADC / I2C / SAO host API with capability + pin-lock.

Per-call enforcement on top of the load-time CapabilityChecker:

  1. Pin must be allowed by the plugin manifest.
  2. Pin must not be locked by another plugin or the native serial CLI.
  3. Pin must not be on the firmware-internal block list (Display SPI, TROPIC01 CS, charger I2C, USB, etc.) - that list is hard-coded.

The lock table is also consulted by future GPIO serial commands so a native console session cannot fight a running plugin for the same pin.

Definition in file host_api_gpio.cpp.

Function Documentation

◆ plg_get_active_plugin()

void * plg_get_active_plugin ( void )

Definition at line 24 of file plugin_log_bridge.cpp.

◆ plg_gpio_on_unload()

void plg_gpio_on_unload ( void * plugin)

Definition at line 186 of file host_api_gpio.cpp.

References LOG_W, and TAG.

◆ plg_log_warn()

void plg_log_warn ( const char * msg)

Definition at line 20 of file plugin_log_bridge.cpp.