M5UnitUnified 0.2.0 git rev:9e1ffe1
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;
24
25namespace m5 {
26namespace unit {
27
28class UnitUnified;
29class Adapter;
30
35class Component {
36public:
43 uint32_t clock{100000};
45 uint32_t stored_size{1};
47 bool self_update{false};
49 uint8_t max_children{0};
50 };
51
55 static const types::uid_t uid;
56 static const types::attr_t attr;
57 static const char name[];
59
63 explicit Component(const uint8_t addr = 0x00); // I2C address
64
65 Component(const Component&) = delete;
66
67 Component(Component&&) noexcept = default;
69
73 Component& operator=(const Component&) = delete;
74
75 Component& operator=(Component&&) noexcept = default;
77
78 virtual ~Component() = default;
79
82
84 {
85 return _component_cfg;
86 }
88 inline void component_config(const component_config_t& cfg)
89 {
90 _component_cfg = cfg;
91 }
93
96
100 virtual bool begin()
101 {
102 return true;
103 }
108 virtual void update(const bool force = false)
109 {
110 (void)force;
111 }
113
116
117 inline const char* deviceName() const
118 {
119 return unit_device_name();
120 }
123 {
124 return unit_identifier();
125 }
128 {
129 return unit_attribute();
130 }
133 {
134 return unit_category();
135 }
137 inline uint32_t order() const
138 {
139 return _order;
140 }
142 inline int16_t channel() const
143 {
144 return _channel;
145 }
147 inline bool isRegistered() const
148 {
149 return _manager != nullptr;
150 }
152 inline uint8_t address() const
153 {
154 return _addr;
155 }
160 inline Adapter* adapter() const
161 {
162 return _adapter.get();
163 }
165 template <class T>
166 inline auto asAdapter(const Adapter::Type t) ->
167 typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
168 {
169 using U = typename std::remove_cv<typename std::remove_pointer<T>::type>::type;
170 static_assert(std::is_base_of<Adapter, U>::value, "T must be derived from Adapter");
171 return (_adapter->type() == t) ? static_cast<U*>(_adapter.get()) : nullptr;
172 }
173 template <class T>
174 inline auto asAdapter(const Adapter::Type t) const -> const
175 typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
176 {
177 using U = typename std::remove_cv<typename std::remove_pointer<T>::type>::type;
178 static_assert(std::is_base_of<Adapter, U>::value, "T must be derived from Adapter");
179 return (_adapter->type() == t) ? static_cast<const U*>(_adapter.get()) : nullptr;
180 }
182
185 bool canAccessI2C() const;
186 bool canAccessGPIO() const;
187 bool canAccessUART() const;
189
192
193 inline bool inPeriodic() const
194 {
195 return in_periodic();
196 }
198 inline bool updated() const
199 {
200 return _updated;
201 }
207 {
208 return _latest;
209 }
215 {
216 return _interval;
217 }
219
222
223 virtual bool assign(m5::hal::bus::Bus* bus);
225 virtual bool assign(TwoWire& wire);
227 virtual bool assign(const int8_t rx_pin, const int8_t tx_pin);
229 virtual bool assign(HardwareSerial& serial);
231
235
236 inline bool hasParent() const
237 {
238 return _parent != nullptr;
239 }
241 inline bool hasSiblings() const
242 {
243 return (_prev != nullptr) || (_next != nullptr);
244 }
246 inline bool hasChildren() const
247 {
248 return _child;
249 }
251 size_t childrenSize() const;
253 bool existsChild(const uint8_t ch) const;
256 {
257 return _parent;
258 }
259#if 0
261 inline const Component* parent() const
262 {
263 return _parent;
264 }
265#endif
267 Component* child(const uint8_t chhanle) const;
269 bool add(Component& c, const int16_t channel);
271 bool selectChannel(const uint8_t ch = 8);
273
275 template <typename T>
276 class iterator {
277 public:
278 using iterator_category = std::forward_iterator_tag;
279 using difference_type = std::ptrdiff_t;
280 using value_type = T;
281 using pointer = T*;
282 using reference = T&;
283
284 explicit iterator(Component* c = nullptr) : _ptr(c)
285 {
286 }
287
288 reference operator*() const
289 {
290 return *_ptr;
291 }
292 pointer operator->() const
293 {
294 return _ptr;
295 }
296 iterator& operator++()
297 {
298 _ptr = _ptr ? _ptr->_next : nullptr;
299 return *this;
300 }
301 iterator operator++(int)
302 {
303 auto tmp = *this;
304 ++(*this);
305 return tmp;
306 }
307 friend bool operator==(const iterator& a, const iterator& b)
308 {
309 return a._ptr == b._ptr;
310 }
311 friend bool operator!=(const iterator& a, const iterator& b)
312 {
313 return a._ptr != b._ptr;
314 }
315
316 private:
317 Component* _ptr;
318 };
319
320 using child_iterator = iterator<Component>;
321 using const_child_iterator = iterator<const Component>;
322 inline child_iterator childBegin() noexcept
323 {
324 return child_iterator(_child);
325 }
326 inline child_iterator childEnd() noexcept
327 {
328 return child_iterator();
329 }
330 inline const_child_iterator childBegin() const noexcept
331 {
332 return const_child_iterator(_child);
333 }
334 inline const_child_iterator childEnd() const noexcept
335 {
336 return const_child_iterator();
337 }
339
341 bool generalCall(const uint8_t* data, const size_t len);
342
344 virtual std::string debugInfo() const;
345
346 // I2C R/W
348 m5::hal::error::error_t readWithTransaction(uint8_t* data, const size_t len);
349
350 template <typename Reg,
351 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
352 std::nullptr_t>::type = nullptr>
353 bool readRegister(const Reg reg, uint8_t* rbuf, const size_t len, const uint32_t delayMillis,
354 const bool stop = true);
355 template <typename Reg,
356 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
357 std::nullptr_t>::type = nullptr>
358 bool readRegister8(const Reg reg, uint8_t& result, const uint32_t delayMillis, const bool stop = true);
359
360 template <typename Reg,
361 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
362 std::nullptr_t>::type = nullptr>
363 inline bool readRegister16BE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true)
364 {
365 return read_register16E(reg, result, delayMillis, stop, true);
366 }
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 readRegister16LE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true)
372 {
373 return read_register16E(reg, result, delayMillis, stop, false);
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 readRegister32BE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true)
380 {
381 return read_register32E(reg, result, delayMillis, stop, true);
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 readRegister32LE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true)
388 {
389 return read_register32E(reg, result, delayMillis, stop, false);
390 }
391
392 m5::hal::error::error_t writeWithTransaction(const uint8_t* data, const size_t len, const uint32_t exparam = 1);
393
394 template <typename Reg,
395 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
396 std::nullptr_t>::type = nullptr>
397 m5::hal::error::error_t writeWithTransaction(const Reg reg, const uint8_t* data, const size_t len,
398 const bool stop = true);
399
400 template <typename Reg,
401 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
402 std::nullptr_t>::type = nullptr>
403 bool writeRegister(const Reg reg, const uint8_t* buf = nullptr, const size_t len = 0U, const bool stop = true);
404
405 template <typename Reg,
406 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
407 std::nullptr_t>::type = nullptr>
408 bool writeRegister8(const Reg reg, const uint8_t value, const bool stop = true);
409
410 template <typename Reg,
411 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
412 std::nullptr_t>::type = nullptr>
413 inline bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop = true)
414 {
415 return write_register16E(reg, value, stop, true);
416 }
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 writeRegister16LE(const Reg reg, const uint16_t value, const bool stop = true)
422 {
423 return write_register16E(reg, value, stop, false);
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 writeRegister32BE(const Reg reg, const uint32_t value, const bool stop = true)
430 {
431 return write_register32E(reg, value, stop, true);
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 writeRegister32LE(const Reg reg, const uint32_t value, const bool stop = true)
438 {
439 return write_register32E(reg, value, stop, false);
440 }
441
442 // GPIO
443 bool pinModeRX(const gpio::Mode m);
444 bool writeDigitalRX(const bool high);
445 bool readDigitalRX(bool& high);
446 bool writeAnalogRX(const uint16_t v);
447 bool readAnalogRX(uint16_t& v);
448 bool pulseInRX(uint32_t& duration, const int state, const uint32_t timeout_us = 1000000);
449
450 bool pinModeTX(const gpio::Mode m);
451 bool writeDigitalTX(const bool high);
452 bool readDigitalTX(bool& high);
453 bool writeAnalogTX(const uint16_t v);
454 bool readAnalogTX(uint16_t& v);
455 bool pulseInTX(uint32_t& duration, const int state, const uint32_t timeout_us = 1000000);
457
458#if defined(DOXYGEN_PROCESS)
459 // There is a problem with the Doxygen output of templates containing std::enable_if,
460 // so we need a section for Dxygen output
464 m5::hal::error::error_t readWithTransaction(uint8_t* data, const size_t len);
466 template <typename Reg>
467 bool readRegister(const Reg reg, uint8_t* rbuf, const size_t len, const uint32_t delayMillis,
468 const bool stop = true);
470 template <typename Reg>
471 bool readRegister8(const Reg reg, uint8_t& result, const uint32_t delayMillis, const bool stop = true);
473 template <typename Reg>
474 bool readRegister16BE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true);
476 template <typename Reg>
477 bool readRegister16LE(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop = true);
479 template <typename Reg>
480 bool readRegister32BE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true);
482 template <typename Reg>
483 bool readRegister32LE(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop = true);
484
486 m5::hal::error::error_t writeWithTransaction(const uint8_t* data, const size_t len, const bool stop = true);
488 template <typename Reg>
489 m5::hal::error::error_t writeWithTransaction(const Reg reg, const uint8_t* data, const size_t len,
490 const bool stop = true);
492 template <typename Reg>
493 bool writeRegister(const Reg reg, const uint8_t* buf = nullptr, const size_t len = 0U, const bool stop = true);
495 template <typename Reg>
496 bool writeRegister8(const Reg reg, const uint8_t value, const bool stop = true);
498 template <typename Reg>
499 bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop = true);
501 template <typename Reg>
502 bool writeRegister16LE(const Reg reg, const uint16_t value, const bool stop = true);
504 template <typename Reg>
505 bool writeRegister32BE(const Reg reg, const uint32_t value, const bool stop = true);
507 template <typename Reg>
508 bool writeRegister32LE(const Reg reg, const uint32_t value, const bool stop = true);
510#endif
511
512protected:
513 // Proper implementation in derived classes is required
514 virtual const char* unit_device_name() const = 0;
515 virtual types::uid_t unit_identifier() const = 0;
516 virtual types::attr_t unit_attribute() const = 0;
517 inline virtual types::category_t unit_category() const
518 {
519 return types::category_t::None;
520 }
521 inline virtual bool in_periodic() const
522 {
523 return _periodic;
524 }
525
526 inline virtual std::shared_ptr<Adapter> ensure_adapter(const uint8_t /*ch*/)
527 {
528 return _adapter; // By default, offer my adapter for sharing
529 }
530
531 // Select valid channel if exists(PaHub etc...)
532 inline virtual m5::hal::error::error_t select_channel(const uint8_t)
533 {
534 return m5::hal::error::error_t::OK;
535 }
536
537 inline size_t stored_size() const
538 {
539 return _component_cfg.stored_size;
540 }
541
542 bool add_child(Component* c);
543
544 // I2C
545 bool changeAddress(const uint8_t addr); // Functions for dynamically addressable devices
546 template <typename Reg,
547 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
548 std::nullptr_t>::type = nullptr>
549 bool read_register16E(const Reg reg, uint16_t& result, const uint32_t delayMillis, const bool stop,
550 const bool endian);
551 template <typename Reg,
552 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
553 std::nullptr_t>::type = nullptr>
554 bool write_register16E(const Reg reg, const uint16_t value, const bool stop, const bool endifan);
555 template <typename Reg,
556 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
557 std::nullptr_t>::type = nullptr>
558 bool read_register32E(const Reg reg, uint32_t& result, const uint32_t delayMillis, const bool stop,
559 const bool endian);
560 template <typename Reg,
561 typename std::enable_if<std::is_integral<Reg>::value && std::is_unsigned<Reg>::value && sizeof(Reg) <= 2,
562 std::nullptr_t>::type = nullptr>
563 bool write_register32E(const Reg reg, const uint32_t value, const bool stop, const bool endifan);
564
565protected:
566 // For periodic measurement
567 types::elapsed_time_t _latest{}, _interval{};
568 bool _periodic{}; // During periodic measurement?
569 bool _updated{};
570
571private:
572 UnitUnified* _manager{};
573 std::shared_ptr<m5::unit::Adapter> _adapter{};
574
575 uint32_t _order{};
576 component_config_t _component_cfg{};
577 int16_t _channel{-1}; // valid [0...]
578 uint8_t _addr{};
579 bool _begun{};
580
581 // for chain
582 Component* _parent{};
583 Component* _next{};
584 Component* _prev{};
585 Component* _child{};
586
587 friend class UnitUnified;
588};
589
607template <class Derived, typename MD>
609public:
612
618 template <typename... Args>
619 inline bool startPeriodicMeasurement(Args&&... args)
620 {
621 // Prepare for future common initiation preprocessing needs
622 return static_cast<Derived*>(this)->start_periodic_measurement(std::forward<Args>(args)...);
623 }
630 template <typename... Args>
631 inline bool stopPeriodicMeasurement(Args&&... args)
632 {
633 // Prepare for future common stopping preprocessing needs
634 return static_cast<Derived*>(this)->stop_periodic_measurement(std::forward<Args>(args)...);
635 }
637
641 inline size_t available() const
642 {
643 return available_periodic_measurement_data();
644 }
646 inline bool empty() const
647 {
648 return empty_periodic_measurement_data();
649 }
651 inline bool full() const
652 {
653 return full_periodic_measurement_data();
654 }
656 inline MD oldest() const
657 {
658 return static_cast<const Derived*>(this)->oldest_periodic_data();
659 }
661 inline MD latest() const
662 {
663 return static_cast<const Derived*>(this)->latest_periodic_data();
664 }
666 inline void discard()
667 {
668 discard_periodic_measurement_data();
669 }
671 inline void flush()
672 {
673 flush_periodic_measurement_data();
674 }
676
677protected:
681 virtual size_t available_periodic_measurement_data() const = 0;
682 virtual bool empty_periodic_measurement_data() const = 0;
683 virtual bool full_periodic_measurement_data() const = 0;
684 virtual void discard_periodic_measurement_data() = 0;
685 virtual void flush_periodic_measurement_data() = 0;
687};
688
689} // namespace unit
690} // namespace m5
691
692// Helper for creating derived classes from Component
694#define M5_UNIT_COMPONENT_HPP_BUILDER(cls, reg) \
695public: \
696 constexpr static uint8_t DEFAULT_ADDRESS{(reg)}; \
697 static const types::uid_t uid; \
698 static const types::attr_t attr; \
699 static const char name[]; \
700 \
701 cls(const cls&) = delete; \
702 \
703 cls& operator=(const cls&) = delete; \
704 \
705 cls(cls&&) noexcept = default; \
706 \
707 cls& operator=(cls&&) noexcept = default; \
708 \
709protected: \
710 inline virtual const char* unit_device_name() const override \
711 { \
712 return name; \
713 } \
714 inline virtual types::uid_t unit_identifier() const override \
715 { \
716 return uid; \
717 } \
718 inline virtual types::attr_t unit_attribute() const override \
719 { \
720 return attr; \
721 }
722
723// Helper for creating derived class from PeriodicMeasurementAdapter
724#define M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER(cls, md) \
725protected: \
726 friend class PeriodicMeasurementAdapter<cls, md>; \
727 \
728 inline md oldest_periodic_data() const \
729 { \
730 return !_data->empty() ? _data->front().value() : md{}; \
731 } \
732 inline md latest_periodic_data() const \
733 { \
734 return !_data->empty() ? _data->back().value() : md{}; \
735 } \
736 inline virtual size_t available_periodic_measurement_data() const override \
737 { \
738 return _data->size(); \
739 } \
740 inline virtual bool empty_periodic_measurement_data() const override \
741 { \
742 return _data->empty(); \
743 } \
744 inline virtual bool full_periodic_measurement_data() const override \
745 { \
746 return _data->full(); \
747 } \
748 inline virtual void discard_periodic_measurement_data() override \
749 { \
750 _data->pop_front(); \
751 } \
752 inline virtual void flush_periodic_measurement_data() override \
753 { \
754 _data->clear(); \
755 }
756
758#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.
Base class of unit component.
virtual void update(const bool force=false)
Update unit.
Definition M5UnitComponent.hpp:108
types::attr_t attribute() const
Gets the attributes.
Definition M5UnitComponent.hpp:127
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:88
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:55
bool selectChannel(const uint8_t ch=8)
Select valid channel if exists.
Definition M5UnitComponent.cpp:157
Component * parent()
Gets the parent unit.
Definition M5UnitComponent.hpp:255
component_config_t component_config()
Gets the common configurations in each unit.
Definition M5UnitComponent.hpp:83
bool writeRegister32BE(const Reg reg, const uint32_t value, const bool stop=true)
Write dword in big-endian order with transaction from register.
bool hasChildren() const
Are there other devices connected to me?
Definition M5UnitComponent.hpp:246
bool isRegistered() const
Is the unit registered with the manager?
Definition M5UnitComponent.hpp:147
virtual std::string debugInfo() const
Output information for debug.
Definition M5UnitComponent.cpp:362
static const char name[]
Device name string.
Definition M5UnitComponent.hpp:57
bool writeRegister32LE(const Reg reg, const uint32_t value, const bool stop=true)
Write dword in little-endian order with transaction from register.
bool inPeriodic() const
In periodic measurement?
Definition M5UnitComponent.hpp:193
bool writeRegister16BE(const Reg reg, const uint16_t value, const bool stop=true)
Write word in big-endian order with transaction from register.
Component * child(const uint8_t chhanle) const
Gets the device connected to the specified channel.
Definition M5UnitComponent.cpp:113
Adapter * adapter() const
Gets the access adapter.
Definition M5UnitComponent.hpp:160
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:236
bool hasSiblings() const
Are there any other devices connected to the same parent unit besides yourself?
Definition M5UnitComponent.hpp:241
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:122
const char * deviceName() const
Gets the device name.
Definition M5UnitComponent.hpp:117
virtual bool assign(m5::hal::bus::Bus *bus)
Assgin m5::hal::bus.
Definition M5UnitComponent.cpp:125
bool updated() const
Periodic measurement data updated?
Definition M5UnitComponent.hpp:198
types::elapsed_time_t updatedMillis() const
Time elapsed since start-up when the measurement data was updated in update()
Definition M5UnitComponent.hpp:206
static const types::attr_t attr
Attributes.
Definition M5UnitComponent.hpp:56
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.
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:174
m5::hal::error::error_t readWithTransaction(uint8_t *data, const size_t len)
Read any data with transaction.
Definition M5UnitComponent.cpp:166
bool writeRegister16LE(const Reg reg, const uint16_t value, const bool stop=true)
Write word in little-endian order with transaction from 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:152
virtual bool begin()
Begin unit.
Definition M5UnitComponent.hpp:100
int16_t channel() const
Gets the channel if connected to another unit.
Definition M5UnitComponent.hpp:142
types::elapsed_time_t interval() const
Gets the periodic measurement interval.
Definition M5UnitComponent.hpp:214
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:166
bool add(Component &c, const int16_t channel)
Connect the unit to the specified channel.
Definition M5UnitComponent.cpp:62
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:137
types::category_t category() const
Gets the category.
Definition M5UnitComponent.hpp:132
Interface class for periodic measurement (CRTP)
Definition M5UnitComponent.hpp:608
MD oldest() const
Retrieve oldest stored data.
Definition M5UnitComponent.hpp:656
size_t available() const
Gets the number of stored data.
Definition M5UnitComponent.hpp:641
bool startPeriodicMeasurement(Args &&... args)
Start periodic measurement.
Definition M5UnitComponent.hpp:619
void discard()
Discard the oldest data accumulated.
Definition M5UnitComponent.hpp:666
MD latest() const
Retrieve latest stored data.
Definition M5UnitComponent.hpp:661
bool stopPeriodicMeasurement(Args &&... args)
Stop periodic measurement.
Definition M5UnitComponent.hpp:631
bool empty() const
Is empty stored data?
Definition M5UnitComponent.hpp:646
bool full() const
Is stored data full?
Definition M5UnitComponent.hpp:651
void flush()
Discard all data.
Definition M5UnitComponent.hpp:671
Top level namespace of M5stack.
Definition test_helper.hpp:18
Unit-related namespace.
Component basic settings for begin.
Definition M5UnitComponent.hpp:41
uint32_t clock
Clock for communication (default as 100000)
Definition M5UnitComponent.hpp:43
uint32_t stored_size
Maximum number of periodic measurement data to be stored.
Definition M5UnitComponent.hpp:45
uint8_t max_children
Maximum number of units that can be connected (default as 0)
Definition M5UnitComponent.hpp:49
bool self_update
Does the user call Unit's update? (default as false)
Definition M5UnitComponent.hpp:47
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