GPIO_BBB.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include "AP_HAL_Linux.h"
  3. #define SYSFS_GPIO_DIR "/sys/class/gpio"
  4. #define GPIO0_BASE 0x44E07000
  5. #define GPIO1_BASE 0x4804C000
  6. #define GPIO2_BASE 0x481AC000
  7. #define GPIO3_BASE 0x481AE000
  8. #define GPIO_SIZE 0x00000FFF
  9. // OE: 0 is output, 1 is input
  10. #define GPIO_OE 0x14d
  11. #define GPIO_IN 0x14e
  12. #define GPIO_OUT 0x14f
  13. #define LED_AMBER 117
  14. #define LED_BLUE 48
  15. #define LED_SAFETY 61
  16. #define SAFETY_SWITCH 116
  17. #define LOW 0
  18. #define HIGH 1
  19. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || \
  20. CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD || \
  21. CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
  22. CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
  23. CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
  24. #define LINUX_GPIO_NUM_BANKS 4
  25. #else
  26. // disable GPIO
  27. #define LINUX_GPIO_NUM_BANKS 0
  28. #endif
  29. // BeagleBone Black GPIO mappings
  30. #define BBB_USR0 53
  31. #define BBB_USR1 54
  32. #define BBB_USR2 55
  33. #define BBB_USR3 56
  34. #define BBB_P8_3 38
  35. #define BBB_P8_4 39
  36. #define BBB_P8_5 34
  37. #define BBB_P8_6 35
  38. #define BBB_P8_7 66
  39. #define BBB_P8_8 67
  40. #define BBB_P8_9 69
  41. #define BBB_P8_10 68
  42. #define BBB_P8_11 45
  43. #define BBB_P8_12 44
  44. #define BBB_P8_13 23
  45. #define BBB_P8_14 26
  46. #define BBB_P8_15 47
  47. #define BBB_P8_16 46
  48. #define BBB_P8_17 27
  49. #define BBB_P8_18 65
  50. #define BBB_P8_19 22
  51. #define BBB_P8_20 63
  52. #define BBB_P8_21 62
  53. #define BBB_P8_22 37
  54. #define BBB_P8_23 36
  55. #define BBB_P8_24 33
  56. #define BBB_P8_25 32
  57. #define BBB_P8_26 61
  58. #define BBB_P8_27 86
  59. #define BBB_P8_28 88
  60. #define BBB_P8_29 87
  61. #define BBB_P8_30 89
  62. #define BBB_P8_31 10
  63. #define BBB_P8_32 11
  64. #define BBB_P8_33 9
  65. #define BBB_P8_34 81
  66. #define BBB_P8_35 8
  67. #define BBB_P8_36 80
  68. #define BBB_P8_37 78
  69. #define BBB_P8_38 79
  70. #define BBB_P8_39 76
  71. #define BBB_P8_40 77
  72. #define BBB_P8_41 74
  73. #define BBB_P8_42 75
  74. #define BBB_P8_43 72
  75. #define BBB_P8_44 73
  76. #define BBB_P8_45 70
  77. #define BBB_P8_46 71
  78. #define BBB_P9_11 30
  79. #define BBB_P9_12 60
  80. #define BBB_P9_13 31
  81. #define BBB_P9_14 50
  82. #define BBB_P9_15 48
  83. #define BBB_P9_16 51
  84. #define BBB_P9_17 5
  85. #define BBB_P9_18 4
  86. #define BBB_P9_19 13
  87. #define BBB_P9_20 12
  88. #define BBB_P9_21 3
  89. #define BBB_P9_22 2
  90. #define BBB_P9_23 49
  91. #define BBB_P9_24 15
  92. #define BBB_P9_25 117
  93. #define BBB_P9_26 14
  94. #define BBB_P9_27 115
  95. #define BBB_P9_28 113
  96. #define BBB_P9_29 111
  97. #define BBB_P9_30 112
  98. #define BBB_P9_31 110
  99. #define BBB_P9_41 20
  100. #define BBB_P9_42 7
  101. namespace Linux {
  102. class GPIO_BBB : public AP_HAL::GPIO {
  103. private:
  104. struct GPIO {
  105. volatile uint32_t *base;
  106. volatile uint32_t *oe;
  107. volatile uint32_t *in;
  108. volatile uint32_t *out;
  109. } gpio_bank[LINUX_GPIO_NUM_BANKS];
  110. public:
  111. GPIO_BBB();
  112. void init() override;
  113. void pinMode(uint8_t pin, uint8_t output) override;
  114. uint8_t read(uint8_t pin) override;
  115. void write(uint8_t pin, uint8_t value) override;
  116. void toggle(uint8_t pin) override;
  117. /* Alternative interface: */
  118. AP_HAL::DigitalSource* channel(uint16_t n) override;
  119. /* return true if USB cable is connected */
  120. bool usb_connected(void) override;
  121. };
  122. }