## Summary * **What is the goal of this PR?** All praise goes to @didacta for his PR #537. Just picked up the reviewer comments to contain the changes as suggested (there was no response for more than 6 weeks, so I wanted to reanimate this feature). Just one addition: should recognize usb cable plug ins / retractions and update the icon immediately * **What changes are included?** ## Additional Context see #537 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< NO >**_
65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <BatteryMonitor.h>
|
|
#include <InputManager.h>
|
|
|
|
// Display SPI pins (custom pins for XteinkX4, not hardware SPI defaults)
|
|
#define EPD_SCLK 8 // SPI Clock
|
|
#define EPD_MOSI 10 // SPI MOSI (Master Out Slave In)
|
|
#define EPD_CS 21 // Chip Select
|
|
#define EPD_DC 4 // Data/Command
|
|
#define EPD_RST 5 // Reset
|
|
#define EPD_BUSY 6 // Busy
|
|
|
|
#define SPI_MISO 7 // SPI MISO, shared between SD card and display (Master In Slave Out)
|
|
|
|
#define BAT_GPIO0 0 // Battery voltage
|
|
|
|
#define UART0_RXD 20 // Used for USB connection detection
|
|
|
|
class HalGPIO {
|
|
#if CROSSPOINT_EMULATED == 0
|
|
InputManager inputMgr;
|
|
#endif
|
|
|
|
bool lastUsbConnected = false;
|
|
bool usbStateChanged = false;
|
|
|
|
public:
|
|
HalGPIO() = default;
|
|
|
|
// Start button GPIO and setup SPI for screen and SD card
|
|
void begin();
|
|
|
|
// Button input methods
|
|
void update();
|
|
bool isPressed(uint8_t buttonIndex) const;
|
|
bool wasPressed(uint8_t buttonIndex) const;
|
|
bool wasAnyPressed() const;
|
|
bool wasReleased(uint8_t buttonIndex) const;
|
|
bool wasAnyReleased() const;
|
|
unsigned long getHeldTime() const;
|
|
|
|
// Check if USB is connected
|
|
bool isUsbConnected() const;
|
|
|
|
// Returns true once per edge (plug or unplug) since the last update()
|
|
bool wasUsbStateChanged() const;
|
|
|
|
enum class WakeupReason { PowerButton, AfterFlash, AfterUSBPower, Other };
|
|
|
|
WakeupReason getWakeupReason() const;
|
|
|
|
// Button indices
|
|
static constexpr uint8_t BTN_BACK = 0;
|
|
static constexpr uint8_t BTN_CONFIRM = 1;
|
|
static constexpr uint8_t BTN_LEFT = 2;
|
|
static constexpr uint8_t BTN_RIGHT = 3;
|
|
static constexpr uint8_t BTN_UP = 4;
|
|
static constexpr uint8_t BTN_DOWN = 5;
|
|
static constexpr uint8_t BTN_POWER = 6;
|
|
};
|
|
|
|
extern HalGPIO gpio; // Singleton
|