armbianio.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef _ARMBIANIO_H
  2. #define _ARMBIANIO_H
  3. //
  4. // SPI_LCD using the SPI interface
  5. // Copyright (c) 2017 Larry Bank
  6. // email: bitbank@pobox.com
  7. // Project started 4/25/2017
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #define GPIO_OUT 0
  23. #define GPIO_IN 1
  24. // Only available on RPI boards
  25. #define GPIO_IN_PULLUP 2
  26. #define EDGE_FALLING 0
  27. #define EDGE_RISING 1
  28. #define EDGE_BOTH 2
  29. #define EDGE_NONE 3
  30. // Virtual header pin number to access the on-board IR receiver module
  31. // with GPIO functions (since it's just a digital input connected to a GPIO)
  32. #define IR_PIN 50
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. //
  37. // Initialize the library
  38. // 1 = success, 0 = failure
  39. //
  40. // Convenience function to behave like original API. Calls AIOInitBoard with
  41. // NULL
  42. //
  43. int AIOInit(void);
  44. //
  45. // Initialize the library
  46. // 1 = success, 0 = failure
  47. //
  48. // On Armbian 4.1x, pBoardName can be NULL and it will read the name internally
  49. // for non-Armbian (e.g. Raspberry Pi) or earlier builds of Armbian, pass the
  50. // board name to get the correct GPIO pin mappings
  51. //
  52. int AIOInitBoard(const char *pBoardName);
  53. // Free the resources
  54. void AIOShutdown(void);
  55. //
  56. // Returns the name of the board you're running on
  57. // or "Unknown" for an unsupported board
  58. //
  59. const char * AIOGetBoardName(void);
  60. //
  61. // Returns a file handle to the I2C device and address specified
  62. // -1 if it fails to open
  63. //
  64. int AIOOpenI2C(int iChannel, int iAddress);
  65. //
  66. // Returns a file handle to the SPI device specified
  67. // -1 if it fails to open
  68. //
  69. int AIOOpenSPI(int iChannel, int iSpeed);
  70. //
  71. // Close the file handle for the I2C bus
  72. //
  73. void AIOCloseI2C(int iHandle);
  74. //
  75. // Close the file handle for the SPI bus
  76. //
  77. void AIOCloseSPI(int iHandle);
  78. //
  79. // Read bytes from the I2C device
  80. // Pass the "starting" register number
  81. // Returns the number of bytes read or -1 for error
  82. //
  83. int AIOReadI2C(int iHandle, unsigned char ucRegister, unsigned char *buf, int iCount);
  84. //
  85. // Write data to the I2C device starting at the given register
  86. // returns the number of bytes written or -1 for error
  87. //
  88. int AIOWriteI2C(int iHandle, unsigned char ucRegister, unsigned char *buf, int iCount);
  89. //
  90. // Read data from the SPI device
  91. // returns the number of bytes read or -1 for error
  92. //
  93. int AIOReadSPI(int iHandle, unsigned char *buf, int iCount);
  94. //
  95. // Write data to the SPI device
  96. // returns the number of bytes written or -1 for error
  97. //
  98. int AIOWriteSPI(int iHandle, unsigned char *buf, int iCount);
  99. //
  100. // Perform a simultaneous read and write on the SPI device
  101. // returns the number of bytes transferred or -1 for error
  102. //
  103. int AIOReadWriteSPI(int iHandle, unsigned char *inbuf, unsigned char *outbuf, int iCount);
  104. //
  105. // Boolean indicating if the current PCB has a built-in IR receiver
  106. //
  107. int AIOHasIR(void);
  108. //
  109. // Boolean indicating if the current PCB has a button/key on it
  110. //
  111. int AIOHasButton(void);
  112. //
  113. // Read the button on the PCB (if present)
  114. //
  115. int AIOReadButton(void);
  116. //
  117. // Configure a GPIO pin for input or output
  118. // (GPIO_IN or GPIO_OUT)
  119. //
  120. int AIOAddGPIO(int iPin, int iDirection);
  121. typedef void (*AIOCALLBACK)(int iPin);
  122. //
  123. // Set edge to call the given function when the state
  124. // changes. AIOAddGPIO must be called first with direction
  125. // set to GPIO_IN
  126. //
  127. int AIOAddGPIOCallback(int iPin, AIOCALLBACK callback);
  128. //
  129. // Set pointer in callback list to NULL and set edge
  130. // to none
  131. //
  132. int AIORemoveGPIOCallback(int iPin);
  133. // The IR counterparts
  134. typedef void (*AIOIRCALLBACK)(int *codeArray);
  135. int AIOAddGPIOIRCallback(int iPin, AIOIRCALLBACK callback);
  136. int AIORemoveGPIOIRCallback(int iPin);
  137. //
  138. // Release a GPIO pin
  139. //
  140. void AIORemoveGPIO(int iPin);
  141. //
  142. // Read the state of a GPIO input pin
  143. // returns 0 or 1
  144. //
  145. int AIOReadGPIO(int iPin);
  146. //
  147. // Sets the state of a GPIO output pin
  148. // Valid states are 1 (on) or 0 (off)
  149. //
  150. int AIOWriteGPIO(int iPin, int iValue);
  151. //
  152. // Set edge value for an open pin
  153. //
  154. int AIOWriteGPIOEdge(int iPin, int iEdge);
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif // _ARMBIANIO_H