Align board project names with board ids (#399)
To avoid keeping track of a list that maps board project names to board ids. Because of this change, we don't have to manually edit `boards.cmake` anymore when adding a new board.
This commit is contained in:
committed by
GitHub
parent
efd3c6041c
commit
61277e74b8
@@ -0,0 +1,33 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
#include <St7796Display.h>
|
||||
|
||||
#define TPAGER_LCD_SPI_HOST SPI2_HOST
|
||||
#define TPAGER_LCD_PIN_CS GPIO_NUM_38
|
||||
#define TPAGER_LCD_PIN_DC GPIO_NUM_37 // RS
|
||||
#define TPAGER_LCD_HORIZONTAL_RESOLUTION 222
|
||||
#define TPAGER_LCD_VERTICAL_RESOLUTION 480
|
||||
#define TPAGER_LCD_SPI_TRANSFER_HEIGHT (TPAGER_LCD_VERTICAL_RESOLUTION / 10)
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
auto configuration = std::make_unique<St7796Display::Configuration>(
|
||||
TPAGER_LCD_SPI_HOST,
|
||||
TPAGER_LCD_PIN_CS,
|
||||
TPAGER_LCD_PIN_DC,
|
||||
480, // w
|
||||
222, // h
|
||||
nullptr,
|
||||
true, //swapXY
|
||||
true, //mirrorX
|
||||
true, //mirrorY
|
||||
true, //invertColor
|
||||
0, //gapX
|
||||
49 //gapY
|
||||
);
|
||||
|
||||
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
|
||||
|
||||
auto display = std::make_shared<St7796Display>(std::move(configuration));
|
||||
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "SdCard.h"
|
||||
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
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 = std::make_unique<SpiSdCardDevice::Config>(
|
||||
TPAGER_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
TPAGER_RADIO_PIN_CS,
|
||||
TPAGER_LCD_PIN_CS
|
||||
}
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createTpagerSdCard();
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "TpagerEncoder.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerEncoder";
|
||||
constexpr auto ENCODER_A = GPIO_NUM_40;
|
||||
constexpr auto ENCODER_B = GPIO_NUM_41;
|
||||
constexpr auto ENCODER_ENTER = GPIO_NUM_7;
|
||||
|
||||
void TpagerEncoder::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
TpagerEncoder* encoder = static_cast<TpagerEncoder*>(lv_indev_get_user_data(indev));
|
||||
constexpr int enter_filter_threshold = 2;
|
||||
static int enter_filter = 0;
|
||||
constexpr int pulses_click = 4;
|
||||
static int pulses_prev = 0;
|
||||
|
||||
// Defaults
|
||||
data->enc_diff = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
int pulses = encoder->getEncoderPulses();
|
||||
int pulse_diff = (pulses - pulses_prev);
|
||||
if ((pulse_diff > pulses_click) || (pulse_diff < -pulses_click)) {
|
||||
data->enc_diff = pulse_diff / pulses_click;
|
||||
pulses_prev = pulses;
|
||||
}
|
||||
|
||||
bool enter = !gpio_get_level(ENCODER_ENTER);
|
||||
if (enter && (enter_filter < enter_filter_threshold)) {
|
||||
enter_filter++;
|
||||
}
|
||||
if (!enter && (enter_filter > 0)) {
|
||||
enter_filter--;
|
||||
}
|
||||
|
||||
if (enter_filter == enter_filter_threshold) {
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
}
|
||||
}
|
||||
|
||||
void TpagerEncoder::initEncoder() {
|
||||
constexpr int LOW_LIMIT = -127;
|
||||
constexpr int HIGH_LIMIT = 126;
|
||||
|
||||
// Accum. count makes it that over- and underflows are automatically compensated.
|
||||
// Prerequisite: watchpoints at low and high limit
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = LOW_LIMIT,
|
||||
.high_limit = HIGH_LIMIT,
|
||||
.flags = {.accum_count = 1},
|
||||
};
|
||||
|
||||
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter intialization failed");
|
||||
}
|
||||
|
||||
pcnt_glitch_filter_config_t filter_config = {
|
||||
.max_glitch_ns = 1000,
|
||||
};
|
||||
|
||||
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter glitch filter config failed");
|
||||
}
|
||||
|
||||
pcnt_chan_config_t chan_1_config = {
|
||||
.edge_gpio_num = ENCODER_B,
|
||||
.level_gpio_num = ENCODER_A,
|
||||
};
|
||||
|
||||
pcnt_chan_config_t chan_2_config = {
|
||||
.edge_gpio_num = ENCODER_A,
|
||||
.level_gpio_num = ENCODER_B,
|
||||
};
|
||||
|
||||
pcnt_channel_handle_t pcnt_chan_1 = nullptr;
|
||||
pcnt_channel_handle_t pcnt_chan_2 = nullptr;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be enabled");
|
||||
}
|
||||
|
||||
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be cleared");
|
||||
}
|
||||
|
||||
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be started");
|
||||
}
|
||||
}
|
||||
|
||||
int TpagerEncoder::getEncoderPulses() const {
|
||||
int pulses = 0;
|
||||
pcnt_unit_get_count(encPcntUnit, &pulses);
|
||||
return pulses;
|
||||
}
|
||||
|
||||
|
||||
bool TpagerEncoder::startLvgl(lv_display_t* display) {
|
||||
initEncoder();
|
||||
|
||||
gpio_input_enable(ENCODER_ENTER);
|
||||
|
||||
encHandle = lv_indev_create();
|
||||
|
||||
lv_indev_set_type(encHandle, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(encHandle, &readCallback);
|
||||
lv_indev_set_display(encHandle, display);
|
||||
lv_indev_set_user_data(encHandle, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TpagerEncoder::stopLvgl() {
|
||||
lv_indev_delete(encHandle);
|
||||
encHandle = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/encoder/EncoderDevice.h>
|
||||
#include <driver/pulse_cnt.h>
|
||||
|
||||
class TpagerEncoder final : public tt::hal::encoder::EncoderDevice {
|
||||
|
||||
lv_indev_t* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = nullptr;
|
||||
|
||||
void initEncoder();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
TpagerEncoder() {}
|
||||
~TpagerEncoder() override {}
|
||||
|
||||
std::string getName() const override { return "T-Lora Pager Encoder"; }
|
||||
std::string getDescription() const override { return "The encoder wheel next to the display"; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override;
|
||||
bool stopLvgl() override;
|
||||
|
||||
int getEncoderPulses() const;
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return encHandle; }
|
||||
};
|
||||
@@ -0,0 +1,221 @@
|
||||
#include "TpagerKeyboard.h"
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerKeyboard";
|
||||
|
||||
constexpr auto BACKLIGHT = GPIO_NUM_46;
|
||||
|
||||
constexpr auto KB_ROWS = 4;
|
||||
constexpr auto KB_COLS = 10;
|
||||
|
||||
// Lowercase Keymap
|
||||
static constexpr char keymap_lc[KB_ROWS][KB_COLS] = {
|
||||
{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'},
|
||||
{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', LV_KEY_ENTER},
|
||||
{'\0', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '\0', LV_KEY_BACKSPACE},
|
||||
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
|
||||
};
|
||||
|
||||
// Uppercase Keymap
|
||||
static constexpr char keymap_uc[KB_ROWS][KB_COLS] = {
|
||||
{'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'},
|
||||
{'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', LV_KEY_ENTER},
|
||||
{'\0', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '\0', LV_KEY_BACKSPACE},
|
||||
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
|
||||
};
|
||||
|
||||
// Symbol Keymap
|
||||
static constexpr char keymap_sy[KB_ROWS][KB_COLS] = {
|
||||
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
|
||||
{'.', '/', '+', '-', '=', ':', '\'', '"', '@', '\t'},
|
||||
{'\0', '_', '$', ';', '?', '!', ',', '.', '\0', LV_KEY_BACKSPACE},
|
||||
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
|
||||
};
|
||||
|
||||
void TpagerKeyboard::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
auto keyboard = static_cast<TpagerKeyboard*>(lv_indev_get_user_data(indev));
|
||||
char keypress = 0;
|
||||
|
||||
if (xQueueReceive(keyboard->queue, &keypress, 0) == pdPASS) {
|
||||
data->key = keypress;
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
} else {
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
|
||||
void TpagerKeyboard::processKeyboard() {
|
||||
static bool shift_pressed = false;
|
||||
static bool sym_pressed = false;
|
||||
static bool cap_toggle = false;
|
||||
static bool cap_toggle_armed = true;
|
||||
bool anykey_pressed = false;
|
||||
|
||||
if (keypad->update()) {
|
||||
anykey_pressed = (keypad->pressed_key_count > 0);
|
||||
for (int i = 0; i < keypad->pressed_key_count; i++) {
|
||||
auto row = keypad->pressed_list[i].row;
|
||||
auto col = keypad->pressed_list[i].col;
|
||||
auto hold = keypad->pressed_list[i].hold_time;
|
||||
|
||||
if ((row == 2) && (col == 0)) {
|
||||
sym_pressed = true;
|
||||
}
|
||||
if ((row == 2) && (col == 8)) {
|
||||
shift_pressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sym_pressed && shift_pressed) && cap_toggle_armed) {
|
||||
cap_toggle = !cap_toggle;
|
||||
cap_toggle_armed = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < keypad->pressed_key_count; i++) {
|
||||
auto row = keypad->pressed_list[i].row;
|
||||
auto col = keypad->pressed_list[i].col;
|
||||
auto hold = keypad->pressed_list[i].hold_time;
|
||||
char chr = '\0';
|
||||
if (sym_pressed) {
|
||||
chr = keymap_sy[row][col];
|
||||
} else if (shift_pressed || cap_toggle) {
|
||||
chr = keymap_uc[row][col];
|
||||
} else {
|
||||
chr = keymap_lc[row][col];
|
||||
}
|
||||
|
||||
if (chr != '\0') xQueueSend(queue, &chr, 50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
for (int i = 0; i < keypad->released_key_count; i++) {
|
||||
auto row = keypad->released_list[i].row;
|
||||
auto col = keypad->released_list[i].col;
|
||||
|
||||
if ((row == 2) && (col == 0)) {
|
||||
sym_pressed = false;
|
||||
}
|
||||
if ((row == 2) && (col == 8)) {
|
||||
shift_pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!sym_pressed && !shift_pressed) && !cap_toggle_armed) {
|
||||
cap_toggle_armed = true;
|
||||
}
|
||||
|
||||
if (anykey_pressed) {
|
||||
makeBacklightImpulse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TpagerKeyboard::startLvgl(lv_display_t* display) {
|
||||
backlightOkay = initBacklight(BACKLIGHT, 30000, LEDC_TIMER_0, LEDC_CHANNEL_1);
|
||||
keypad->init(KB_ROWS, KB_COLS);
|
||||
|
||||
assert(inputTimer == nullptr);
|
||||
inputTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
processKeyboard();
|
||||
});
|
||||
|
||||
assert(backlightImpulseTimer == nullptr);
|
||||
backlightImpulseTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
processBacklightImpulse();
|
||||
});
|
||||
|
||||
kbHandle = lv_indev_create();
|
||||
lv_indev_set_type(kbHandle, LV_INDEV_TYPE_KEYPAD);
|
||||
lv_indev_set_read_cb(kbHandle, &readCallback);
|
||||
lv_indev_set_display(kbHandle, display);
|
||||
lv_indev_set_user_data(kbHandle, this);
|
||||
|
||||
inputTimer->start(20 / portTICK_PERIOD_MS);
|
||||
backlightImpulseTimer->start(50 / portTICK_PERIOD_MS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TpagerKeyboard::stopLvgl() {
|
||||
assert(inputTimer);
|
||||
inputTimer->stop();
|
||||
inputTimer = nullptr;
|
||||
|
||||
assert(backlightImpulseTimer);
|
||||
backlightImpulseTimer->stop();
|
||||
backlightImpulseTimer = nullptr;
|
||||
|
||||
lv_indev_delete(kbHandle);
|
||||
kbHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TpagerKeyboard::isAttached() const {
|
||||
return tt::hal::i2c::masterHasDeviceAtAddress(keypad->getPort(), keypad->getAddress(), 100);
|
||||
}
|
||||
|
||||
bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
|
||||
backlightPin = pin;
|
||||
backlightTimer = timer;
|
||||
backlightChannel = channel;
|
||||
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_8_BIT,
|
||||
.timer_num = backlightTimer,
|
||||
.freq_hz = frequencyHz,
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false
|
||||
};
|
||||
|
||||
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Backlight timer config failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.gpio_num = backlightPin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = backlightChannel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = backlightTimer,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
.flags = {
|
||||
.output_invert = 0
|
||||
}
|
||||
};
|
||||
|
||||
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Backlight channel config failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TpagerKeyboard::setBacklightDuty(uint8_t duty) {
|
||||
if (!backlightOkay) {
|
||||
TT_LOG_E(TAG, "Backlight not ready");
|
||||
return false;
|
||||
}
|
||||
return (ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK) &&
|
||||
(ledc_update_duty(LEDC_LOW_SPEED_MODE, backlightChannel) == ESP_OK);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::makeBacklightImpulse() {
|
||||
backlightImpulseDuty = 255;
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::processBacklightImpulse() {
|
||||
if (backlightImpulseDuty > 64) {
|
||||
backlightImpulseDuty--;
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
#include <Tca8418.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <freertos/queue.h>
|
||||
|
||||
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
|
||||
lv_indev_t* _Nullable kbHandle = nullptr;
|
||||
gpio_num_t backlightPin = GPIO_NUM_NC;
|
||||
ledc_timer_t backlightTimer;
|
||||
ledc_channel_t backlightChannel;
|
||||
bool backlightOkay = false;
|
||||
int backlightImpulseDuty = 0;
|
||||
QueueHandle_t queue = nullptr;
|
||||
|
||||
std::shared_ptr<Tca8418> keypad;
|
||||
std::unique_ptr<tt::Timer> inputTimer;
|
||||
std::unique_ptr<tt::Timer> backlightImpulseTimer;
|
||||
|
||||
bool initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel);
|
||||
void processKeyboard();
|
||||
void processBacklightImpulse();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
explicit TpagerKeyboard(const std::shared_ptr<Tca8418>& tca) : keypad(tca) {
|
||||
queue = xQueueCreate(20, sizeof(char));
|
||||
}
|
||||
|
||||
~TpagerKeyboard() override {
|
||||
vQueueDelete(queue);
|
||||
}
|
||||
|
||||
std::string getName() const override { return "T-Lora Pager Keyboard"; }
|
||||
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override;
|
||||
bool stopLvgl() override;
|
||||
|
||||
bool isAttached() const override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; }
|
||||
|
||||
bool setBacklightDuty(uint8_t duty);
|
||||
void makeBacklightImpulse();
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "TpagerPower.h"
|
||||
|
||||
#include <Bq25896.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerPower";
|
||||
|
||||
constexpr auto TPAGER_GAUGE_I2C_BUS_HANDLE = I2C_NUM_0;
|
||||
|
||||
TpagerPower::~TpagerPower() {}
|
||||
|
||||
bool TpagerPower::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case IsCharging:
|
||||
case Current:
|
||||
case BatteryVoltage:
|
||||
case ChargeLevel:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
|
||||
bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
uint16_t u16 = 0;
|
||||
int16_t s16 = 0;
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case IsCharging:
|
||||
Bq27220::BatteryStatus status;
|
||||
if (gauge->getBatteryStatus(status)) {
|
||||
data.valueAsBool = !status.reg.DSG;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case Current:
|
||||
if (gauge->getCurrent(s16)) {
|
||||
data.valueAsInt32 = s16;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case BatteryVoltage:
|
||||
if (gauge->getVoltage(u16)) {
|
||||
data.valueAsUint32 = u16;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case ChargeLevel:
|
||||
if (gauge->getStateOfCharge(u16)) {
|
||||
data.valueAsUint8 = u16;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TpagerPower::powerOff() {
|
||||
auto device = tt::hal::findDevice([](auto device) {
|
||||
return device->getName() == "BQ25896";
|
||||
});
|
||||
|
||||
if (device == nullptr) {
|
||||
TT_LOG_E(TAG, "BQ25896 not found");
|
||||
return;
|
||||
}
|
||||
|
||||
auto bq25896 = std::reinterpret_pointer_cast<Bq25896>(device);
|
||||
if (bq25896 != nullptr) {
|
||||
bq25896->powerOff();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/power/PowerDevice.h"
|
||||
#include <Bq27220.h>
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
class TpagerPower : public PowerDevice {
|
||||
std::shared_ptr<Bq27220> gauge;
|
||||
|
||||
public:
|
||||
|
||||
TpagerPower(const std::shared_ptr<Bq27220>& bq) : gauge(bq) {}
|
||||
~TpagerPower();
|
||||
|
||||
std::string getName() const final { return "T-LoRa Pager Power measument"; }
|
||||
std::string getDescription() const final { return "Power measurement interface via I2C fuel gauge"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
bool supportsPowerOff() const override { return true; }
|
||||
void powerOff() override;
|
||||
};
|
||||
Reference in New Issue
Block a user