mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-21 07:55:06 +00:00
Add StickC Plus implementation
This commit is contained in:
parent
f45f809c9b
commit
bd7e6197f4
@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS ${SOURCE_FILES}
|
SRCS ${SOURCE_FILES}
|
||||||
INCLUDE_DIRS "Source"
|
INCLUDE_DIRS "Source"
|
||||||
REQUIRES Tactility esp_lvgl_port esp_lcd ILI934x FT6x36 driver vfs fatfs
|
REQUIRES Tactility esp_lvgl_port esp_lcd AXP192 ST7789 ButtonControl
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,9 +1,4 @@
|
|||||||
# M5Stack Core2
|
# M5Stack StickC Plus
|
||||||
|
|
||||||
This board implementation concerns the original Core2 hardware and **not** the v1.1 variant.
|
|
||||||
|
|
||||||
Reference implementations:
|
|
||||||
- [ESP-BSP](https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_2)
|
|
||||||
|
|
||||||
Docs:
|
Docs:
|
||||||
- [M5Stack.com](https://docs.m5stack.com/en/core/Core2)
|
- [M5Stack.com](https://docs.m5stack.com/en/core/m5stickc_plus)
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
bool initBoot();
|
|
||||||
@ -1,25 +1,36 @@
|
|||||||
#include "M5stackCore2.h"
|
#include "M5StackStickCPlus.h"
|
||||||
#include "InitBoot.h"
|
|
||||||
#include "devices/Display.h"
|
#include "devices/Display.h"
|
||||||
#include "devices/Core2Power.h"
|
#include "devices/Power.h"
|
||||||
#include "devices/SdCard.h"
|
#include <ButtonControl.h>
|
||||||
|
|
||||||
#include <lvgl.h>
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
|
|
||||||
#define CORE2_SPI_TRANSFER_SIZE_LIMIT (CORE2_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)
|
#define SPI_TRANSFER_SIZE_LIMIT (LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)
|
||||||
|
|
||||||
using namespace tt::hal;
|
using namespace tt::hal;
|
||||||
|
|
||||||
|
constexpr auto* TAG = "StickCPlus";
|
||||||
|
|
||||||
|
bool initBoot() {
|
||||||
|
TT_LOG_I(TAG, "initBoot");
|
||||||
|
|
||||||
|
// CH552 applies 4 V to GPIO 0, which reduces Wi-Fi sensitivity
|
||||||
|
// Setting output to high adds a bias of 3.3 V and suppresses over-voltage:
|
||||||
|
gpio::configure(0, gpio::Mode::Output, false, false);
|
||||||
|
gpio::setLevel(0, true);
|
||||||
|
|
||||||
|
return initAxp();
|
||||||
|
}
|
||||||
|
|
||||||
static DeviceVector createDevices() {
|
static DeviceVector createDevices() {
|
||||||
return {
|
return {
|
||||||
createPower(),
|
getAxp192(),
|
||||||
createSdCard(),
|
// ButtonControl::createTwoButtonControl(37, 39),
|
||||||
createDisplay()
|
createDisplay()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const Configuration m5stack_core2 = {
|
extern const Configuration m5stack_stickc_plus = {
|
||||||
.initBoot = initBoot,
|
.initBoot = initBoot,
|
||||||
.createDevices = createDevices,
|
.createDevices = createDevices,
|
||||||
.i2c = {
|
.i2c = {
|
||||||
@ -41,7 +52,7 @@ extern const Configuration m5stack_core2 = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
i2c::Configuration {
|
i2c::Configuration {
|
||||||
.name = "External", // (Grove)
|
.name = "Grove",
|
||||||
.port = I2C_NUM_1,
|
.port = I2C_NUM_1,
|
||||||
.initMode = i2c::InitMode::ByTactility,
|
.initMode = i2c::InitMode::ByTactility,
|
||||||
.isMutable = true,
|
.isMutable = true,
|
||||||
@ -63,17 +74,17 @@ extern const Configuration m5stack_core2 = {
|
|||||||
.device = SPI2_HOST,
|
.device = SPI2_HOST,
|
||||||
.dma = SPI_DMA_CH_AUTO,
|
.dma = SPI_DMA_CH_AUTO,
|
||||||
.config = {
|
.config = {
|
||||||
.mosi_io_num = GPIO_NUM_23,
|
.mosi_io_num = GPIO_NUM_15,
|
||||||
.miso_io_num = GPIO_NUM_38,
|
.miso_io_num = GPIO_NUM_NC,
|
||||||
.sclk_io_num = GPIO_NUM_18,
|
.sclk_io_num = GPIO_NUM_13,
|
||||||
.quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
.quadwp_io_num = GPIO_NUM_NC,
|
||||||
.quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
.quadhd_io_num = GPIO_NUM_NC,
|
||||||
.data4_io_num = GPIO_NUM_NC,
|
.data4_io_num = GPIO_NUM_NC,
|
||||||
.data5_io_num = GPIO_NUM_NC,
|
.data5_io_num = GPIO_NUM_NC,
|
||||||
.data6_io_num = GPIO_NUM_NC,
|
.data6_io_num = GPIO_NUM_NC,
|
||||||
.data7_io_num = GPIO_NUM_NC,
|
.data7_io_num = GPIO_NUM_NC,
|
||||||
.data_io_default_level = false,
|
.data_io_default_level = false,
|
||||||
.max_transfer_sz = CORE2_SPI_TRANSFER_SIZE_LIMIT,
|
.max_transfer_sz = SPI_TRANSFER_SIZE_LIMIT,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||||
.intr_flags = 0
|
.intr_flags = 0
|
||||||
5
Boards/M5stackStickCPlus/Source/M5StackStickCPlus.h
Normal file
5
Boards/M5stackStickCPlus/Source/M5StackStickCPlus.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Tactility/hal/Configuration.h>
|
||||||
|
|
||||||
|
extern const tt::hal::Configuration m5stack_stickc_plus;
|
||||||
@ -1,5 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Tactility/hal/Configuration.h>
|
|
||||||
|
|
||||||
extern const tt::hal::Configuration m5stack_core2;
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
#include "Core2Power.h"
|
|
||||||
#include <Tactility/TactilityCore.h>
|
|
||||||
#include "axp192/axp192.h"
|
|
||||||
|
|
||||||
constexpr auto TAG = "Core2Power";
|
|
||||||
|
|
||||||
extern axp192_t axpDevice;
|
|
||||||
|
|
||||||
bool Core2Power::supportsMetric(MetricType type) const {
|
|
||||||
switch (type) {
|
|
||||||
using enum MetricType;
|
|
||||||
case BatteryVoltage:
|
|
||||||
case ChargeLevel:
|
|
||||||
case IsCharging:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Core2Power::getMetric(MetricType type, MetricData& data) {
|
|
||||||
switch (type) {
|
|
||||||
using enum MetricType;
|
|
||||||
case BatteryVoltage: {
|
|
||||||
float voltage;
|
|
||||||
if (axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &voltage) == ESP_OK) {
|
|
||||||
data.valueAsUint32 = (uint32_t)std::max((voltage * 1000.f), 0.0f);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ChargeLevel: {
|
|
||||||
float vbat, charge_current;
|
|
||||||
if (
|
|
||||||
axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &vbat) == ESP_OK &&
|
|
||||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK
|
|
||||||
) {
|
|
||||||
float max_voltage = 4.20f;
|
|
||||||
float min_voltage = 2.69f; // From M5Unified
|
|
||||||
float voltage_correction = (charge_current > 0.01f) ? -0.1f : 0.f; // Roughly 0.1V drop when ccharging
|
|
||||||
float corrected_voltage = vbat + voltage_correction;
|
|
||||||
if (corrected_voltage > 2.69f) {
|
|
||||||
float charge_factor = (corrected_voltage - min_voltage) / (max_voltage - min_voltage);
|
|
||||||
data.valueAsUint8 = (uint8_t)(charge_factor * 100.f);
|
|
||||||
} else {
|
|
||||||
data.valueAsUint8 = 0;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case IsCharging: {
|
|
||||||
float charge_current;
|
|
||||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK) {
|
|
||||||
data.valueAsBool = charge_current > 0.001f;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case Current: {
|
|
||||||
float charge_current, discharge_current;
|
|
||||||
if (
|
|
||||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK &&
|
|
||||||
axp192_read(&axpDevice, AXP192_DISCHARGE_CURRENT, &discharge_current) == ESP_OK
|
|
||||||
) {
|
|
||||||
if (charge_current > 0.0f) {
|
|
||||||
data.valueAsInt32 = (int32_t) (charge_current * 1000.0f);
|
|
||||||
} else {
|
|
||||||
data.valueAsInt32 = -(int32_t) (discharge_current * 1000.0f);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Core2Power::isAllowedToCharge() const {
|
|
||||||
uint8_t buffer;
|
|
||||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
|
||||||
return buffer & 0x80;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Core2Power::setAllowedToCharge(bool canCharge) {
|
|
||||||
uint8_t buffer;
|
|
||||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
|
||||||
buffer = (buffer & 0x7F) + (canCharge ? 0x80 : 0x00);
|
|
||||||
axp192_write(&axpDevice, AXP192_CHARGE_CONTROL_1, buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::shared_ptr<PowerDevice> power;
|
|
||||||
|
|
||||||
std::shared_ptr<PowerDevice> createPower() {
|
|
||||||
if (power == nullptr) {
|
|
||||||
power = std::make_shared<Core2Power>();
|
|
||||||
}
|
|
||||||
return power;
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Tactility/hal/power/PowerDevice.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using tt::hal::power::PowerDevice;
|
|
||||||
|
|
||||||
class Core2Power : public PowerDevice {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Core2Power() = default;
|
|
||||||
~Core2Power() override = default;
|
|
||||||
|
|
||||||
std::string getName() const final { return "AXP192 Power"; }
|
|
||||||
std::string getDescription() const final { return "Power management via I2C"; }
|
|
||||||
|
|
||||||
bool supportsMetric(MetricType type) const override;
|
|
||||||
bool getMetric(MetricType type, MetricData& data) override;
|
|
||||||
|
|
||||||
bool supportsChargeControl() const override { return true; }
|
|
||||||
bool isAllowedToCharge() const override;
|
|
||||||
void setAllowedToCharge(bool canCharge) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::shared_ptr<PowerDevice> createPower();
|
|
||||||
@ -1,36 +1,63 @@
|
|||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
|
|
||||||
#include <Ft6x36Touch.h>
|
#include "Power.h"
|
||||||
#include <Ili934xDisplay.h>
|
|
||||||
|
|
||||||
std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
#include <St7789Display.h>
|
||||||
auto configuration = std::make_unique<Ft6x36Touch::Configuration>(
|
#include <bitset>
|
||||||
I2C_NUM_0,
|
|
||||||
GPIO_NUM_39,
|
|
||||||
CORE2_LCD_HORIZONTAL_RESOLUTION,
|
|
||||||
CORE2_LCD_VERTICAL_RESOLUTION
|
|
||||||
);
|
|
||||||
|
|
||||||
auto touch = std::make_shared<Ft6x36Touch>(std::move(configuration));
|
constexpr auto* TAG = "StickCPlus";
|
||||||
return std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(touch);
|
|
||||||
|
static void setBacklightOn(bool on) {
|
||||||
|
const auto axp = getAxp192();
|
||||||
|
const auto* driver = axp->getAxp192();
|
||||||
|
uint8_t state;
|
||||||
|
if (axp192_read(driver, AXP192_DCDC13_LDO23_CONTROL, &state) != AXP192_OK) {
|
||||||
|
TT_LOG_I(TAG, "Failed to read LCD brightness state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::bitset<8> new_state = state;
|
||||||
|
if (new_state[2] != on) {
|
||||||
|
new_state[2] = on;
|
||||||
|
const auto new_state_long = new_state.to_ulong();
|
||||||
|
axp192_write(driver, AXP192_DCDC13_LDO23_CONTROL, static_cast<uint8_t>(new_state_long)); // Display on/off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setBrightness(uint8_t brightness) {
|
||||||
|
const auto axp = getAxp192();
|
||||||
|
if (brightness)
|
||||||
|
{
|
||||||
|
brightness = (((brightness >> 1) + 8) / 13) + 5;
|
||||||
|
setBacklightOn(true);
|
||||||
|
axp192_write(axp->getAxp192(), AXP192_LDO23_VOLTAGE, brightness << 4); // Display brightness
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setBacklightOn(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||||
auto touch = createTouch();
|
auto configuration = std::make_unique<St7789Display::Configuration>(
|
||||||
|
LCD_SPI_HOST,
|
||||||
auto configuration = std::make_unique<Ili934xDisplay::Configuration>(
|
LCD_PIN_CS,
|
||||||
CORE2_LCD_SPI_HOST,
|
LCD_PIN_DC,
|
||||||
CORE2_LCD_PIN_CS,
|
LCD_HORIZONTAL_RESOLUTION,
|
||||||
CORE2_LCD_PIN_DC,
|
LCD_VERTICAL_RESOLUTION,
|
||||||
CORE2_LCD_HORIZONTAL_RESOLUTION,
|
nullptr,
|
||||||
CORE2_LCD_VERTICAL_RESOLUTION,
|
|
||||||
touch,
|
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
true
|
true,
|
||||||
|
LCD_DRAW_BUFFER_SIZE,
|
||||||
|
52,
|
||||||
|
40
|
||||||
);
|
);
|
||||||
|
|
||||||
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
|
configuration->pixelClockFrequency = 40'000'000;
|
||||||
|
configuration->resetPin = LCD_PIN_RESET;
|
||||||
|
|
||||||
|
configuration->backlightDutyFunction = setBrightness;
|
||||||
|
const auto display = std::make_shared<St7789Display>(std::move(configuration));
|
||||||
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
|
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,13 @@
|
|||||||
#include "Tactility/hal/display/DisplayDevice.h"
|
#include "Tactility/hal/display/DisplayDevice.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#define CORE2_LCD_SPI_HOST SPI2_HOST
|
#define LCD_SPI_HOST SPI2_HOST
|
||||||
#define CORE2_LCD_PIN_CS GPIO_NUM_5
|
#define LCD_PIN_CS GPIO_NUM_5
|
||||||
#define CORE2_LCD_PIN_DC GPIO_NUM_15
|
#define LCD_PIN_DC GPIO_NUM_23
|
||||||
#define CORE2_LCD_HORIZONTAL_RESOLUTION 320
|
#define LCD_PIN_RESET GPIO_NUM_18
|
||||||
#define CORE2_LCD_VERTICAL_RESOLUTION 240
|
#define LCD_HORIZONTAL_RESOLUTION 135
|
||||||
#define CORE2_LCD_DRAW_BUFFER_HEIGHT (CORE2_LCD_VERTICAL_RESOLUTION / 10)
|
#define LCD_VERTICAL_RESOLUTION 240
|
||||||
#define CORE2_LCD_DRAW_BUFFER_SIZE (CORE2_LCD_HORIZONTAL_RESOLUTION * CORE2_LCD_DRAW_BUFFER_HEIGHT)
|
#define LCD_DRAW_BUFFER_HEIGHT (LCD_VERTICAL_RESOLUTION / 3)
|
||||||
|
#define LCD_DRAW_BUFFER_SIZE (LCD_HORIZONTAL_RESOLUTION * LCD_DRAW_BUFFER_HEIGHT)
|
||||||
|
|
||||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||||
|
|||||||
38
Boards/M5stackStickCPlus/Source/devices/Power.cpp
Normal file
38
Boards/M5stackStickCPlus/Source/devices/Power.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <Axp192.h>
|
||||||
|
|
||||||
|
static std::shared_ptr<Axp192> axp192 = nullptr;
|
||||||
|
|
||||||
|
std::shared_ptr<Axp192> createAxp192() {
|
||||||
|
assert(axp192 == nullptr);
|
||||||
|
auto configuration = std::make_unique<Axp192::Configuration>(I2C_NUM_0);
|
||||||
|
axp192 = std::make_shared<Axp192>(std::move(configuration));
|
||||||
|
return axp192;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Axp192> getAxp192() {
|
||||||
|
assert(axp192 != nullptr);
|
||||||
|
return axp192;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool initAxp() {
|
||||||
|
const auto axp = createAxp192();
|
||||||
|
return axp->init([](auto* driver) {
|
||||||
|
// Reference: https://github.com/pr3y/Bruce/blob/main/lib/utility/AXP192.cpp
|
||||||
|
axp192_ioctl(driver, AXP192_LDO23_VOLTAGE, 3300); // LCD backlight
|
||||||
|
axp192_ioctl(driver, AXP192_ADC_ENABLE_1, 0xff); // Set all ADC enabled
|
||||||
|
axp192_ioctl(driver, AXP192_CHARGE_CONTROL_1, 0xc0); // Battery charging at 4.2 V and 100 mA
|
||||||
|
axp192_ioctl(driver, AXP192_ADC_ENABLE_1, 0xff); // Enable battery, AC in, Vbus, APS ADC
|
||||||
|
uint8_t buffer;
|
||||||
|
axp192_read(driver, AXP192_DCDC13_LDO23_CONTROL, &buffer);
|
||||||
|
axp192_ioctl(driver, AXP192_DCDC13_LDO23_CONTROL, buffer | 0x4D); // Enable Ext, LDO2, LDO3, DCDC1
|
||||||
|
axp192_ioctl(driver, AXP192_PEK, 0x0C); // 128 ms power on, 4 s power off
|
||||||
|
axp192_ioctl(driver, AXP192_GPIO0_LDOIO0_VOLTAGE, 0xF0); // 3.3 V RTC voltage
|
||||||
|
axp192_ioctl(driver, AXP192_GPIO0_CONTROL, 0x02); // Set GPIO0 to LDO
|
||||||
|
axp192_ioctl(driver, AXP192_VBUS_IPSOUT_CHANNEL, 0x80); // Disable Vbus hold limit
|
||||||
|
axp192_ioctl(driver, AXP192_BATTERY_CHARGE_HIGH_TEMP, 0xFC); // Set temperature protection
|
||||||
|
axp192_ioctl(driver, AXP192_BATTERY_CHARGE_CONTROL, 0xA2); // Enable RTC BAT charge
|
||||||
|
axp192_ioctl(driver, AXP192_SHUTDOWN_BATTERY_CHGLED_CONTROL, 0x46); // Enable bat detection
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
9
Boards/M5stackStickCPlus/Source/devices/Power.h
Normal file
9
Boards/M5stackStickCPlus/Source/devices/Power.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Axp192.h>
|
||||||
|
|
||||||
|
bool initAxp();
|
||||||
|
|
||||||
|
// Must call initAxp() first before this returns a non-nullptr response
|
||||||
|
std::shared_ptr<Axp192> getAxp192();
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
#include "SdCard.h"
|
|
||||||
|
|
||||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
|
||||||
|
|
||||||
constexpr auto CORE2_SDCARD_PIN_CS = GPIO_NUM_4;
|
|
||||||
constexpr auto CORE2_LCD_PIN_CS = GPIO_NUM_5;
|
|
||||||
|
|
||||||
using tt::hal::sdcard::SpiSdCardDevice;
|
|
||||||
|
|
||||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
|
||||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
|
||||||
CORE2_SDCARD_PIN_CS,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
SdCardDevice::MountBehaviour::AtBoot,
|
|
||||||
tt::lvgl::getSyncLock(),
|
|
||||||
std::vector {
|
|
||||||
CORE2_LCD_PIN_CS
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return std::make_shared<SpiSdCardDevice>(
|
|
||||||
std::move(configuration)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
|
||||||
|
|
||||||
using tt::hal::sdcard::SdCardDevice;
|
|
||||||
|
|
||||||
std::shared_ptr<SdCardDevice> createSdCard();
|
|
||||||
@ -61,6 +61,8 @@ function(INIT_TACTILITY_GLOBALS SDKCONFIG_FILE)
|
|||||||
set(TACTILITY_BOARD_PROJECT M5stackCore2)
|
set(TACTILITY_BOARD_PROJECT M5stackCore2)
|
||||||
elseif (board_id STREQUAL "m5stack-cores3")
|
elseif (board_id STREQUAL "m5stack-cores3")
|
||||||
set(TACTILITY_BOARD_PROJECT M5stackCoreS3)
|
set(TACTILITY_BOARD_PROJECT M5stackCoreS3)
|
||||||
|
elseif (board_id STREQUAL "m5stack-stickc-plus")
|
||||||
|
set(TACTILITY_BOARD_PROJECT M5stackStickCPlus)
|
||||||
elseif (board_id STREQUAL "unphone")
|
elseif (board_id STREQUAL "unphone")
|
||||||
set(TACTILITY_BOARD_PROJECT UnPhone)
|
set(TACTILITY_BOARD_PROJECT UnPhone)
|
||||||
elseif (board_id STREQUAL "waveshare-s3-touch-43")
|
elseif (board_id STREQUAL "waveshare-s3-touch-43")
|
||||||
|
|||||||
@ -51,6 +51,8 @@ menu "Tactility App"
|
|||||||
bool "M5Stack Core2"
|
bool "M5Stack Core2"
|
||||||
config TT_BOARD_M5STACK_CORES3
|
config TT_BOARD_M5STACK_CORES3
|
||||||
bool "M5Stack CoreS3"
|
bool "M5Stack CoreS3"
|
||||||
|
config TT_BOARD_M5STACK_STICKC_PLUS
|
||||||
|
bool "M5Stack StickC Plus"
|
||||||
config TT_BOARD_UNPHONE
|
config TT_BOARD_UNPHONE
|
||||||
bool "unPhone"
|
bool "unPhone"
|
||||||
config TT_BOARD_WAVESHARE_S3_TOUCH_43
|
config TT_BOARD_WAVESHARE_S3_TOUCH_43
|
||||||
|
|||||||
@ -53,6 +53,9 @@
|
|||||||
#elif defined(CONFIG_TT_BOARD_M5STACK_CORES3)
|
#elif defined(CONFIG_TT_BOARD_M5STACK_CORES3)
|
||||||
#include "M5stackCoreS3.h"
|
#include "M5stackCoreS3.h"
|
||||||
#define TT_BOARD_HARDWARE &m5stack_cores3
|
#define TT_BOARD_HARDWARE &m5stack_cores3
|
||||||
|
#elif defined(CONFIG_TT_BOARD_M5STACK_STICKC_PLUS)
|
||||||
|
#include "M5StackStickCPlus.h"
|
||||||
|
#define TT_BOARD_HARDWARE &m5stack_stickc_plus
|
||||||
#elif defined(CONFIG_TT_BOARD_UNPHONE)
|
#elif defined(CONFIG_TT_BOARD_UNPHONE)
|
||||||
#include "UnPhone.h"
|
#include "UnPhone.h"
|
||||||
#define TT_BOARD_HARDWARE &unPhone
|
#define TT_BOARD_HARDWARE &unPhone
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user