Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Hardware::OWI Class Reference

#include <OWI.h>

Inheritance diagram for Hardware::OWI:
Inheritance graph
Collaboration diagram for Hardware::OWI:
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 (TWI &twi, uint8_t subaddr=0)
 
virtual bool reset ()
 
virtual uint8_t read (uint8_t bits=CHARBITS)
 
virtual void write (uint8_t value, uint8_t bits=CHARBITS)
 
virtual int8_t triplet (uint8_t &dir)
 
bool device_reset ()
 
bool device_configuration (bool apu=true, bool spu=false, bool iws=false)
 
bool channel_select (uint8_t chan)
 
bool read (void *buf, size_t count)
 
void write (uint8_t cmd, const void *buf, size_t count)
 
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

DS2482 m_bridge
 

Static Protected Attributes

static const uint8_t RESET_RETRY_MAX = 4
 

Detailed Description

Definition at line 30 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

Hardware::OWI::OWI ( TWI &  twi,
uint8_t  subaddr = 0 
)
inline

Construct one wire bus manager for DS2482.

Parameters
[in]twibus manager.
[in]subaddrsub-address for device.

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.

bool Hardware::OWI::channel_select ( uint8_t  chan)
inline

Select given channel (DS2482-800). Return true if successful otherwise false.

Parameters
[in]chanchannel number (0..7).
Returns
bool.

Definition at line 142 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 Hardware::OWI::device_configuration ( bool  apu = true,
bool  spu = false,
bool  iws = false 
)
inline

Configure one wire bus master with given parameters. Returns true if successful otherwise false.

Parameters
[in]apuactive pull-up (default true).
[in]spustrong pull-up (default false).
[in]iwsone wire speed (default false).
Returns
bool.

Definition at line 131 of file OWI.h.

bool Hardware::OWI::device_reset ( )
inline

Global reset of device state machine logic. Returns true if successful otherwise false.

Returns
bool.

Definition at line 118 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.

virtual uint8_t Hardware::OWI::read ( uint8_t  bits = CHARBITS)
inlinevirtual

Read the given number of bits from the one wire bus. Default number of bits is 8. Calculate partial check-sum.

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

Implements OWI.

Definition at line 60 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.

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.

virtual bool Hardware::OWI::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 Hardware::OWI::triplet ( uint8_t &  dir)
inlinevirtual

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 from OWI.

Definition at line 108 of file OWI.h.

virtual void Hardware::OWI::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 86 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.

Member Data Documentation

DS2482 Hardware::OWI::m_bridge
protected

Definition at line 148 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: