utl::_1wire_i< impl_t > Class Template Reference

Template base class for 1-wire communication interface using CRTP. More...

`#include <_1wire.h>`

Inheritance diagram for utl::_1wire_i< impl_t >:

## Public Types

enum | Speed { Speed::STD =0, Speed::OVDR }
| 1-wire bus speed More...
using | type = _1wire_i
| Export type as identity meta-function. More...

## Public Member Functions

User functionality provided by the interface
bool | reset (Speed s=Speed::STD)
| Generate a 1-wire reset. More...
byte_t | tx_data (byte_t out, Speed s=Speed::STD)
size_t | tx_data (const byte_t *out, byte_t *in, size_t n, Speed s=Speed::STD)
byte_t | rx_data (Speed s=Speed::STD)
size_t | rx_data (byte_t *in, size_t n, Speed s=Speed::STD)
void | match (_1wire_id_t &id, Speed s=Speed::STD)
void | match_n_ovdr (_1wire_id_t &id)
void | skip (Speed s=Speed::STD)
void | skip_n_ovdr ()
_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_, pos_ and cur_ to zero and then doing the search. More...
_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 'first' operation or another 'next' operation. Based on maxim-ic application note 187. More...

## Protected Member Functions

Object lifetime
| _1wire_i ()=default
| Allow constructor from derived only. More...
| ~_1wire_i ()=default
| Allow destructor from derived only. More...
| _1wire_i (const _1wire_i &)=delete
| No copies. More...
_1wire_i & | operator= (const _1wire_i &)=delete

## Private Member Functions

| _CRTP_IMPL (impl_t)
Implementation requirements

Note
  In order for the implementation to have the following as private members too it need to declare this class as friend

Speed | speed () const
| Get the 1-wire bus speed. More...
void | speed (Speed s)
bool | bit (bool b)
| Write a bit to the 1-Wire bus, return response/write status and provide the recovery time. More...
bool | _reset (Speed s)

## Private Attributes

_1wire_id_t | dec_ {_1wire_id_t::nullDev()}
_1wire_id_t | pos_ {_1wire_id_t::nullDev()}
_1wire_id_t | cur_ {_1wire_id_t::nullDev()}

## Friends api to provide functionality to all class specializations

enum | Command { CMD_READ_ROM = 0x33, CMD_OVDR_SKIP = 0x3C, CMD_MATCH = 0x55, CMD_OVDR_MATCH = 0x69, CMD_SKIP = 0xCC, CMD_ALARM_SEARCH = 0xEC, CMD_SEARCH_ROM = 0xF0 }
template<typename _T >
byte_t | _1wire_i_det::_touch (_T &, byte_t, typename _T::Speed)
template<typename _T >
void | _1wire_i_det::_match (_T &obj, _1wire_id_t &id, typename _T::Speed s)
template<typename _T >
void | _1wire_i_det::_match_n_ovdr (_T &obj, _1wire_id_t &id)
template<typename _T >
void | _1wire_i_det::_skip (_T &obj, typename _T::Speed s)
template<typename _T >
void | _1wire_i_det::_skip_n_ovdr (_T &obj)
template<typename _T >
_1wire_id_t | _1wire_i_det::_first (_T &, typename _T::Speed, bool)
template<typename _T >
_1wire_id_t | _1wire_i_det::_next (_T &, typename _T::Speed, bool)

## Detailed Description

### template<typename impl_t>
class utl::_1wire_i< impl_t >

Template base class for 1-wire communication interface using CRTP.

Parameters

  impl_t | The CRTP type (the derived/implementation class typename).

Definition at line 57 of file _1wire.h.

## Member Typedef Documentation

## type

template<typename impl_t>

using utl::_1wire_i< impl_t >::type = _1wire_i

Export type as identity meta-function.

Definition at line 61 of file _1wire.h.

## Member Enumeration Documentation

## Command

template<typename impl_t>

enum utl::_1wire_i::Command

private

Enumerator
CMD_READ_ROM |
CMD_OVDR_SKIP |
CMD_MATCH |
CMD_OVDR_MATCH |
CMD_SKIP |
CMD_ALARM_SEARCH |
CMD_SEARCH_ROM |

Definition at line 97 of file _1wire.h.

## Speed

template<typename impl_t>

enum utl::_1wire_i::Speed

strong

1-wire bus speed

Enumerator
STD |
OVDR |

Definition at line 64 of file _1wire.h.

## Constructor & Destructor Documentation

## _1wire_i() [1/2]

template<typename impl_t>

utl::_1wire_i< impl_t >::_1wire_i | ( |  | ) |

protecteddefault

Allow constructor from derived only.

## ~_1wire_i()

template<typename impl_t>

utl::_1wire_i< impl_t >::~_1wire_i | ( |  | ) |

protecteddefault

Allow destructor from derived only.

## _1wire_i() [2/2]

template<typename impl_t>

utl::_1wire_i< impl_t >::_1wire_i | ( | const _1wire_i< impl_t > & |  | ) |

protecteddelete

No copies.

## Member Function Documentation

## _CRTP_IMPL()

template<typename impl_t>

utl::_1wire_i< impl_t >::_CRTP_IMPL | ( | impl_t |  | ) |

private

## _reset()

template<typename impl_t>

bool utl::_1wire_i< impl_t >::_reset | ( | Speed | s | ) |

inlineprivate

Generate a 1-wire reset and return the operation status

Definition at line 89 of file _1wire.h.

## bit()

template<typename impl_t>

bool utl::_1wire_i< impl_t >::bit | ( | bool | b | ) |

inlineprivate

Write a bit to the 1-Wire bus, return response/write status and provide the recovery time.

Definition at line 88 of file _1wire.h.

## first()

template<typename impl_t>

_1wire_id_t utl::_1wire_i< impl_t >::first | ( | Speed | s = `Speed::STD`,
|  | bool | alarm = `false`
| ) |  |

inline

'first' operation, to search on the 1-Wire for the first device. This is performed by setting dec_, pos_ and cur_ to zero and then doing the search.

Parameters

  s | The bus speed
  alarm | If set, search for alarm devices

Returns
  ID The romID
  - nullDev Indicate no [more] device[s]

Definition at line 207 of file _1wire.h.

## match()

template<typename impl_t>

void utl::_1wire_i< impl_t >::match | ( | _1wire_id_t & | id,
|  | Speed | s = `Speed::STD`
| ) |  |

inline

Send match rom command

Parameters

  id | The ID to select on the bus
  s | The speed to use for the command

Definition at line 173 of file _1wire.h.

## match_n_ovdr()

template<typename impl_t>

void utl::_1wire_i< impl_t >::match_n_ovdr | ( | _1wire_id_t & | id | ) |

inline

Match and overdrive sequence

Parameters

  obj | The object from which we call private members
  id | The ID to select on the bus

Definition at line 181 of file _1wire.h.

## next()

template<typename impl_t>

_1wire_id_t utl::_1wire_i< impl_t >::next | ( | Speed | s = `Speed::STD`,
|  | bool | alarm = `false`
| ) |  |

inline

'next' operation, to search on the 1-Wire for the next device. This search is usually performed after a 'first' operation or another 'next' operation. Based on maxim-ic application note 187.

Parameters

  s | The bus speed
  alarm | If set, search for alarm devices

Returns
  ID The romID
  - nullDev Indicate no [more] device[s]

Definition at line 220 of file _1wire.h.

## operator=()

template<typename impl_t>

_1wire_i& utl::_1wire_i< impl_t >::operator= | ( | const _1wire_i< impl_t > & |  | ) |

protecteddelete

## reset()

template<typename impl_t>

bool utl::_1wire_i< impl_t >::reset | ( | Speed | s = `Speed::STD` | ) |

inline

Generate a 1-wire reset.

Parameters

  s | Bus speed

Returns
  The status of the operation
  - 0 Fail
  - 1 Success

Definition at line 128 of file _1wire.h.

## rx_data() [1/2]

template<typename impl_t>

byte_t utl::_1wire_i< impl_t >::rx_data | ( | Speed | s = `Speed::STD` | ) |

inline

Receive a byte from 1-Wire bus while transmitting 0xFF

Parameters

  s | Bus speed to use

Returns
  The byte received.

Definition at line 156 of file _1wire.h.

## rx_data() [2/2]

template<typename _I >

size_t utl::_1wire_i< _I >::rx_data | ( | byte_t * | in,
|  | size_t | n,
|  | Speed | s = `Speed::STD`
| ) |  |

Receive a number of bytes from 1-wire bus while transmitting 0xFFs

Parameters

  in | Pointer to data to store
  n | Number of bytes
  s | Speed to use

Returns
  The number of transmitted bytes

Definition at line 248 of file _1wire.h.

## skip()

template<typename impl_t>

void utl::_1wire_i< impl_t >::skip | ( | Speed | s = `Speed::STD` | ) |

inline

Send skip command to the bus

Parameters

  id | The ID to select on the bus

Definition at line 188 of file _1wire.h.

## skip_n_ovdr()

template<typename impl_t>

void utl::_1wire_i< impl_t >::skip_n_ovdr | ( |  | ) |

inline

Send the Skip and Overdrive sequence

Definition at line 194 of file _1wire.h.

## speed() [1/2]

template<typename impl_t>

Speed utl::_1wire_i< impl_t >::speed | ( |  | ) | const

inlineprivate

Get the 1-wire bus speed.

Definition at line 85 of file _1wire.h.

## speed() [2/2]

template<typename impl_t>

void utl::_1wire_i< impl_t >::speed | ( | Speed | s | ) |

inlineprivate

Set the 1-wire bus speed

Definition at line 86 of file _1wire.h.

## tx_data() [1/2]

template<typename impl_t>

byte_t utl::_1wire_i< impl_t >::tx_data | ( | byte_t | out,
|  | Speed | s = `Speed::STD`
| ) |  |

inline

Transmit a byte to 1-Wire bus and read the response

Parameters

  out | The byte to write
  s | Bus speed to use

Returns
  The byte received.

Definition at line 138 of file _1wire.h.

## tx_data() [2/2]

template<typename _I >

size_t utl::_1wire_i< _I >::tx_data | ( | const byte_t * | out,
|  | byte_t * | in,
|  | size_t | n,
|  | Speed | s = `Speed::STD`
| ) |  |

Transmit a number of bytes to 1-wire bus and read the response

Parameters

  out | Pointer to data to transmit
  in | Pointer to data to store
  n | Number of bytes
  s | Speed to use

Returns
  The number of transmitted bytes

Definition at line 241 of file _1wire.h.

## Friends And Related Function Documentation

## _1wire_i_det::_first

template<typename impl_t>
template<typename _T >

_1wire_id_t _1wire_i_det::_first | ( | _T & | ,
|  | typename _T::Speed | ,
|  | bool |
| ) |  |

friend

## _1wire_i_det::_match

template<typename impl_t>
template<typename _T >

void _1wire_i_det::_match | ( | _T & | obj,
|  | _1wire_id_t & | id,
|  | typename _T::Speed | s
| ) |  |

friend

## _1wire_i_det::_match_n_ovdr

template<typename impl_t>
template<typename _T >

void _1wire_i_det::_match_n_ovdr | ( | _T & | obj,
|  | _1wire_id_t & | id
| ) |  |

friend

## _1wire_i_det::_next

template<typename impl_t>
template<typename _T >

_1wire_id_t _1wire_i_det::_next | ( | _T & | ,
|  | typename _T::Speed | ,
|  | bool |
| ) |  |

friend

## _1wire_i_det::_skip

template<typename impl_t>
template<typename _T >

void _1wire_i_det::_skip | ( | _T & | obj,
|  | typename _T::Speed | s
| ) |  |

friend

## _1wire_i_det::_skip_n_ovdr

template<typename impl_t>
template<typename _T >

void _1wire_i_det::_skip_n_ovdr | ( | _T & | obj | ) |

friend

## _1wire_i_det::_touch

template<typename impl_t>
template<typename _T >

byte_t _1wire_i_det::_touch | ( | _T & | ,
|  | byte_t | ,
|  | typename _T::Speed |
| ) |  |

friend

## Member Data Documentation

## cur_

template<typename impl_t>

_1wire_id_t utl::_1wire_i< impl_t >::cur_ {_1wire_id_t::nullDev()}

private

Definition at line 237 of file _1wire.h.

## dec_

template<typename impl_t>

_1wire_id_t utl::_1wire_i< impl_t >::dec_ {_1wire_id_t::nullDev()}

private

Hold the algorithm's select bit when a discrepancy is detected. We use this variable to navigate to the ROM tree as we store the path we take each time (0-1). Each bit represent a bit position in the ROM ID.

Definition at line 226 of file _1wire.h.

## pos_

template<typename impl_t>

_1wire_id_t utl::_1wire_i< impl_t >::pos_ {_1wire_id_t::nullDev()}

private

Hold the discrepancy position. We use this variable to navigate to the ROM tree as we store the crossroads(1) we encounter. Each bit represent a bit position in the ROM ID.

Definition at line 232 of file _1wire.h.

The documentation for this class was generated from the following file:

- include/utl/com/_1wire.h