M5UnitUnified 0.5.5 git rev:bf711f3
Loading...
Searching...
No Matches
M5UnitUnified.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
16#ifndef M5_UNIT_UNIFIED_HPP
17#define M5_UNIT_UNIFIED_HPP
18
19#include "M5UnitComponent.hpp"
20#include <M5HAL.hpp>
21#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
22#else
23#include <driver/rmt.h>
24#endif
25#include <vector>
26#include <string>
27
28#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
29class TwoWire;
30class HardwareSerial;
31class SPIClass;
32struct SPISettings;
33#endif
34
39namespace m5 {
40class I2C_Class;
45namespace unit {
46class Component;
47
52class UnitUnified {
53public:
54 using container_type = std::vector<Component*>;
55
59 UnitUnified() = default;
60 UnitUnified(const UnitUnified&) = delete;
61 UnitUnified(UnitUnified&&) noexcept = default;
63
67 UnitUnified& operator=(const UnitUnified&) = delete;
68
69 UnitUnified& operator=(UnitUnified&&) noexcept = default;
71
74#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
81 bool add(Component& u, TwoWire& wire);
82#endif
83#if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && __has_include(<driver/i2c_master.h>))
90 bool add(Component& u, i2c_master_bus_handle_t bus);
91#endif
92#if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && !__has_include(<driver/i2c_master.h>))
101 bool add(Component& u, const i2c_port_t port, const gpio_num_t sda, const gpio_num_t scl);
102#endif
109 bool add(Component& u, m5::I2C_Class& i2c);
111
114
121 bool add(Component& u, const int8_t rx_pin, const int8_t tx_pin);
123
126#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
133 bool add(Component& u, HardwareSerial& serial);
134#endif
135#if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
143 bool add(Component& u, const uart_port_t uart_num);
144#endif
146
149#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
157 bool add(Component& u, SPIClass& spi, const SPISettings& settings);
158#endif
159#if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
168 bool add(Component& u, spi_device_handle_t handle, const gpio_num_t cs = GPIO_NUM_NC);
169#endif
171
174
180 bool add(Component& u, m5::hal::bus::Bus* bus);
182
187 bool begin();
192 void update(const bool force = false);
193
198 std::string debugInfo() const;
199
200protected:
201 bool add_children(Component& u);
202 std::string make_unit_info(const Component* u, const uint8_t indent = 0) const;
203
204protected:
205 container_type _units{};
206
207private:
208 static uint32_t _registerCount;
209};
210
211} // namespace unit
212} // namespace m5
213
214#endif
Main header of M5UnitComponent.
Base class of unit component.
bool add(Component &u, spi_device_handle_t handle, const gpio_num_t cs=GPIO_NUM_NC)
Adding unit to be managed (SPI, ESP-IDF native driver)
std::string debugInfo() const
Output information for debug.
Definition M5UnitUnified.cpp:285
bool add(Component &u, i2c_master_bus_handle_t bus)
Adding unit to be managed (I2C, ESP-IDF native driver)
bool add(Component &u, SPIClass &spi, const SPISettings &settings)
Add unit to be managed (SPI)
bool begin()
Begin all units under management.
Definition M5UnitUnified.cpp:263
bool add(Component &u, HardwareSerial &serial)
Add unit to be managed (UART)
bool add(Component &u, const uart_port_t uart_num)
Adding unit to be managed (UART, ESP-IDF native driver)
void update(const bool force=false)
Update all units under management.
Definition M5UnitUnified.cpp:275
bool add(Component &u, const i2c_port_t port, const gpio_num_t sda, const gpio_num_t scl)
Adding unit to be managed (I2C, ESP-IDF legacy driver)
bool add(Component &u, TwoWire &wire)
Add unit to be managed (I2C via TwoWire)
Top level namespace of M5Stack.
Definition test_helper.hpp:20
Unit-related namespace.