CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
Hardware: GPIO / PWM / ADC / I2C / SAO

Direct access to user-accessible GPIO, ADC, I2C and the SAO EEPROM. More...

Macros

#define GPIO_DIR_IN   0
#define GPIO_DIR_OUT   1
#define GPIO_DIR_OUT_OD   2
#define GPIO_PULL_NONE   0
#define GPIO_PULL_UP   1
#define GPIO_PULL_DOWN   2

Functions

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.
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 offset, uint8_t *buf, size_t len)
 Read from the SAO addon EEPROM at byte offset.
int host_sao_eeprom_write (uint16_t offset, const uint8_t *buf, size_t len)
 Write to the SAO addon EEPROM at byte offset.

Detailed Description

Direct access to user-accessible GPIO, ADC, I2C and the SAO EEPROM.

Pin usage must be declared in the manifest (capabilities.gpio_pins, pwm_pins, adc_pins). Conflicting claims fail with HOST_ERR_BUSY.

Macro Definition Documentation

◆ GPIO_DIR_IN

#define GPIO_DIR_IN   0

Definition at line 1475 of file host_api.h.

Referenced by host_gpio_set_direction().

◆ GPIO_DIR_OUT

#define GPIO_DIR_OUT   1

Definition at line 1476 of file host_api.h.

Referenced by host_gpio_set_direction().

◆ GPIO_DIR_OUT_OD

#define GPIO_DIR_OUT_OD   2

Definition at line 1477 of file host_api.h.

Referenced by host_gpio_set_direction().

◆ GPIO_PULL_DOWN

#define GPIO_PULL_DOWN   2

Definition at line 1481 of file host_api.h.

Referenced by host_gpio_set_pull().

◆ GPIO_PULL_NONE

#define GPIO_PULL_NONE   0

Definition at line 1479 of file host_api.h.

Referenced by host_gpio_set_pull().

◆ GPIO_PULL_UP

#define GPIO_PULL_UP   1

Definition at line 1480 of file host_api.h.

Referenced by host_gpio_set_pull().

Function Documentation

◆ host_adc_read()

int host_adc_read ( uint8_t pin,
uint16_t * raw,
uint16_t * millivolt )

Single-shot ADC read.

Parameters
rawRaw ADC count, or NULL to skip.
millivoltCalibrated voltage in mV, or NULL to skip.

Definition at line 271 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NOT_SUPPORTED, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_adc_read().

◆ host_gpio_pwm_set_duty()

int host_gpio_pwm_set_duty ( uint8_t pin,
uint16_t duty_per_mille )

Update PWM duty without restarting the timer.

Definition at line 250 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_pwm_set_duty().

◆ host_gpio_pwm_start()

int host_gpio_pwm_start ( uint8_t pin,
uint32_t freq_hz,
uint16_t duty_per_mille )

Start LEDC PWM on pin.

Parameters
duty_per_milleDuty cycle in 0..1000 (per-mille resolution).

Definition at line 210 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_pwm_start().

◆ host_gpio_pwm_stop()

int host_gpio_pwm_stop ( uint8_t pin)

Stop PWM and release the LEDC channel.

Definition at line 262 of file host_api_gpio.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_pwm_stop().

◆ host_gpio_read()

int host_gpio_read ( uint8_t pin,
bool * level )

Sample a digital input.

Definition at line 167 of file host_api_gpio.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_read().

◆ host_gpio_release()

int host_gpio_release ( uint8_t pin)

Release the pin claim so other plugins can use it.

Definition at line 176 of file host_api_gpio.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_release().

◆ host_gpio_set_direction()

int host_gpio_set_direction ( uint8_t pin,
uint8_t direction )

Configure pin direction (one of GPIO_DIR_*).

Definition at line 124 of file host_api_gpio.cpp.

References GPIO_DIR_IN, GPIO_DIR_OUT, GPIO_DIR_OUT_OD, HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_set_direction().

◆ host_gpio_set_pull()

int host_gpio_set_pull ( uint8_t pin,
uint8_t pull )

Configure internal pull resistor (one of GPIO_PULL_*).

Definition at line 143 of file host_api_gpio.cpp.

References GPIO_PULL_DOWN, GPIO_PULL_NONE, GPIO_PULL_UP, HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_set_pull().

◆ host_gpio_write()

int host_gpio_write ( uint8_t pin,
bool level )

Drive a digital output high/low.

Definition at line 159 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_gpio_write().

◆ host_i2c_read()

int host_i2c_read ( uint8_t bus,
uint8_t addr,
uint8_t * data,
size_t len )

I2C read transaction.

Definition at line 329 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_i2c_read().

◆ host_i2c_scan()

int host_i2c_scan ( uint8_t bus,
uint8_t * found_addrs,
size_t * count )

Scan the I2C bus for responding addresses.

Parameters
countIn: capacity of found_addrs; out: number of devices found.

Definition at line 351 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_i2c_scan().

◆ host_i2c_write()

int host_i2c_write ( uint8_t bus,
uint8_t addr,
const uint8_t * data,
size_t len )

I2C write transaction.

Definition at line 319 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_i2c_write().

◆ host_i2c_write_read()

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.

Definition at line 339 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_i2c_write_read().

◆ host_sao_eeprom_read()

int host_sao_eeprom_read ( uint16_t offset,
uint8_t * buf,
size_t len )

Read from the SAO addon EEPROM at byte offset.

Definition at line 368 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, HOST_OK, and SAO_EEPROM_ADDR.

Referenced by cdc::plugin_manager::w_host_sao_eeprom_read().

◆ host_sao_eeprom_write()

int host_sao_eeprom_write ( uint16_t offset,
const uint8_t * buf,
size_t len )

Write to the SAO addon EEPROM at byte offset.

Definition at line 378 of file host_api_gpio.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_CAPABILITY, HOST_OK, and SAO_EEPROM_ADDR.

Referenced by cdc::plugin_manager::w_host_sao_eeprom_write().