one_wire_slave.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file one_wire_slave.h
  3. *
  4. * 1-Wire slave library.
  5. */
  6. #pragma once
  7. #include <stddef.h>
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include <furi_hal_gpio.h>
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef struct OneWireDevice OneWireDevice;
  15. typedef struct OneWireSlave OneWireSlave;
  16. typedef void (*OneWireSlaveResetCallback)(void* context);
  17. typedef void (*OneWireSlaveResultCallback)(void* context);
  18. typedef bool (*OneWireSlaveCommandCallback)(uint8_t command, void* context);
  19. /**
  20. * Allocate onewire slave
  21. * @param gpio_pin
  22. * @return OneWireSlave*
  23. */
  24. OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin);
  25. /**
  26. * Free onewire slave
  27. * @param bus
  28. */
  29. void onewire_slave_free(OneWireSlave* bus);
  30. /**
  31. * Start working with the bus
  32. * @param bus
  33. */
  34. void onewire_slave_start(OneWireSlave* bus);
  35. /**
  36. * Stop working with the bus
  37. * @param bus
  38. */
  39. void onewire_slave_stop(OneWireSlave* bus);
  40. /**
  41. * TODO: description comment
  42. */
  43. bool onewire_slave_receive_bit(OneWireSlave* bus);
  44. /**
  45. * TODO: description comment
  46. */
  47. bool onewire_slave_send_bit(OneWireSlave* bus, bool value);
  48. /**
  49. * Send data
  50. * @param bus
  51. * @param data
  52. * @param data_size
  53. * @return bool
  54. */
  55. bool onewire_slave_send(OneWireSlave* bus, const uint8_t* data, size_t data_size);
  56. /**
  57. * Receive data
  58. * @param bus
  59. * @param data
  60. * @param data_size
  61. * @return bool
  62. */
  63. bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, size_t data_size);
  64. /**
  65. * Set a callback to be called on each reset
  66. * @param bus
  67. * @param callback
  68. * @param context
  69. */
  70. void onewire_slave_set_reset_callback(
  71. OneWireSlave* bus,
  72. OneWireSlaveResetCallback callback,
  73. void* context);
  74. /**
  75. * Set a callback to be called on each command
  76. * @param bus
  77. * @param callback
  78. * @param context
  79. */
  80. void onewire_slave_set_command_callback(
  81. OneWireSlave* bus,
  82. OneWireSlaveCommandCallback callback,
  83. void* context);
  84. /**
  85. * Set a callback to report emulation success
  86. * @param bus
  87. * @param result_cb
  88. * @param context
  89. */
  90. void onewire_slave_set_result_callback(
  91. OneWireSlave* bus,
  92. OneWireSlaveResultCallback result_cb,
  93. void* context);
  94. #ifdef __cplusplus
  95. }
  96. #endif