New logging and more (#446)
- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>` - Changed default timezone to Europe/Amsterdam - Fix for logic bug in unPhone hardware - Fix for init/deinit in DRV2605 driver - Other fixes - Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
committed by
GitHub
parent
719f7bcece
commit
f620255c41
@@ -1,9 +1,11 @@
|
||||
#include "UnPhoneFeatures.h"
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/Preferences.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <esp_sleep.h>
|
||||
|
||||
constexpr auto* TAG = "unPhone";
|
||||
static const auto LOGGER = tt::Logger("unPhone");
|
||||
|
||||
std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
static std::unique_ptr<tt::Thread> powerThread;
|
||||
@@ -46,10 +48,10 @@ public:
|
||||
}
|
||||
|
||||
void printInfo() {
|
||||
TT_LOG_I("TAG", "Device stats:");
|
||||
TT_LOG_I("TAG", " boot: %ld", getValue(bootCountKey));
|
||||
TT_LOG_I("TAG", " power off: %ld", getValue(powerOffCountKey));
|
||||
TT_LOG_I("TAG", " power sleep: %ld", getValue(powerSleepKey));
|
||||
LOGGER.info("Device stats:");
|
||||
LOGGER.info(" boot: {}", getValue(bootCountKey));
|
||||
LOGGER.info(" power off: {}", getValue(powerOffCountKey));
|
||||
LOGGER.info(" power sleep: {}", getValue(powerSleepKey));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,11 +91,11 @@ static void updatePowerSwitch() {
|
||||
if (!unPhoneFeatures->isPowerSwitchOn()) {
|
||||
if (last_state != PowerState::Off) {
|
||||
last_state = PowerState::Off;
|
||||
TT_LOG_W(TAG, "Power off");
|
||||
LOGGER.warn("Power off");
|
||||
}
|
||||
|
||||
if (!unPhoneFeatures->isUsbPowerConnected()) { // and usb unplugged we go into shipping mode
|
||||
TT_LOG_W(TAG, "Shipping mode until USB connects");
|
||||
LOGGER.warn("Shipping mode until USB connects");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
unPhoneFeatures.setExpanderPower(true);
|
||||
@@ -107,7 +109,7 @@ static void updatePowerSwitch() {
|
||||
|
||||
unPhoneFeatures->setShipping(true); // tell BM to stop supplying power until USB connects
|
||||
} else { // When power switch is off, but USB is plugged in, we wait (deep sleep) until USB is unplugged.
|
||||
TT_LOG_W(TAG, "Waiting for USB disconnect to power off");
|
||||
LOGGER.warn("Waiting for USB disconnect to power off");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
powerInfoBuzz(2);
|
||||
@@ -126,7 +128,7 @@ static void updatePowerSwitch() {
|
||||
} else {
|
||||
if (last_state != PowerState::On) {
|
||||
last_state = PowerState::On;
|
||||
TT_LOG_W(TAG, "Power on");
|
||||
LOGGER.warn("Power on");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
powerInfoBuzz(1);
|
||||
@@ -163,7 +165,7 @@ static bool unPhonePowerOn() {
|
||||
unPhoneFeatures = std::make_shared<UnPhoneFeatures>(bq24295);
|
||||
|
||||
if (!unPhoneFeatures->init()) {
|
||||
TT_LOG_E(TAG, "UnPhoneFeatures init failed");
|
||||
LOGGER.error("UnPhoneFeatures init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -183,10 +185,10 @@ static bool unPhonePowerOn() {
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
LOGGER.info(LOG_MESSAGE_POWER_ON_START);
|
||||
|
||||
if (!unPhonePowerOn()) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "UnPhoneFeatures.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <esp_io_expander.h>
|
||||
#include <esp_sleep.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("unPhoneFeatures");
|
||||
|
||||
namespace pin {
|
||||
static const gpio_num_t BUTTON1 = GPIO_NUM_45; // left button
|
||||
static const gpio_num_t BUTTON2 = GPIO_NUM_0; // middle button
|
||||
@@ -27,8 +29,6 @@ namespace expanderpin {
|
||||
static const esp_io_expander_pin_num_t VIBE = IO_EXPANDER_PIN_NUM_7;
|
||||
} // namespace expanderpin
|
||||
|
||||
#define TAG "unhpone_features"
|
||||
|
||||
// TODO: Make part of a new type of UnPhoneFeatures data struct that holds all the thread-related data
|
||||
QueueHandle_t interruptQueue;
|
||||
|
||||
@@ -42,7 +42,7 @@ static int32_t buttonHandlingThreadMain(const bool* interrupted) {
|
||||
while (!*interrupted) {
|
||||
if (xQueueReceive(interruptQueue, &pinNumber, portMAX_DELAY)) {
|
||||
// The buttons might generate more than 1 click because of how they are built
|
||||
TT_LOG_I(TAG, "Pressed button %d", pinNumber);
|
||||
LOGGER.info("Pressed button {}", pinNumber);
|
||||
if (pinNumber == pin::BUTTON1) {
|
||||
tt::app::stop();
|
||||
}
|
||||
@@ -75,7 +75,7 @@ bool UnPhoneFeatures::initPowerSwitch() {
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Power pin init failed");
|
||||
LOGGER.error("Power pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ bool UnPhoneFeatures::initPowerSwitch() {
|
||||
rtc_gpio_pulldown_en(pin::POWER_SWITCH) == ESP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to set RTC for power switch");
|
||||
LOGGER.error("Failed to set RTC for power switch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::initNavButtons() {
|
||||
if (!initGpioExpander()) {
|
||||
TT_LOG_E(TAG, "GPIO expander init failed");
|
||||
LOGGER.error("GPIO expander init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -125,17 +125,17 @@ bool UnPhoneFeatures::initNavButtons() {
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Nav button pin init failed");
|
||||
LOGGER.error("Nav button pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
gpio_install_isr_service(0) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON1, navButtonInterruptHandler, (void*)pin::BUTTON1) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON2, navButtonInterruptHandler, (void*)pin::BUTTON2) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON3, navButtonInterruptHandler, (void*)pin::BUTTON3) != ESP_OK
|
||||
gpio_isr_handler_add(pin::BUTTON1, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON1)) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON2, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON2)) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON3, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON3)) != ESP_OK
|
||||
) {
|
||||
TT_LOG_E(TAG, "Nav buttons ISR init failed");
|
||||
LOGGER.error("Nav buttons ISR init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ bool UnPhoneFeatures::initOutputPins() {
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Output pin init failed");
|
||||
LOGGER.error("Output pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ bool UnPhoneFeatures::initGpioExpander() {
|
||||
// ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110 corresponds with 0x26 from the docs at
|
||||
// https://gitlab.com/hamishcunningham/unphonelibrary/-/blob/main/unPhone.h?ref_type=heads#L206
|
||||
if (esp_io_expander_new_i2c_tca95xx_16bit(I2C_NUM_0, ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110, &ioExpander) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "IO expander init failed");
|
||||
LOGGER.error("IO expander init failed");
|
||||
return false;
|
||||
}
|
||||
assert(ioExpander != nullptr);
|
||||
@@ -201,25 +201,25 @@ bool UnPhoneFeatures::initGpioExpander() {
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::init() {
|
||||
TT_LOG_I(TAG, "init");
|
||||
LOGGER.info("init");
|
||||
|
||||
if (!initGpioExpander()) {
|
||||
TT_LOG_E(TAG, "GPIO expander init failed");
|
||||
LOGGER.error("GPIO expander init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initNavButtons()) {
|
||||
TT_LOG_E(TAG, "Input pin init failed");
|
||||
LOGGER.error("Input pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initOutputPins()) {
|
||||
TT_LOG_E(TAG, "Output pin init failed");
|
||||
LOGGER.error("Output pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initPowerSwitch()) {
|
||||
TT_LOG_E(TAG, "Power button init failed");
|
||||
LOGGER.error("Power button init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ void UnPhoneFeatures::printInfo() const {
|
||||
batteryManagement->printInfo();
|
||||
bool backlight_power;
|
||||
const char* backlight_power_state = getBacklightPower(backlight_power) && backlight_power ? "on" : "off";
|
||||
TT_LOG_I(TAG, "Backlight: %s", backlight_power_state);
|
||||
LOGGER.info("Backlight: {}", backlight_power_state);
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setRgbLed(bool red, bool green, bool blue) const {
|
||||
@@ -286,11 +286,11 @@ void UnPhoneFeatures::turnPeripheralsOff() const {
|
||||
|
||||
bool UnPhoneFeatures::setShipping(bool on) const {
|
||||
if (on) {
|
||||
TT_LOG_W(TAG, "setShipping: on");
|
||||
LOGGER.warn("setShipping: on");
|
||||
batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Disabled);
|
||||
batteryManagement->setBatFetOn(false);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "setShipping: off");
|
||||
LOGGER.warn("setShipping: off");
|
||||
batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Enabled40s);
|
||||
batteryManagement->setBatFetOn(true);
|
||||
}
|
||||
|
||||
@@ -2,18 +2,19 @@
|
||||
#include "Touch.h"
|
||||
|
||||
#include <UnPhoneFeatures.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <hx8357/disp_spi.h>
|
||||
#include <hx8357/hx8357.h>
|
||||
|
||||
constexpr auto TAG = "Hx8357Display";
|
||||
static const auto LOGGER = tt::Logger("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 Hx8357Display::start() {
|
||||
TT_LOG_I(TAG, "start");
|
||||
LOGGER.info("start");
|
||||
|
||||
disp_spi_add_device(SPI2_HOST);
|
||||
|
||||
@@ -26,16 +27,16 @@ bool Hx8357Display::start() {
|
||||
}
|
||||
|
||||
bool Hx8357Display::stop() {
|
||||
TT_LOG_I(TAG, "stop");
|
||||
LOGGER.info("stop");
|
||||
disp_spi_remove_device();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hx8357Display::startLvgl() {
|
||||
TT_LOG_I(TAG, "startLvgl");
|
||||
LOGGER.info("startLvgl");
|
||||
|
||||
if (lvglDisplay != nullptr) {
|
||||
TT_LOG_W(TAG, "LVGL was already started");
|
||||
LOGGER.warn("LVGL was already started");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ bool Hx8357Display::startLvgl() {
|
||||
lv_display_set_flush_cb(lvglDisplay, hx8357_flush);
|
||||
|
||||
if (lvglDisplay == nullptr) {
|
||||
TT_LOG_I(TAG, "Failed");
|
||||
LOGGER.info("Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,10 +74,10 @@ bool Hx8357Display::startLvgl() {
|
||||
}
|
||||
|
||||
bool Hx8357Display::stopLvgl() {
|
||||
TT_LOG_I(TAG, "stopLvgl");
|
||||
LOGGER.info("stopLvgl");
|
||||
|
||||
if (lvglDisplay == nullptr) {
|
||||
TT_LOG_W(TAG, "LVGL was already stopped");
|
||||
LOGGER.warn("LVGL was already stopped");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ bool Hx8357Display::stopLvgl() {
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr && touch_device->getLvglIndev() != nullptr) {
|
||||
TT_LOG_I(TAG, "Stopping touch device");
|
||||
LOGGER.info("Stopping touch device");
|
||||
touch_device->stopLvgl();
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ bool Hx8357Display::stopLvgl() {
|
||||
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");
|
||||
LOGGER.info("Created touch device");
|
||||
}
|
||||
|
||||
return touchDevice;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "Touch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
std::shared_ptr<Xpt2046Touch> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046Touch::Configuration>(
|
||||
SPI2_HOST,
|
||||
|
||||
Reference in New Issue
Block a user