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,5 +1,6 @@
|
||||
#include <Bq27220.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
@@ -8,16 +9,16 @@
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
constexpr auto* TAG = "TLoraPager";
|
||||
static const auto LOGGER = tt::Logger("T-Lora Pager");
|
||||
|
||||
bool tpagerInit() {
|
||||
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
LOGGER.info(LOG_MESSAGE_POWER_ON_START);
|
||||
|
||||
/* 32 Khz and higher gives an issue where the screen starts dimming again above 80% brightness
|
||||
* when moving the brightness slider rapidly from a lower setting to 100%.
|
||||
* This is not a slider bug (data was debug-traced) */
|
||||
if (!driver::pwmbacklight::init(GPIO_NUM_42, 30000)) {
|
||||
TT_LOG_E(TAG, "Backlight init failed");
|
||||
LOGGER.error("Backlight init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,9 +45,9 @@ bool tpagerInit() {
|
||||
.baudRate = 38400,
|
||||
.model = tt::hal::gps::GpsModel::UBLOX10
|
||||
})) {
|
||||
TT_LOG_I(TAG, "Configured internal GPS");
|
||||
LOGGER.info("Configured internal GPS");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to configure internal GPS");
|
||||
LOGGER.error("Failed to configure internal GPS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "TpagerEncoder.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerEncoder";
|
||||
static const auto LOGGER = tt::Logger("TpagerEncoder");
|
||||
|
||||
constexpr auto ENCODER_A = GPIO_NUM_40;
|
||||
constexpr auto ENCODER_B = GPIO_NUM_41;
|
||||
constexpr auto ENCODER_ENTER = GPIO_NUM_7;
|
||||
@@ -39,7 +40,9 @@ void TpagerEncoder::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
}
|
||||
}
|
||||
|
||||
void TpagerEncoder::initEncoder() {
|
||||
bool TpagerEncoder::initEncoder() {
|
||||
assert(encPcntUnit == nullptr);
|
||||
|
||||
constexpr int LOW_LIMIT = -127;
|
||||
constexpr int HIGH_LIMIT = 126;
|
||||
|
||||
@@ -48,11 +51,15 @@ void TpagerEncoder::initEncoder() {
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = LOW_LIMIT,
|
||||
.high_limit = HIGH_LIMIT,
|
||||
.flags = {.accum_count = 1},
|
||||
.intr_priority = 0,
|
||||
.flags = {
|
||||
.accum_count = 1
|
||||
},
|
||||
};
|
||||
|
||||
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter intialization failed");
|
||||
LOGGER.error("Pulsecounter initialization failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
pcnt_glitch_filter_config_t filter_config = {
|
||||
@@ -60,17 +67,34 @@ void TpagerEncoder::initEncoder() {
|
||||
};
|
||||
|
||||
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter glitch filter config failed");
|
||||
LOGGER.error("Pulsecounter glitch filter config failed");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
pcnt_chan_config_t chan_1_config = {
|
||||
.edge_gpio_num = ENCODER_B,
|
||||
.level_gpio_num = ENCODER_A,
|
||||
.flags {
|
||||
.invert_edge_input = 0,
|
||||
.invert_level_input = 0,
|
||||
.virt_edge_io_level = 0,
|
||||
.virt_level_io_level = 0,
|
||||
.io_loop_back = 0
|
||||
}
|
||||
};
|
||||
|
||||
pcnt_chan_config_t chan_2_config = {
|
||||
.edge_gpio_num = ENCODER_A,
|
||||
.level_gpio_num = ENCODER_B,
|
||||
.flags {
|
||||
.invert_edge_input = 0,
|
||||
.invert_level_input = 0,
|
||||
.virt_edge_io_level = 0,
|
||||
.virt_level_io_level = 0,
|
||||
.io_loop_back = 0
|
||||
}
|
||||
};
|
||||
|
||||
pcnt_channel_handle_t pcnt_chan_1 = nullptr;
|
||||
@@ -78,37 +102,60 @@ void TpagerEncoder::initEncoder() {
|
||||
|
||||
if ((pcnt_new_channel(encPcntUnit, &chan_1_config, &pcnt_chan_1) != ESP_OK) ||
|
||||
(pcnt_new_channel(encPcntUnit, &chan_2_config, &pcnt_chan_2) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter channel config failed");
|
||||
LOGGER.error("Pulsecounter channel config failed");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Second argument is rising edge, third argument is falling edge
|
||||
if ((pcnt_channel_set_edge_action(pcnt_chan_1, PCNT_CHANNEL_EDGE_ACTION_DECREASE, PCNT_CHANNEL_EDGE_ACTION_INCREASE) != ESP_OK) ||
|
||||
(pcnt_channel_set_edge_action(pcnt_chan_2, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_DECREASE) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter edge action config failed");
|
||||
LOGGER.error("Pulsecounter edge action config failed");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Second argument is low level, third argument is high level
|
||||
if ((pcnt_channel_set_level_action(pcnt_chan_1, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK) ||
|
||||
(pcnt_channel_set_level_action(pcnt_chan_2, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter level action config failed");
|
||||
LOGGER.error("Pulsecounter level action config failed");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((pcnt_unit_add_watch_point(encPcntUnit, LOW_LIMIT) != ESP_OK) ||
|
||||
(pcnt_unit_add_watch_point(encPcntUnit, HIGH_LIMIT) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter watch point config failed");
|
||||
LOGGER.error("Pulsecounter watch point config failed");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be enabled");
|
||||
LOGGER.error("Pulsecounter could not be enabled");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be cleared");
|
||||
LOGGER.error("Pulsecounter could not be cleared");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be started");
|
||||
LOGGER.error("Pulsecounter could not be started");
|
||||
pcnt_del_unit(encPcntUnit);
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int TpagerEncoder::getEncoderPulses() const {
|
||||
@@ -117,9 +164,29 @@ int TpagerEncoder::getEncoderPulses() const {
|
||||
return pulses;
|
||||
}
|
||||
|
||||
bool TpagerEncoder::deinitEncoder() {
|
||||
assert(encPcntUnit != nullptr);
|
||||
|
||||
if (pcnt_unit_stop(encPcntUnit) != ESP_OK) {
|
||||
LOGGER.warn("Failed to stop encoder");
|
||||
}
|
||||
|
||||
if (pcnt_del_unit(encPcntUnit) != ESP_OK) {
|
||||
LOGGER.warn("Failed to delete encoder");
|
||||
encPcntUnit = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGGER.info("Deinitialized");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TpagerEncoder::startLvgl(lv_display_t* display) {
|
||||
initEncoder();
|
||||
if (encPcntUnit == nullptr && !initEncoder()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gpio_input_enable(ENCODER_ENTER);
|
||||
|
||||
@@ -137,5 +204,10 @@ bool TpagerEncoder::stopLvgl() {
|
||||
lv_indev_delete(encHandle);
|
||||
encHandle = nullptr;
|
||||
|
||||
if (encPcntUnit != nullptr && !deinitEncoder()) {
|
||||
// We're not returning false as LVGL as effectively deinitialized
|
||||
LOGGER.warn("Deinitialization failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ class TpagerEncoder final : public tt::hal::encoder::EncoderDevice {
|
||||
lv_indev_t* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = nullptr;
|
||||
|
||||
void initEncoder();
|
||||
bool initEncoder();
|
||||
bool deinitEncoder();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "TpagerKeyboard.h"
|
||||
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <driver/i2c.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerKeyboard";
|
||||
static const auto LOGGER = tt::Logger("TpagerKeyboard");
|
||||
|
||||
constexpr auto BACKLIGHT = GPIO_NUM_46;
|
||||
|
||||
@@ -174,7 +174,7 @@ bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_ti
|
||||
};
|
||||
|
||||
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Backlight timer config failed");
|
||||
LOGGER.error("Backlight timer config failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_ti
|
||||
};
|
||||
|
||||
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Backlight channel config failed");
|
||||
LOGGER.error("Backlight channel config failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -201,7 +201,7 @@ bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_ti
|
||||
|
||||
bool TpagerKeyboard::setBacklightDuty(uint8_t duty) {
|
||||
if (!backlightOkay) {
|
||||
TT_LOG_E(TAG, "Backlight not ready");
|
||||
LOGGER.error("Backlight not ready");
|
||||
return false;
|
||||
}
|
||||
return (ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK) &&
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "TpagerPower.h"
|
||||
|
||||
#include <Bq25896.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerPower";
|
||||
static const auto LOGGER = tt::Logger("TpagerPower");
|
||||
|
||||
constexpr auto TPAGER_GAUGE_I2C_BUS_HANDLE = I2C_NUM_0;
|
||||
|
||||
@@ -68,7 +68,7 @@ void TpagerPower::powerOff() {
|
||||
});
|
||||
|
||||
if (device == nullptr) {
|
||||
TT_LOG_E(TAG, "BQ25896 not found");
|
||||
LOGGER.error("BQ25896 not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user