Name

GPIO Support — Details

Synopsis

#include <cyg/hal/hal_io.h>
    

pin = CYGHWR_HAL_LPC1XXX_GPIO( port , bit , mode );

CYGHWR_HAL_LPC1XXX_GPIO_SET ( pin );

CYGHWR_HAL_LPC1XXX_GPIO_OUT ( pin , val );

CYGHWR_HAL_LPC1XXX_GPIO_IN ( pin , *val );

Description

The LPC1XXX HAL provides a number of macros to support the encoding of GPIO pin identity and configuration into a single 32 bit descriptor. This is useful to drivers and other packages that need to configure and use different lines for different devices.

A descriptor is created with CYGHWR_HAL_LPC1XXX_GPIO(port, bit, mode) which takes the following arguments:

port
This identifies the GPIO port to which the pin is attached. Ports are identified numerically between 0 and 4.
bit
This gives the bit or pin number within the port. These are numbered from 0 to 31.
mode
This defines the mode in which the pin is to be used. The following values are currently defined: IN_PULLUP defines the pin as a GPIO input with a pull up resistor, IN_PULLDOWN defines the pin as a GPIO input with a pull down resistor, OUT_OPENDRAIN defines the pin as a GPIO output with an open drain, OUT_PULLUP defines the pin as a GPIO out with a pull up resistor, OUT_PULLDOWN defines the pin as a GPIO output with a pull down resistor, ALT1, ALT2, ALT3 define the pin as a line under the control of a peripheral. This set may be extended as further requirements emerge, so check the sources for new definitions.

The following examples show how this macro may be used:

// Define port 0 pin 2 as a peripheral pin for alternate peripheral 1
#define CYGHWR_HAL_LPC1XXX_UART0_TX             CYGHWR_HAL_LPC1XXX_GPIO( 0,  2, ALT1 )

// Define port 0 pin 16 as a GPIO output pin with a pull up resistor
#define CYGHWR_HAL_LPC1XXX_SPI_CS0              CYGHWR_HAL_LPC1XXX_GPIO(0, 16, OUT_PULLUP)

Additionally, the macro CYGHWR_HAL_LPC1XXX_GPIO_NONE may be used in place of a pin descriptor and has a value that no valid descriptor can take. It may therefore be used as a placeholder where no GPIO pin is present or to be used.

The remaining macros all take a GPIO pin descriptor as an argument. CYGHWR_HAL_LPC1XXX_GPIO_SET configures the pin according to the descriptor and must be called before any other macros. CYGHWR_HAL_LPC1XXX_GPIO_OUT sets the output to the value of the least significant bit of the val argument. The val argument of CYGHWR_HAL_LPC1XXX_GPIO_IN should be a pointer to an int, which will be set to 0 if the pin input is zero, and 1 otherwise.