Firmware SDK
twr_onewire.h
1 #ifndef _TWR_ONEWIRE_H
2 #define _TWR_ONEWIRE_H
3 
4 #include <twr_gpio.h>
5 
9 
10 #define TWR_ONEWIRE_DEVICE_NUMBER_SKIP_ROM 0
11 
13 
14 typedef struct twr_onewire_t twr_onewire_t;
15 
17 
18 typedef struct
19 {
20  bool (*init)(void *ctx);
21  bool (*enable)(void *ctx);
22  bool (*disable)(void *ctx);
23  bool (*reset)(void *ctx);
24  void (*write_bit)(void *ctx, uint8_t bit);
25  uint8_t (*read_bit)(void *ctx);
26  void (*write_byte)(void *ctx, uint8_t byte);
27  uint8_t (*read_byte)(void *ctx);
28  bool (*search_next)(void *ctx, twr_onewire_t *onewire, uint64_t *device_number);
29 
30 } twr_onewire_driver_t;
31 
32 struct twr_onewire_t
33 {
34  uint8_t _last_discrepancy;
35  uint8_t _last_family_discrepancy;
36  bool _last_device_flag;
37  uint8_t _last_rom_no[8];
38 
39  int _lock_count;
40  void *_driver_ctx;
41  const twr_onewire_driver_t *_driver;
42  bool _auto_ds28e17_sleep_mode;
43 };
44 
46 
47 
48 
49 void twr_onewire_init_gpio(twr_onewire_t *self, twr_gpio_channel_t channel);
50 
55 
56 bool twr_onewire_init(twr_onewire_t *self, const twr_onewire_driver_t *driver, void *driver_ctx);
57 
62 
64 
69 
71 
76 
78 
83 
85 
89 
90 void twr_onewire_select(twr_onewire_t *self, uint64_t *device_number);
91 
94 
96 
101 
102 void twr_onewire_write(twr_onewire_t *self, const void *buffer, size_t length);
103 
108 
109 void twr_onewire_read(twr_onewire_t *self, void *buffer, size_t length);
110 
114 
115 void twr_onewire_write_byte(twr_onewire_t *self, uint8_t data);
116 
120 
121 uint8_t twr_onewire_read_byte(twr_onewire_t *self);
122 
126 
127 void twr_onewire_write_bit(twr_onewire_t *self, int bit);
128 
132 
134 
140 
141 int twr_onewire_search_all(twr_onewire_t *self, uint64_t *device_list, size_t device_list_size);
142 
149 
150 int twr_onewire_search_family(twr_onewire_t *self, uint8_t family_code, uint64_t *device_list, size_t device_list_size);
151 
155 
156 void twr_onewire_search_start(twr_onewire_t *self, uint8_t family_code);
157 
162 
163 bool twr_onewire_search_next(twr_onewire_t *self, uint64_t *device_number);
164 
167 
169 
175 
176 uint8_t twr_onewire_crc8(const void *buffer, size_t length, uint8_t crc);
177 
183 
184 uint16_t twr_onewire_crc16(const void *buffer, size_t length, uint16_t crc);
185 
187 
188 #endif // _TWR_ONEWIRE_H
twr_gpio_channel_t
GPIO channels.
Definition: twr_gpio.h:13
void twr_onewire_write(twr_onewire_t *self, const void *buffer, size_t length)
Select device.
Definition: twr_onewire.c:96
void twr_onewire_write_byte(twr_onewire_t *self, uint8_t data)
Select device.
Definition: twr_onewire.c:116
void twr_onewire_search_start(twr_onewire_t *self, uint8_t family_code)
Start of manual search, see also twr_onewire_search_next.
Definition: twr_onewire.c:214
struct twr_onewire_t twr_onewire_t
1-Wire instance
Definition: twr_onewire.h:14
void twr_onewire_skip_rom(twr_onewire_t *self)
Skip ROM.
Definition: twr_onewire.c:89
bool twr_onewire_is_transaction(twr_onewire_t *self)
Is transaction run.
Definition: twr_onewire.c:50
bool twr_onewire_transaction_start(twr_onewire_t *self)
Start transaction, enable pll and run timer.
Definition: twr_onewire.c:31
bool twr_onewire_reset(twr_onewire_t *self)
Reset the 1-Wire bus and return the presence of any device.
Definition: twr_onewire.c:55
int twr_onewire_search_all(twr_onewire_t *self, uint64_t *device_list, size_t device_list_size)
Search for all devices on 1-Wire.
Definition: twr_onewire.c:146
bool twr_onewire_init(twr_onewire_t *self, const twr_onewire_driver_t *driver, void *driver_ctx)
Initialize 1-Wire.
Definition: twr_onewire.c:12
int twr_onewire_search_family(twr_onewire_t *self, uint8_t family_code, uint64_t *device_list, size_t device_list_size)
Search for all devices on 1-Wire with family code.
Definition: twr_onewire.c:153
void twr_onewire_read(twr_onewire_t *self, void *buffer, size_t length)
Select device.
Definition: twr_onewire.c:106
uint8_t twr_onewire_crc8(const void *buffer, size_t length, uint8_t crc)
Calculate 8-bit CRC.
Definition: twr_onewire.c:165
void twr_onewire_select(twr_onewire_t *self, uint64_t *device_number)
Select device.
Definition: twr_onewire.c:68
uint8_t twr_onewire_read_byte(twr_onewire_t *self)
Select device.
Definition: twr_onewire.c:123
uint16_t twr_onewire_crc16(const void *buffer, size_t length, uint16_t crc)
Calculate 16-bit CRC, polynomial 0x8005.
Definition: twr_onewire.c:192
int twr_onewire_read_bit(twr_onewire_t *self)
Select device.
Definition: twr_onewire.c:138
bool twr_onewire_transaction_stop(twr_onewire_t *self)
Stop transaction.
Definition: twr_onewire.c:43
void twr_onewire_write_bit(twr_onewire_t *self, int bit)
Select device.
Definition: twr_onewire.c:131
void twr_onewire_auto_ds28e17_sleep_mode(twr_onewire_t *self, bool on)
Enable call sleep mode for all ds28e17 after transaction.
Definition: twr_onewire.c:160
bool twr_onewire_search_next(twr_onewire_t *self, uint64_t *device_number)
Manual search of next device.
Definition: twr_onewire.c:226