6.5.3. GPIO

6.5.3.1. Functions

UINT8_t PLTFRM_checkGPIOEvt(void)

Typically called from the main system loop, this checks if any GPIO events (interrupts) have occurred. If so, the function internally calls the callback functions associated with those events.

Returns:If no events have been processed, 0 is returned. Otherwise, 1 is returned.
PLTFRM_sts_t PLTFRM_allocGPIOPin(UINT8_t devId, PLTFRM_gpioPortId_t portId, PLTFRM_gpioPortPin_t portPinNr, PLTFRM_gpioDirn_t pinDirn, PLTRM_gpioOutVal_t initOutVal, PLTFRM_gpioIntEdge_t intEdge, PLTFRM_intCbFunc_t cbFunc_p)

This function allocates GPIO ports and pins to devices. Allocation is nothing more than storing the information so that conflicts can be detected and avoided. Thus, this function ensures that no two devices end up using the same port and pin combination. It also does initialization of the GPIO port/pin for the device. This function is typically called during platform initialization.

Parameters:
  • devId – Identity of the device.
  • portId – Identity of the port.
  • portPinNr – Pin number on the identified port.
  • pinDirn – Direction in which the GPIO operates. Input implies signals coming to the MSP430 and vice versa. For example, an LED connected to a GPIO pin has output direction while a reed switch would be configured as input direction.
  • initOutVal – Initialization value. If pinDirn is PLTFRM_GPIO_PIN_DIRECTION_INPUT, this parameter is irrelevant and could be set to PLTFRM_GPIO_OUTPUT_NA.
  • intEdge – Positive or negative edge for the interrupts. If this is not an interrupt source, set this to PLTFRM_GPIO_INT_EDGE_NA. Interrupt sources can be connected to only ports PLTFRM_GPIO_PORT_3 and PLTFRM_GPIO_PORT_4.
  • cbFunc_p – Points to the callback function in case GPIO pin is associated with an interrupt source. If not, this should be NULL. If intEdge is not PLTFRM_GPIO_INT_EDGE_NA, a callback function is expected.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_HW_CONN, PLTFRM_STS_INV_HW_RESOURCE, PLTFRM_STS_RESOURCE_CONFLICT and PLTFRM_STS_INV_PARAM.

Example (LED1 connected to port 3, pin 0):

sts = PLTFRM_allocGPIOPin(PLTFRM_LED_1_DEV_ID,
                       PLTFRM_GPIO_PORT_3,
                       PLTFRM_GPIO_PORT_PIN_0,
                       PLTFRM_GPIO_PIN_DIRECTION_OUTPUT,
                       PLTFRM_GPIO_OUTPUT_LOW,
                       PLTFRM_GPIO_INT_EDGE_NA,
                       NULL);
if (sts != PLTFRM_STS_SUCCESS)
{
  SYS_fatal();
}
PLTFRM_sts_t PLTFRM_gpioPinIntCtrlOpn(PLTFRM_gpioPortId_t portId, PLTFRM_gpioPortPin_t portPinNr, PLTFRM_gpioIntCtrlOpn_t opn, UINT8_t clearIntFlag)

This function can be used to enable or disable interrupts on a GPIO port/pin. Typically it is used to enable interrupt following the processing of a previous interrupt. An easy way to call this function is via the defined macros PLTFRM_enaGPIOInt() and PLTFRM_disGPIOInt().

Parameters:
  • portId – Identity of the port. This is limited to values PLTFRM_GPIO_PORT_1 and PLTFRM_GPIO_PORT_2.
  • portPinNr – Pin number on the identified port.
  • opn – Specifies the operation, either to enable or disable the interrupts.
  • clearIntFlag – When set to 1, the interrupt pending flag is cleared before enabling the interrupt. This parameter is not relevant when opn is PLTFRM_DISABLE_GPIO_PIN_INT and therefore can be set to 0.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_INV_PARAM.

PLTFRM_sts_t PLTFRM_gpioEnablePull(PLTFRM_gpioPortId_t portId, PLTFRM_gpioPortPin_t portPinNr, PLTFRM_gpioPullType_t pullType)

Each GPIO pin is associated with a pull-up/pull-down resistor. This function configures the resistor in one of these two modes. An easy way to call this function is via the defined macros PLTFRM_gpioEnablePullDown() and PLTFRM_gpioEnablePullUp().

Parameters:
  • portId – Identity of the port.
  • portPinNr – Pin number on the identified port.
  • pullType – Set to either PLTFRM_GPIO_INPUT_PULL_DOWN or PLTFRM_GPIO_INPUT_PULL_UP.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_INV_PARAM.

PLTFRM_sts_t PLTFRM_gpioCfgIntEdge(PLTFRM_gpioPortId_t portId, PLTFRM_gpioPortPin_t portPinNr, PLTFRM_gpioIntEdge_t edgeType)

Configures the operation of port/pin with respect to its interrupt edge. If specified as PLTFRM_GPIO_INT_EDGE_POSITIVE, positive edge is configured. Otherwise, negative edge is configured.

Parameters:
  • portId – Identity of the port.
  • portPinNr – Pin number on the identified port.
  • edgeType – Specifies the interrupt edge to be configured.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure.

6.5.3.2. Macros

// Interrupt capable ports (Port 1 and Port 2)
#define PLTFRM_INT_CAP_GPIO_PORT_COUNT  2

#define PLTFRM_GPIO_PORT_SIZE  8

#define PLTFRM_disGPIOInt(portId, portPinNr) \
        PLTFRM_gpioPinIntCtrlOpn(portId, portPinNr, PLTFRM_DISABLE_GPIO_PIN_INT, 0x0)

#define PLTFRM_enaGPIOInt(portId, portPinNr, clearIntFlag) \
        PLTFRM_gpioPinIntCtrlOpn(portId, portPinNr, PLTFRM_ENABLE_GPIO_PIN_INT, clearIntFlag)

#define PLTFRM_gpioEnablePullDown(portId, portPinNr) \
                PLTFRM_gpioEnablePull(portId, portPinNr, PLTFRM_GPIO_INPUT_PULL_DOWN)

#define PLTFRM_gpioEnablePullUp(portId, portPinNr) \
                PLTFRM_gpioEnablePull(portId, portPinNr, PLTFRM_GPIO_INPUT_PULL_UP)

6.5.3.3. Type Definitions

typedef enum
{
   PLTFRM_GPIO_INT_EDGE_NA = 0,
   PLTFRM_GPIO_INT_EDGE_POSITIVE = 1,
   PLTFRM_GPIO_INT_EDGE_NEGATIVE = 2
} PLTFRM_gpioIntEdge_t;

typedef enum
{
   PLTFRM_GPIO_PIN_DIRECTION_INPUT = 0,
   PLTFRM_GPIO_PIN_DIRECTION_OUTPUT = 1
} PLTFRM_gpioDirn_t;

typedef enum
{
   PLTFRM_GPIO_PORT_1 = 0,
   PLTFRM_GPIO_PORT_2 = 1,
   PLTFRM_GPIO_PORT_3 = 2,
   PLTFRM_GPIO_PORT_4 = 3
} PLTFRM_gpioPortId_t;

typedef enum
{
   PLTFRM_GPIO_OUTPUT_LOW = 0,
   PLTFRM_GPIO_OUTPUT_HIGH = 1,
   PLTFRM_GPIO_OUTPUT_NA = 2   // Not applicable
} PLTRM_gpioOutVal_t;

typedef enum
{
   PLTFRM_GPIO_INPUT_LOW = 0,
   PLTFRM_GPIO_INPUT_HIGH = 1
} PLTRM_gpioInVal_t;

typedef enum
{
   PLTFRM_GPIO_INPUT_PULL_DOWN,
   PLTFRM_GPIO_INPUT_PULL_UP
} PLTFRM_gpioPullType_t;

typedef enum
{
   PLTFRM_GPIO_PORT_PIN_0,
   PLTFRM_GPIO_PORT_PIN_1,
   PLTFRM_GPIO_PORT_PIN_2,
   PLTFRM_GPIO_PORT_PIN_3,
   PLTFRM_GPIO_PORT_PIN_4,
   PLTFRM_GPIO_PORT_PIN_5,
   PLTFRM_GPIO_PORT_PIN_6,
   PLTFRM_GPIO_PORT_PIN_7
} PLTFRM_gpioPortPin_t;

typedef enum
{
   PLTFRM_ENABLE_GPIO_PIN_INT,
   PLTFRM_DISABLE_GPIO_PIN_INT
} PLTFRM_gpioIntCtrlOpn_t;

typedef enum
{
   PLTFRM_GLOBAL_INT_ENABLED,
   PLTFRM_GLOBAL_INT_DISABLED
} PLTFRM_globalIntState_t;

typedef void (*PLTFRM_intCbFunc_t)(UINT8_t devId);

typedef struct
{
   UINT8_t devId;
   PLTFRM_intCbFunc_t cbFunc_p;
} PLTFRM_intCapGPIOPortPinInfo_s;

typedef struct
{
   UINT8_t intFlags;
   PLTFRM_intCapGPIOPortPinInfo_s pinInfo[PLTFRM_GPIO_PORT_SIZE];
} PLTFRM_intCapGPIOPortInfo_s;

typedef struct
{
   UINT8_t devId;
} PLTFRM_gpioPortPinInfo_s;

typedef struct
{
   PLTFRM_gpioPortPinInfo_s pinInfo[PLTFRM_GPIO_PORT_SIZE];
} PLTFRM_gpioPortInfo_s;