_1wire_uart.h
Go to the documentation of this file.
#ifndef __utl_com_1wire_uart_h__
#define __utl_com_1wire_uart_h__
#include <utl/core/impl.h>
#include <utl/core/crtp.h>
#include <utl/com/_1wire.h>
namespace utl {
template <typename Impl_t>
class _1wire_uart_i : public _1wire_i<_1wire_uart_i<Impl_t>> {
_CRTP_IMPL(Impl_t);
friend _1wire_i <_1wire_uart_i<Impl_t>>;
public:
using type = _1wire_uart_i<Impl_t>;
using Speed = typename _1wire_i<type>::Speed;
protected:
_1wire_uart_i () = default;
~_1wire_uart_i () = default;
private:
byte_t UART_RW (byte_t byte) { return impl().UART_RW (byte); }
void UART_BR (uint32_t br) { impl().UART_BR (br); }
private:
enum BR {
BR_STD_RST =9600,
BR_OVR_RST =57600,
BR_STD =115200,
BR_OVR =921600
};
Speed _speed {Speed::STD};
Speed speed () const { return _speed; }
void speed (Speed s);
bool bit (bool b) {
if (b)
return (UART_RW (0xFF) < 0xFF) ? 0 : 1;
else {
UART_RW (0x00);
return 0;
}
}
bool _reset (Speed s);
};
template <typename Impl_t>
void _1wire_uart_i<Impl_t>::speed (Speed s) {
switch (_speed = s) {
case Speed::STD: UART_BR (BR_STD); break;
case Speed::OVDR: UART_BR (BR_OVR); break;
}
}
template <typename Impl_t>
bool _1wire_uart_i<Impl_t>::_reset (Speed s) {
// Select frame to send
uint8_t w = ((_speed = s) == Speed::STD) ? 0xF0 : 0xF8;
// Select baudrate
impl().UART_BR ((_speed == Speed::STD) ? BR_STD_RST : BR_OVR_RST);
// Send frame and check the result
return (impl().UART_RW (w) < w);
}
template <>
class _1wire_uart_i<virtual_tag> : public _1wire_i<virtual_tag> {
public:
using type = _1wire_uart_i<virtual_tag>;
using Speed = typename _1wire_i<virtual_tag>::Speed;
protected:
_1wire_uart_i () = default;
~_1wire_uart_i () = default;
private:
virtual byte_t UART_RW (byte_t byte) =0;
virtual void UART_BR (uint32_t br) =0;
private:
enum BR {
BR_STD_RST =9600,
BR_OVR_RST =57600,
BR_STD =115200,
BR_OVR =921600
};
Speed _speed {Speed::STD};
Speed speed () const { return _speed; }
void speed (Speed s);
bool bit (bool b) {
if (b)
return (UART_RW (0xFF) < 0xFF) ? 0 : 1;
else {
UART_RW (0x00);
return 0;
}
}
bool _reset (Speed s);
};
void _1wire_uart_i<virtual_tag>::speed (Speed s) {
switch (_speed = s) {
case Speed::STD: UART_BR (BR_STD); break;
case Speed::OVDR: UART_BR (BR_OVR); break;
}
}
bool _1wire_uart_i<virtual_tag>::_reset (Speed s) {
// Select frame to send
uint8_t w = ((_speed = s) == Speed::STD) ? 0xF0 : 0xF8;
// Select baudrate
UART_BR ((_speed == Speed::STD) ? BR_STD_RST : BR_OVR_RST);
// Send frame and check the result
return (UART_RW (w) < w);
}
} // namespace utl
#endif /* __utl_com_1wire_uart_h__ */
utl::_1wire_uart_i::_CRTP_IMPL
_CRTP_IMPL(Impl_t)
utl::_1wire_uart_i< virtual_tag >::bit
bool bit(bool b)
Send a 1-Wire write bit and read the response.
Definition: _1wire_uart.h:277
utl::_1wire_uart_i::Speed
typename _1wire_i< type >::Speed Speed
Bring bus speed.
Definition: _1wire_uart.h:57
utl::_1wire_uart_i::UART_BR
void UART_BR(uint32_t br)
Implementers&#39;s (driver) baudrate function.
Definition: _1wire_uart.h:96
utl::_1wire_uart_i::BR_STD
Definition: _1wire_uart.h:106
crtp.h
utl::_1wire_i::Speed
Speed
1-wire bus speed
Definition: _1wire.h:64
utl::_1wire_uart_i< virtual_tag >::speed
Speed speed() const
Get the 1-wire bus speed.
Definition: _1wire_uart.h:252
utl::_1wire_uart_i< virtual_tag >
A virtual base class interface implementation. Using the private virtual interface we provide the int...
Definition: _1wire_uart.h:198
utl::_1wire_uart_i::BR_OVR_RST
Definition: _1wire_uart.h:105
utl::_1wire_uart_i::_speed
Speed _speed
Definition: _1wire_uart.h:109
_1wire.h
An 1-wire interface implementation.
utl::_1wire_uart_i::BR_OVR
Definition: _1wire_uart.h:107
utl::_1wire_i< virtual_tag >
A virtual base class implementation.
Definition: _1wire.h:260
utl::_1wire_uart_i::bit
bool bit(bool b)
Send a 1-Wire write bit and read the response.
Definition: _1wire_uart.h:136
utl
STL&#39;s core language concepts.
Definition: _1wire.h:30
utl::_1wire_uart_i::~_1wire_uart_i
~_1wire_uart_i()=default
utl::_1wire_uart_i::BR
BR
1-wire UART baudrates
Definition: _1wire_uart.h:103
utl::_1wire_uart_i< virtual_tag >::BR
BR
1-wire UART baudrates
Definition: _1wire_uart.h:244
utl::_1wire_uart_i::_reset
bool _reset(Speed s)
Generate a 1-wire reset Reset \ / \ X X X / RS: | | | | | | | | | | | bit: ST 0 1 2 3 4 5 6 7 SP < ...
Definition: _1wire_uart.h:181
utl::_1wire_uart_i::UART_RW
byte_t UART_RW(byte_t byte)
Implementers&#39;s (driver) read-write function. We expect the following USART configuration: ...
Definition: _1wire_uart.h:89
utl::_1wire_uart_i::BR_STD_RST
Definition: _1wire_uart.h:104
utl::_1wire_i
Template base class for 1-wire communication interface using CRTP.
Definition: _1wire.h:57
utl::byte_t
uint8_t byte_t
8 bits wide
Definition: types.h:31
utl::virtual_tag
virtual support tag type
Definition: crtp.h:40
utl::_1wire_uart_i::_1wire_uart_i
_1wire_uart_i()=default
Allow constructor from derived only.
utl::_1wire_uart_i::speed
Speed speed() const
Get the 1-wire bus speed.
Definition: _1wire_uart.h:111
utl::_1wire_uart_i
1-wire UART interface template class using CRTP Using the private virtual interface we provide the in...
Definition: _1wire_uart.h:52
impl.h
Implementation detail main forward header.
utl::_1wire_i< virtual_tag >::Speed
Speed
1-wire bus speed
Definition: _1wire.h:265