|
@@ -27,11 +27,11 @@ |
|
|
|
|
|
|
|
|
namespace utl {
|
|
|
namespace utl {
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
* \ingroup Communication
|
|
|
|
|
|
* \brief Abstract base class for i2c bus
|
|
|
|
|
|
*/
|
|
|
|
|
|
//!@{
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
* \ingroup Communication
|
|
|
|
|
|
* \brief Abstract base class for i2c bus
|
|
|
|
|
|
*/
|
|
|
|
|
|
//!@{
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
|
* \brief
|
|
|
* \brief
|
|
@@ -70,12 +70,13 @@ namespace utl { |
|
|
* it also need to declare this class as friend
|
|
|
* it also need to declare this class as friend
|
|
|
*/
|
|
|
*/
|
|
|
//!@{
|
|
|
//!@{
|
|
|
//! uint32_t _frequency () const; < clock frequency of the bus [Hz]
|
|
|
|
|
|
//! void _frequency (uint32_t); < set clock frequency of the bus [Hz]
|
|
|
|
|
|
//! void _start(); < Send start functionality
|
|
|
|
|
|
//! void _stop(); < Send stop functionality
|
|
|
|
|
|
//! byte_t _read (bool ack, Sequence seq); < Receive a byte from the i2c bus.
|
|
|
|
|
|
//! bool _write (byte_t byte, Sequence seq);< Transmit a byte to the i2c bus.
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
uint32_t _clock () const { return impl()._clock (); } //!< clock frequency of the bus [Hz]
|
|
|
|
|
|
void _clock (uint32_t c) { impl()._clock (c); } //!< set clock frequency of the bus [Hz]
|
|
|
|
|
|
void _start() { impl()._start (); } //!< Send start functionality
|
|
|
|
|
|
void _stop() { impl()._stop (); } //!< Send stop functionality
|
|
|
|
|
|
byte_t _rx_data (bool ack, Sequence seq) { return impl()._rx_data (ack, seq); }
|
|
|
|
|
|
bool _tx_data (byte_t byte, Sequence seq) { return impl()._tx_data (byte, seq); }
|
|
|
//!@}
|
|
|
//!@}
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
@@ -83,8 +84,8 @@ namespace utl { |
|
|
*/
|
|
|
*/
|
|
|
//!@{
|
|
|
//!@{
|
|
|
public:
|
|
|
public:
|
|
|
uint32_t frequency () const { return impl()._frequency (); } //!< \return clock frequency of the bus
|
|
|
|
|
|
void frequency (uint32_t f) { impl()._frequency (f); } //!< \brief set clock frequency of the bus
|
|
|
|
|
|
|
|
|
uint32_t clock () const { return _clock (); } //!< \return clock frequency of the bus
|
|
|
|
|
|
void clock (uint32_t f) { _clock (f); } //!< \brief set clock frequency of the bus
|
|
|
//!@}
|
|
|
//!@}
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
@@ -92,8 +93,8 @@ namespace utl { |
|
|
*/
|
|
|
*/
|
|
|
//!@{
|
|
|
//!@{
|
|
|
public:
|
|
|
public:
|
|
|
void start() { impl()._start (); } //!< Send start functionality
|
|
|
|
|
|
void stop () { impl()._stop (); } //!< Send stop functionality
|
|
|
|
|
|
|
|
|
void start() { _start (); } //!< Send start functionality
|
|
|
|
|
|
void stop () { _stop (); } //!< Send stop functionality
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
|
* \brief
|
|
|
* \brief
|
|
@@ -107,8 +108,8 @@ namespace utl { |
|
|
* \arg Sequence::BYTEnACK Receive the byte and send the ack bit
|
|
|
* \arg Sequence::BYTEnACK Receive the byte and send the ack bit
|
|
|
* \return The byte received.
|
|
|
* \return The byte received.
|
|
|
*/
|
|
|
*/
|
|
|
byte_t read (bool ack, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return impl()._read (ack, seq);
|
|
|
|
|
|
|
|
|
byte_t rx_data (bool ack, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _rx_data (ack, seq);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
@@ -123,8 +124,8 @@ namespace utl { |
|
|
* \arg false Slave didn't ACK
|
|
|
* \arg false Slave didn't ACK
|
|
|
* \arg true Slave did ACK
|
|
|
* \arg true Slave did ACK
|
|
|
*/
|
|
|
*/
|
|
|
bool write (byte_t byte, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return impl()._write (byte, seq);
|
|
|
|
|
|
|
|
|
bool tx_data (byte_t byte, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _tx_data (byte, seq);
|
|
|
}
|
|
|
}
|
|
|
//!@}
|
|
|
//!@}
|
|
|
|
|
|
|
|
@@ -164,20 +165,20 @@ namespace utl { |
|
|
*/
|
|
|
*/
|
|
|
//!@{
|
|
|
//!@{
|
|
|
private:
|
|
|
private:
|
|
|
virtual uint32_t _frequency () const = 0; //!< \return clock frequency of the bus [Hz]
|
|
|
|
|
|
virtual void _frequency (uint32_t) = 0; //!< \brief set clock frequency of the bus [Hz]
|
|
|
|
|
|
virtual void _start() = 0; //!< Send start functionality
|
|
|
|
|
|
virtual void _stop() = 0; //!< Send stop functionality
|
|
|
|
|
|
virtual byte_t _read (bool ack, Sequence seq) = 0; //!< Receive a byte from the i2c bus.
|
|
|
|
|
|
virtual bool _write (byte_t byte, Sequence seq) = 0; //!< Transmit a byte to the i2c bus.
|
|
|
|
|
|
|
|
|
virtual uint32_t _clock () const = 0; //!< \return clock frequency of the bus [Hz]
|
|
|
|
|
|
virtual void _clock (uint32_t) = 0; //!< \brief set clock frequency of the bus [Hz]
|
|
|
|
|
|
virtual void _start() = 0; //!< Send start functionality
|
|
|
|
|
|
virtual void _stop() = 0; //!< Send stop functionality
|
|
|
|
|
|
virtual byte_t _rx_data (bool ack, Sequence seq) = 0; //!< Receive a byte from the i2c bus.
|
|
|
|
|
|
virtual bool _tx_data (byte_t byte, Sequence seq) = 0; //!< Transmit a byte to the i2c bus.
|
|
|
//!@}
|
|
|
//!@}
|
|
|
/*!
|
|
|
/*!
|
|
|
* \name Get/Set functions
|
|
|
* \name Get/Set functions
|
|
|
*/
|
|
|
*/
|
|
|
//!@{
|
|
|
//!@{
|
|
|
public:
|
|
|
public:
|
|
|
uint32_t frequency () const { return _frequency(); } //!< \return clock frequency of the bus [Hz]
|
|
|
|
|
|
void frequency (uint32_t f) { _frequency(f); } //!< \brief set clock frequency of the bus [Hz]
|
|
|
|
|
|
|
|
|
uint32_t clock () const { return _clock(); } //!< \return clock frequency of the bus [Hz]
|
|
|
|
|
|
void clock (uint32_t c) { _clock(c); } //!< \brief set clock frequency of the bus [Hz]
|
|
|
//!@}
|
|
|
//!@}
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
@@ -199,8 +200,8 @@ namespace utl { |
|
|
* \arg Sequence::BYTEnACK Receive the byte and send the ack bit
|
|
|
* \arg Sequence::BYTEnACK Receive the byte and send the ack bit
|
|
|
* \return The byte received.
|
|
|
* \return The byte received.
|
|
|
*/
|
|
|
*/
|
|
|
byte_t read (bool ack, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _read (ack, seq);
|
|
|
|
|
|
|
|
|
byte_t rx_data (bool ack, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _rx_data (ack, seq);
|
|
|
}
|
|
|
}
|
|
|
/*!
|
|
|
/*!
|
|
|
* \brief
|
|
|
* \brief
|
|
@@ -214,8 +215,8 @@ namespace utl { |
|
|
* \arg false Slave didn't ACK
|
|
|
* \arg false Slave didn't ACK
|
|
|
* \arg true Slave did ACK
|
|
|
* \arg true Slave did ACK
|
|
|
*/
|
|
|
*/
|
|
|
bool write (byte_t byte, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _write (byte, seq);
|
|
|
|
|
|
|
|
|
bool tx_data (byte_t byte, Sequence seq =Sequence::BYTEnACK) {
|
|
|
|
|
|
return _tx_data (byte, seq);
|
|
|
}
|
|
|
}
|
|
|
//!@}
|
|
|
//!@}
|
|
|
|
|
|
|
|
@@ -231,25 +232,25 @@ namespace utl { |
|
|
requires not_<std::is_copy_constructible<T>::value>::value;
|
|
|
requires not_<std::is_copy_constructible<T>::value>::value;
|
|
|
requires not_<std::is_copy_assignable<T>::value>::value;
|
|
|
requires not_<std::is_copy_assignable<T>::value>::value;
|
|
|
// Methods
|
|
|
// Methods
|
|
|
{ct.frequency()} -> uint32_t;
|
|
|
|
|
|
{t.frequency(0)} -> void;
|
|
|
|
|
|
{t.start()} -> void;
|
|
|
|
|
|
{t.stop()} -> void;
|
|
|
|
|
|
{t.read (1, s)} -> byte_t;
|
|
|
|
|
|
{t.write(0, s)} -> bool;
|
|
|
|
|
|
|
|
|
{ct.clock()} -> uint32_t;
|
|
|
|
|
|
{t.clock(0)} -> void;
|
|
|
|
|
|
{t.start()} -> void;
|
|
|
|
|
|
{t.stop()} -> void;
|
|
|
|
|
|
{t.rx_data (1, s)} -> byte_t;
|
|
|
|
|
|
{t.tx_data (0, s)} -> bool;
|
|
|
};
|
|
|
};
|
|
|
#else
|
|
|
#else
|
|
|
namespace i2c_i_cnpt {
|
|
|
|
|
|
|
|
|
namespace i2c_i_details {
|
|
|
using std::declval;
|
|
|
using std::declval;
|
|
|
|
|
|
|
|
|
template <class _Tp> using try_cfreq_t = decltype (declval<const _Tp>().frequency());
|
|
|
|
|
|
template <class _Tp> using try_freq_t = decltype (declval<_Tp>().frequency(declval<uint32_t>()));
|
|
|
|
|
|
|
|
|
template <class _Tp> using try_cclk_t = decltype (declval<const _Tp>().clock());
|
|
|
|
|
|
template <class _Tp> using try_clk_t = decltype (declval<_Tp>().clock(declval<uint32_t>()));
|
|
|
template <class _Tp> using try_start_t = decltype (declval<_Tp>().start());
|
|
|
template <class _Tp> using try_start_t = decltype (declval<_Tp>().start());
|
|
|
template <class _Tp> using try_stop_t = decltype (declval<_Tp>().stop());
|
|
|
template <class _Tp> using try_stop_t = decltype (declval<_Tp>().stop());
|
|
|
template <class _Tp> using try_read_t
|
|
|
|
|
|
= decltype (declval<_Tp>().read (declval<bool>(), declval<typename _Tp::Sequence>()));
|
|
|
|
|
|
template <class _Tp> using try_write_t
|
|
|
|
|
|
= decltype (declval<_Tp>().write (declval<byte_t>(), declval<typename _Tp::Sequence>()));
|
|
|
|
|
|
|
|
|
template <class _Tp> using try_rx_data_t
|
|
|
|
|
|
= decltype (declval<_Tp>().rx_data (declval<bool>(), declval<typename _Tp::Sequence>()));
|
|
|
|
|
|
template <class _Tp> using try_tx_data_t
|
|
|
|
|
|
= decltype (declval<_Tp>().tx_data (declval<byte_t>(), declval<typename _Tp::Sequence>()));
|
|
|
|
|
|
|
|
|
//! Primary template to catch any non I2C interface types
|
|
|
//! Primary template to catch any non I2C interface types
|
|
|
template <typename _Tp, typename =void>
|
|
|
template <typename _Tp, typename =void>
|
|
@@ -260,13 +261,13 @@ namespace utl { |
|
|
struct is_i2c_ <_Tp,
|
|
|
struct is_i2c_ <_Tp,
|
|
|
void_t <
|
|
|
void_t <
|
|
|
typename _Tp::Sequence,
|
|
|
typename _Tp::Sequence,
|
|
|
use_if_same_t <uint32_t,try_cfreq_t <_Tp>>,
|
|
|
|
|
|
use_if_same_t <void, try_freq_t <_Tp>>,
|
|
|
|
|
|
|
|
|
use_if_same_t <uint32_t,try_cclk_t <_Tp>>,
|
|
|
|
|
|
use_if_same_t <void, try_clk_t <_Tp>>,
|
|
|
use_if_same_t <void, try_start_t <_Tp>>,
|
|
|
use_if_same_t <void, try_start_t <_Tp>>,
|
|
|
use_if_same_t <void, try_stop_t <_Tp>>,
|
|
|
use_if_same_t <void, try_stop_t <_Tp>>,
|
|
|
use_if_same_t <byte_t, try_read_t <_Tp>>,
|
|
|
|
|
|
use_if_same_t <bool, try_write_t <_Tp>>
|
|
|
|
|
|
> //!^ SFINAE may apply inside if_same_t<> also
|
|
|
|
|
|
|
|
|
use_if_same_t <byte_t, try_rx_data_t <_Tp>>,
|
|
|
|
|
|
use_if_same_t <bool, try_tx_data_t <_Tp>>
|
|
|
|
|
|
>
|
|
|
> : true_ { };
|
|
|
> : true_ { };
|
|
|
}
|
|
|
}
|
|
|
/*!
|
|
|
/*!
|
|
@@ -275,10 +276,10 @@ namespace utl { |
|
|
* \return True if _Tp is a i2c interface
|
|
|
* \return True if _Tp is a i2c interface
|
|
|
*/
|
|
|
*/
|
|
|
template <typename _Tp>
|
|
|
template <typename _Tp>
|
|
|
constexpr bool i2c_c = i2c_i_cnpt::is_i2c_<_Tp>::value;
|
|
|
|
|
|
|
|
|
constexpr bool i2c_c = i2c_i_details::is_i2c_<_Tp>::value;
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
//!@}
|
|
|
|
|
|
|
|
|
//!@}
|
|
|
|
|
|
|
|
|
} // namespace utl
|
|
|
} // namespace utl
|
|
|
|
|
|
|
|
|