unPhone implementation and more (#169)
- 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`
This commit is contained in:
committed by
GitHub
parent
3ea02d912f
commit
72230129bb
@@ -74,7 +74,7 @@ bool SpiSdCard::mountInternal(const char* mountPoint) {
|
||||
// The following value is from T-Deck repo's UnitTest.ino project:
|
||||
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
|
||||
// Observation: Using this automatically sets the bus to 20MHz
|
||||
host.max_freq_khz = config->spiFrequency;
|
||||
host.max_freq_khz = config->spiFrequency / 1000U;
|
||||
host.slot = config->spiHost;
|
||||
|
||||
esp_err_t result = esp_vfs_fat_sdspi_mount(mountPoint, &host, &slot_config, &mount_config, &card);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "I2cDevice.h"
|
||||
|
||||
bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) {
|
||||
out = (data[0] & 0x0F) << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2cDevice::readRegister14(uint8_t reg, float& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) {
|
||||
out = (data[0] & 0x3F) << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) {
|
||||
out = data[0] << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2cDevice::readRegister8(uint8_t reg, uint8_t& result) const {
|
||||
return tt::hal::i2c::masterWriteRead(port, address, ®, 1, &result, 1, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
bool I2cDevice::writeRegister8(uint8_t reg, uint8_t value) const {
|
||||
return tt::hal::i2c::masterWriteRegister(port, address, reg, &value, 1, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
bool I2cDevice::bitOn(uint8_t reg, uint8_t bitmask) const {
|
||||
uint8_t state;
|
||||
if (readRegister8(reg, state)) {
|
||||
state |= bitmask;
|
||||
return writeRegister8(reg, state);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool I2cDevice::bitOff(uint8_t reg, uint8_t bitmask) const {
|
||||
uint8_t state;
|
||||
if (readRegister8(reg, state)) {
|
||||
state &= ~bitmask;
|
||||
return writeRegister8(reg, state);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#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) {}
|
||||
};
|
||||
@@ -80,14 +80,6 @@ bool isStarted(i2c_port_t port) {
|
||||
return started;
|
||||
}
|
||||
|
||||
bool read(i2c_port_t port, uint16_t address, uint32_t reg, uint8_t* buffer, uint16_t size, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool write(i2c_port_t port, uint16_t address, uint32_t reg, const uint8_t* buffer, uint16_t size, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool lock(i2c_port_t port, TickType_t timeout) {
|
||||
return dataArray[port].mutex.lock(timeout);
|
||||
}
|
||||
@@ -96,6 +88,30 @@ bool unlock(i2c_port_t port) {
|
||||
return dataArray[port].mutex.unlock();
|
||||
}
|
||||
|
||||
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout) {
|
||||
return (rand()) % 25 == 0;
|
||||
}
|
||||
|
||||
@@ -60,13 +60,12 @@ bool startMassStorageWithSdmmc() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = tusbStartMassStorageWithSdmmc();
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to init mass storage: %s", esp_err_to_name(result));
|
||||
return false;
|
||||
} else {
|
||||
if (tusbStartMassStorageWithSdmmc()) {
|
||||
currentMode = Mode::MassStorageSdmmc;
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to init mass storage");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,12 @@ bool tusbStartMassStorageWithSdmmc() {
|
||||
}
|
||||
};
|
||||
|
||||
return tinyusb_msc_storage_init_sdmmc(&config_sdmmc) == ESP_OK;
|
||||
auto result = tinyusb_msc_storage_init_sdmmc(&config_sdmmc);
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "TinyUSB init failed: %s", esp_err_to_name(result));
|
||||
}
|
||||
|
||||
return result == ESP_OK;
|
||||
}
|
||||
|
||||
void tusbStop() {
|
||||
|
||||
Reference in New Issue
Block a user