one_wire_host.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file one_wire_host.h
  3. *
  4. * 1-Wire host (master) library
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <furi_hal_gpio.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. typedef enum {
  14. OneWireHostSearchModeConditional = 0, /**< Search for alarmed device */
  15. OneWireHostSearchModeNormal = 1, /**< Search for all devices */
  16. } OneWireHostSearchMode;
  17. typedef struct OneWireHost OneWireHost;
  18. /**
  19. * Allocate OneWireHost instance
  20. * @param [in] gpio_pin connection pin
  21. * @return pointer to OneWireHost instance
  22. */
  23. OneWireHost* onewire_host_alloc(const GpioPin* gpio_pin);
  24. /**
  25. * Destroy OneWireHost instance, free resources
  26. * @param [in] host pointer to OneWireHost instance
  27. */
  28. void onewire_host_free(OneWireHost* host);
  29. /**
  30. * Reset the 1-Wire bus
  31. * @param [in] host pointer to OneWireHost instance
  32. * @return true if presence was detected, false otherwise
  33. */
  34. bool onewire_host_reset(OneWireHost* host);
  35. /**
  36. * Read one bit
  37. * @param [in] host pointer to OneWireHost instance
  38. * @return received bit value
  39. */
  40. bool onewire_host_read_bit(OneWireHost* host);
  41. /**
  42. * Read one byte
  43. * @param [in] host pointer to OneWireHost instance
  44. * @return received byte value
  45. */
  46. uint8_t onewire_host_read(OneWireHost* host);
  47. /**
  48. * Read one or more bytes
  49. * @param [in] host pointer to OneWireHost instance
  50. * @param [out] buffer received data buffer
  51. * @param [in] count number of bytes to read
  52. */
  53. void onewire_host_read_bytes(OneWireHost* host, uint8_t* buffer, uint16_t count);
  54. /**
  55. * Write one bit
  56. * @param [in] host pointer to OneWireHost instance
  57. * @param value bit value to write
  58. */
  59. void onewire_host_write_bit(OneWireHost* host, bool value);
  60. /**
  61. * Write one byte
  62. * @param [in] host pointer to OneWireHost instance
  63. * @param value byte value to write
  64. */
  65. void onewire_host_write(OneWireHost* host, uint8_t value);
  66. /**
  67. * Write one or more bytes
  68. * @param [in] host pointer to OneWireHost instance
  69. * @param [in] buffer pointer to the data to write
  70. * @param [in] count size of the data to write
  71. */
  72. void onewire_host_write_bytes(OneWireHost* host, const uint8_t* buffer, uint16_t count);
  73. /**
  74. * Start working with the bus
  75. * @param [in] host pointer to OneWireHost instance
  76. */
  77. void onewire_host_start(OneWireHost* host);
  78. /**
  79. * Stop working with the bus
  80. * @param [in] host pointer to OneWireHost instance
  81. */
  82. void onewire_host_stop(OneWireHost* host);
  83. /**
  84. * Reset previous search results
  85. * @param [in] host pointer to OneWireHost instance
  86. */
  87. void onewire_host_reset_search(OneWireHost* host);
  88. /**
  89. * Set the family code to search for
  90. * @param [in] host pointer to OneWireHost instance
  91. * @param [in] family_code device family code
  92. */
  93. void onewire_host_target_search(OneWireHost* host, uint8_t family_code);
  94. /**
  95. * Search for devices on the 1-Wire bus
  96. * @param [in] host pointer to OneWireHost instance
  97. * @param [out] new_addr pointer to the buffer to contain the unique ROM of the found device
  98. * @param [in] mode search mode
  99. * @return true on success, false otherwise
  100. */
  101. bool onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode);
  102. /**
  103. * Enable overdrive mode
  104. * @param [in] host pointer to OneWireHost instance
  105. * @param [in] set true to turn overdrive on, false to turn it off
  106. */
  107. void onewire_host_set_overdrive(OneWireHost* host, bool set);
  108. #ifdef __cplusplus
  109. }
  110. #endif