Skip to content

Commit 70a3612

Browse files
authored
Wokring GPIO (ARMmbed#29)
* GPIO port * fixed hw_types * delete TODO * remove ARCM_BASE * fixed naming issue * possible fixed for LED3 * working GPIO * GPIO is working * add function for gpio_is_connected
1 parent 4e85fbf commit 70a3612

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/PinNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ typedef enum {
113113
USBTX = PIN_55,
114114
USBRX = PIN_57,
115115

116+
//Button
117+
BUTTON1 = PIN_04,
118+
BUTTON2 = PIN_15,
119+
116120
// Not connected
117121
NC = (int)0xFFFFFFFF
118122
} PinName;

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/gpio_api.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
* limitations under the License.
1515
*/
1616
#include "gpio_api.h"
17+
#include "mbed_error.h"
1718
#include "pinmap.h"
1819
#include <ti/devices/cc32xx/inc/hw_types.h>
1920
#include <ti/devices/cc32xx/driverlib/pin.h>
2021
#include <ti/devices/cc32xx/driverlib/gpio.h>
2122
#include <ti/devices/cc32xx/inc/hw_ints.h>
2223
#include <ti/devices/cc32xx/driverlib/prcm.h>
2324

24-
#define PIN_RESERVED 0xFF
25-
2625

2726

2827
static const unsigned long g_ulPinToGPIOPinBit[64] =
@@ -79,17 +78,17 @@ static const PinMap PinMap_GPIO[] = {
7978

8079
{PIN_07, CC3220SF_GPIOA2_BASE, 0}, //GPIO_16
8180
{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)
81+
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_18 (Reserved) No package pin associate with this GPIO
82+
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_19 (Reserved) No package pin associate with this GPIO
83+
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_20 (Reserved) No package pin associate with this GPIO
84+
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_21 (Reserved) No package pin associate with this GPIO
8685
{PIN_15, CC3220SF_GPIOA2_BASE, 0}, //GPIO_22
8786
{PIN_16, CC3220SF_GPIOA2_BASE, 0}, //GPIO_23
8887

8988
{PIN_17, CC3220SF_GPIOA3_BASE, 0}, //GPIO_24
9089
{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)
90+
//{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_26 (Restricted Use; Antenna Selection 1 Only) No package pin associate with this GPIO
91+
//{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_27 (Restricted Use; Antenna Selection 1 Only) No package pin associate with this GPIO
9392
{PIN_18, CC3220SF_GPIOA3_BASE, 0}, //GPIO_28
9493
{PIN_20, CC3220SF_GPIOA3_BASE, 0}, //GPIO_29
9594
{PIN_53, CC3220SF_GPIOA3_BASE, 0}, //GPIO_30 (PM/Dig Mux)
@@ -108,6 +107,7 @@ uint32_t gpio_set(PinName pin)
108107
// with the object created for the pin
109108
void gpio_init(gpio_t *obj, PinName pin)
110109
{
110+
MBED_ASSERT(pin != (PinName)NC);
111111
unsigned long gpio_base = (unsigned long)pinmap_peripheral(pin, PinMap_GPIO);
112112
obj->gpio_port_base_addr = gpio_base;
113113
obj->pin = pin;
@@ -151,11 +151,12 @@ void gpio_mode(gpio_t *obj, PinMode mode)
151151

152152

153153
if(obj->dir == PIN_INPUT){ //setting the correct input pin mode from STD, PULL_UP, or PULL_DOWN
154-
PinModeSet(obj->pin, inPinTypes[mode]);
154+
PinModeSet(obj->pin, inPinTypes[mode]);
155+
pin_mode(obj->pin, mode);
155156
}
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+
else if(obj->dir == PIN_OUTPUT){ //setting the correct output pin mode from STD, open-drain PULL_UP, or open drain PULL_DOWN.
157158
PinModeSet(obj->pin, outPinTypes[mode]);
158-
PinConfigSet(obj->pin,outPinStrengths[0],outPinTypes[mode]);
159+
pin_mode(obj->pin, mode);
159160
}
160161

161162
}
@@ -168,16 +169,15 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
168169

169170
int gpio_is_connected(const gpio_t *obj)
170171
{
171-
// TODO
172-
return 0;
172+
return (obj->pin == NC);
173173
}
174174

175175
void gpio_write(gpio_t *obj, int value)
176176
{
177-
GPIOPinWrite(obj->gpio_port_base_addr, g_ulPinToGPIOPinBit[obj->pin], value<<(g_ulPinToGPIOPinBit[obj->pin]>>1));
177+
GPIOPinWrite(obj->gpio_port_base_addr, g_ulPinToGPIOPinBit[obj->pin], value*(g_ulPinToGPIOPinBit[obj->pin]));
178178
}
179179

180180
int gpio_read(gpio_t *obj)
181181
{
182-
return (int)GPIOPinRead(obj->gpio_port_base_addr,g_ulPinToGPIOPinBit[obj->pin]);
182+
return (GPIOPinRead(obj->gpio_port_base_addr,g_ulPinToGPIOPinBit[obj->pin]) != 0);
183183
}

0 commit comments

Comments
 (0)