- Implemented [unPhone](https://unphone.net/) v9 board - Updated `.clang-format` to better reflect the intended code style - Fix SD card compatibility issues for all boards (frequency wasn't set well) - Moved `I2cDevice` class from CoreS3 board project to TactilityHeadless project - Tactility configuration now has default empty lists for apps and services fields - Fix for Launcher app: we don't need padding when showing it vertically - Fix for I2cDevice read/write calls that checked for `esp_err_t` instead of `bool` - Fix for TinyUSB init that checked for `esp_err_t` instead of `bool`
33 lines
1.0 KiB
C++
33 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "./I2c.h"
|
|
|
|
/**
|
|
* Represents an I2C peripheral at a specific port and address.
|
|
* It helps to read and write registers.
|
|
*
|
|
* All read and write calls are thread-safe.
|
|
*/
|
|
class I2cDevice {
|
|
|
|
protected:
|
|
|
|
i2c_port_t port;
|
|
uint8_t address;
|
|
|
|
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
|
|
|
|
bool readRegister8(uint8_t reg, uint8_t& result) const;
|
|
bool writeRegister8(uint8_t reg, uint8_t value) const;
|
|
bool readRegister12(uint8_t reg, float& out) const;
|
|
bool readRegister14(uint8_t reg, float& out) const;
|
|
bool readRegister16(uint8_t reg, uint16_t& out) const;
|
|
bool bitOn(uint8_t reg, uint8_t bitmask) const;
|
|
bool bitOff(uint8_t reg, uint8_t bitmask) const;
|
|
bool bitOnByIndex(uint8_t reg, uint8_t index) const { return bitOn(reg, 1 << index); }
|
|
bool bitOffByIndex(uint8_t reg, uint8_t index) const { return bitOff(reg, 1 << index); }
|
|
public:
|
|
|
|
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
|
|
};
|