34 if (count !=
sizeof(cmd))
goto error;
37 count =
twi.
read(&status,
sizeof(status));
39 return (count ==
sizeof(status) && status.
RST);
58 config.
COMP = ~config;
65 if (count !=
sizeof(cmd))
goto error;
68 count =
twi.
read(&status,
sizeof(status));
70 return (count ==
sizeof(status) && !status.
RST);
86 cmd[1] = (uint8_t) addr;
89 if (count !=
sizeof(cmd))
goto error;
92 count =
twi.
read(®,
sizeof(reg));
94 return ((count ==
sizeof(reg)) ? reg : -1);
108 if (chan > 7)
return (
false);
112 cmd[1] = (~chan << 4) | chan;
114 count =
twi.
write(cmd,
sizeof(cmd));
116 return (count ==
sizeof(cmd));
130 if (count !=
sizeof(cmd))
goto error;
133 for (
int i = 0; i <
POLL_MAX; i++) {
134 count =
twi.
read(&status,
sizeof(status));
135 if (count ==
sizeof(status) && !status.
IWB)
break;
138 return (count ==
sizeof(status) && status.
PPD);
156 count =
twi.
write(cmd,
sizeof(cmd));
157 if (count !=
sizeof(cmd))
goto error;
160 for (
int i = 0; i <
POLL_MAX; i++) {
161 count =
twi.
read(&status,
sizeof(status));
162 if (count ==
sizeof(status) && !status.
IWB)
break;
165 if (count !=
sizeof(status) || status.
IWB)
return (-1);
182 cmd[1] = (value ? 0x80 : 0x00);
184 count =
twi.
write(cmd,
sizeof(cmd));
185 if (count !=
sizeof(cmd))
goto error;
188 for (
int i = 0; i <
POLL_MAX; i++) {
189 count =
twi.
read(&status,
sizeof(status));
190 if (count ==
sizeof(status) && !status.
IWB)
break;
193 return (count ==
sizeof(status) && !status.
IWB);
211 count =
twi.
write(cmd,
sizeof(cmd));
212 if (count !=
sizeof(cmd))
goto error;
215 for (
int i = 0; i <
POLL_MAX; i++) {
216 count =
twi.
read(&status,
sizeof(status));
217 if (count ==
sizeof(status) && !status.
IWB)
break;
220 return (count ==
sizeof(status) && !status.
IWB);
238 if (count !=
sizeof(cmd))
goto error;
241 for (
int i = 0; i <
POLL_MAX; i++) {
242 count =
twi.
read(&status,
sizeof(status));
243 if (count ==
sizeof(status) && !status.
IWB)
break;
246 if (count !=
sizeof(status) || status.
IWB)
return (
false);
265 cmd[1] = (direction ? 0x80 : 0x00);
267 count =
twi.
write(cmd,
sizeof(cmd));
268 if (count !=
sizeof(cmd))
goto error;
271 for (
int i = 0; i <
POLL_MAX; i++) {
272 count =
twi.
read(&status,
sizeof(status));
273 if (count ==
sizeof(status) && !status.
IWB)
break;
276 if (count !=
sizeof(status) && status.
IWB)
return (-1);
279 return (status >> 5);
bool device_config(bool apu=true, bool spu=false, bool iws=false)
bool one_wire_write_bit(bool value)
uint8_t APU
< Bitfield access (little endian).
int set_read_pointer(Register addr)
bool one_wire_write_byte(uint8_t value)
bool channel_select(uint8_t chan)
int read(void *buf, size_t size)
uint8_t IWB
< Bitfield access (little endian).
uint8_t SPU
Strong Pullup.
int one_wire_triplet(bool direction=false)
int write(void *buf, size_t size)
static const int POLL_MAX
uint8_t PPD
Presence-Pulse Detect.
void acquire(TWI::Driver *dev)
uint8_t COMP
Complement of lower 4-bits.
uint8_t SBR
Single Bit Result.