MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
GPIO_Adapter

Overview

Data Structures

struct  hal_gpio_pin_config_t
 The pin config struct of GPIO adapter. More...
 

Macros

#define HAL_GPIO_HANDLE_SIZE   (16U)
 Definition of GPIO adapter handle size. More...
 
#define GPIO_HANDLE_DEFINE(name)   uint32_t name[((HAL_GPIO_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
 Defines the gpio handle. More...
 
#define HAL_GPIO_ISR_PRIORITY   (3U)
 Definition of GPIO adapter isr priority. More...
 

Typedefs

typedef void * hal_gpio_handle_t
 The handle of GPIO adapter. More...
 
typedef void(* hal_gpio_callback_t )(void *param)
 The callback function of GPIO adapter. More...
 

Enumerations

enum  hal_gpio_interrupt_trigger_t {
  kHAL_GpioInterruptDisable = 0x0U,
  kHAL_GpioInterruptLogicZero = 0x1U,
  kHAL_GpioInterruptRisingEdge = 0x2U,
  kHAL_GpioInterruptFallingEdge = 0x3U,
  kHAL_GpioInterruptEitherEdge = 0x4U,
  kHAL_GpioInterruptLogicOne = 0x5U
}
 The interrupt trigger of GPIO adapter. More...
 
enum  hal_gpio_status_t {
  kStatus_HAL_GpioSuccess = kStatus_Success,
  kStatus_HAL_GpioError = MAKE_STATUS(kStatusGroup_HAL_GPIO, 1),
  kStatus_HAL_GpioLackSource = MAKE_STATUS(kStatusGroup_HAL_GPIO, 2),
  kStatus_HAL_GpioPinConflict = MAKE_STATUS(kStatusGroup_HAL_GPIO, 3)
}
 The status of GPIO adapter. More...
 
enum  hal_gpio_direction_t {
  kHAL_GpioDirectionOut = 0x00U,
  kHAL_GpioDirectionIn
}
 The direction of GPIO adapter. More...
 

Functions

hal_gpio_status_t HAL_GpioInit (hal_gpio_handle_t gpioHandle, hal_gpio_pin_config_t *pinConfig)
 Initializes an GPIO instance with the GPIO handle and the user configuration structure. More...
 
hal_gpio_status_t HAL_GpioDeinit (hal_gpio_handle_t gpioHandle)
 Deinitializes a GPIO instance. More...
 
hal_gpio_status_t HAL_GpioGetInput (hal_gpio_handle_t gpioHandle, uint8_t *pinState)
 Gets the pin voltage. More...
 
hal_gpio_status_t HAL_GpioSetOutput (hal_gpio_handle_t gpioHandle, uint8_t pinState)
 Sets the pin voltage. More...
 
hal_gpio_status_t HAL_GpioGetTriggerMode (hal_gpio_handle_t gpioHandle, hal_gpio_interrupt_trigger_t *gpioTrigger)
 Gets the pin interrupt trigger mode. More...
 
hal_gpio_status_t HAL_GpioSetTriggerMode (hal_gpio_handle_t gpioHandle, hal_gpio_interrupt_trigger_t gpioTrigger)
 Sets the pin interrupt trigger mode. More...
 
hal_gpio_status_t HAL_GpioInstallCallback (hal_gpio_handle_t gpioHandle, hal_gpio_callback_t callback, void *callbackParam)
 Installs a callback and callback parameter. More...
 
hal_gpio_status_t HAL_GpioWakeUpSetting (hal_gpio_handle_t gpioHandle, uint8_t enable)
 Enables or disables the GPIO wake-up feature. More...
 
hal_gpio_status_t HAL_GpioEnterLowpower (hal_gpio_handle_t gpioHandle)
 Prepares to enter low power consumption. More...
 
hal_gpio_status_t HAL_GpioExitLowpower (hal_gpio_handle_t gpioHandle)
 Restores from low power consumption. More...
 

Data Structure Documentation

struct hal_gpio_pin_config_t

Macro Definition Documentation

#define HAL_GPIO_HANDLE_SIZE   (16U)
#define GPIO_HANDLE_DEFINE (   name)    uint32_t name[((HAL_GPIO_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]

This macro is used to define a 4 byte aligned gpio handle. Then use "(hal_gpio_handle_t)name" to get the gpio handle.

The macro should be global and could be optional. You could also define gpio handle by yourself.

This is an example,

* GPIO_HANDLE_DEFINE(gpioHandle);
*
Parameters
nameThe name string of the gpio handle.
#define HAL_GPIO_ISR_PRIORITY   (3U)

Typedef Documentation

typedef void* hal_gpio_handle_t
typedef void(* hal_gpio_callback_t)(void *param)

Enumeration Type Documentation

Enumerator
kHAL_GpioInterruptDisable 

Interrupt disable.

kHAL_GpioInterruptLogicZero 

Interrupt when logic zero.

kHAL_GpioInterruptRisingEdge 

Interrupt on rising edge.

kHAL_GpioInterruptFallingEdge 

Interrupt on falling edge.

kHAL_GpioInterruptEitherEdge 

Interrupt on either edge.

kHAL_GpioInterruptLogicOne 

Interrupt when logic one.

Enumerator
kStatus_HAL_GpioSuccess 

Success.

kStatus_HAL_GpioError 

Failed.

kStatus_HAL_GpioLackSource 

Lack of sources.

kStatus_HAL_GpioPinConflict 

PIN conflict.

Enumerator
kHAL_GpioDirectionOut 

Out.

kHAL_GpioDirectionIn 

In.

Function Documentation

hal_gpio_status_t HAL_GpioInit ( hal_gpio_handle_t  gpioHandle,
hal_gpio_pin_config_t pinConfig 
)

This function configures the GPIO module with user-defined settings. The user can configure the configuration structure. The parameter gpioHandle is a pointer to point to a memory space of size HAL_GPIO_HANDLE_SIZE allocated by the caller. Example below shows how to use this API to configure the GPIO.

* GPIO_HANDLE_DEFINE(g_GpioHandle);
* config.direction = kHAL_GpioDirectionOut;
* config.port = 0;
* config.pin = 0;
* config.level = 0;
* HAL_GpioInit((hal_gpio_handle_t)g_GpioHandle, &config);
*
Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define the handle in the following two ways: GPIO_HANDLE_DEFINE(gpioHandle); or uint32_t gpioHandle[((HAL_GPIO_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
pinConfigPointer to user-defined configuration structure.
Return values
kStatus_HAL_GpioErrorAn error occurred while initializing the GPIO.
kStatus_HAL_GpioPinConflictThe pair of the pin and port passed by pinConfig is initialized.
kStatus_HAL_GpioSuccessGPIO initialization succeed
hal_gpio_status_t HAL_GpioDeinit ( hal_gpio_handle_t  gpioHandle)

This function disables the trigger mode.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
Return values
kStatus_HAL_GpioSuccessGPIO de-initialization succeed
hal_gpio_status_t HAL_GpioGetInput ( hal_gpio_handle_t  gpioHandle,
uint8_t *  pinState 
)

This function gets the pin voltage. 0 - low level voltage, 1 - high level voltage.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
pinStateA pointer to save the pin state.
Return values
kStatus_HAL_GpioSuccessGet successfully.
hal_gpio_status_t HAL_GpioSetOutput ( hal_gpio_handle_t  gpioHandle,
uint8_t  pinState 
)

This function sets the pin voltage. 0 - low level voltage, 1 - high level voltage.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
pinStatePin state.
Return values
kStatus_HAL_GpioSuccessSet successfully.
hal_gpio_status_t HAL_GpioGetTriggerMode ( hal_gpio_handle_t  gpioHandle,
hal_gpio_interrupt_trigger_t gpioTrigger 
)

This function gets the pin interrupt trigger mode. The trigger mode please refer to hal_gpio_interrupt_trigger_t.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
gpioTriggerA pointer to save the pin trigger mode value.
Return values
kStatus_HAL_GpioSuccessGet successfully.
kStatus_HAL_GpioErrorThe pin is the ouput setting.
hal_gpio_status_t HAL_GpioSetTriggerMode ( hal_gpio_handle_t  gpioHandle,
hal_gpio_interrupt_trigger_t  gpioTrigger 
)

This function sets the pin interrupt trigger mode. The trigger mode please refer to hal_gpio_interrupt_trigger_t.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
gpioTriggerThe pin trigger mode value.
Return values
kStatus_HAL_GpioSuccessSet successfully.
kStatus_HAL_GpioErrorThe pin is the ouput setting.
hal_gpio_status_t HAL_GpioInstallCallback ( hal_gpio_handle_t  gpioHandle,
hal_gpio_callback_t  callback,
void *  callbackParam 
)

This function is used to install the callback and callback parameter for GPIO module. When the pin state interrupt happened, the driver will notify the upper layer by the installed callback function. After the callback called, the GPIO pin state can be got by calling function HAL_GpioGetInput.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
callbackThe callback function.
callbackParamThe parameter of the callback function.
Return values
kStatus_HAL_GpioSuccessSuccessfully install the callback.
hal_gpio_status_t HAL_GpioWakeUpSetting ( hal_gpio_handle_t  gpioHandle,
uint8_t  enable 
)

This function enables or disables the GPIO wake-up feature.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
enableenable or disable (0 - disable, 1 - enable).
Return values
kStatus_HAL_GpioErrorAn error occurred.
kStatus_HAL_GpioSuccessSet successfully.
hal_gpio_status_t HAL_GpioEnterLowpower ( hal_gpio_handle_t  gpioHandle)

This function is used to prepare to enter low power consumption.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
Return values
kStatus_HAL_GpioSuccessSuccessful operation.
hal_gpio_status_t HAL_GpioExitLowpower ( hal_gpio_handle_t  gpioHandle)

This function is used to restore from low power consumption.

Parameters
gpioHandleGPIO handle pointer. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
Return values
kStatus_HAL_GpioSuccessSuccessful operation.