Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
Diff: Links/SelectRom.hpp
- Revision:
- 8:211d1b8f730c
- Parent:
- 5:3523abdda8ed
- Parent:
- 7:471901a04573
diff -r 3523abdda8ed -r 211d1b8f730c Links/SelectRom.hpp --- a/Links/SelectRom.hpp Tue Jul 24 08:33:31 2018 +0000 +++ b/Links/SelectRom.hpp Wed Apr 03 12:33:10 2019 +0000 @@ -43,6 +43,7 @@ class OneWireMaster; +/// Selects a 1-Wire device on the bus for communication. typedef Function<error_code(OneWireMaster &)> SelectRom; typedef Function<error_code(OneWireMaster &, const RomId & romId)> SelectRomExt; @@ -52,41 +53,47 @@ typedef SelectRom::argument_type argument_type; typedef SelectRom::result_type result_type; - explicit SelectMatchRom(const RomId & romId = RomId()) : romId_(romId) {} + explicit SelectMatchRom(RomId::const_span romId) { setRomId(romId); } - const RomId & romId() const { return romId_; } - void setRomId(const RomId & romId) { romId_ = romId; } + RomId::const_span romId() const { return romId_; } + + void setRomId(RomId::const_span romId) { copy(romId, make_span(romId_)); } MaximInterface_EXPORT error_code operator()(OneWireMaster & master) const; private: - RomId romId_; + RomId::array romId_; }; -/// Selector for a multidrop 1-Wire bus where slaves support the Resume ROM command. +/// @brief +/// Selector for a multidrop 1-Wire bus where slaves support the Resume ROM +/// command. class SelectMatchRomWithResume { public: typedef SelectRom::argument_type argument_type; typedef SelectRom::result_type result_type; struct SharedData { - RomId lastRom; - - SharedData() : lastRom() {} + SharedData() : lastRomId() {} + RomId::array lastRomId; }; - explicit SelectMatchRomWithResume(SharedData & data, - const RomId & romId = RomId()) - : romId_(romId), data(&data) {} + SelectMatchRomWithResume(SharedData & data, RomId::const_span romId) + : data(&data) { + setRomId(romId); + } - const RomId & romId() const { return romId_; } - void setRomId(const RomId & romId) { romId_ = romId; } + void setSharedData(SharedData & data) { this->data = &data; } + + RomId::const_span romId() const { return romId_; } + + void setRomId(RomId::const_span romId) { copy(romId, make_span(romId_)); } MaximInterface_EXPORT error_code operator()(OneWireMaster & master) const; private: - RomId romId_; SharedData * data; + RomId::array romId_; }; } // namespace MaximInterface