M5UnitUnified 0.6.3 git rev:e38fc73
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(ESP_PLATFORM) && !defined(M5_UNIT_UNIFIED_USING_RMT_V2)
22#include <driver/rmt.h>
23#endif
24#include <vector>
25#include <string>
26
27#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
28class TwoWire;
29class HardwareSerial;
30class SPIClass;
31struct SPISettings;
32#endif
33
38namespace m5 {
39class I2C_Class;
44namespace unit {
45class Component;
46
51class UnitUnified {
52public:
53 using container_type = std::vector<Component*>;
54
58 UnitUnified() = default;
59 UnitUnified(const UnitUnified&) = delete;
60 UnitUnified(UnitUnified&&) noexcept = default;
62
66 UnitUnified& operator=(const UnitUnified&) = delete;
67
68 UnitUnified& operator=(UnitUnified&&) noexcept = default;
70
73#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
80 bool add(Component& u, TwoWire& wire);
81#endif
82#if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && __has_include(<driver/i2c_master.h>))
89 bool add(Component& u, i2c_master_bus_handle_t bus);
100 bool add(Component& u, i2c_master_bus_handle_t bus, const i2c_port_t port, const gpio_num_t sda,
101 const gpio_num_t scl);
102#endif
103#if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && !__has_include(<driver/i2c_master.h>))
112 bool add(Component& u, const i2c_port_t port, const gpio_num_t sda, const gpio_num_t scl);
113#endif
120 bool add(Component& u, m5::I2C_Class& i2c);
122
123#if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
126
134 bool add(Component& u, const int8_t rx_pin, const int8_t tx_pin);
136#endif
137
140#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
147 bool add(Component& u, HardwareSerial& serial);
148#endif
149#if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
157 bool add(Component& u, const uart_port_t uart_num);
158#endif
160
163#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
171 bool add(Component& u, SPIClass& spi, const SPISettings& settings);
172#endif
173#if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
182 bool add(Component& u, spi_device_handle_t handle, const gpio_num_t cs = GPIO_NUM_NC);
183#endif
185
188
194 bool add(Component& u, m5::hal::bus::Bus* bus);
196
201 bool begin();
206 void update(const bool force = false);
207
212 std::string debugInfo() const;
213
214protected:
215 bool add_children(Component& u);
216 std::string make_unit_info(const Component* u, const uint8_t indent = 0) const;
217
218protected:
219 container_type _units{};
220
221private:
222 static uint32_t _registerCount;
223};
224
225} // namespace unit
226} // namespace m5
227
228#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:321
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:299
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:311
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, const int8_t rx_pin, const int8_t tx_pin)
Add unit to be managed (GPIO)
bool add(Component &u, i2c_master_bus_handle_t bus, const i2c_port_t port, const gpio_num_t sda, const gpio_num_t scl)
Adding unit to be managed (I2C, ESP-IDF native driver, with the bus port and pins)
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.