one_wire_host.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 all devices */
  16. } OneWireHostSearchMode;
  17. typedef struct OneWireHost OneWireHost;
  18. /**
  19. * Allocate onewire host bus
  20. * @param pin
  21. * @return OneWireHost*
  22. */
  23. OneWireHost* onewire_host_alloc(const GpioPin* gpio_pin);
  24. /**
  25. * Deallocate onewire host bus
  26. * @param host
  27. */
  28. void onewire_host_free(OneWireHost* host);
  29. /**
  30. * Reset bus
  31. * @param host
  32. * @return bool
  33. */
  34. bool onewire_host_reset(OneWireHost* host);
  35. /**
  36. * Read one bit
  37. * @param host
  38. * @return bool
  39. */
  40. bool onewire_host_read_bit(OneWireHost* host);
  41. /**
  42. * Read one byte
  43. * @param host
  44. * @return uint8_t
  45. */
  46. uint8_t onewire_host_read(OneWireHost* host);
  47. /**
  48. * Read many bytes
  49. * @param host
  50. * @param buffer
  51. * @param count
  52. */
  53. void onewire_host_read_bytes(OneWireHost* host, uint8_t* buffer, uint16_t count);
  54. /**
  55. * Write one bit
  56. * @param host
  57. * @param value
  58. */
  59. void onewire_host_write_bit(OneWireHost* host, bool value);
  60. /**
  61. * Write one byte
  62. * @param host
  63. * @param value
  64. */
  65. void onewire_host_write(OneWireHost* host, uint8_t value);
  66. /**
  67. * Write many bytes
  68. * @param host
  69. * @param buffer
  70. * @param count
  71. */
  72. void onewire_host_write_bytes(OneWireHost* host, const uint8_t* buffer, uint16_t count);
  73. /**
  74. * Skip ROM command
  75. * @param host
  76. */
  77. void onewire_host_skip(OneWireHost* host);
  78. /**
  79. * Start working with the bus
  80. * @param host
  81. */
  82. void onewire_host_start(OneWireHost* host);
  83. /**
  84. * Stop working with the bus
  85. * @param host
  86. */
  87. void onewire_host_stop(OneWireHost* host);
  88. /**
  89. *
  90. * @param host
  91. */
  92. void onewire_host_reset_search(OneWireHost* host);
  93. /**
  94. *
  95. * @param host
  96. * @param family_code
  97. */
  98. void onewire_host_target_search(OneWireHost* host, uint8_t family_code);
  99. /**
  100. *
  101. * @param host
  102. * @param newAddr
  103. * @param mode
  104. * @return uint8_t
  105. */
  106. uint8_t onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode);
  107. #ifdef __cplusplus
  108. }
  109. #endif