M5UnitUnified 0.4.6 git rev:c61a63c
Loading...
Searching...
No Matches
M5UnitComponent.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_COMPONENT_HPP
11#define M5_UNIT_COMPONENT_HPP
12
15#include <cstdint>
16#include <vector>
17#include <algorithm>
18#include <iterator>
19#include <type_traits>
20#include <memory>
21
22class TwoWire;
23class HardwareSerial;
24class SPIClass;
25struct SPISettings;
26
27namespace m5 {
28class I2C_Class;
29namespace unit {
30
31class UnitUnified;
32class Adapter;
33
38class Component {
39public:
46 uint32_t clock{100000};
48 uint32_t stored_size{1};
50 bool self_update{false};
52 uint8_t max_children{0};
53 };
54
58 static const types::uid_t uid;
59 static const types::attr_t attr;
60 static const char name[];
62
66 explicit Component(const uint8_t addr = 0x00); // I2C address
67
68 Component(const Component&) = delete;
69
70 Component(Component&&) noexcept = default;
72
76 Component& operator=(const Component&) = delete;
77
78 Component& operator=(Component&&) noexcept = default;
80
81 virtual ~Component() = default;
82
85
87 {
88 return _component_cfg;
89 }
91 inline void component_config(const component_config_t& cfg)
92 {
93 _component_cfg = cfg;
94 }
96
99
103 virtual bool begin()
104 {
105 return true;
106 }
111 virtual void update(const bool force = false)
112 {
113 (void)force;
114 }
116
119
120 inline const char* deviceName() const
121 {
122 return unit_device_name();
123 }
126 {
127 return unit_identifier();
128 }
131 {
132 return unit_attribute();
133 }
136 {
137 return unit_category();
138 }
140 inline uint32_t order() const
141 {
142 return _order;
143 }
145 inline int16_t channel() const
146 {
147 return _channel;
148 }
150 inline bool isRegistered() const
151 {
152 return _manager != nullptr;
153 }
155 inline uint8_t address() const
156 {
157 return _addr;
158 }
163 inline Adapter* adapter() const
164 {
165 return _adapter.get();
166 }
168 template <class T>
169 inline auto asAdapter(const Adapter::Type t) ->
170 typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
171 {
172 using U = typename std::remove_cv<typename std::remove_pointer<T>::type>::type;
173 static_assert(std::is_base_of<Adapter, U>::value, "T must be derived from Adapter");
174 return (_adapter->type() == t) ? static_cast<U*>(_adapter.get()) : nullptr;
175 }
176 template <class T>
177 inline auto asAdapter(const Adapter::Type t) const -> const
178 typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
179 {
180 using U = typename std::remove_cv<typename std::remove_pointer<T>::type>::type;
181 static_assert(std::is_base_of<Adapter, U>::value, "T must be derived from Adapter");
182 return (_adapter->type() == t) ? static_cast<const U*>(_adapter.get()) : nullptr;
183 }
185
188 bool canAccessI2C() const;
189 bool canAccessGPIO() const;
190 bool canAccessUART() const;
191 bool canAccessSPI() const;
193
196
197 inline bool inPeriodic() const
198 {
199 return in_periodic();
200 }
202 inline bool updated() const
203 {
204 return _updated;
205 }
211 {
212 return _latest;
213 }
219 {
220 return _interval;
221 }
223
226
227 virtual bool assign(m5::hal::bus::Bus* bus);
229 virtual bool assign(TwoWire& wire);
231 virtual bool assign(m5::I2C_Class& i2c);
233 virtual bool assign(const int8_t rx_pin, const int8_t tx_pin);
235 virtual bool assign(HardwareSerial& serial);
237 virtual bool assign(SPIClass& spi, const SPISettings& settings);
239
243
244 inline bool hasParent() const
245 {
246 return _parent != nullptr;
247 }
249 inline bool hasSiblings() const
250 {
251 return (_prev != nullptr) || (_next != nullptr);
252 }
254 inline bool hasChildren() const
255 {
256 return _child;
257 }
259 size_t childrenSize() const;
261 bool existsChild(const uint8_t ch) const;
264 {
265 return _parent;
266 }
268 Component* child(const uint8_t channel) const;
270 bool add(Component& c, const int16_t channel);
272 bool selectChannel(const uint8_t ch = 8);
274
276 template <typename T>
277 class iterator {
278 public:
279 using iterator_category = std::forward_iterator_tag;
280 using difference_type = std::ptrdiff_t;
281 using value_type = T;
282 using pointer = T*;
283 using reference = T&;
284
285 explicit iterator(Component* c = nullptr) : _ptr(c)
286 {
287 }
288
289 reference operator*() const
290 {
291 return *_ptr;
292 }
293 pointer operator->() const
294 {
295 return _ptr;
296 }
297 iterator& operator++()
298 {
299 _ptr = _ptr ? _ptr->_next : nullptr;
300 return *this;
301 }
302 iterator operator++(int)
303 {
304 auto tmp = *this;
305 ++(*this);
306 return tmp;
307 }
308 friend bool operator==(const iterator& a, const iterator& b)
309 {
310 return a._ptr == b._ptr;
311 }
312 friend bool operator!=(const iterator& a, const iterator& b)
313 {
314 return a._ptr != b._ptr;
315 }
316
317 private:
318 Component* _ptr;
319 };
320
321 using child_iterator = iterator<Component>;
322 using const_child_iterator = iterator<const Component>;
323 inline child_iterator childBegin() noexcept
324 {
325 return child_iterator(_child);
326 }
327 inline child_iterator childEnd() noexcept
328 {
329 return child_iterator();
330 }
331 inline const_child_iterator childBegin() const noexcept
332 {
333 return const_child_iterator(_child);
334 }
335 inline const_child_iterator childEnd() const noexcept
336 {
337 return const_child_iterator();
338 }
340
347 bool generalCall(const uint8_t* data, const size_t len);
348
350 virtual std::string debugInfo() const;
351
353
354 // I2C R/W
356 m5::hal::error::error_t readWithTransaction(uint8_t* data, const size_t len);
357
358 template <typename Reg,
359 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
360 std::nullptr_t>::type = nullptr>
361 bool readRegister(const Reg reg, uint8_t* rbuf, const size_t len, const uint32_t delayMillis,
362 const bool stop = true);
363 template <typename Reg,
364 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
365 std::nullptr_t>::type = nullptr>
366 bool readRegister8(const Reg reg, uint8_t& result, const uint32_t delayMillis, const bool stop = true);
367
368 template <typename Reg,
369 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
370 std::nullptr_t>::type = nullptr>
371 inline bool readRegister16BE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true)
372 {
373 return read_register16E(reg, result, delayMillis, stop, true);
374 }
375
376 template <typename Reg,
377 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
378 std::nullptr_t>::type = nullptr>
379 inline bool readRegister16LE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true)
380 {
381 return read_register16E(reg, result, delayMillis, stop, false);
382 }
383
384 template <typename Reg,
385 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
386 std::nullptr_t>::type = nullptr>
387 inline bool readRegister32BE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true)
388 {
389 return read_register32E(reg, result, delayMillis, stop, true);
390 }
391
392 template <typename Reg,
393 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
394 std::nullptr_t>::type = nullptr>
395 inline bool readRegister32LE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true)
396 {
397 return read_register32E(reg, result, delayMillis, stop, false);
398 }
399
400 m5::hal::error::error_t writeWithTransaction(const uint8_t* data, const size_t len, const uint32_t exparam = 1);
401
402 template <typename Reg,
403 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
404 std::nullptr_t>::type = nullptr>
405 m5::hal::error::error_t writeWithTransaction(const Reg reg, const uint8_t* data, const size_t len,
406 const bool stop = true);
407
408 template <typename Reg,
409 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
410 std::nullptr_t>::type = nullptr>
411 bool writeRegister(const Reg reg, const uint8_t* buf = nullptr, const size_t len = 0U, const bool stop = true);
412
413 template <typename Reg,
414 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
415 std::nullptr_t>::type = nullptr>
416 bool writeRegister8(const Reg reg, const uint8_t value, const bool stop = true);
417
418 template <typename Reg,
419 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
420 std::nullptr_t>::type = nullptr>
421 inline bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop = true)
422 {
423 return write_register16E(reg, value, stop, true);
424 }
425
426 template <typename Reg,
427 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
428 std::nullptr_t>::type = nullptr>
429 inline bool writeRegister16LE(const Reg reg, const uint16_t value, const bool stop = true)
430 {
431 return write_register16E(reg, value, stop, false);
432 }
433
434 template <typename Reg,
435 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
436 std::nullptr_t>::type = nullptr>
437 inline bool writeRegister32BE(const Reg reg, const uint32_t value, const bool stop = true)
438 {
439 return write_register32E(reg, value, stop, true);
440 }
441
442 template <typename Reg,
443 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
444 std::nullptr_t>::type = nullptr>
445 inline bool writeRegister32LE(const Reg reg, const uint32_t value, const bool stop = true)
446 {
447 return write_register32E(reg, value, stop, false);
448 }
449
450 // GPIO
451 bool pinModeRX(const gpio::Mode m);
452 bool writeDigitalRX(const bool high);
453 bool readDigitalRX(bool& high);
454 bool writeAnalogRX(const uint16_t v);
455 bool readAnalogRX(uint16_t& v);
456 bool readAnalogMilliVoltsRX(uint32_t& mv);
457 bool pulseInRX(uint32_t& duration, const int state, const uint32_t timeout_us = 1000000);
458
459 bool pinModeTX(const gpio::Mode m);
460 bool writeDigitalTX(const bool high);
461 bool readDigitalTX(bool& high);
462 bool writeAnalogTX(const uint16_t v);
463 bool readAnalogTX(uint16_t& v);
464 bool readAnalogMilliVoltsTX(uint32_t& mv);
465 bool pulseInTX(uint32_t& duration, const int state, const uint32_t timeout_us = 1000000);
467
468#if defined(DOXYGEN_PROCESS)
469 // There is a problem with the Doxygen output of templates containing std::enable_if,
470 // so we need a section for Doxygen output
474 m5::hal::error::error_t readWithTransaction(uint8_t* data, const size_t len);
476 template <typename Reg>
477 bool readRegister(const Reg reg, uint8_t* rbuf, const size_t len, const uint32_t delayMillis,
478 const bool stop = true);
480 template <typename Reg>
481 bool readRegister8(const Reg reg, uint8_t& result, const uint32_t delayMillis, const bool stop = true);
483 template <typename Reg>
484 bool readRegister16BE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true);
486 template <typename Reg>
487 bool readRegister16LE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true);
489 template <typename Reg>
490 bool readRegister32BE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true);
492 template <typename Reg>
493 bool readRegister32LE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true);
494
496 m5::hal::error::error_t writeWithTransaction(const uint8_t* data, const size_t len, const bool stop = true);
498 template <typename Reg>
499 m5::hal::error::error_t writeWithTransaction(const Reg reg, const uint8_t* data, const size_t len,
500 const bool stop = true);
502 template <typename Reg>
503 bool writeRegister(const Reg reg, const uint8_t* buf = nullptr, const size_t len = 0U, const bool stop = true);
505 template <typename Reg>
506 bool writeRegister8(const Reg reg, const uint8_t value, const bool stop = true);
508 template <typename Reg>
509 bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop = true);
511 template <typename Reg>
512 bool writeRegister16LE(const Reg reg, const uint16_t value, const bool stop = true);
514 template <typename Reg>
515 bool writeRegister32BE(const Reg reg, const uint32_t value, const bool stop = true);
517 template <typename Reg>
518 bool writeRegister32LE(const Reg reg, const uint32_t value, const bool stop = true);
520#endif
521
522protected:
523 // Proper implementation in derived classes is required
524 virtual const char* unit_device_name() const = 0;
525 virtual types::uid_t unit_identifier() const = 0;
526 virtual types::attr_t unit_attribute() const = 0;
527 inline virtual types::category_t unit_category() const
528 {
529 return types::category_t::None;
530 }
531 inline virtual bool in_periodic() const
532 {
533 return _periodic;
534 }
535
536 inline virtual std::shared_ptr<Adapter> ensure_adapter(const uint8_t /*ch*/)
537 {
538 return _adapter; // By default, offer my adapter for sharing
539 }
540
541 // Select valid channel if exists(PaHub etc...)
542 inline virtual m5::hal::error::error_t select_channel(const uint8_t)
543 {
544 return m5::hal::error::error_t::OK;
545 }
546
547 inline size_t stored_size() const
548 {
549 return _component_cfg.stored_size;
550 }
551
552 bool add_child(Component* c);
553
554 // I2C
555 bool changeAddress(const uint8_t addr); // Functions for dynamically addressable devices
556 template <typename Reg,
557 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
558 std::nullptr_t>::type = nullptr>
559 bool read_register16E(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop,
560 const bool endian);
561 template <typename Reg,
562 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
563 std::nullptr_t>::type = nullptr>
564 bool write_register16E(const Reg reg, const uint16_t value, const bool stop, const bool endian);
565 template <typename Reg,
566 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
567 std::nullptr_t>::type = nullptr>
568 bool read_register32E(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop,
569 const bool endian);
570 template <typename Reg,
571 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
572 std::nullptr_t>::type = nullptr>
573 bool write_register32E(const Reg reg, const uint32_t value, const bool stop, const bool endian);
574
575protected:
576 // For periodic measurement
577 types::elapsed_time_t _latest{}, _interval{};
578 bool _periodic{}; // During periodic measurement?
579 bool _updated{};
580
581private:
582 UnitUnified* _manager{};
583 std::shared_ptr<m5::unit::Adapter> _adapter{};
584
585 uint32_t _order{};
586 component_config_t _component_cfg{};
587 int16_t _channel{-1}; // valid [0...]
588 uint8_t _addr{};
589 bool _begun{};
590
591 // for chain
592 Component* _parent{};
593 Component* _next{};
594 Component* _prev{};
595 Component* _child{};
596
597 friend class UnitUnified;
598};
599
617template <class Derived, typename MD>
619public:
622
628 template <typename... Args>
629 inline bool startPeriodicMeasurement(Args&&... args)
630 {
631 // Prepare for future common initiation preprocessing needs
632 return static_cast<Derived*>(this)->start_periodic_measurement(std::forward<Args>(args)...);
633 }
640 template <typename... Args>
641 inline bool stopPeriodicMeasurement(Args&&... args)
642 {
643 // Prepare for future common stopping preprocessing needs
644 return static_cast<Derived*>(this)->stop_periodic_measurement(std::forward<Args>(args)...);
645 }
647
651 inline size_t available() const
652 {
653 return available_periodic_measurement_data();
654 }
656 inline bool empty() const
657 {
658 return empty_periodic_measurement_data();
659 }
661 inline bool full() const
662 {
663 return full_periodic_measurement_data();
664 }
666 inline MD oldest() const
667 {
668 return static_cast<const Derived*>(this)->oldest_periodic_data();
669 }
671 inline MD latest() const
672 {
673 return static_cast<const Derived*>(this)->latest_periodic_data();
674 }
676 inline void discard()
677 {
678 discard_periodic_measurement_data();
679 }
681 inline void flush()
682 {
683 flush_periodic_measurement_data();
684 }
686
687protected:
691 virtual size_t available_periodic_measurement_data() const = 0;
692 virtual bool empty_periodic_measurement_data() const = 0;
693 virtual bool full_periodic_measurement_data() const = 0;
694 virtual void discard_periodic_measurement_data() = 0;
695 virtual void flush_periodic_measurement_data() = 0;
697};
698
699} // namespace unit
700} // namespace m5
701
702// Helper for creating derived classes from Component
704#define M5_UNIT_COMPONENT_HPP_BUILDER(cls, reg) \
705public: \
706 constexpr static uint8_t DEFAULT_ADDRESS{(reg)}; \
707 static const types::uid_t uid; \
708 static const types::attr_t attr; \
709 static const char name[]; \
710 \
711 cls(const cls&) = delete; \
712 \
713 cls& operator=(const cls&) = delete; \
714 \
715 cls(cls&&) noexcept = default; \
716 \
717 cls& operator=(cls&&) noexcept = default; \
718 \
719protected: \
720 inline virtual const char* unit_device_name() const override \
721 { \
722 return name; \
723 } \
724 inline virtual types::uid_t unit_identifier() const override \
725 { \
726 return uid; \
727 } \
728 inline virtual types::attr_t unit_attribute() const override \
729 { \
730 return attr; \
731 }
732
733// Helper for creating derived class from PeriodicMeasurementAdapter
734#define M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER(cls, md) \
735protected: \
736 friend class PeriodicMeasurementAdapter<cls, md>; \
737 \
738 inline md oldest_periodic_data() const \
739 { \
740 return !_data->empty() ? _data->front().value() : md{}; \
741 } \
742 inline md latest_periodic_data() const \
743 { \
744 return !_data->empty() ? _data->back().value() : md{}; \
745 } \
746 inline virtual size_t available_periodic_measurement_data() const override \
747 { \
748 return _data->size(); \
749 } \
750 inline virtual bool empty_periodic_measurement_data() const override \
751 { \
752 return _data->empty(); \
753 } \
754 inline virtual bool full_periodic_measurement_data() const override \
755 { \
756 return _data->full(); \
757 } \
758 inline virtual void discard_periodic_measurement_data() override \
759 { \
760 _data->pop_front(); \
761 } \
762 inline virtual void flush_periodic_measurement_data() override \
763 { \
764 _data->clear(); \
765 }
766
768#endif
Adapters to treat M5HAL and any connection in the same way.
Adapter base class to treat M5HAL and TwoWire,GPIO,Serial,SPI... in the same way.
Type
Adapter type.
Definition adapter_base.hpp:28
Base class of unit component.
virtual void update(const bool force=false)
Update unit.
Definition M5UnitComponent.hpp:111
types::attr_t attribute() const
Gets the attributes.
Definition M5UnitComponent.hpp:130
bool writeRegister8(const Reg reg, const uint8_t value, const bool stop=true)
Write byte with transaction to register.
bool existsChild(const uint8_t ch) const
Is there an other unit connected to the specified channel?
Definition M5UnitComponent.cpp:39
bool readRegister8(const Reg reg, uint8_t &result, const uint32_t delayMillis, const bool stop=true)
Read byte with transaction from register.
bool readRegister16BE(const Reg reg, uint16_t &result, const uint32_t delayMillis, const bool stop=true)
Read word in big-endian order with transaction from register.
void component_config(const component_config_t &cfg)
Set the common configurations in each unit.
Definition M5UnitComponent.hpp:91
bool writeRegister(const Reg reg, const uint8_t *buf=nullptr, const size_t len=0U, const bool stop=true)
Write any data with transaction to register.
static const types::uid_t uid
Unique identifier.
Definition M5UnitComponent.hpp:58
bool selectChannel(const uint8_t ch=8)
Select valid channel if exists.
Definition M5UnitComponent.cpp:189
Component * parent()
Gets the parent unit.
Definition M5UnitComponent.hpp:263
bool writeRegister32BE(const Reg reg, const uint32_t value, const bool stop=true)
Write dword in big-endian order with transaction to register.
bool hasChildren() const
Are there other devices connected to me?
Definition M5UnitComponent.hpp:254
bool isRegistered() const
Is the unit registered with the manager?
Definition M5UnitComponent.hpp:150
virtual std::string debugInfo() const
Output information for debug.
Definition M5UnitComponent.cpp:404
static const char name[]
Device name string.
Definition M5UnitComponent.hpp:60
bool writeRegister32LE(const Reg reg, const uint32_t value, const bool stop=true)
Write dword in little-endian order with transaction to register.
bool inPeriodic() const
In periodic measurement?
Definition M5UnitComponent.hpp:197
bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop=true)
Write word in big-endian order with transaction to register.
Adapter * adapter() const
Gets the access adapter.
Definition M5UnitComponent.hpp:163
m5::hal::error::error_t writeWithTransaction(const Reg reg, const uint8_t *data, const size_t len, const bool stop=true)
Write any data with transaction to register.
bool hasParent() const
Has parent unit?
Definition M5UnitComponent.hpp:244
bool hasSiblings() const
Are there any other devices connected to the same parent unit besides yourself?
Definition M5UnitComponent.hpp:249
size_t childrenSize() const
Number of units connected to me.
Definition M5UnitComponent.cpp:28
types::uid_t identifier() const
Gets the identifier.
Definition M5UnitComponent.hpp:125
const char * deviceName() const
Gets the device name.
Definition M5UnitComponent.hpp:120
virtual bool assign(m5::hal::bus::Bus *bus)
Assign m5::hal::bus.
Definition M5UnitComponent.cpp:136
bool updated() const
Periodic measurement data updated?
Definition M5UnitComponent.hpp:202
types::elapsed_time_t updatedMillis() const
Time elapsed since start-up when the measurement data was updated in update()
Definition M5UnitComponent.hpp:210
static const types::attr_t attr
Attributes.
Definition M5UnitComponent.hpp:59
bool readRegister16LE(const Reg reg, uint16_t &result, const uint32_t delayMillis, const bool stop=true)
Read word in little-endian order with transaction from register.
bool readRegister32BE(const Reg reg, uint32_t &result, const uint32_t delayMillis, const bool stop=true)
Read dword in big-endian order with transaction from register.
Component * child(const uint8_t channel) const
Gets the device connected to the specified channel.
Definition M5UnitComponent.cpp:124
auto asAdapter(const Adapter::Type t) const -> const typename std::remove_cv< typename std::remove_pointer< T >::type >::type *
Gets the device name.
Definition M5UnitComponent.hpp:177
m5::hal::error::error_t readWithTransaction(uint8_t *data, const size_t len)
Read any data with transaction.
Definition M5UnitComponent.cpp:198
bool writeRegister16LE(const Reg reg, const uint16_t value, const bool stop=true)
Write word in little-endian order with transaction to register.
m5::hal::error::error_t writeWithTransaction(const uint8_t *data, const size_t len, const bool stop=true)
Write any data with transaction.
bool readRegister(const Reg reg, uint8_t *rbuf, const size_t len, const uint32_t delayMillis, const bool stop=true)
Read any data with transaction from register.
uint8_t address() const
Address used to I2C access the device.
Definition M5UnitComponent.hpp:155
virtual bool begin()
Begin unit.
Definition M5UnitComponent.hpp:103
int16_t channel() const
Gets the channel if connected to another unit.
Definition M5UnitComponent.hpp:145
types::elapsed_time_t interval() const
Gets the periodic measurement interval.
Definition M5UnitComponent.hpp:218
bool generalCall(const uint8_t *data, const size_t len)
General call for I2C.
auto asAdapter(const Adapter::Type t) -> typename std::remove_cv< typename std::remove_pointer< T >::type >::type *
Gets the access adapter.
Definition M5UnitComponent.hpp:169
bool add(Component &c, const int16_t channel)
Connect the unit to the specified channel.
Definition M5UnitComponent.cpp:67
component_config_t component_config() const
Gets the common configurations in each unit.
Definition M5UnitComponent.hpp:86
bool readRegister32LE(const Reg reg, uint32_t &result, const uint32_t delayMillis, const bool stop=true)
Read dword in little-endian order with transaction from register.
uint32_t order() const
Gets the registered order (== 0 means not yet)
Definition M5UnitComponent.hpp:140
types::category_t category() const
Gets the category.
Definition M5UnitComponent.hpp:135
Interface class for periodic measurement (CRTP)
Definition M5UnitComponent.hpp:618
MD oldest() const
Retrieve oldest stored data.
Definition M5UnitComponent.hpp:666
size_t available() const
Gets the number of stored data.
Definition M5UnitComponent.hpp:651
bool startPeriodicMeasurement(Args &&... args)
Start periodic measurement.
Definition M5UnitComponent.hpp:629
void discard()
Discard the oldest data accumulated.
Definition M5UnitComponent.hpp:676
MD latest() const
Retrieve latest stored data.
Definition M5UnitComponent.hpp:671
bool stopPeriodicMeasurement(Args &&... args)
Stop periodic measurement.
Definition M5UnitComponent.hpp:641
bool empty() const
Is empty stored data?
Definition M5UnitComponent.hpp:656
bool full() const
Is stored data full?
Definition M5UnitComponent.hpp:661
void flush()
Discard all data.
Definition M5UnitComponent.hpp:681
Top level namespace of M5Stack.
Definition test_helper.hpp:20
Unit-related namespace.
Component basic settings for begin.
Definition M5UnitComponent.hpp:44
uint32_t clock
Clock for communication (default as 100000)
Definition M5UnitComponent.hpp:46
uint32_t stored_size
Maximum number of periodic measurement data to be stored.
Definition M5UnitComponent.hpp:48
uint8_t max_children
Maximum number of units that can be connected (default as 0)
Definition M5UnitComponent.hpp:52
bool self_update
Does the user call Unit's update? (default as false)
Definition M5UnitComponent.hpp:50
Type and enumerator definitions.
unsigned long elapsed_time_t
Elapsed time unit (ms)
Definition types.hpp:42
uint32_t attr_t
Component attribute bits.
Definition types.hpp:41
uint32_t uid_t
Component unique identifier.
Definition types.hpp:40
category_t
Unit category (used for static class determination)
Definition types.hpp:35