Ken Van Hoeylandt 1627b9fa85
Merge develop into main (#316)
- Updated all boards to use `hal::Configuration.createDevices`
- Updated all boards to use new directory structure and file naming convention
- Refactored `Xpt2046SoftSpi` driver.
- Created `Axp2101Power` device in `Drivers/AXP2101`
- Removed global static instances from some drivers (instances that kept a reference to the Device*)
- Improved `SystemInfoApp` UI: better memory labels, hide external memory bar when there's no PSRAM
- Fix for HAL: register touch devices after displays are registered
- Fix for Boot splash hanging on WiFi init: unlock file lock after using it
2025-09-03 22:05:28 +02:00

51 lines
1.6 KiB
C++

#include "axp192/axp192.h"
#include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.h>
#include <Tactility/CoreDefines.h>
#include <driver/i2c.h>
#include <driver/spi_master.h>
constexpr auto* TAG = "Core2";
axp192_t axpDevice;
static int32_t axpI2cRead(TT_UNUSED void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) {
if (tt::hal::i2c::masterReadRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS)) {
return AXP192_OK;
} else {
return 1;
}
}
static int32_t axpI2cWrite(TT_UNUSED void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) {
if (tt::hal::i2c::masterWriteRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS)) {
return AXP192_OK;
} else {
return 1;
}
}
void initAxp() {
axpDevice.read = axpI2cRead;
axpDevice.write = axpI2cWrite;
axp192_ioctl(&axpDevice, AXP192_LDO2_SET_VOLTAGE, 3300); // LCD + SD
axp192_ioctl(&axpDevice, AXP192_LDO3_SET_VOLTAGE, 0); // VIB_MOTOR STOP
axp192_ioctl(&axpDevice, AXP192_DCDC3_SET_VOLTAGE, 3300);
axp192_ioctl(&axpDevice, AXP192_LDO2_ENABLE);
axp192_ioctl(&axpDevice, AXP192_LDO3_DISABLE);
axp192_ioctl(&axpDevice, AXP192_DCDC3_ENABLE);
axp192_write(&axpDevice, AXP192_PWM1_DUTY_CYCLE_2, 255); // PWM 255 (LED OFF)
axp192_write(&axpDevice, AXP192_GPIO1_CONTROL, 0x02); // GPIO1 PWM
// TODO: We could charge at 390mA according to the M5Unified code, but the AXP driver in M5Unified limits to 132mA, so it's unclear what the AXP supports.
}
bool initBoot() {
TT_LOG_I(TAG, "initBoot");
initAxp();
return true;
}