Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Software::OWI< PIN > Class Template Reference

#include <OWI.h>

Inheritance diagram for Software::OWI< PIN >:
Inheritance graph
Collaboration diagram for Software::OWI< PIN >:
Collaboration graph

Public Types

enum  {
  SEARCH_ROM = 0xF0, READ_ROM = 0x33, MATCH_ROM = 0x55, SKIP_ROM = 0xCC,
  ALARM_SEARCH = 0xEC, LABEL_ROM = 0x15, MATCH_LABEL = 0x51
}
 
enum  { FIRST = -1, ERROR = -1, LAST = ROMBITS }
 

Public Member Functions

 OWI ()
 
virtual bool reset ()
 
virtual uint8_t read (uint8_t bits=CHARBITS)
 
virtual void write (uint8_t value, uint8_t bits=CHARBITS)
 
bool read (void *buf, size_t count)
 
void write (uint8_t cmd, const void *buf, size_t count)
 
virtual int8_t triplet (uint8_t &dir)
 
int8_t search_rom (uint8_t family, uint8_t *code, int8_t last=FIRST)
 
bool read_rom (uint8_t *code)
 
bool match_rom (uint8_t *code)
 
bool skip_rom ()
 
int8_t alarm_search (uint8_t *code, int8_t last=FIRST)
 
bool match_label (uint8_t label)
 

Static Public Member Functions

static uint8_t crc_update (uint8_t crc, uint8_t data)
 
static uint8_t crc (const void *buf, size_t count)
 
static uint8_t crc_P (const void *buf, size_t count)
 

Static Public Attributes

static const size_t ROM_MAX = 8
 
static const size_t ROMBITS = ROM_MAX * CHARBITS
 

Protected Member Functions

int8_t search (uint8_t *code, int8_t last=FIRST)
 

Protected Attributes

GPIO< PIN > m_pin
 

Static Protected Attributes

static const uint8_t RESET_RETRY_MAX = 4
 

Detailed Description

template<BOARD::pin_t PIN>
class Software::OWI< PIN >

Definition at line 31 of file OWI.h.

Member Enumeration Documentation

anonymous enum
inherited

Standard 1-Wire ROM Commands.

Enumerator
SEARCH_ROM 

Initiate device search.

READ_ROM 

Read device family code and serial number.

MATCH_ROM 

Select device with 64-bit rom code.

SKIP_ROM 

Broadcast or single device.

ALARM_SEARCH 

Initiate device alarm search.

LABEL_ROM 

Set short address (8-bit).

MATCH_LABEL 

Select device with 8-bit short address.

Definition at line 128 of file OWI.h.

anonymous enum
inherited

Search position and return values.

Enumerator
FIRST 

Start position of search.

ERROR 

Error during search.

LAST 

Last position, search completed.

Definition at line 190 of file OWI.h.

Constructor & Destructor Documentation

template<BOARD::pin_t PIN>
Software::OWI< PIN >::OWI ( )
inline

Construct one wire bus connected to the given template pin parameter.

Definition at line 37 of file OWI.h.

Member Function Documentation

int8_t OWI::alarm_search ( uint8_t *  code,
int8_t  last = FIRST 
)
inlineinherited

Search alarming device given the last position of discrepancy.

Parameters
[in]codedevice identity.
[in]lastposition of discrepancy (default FIRST).
Returns
position of difference or negative error code.

Definition at line 261 of file OWI.h.

static uint8_t OWI::crc ( const void *  buf,
size_t  count 
)
inlinestaticinherited

Optimized Dallas/Maxim iButton 8-bit Cyclic Redundancy Check calculation. Polynomial: x^8 + x^5 + x^4 + 1 (0x8C).

Parameters
[in]bufbuffer pointer.
[in]countnumber of bytes.
Returns
crc.

Definition at line 166 of file OWI.h.

static uint8_t OWI::crc_P ( const void *  buf,
size_t  count 
)
inlinestaticinherited

Optimized Dallas/Maxim iButton 8-bit Cyclic Redundancy Check calculation. Polynomial: x^8 + x^5 + x^4 + 1 (0x8C).

Parameters
[in]bufbuffer pointer (program memory).
[in]countnumber of bytes.
Returns
crc.

Definition at line 181 of file OWI.h.

static uint8_t OWI::crc_update ( uint8_t  crc,
uint8_t  data 
)
inlinestaticinherited

Optimized Dallas/Maxim iButton 8-bit Cyclic Redundancy Check calculation. Polynomial: x^8 + x^5 + x^4 + 1 (0x8C). See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27

Parameters
[in]crccyclic redundancy check sum.
[in]datato append.
Returns
crc.

Definition at line 146 of file OWI.h.

bool OWI::match_label ( uint8_t  label)
inlineinherited

Match device label. Address the device with the given label. Device specific function command should follow.

Parameters
[in]labeldevice short address.
Returns
true(1) if successful otherwise false(0).

Definition at line 274 of file OWI.h.

bool OWI::match_rom ( uint8_t *  code)
inlineinherited

Match device rom. Address the device with the rom code. Device specific function command should follow. May be used to verify rom code.

Parameters
[in]codedevice identity.
Returns
true(1) if successful otherwise false(0).

Definition at line 236 of file OWI.h.

bool OWI::read ( void *  buf,
size_t  count 
)
inlineinherited

Read given number of bytes from one wire bus (device) to given buffer. Calculates 8-bit Cyclic Redundancy Check sum and return result of check.

Parameters
[in]bufbuffer pointer.
[in]countnumber of bytes to read.
Returns
true(1) if check sum is correct otherwise false(0).

Definition at line 62 of file OWI.h.

template<BOARD::pin_t PIN>
virtual uint8_t Software::OWI< PIN >::read ( uint8_t  bits = CHARBITS)
inlinevirtual

Read the given number of bits from the one wire bus. Default number of bits is 8.

Parameters
[in]bitsto be read.
Returns
value read.

Implements OWI.

Definition at line 72 of file OWI.h.

bool OWI::read_rom ( uint8_t *  code)
inlineinherited

Read device rom. This can only be used when there is only one device on the bus.

Parameters
[in]codedevice identity.
Returns
true(1) if successful otherwise false(0).

Definition at line 222 of file OWI.h.

template<BOARD::pin_t PIN>
virtual bool Software::OWI< PIN >::reset ( )
inlinevirtual

Reset the one wire bus and check that at least one device is presence.

Returns
true(1) if successful otherwise false(0).

Implements OWI.

Definition at line 48 of file OWI.h.

int8_t OWI::search ( uint8_t *  code,
int8_t  last = FIRST 
)
inlineprotectedinherited

Search device rom given the last position of discrepancy and partial or full rom code.

Parameters
[in]codedevice identity rom.
[in]lastposition of discrepancy (default FIRST).
Returns
position of difference or negative error code.

Definition at line 357 of file OWI.h.

int8_t OWI::search_rom ( uint8_t  family,
uint8_t *  code,
int8_t  last = FIRST 
)
inlineinherited

Search device rom given the last position of discrepancy. Return position of difference or negative error code.

Parameters
[in]familycode.
[in]codedevice identity.
[in]lastposition of discrepancy (default FIRST).
Returns
position of difference or negative error code.

Definition at line 204 of file OWI.h.

bool OWI::skip_rom ( )
inlineinherited

Skip device rom for boardcast or single device access. Device specific function command should follow.

Returns
true(1) if successful otherwise false(0).

Definition at line 248 of file OWI.h.

virtual int8_t OWI::triplet ( uint8_t &  dir)
inlinevirtualinherited

Search (rom and alarm) support function. Reads 2-bits and writes given direction 1-bit value when discrepancy 0b00 read. Writes one(1) when 0b01 read, zero(0) on 0b10. Reading 0b11 is an error state.

Parameters
[in,out]dirbit to write when discrepancy read.
Returns
2-bits read and bit written.

Reimplemented in Hardware::OWI.

Definition at line 106 of file OWI.h.

void OWI::write ( uint8_t  cmd,
const void *  buf,
size_t  count 
)
inlineinherited

Write the given command and given number of bytes from buffer to the one wire bus (device).

Parameters
[in]cmdcommand to write.
[in]bufbuffer pointer.
[in]countnumber of bytes to write.

Definition at line 90 of file OWI.h.

template<BOARD::pin_t PIN>
virtual void Software::OWI< PIN >::write ( uint8_t  value,
uint8_t  bits = CHARBITS 
)
inlinevirtual

Write the given value to the one wire bus. The bits are written from LSB to MSB.

Parameters
[in]valueto write.
[in]bitsto be written.

Implements OWI.

Definition at line 98 of file OWI.h.

Member Data Documentation

template<BOARD::pin_t PIN>
GPIO<PIN> Software::OWI< PIN >::m_pin
protected

1-Wire bus pin.

Definition at line 123 of file OWI.h.

const uint8_t OWI::RESET_RETRY_MAX = 4
staticprotectedinherited

Maximum number of reset retries.

Definition at line 348 of file OWI.h.

const size_t OWI::ROM_MAX = 8
staticinherited

One Wire device identity ROM size in bytes.

Definition at line 32 of file OWI.h.

const size_t OWI::ROMBITS = ROM_MAX * CHARBITS
staticinherited

One Wire device identity ROM size in bits.

Definition at line 35 of file OWI.h.


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