gblink_pinconf.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: BSD-2-Clause
  2. // Copyright (c) 2023 KBEmbedded
  3. #ifndef __GBLINK_PINCONF_H__
  4. #define __GBLINK_PINCONF_H__
  5. #pragma once
  6. #include <furi.h>
  7. #include <furi_hal.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * Set one of the pre-configured pinouts
  13. *
  14. * @param handle Pointer to gblink handle
  15. * @param pinout Which pinout to use
  16. *
  17. * @note The gblink instance must not be gblink_start()'ed!
  18. *
  19. * @returns 0 on success, -1 if gblink instance is not gblink_stop()'ed.
  20. */
  21. int gblink_pin_set_default(void *handle, gblink_pinouts pinout);
  22. /**
  23. * Check if the pinout set matches a pre-configured one
  24. *
  25. * @param handle Pointer to gblink handle
  26. *
  27. * @returns The index of the pre-configured pinout or -1 on error
  28. */
  29. int gblink_pin_get_default(void *handle);
  30. /**
  31. * Set a GPIO pin to a specific pin mode for the EXT interface
  32. *
  33. * @param handle Pointer to gblink handle
  34. * @param pin Pin mode to assign to the gpio pin
  35. * @param pinnum GPIO pin number to assign pin mode to
  36. *
  37. * @note The gblink instance must not be gblink_start()'ed!
  38. *
  39. * @returns 0 on success, -1 if gblink instance is not gblink_stop()ed
  40. */
  41. int gblink_pin_set(void *handle, gblink_bus_pins pin, unsigned int pinum);
  42. /**
  43. * Get the pin number associated with the requested pin mode
  44. *
  45. *
  46. * @param handle Pointer to gblink handle
  47. * @param pin Pin mode to inquire about
  48. *
  49. * @returns Pin number of the requested pin or -1 on error
  50. */
  51. int gblink_pin_get(void *handle, gblink_bus_pins pin);
  52. /**
  53. * Set a gpio pin to a specific pin mode via GpioPin
  54. *
  55. * @param handle Pointer to gblink handle
  56. * @param pin Pin mode to assign to the gpio pin
  57. * @param gpio Which gpio pin to assign the pin mode
  58. *
  59. * @note The gblink instance must not be gblink_start()'ed!
  60. * @note There is no sane way to do bounds checking with this function, so be
  61. * careful when passing pointers to ensure they are actually Flipper GpioPin
  62. * references.
  63. *
  64. * @returns 0 on success, -1 if gblink instance is not gblink_stop()'ed.
  65. */
  66. int gblink_pin_set_by_gpiopin(void *handle, gblink_bus_pins pin, const GpioPin *gpio);
  67. /**
  68. * Get the GpioPin associated with the requested pin mode
  69. *
  70. * @param handle Pointer to gblink handle
  71. * @param pin Pin mode to inquire about
  72. *
  73. * @returns GpioPin pointer
  74. */
  75. const GpioPin *gblink_pin_get_by_gpiopin(void *handle, gblink_bus_pins pin);
  76. /**
  77. * Returns the pinnum of the highest usable, non-debug pin.
  78. *
  79. * @returns count of highest usable, non-debug pin or -1 on error
  80. */
  81. int gblink_pin_count_max(void);
  82. /**
  83. * Get the next usable, non-debug GPIO pin by number.
  84. *
  85. * The return value is the next usable, non-debug pin starting from pinnum and
  86. * will include pinnum if it is a valid pin.
  87. *
  88. * @param pinnum GPIO pin number to check if it is a valid pin.
  89. *
  90. * @returns -1 on error or no more valid pins. Any other value is the next usable
  91. * pin which can include pinnum if it is usable. If pinnum is not usable, the next
  92. * numbered pin which is will be returned or -1 if there are no further pins.
  93. */
  94. int gblink_pin_get_next(unsigned int pinnum);
  95. /**
  96. * Get the previous usable, non-debug GPIO pin by number.
  97. *
  98. * The return value is the previous usable, non-debug pin starting from pinnum and
  99. * will include pinnum if it is a valid pin.
  100. *
  101. * @param pinnum GPIO pin number to check if it is a valid pin.
  102. *
  103. * @returns -1 on error or no more valid pins. Any other value is the previous usable
  104. * pin which can include pinnum if it is usable. If pinnum is not usable, the previous
  105. * numbered pin which is will be returned or -1 if there are no further pins.
  106. */
  107. int gblink_pin_get_prev(unsigned int pinnum);
  108. /**
  109. * Load pin configuration from file automatically
  110. * Loads from .gblink_pinconf in app data folder
  111. *
  112. * @param gblink Pointer to gblink instance to set pins configurations
  113. *
  114. * @returns true on success, false on error
  115. *
  116. * @note This function should be called from the context of the application and
  117. * not any other threads as it uses the app data folder to load data from
  118. */
  119. bool gblink_pinconf_load(void *gblink);
  120. /**
  121. * Save current pin configuration to file automatically
  122. * Saves to .gblink_pinconf in app data folder
  123. *
  124. * @param gblink Pointer to gblink instance to save pins configurations
  125. *
  126. * @returns true on success, false on error
  127. *
  128. * @note This function should be called from the context of the application and
  129. * not any other threads as it uses the app data folder to save data to.
  130. */
  131. bool gblink_pinconf_save(void *gblink);
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif // __GBLINK_PINCONF_H__