Fix memory leaks

This commit is contained in:
Ken Van Hoeylandt 2025-08-30 12:39:10 +02:00
parent 612377974a
commit 61756bf542
16 changed files with 74 additions and 102 deletions

View File

@ -4,13 +4,13 @@
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#define SDCARD_SPI_HOST SPI3_HOST
#define SDCARD_PIN_CS GPIO_NUM_5
constexpr auto SDCARD_SPI_HOST = SPI3_HOST;
constexpr auto SDCARD_PIN_CS = GPIO_NUM_5;
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createYellowSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
@ -21,10 +21,8 @@ std::shared_ptr<SdCardDevice> createYellowSdCard() {
SDCARD_SPI_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -9,7 +9,7 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
@ -20,10 +20,8 @@ std::shared_ptr<SdCardDevice> createSdCard() {
SDCARD_SPI_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -5,13 +5,13 @@
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <Tactility/lvgl/LvglSync.h>
#define SDCARD_SPI_HOST SPI3_HOST
#define SDCARD_PIN_CS GPIO_NUM_5
constexpr auto SDCARD_SPI_HOST = SPI3_HOST;
constexpr auto SDCARD_PIN_CS = GPIO_NUM_5;
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createYellowSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
@ -22,10 +22,8 @@ std::shared_ptr<SdCardDevice> createYellowSdCard() {
SDCARD_SPI_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -7,23 +7,21 @@
using tt::hal::sdcard::SpiSdCardDevice;
#define CROWPANEL_SDCARD_PIN_CS GPIO_NUM_7
constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
CROWPANEL_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{},
std::vector<gpio_num_t>(),
SPI3_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -7,23 +7,21 @@
using tt::hal::sdcard::SpiSdCardDevice;
#define CROWPANEL_SDCARD_PIN_CS GPIO_NUM_7
constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
CROWPANEL_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{},
std::vector<gpio_num_t>(),
SPI3_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -8,7 +8,7 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
// See https://github.com/Elecrow-RD/CrowPanel-Advance-HMI-ESP32-AI-Display/blob/master/5.0/factory_code/factory_code.ino
GPIO_NUM_0, // It's actually not connected, but in the demo pin 0 is used
GPIO_NUM_NC,
@ -17,9 +17,7 @@ std::shared_ptr<SdCardDevice> createSdCard() {
SdCardDevice::MountBehaviour::AtBoot
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -8,20 +8,18 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
GPIO_NUM_5,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{},
std::vector<gpio_num_t>(),
SPI3_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -6,20 +6,18 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
GPIO_NUM_5,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{},
std::vector<gpio_num_t>(),
SPI3_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -8,7 +8,7 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
GPIO_NUM_10,
GPIO_NUM_NC,
GPIO_NUM_NC,
@ -16,9 +16,7 @@ std::shared_ptr<SdCardDevice> createSdCard() {
SdCardDevice::MountBehaviour::AtBoot
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -20,7 +20,7 @@ bool tpagerInit() {
return false;
}
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) {
auto gps_service = tt::service::gps::findGpsService();
if (gps_service != nullptr) {
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;
@ -29,8 +29,8 @@ bool tpagerInit() {
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {
.uartName = "Internal",
.baudRate = 38400,
.model = tt::hal::gps::GpsModel::UBLOX10})
) {
.model = tt::hal::gps::GpsModel::UBLOX10
})) {
TT_LOG_I(TAG, "Configured internal GPS");
} else {
TT_LOG_E(TAG, "Failed to configure internal GPS");

View File

@ -5,25 +5,25 @@
using tt::hal::sdcard::SpiSdCardDevice;
#define TPAGER_SDCARD_PIN_CS GPIO_NUM_21
#define TPAGER_LCD_PIN_CS GPIO_NUM_38
#define TPAGER_RADIO_PIN_CS GPIO_NUM_36
constexpr auto TPAGER_SDCARD_PIN_CS = GPIO_NUM_21;
constexpr auto TPAGER_LCD_PIN_CS = GPIO_NUM_38;
constexpr auto TPAGER_RADIO_PIN_CS = GPIO_NUM_36;
std::shared_ptr<SdCardDevice> createTpagerSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
TPAGER_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{TPAGER_RADIO_PIN_CS,
TPAGER_LCD_PIN_CS}
std::vector {
TPAGER_RADIO_PIN_CS,
TPAGER_LCD_PIN_CS
}
);
auto* sdcard = (SdCardDevice*)new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -7,27 +7,25 @@
using tt::hal::sdcard::SpiSdCardDevice;
#define TDECK_SDCARD_PIN_CS GPIO_NUM_39
#define TDECK_LCD_PIN_CS GPIO_NUM_12
#define TDECK_RADIO_PIN_CS GPIO_NUM_9
constexpr auto TDECK_SDCARD_PIN_CS = GPIO_NUM_39;
constexpr auto TDECK_LCD_PIN_CS = GPIO_NUM_12;
constexpr auto TDECK_RADIO_PIN_CS = GPIO_NUM_9;
std::shared_ptr<SdCardDevice> createTdeckSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
TDECK_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{
std::vector {
TDECK_RADIO_PIN_CS,
TDECK_LCD_PIN_CS
}
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -11,21 +11,19 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
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
}
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -5,28 +5,26 @@
#include <esp_vfs_fat.h>
#define CORES3_SDCARD_PIN_CS GPIO_NUM_4
#define CORES3_LCD_PIN_CS GPIO_NUM_3
constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4;
constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3;
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
CORES3_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{
std::vector {
CORES3_LCD_PIN_CS
},
SPI3_HOST
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -13,23 +13,21 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createUnPhoneSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
UNPHONE_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
tt::lvgl::getSyncLock(),
{
std::vector {
UNPHONE_LORA_PIN_CS,
UNPHONE_LCD_PIN_CS,
UNPHONE_TOUCH_PIN_CS
}
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}

View File

@ -5,7 +5,7 @@
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto* configuration = new SpiSdCardDevice::Config(
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
GPIO_NUM_10,
GPIO_NUM_NC,
GPIO_NUM_NC,
@ -13,9 +13,7 @@ std::shared_ptr<SdCardDevice> createSdCard() {
SdCardDevice::MountBehaviour::AtBoot
);
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
return std::shared_ptr<SdCardDevice>(sdcard);
}