esp32-warm-water
esp32 based project for the control of a heating element based on temperature
owb.c
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2017 David Antliff
5  * Copyright (c) 2017 Chris Morgan <chmorgan@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
30 #include <stddef.h>
31 #include <stdbool.h>
32 #include <inttypes.h>
33 #include <string.h>
34 #include <stdlib.h>
35 
36 #include "freertos/FreeRTOS.h"
37 #include "freertos/task.h"
38 #include "esp_log.h"
39 #include "sdkconfig.h"
40 #include "driver/gpio.h"
41 
42 #include "owb.h"
43 #include "owb_gpio.h"
44 
45 static const char *TAG = CONFIG_OWB_TAG;
46 
47 static bool _is_init(const OneWireBus *bus)
48 {
49  bool ok = false;
50  if (bus != NULL)
51  {
52  if (bus->driver)
53  {
54  // OK
55  ok = true;
56  }
57  else
58  {
59  ESP_LOGE(TAG, "bus is not initialised");
60  }
61  }
62  else
63  {
64  ESP_LOGE(TAG, "bus is NULL");
65  }
66  return ok;
67 }
68 
75 static uint8_t _calc_crc(uint8_t crc, uint8_t data)
76 {
77  // https://www.maximintegrated.com/en/app-notes/index.mvp/id/27
78  static const uint8_t table[256] = {
79  0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
80  157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
81  35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
82  190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
83  70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
84  219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
85  101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
86  248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
87  140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
88  17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
89  175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
90  50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
91  202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
92  87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
93  233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
94  116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53};
95 
96  return table[crc ^ data];
97 }
98 
99 static uint8_t _calc_crc_block(uint8_t crc, const uint8_t *buffer, size_t len)
100 {
101  do
102  {
103  crc = _calc_crc(crc, *buffer++);
104  ESP_LOGD(TAG, "buffer 0x%02x, crc 0x%02x, len %d", (uint8_t) * (buffer - 1), (int)crc, (int)len);
105  } while (--len > 0);
106  return crc;
107 }
108 
113 static owb_status _search(const OneWireBus *bus, OneWireBus_SearchState *state, bool *is_found)
114 {
115  // Based on https://www.maximintegrated.com/en/app-notes/index.mvp/id/187
116 
117  // initialize for search
118  int id_bit_number = 1;
119  int last_zero = 0;
120  int rom_byte_number = 0;
121  uint8_t id_bit = 0;
122  uint8_t cmp_id_bit = 0;
123  uint8_t rom_byte_mask = 1;
124  uint8_t search_direction = 0;
125  bool search_result = false;
126  uint8_t crc8 = 0;
128 
129  // if the last call was not the last one
130  if (!state->last_device_flag)
131  {
132  // 1-Wire reset
133  bool is_present;
134  bus->driver->reset(bus, &is_present);
135  if (!is_present)
136  {
137  // reset the search
138  state->last_discrepancy = 0;
139  state->last_device_flag = false;
140  state->last_family_discrepancy = 0;
141  *is_found = false;
142  return OWB_STATUS_OK;
143  }
144 
145  // issue the search command
146  bus->driver->write_bits(bus, OWB_ROM_SEARCH, 8);
147 
148  // loop to do the search
149  do
150  {
151  id_bit = cmp_id_bit = 0;
152 
153  // read a bit and its complement
154  bus->driver->read_bits(bus, &id_bit, 1);
155  bus->driver->read_bits(bus, &cmp_id_bit, 1);
156 
157  // check for no devices on 1-wire (signal level is high in both bit reads)
158  if (id_bit && cmp_id_bit)
159  {
160  break;
161  }
162  else
163  {
164  // all devices coupled have 0 or 1
165  if (id_bit != cmp_id_bit)
166  {
167  search_direction = (id_bit) ? 1 : 0; // bit write value for search
168  }
169  else
170  {
171  // if this discrepancy if before the Last Discrepancy
172  // on a previous next then pick the same as last time
173  if (id_bit_number < state->last_discrepancy)
174  {
175  search_direction = ((state->rom_code.bytes[rom_byte_number] & rom_byte_mask) > 0);
176  }
177  else
178  {
179  // if equal to last pick 1, if not then pick 0
180  search_direction = (id_bit_number == state->last_discrepancy);
181  }
182 
183  // if 0 was picked then record its position in LastZero
184  if (search_direction == 0)
185  {
186  last_zero = id_bit_number;
187 
188  // check for Last discrepancy in family
189  if (last_zero < 9)
190  {
191  state->last_family_discrepancy = last_zero;
192  }
193  }
194  }
195 
196  // set or clear the bit in the ROM byte rom_byte_number
197  // with mask rom_byte_mask
198  if (search_direction == 1)
199  {
200  state->rom_code.bytes[rom_byte_number] |= rom_byte_mask;
201  }
202  else
203  {
204  state->rom_code.bytes[rom_byte_number] &= ~rom_byte_mask;
205  }
206 
207  // serial number search direction write bit
208  bus->driver->write_bits(bus, search_direction, 1);
209 
210  // increment the byte counter id_bit_number
211  // and shift the mask rom_byte_mask
212  id_bit_number++;
213  rom_byte_mask <<= 1;
214 
215  // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
216  if (rom_byte_mask == 0)
217  {
218  crc8 = owb_crc8_byte(crc8, state->rom_code.bytes[rom_byte_number]); // accumulate the CRC
219  rom_byte_number++;
220  rom_byte_mask = 1;
221  }
222  }
223  } while (rom_byte_number < 8); // loop until through all ROM bytes 0-7
224 
225  // if the search was successful then
226  if (!((id_bit_number < 65) || (crc8 != 0)))
227  {
228  // search successful so set LastDiscrepancy,LastDeviceFlag,search_result
229  state->last_discrepancy = last_zero;
230 
231  // check for last device
232  if (state->last_discrepancy == 0)
233  {
234  state->last_device_flag = true;
235  }
236 
237  search_result = true;
238  }
239  }
240 
241  // if no device found then reset counters so next 'search' will be like a first
242  if (!search_result || !state->rom_code.bytes[0])
243  {
244  state->last_discrepancy = 0;
245  state->last_device_flag = false;
246  state->last_family_discrepancy = 0;
247  search_result = false;
248  }
249 
250  status = OWB_STATUS_OK;
251 
252  *is_found = search_result;
253 
254  return status;
255 }
256 
257 // Public API
258 
260 {
262 
263  if (!_is_init(bus))
264  {
266  }
267  else
268  {
269  bus->driver->uninitialize(bus);
270  status = OWB_STATUS_OK;
271  }
272 
273  return status;
274 }
275 
276 owb_status owb_use_crc(OneWireBus *bus, bool use_crc)
277 {
279 
280  if (!bus)
281  {
282  status = OWB_STATUS_PARAMETER_NULL;
283  }
284  else if (!_is_init(bus))
285  {
287  }
288  else
289  {
290  bus->use_crc = use_crc;
291  ESP_LOGD(TAG, "use_crc %d", bus->use_crc);
292 
293  status = OWB_STATUS_OK;
294  }
295 
296  return status;
297 }
298 
299 owb_status owb_use_parasitic_power(OneWireBus *bus, bool use_parasitic_power)
300 {
302 
303  if (!bus)
304  {
305  status = OWB_STATUS_PARAMETER_NULL;
306  }
307  else if (!_is_init(bus))
308  {
310  }
311  else
312  {
313  bus->use_parasitic_power = use_parasitic_power;
314  ESP_LOGD(TAG, "use_parasitic_power %d", bus->use_parasitic_power);
315 
316  status = OWB_STATUS_OK;
317  }
318 
319  return status;
320 }
321 
323 {
325 
326  if (!bus)
327  {
328  status = OWB_STATUS_PARAMETER_NULL;
329  }
330  else if (!_is_init(bus))
331  {
333  }
334  else
335  {
336  if (gpio != GPIO_NUM_NC)
337  {
338  // The strong GPIO pull-up is only activated if parasitic-power mode is enabled
339  if (!bus->use_parasitic_power)
340  {
341  ESP_LOGW(TAG, "Strong pull-up GPIO set with parasitic-power disabled");
342  }
343 
344  gpio_pad_select_gpio(gpio);
345  gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
346  }
347  else
348  {
349  gpio_reset_pin(bus->strong_pullup_gpio);
350  }
351 
352  bus->strong_pullup_gpio = gpio;
353  ESP_LOGD(TAG, "use_strong_pullup_gpio %d", bus->strong_pullup_gpio);
354 
355  status = OWB_STATUS_OK;
356  }
357 
358  return status;
359 }
360 
362 {
364 
365  memset(rom_code, 0, sizeof(OneWireBus_ROMCode));
366 
367  if (!bus || !rom_code)
368  {
369  status = OWB_STATUS_PARAMETER_NULL;
370  }
371  else if (!_is_init(bus))
372  {
374  }
375  else
376  {
377  bool is_present;
378  bus->driver->reset(bus, &is_present);
379  if (is_present)
380  {
381  uint8_t value = OWB_ROM_READ;
382  bus->driver->write_bits(bus, value, 8);
383  owb_read_bytes(bus, rom_code->bytes, sizeof(OneWireBus_ROMCode));
384 
385  if (bus->use_crc)
386  {
387  if (owb_crc8_bytes(0, rom_code->bytes, sizeof(OneWireBus_ROMCode)) != 0)
388  {
389  ESP_LOGE(TAG, "CRC failed");
390  memset(rom_code->bytes, 0, sizeof(OneWireBus_ROMCode));
391  status = OWB_STATUS_CRC_FAILED;
392  }
393  else
394  {
395  status = OWB_STATUS_OK;
396  }
397  }
398  else
399  {
400  status = OWB_STATUS_OK;
401  }
402  char rom_code_s[OWB_ROM_CODE_STRING_LENGTH];
403  owb_string_from_rom_code(*rom_code, rom_code_s, sizeof(rom_code_s));
404  ESP_LOGD(TAG, "rom_code %s", rom_code_s);
405  }
406  else
407  {
409  ESP_LOGE(TAG, "ds18b20 device not responding");
410  }
411  }
412 
413  return status;
414 }
415 
416 owb_status owb_verify_rom(const OneWireBus *bus, OneWireBus_ROMCode rom_code, bool *is_present)
417 {
419  bool result = false;
420 
421  if (!bus || !is_present)
422  {
423  status = OWB_STATUS_PARAMETER_NULL;
424  }
425  else if (!_is_init(bus))
426  {
428  }
429  else
430  {
431  OneWireBus_SearchState state = {
432  .rom_code = rom_code,
433  .last_discrepancy = 64,
434  .last_device_flag = false,
435  };
436 
437  bool is_found = false;
438  _search(bus, &state, &is_found);
439  if (is_found)
440  {
441  result = true;
442  for (int i = 0; i < sizeof(state.rom_code.bytes) && result; ++i)
443  {
444  result = rom_code.bytes[i] == state.rom_code.bytes[i];
445  ESP_LOGD(TAG, "%02x %02x", rom_code.bytes[i], state.rom_code.bytes[i]);
446  }
447  is_found = result;
448  }
449  ESP_LOGD(TAG, "state.last_discrepancy %d, state.last_device_flag %d, is_found %d",
450  state.last_discrepancy, state.last_device_flag, is_found);
451 
452  ESP_LOGD(TAG, "rom code %sfound", result ? "" : "not ");
453  *is_present = result;
454  status = OWB_STATUS_OK;
455  }
456 
457  return status;
458 }
459 
460 owb_status owb_reset(const OneWireBus *bus, bool *a_device_present)
461 {
463 
464  if (!bus || !a_device_present)
465  {
466  status = OWB_STATUS_PARAMETER_NULL;
467  }
468  else if (!_is_init(bus))
469  {
471  }
472  else
473  {
474  status = bus->driver->reset(bus, a_device_present);
475  }
476 
477  return status;
478 }
479 
480 owb_status owb_read_bit(const OneWireBus *bus, uint8_t *out)
481 {
483 
484  if (!bus || !out)
485  {
486  status = OWB_STATUS_PARAMETER_NULL;
487  }
488  else if (!_is_init(bus))
489  {
491  }
492  else
493  {
494  bus->driver->read_bits(bus, out, 1);
495  ESP_LOGD(TAG, "owb_read_bit: %02x", *out);
496  status = OWB_STATUS_OK;
497  }
498 
499  return status;
500 }
501 
502 owb_status owb_read_byte(const OneWireBus *bus, uint8_t *out)
503 {
505 
506  if (!bus || !out)
507  {
508  status = OWB_STATUS_PARAMETER_NULL;
509  }
510  else if (!_is_init(bus))
511  {
513  }
514  else
515  {
516  bus->driver->read_bits(bus, out, 8);
517  ESP_LOGD(TAG, "owb_read_byte: %02x", *out);
518  status = OWB_STATUS_OK;
519  }
520 
521  return status;
522 }
523 
524 owb_status owb_read_bytes(const OneWireBus *bus, uint8_t *buffer, unsigned int len)
525 {
527 
528  if (!bus || !buffer)
529  {
530  status = OWB_STATUS_PARAMETER_NULL;
531  }
532  else if (!_is_init(bus))
533  {
535  }
536  else
537  {
538  for (int i = 0; i < len; ++i)
539  {
540  uint8_t out;
541  bus->driver->read_bits(bus, &out, 8);
542  buffer[i] = out;
543  }
544 
545  ESP_LOGD(TAG, "owb_read_bytes, len %d:", len);
546  ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, len, ESP_LOG_DEBUG);
547 
548  status = OWB_STATUS_OK;
549  }
550 
551  return status;
552 }
553 
554 owb_status owb_write_bit(const OneWireBus *bus, const uint8_t bit)
555 {
557 
558  if (!bus)
559  {
560  status = OWB_STATUS_PARAMETER_NULL;
561  }
562  else if (!_is_init(bus))
563  {
565  }
566  else
567  {
568  ESP_LOGD(TAG, "owb_write_bit: %02x", bit);
569  bus->driver->write_bits(bus, bit & 0x01u, 1);
570  status = OWB_STATUS_OK;
571  }
572 
573  return status;
574 }
575 
576 owb_status owb_write_byte(const OneWireBus *bus, uint8_t data)
577 {
579 
580  if (!bus)
581  {
582  status = OWB_STATUS_PARAMETER_NULL;
583  }
584  else if (!_is_init(bus))
585  {
587  }
588  else
589  {
590  ESP_LOGD(TAG, "owb_write_byte: %02x", data);
591  bus->driver->write_bits(bus, data, 8);
592  status = OWB_STATUS_OK;
593  }
594 
595  return status;
596 }
597 
598 owb_status owb_write_bytes(const OneWireBus *bus, const uint8_t *buffer, size_t len)
599 {
601 
602  if (!bus || !buffer)
603  {
604  status = OWB_STATUS_PARAMETER_NULL;
605  }
606  else if (!_is_init(bus))
607  {
609  }
610  else
611  {
612  ESP_LOGD(TAG, "owb_write_bytes, len %d:", len);
613  ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, len, ESP_LOG_DEBUG);
614 
615  for (int i = 0; i < len; i++)
616  {
617  bus->driver->write_bits(bus, buffer[i], 8);
618  }
619 
620  status = OWB_STATUS_OK;
621  }
622 
623  return status;
624 }
625 
627 {
629 
630  if (!bus)
631  {
632  status = OWB_STATUS_PARAMETER_NULL;
633  }
634  else if (!_is_init(bus))
635  {
637  }
638  else
639  {
640  owb_write_bytes(bus, (uint8_t *)&rom_code, sizeof(rom_code));
641  status = OWB_STATUS_OK;
642  }
643 
644  return status;
645 }
646 
647 uint8_t owb_crc8_byte(uint8_t crc, uint8_t data)
648 {
649  return _calc_crc(crc, data);
650 }
651 
652 uint8_t owb_crc8_bytes(uint8_t crc, const uint8_t *data, size_t len)
653 {
654  return _calc_crc_block(crc, data, len);
655 }
656 
657 owb_status owb_search_first(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
658 {
659  bool result;
661 
662  if (!bus || !state || !found_device)
663  {
664  status = OWB_STATUS_PARAMETER_NULL;
665  }
666  else if (!_is_init(bus))
667  {
669  }
670  else
671  {
672  memset(&state->rom_code, 0, sizeof(state->rom_code));
673  state->last_discrepancy = 0;
674  state->last_family_discrepancy = 0;
675  state->last_device_flag = false;
676  _search(bus, state, &result);
677  status = OWB_STATUS_OK;
678 
679  *found_device = result;
680  }
681 
682  return status;
683 }
684 
685 owb_status owb_search_next(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
686 {
688  bool result = false;
689 
690  if (!bus || !state || !found_device)
691  {
692  status = OWB_STATUS_PARAMETER_NULL;
693  }
694  else if (!_is_init(bus))
695  {
697  }
698  else
699  {
700  _search(bus, state, &result);
701  status = OWB_STATUS_OK;
702 
703  *found_device = result;
704  }
705 
706  return status;
707 }
708 
709 char *owb_string_from_rom_code(OneWireBus_ROMCode rom_code, char *buffer, size_t len)
710 {
711  for (int i = sizeof(rom_code.bytes) - 1; i >= 0; i--)
712  {
713  sprintf(buffer, "%02x", rom_code.bytes[i]);
714  buffer += 2;
715  }
716  return buffer;
717 }
718 
720 {
722 
723  if (!bus)
724  {
725  status = OWB_STATUS_PARAMETER_NULL;
726  }
727  else if (!_is_init(bus))
728  {
730  }
731  else
732  {
734  {
735  gpio_set_level(bus->strong_pullup_gpio, enable ? 1 : 0);
736  ESP_LOGD(TAG, "strong pullup GPIO %d", enable);
737  } // else ignore
738 
739  status = OWB_STATUS_OK;
740  }
741 
742  return status;
743 }
owb_status owb_set_strong_pullup(const OneWireBus *bus, bool enable)
Enable or disable the strong-pullup GPIO, if configured.
Definition: owb.c:719
owb_status owb_read_byte(const OneWireBus *bus, uint8_t *out)
Read a single byte from the 1-Wire bus.
Definition: owb.c:502
uint8_t owb_crc8_byte(uint8_t crc, uint8_t data)
1-Wire 8-bit CRC lookup.
Definition: owb.c:647
owb_status owb_read_rom(const OneWireBus *bus, OneWireBus_ROMCode *rom_code)
Read ROM code from device - only works when there is a single device on the bus.
Definition: owb.c:361
owb_status owb_use_parasitic_power(OneWireBus *bus, bool use_parasitic_power)
Enable or disable use of parasitic power on the One Wire Bus. This affects how devices signal on the ...
Definition: owb.c:299
uint8_t owb_crc8_bytes(uint8_t crc, const uint8_t *data, size_t len)
1-Wire 8-bit CRC lookup with accumulation over a block of bytes.
Definition: owb.c:652
owb_status owb_write_rom_code(const OneWireBus *bus, OneWireBus_ROMCode rom_code)
Write a ROM code to the 1-Wire bus ensuring LSB is sent first.
Definition: owb.c:626
owb_status owb_write_bytes(const OneWireBus *bus, const uint8_t *buffer, size_t len)
Write a number of bytes to the 1-Wire bus.
Definition: owb.c:598
char * owb_string_from_rom_code(OneWireBus_ROMCode rom_code, char *buffer, size_t len)
Create a string representation of a ROM code, most significant byte (CRC8) first.
Definition: owb.c:709
owb_status owb_read_bytes(const OneWireBus *bus, uint8_t *buffer, unsigned int len)
Read a number of bytes from the 1-Wire bus.
Definition: owb.c:524
owb_status owb_use_crc(OneWireBus *bus, bool use_crc)
Enable or disable use of CRC checks on device communications.
Definition: owb.c:276
owb_status owb_read_bit(const OneWireBus *bus, uint8_t *out)
Read a single bit from the 1-Wire bus.
Definition: owb.c:480
owb_status owb_uninitialize(OneWireBus *bus)
call to release resources after completing use of the OneWireBus
Definition: owb.c:259
owb_status owb_write_byte(const OneWireBus *bus, uint8_t data)
Write a single byte to the 1-Wire bus.
Definition: owb.c:576
owb_status owb_search_next(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the next device on the 1-Wire bus, if present, starting from the provided state....
Definition: owb.c:685
owb_status owb_use_strong_pullup_gpio(OneWireBus *bus, gpio_num_t gpio)
Enable or disable use of extra GPIO to activate strong pull-up circuit. This only has effect if paras...
Definition: owb.c:322
owb_status owb_search_first(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the first device on the 1-Wire bus, if present.
Definition: owb.c:657
owb_status owb_reset(const OneWireBus *bus, bool *a_device_present)
Reset the 1-Wire bus.
Definition: owb.c:460
owb_status owb_write_bit(const OneWireBus *bus, const uint8_t bit)
Write a bit to the 1-Wire bus.
Definition: owb.c:554
owb_status owb_verify_rom(const OneWireBus *bus, OneWireBus_ROMCode rom_code, bool *is_present)
Verify the device specified by ROM code is present.
Definition: owb.c:416
Interface definitions for the 1-Wire bus component.
#define OWB_ROM_READ
Read device ROM (single device on bus only)
Definition: owb.h:52
owb_status
Represents the result of OWB API functions.
Definition: owb.h:114
@ OWB_STATUS_PARAMETER_NULL
Function was passed a null pointer.
Definition: owb.h:118
@ OWB_STATUS_CRC_FAILED
CRC failed on data received from a device or devices.
Definition: owb.h:120
@ OWB_STATUS_OK
Operation succeeded.
Definition: owb.h:116
@ OWB_STATUS_NOT_SET
A status value has not been set.
Definition: owb.h:115
@ OWB_STATUS_NOT_INITIALIZED
Function was passed an uninitialised variable.
Definition: owb.h:117
@ OWB_STATUS_DEVICE_NOT_RESPONDING
No response received from the addressed device or devices.
Definition: owb.h:119
#define OWB_ROM_CODE_STRING_LENGTH
Typical length of OneWire bus ROM ID as ASCII hex string, including null terminator.
Definition: owb.h:57
#define OWB_ROM_SEARCH
Perform Search ROM cycle to identify devices on the bus.
Definition: owb.h:51
#define GPIO_NUM_NC
ESP-IDF prior to v4.x does not define GPIO_NUM_NC.
Definition: owb.h:60
Interface definitions for the ESP32 GPIO driver used to communicate with devices on the One Wire Bus.
Represents the state of a device search on the 1-Wire bus.
Definition: owb.h:103
int last_family_discrepancy
Bit index that identifies the last discrepancy within the first 8-bit family code of the ROM code.
Definition: owb.h:106
int last_device_flag
Flag to indicate previous search was the last device detected.
Definition: owb.h:107
OneWireBus_ROMCode rom_code
Device ROM code.
Definition: owb.h:104
int last_discrepancy
Bit index that identifies from which bit the next search discrepancy check should start.
Definition: owb.h:105
Structure containing 1-Wire bus information relevant to a single instance.
Definition: owb.h:69
gpio_num_t strong_pullup_gpio
Set if an external strong pull-up circuit is required.
Definition: owb.h:73
bool use_parasitic_power
True if parasitic-powered devices are expected on the bus.
Definition: owb.h:72
const struct owb_driver * driver
Pointer to hardware driver instance.
Definition: owb.h:74
bool use_crc
True if CRC checks are to be used when retrieving information from a device on the bus.
Definition: owb.h:71
owb_status(* read_bits)(const OneWireBus *bus, uint8_t *in, int number_of_bits_to_read)
Definition: owb.h:141
owb_status(* uninitialize)(const OneWireBus *bus)
Definition: owb.h:132
owb_status(* write_bits)(const OneWireBus *bus, uint8_t out, int number_of_bits_to_write)
Definition: owb.h:138
owb_status(* reset)(const OneWireBus *bus, bool *is_present)
Definition: owb.h:135
Represents a 1-Wire ROM Code. This is a sequence of eight bytes, where the first byte is the family n...
Definition: owb.h:83
uint8_t bytes[8]
Provides raw byte access.
Definition: owb.h:92
const char * TAG
Definition: wifi_sta.c:42