15
15
*/
16
16
#include "gpio_api.h"
17
17
#include "pinmap.h"
18
+ #include <ti/devices/cc32xx/inc/hw_types.h>
19
+ #include <ti/devices/cc32xx/driverlib/pin.h>
20
+ #include <ti/devices/cc32xx/driverlib/gpio.h>
21
+ #include <ti/devices/cc32xx/inc/hw_ints.h>
22
+ #include <ti/devices/cc32xx/driverlib/prcm.h>
23
+
24
+ #define PIN_RESERVED 0xFF
25
+
26
+
27
+
28
+ static const unsigned long g_ulPinToGPIOPinBit [64 ] =
29
+ {
30
+ GPIO_PIN_2 ,GPIO_PIN_3 ,GPIO_PIN_4 ,GPIO_PIN_5 ,GPIO_PIN_6 ,GPIO_PIN_7 ,GPIO_PIN_0 ,GPIO_PIN_1 ,255 ,255 ,GPIO_PIN_2 ,
31
+ GPIO_PIN_3 ,GPIO_PIN_4 ,GPIO_PIN_5 ,GPIO_PIN_6 ,GPIO_PIN_7 ,GPIO_PIN_0 ,255 ,GPIO_PIN_4 ,GPIO_PIN_5 ,GPIO_PIN_1 ,255 ,
32
+ 255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,
33
+ 255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,
34
+ GPIO_PIN_7 ,255 ,255 ,255 ,255 ,GPIO_PIN_0 ,255 ,255 ,GPIO_PIN_6 ,255 ,GPIO_PIN_1 ,
35
+ 255 ,GPIO_PIN_2 ,GPIO_PIN_3 ,GPIO_PIN_4 ,GPIO_PIN_5 ,GPIO_PIN_6 ,GPIO_PIN_7 ,GPIO_PIN_0 ,GPIO_PIN_1
36
+ };
37
+
38
+ /* Table of GPIO input types */
39
+ const uint16_t inPinTypes [] = {
40
+ PIN_TYPE_STD , /* GPIO_CFG_IN_NOPULL */
41
+ PIN_TYPE_STD_PD , /* GPIO_CFG_IN_PD */
42
+ PIN_TYPE_STD_PU /* GPIO_CFG_IN_PU */
43
+
44
+ };
45
+
46
+ /* Table of GPIO output types */
47
+ const uint16_t outPinTypes [] = {
48
+ PIN_TYPE_STD , /* GPIO_CFG_OUT_STD */
49
+ PIN_TYPE_OD_PD , /* GPIO_CFG_OUT_OD_PD */
50
+ PIN_TYPE_OD_PU , /* GPIO_CFG_OUT_OD_PU */
51
+ PIN_TYPE_OD /* GPIO_CFG_OUT_OD_NOPULL */
52
+ };
53
+
54
+ /* Table of GPIO drive strengths */
55
+ const uint16_t outPinStrengths [] = {
56
+ PIN_STRENGTH_2MA , /* GPIO_CFG_OUT_STR_LOW */
57
+ PIN_STRENGTH_4MA , /* GPIO_CFG_OUT_STR_MED */
58
+ PIN_STRENGTH_6MA /* GPIO_CFG_OUT_STR_HIGH */
59
+ };
60
+
61
+ static const PinMap PinMap_GPIO [] = {
62
+ {PIN_50 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_00 (PM/Dig Mux)
63
+ {PIN_55 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_01
64
+ {PIN_57 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_02 (Dig/ADC Mux)
65
+ {PIN_58 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_03 (Dig/ADC Mux)
66
+ {PIN_59 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_04 (Dig/ADC Mux)
67
+ {PIN_60 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_05 (Dig/ADC Mux)
68
+ {PIN_61 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_06
69
+ {PIN_62 , CC3220SF_GPIOA0_BASE , 0 }, //GPIO_07
70
+
71
+ {PIN_63 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_08
72
+ {PIN_64 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_09
73
+ {PIN_01 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_10
74
+ {PIN_02 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_11
75
+ {PIN_03 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_12
76
+ {PIN_04 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_13
77
+ {PIN_05 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_14
78
+ {PIN_06 , CC3220SF_GPIOA1_BASE , 0 }, //GPIO_15
79
+
80
+ {PIN_07 , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_16
81
+ {PIN_08 , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_17
82
+ {PIN_RESERVED , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_18 (Reserved)
83
+ {PIN_RESERVED , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_19 (Reserved)
84
+ {PIN_RESERVED , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_20 (Reserved)
85
+ {PIN_RESERVED , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_21 (Reserved)
86
+ {PIN_15 , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_22
87
+ {PIN_16 , CC3220SF_GPIOA2_BASE , 0 }, //GPIO_23
88
+
89
+ {PIN_17 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_24
90
+ {PIN_21 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_25
91
+ {PIN_RESERVED , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_26 (Restricted Use; Antenna Selection 1 Only)
92
+ {PIN_RESERVED , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_27 (Restricted Use; Antenna Selection 1 Only)
93
+ {PIN_18 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_28
94
+ {PIN_20 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_29
95
+ {PIN_53 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_30 (PM/Dig Mux)
96
+ {PIN_45 , CC3220SF_GPIOA3_BASE , 0 }, //GPIO_31 (PM/Dig Mux)
97
+ {NC , NC , 0 }
98
+ };
18
99
19
100
// function to enable the GPIO pin
20
101
uint32_t gpio_set (PinName pin )
@@ -27,17 +108,62 @@ uint32_t gpio_set(PinName pin)
27
108
// with the object created for the pin
28
109
void gpio_init (gpio_t * obj , PinName pin )
29
110
{
30
- // TODO
111
+ unsigned long gpio_base = (unsigned long )pinmap_peripheral (pin , PinMap_GPIO );
112
+ obj -> gpio_port_base_addr = gpio_base ;
113
+ obj -> pin = pin ;
114
+
115
+
116
+ //figuring out PRCM GPIO CLOCK Index
117
+
118
+ unsigned short prcm_peripheral ;
119
+ switch (gpio_base )
120
+ {
121
+ case CC3220SF_GPIOA0_BASE :
122
+ prcm_peripheral = PRCM_GPIOA0 ;
123
+ break ;
124
+
125
+ case CC3220SF_GPIOA1_BASE :
126
+ prcm_peripheral = PRCM_GPIOA1 ;
127
+ break ;
128
+
129
+ case CC3220SF_GPIOA2_BASE :
130
+ prcm_peripheral = PRCM_GPIOA2 ;
131
+ break ;
132
+
133
+ case CC3220SF_GPIOA3_BASE :
134
+ prcm_peripheral = PRCM_GPIOA3 ;
135
+ break ;
136
+ default :
137
+ break ;
138
+ }
139
+
140
+ //initialize GPIO PORT clock
141
+ PRCMPeripheralClkEnable (prcm_peripheral , PRCM_RUN_MODE_CLK || PRCM_SLP_MODE_CLK );
142
+
143
+ //wait until gpio clock settle
144
+ while (!PRCMPeripheralStatusGet (prcm_peripheral )){}
145
+
31
146
}
32
147
33
148
void gpio_mode (gpio_t * obj , PinMode mode )
34
149
{
35
- // TODO
150
+ obj -> mode = mode ;
151
+
152
+
153
+ if (obj -> dir == PIN_INPUT ){ //setting the correct input pin mode from STD, PULL_UP, or PULL_DOWN
154
+ PinModeSet (obj -> pin , inPinTypes [mode ]);
155
+ }
156
+ else if (obj -> dir == PIN_OUTPUT ){ //setting the correct output pin mode from STD, open-drain PULL_UP, or open drain PULL_DOWN. It seem that Mbed does not have an option for open-drain no pull
157
+ PinModeSet (obj -> pin , outPinTypes [mode ]);
158
+ PinConfigSet (obj -> pin ,outPinStrengths [0 ],outPinTypes [mode ]);
159
+ }
160
+
36
161
}
37
162
38
163
void gpio_dir (gpio_t * obj , PinDirection direction )
39
164
{
40
- // TODO
165
+ obj -> dir = direction ;
166
+ GPIODirModeSet (obj -> gpio_port_base_addr , g_ulPinToGPIOPinBit [obj -> pin ],direction );
41
167
}
42
168
43
169
int gpio_is_connected (const gpio_t * obj )
@@ -48,11 +174,10 @@ int gpio_is_connected(const gpio_t *obj)
48
174
49
175
void gpio_write (gpio_t * obj , int value )
50
176
{
51
- //TODO
177
+ GPIOPinWrite ( obj -> gpio_port_base_addr , g_ulPinToGPIOPinBit [ obj -> pin ], value <<( g_ulPinToGPIOPinBit [ obj -> pin ]>> 1 ));
52
178
}
53
179
54
180
int gpio_read (gpio_t * obj )
55
181
{
56
- //TODO
57
- return 0 ;
182
+ return (int )GPIOPinRead (obj -> gpio_port_base_addr ,g_ulPinToGPIOPinBit [obj -> pin ]);
58
183
}
0 commit comments