M5Unit-FINGER 0.2.0 git rev:ee2afce
Loading...
Searching...
No Matches
m5_unit_finger_wiring.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
15#ifndef M5_UNIT_FINGER_WIRING_HPP
16#define M5_UNIT_FINGER_WIRING_HPP
17
19#include <M5UnitUnified.hpp>
20#include <wiring/m5_unit_unified_wiring.hpp> // for m5::unit::wiring::defaultUartSerial()
21
22#if defined(ARDUINO)
23#include <HardwareSerial.h>
24#endif
25
26namespace m5 {
27namespace unit {
28namespace fpc1xxx {
29namespace faces {
30namespace wiring {
31
32#if defined(__M5UNIFIED_HPP__)
37struct FacesPins {
38 int rx;
39 int tx;
40 int panel_power;
41 int touch_power;
42};
43
48inline FacesPins getFacesPins()
49{
50 switch (M5.getBoard()) {
51 case m5::board_t::board_M5Stack: // Core / Gray / Fire (M-Bus)
52 return {16, 17, 26, 5};
53 default:
54 return {-1, -1, -1, -1};
55 }
56}
57
58#if defined(ARDUINO)
70inline bool addFacesUART(UnitUnified& units, UnitFacesFinger& unit, const uint32_t baud = 19200,
71 const uint32_t config = SERIAL_8N1)
72{
73 const auto fp = getFacesPins();
74 if (fp.rx < 0 || fp.tx < 0) {
75 M5_LIB_LOGE("wiring: addFacesUART unsupported board=0x%02x", static_cast<int>(M5.getBoard()));
76 return false;
77 }
78 M5_LIB_LOGI("wiring: addFacesUART board=0x%02x rx=%d tx=%d pwr=%d tch=%d baud=%lu", static_cast<int>(M5.getBoard()),
79 fp.rx, fp.tx, fp.panel_power, fp.touch_power, (unsigned long)baud);
80
81 auto cfg = unit.config();
82 cfg.panel_power_pin = fp.panel_power;
83 cfg.touch_power_pin = fp.touch_power;
84 unit.config(cfg);
85
86 HardwareSerial& serial = m5::unit::wiring::defaultUartSerial();
87 serial.end();
88 serial.begin(baud, config, fp.rx, fp.tx);
89 return units.add(unit, serial);
90}
91#else // ESP-IDF native
104inline bool addFacesUART(UnitUnified& units, UnitFacesFinger& unit, const uint32_t baud = 19200,
105 const m5::unit::wiring::UartConfig config = m5::unit::wiring::UartConfig::Default)
106{
107 const auto fp = getFacesPins();
108 if (fp.rx < 0 || fp.tx < 0) {
109 M5_LIB_LOGE("wiring: addFacesUART unsupported board=0x%02x", static_cast<int>(M5.getBoard()));
110 return false;
111 }
112 M5_LIB_LOGI("wiring(ESP-IDF): addFacesUART board=0x%02x rx=%d tx=%d pwr=%d tch=%d baud=%u",
113 static_cast<int>(M5.getBoard()), fp.rx, fp.tx, fp.panel_power, fp.touch_power, (unsigned)baud);
114
115 auto cfg = unit.config();
116 cfg.panel_power_pin = fp.panel_power;
117 cfg.touch_power_pin = fp.touch_power;
118 unit.config(cfg);
119
120 auto port = m5::unit::wiring::uartPortHandle(m5::unit::wiring::defaultUartPort(), static_cast<gpio_num_t>(fp.rx),
121 static_cast<gpio_num_t>(fp.tx), baud, config);
122 if (port == UART_NUM_MAX) {
123 return false;
124 }
125 return units.add(unit, port);
126}
127#endif // ARDUINO
128#endif // __M5UNIFIED_HPP__
129
130} // namespace wiring
131} // namespace faces
132} // namespace fpc1xxx
133} // namespace unit
134} // namespace m5
135#endif // M5_UNIT_FINGER_WIRING_HPP
Top level namespace of M5Stack.
Unit-related namespace.
Faces Finger Module (FPC1020A via M-Bus) for M5UnitUnified.