one_wire_host.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. CONDITIONAL_SEARCH = 0, /**< Search for alarmed device */
  15. NORMAL_SEARCH = 1, /**< Search all devices */
  16. } OneWireHostSearchMode;
  17. typedef struct OneWireHost OneWireHost;
  18. /**
  19. * Allocate onewire host bus
  20. * @param gpio
  21. * @return OneWireHost*
  22. */
  23. OneWireHost* onewire_host_alloc();
  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. * Skip ROM command
  68. * @param host
  69. */
  70. void onewire_host_skip(OneWireHost* host);
  71. /**
  72. * Start working with the bus
  73. * @param host
  74. */
  75. void onewire_host_start(OneWireHost* host);
  76. /**
  77. * Stop working with the bus
  78. * @param host
  79. */
  80. void onewire_host_stop(OneWireHost* host);
  81. /**
  82. *
  83. * @param host
  84. */
  85. void onewire_host_reset_search(OneWireHost* host);
  86. /**
  87. *
  88. * @param host
  89. * @param family_code
  90. */
  91. void onewire_host_target_search(OneWireHost* host, uint8_t family_code);
  92. /**
  93. *
  94. * @param host
  95. * @param newAddr
  96. * @param mode
  97. * @return uint8_t
  98. */
  99. uint8_t onewire_host_search(OneWireHost* host, uint8_t* newAddr, OneWireHostSearchMode mode);
  100. #ifdef __cplusplus
  101. }
  102. #endif