M5Unit-FINGER 0.2.1 git rev:342aaa0
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)
71inline bool addFacesUART(UnitUnified& units, UnitFacesFinger& unit, const uint32_t baud = 19200,
72 const uint32_t config = SERIAL_8N1)
73{
74 const auto fp = getFacesPins();
75 if (fp.rx < 0 || fp.tx < 0) {
76 M5_LIB_LOGE("wiring: addFacesUART unsupported board=0x%02x", static_cast<int>(M5.getBoard()));
77 return false;
78 }
79 M5_LIB_LOGI("wiring: addFacesUART board=0x%02x rx=%d tx=%d pwr=%d tch=%d baud=%lu", static_cast<int>(M5.getBoard()),
80 fp.rx, fp.tx, fp.panel_power, fp.touch_power, (unsigned long)baud);
81
82 auto cfg = unit.config();
83 cfg.panel_power_pin = fp.panel_power;
84 cfg.touch_power_pin = fp.touch_power;
85 unit.config(cfg);
86
87 HardwareSerial& serial = m5::unit::wiring::defaultUartSerial();
88 serial.end();
89 serial.begin(baud, config, fp.rx, fp.tx);
90 return units.add(unit, serial);
91}
92#else // ESP-IDF native
106inline bool addFacesUART(UnitUnified& units, UnitFacesFinger& unit, const uint32_t baud = 19200,
107 const m5::unit::wiring::UartConfig config = m5::unit::wiring::UartConfig::Default)
108{
109 const auto fp = getFacesPins();
110 if (fp.rx < 0 || fp.tx < 0) {
111 M5_LIB_LOGE("wiring: addFacesUART unsupported board=0x%02x", static_cast<int>(M5.getBoard()));
112 return false;
113 }
114 M5_LIB_LOGI("wiring(ESP-IDF): addFacesUART board=0x%02x rx=%d tx=%d pwr=%d tch=%d baud=%u",
115 static_cast<int>(M5.getBoard()), fp.rx, fp.tx, fp.panel_power, fp.touch_power, (unsigned)baud);
116
117 auto cfg = unit.config();
118 cfg.panel_power_pin = fp.panel_power;
119 cfg.touch_power_pin = fp.touch_power;
120 unit.config(cfg);
121
122 auto port = m5::unit::wiring::uartPortHandle(m5::unit::wiring::defaultUartPort(), static_cast<gpio_num_t>(fp.rx),
123 static_cast<gpio_num_t>(fp.tx), baud, config);
124 if (port == UART_NUM_MAX) {
125 return false;
126 }
127 return units.add(unit, port);
128}
129#endif // ARDUINO
130#endif // __M5UNIFIED_HPP__
131
132} // namespace wiring
133} // namespace faces
134} // namespace fpc1xxx
135} // namespace unit
136} // namespace m5
137#endif // M5_UNIT_FINGER_WIRING_HPP
Top level namespace of M5Stack.
Unit-related namespace.
Faces Finger Module (FPC1020A via M-Bus) for M5UnitUnified.