firmware/src/input/i2cButton.cpp
Thomas Göttgens 71d84404c6
Some checks are pending
CI / setup (check) (push) Waiting to run
CI / setup (esp32) (push) Waiting to run
CI / setup (esp32c3) (push) Waiting to run
CI / setup (esp32c6) (push) Waiting to run
CI / setup (esp32s3) (push) Waiting to run
CI / setup (nrf52840) (push) Waiting to run
CI / setup (rp2040) (push) Waiting to run
CI / setup (rp2350) (push) Waiting to run
CI / setup (stm32) (push) Waiting to run
CI / version (push) Waiting to run
CI / check (push) Blocked by required conditions
CI / build-esp32 (push) Blocked by required conditions
CI / build-esp32s3 (push) Blocked by required conditions
CI / build-esp32c3 (push) Blocked by required conditions
CI / build-esp32c6 (push) Blocked by required conditions
CI / build-nrf52840 (push) Blocked by required conditions
CI / build-rp2040 (push) Blocked by required conditions
CI / build-rp2350 (push) Blocked by required conditions
CI / build-stm32 (push) Blocked by required conditions
CI / build-debian-src (push) Waiting to run
CI / package-pio-deps-native-tft (push) Waiting to run
CI / test-native (push) Waiting to run
CI / docker-deb-amd64 (push) Waiting to run
CI / docker-deb-amd64-tft (push) Waiting to run
CI / docker-alp-amd64 (push) Waiting to run
CI / docker-alp-amd64-tft (push) Waiting to run
CI / docker-deb-arm64 (push) Waiting to run
CI / docker-deb-armv7 (push) Waiting to run
CI / gather-artifacts (esp32) (push) Blocked by required conditions
CI / gather-artifacts (esp32c3) (push) Blocked by required conditions
CI / gather-artifacts (esp32c6) (push) Blocked by required conditions
CI / gather-artifacts (esp32s3) (push) Blocked by required conditions
CI / gather-artifacts (nrf52840) (push) Blocked by required conditions
CI / gather-artifacts (rp2040) (push) Blocked by required conditions
CI / gather-artifacts (rp2350) (push) Blocked by required conditions
CI / gather-artifacts (stm32) (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
CI / release-firmware (esp32) (push) Blocked by required conditions
CI / release-firmware (esp32c3) (push) Blocked by required conditions
CI / release-firmware (esp32c6) (push) Blocked by required conditions
CI / release-firmware (esp32s3) (push) Blocked by required conditions
CI / release-firmware (nrf52840) (push) Blocked by required conditions
CI / release-firmware (rp2040) (push) Blocked by required conditions
CI / release-firmware (rp2350) (push) Blocked by required conditions
CI / release-firmware (stm32) (push) Blocked by required conditions
CI / publish-firmware (push) Blocked by required conditions
add WIP for Unit C6L (#7433)
* add WIP for Unit C6L
* adapt to new config structure
* Add c6l BLE and screen support (#7991)
* Minor c6l fix
* Move out of PRIVATE_HW
---------
Co-authored-by: Austin <vidplace7@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Jason P <Xaositek@users.noreply.github.com>
Co-authored-by: Markus <Links2004@users.noreply.github.com>
2025-09-17 22:40:55 +02:00

95 lines
2.7 KiB
C++

#include "i2cButton.h"
#include "meshUtils.h"
#include "configuration.h"
#if defined(M5STACK_UNITC6L)
#include "MeshService.h"
#include "RadioLibInterface.h"
#include "buzz.h"
#include "input/InputBroker.h"
#include "main.h"
#include "modules/CannedMessageModule.h"
#include "modules/ExternalNotificationModule.h"
#include "power.h"
#include "sleep.h"
#ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif
i2cButtonThread *i2cButton;
using namespace concurrency;
extern void i2c_read_byte(uint8_t addr, uint8_t reg, uint8_t *value);
extern void i2c_write_byte(uint8_t addr, uint8_t reg, uint8_t value);
#define PI4IO_M_ADDR 0x43
#define getbit(x, y) ((x) >> (y)&0x01)
#define PI4IO_REG_IRQ_STA 0x13
#define PI4IO_REG_IN_STA 0x0F
#define PI4IO_REG_CHIP_RESET 0x01
i2cButtonThread::i2cButtonThread(const char *name) : OSThread(name)
{
_originName = name;
if (inputBroker)
inputBroker->registerSource(this);
}
int32_t i2cButtonThread::runOnce()
{
static bool btn1_pressed = false;
static uint32_t press_start_time = 0;
const uint32_t LONG_PRESS_TIME = 1000;
static bool long_press_triggered = false;
uint8_t in_data;
i2c_read_byte(PI4IO_M_ADDR, PI4IO_REG_IRQ_STA, &in_data);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_IRQ_STA, in_data);
if (getbit(in_data, 0)) {
uint8_t input_state;
i2c_read_byte(PI4IO_M_ADDR, PI4IO_REG_IN_STA, &input_state);
if (!getbit(input_state, 0)) {
if (!btn1_pressed) {
btn1_pressed = true;
press_start_time = millis();
long_press_triggered = false;
}
} else {
if (btn1_pressed) {
btn1_pressed = false;
uint32_t press_duration = millis() - press_start_time;
if (long_press_triggered) {
long_press_triggered = false;
return 50;
}
if (press_duration < LONG_PRESS_TIME) {
InputEvent evt;
evt.source = "UserButton";
evt.inputEvent = INPUT_BROKER_USER_PRESS;
evt.kbchar = 0;
evt.touchX = 0;
evt.touchY = 0;
this->notifyObservers(&evt);
}
}
}
}
if (btn1_pressed && !long_press_triggered && (millis() - press_start_time >= LONG_PRESS_TIME)) {
long_press_triggered = true;
InputEvent evt;
evt.source = "UserButton";
evt.inputEvent = INPUT_BROKER_SELECT;
evt.kbchar = 0;
evt.touchX = 0;
evt.touchY = 0;
this->notifyObservers(&evt);
}
return 50;
}
#endif