Guest User

Untitled

a guest
Jun 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- */
  2. /* Pinmux setting working in conjuction with the universal cape */
  3.  
  4. /* [[
  5. * Comments in here in [[ double square brackets ]] are meta comments useful
  6. * while working on a review of this API.
  7. *
  8. * Note, this _only_ addresses pinmux configuration, not anything how to write
  9. * or read bits on GPIOs etc. This is left up to the application (I usually just
  10. * memory map the proper regions in code or PRU, but there are many different
  11. * ways including writing to device-paths).
  12. *
  13. * So this is a separate can of worms explicitly a non-goal of this API.
  14. *
  15. * ]]
  16. */
  17.  
  18. #ifndef BEAGLEBONE_PINMUX_H
  19. #define BEAGLEBONE_PINMUX_H
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. #include <stdint.h>
  26.  
  27. /* The different types of physical header configurations. */
  28.  
  29. /* [[ This should have good names that are also not too specific
  30. * (e.g. BEAGLEBONE_BLACK would not cover Beaglebone Green. ]]
  31. */
  32. enum BeagleboneHeaderConfiguration {
  33. BEAGLEBONE_NONE, /* This is not a supported Beaglebone. */
  34. /* [[ the old white Beaglebone, what was the configuration there ? ]] */
  35. BEAGLEBONE_2x46, /* Beaglebone Black, Green etc. Headers P8, P9 */
  36. BEAGLEBONE_2x36, /* Pocketbeagle; Headers P1, P2 */
  37. BEAGLEBONE_BLUE, /* Various headers [[hopefully they have names?]] */
  38. };
  39.  
  40. enum BeaglebonePinType {
  41. PIN_TYPE_GPIO_IN,
  42. PIN_TYPE_GPIO_OUT,
  43. PIN_TYPE_PRU_IN,
  44. PIN_TYPE_PRU_OUT,
  45. PIN_TYPE_PWM,
  46. PIN_TYPE_TIMER,
  47. PIN_TYPE_ANALOG_IN,
  48. PIN_TYPE_QEP,
  49. PIN_TYPE_CAN,
  50. PIN_TYPE_SPI,
  51. PIN_TYPE_SPI_CS,
  52. PIN_TYPE_I2C,
  53. PIN_TYPE_UART,
  54. /* [[ what else ? ]]
  55. [[ Do we need qualifications ? Is it ever possible to have
  56. e.g. either GPIO 12 or 21 on a pin, so that we'd need to
  57. qualify which GPIO ? Similar: can a single pin be either part
  58. of SPI_0 or SPI_1 ? ]] */
  59. };
  60.  
  61. /* Optional mods for */
  62. enum BeaglebonePinModifier {
  63. PIN_MOD_NONE = 0,
  64. PIN_MOD_PULL_UP = 1,
  65. PIN_MOD_PULL_DOWN = 2,
  66. PIN_MOD_DRIVE_HIGH = 4,
  67. PIN_MOD_DRIVE_LOW = 8,
  68. /* [[ there are probably others, such as slow rise ? ]] */
  69. };
  70.  
  71. /* Result of the configuration call */
  72. enum BeaglebonePinConfigResult {
  73. PIN_CONFIG_SUCCESS,
  74. PIN_CONFIG_INVALID_HEADER, /* unknown header number on this BB */
  75. PIN_CONFIG_INVALID_PIN, /* unknown pin number on this BB header */
  76. PIN_CONFIG_INVALID_TYPE, /* Pin cannot be conf'd to this type */
  77. PIN_CONFIG_INVALID_MOD, /* Invalid modification or combo. */
  78. };
  79.  
  80. /* Utility function: Return the header configuration of the currently
  81. * running beaglebone. This helps to decide which headers and pins are
  82. * available.
  83. */
  84. enum BeagleboneHeaderConfiguration bb_discover_header_config(void);
  85.  
  86. /* Configure pin on beaglebone. The configuration might fail if you attempt
  87. * to configure a pin that is not valid on the beaglebone this is running
  88. * on. For instance: valid header numbers for the Beaglebone Black are 8 or 9,
  89. * while on the Pocketbeagle it is 1 or 2.
  90. *
  91. * "header_number" is the number of the header on this Beaglebone as shown
  92. * on the silk screen.
  93. * "pin" The pin number on the given header. See silk-screen for
  94. * guidance which is pin 1.
  95. *
  96. * [[ Instead of the header + pin thing, should we have some defines such
  97. * as BB_P8_13 defines (as it is often done) that essentially just refers
  98. * to the internal numbering of the Sitara and then do the pinmapping from
  99. * there ? this requires however, that different Beagleboards have disjoint
  100. * sets of pins, which looks like it is at least true currently with
  101. * P8, P9 (BBB) vs P1, P2 (Pocketbeagle) prefix
  102. *
  103. * It would require some set of #defines or enums in the global namespace
  104. * though.
  105. * ]]
  106. *
  107. * "type" The functional type this pin should be configured to. For
  108. * each pin, there is only a subset available.
  109. * "pin_mode" is a bit-ored combination of BeaglebonePinModifier.
  110. *
  111. * [[ Instead of type + pin_mode, should we just have them OR-ed together ?
  112. * PIN_TYPE_GPIO_IN | PIN_MOD_PULL_UP
  113. * This is shorter to write, but also muddies the type-safetey and clarity ]]
  114. */
  115. enum BeaglebonePinConfigResult bb_config_pin(int header_number, int pin,
  116. enum BeaglebonePinType type,
  117. uint32_t pin_mods);
  118.  
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122.  
  123. #endif /* BEAGLEBONE_PINMUX_H */
Add Comment
Please, Sign In to add comment