mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-19 03:13:14 +00:00
UnPhone updates and cleanup of Xpt2046 devices (remove static variables)
This commit is contained in:
parent
176f210ced
commit
5c068974ff
@ -3,7 +3,7 @@
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <esp_sleep.h>
|
||||
|
||||
#define TAG "unphone"
|
||||
constexpr auto* TAG = "unPhone";
|
||||
|
||||
std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
static std::unique_ptr<tt::Thread> powerThread;
|
||||
@ -14,8 +14,6 @@ static const char* powerSleepKey = "power_sleep_key";
|
||||
|
||||
class DeviceStats {
|
||||
|
||||
private:
|
||||
|
||||
tt::Preferences preferences = tt::Preferences("unphone");
|
||||
|
||||
int32_t getValue(const char* key) {
|
||||
@ -161,7 +159,6 @@ static bool unPhonePowerOn() {
|
||||
bootStats.notifyBootStart();
|
||||
|
||||
bq24295 = std::make_shared<Bq24295>(I2C_NUM_0);
|
||||
tt::hal::registerDevice(bq24295);
|
||||
|
||||
unPhoneFeatures = std::make_shared<UnPhoneFeatures>(bq24295);
|
||||
|
||||
|
||||
@ -1,20 +1,25 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "UnPhoneFeatures.h"
|
||||
#include "Xpt2046Power.h"
|
||||
#include "hal/UnPhoneDisplay.h"
|
||||
#include "hal/UnPhoneDisplayConstants.h"
|
||||
#include "hal/UnPhoneSdCard.h"
|
||||
#include "devices/Hx8357Display.h"
|
||||
#include "devices/SdCard.h"
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
#define UNPHONE_SPI_TRANSFER_SIZE_LIMIT (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_SPI_TRANSFER_HEIGHT * LV_COLOR_DEPTH / 8)
|
||||
|
||||
bool unPhoneInitPower();
|
||||
|
||||
static tt::hal::DeviceVector createDevices() {
|
||||
return {
|
||||
std::make_shared<Xpt2046Power>(),
|
||||
createDisplay(),
|
||||
createSdCard()
|
||||
};
|
||||
}
|
||||
|
||||
extern const tt::hal::Configuration unPhone = {
|
||||
.initBoot = unPhoneInitPower,
|
||||
.createDisplay = createDisplay,
|
||||
.sdcard = createUnPhoneSdCard(),
|
||||
.power = getOrCreatePower,
|
||||
.createDevices = createDevices,
|
||||
.i2c = {
|
||||
tt::hal::i2c::Configuration {
|
||||
.name = "Internal",
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
#include "UnPhoneDisplay.h"
|
||||
#include "UnPhoneDisplayConstants.h"
|
||||
#include "UnPhoneTouch.h"
|
||||
#include "UnPhoneFeatures.h"
|
||||
#include "Hx8357Display.h"
|
||||
#include "Touch.h"
|
||||
|
||||
#include <UnPhoneFeatures.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <hx8357/disp_spi.h>
|
||||
#include <hx8357/hx8357.h>
|
||||
|
||||
constexpr auto TAG = "UnPhoneDisplay";
|
||||
constexpr auto TAG = "Hx8357Display";
|
||||
constexpr auto BUFFER_SIZE = (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8);
|
||||
|
||||
extern std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
|
||||
bool UnPhoneDisplay::start() {
|
||||
bool Hx8357Display::start() {
|
||||
TT_LOG_I(TAG, "start");
|
||||
|
||||
disp_spi_add_device(SPI2_HOST);
|
||||
@ -27,13 +25,13 @@ bool UnPhoneDisplay::start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::stop() {
|
||||
bool Hx8357Display::stop() {
|
||||
TT_LOG_I(TAG, "stop");
|
||||
disp_spi_remove_device();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::startLvgl() {
|
||||
bool Hx8357Display::startLvgl() {
|
||||
TT_LOG_I(TAG, "startLvgl");
|
||||
|
||||
if (lvglDisplay != nullptr) {
|
||||
@ -74,7 +72,7 @@ bool UnPhoneDisplay::startLvgl() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::stopLvgl() {
|
||||
bool Hx8357Display::stopLvgl() {
|
||||
TT_LOG_I(TAG, "stopLvgl");
|
||||
|
||||
if (lvglDisplay == nullptr) {
|
||||
@ -100,7 +98,7 @@ bool UnPhoneDisplay::stopLvgl() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable UnPhoneDisplay::getTouchDevice() {
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable Hx8357Display::getTouchDevice() {
|
||||
if (touchDevice == nullptr) {
|
||||
touchDevice = std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(createTouch());
|
||||
TT_LOG_I(TAG, "Created touch device");
|
||||
@ -110,10 +108,10 @@ std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable UnPhoneDisplay::getTouchD
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
return std::make_shared<UnPhoneDisplay>();
|
||||
return std::make_shared<Hx8357Display>();
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::UnPhoneDisplayDriver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) {
|
||||
bool Hx8357Display::Hx8357Driver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) {
|
||||
lv_area_t area = { xStart, yStart, xEnd, yEnd };
|
||||
hx8357_flush(nullptr, &area, (uint8_t*)pixelData);
|
||||
return true;
|
||||
@ -7,18 +7,26 @@
|
||||
#include <esp_lcd_types.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "UnPhoneDisplayConstants.h"
|
||||
|
||||
#include <Tactility/hal/spi/Spi.h>
|
||||
|
||||
class UnPhoneDisplay : public tt::hal::display::DisplayDevice {
|
||||
#define UNPHONE_LCD_SPI_HOST SPI2_HOST
|
||||
#define UNPHONE_LCD_PIN_CS GPIO_NUM_48
|
||||
#define UNPHONE_LCD_PIN_DC GPIO_NUM_47
|
||||
#define UNPHONE_LCD_PIN_RESET GPIO_NUM_46
|
||||
#define UNPHONE_LCD_SPI_FREQUENCY 27000000
|
||||
#define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define UNPHONE_LCD_VERTICAL_RESOLUTION 480
|
||||
#define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15)
|
||||
#define UNPHONE_LCD_SPI_TRANSFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15)
|
||||
|
||||
class Hx8357Display : public tt::hal::display::DisplayDevice {
|
||||
|
||||
uint8_t* _Nullable buffer = nullptr;
|
||||
lv_display_t* _Nullable lvglDisplay = nullptr;
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable touchDevice;
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable nativeDisplay;
|
||||
|
||||
class UnPhoneDisplayDriver : public tt::hal::display::DisplayDriver {
|
||||
class Hx8357Driver : public tt::hal::display::DisplayDriver {
|
||||
std::shared_ptr<tt::Lock> lock = tt::hal::spi::getLock(SPI2_HOST);
|
||||
public:
|
||||
tt::hal::display::ColorFormat getColorFormat() const override { return tt::hal::display::ColorFormat::RGB888; }
|
||||
@ -52,7 +60,7 @@ public:
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable getDisplayDriver() override {
|
||||
if (nativeDisplay == nullptr) {
|
||||
nativeDisplay = std::make_shared<UnPhoneDisplayDriver>();
|
||||
nativeDisplay = std::make_shared<Hx8357Driver>();
|
||||
}
|
||||
assert(nativeDisplay != nullptr);
|
||||
return nativeDisplay;
|
||||
@ -1,10 +1,8 @@
|
||||
#include "UnPhoneSdCard.h"
|
||||
#include "SdCard.h"
|
||||
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
|
||||
#define UNPHONE_SDCARD_PIN_CS GPIO_NUM_43
|
||||
#define UNPHONE_LCD_PIN_CS GPIO_NUM_48
|
||||
#define UNPHONE_LORA_PIN_CS GPIO_NUM_44
|
||||
@ -12,7 +10,7 @@
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createUnPhoneSdCard() {
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
UNPHONE_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
@ -4,4 +4,4 @@
|
||||
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createUnPhoneSdCard();
|
||||
std::shared_ptr<SdCardDevice> createSdCard();
|
||||
@ -1,11 +1,10 @@
|
||||
#include "UnPhoneTouch.h"
|
||||
#include "UnPhoneDisplayConstants.h"
|
||||
#include "Touch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
std::shared_ptr<Xpt2046Touch> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046Touch::Configuration>(
|
||||
UNPHONE_LCD_SPI_HOST,
|
||||
SPI2_HOST,
|
||||
GPIO_NUM_38,
|
||||
320,
|
||||
480
|
||||
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define UNPHONE_LCD_SPI_HOST SPI2_HOST
|
||||
#define UNPHONE_LCD_PIN_CS GPIO_NUM_48
|
||||
#define UNPHONE_LCD_PIN_DC GPIO_NUM_47
|
||||
#define UNPHONE_LCD_PIN_RESET GPIO_NUM_46
|
||||
#define UNPHONE_LCD_SPI_FREQUENCY 27000000
|
||||
#define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define UNPHONE_LCD_VERTICAL_RESOLUTION 480
|
||||
#define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15)
|
||||
#define UNPHONE_LCD_SPI_TRANSFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15)
|
||||
@ -102,13 +102,3 @@ bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<PowerDevice> power;
|
||||
|
||||
std::shared_ptr<PowerDevice> getOrCreatePower() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<Xpt2046Power>();
|
||||
}
|
||||
return power;
|
||||
}
|
||||
|
||||
|
||||
@ -18,14 +18,11 @@ class Xpt2046Power : public PowerDevice {
|
||||
|
||||
public:
|
||||
|
||||
~Xpt2046Power() = default;
|
||||
~Xpt2046Power() override = default;
|
||||
|
||||
std::string getName() const final { return "XPT2046 Power Measurement"; }
|
||||
std::string getDescription() const final { return "Power interface via XPT2046 voltage measurement"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> getOrCreatePower();
|
||||
|
||||
@ -5,9 +5,6 @@
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_lcd_touch_xpt2046.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
Xpt2046Touch* Xpt2046Touch::instance = nullptr;
|
||||
|
||||
bool Xpt2046Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
const esp_lcd_panel_io_spi_config_t io_config = ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG(configuration->spiPinCs);
|
||||
|
||||
@ -39,8 +39,6 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
static Xpt2046Touch* instance;
|
||||
|
||||
std::unique_ptr<Configuration> configuration;
|
||||
|
||||
bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) override;
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include "Tactility/hal/spi/SpiInit.h"
|
||||
#include "Tactility/hal/uart/UartInit.h"
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
|
||||
namespace tt::hal {
|
||||
@ -35,6 +37,16 @@ void registerDevices(const Configuration& configuration) {
|
||||
auto devices = configuration.createDevices();
|
||||
for (auto& device : devices) {
|
||||
registerDevice(device);
|
||||
|
||||
// Register attached devices
|
||||
if (device->getType() == Device::Type::Display) {
|
||||
const auto display = std::static_pointer_cast<display::DisplayDevice>(device);
|
||||
assert(display != nullptr);
|
||||
const std::shared_ptr<Device> touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
registerDevice(touch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user