COSA
An Object-Oriented Platform for Arduino Programming
DS2482.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_DS2482_HH
22 #define COSA_DS2482_HH
23 
24 #include "Cosa/TWI.hh"
25 
34 class DS2482 : private TWI::Driver {
35 public:
40  DS2482(uint8_t subaddr = 0) : TWI::Driver(0x18 | (subaddr & 0x03)) {}
41 
47  bool device_reset();
48 
57  bool device_config(bool apu = true, bool spu = false, bool iws = false);
58 
62  enum Register {
67  } __attribute__((packed));
68 
75  int set_read_pointer(Register addr);
76 
83  bool channel_select(uint8_t chan);
84 
91  bool one_wire_reset();
92 
98  int one_wire_read_bit();
99 
106  bool one_wire_write_bit(bool value);
107 
114  bool one_wire_write_byte(uint8_t value);
115 
121  int one_wire_read_byte();
122 
129  int one_wire_triplet(bool direction = false);
130 
131 protected:
135  enum {
136  DEVICE_RESET = 0xf0,
139  CHANNEL_SELECT = 0xc3,
140  ONE_WIRE_RESET = 0xb4,
145  } __attribute__((packed));
146 
150  union status_t {
151  uint8_t as_uint8;
152  struct {
153  uint8_t IWB:1;
154  uint8_t PPD:1;
155  uint8_t SD:1;
156  uint8_t LL:1;
157  uint8_t RST:1;
158  uint8_t SBR:1;
159  uint8_t TSB:1;
160  uint8_t DIR:1;
161  };
162  operator uint8_t()
163  {
164  return (as_uint8);
165  }
166  };
167 
171  union config_t {
172  uint8_t as_uint8;
173  struct {
174  uint8_t APU:1;
175  uint8_t ZERO:1;
176  uint8_t SPU:1;
177  uint8_t IWS:1;
178  uint8_t COMP:4;
179  };
180  operator uint8_t()
181  {
182  return (as_uint8);
183  }
185  {
186  as_uint8 = 0;
187  }
188  };
189 
191  static const int POLL_MAX = 20;
192 };
193 
194 #endif
Definition: TWI.hh:51
bool one_wire_reset()
Definition: DS2482.cpp:120
Channel Select.
Definition: DS2482.hh:139
Set Read Pointer.
Definition: DS2482.hh:137
bool device_config(bool apu=true, bool spu=false, bool iws=false)
Definition: DS2482.cpp:47
uint8_t TSB
Triplet Second Bit.
Definition: DS2482.hh:159
uint8_t DIR
Branch Direction Taken.
Definition: DS2482.hh:160
bool one_wire_write_bit(bool value)
Definition: DS2482.cpp:174
uint8_t RST
Device Reset.
Definition: DS2482.hh:157
uint8_t as_uint8
Unsigned byte access.
Definition: DS2482.hh:151
int set_read_pointer(Register addr)
Definition: DS2482.cpp:78
uint8_t as_uint8
Unsigned byte access.
Definition: DS2482.hh:172
1-Wire Write Byte.
Definition: DS2482.hh:142
bool device_reset()
Definition: DS2482.cpp:24
1-Wire Single Bit.
Definition: DS2482.hh:141
Definition: DS2482.hh:34
bool one_wire_write_byte(uint8_t value)
Definition: DS2482.cpp:201
Definition: SD.hh:35
bool channel_select(uint8_t chan)
Definition: DS2482.cpp:102
uint8_t IWB
< Bitfield access (little endian).
Definition: DS2482.hh:153
int one_wire_triplet(bool direction=false)
Definition: DS2482.cpp:257
static const int POLL_MAX
Definition: DS2482.hh:191
int one_wire_read_byte()
Definition: DS2482.cpp:228
uint8_t PPD
Presence-Pulse Detect.
Definition: DS2482.hh:154
int one_wire_read_bit()
Definition: DS2482.cpp:146
Driver(uint8_t addr)
Definition: TWI.hh:70
Register
Definition: DS2482.hh:62
uint8_t LL
Logic Level.
Definition: DS2482.hh:156
1-Wire Read Byte.
Definition: DS2482.hh:143
Device Reset.
Definition: DS2482.hh:136
1-Wire Reset.
Definition: DS2482.hh:140
uint8_t SBR
Single Bit Result.
Definition: DS2482.hh:158
1-Wire Triplet.
Definition: DS2482.hh:144
DS2482(uint8_t subaddr=0)
Definition: DS2482.hh:40
Write Configuration.
Definition: DS2482.hh:138