mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
## Summary Extracted some changes from https://github.com/crosspoint-reader/crosspoint-reader/pull/500 to make reviewing easier This PR adds HAL (Hardware Abstraction Layer) for display and GPIO components, making it easier to write a stub or an emulated implementation of the hardware. SD card HAL will be added via another PR, because it's a bit more tricky. --- ### 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**
62 lines
1.6 KiB
C++
62 lines
1.6 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
|
|
|
|
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;
|
|
|
|
// Setup wake up GPIO and enter deep sleep
|
|
void startDeepSleep();
|
|
|
|
// Get battery percentage (range 0-100)
|
|
int getBatteryPercentage() const;
|
|
|
|
// Check if USB is connected
|
|
bool isUsbConnected() const;
|
|
|
|
// Check if wakeup was caused by power button press
|
|
bool isWakeupByPowerButton() 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;
|
|
};
|