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