![]() |
OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
|
Hardware abstraction and low-level utilities. More...
#include "InternalTypes.hpp"#include "SimWheelTypes.hpp"#include "driver/i2c_types.h"#include "driver/i2c_master.h"Go to the source code of this file.
Classes | |
| class | i2c_error |
| Exception for I2C bus initialization failure. More... | |
| class | i2c_device_not_found |
| Exception for I2C devices not found. More... | |
| class | i2c_full_address_unknown |
| Exception for unknown full I2C address. More... | |
Macros | |
| #define | AS_GPIO(pin) |
| Cast GPIO to an ESP32 pin number. | |
| #define | AS_PORT(bus) |
| Cast I2CBus to an ESP32 port number. | |
| #define | GPIO_SET_LEVEL(pin, level) |
| Macro to write a logic level in a GPIO pin. | |
| #define | I2C_SLAVE(dev) |
| Cast to an I2C slave device handle. | |
| #define | GPIO_GET_LEVEL(pin) |
| Macro to read the logic level in a GPIO pin. | |
| #define | DELAY_TICKS(ticks) |
| Macro to wait in tick units. | |
| #define | DELAY_MS(ms) |
| Macro to wait in millisecond units. | |
| #define | NS_PER_LOOP ((4000 + CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ - 1) / CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) |
| Time per loop of active_wait_ns() computed as 4 CPU instructions. | |
| #define | active_wait_ns(n) |
| Active wait without context switching. | |
Typedefs | |
| typedef void(* | ISRHandler) (void *arg) |
| Interrupt Service Routine. | |
Functions | |
| void | internals::hal::i2c::initialize (GPIO sda, GPIO scl, I2CBus bus, bool enableInternalPullup=true) |
| Initialize an I2C bus to certain pins. | |
| void | internals::hal::i2c::require (I2CBus bus=I2CBus::PRIMARY) |
| Ensure the I2C bus is initialized. | |
| i2c_master_dev_handle_t | internals::hal::i2c::add_device (uint8_t address7bits, uint8_t max_speed_multiplier, I2CBus bus) |
| Add an slave device ensuring the bus is initialized. | |
| void | internals::hal::i2c::remove_device (i2c_master_dev_handle_t i2c_device) |
| Remove an slave device. | |
| bool | internals::hal::i2c::probe (uint8_t address7bits, I2CBus bus=I2CBus::PRIMARY) |
| Check slave device availability on an I2C bus. | |
| void | internals::hal::i2c::probe (std::vector< uint8_t > &result, I2CBus bus=I2CBus::PRIMARY) |
| Retrieve all devices available on an I2C bus. | |
| void | internals::hal::i2c::abortOnInvalidAddress (uint8_t address7bits, uint8_t minAddress=0, uint8_t maxAddress=127) |
| Abort and reboot on an invalid I2C address. | |
| uint8_t | internals::hal::i2c::findFullAddress (std::vector< uint8_t > &fullAddressList, uint8_t hardwareAddress, uint8_t hardwareAddressMask=0b00000111) |
| Find the full address of a device. | |
| int | internals::hal::gpio::getADCreading (ADC_GPIO pin, int sampleCount=1) |
| Get the mean of some continuous ADC readings. | |
| void | internals::hal::gpio::forOutput (OutputGPIO pin, bool initialLevel, bool openDrain) |
| Configure a pin for output. | |
| void | internals::hal::gpio::forInput (InputGPIO pin, bool enablePullDown, bool enablePullUp) |
| Configure a pin for digital input. | |
| void | internals::hal::gpio::enableISR (InputGPIO pin, ISRHandler handler, void *param=nullptr) |
| Enable an interrupt service routine. | |
Hardware abstraction and low-level utilities.
Definition in file HAL.hpp.
| #define active_wait_ns | ( | n | ) |
Active wait without context switching.
| n | Time to wait in nanoseconds |
| #define AS_GPIO | ( | pin | ) |
| #define AS_PORT | ( | bus | ) |
| #define DELAY_MS | ( | ms | ) |
| #define DELAY_TICKS | ( | ticks | ) |
| #define GPIO_GET_LEVEL | ( | pin | ) |
| #define GPIO_SET_LEVEL | ( | pin, | |
| level ) |
| #define I2C_SLAVE | ( | dev | ) |
| #define NS_PER_LOOP ((4000 + CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ - 1) / CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) |
Time per loop of active_wait_ns() computed as 4 CPU instructions.
| typedef void(* ISRHandler) (void *arg) |
| void internals::hal::i2c::abortOnInvalidAddress | ( | uint8_t | address7bits, |
| uint8_t | minAddress = 0, | ||
| uint8_t | maxAddress = 127 ) |
Abort and reboot on an invalid I2C address.
| address7bits | I2C address to check in 7 bits format. |
| minAddress | Start of custom valid address range, inclusive. |
| maxAddress | End of custom valid address range, inclusive. |
| i2c_master_dev_handle_t internals::hal::i2c::add_device | ( | uint8_t | address7bits, |
| uint8_t | max_speed_multiplier, | ||
| I2CBus | bus ) |
Add an slave device ensuring the bus is initialized.
| address7bits | Full address in 7 bit format |
| max_speed_multiplier | A bus speed multiplier in the range [1,4] |
| bus | I2C bus required |
| void internals::hal::gpio::enableISR | ( | InputGPIO | pin, |
| ISRHandler | handler, | ||
| void * | param = nullptr ) |
Enable an interrupt service routine.
| pin | Pin |
| handler | Routine |
| param | Parameter to handler |
| uint8_t internals::hal::i2c::findFullAddress | ( | std::vector< uint8_t > & | fullAddressList, |
| uint8_t | hardwareAddress, | ||
| uint8_t | hardwareAddressMask = 0b00000111 ) |
Find the full address of a device.
| [in] | fullAddressList | A list of full addresses obtained from i2c::probe() |
| [in] | hardwareAddress | A partial 7-bit address |
| [in] | hardwareAddressMask | A mask. Bits set to 1 will be taken from hardwareAddress. Bits set to 0 have to be found. |
hardwareAddress hardwareAddress | void internals::hal::gpio::forInput | ( | InputGPIO | pin, |
| bool | enablePullDown, | ||
| bool | enablePullUp ) |
Configure a pin for digital input.
| pin | |
| enablePullDown | |
| enablePullUp |
| void internals::hal::gpio::forOutput | ( | OutputGPIO | pin, |
| bool | initialLevel, | ||
| bool | openDrain ) |
Configure a pin for output.
| pin | Pin number |
| initialLevel | If true, set to HIGH after initialization. Otherwise, set to LOW after initialization. |
| openDrain | If true, configure in open drain mode. If false, configure in output mode. |
| int internals::hal::gpio::getADCreading | ( | ADC_GPIO | pin, |
| int | sampleCount = 1 ) |
Get the mean of some continuous ADC readings.
| pin | Pin number. Must be ADC-capable. |
| sampleCount | Number of continuous ADC samples. Pass 1 for a single reading (default). Must be greater than zero. |
sampleCount is not greater than zero. | void internals::hal::i2c::initialize | ( | GPIO | sda, |
| GPIO | scl, | ||
| I2CBus | bus, | ||
| bool | enableInternalPullup = true ) |
Initialize an I2C bus to certain pins.
| sda | SDA pin for the I2C bus. |
| scl | SCL pin for the I2C bus. |
| bus | I2C bus to initialize. |
| enableInternalPullup | If true (default), the bus is pulled up using internal pullup resistors. If false, external pullup resistors must be in place as the internal ones are not enabled. Otherwise, the bus won't work. |
| void internals::hal::i2c::probe | ( | std::vector< uint8_t > & | result, |
| I2CBus | bus = I2CBus::PRIMARY ) |
Retrieve all devices available on an I2C bus.
| [out] | result | List of addresses found, in 7-bit format. |
| [in] | bus | I2C bus. |
| bool internals::hal::i2c::probe | ( | uint8_t | address7bits, |
| I2CBus | bus = I2CBus::PRIMARY ) |
Check slave device availability on an I2C bus.
| address7bits | I2C address of a slave device in 7 bits format. |
| bus | I2C bus. |
| void internals::hal::i2c::remove_device | ( | i2c_master_dev_handle_t | i2c_device | ) |
Remove an slave device.
| i2c_device | Device handle |
| void internals::hal::i2c::require | ( | I2CBus | bus = I2CBus::PRIMARY | ) |
Ensure the I2C bus is initialized.
| bus | I2C bus required. |