Skip to content

Commit

Permalink
Wokring GPIO (ARMmbed#29)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dragoniteArm authored Jul 13, 2018
1 parent 4e85fbf commit 70a3612
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/PinNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ typedef enum {
USBTX = PIN_55,
USBRX = PIN_57,

//Button
BUTTON1 = PIN_04,
BUTTON2 = PIN_15,

// Not connected
NC = (int)0xFFFFFFFF
} PinName;
Expand Down
30 changes: 15 additions & 15 deletions targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/
#include "gpio_api.h"
#include "mbed_error.h"
#include "pinmap.h"
#include <ti/devices/cc32xx/inc/hw_types.h>
#include <ti/devices/cc32xx/driverlib/pin.h>
#include <ti/devices/cc32xx/driverlib/gpio.h>
#include <ti/devices/cc32xx/inc/hw_ints.h>
#include <ti/devices/cc32xx/driverlib/prcm.h>

#define PIN_RESERVED 0xFF



static const unsigned long g_ulPinToGPIOPinBit[64] =
Expand Down Expand Up @@ -79,17 +78,17 @@ static const PinMap PinMap_GPIO[] = {

{PIN_07, CC3220SF_GPIOA2_BASE, 0}, //GPIO_16
{PIN_08, CC3220SF_GPIOA2_BASE, 0}, //GPIO_17
{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_18 (Reserved)
{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_19 (Reserved)
{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_20 (Reserved)
{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_21 (Reserved)
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_18 (Reserved) No package pin associate with this GPIO
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_19 (Reserved) No package pin associate with this GPIO
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_20 (Reserved) No package pin associate with this GPIO
//{PIN_RESERVED, CC3220SF_GPIOA2_BASE, 0}, //GPIO_21 (Reserved) No package pin associate with this GPIO
{PIN_15, CC3220SF_GPIOA2_BASE, 0}, //GPIO_22
{PIN_16, CC3220SF_GPIOA2_BASE, 0}, //GPIO_23

{PIN_17, CC3220SF_GPIOA3_BASE, 0}, //GPIO_24
{PIN_21, CC3220SF_GPIOA3_BASE, 0}, //GPIO_25
{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_26 (Restricted Use; Antenna Selection 1 Only)
{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_27 (Restricted Use; Antenna Selection 1 Only)
//{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_26 (Restricted Use; Antenna Selection 1 Only) No package pin associate with this GPIO
//{PIN_RESERVED, CC3220SF_GPIOA3_BASE, 0}, //GPIO_27 (Restricted Use; Antenna Selection 1 Only) No package pin associate with this GPIO
{PIN_18, CC3220SF_GPIOA3_BASE, 0}, //GPIO_28
{PIN_20, CC3220SF_GPIOA3_BASE, 0}, //GPIO_29
{PIN_53, CC3220SF_GPIOA3_BASE, 0}, //GPIO_30 (PM/Dig Mux)
Expand All @@ -108,6 +107,7 @@ uint32_t gpio_set(PinName pin)
// with the object created for the pin
void gpio_init(gpio_t *obj, PinName pin)
{
MBED_ASSERT(pin != (PinName)NC);
unsigned long gpio_base = (unsigned long)pinmap_peripheral(pin, PinMap_GPIO);
obj->gpio_port_base_addr = gpio_base;
obj->pin = pin;
Expand Down Expand Up @@ -151,11 +151,12 @@ void gpio_mode(gpio_t *obj, PinMode mode)


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

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

int gpio_is_connected(const gpio_t *obj)
{
// TODO
return 0;
return (obj->pin == NC);
}

void gpio_write(gpio_t *obj, int value)
{
GPIOPinWrite(obj->gpio_port_base_addr, g_ulPinToGPIOPinBit[obj->pin], value<<(g_ulPinToGPIOPinBit[obj->pin]>>1));
GPIOPinWrite(obj->gpio_port_base_addr, g_ulPinToGPIOPinBit[obj->pin], value*(g_ulPinToGPIOPinBit[obj->pin]));
}

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

0 comments on commit 70a3612

Please sign in to comment.