1 #include <twr_ds28e17.h>
11 static bool _twr_ds28e17_write(
twr_ds28e17_t *
self, uint8_t *head,
size_t head_length,
void *buffer,
size_t length);
12 static bool _twr_ds28e17_read(
twr_ds28e17_t *
self, uint8_t *head,
size_t head_length,
void *buffer,
size_t length);
16 memset(
self, 0,
sizeof(*
self));
18 self->_device_number = device_number;
20 self->_onewire = onewire;
32 return self->_device_number;
51 buffer[1] = _twr_ds28e17_set_speed_lut[speed];
66 head[2] = (uint8_t) transfer->
length;
68 return _twr_ds28e17_write(
self, head,
sizeof(head), transfer->
buffer, transfer->
length);
77 head[2] = (uint8_t) transfer->
length;
79 return _twr_ds28e17_read(
self, head,
sizeof(head), transfer->
buffer, transfer->
length);
93 head[2] = (uint8_t) transfer->
length + 2;
100 head[2] = (uint8_t) transfer->
length + 1;
104 return _twr_ds28e17_write(
self, head, head_length, transfer->
buffer, transfer->
length);
121 head[5] = transfer->
length;
128 head[4] = transfer->
length;
131 return _twr_ds28e17_read(
self, head, head_length, transfer->
buffer, transfer->
length);
134 static bool _twr_ds28e17_write(
twr_ds28e17_t *
self, uint8_t *head,
size_t head_length,
void *buffer,
size_t length)
181 return (status == 0x00) && (write_status == 0x00);
184 static bool _twr_ds28e17_read(
twr_ds28e17_t *
self, uint8_t *head,
size_t head_length,
void *buffer,
size_t length)
225 if ((status != 0x00) || (write_status != 0x00))
bool twr_ds28e17_write(twr_ds28e17_t *self, const twr_i2c_transfer_t *transfer)
Write to I2C.
bool twr_ds28e17_memory_read(twr_ds28e17_t *self, const twr_i2c_memory_transfer_t *transfer)
Memory read from I2C.
void twr_ds28e17_deinit(twr_ds28e17_t *self)
Deinitialize DS28E17.
bool twr_ds28e17_memory_write(twr_ds28e17_t *self, const twr_i2c_memory_transfer_t *transfer)
Memory write to I2C.
bool twr_ds28e17_set_speed(twr_ds28e17_t *self, twr_i2c_speed_t speed)
Set I2C speed.
void twr_ds28e17_init(twr_ds28e17_t *self, twr_onewire_t *onewire, uint64_t device_number)
Initialize DS28E17.
bool twr_ds28e17_read(twr_ds28e17_t *self, const twr_i2c_transfer_t *transfer)
Read from I2C.
uint64_t twr_ds28e17_get_device_number(twr_ds28e17_t *self)
Get Device number.
twr_gpio_channel_t
GPIO channels.
twr_i2c_speed_t
I2C communication speed.
#define TWR_I2C_MEMORY_ADDRESS_16_BIT
This flag extends I2C memory transfer address from 8-bit to 16-bit.
@ TWR_I2C_SPEED_400_KHZ
I2C communication speed is 400 kHz.
@ TWR_I2C_SPEED_100_KHZ
I2C communication speed is 100 kHz.
void twr_onewire_write(twr_onewire_t *self, const void *buffer, size_t length)
Select device.
struct twr_onewire_t twr_onewire_t
1-Wire instance
bool twr_onewire_transaction_start(twr_onewire_t *self)
Start transaction, enable pll and run timer.
bool twr_onewire_reset(twr_onewire_t *self)
Reset the 1-Wire bus and return the presence of any device.
void twr_onewire_read(twr_onewire_t *self, void *buffer, size_t length)
Select device.
void twr_onewire_select(twr_onewire_t *self, uint64_t *device_number)
Select device.
uint8_t twr_onewire_read_byte(twr_onewire_t *self)
Select device.
uint16_t twr_onewire_crc16(const void *buffer, size_t length, uint16_t crc)
Calculate 16-bit CRC, polynomial 0x8005.
int twr_onewire_read_bit(twr_onewire_t *self)
Select device.
bool twr_onewire_transaction_stop(twr_onewire_t *self)
Stop transaction.
void twr_onewire_auto_ds28e17_sleep_mode(twr_onewire_t *self, bool on)
Enable call sleep mode for all ds28e17 after transaction.
twr_tick_t twr_tick_get(void)
Get absolute timestamp since start of program.
uint64_t twr_tick_t
Timestamp data type.
I2C memory transfer parameters.
uint32_t memory_address
8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16...
uint8_t device_address
7-bit I2C device address
size_t length
Length of buffer which is being written or read.
void * buffer
Pointer to buffer which is being written or read.
void * buffer
Pointer to buffer which is being written or read.
uint8_t device_address
7-bit I2C device address
size_t length
Length of buffer which is being written or read.