GPIO Support — Details
pin = CYGHWR_HAL_LPC1XXX_GPIO(
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
bit, mode) which takes the following arguments:
- This identifies the GPIO port to which the pin is attached. Ports are identified numerically between 0 and 4.
- This gives the bit or pin number within the port. These are numbered from 0 to 31.
This defines the mode in which the pin is to be used. The following values are currently defined:
IN_PULLUPdefines the pin as a GPIO input with a pull up resistor,
IN_PULLDOWNdefines the pin as a GPIO input with a pull down resistor,
OUT_OPENDRAINdefines the pin as a GPIO output with an open drain,
OUT_PULLUPdefines the pin as a GPIO out with a pull up resistor,
OUT_PULLDOWNdefines the pin as a GPIO output with a pull down resistor,
ALT3define 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
configures the pin according to the descriptor and must be called
before any other
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.
|2019-03-19||eCosPro Non-Commercial Public License|