api-gpio.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include "api-hal-gpio.h"
  3. #include <furi/valuemutex.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct {
  8. ValueMutex* gpio_mutex;
  9. GpioPin* gpio;
  10. } GpioDisableRecord;
  11. /**
  12. * Init GPIO API
  13. * @return true on successful gpio initialization, false otherwize
  14. */
  15. bool gpio_api_init();
  16. /**
  17. * Init GPIO
  18. * @param gpio GpioPin instance
  19. * @param mode GpioMode gpio mode
  20. */
  21. void gpio_init(const GpioPin* gpio, const GpioMode mode);
  22. /**
  23. * Init GPIO, extended version
  24. * @param gpio GpioPin instance
  25. * @param mode GpioMode gpio mode
  26. * @param pull GpioPull gpio pull mode
  27. * @param speed GpioSpeed gpio speed
  28. */
  29. void gpio_init_ex(
  30. const GpioPin* gpio,
  31. const GpioMode mode,
  32. const GpioPull pull,
  33. const GpioSpeed speed);
  34. /**
  35. * Write value to GPIO
  36. * @param gpio GpioPin instance
  37. * @param state false = LOW, true = HIGH
  38. */
  39. static inline void gpio_write(const GpioPin* gpio, const bool state) {
  40. hal_gpio_write(gpio, state);
  41. }
  42. /**
  43. * Read value from GPIO
  44. * @param gpio GpioPin instance
  45. * @return false = LOW, true = HIGH
  46. */
  47. static inline bool gpio_read(const GpioPin* gpio) {
  48. return hal_gpio_read(gpio);
  49. }
  50. /**
  51. * Put GPIO to Z-state
  52. * @param gpio_record GpioDisableRecord instance
  53. */
  54. void gpio_disable(GpioDisableRecord* gpio_record);
  55. /**
  56. * Get GPIO record
  57. * @param name name of record
  58. * @return ValueMutex instance
  59. */
  60. ValueMutex* gpio_open_mutex(const char* name);
  61. /**
  62. * Get GPIO record and acquire mutex
  63. * @param name name of record
  64. * @return GpioPin instance
  65. */
  66. GpioPin* gpio_open(const char* name);
  67. /**
  68. * Get RFID IN level
  69. * @return false = LOW, true = HIGH
  70. */
  71. bool get_rfid_in_level();
  72. #ifdef __cplusplus
  73. }
  74. #endif