Skip to content

Commit aa04668

Browse files
committed
Merge branch 'develop'
2 parents 3043f2d + a302fd6 commit aa04668

5 files changed

Lines changed: 49 additions & 24 deletions

File tree

library.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"url": "https://github.com/m5stack/M5UnitUnified.git"
1212
},
1313
"dependencies": {
14-
"m5stack/M5Utility": ">=0.0.10",
15-
"m5stack/M5HAL": "*"
14+
"m5stack/M5Utility": ">=0.0.13",
15+
"m5stack/M5HAL": ">=0.0.4"
1616
},
17-
"version": "0.4.7",
17+
"version": "0.4.8",
1818
"frameworks": [
1919
"arduino"
2020
],

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5UnitUnified
2-
version=0.4.7
2+
version=0.4.8
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=M5UnitUnified is a library for unified handling of various M5 units products.
@@ -8,4 +8,4 @@ category=Device Control
88
url=https://github.com/m5stack/M5UnitUnified
99
architectures=esp32
1010
includes=M5UnitUnified.h
11-
depends=M5Utility,M5HAL
11+
depends=M5Utility (>=0.0.13),M5HAL (>=0.0.4)

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ lib_deps = ${env.lib_deps}
106106
[StickS3]
107107
extends = m5base
108108
board = esp32-s3-devkitc-1
109-
board_build.arduino.partitions = default_8MB.csv
110-
board_build.arduino.memory_type = qio_opi
109+
board_build.partitions = default_8MB.csv
110+
board_build.memory_type = qio_opi
111111
build_flags =
112112
-DESP32S3
113113
-DBOARD_HAS_PSRAM

src/wiring/m5_unit_unified_wiring.hpp

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
/*!
77
@file m5_unit_unified_wiring.hpp
88
@brief Opt-in, header-only board-aware connection helpers for M5UnitUnified examples
9+
10+
@details
11+
This header exists solely to keep the example code in M5UnitUnified and M5Unit-* repositories
12+
short and readable. Each helper resolves board-specific pins / backends through M5Unified,
13+
opens the bus, and calls UnitUnified::add().
14+
15+
Users SHOULD treat these helpers as reference implementations, not as the only supported way
16+
to wire a unit. In real applications, prefer to call UnitUnified::add() directly with a bus
17+
or handle that fits the application's lifecycle (shared bus management, custom pins,
18+
alternative backends, etc.).
19+
920
@note REQUIRES <M5Unified.h> (or <M5Unified.hpp>) to be included BEFORE this header.
1021
Pin-acquisition helpers (i2cPins / gpioPins / uartPins / spiPins / hatI2CPins / hatGPIOPins /
1122
hatUARTPins) work on both Arduino and ESP-IDF (any platform where M5Unified is available).
@@ -332,14 +343,18 @@ inline HardwareSerial& defaultUartSerial()
332343
}
333344

334345
/*!
335-
@brief Add a unit on UART, preferring PortC and falling back to PortA
336-
@note On NanoC6 / NanoH2 fallback, M5.Ex_I2C.begin() + release() is called to flip the m5gfx
346+
@brief Add a unit on the board's default UART, preferring PortC and falling back to PortA
347+
@param baud Baud rate (default 115200)
348+
@param config UART config (0 = SERIAL_8N1, otherwise passed through)
349+
@note Selects HardwareSerial via defaultUartSerial() based on board.
350+
On NanoC6 / NanoH2 fallback, M5.Ex_I2C.begin() + release() is called to flip the m5gfx
337351
I2C `initialized` flag so release() actually detaches the bus + restores pins.
338352
*/
339-
inline bool addUART(UnitUnified& units, Component& unit, HardwareSerial& serial, const uint32_t baud = 115200,
340-
const uint32_t config = SERIAL_8N1)
353+
inline bool addUART(UnitUnified& units, Component& unit, const uint32_t baud = 115200, const uint32_t config = 0)
341354
{
342-
const auto p = uartPins();
355+
HardwareSerial& serial = defaultUartSerial();
356+
const uint32_t cfg = (config == 0) ? static_cast<uint32_t>(SERIAL_8N1) : config;
357+
const auto p = uartPins();
343358
if (p.fallback_a) {
344359
const auto b = M5.getBoard();
345360
if (b == m5::board_t::board_M5NanoC6 || b == m5::board_t::board_M5NanoH2) {
@@ -350,10 +365,10 @@ inline bool addUART(UnitUnified& units, Component& unit, HardwareSerial& serial,
350365
M5.Ex_I2C.release();
351366
}
352367
}
353-
M5_LIB_LOGI("wiring: UART rx=%d tx=%d baud=%lu fallback_a=%d", (int)p.rx, (int)p.tx, (unsigned long)baud,
354-
(int)p.fallback_a);
368+
M5_LIB_LOGI("wiring: UART rx=%d tx=%d baud=%lu config=0x%lx fallback_a=%d", (int)p.rx, (int)p.tx,
369+
(unsigned long)baud, (unsigned long)cfg, (int)p.fallback_a);
355370
serial.end();
356-
serial.begin(baud, config, p.rx, p.tx);
371+
serial.begin(baud, cfg, p.rx, p.tx);
357372
return units.add(unit, serial);
358373
}
359374

@@ -366,12 +381,18 @@ inline bool spiBus(UnitUnified& units, Component& unit, SPIClass& spi, const SPI
366381

367382
/*!
368383
@brief Add a unit on the board's shared SD/SPI bus, beginning it on demand
384+
@param clock_hz SPI clock in Hz
385+
@param mode SPI mode 0/1/2/3 (default 0)
386+
@param bit_order Bit order: 0 = MSBFIRST (default), 1 = LSBFIRST
369387
@note Resolves the sd_spi_* pins. SPI.begin() is called only if the bus is not already begun.
370388
*/
371-
inline bool addSPI(UnitUnified& units, Component& unit, const SPISettings& settings)
389+
inline bool addSPI(UnitUnified& units, Component& unit, const uint32_t clock_hz, const uint8_t mode = 0,
390+
const uint8_t bit_order = 0)
372391
{
392+
SPISettings settings{clock_hz, static_cast<uint8_t>((bit_order == 0) ? MSBFIRST : LSBFIRST), mode};
373393
const auto p = spiPins();
374-
M5_LIB_LOGI("wiring: addSPI sclk=%d miso=%d mosi=%d", (int)p.sclk, (int)p.miso, (int)p.mosi);
394+
M5_LIB_LOGI("wiring: addSPI sclk=%d miso=%d mosi=%d clock=%lu mode=%u bit_order=%u", (int)p.sclk, (int)p.miso,
395+
(int)p.mosi, (unsigned long)clock_hz, (unsigned)mode, (unsigned)bit_order);
375396
if (!SPI.bus()) {
376397
SPI.begin(p.sclk, p.miso, p.mosi);
377398
}
@@ -427,19 +448,23 @@ inline bool addHatGPIO(UnitUnified& units, Component& unit, const GpioRole role
427448

428449
/*!
429450
@brief Add a unit on the board's Hat UART header
451+
@param baud Baud rate (default 115200)
452+
@param config UART config (0 = SERIAL_8N1, otherwise passed through)
453+
@note Selects HardwareSerial via defaultUartSerial() based on board.
430454
*/
431-
inline bool addHatUART(UnitUnified& units, Component& unit, HardwareSerial& serial, const uint32_t baud = 115200,
432-
const uint32_t config = SERIAL_8N1)
455+
inline bool addHatUART(UnitUnified& units, Component& unit, const uint32_t baud = 115200, const uint32_t config = 0)
433456
{
434-
const auto p = hatUARTPins();
457+
HardwareSerial& serial = defaultUartSerial();
458+
const uint32_t cfg = (config == 0) ? static_cast<uint32_t>(SERIAL_8N1) : config;
459+
const auto p = hatUARTPins();
435460
if (p.rx < 0 || p.tx < 0) {
436461
M5_LIB_LOGE("wiring: Hat UART unsupported board=0x%02x", (int)M5.getBoard());
437462
return false;
438463
}
439-
M5_LIB_LOGI("wiring: addHatUART board=0x%02x rx=%d tx=%d baud=%lu", (int)M5.getBoard(), (int)p.rx, (int)p.tx,
440-
(unsigned long)baud);
464+
M5_LIB_LOGI("wiring: addHatUART board=0x%02x rx=%d tx=%d baud=%lu config=0x%lx", (int)M5.getBoard(), (int)p.rx,
465+
(int)p.tx, (unsigned long)baud, (unsigned long)cfg);
441466
serial.end();
442-
serial.begin(baud, config, p.rx, p.tx);
467+
serial.begin(baud, cfg, p.rx, p.tx);
443468
return units.add(unit, serial);
444469
}
445470
#endif // ARDUINO

test/embedded/test_update/update_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static bool add_with_gpio(UnitUnified& units, Component& u)
3535

3636
static bool add_with_uart(UnitUnified& units, Component& u)
3737
{
38-
return m5::unit::wiring::addUART(units, u, m5::unit::wiring::defaultUartSerial());
38+
return m5::unit::wiring::addUART(units, u);
3939
}
4040

4141
static bool add_with_spi(UnitUnified& units, Component& u)

0 commit comments

Comments
 (0)