55** A new approach to connect and handle various M5 units in the M5Stack**
66Library for M5Stack Series and M5Unit Series
77
8- ** Notice: Now α version**
9- Please send your comments and requests to Issue or PR.
10-
118## Overview
129M5UnitUnified is a library for unified handling of various M5 units products.
1310
@@ -26,7 +23,7 @@ All M5UnitUnified and related libraries are under the [MIT license](LICENSE).
2623
2724
2825## How to install
29- Alpha version, but registered in the Library Manager
26+ The library is registered with the library manager.
3027
3128### Arduino IDE
3229
@@ -175,6 +172,47 @@ void loop() {
175172
176173```
177174
175+ #### Unit using SPI
176+
177+ ``` cpp
178+ // If you use other units, change include files(*1), instances(*2), and call any API(*3)
179+ #include < M5Unified.h>
180+ #include < M5UnitUnified.h>
181+ #include < M5UnitUnifiedFoo.h> // *1 Include the header of the unit to be used
182+
183+ m5::unit::UnitUnified Units;
184+ m5::unit::UnitFoo unit; // *2 Instance of the unit
185+
186+ void setup ()
187+ {
188+ M5.begin();
189+
190+ if (!SPI.bus()) {
191+ auto spi_sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
192+ auto spi_mosi = M5.getPin(m5::pin_name_t::sd_spi_mosi);
193+ auto spi_miso = M5.getPin(m5::pin_name_t::sd_spi_miso);
194+ M5_LOGI ("getPin: %d,%d,%d", spi_sclk, spi_mosi, spi_miso);
195+ SPI.begin(spi_sclk, spi_miso, spi_mosi);
196+ }
197+
198+ // Note that the depending on the target unit
199+ SPISettings settings = {10000000, MSBFIRST, SPI_MODE1};
200+ if (!Units.add(cap, SPI, settings) || !Units.begin()) {
201+ M5_LOGE ("Failed to begin");
202+ lcd.fillScreen(TFT_RED);
203+ while (true) {
204+ m5::utility::delay(10000);
205+ }
206+ }
207+ }
208+
209+ void loop () {
210+ M5.update();
211+ Units.update();
212+ // *3 Arbitrary API calls to the unit...
213+ }
214+ ```
215+
178216- Nonstandard usage
179217 - [ To update the unit yourself usage example] ( examples/Basic/SelfUpdate )
180218 - [ Using only unit component without UnitUnified manager] ( examples/Basic/ComponentOnly )
@@ -186,9 +224,10 @@ void loop() {
186224Support ESP-IDF with M5HAL in the future.
187225
188226### Supported connection
189- - I2C with TwoWire
227+ - I2C with TwoWire class
190228- GPIO (Currently only functions required for the units are included)
191- - UART with HardwareSerial
229+ - UART with HardwareSerial class
230+ - SPI with SPI class
192231
193232### Supported devices, units
194233See also [ Wiki] ( https://github.com/m5stack/M5UnitUnified/wiki/ )
0 commit comments