21 #ifndef __utl_com_1wire_h__ 22 #define __utl_com_1wire_h__ 41 namespace _1wire_i_det {
43 template <
typename _T>
void _match (_T& obj,
_1wire_id_t&
id,
typename _T::Speed s);
45 template <
typename _T>
void _skip (_T& obj,
typename _T::Speed s);
47 template <
typename _T>
_1wire_id_t _first (_T& obj,
typename _T::Speed s,
bool alarm);
48 template <
typename _T>
_1wire_id_t _next (_T& obj,
typename _T::Speed s,
bool alarm);
56 template <
typename impl_t>
87 bool bit (
bool b) {
return impl().bit(b); }
240 template <
typename _I>
242 for (
size_t nn {n} ; nn ; --nn)
243 *in++ = tx_data (*out++, s);
247 template <
typename _I>
249 for (
size_t nn {n} ; nn ; --nn)
250 *in++ = tx_data (0xFF, s);
286 virtual bool bit () =0;
287 virtual bool bit (
bool) =0;
441 for (
size_t nn {n} ; nn ; --nn)
447 for (
size_t nn {n} ; nn ; --nn)
455 namespace _1wire_i_det {
466 template <
typename _T>
471 if (obj.speed () != s)
473 for (uint8_t i =8; i>0 ; --i) {
475 ret |= (obj.bit (out & 0x01)) ? 0x80 : 0x00;
492 template <
typename _T>
494 _touch (obj, (s == _T::Speed::STD) ? _T::CMD_MATCH : _T::CMD_OVDR_MATCH, s);
495 for (uint8_t& b :
id)
504 template <
typename _T>
506 _touch (obj, _T::CMD_MATCH, _T::Speed::STD);
507 for (uint8_t& b :
id)
508 _touch (obj, b, _T::Speed::OVDR);
516 template <
typename _T>
517 void _skip (_T& obj,
typename _T::Speed s) {
518 _touch (obj, (s == _T::Speed::STD) ? _T::CMD_SKIP : _T::CMD_SKIP, s);
525 template <
typename _T>
527 _touch (obj, _T::CMD_OVDR_SKIP, _T::Speed::STD);
539 template <
typename _T>
542 return _next (obj, s, alarm);
555 template <
typename _T>
568 if (!obj.reset (s)) {
573 if (alarm) obj.tx_data (_T::CMD_ALARM_SEARCH, s);
574 else obj.tx_data (_T::CMD_SEARCH_ROM, s);
577 if (obj.speed () != s)
581 for (i =0 ; i<64 ; ++i) {
601 obj.dec_.bit (i, (b = 1));
606 b = obj.dec_.bit (i);
613 else if (bxx == 0x01) {
619 else if (bxx == 0x02) {
644 #if defined _utl_have_concepts 648 template <
typename T>
649 concept
bool _1Wire_i = requires (T t,
typename T::Speed s, _1wire_id_t
id) {
651 requires not_<std::is_copy_constructible<T>::value>::value;
652 requires not_<std::is_copy_assignable<T>::value>::value;
657 {t.reset(s)} -> bool;
664 {t.first(s)} -> _1wire_id_t;
665 {t.next(s)} -> _1wire_id_t;
668 namespace _1wire_i_det {
671 template <
class _Tp>
using try_reset_t = decltype (declval<_Tp>().reset (declval<typename _Tp::Speed>()));
672 template <
class _Tp>
using try_rx1_t = decltype (declval<_Tp>().rx_data (declval<typename _Tp::Speed>()));
673 template <
class _Tp>
using try_tx1_t = decltype (declval<_Tp>().tx_data (declval<byte_t>(), declval<typename _Tp::Speed>()));
675 template <
class _Tp>
using try_match_t = decltype (declval<_Tp>().match (declval<_1wire_id_t&>(), declval<typename _Tp::Speed>()));
676 template <
class _Tp>
using try_match_n_ovdr_t = decltype (declval<_Tp>().match_n_ovdr (declval<_1wire_id_t&>()));
677 template <
class _Tp>
using try_skip_t = decltype (declval<_Tp>().skip (declval<typename _Tp::Speed>()));
679 template <
class _Tp>
using try_first_t = decltype (declval<_Tp>().first (declval<typename _Tp::Speed>()));
680 template <
class _Tp>
using try_next_t = decltype (declval<_Tp>().next (declval<typename _Tp::Speed>()));
683 template <
typename _Tp,
typename =
void>
687 template <
typename _Tp>
_1wire_id_t first(Speed s=Speed::STD, bool alarm=false)
'first' operation, to search on the 1-Wire for the first device. This is performed by setting dec_...
bool bit(bool b)
Write a bit to the 1-Wire bus, return response/write status and provide the recovery time...
void void_t
void_t type alias
void match_n_ovdr(_1wire_id_t &id)
decltype(declval< _Tp >().match_n_ovdr(declval< _1wire_id_t & >())) try_match_n_ovdr_t
Primary template to catch any non 1-wire interface types.
void match(_1wire_id_t &id, Speed s=Speed::STD)
static int compare(const _1wire_id_t &lhs, const _1wire_id_t &rhs) noexcept
Full compare two dev_ids.
decltype(declval< _Tp >().match(declval< _1wire_id_t & >(), declval< typename _Tp::Speed >())) try_match_t
void match(_1wire_id_t &id, Speed s=Speed::STD)
void _match_n_ovdr(_T &obj, _1wire_id_t &id)
byte_t tx_data(byte_t out, Speed s=Speed::STD)
byte_t rx_data(Speed s=Speed::STD)
_1wire_id_t _first(_T &obj, typename _T::Speed s, bool alarm)
'first' operation, to search on the 1-Wire for the first device. This is performed by setting dec_...
bool reset(Speed s=Speed::STD)
Generate a 1-wire reset.
_1wire_id_t _next(_T &obj, typename _T::Speed s, bool alarm)
'next' operation, to search on the 1-Wire for the next device. This search is usually performed after...
_1wire_id_t next(Speed s=Speed::STD, bool alarm=false)
'next' operation, to search on the 1-Wire for the next device. This search is usually performed after...
A virtual base class implementation.
bool reset(Speed s=Speed::STD)
Generate a 1-wire reset.
_1wire_id_t first(Speed s=Speed::STD, bool alarm=false)
'first' operation, to search on the 1-Wire for the first device. This is performed by setting dec_...
STL's core language concepts.
decltype(declval< _Tp >().skip(declval< typename _Tp::Speed >())) try_skip_t
void match_n_ovdr(_1wire_id_t &id)
byte_t rx_data(Speed s=Speed::STD)
decltype(declval< _Tp >().tx_data(declval< byte_t >(), declval< typename _Tp::Speed >())) try_tx1_t
void _skip_n_ovdr(_T &obj)
_1wire_i type
Export type as identity meta-function.
void skip(Speed s=Speed::STD)
decltype(declval< _Tp >().skip_n_ovdr()) try_skip_n_ovdr_t
Speed speed() const
Get the 1-wire bus speed.
decltype(declval< _Tp >().first(declval< typename _Tp::Speed >())) try_first_t
byte_t tx_data(byte_t out, Speed s=Speed::STD)
_1wire_i & operator=(const _1wire_i &)=delete
void skip(Speed s=Speed::STD)
static constexpr const _1wire_id_t & nullDev()
Return nullDev reference.
~_1wire_i()=default
Allow destructor from derived only.
_1wire_id_t next(Speed s=Speed::STD, bool alarm=false)
'next' operation, to search on the 1-Wire for the next device. This search is usually performed after...
decltype(declval< _Tp >().rx_data(declval< typename _Tp::Speed >())) try_rx1_t
Template base class for 1-wire communication interface using CRTP.
uint8_t byte_t
8 bits wide
decltype(declval< _Tp >().reset(declval< typename _Tp::Speed >())) try_reset_t
void _skip(_T &obj, typename _T::Speed s)
decltype(declval< _Tp >().next(declval< typename _Tp::Speed >())) try_next_t
Implementation detail main forward header.
void _match(_T &obj, _1wire_id_t &id, typename _T::Speed s)
_1wire_i()=default
Allow constructor from derived only.
constexpr bool bit(uint8_t bit) const noexcept
byte_t _touch(_T &obj, byte_t out, typename _T::Speed s)
Write a byte to 1-Wire bus and read the response.