Hi Nelson,
It does take a little detective work to understand the operation and configuration of the GPIO. Let me try to explain.
The KSDK->platform->gpio->drivers->fsl_gpio_driver.h has a macro for combine a PORTx + pin location within the register into one value with the following:
/*! @brief Combines the port number and the pin number into a single scalar value. */
#define GPIO_MAKE_PIN(r,p) (((r)<< GPIO_PORT_SHIFT) | (p))
In the application there is a gpio_pins.h header.
I accumulates all the pins that are going to be used as GPIO and places in a enum structure as follows:
/*! @brief Pin names */
enum _gpio_pins_pinNames{
kGpioSW2 = GPIO_MAKE_PIN(GPIOC_IDX, 6U),
kGpioSW3 = GPIO_MAKE_PIN(GPIOA_IDX, 4U),
kGpioSdhc0Cd = GPIO_MAKE_PIN(GPIOE_IDX, 6U),
kGpioLED1 = GPIO_MAKE_PIN(GPIOE_IDX, 26U),
kGpioLED2 = GPIO_MAKE_PIN(GPIOB_IDX, 22U),
kGpioLED3 = GPIO_MAKE_PIN(GPIOB_IDX, 21U),
};
As example on frdmk64 since I have that project opened kGpioLED1
"gpio_pins.c" will define parameters for the gpio pin such as input/output, slewrate, Open Drain or not, Drive Strength using the following structure as example:
const gpio_output_pin_user_config_t ledPins[] = {
{
.pinName = kGpioLED1,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortLowDriveStrength,
},
....other pin definitions that get used by the
So that is a pre-defined set of pins to control the tri-colored LED on the frdm-k64f Freedom board.
In the example application, gpio_example_frdmk64f (since the frdmkl25z doesn't have gpio example yet) the main.c defines one output gpio pin to control the kGpioLED1 as:
// Define gpio output pin config structure LED1.
gpio_output_pin_user_config_t outputPin[] = {
{
.pinName = kGpioLED1,
.config.outputLogic = 0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
.config.slewRate = kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
.config.driveStrength = kPortHighDriveStrength,
#endif
},
{
.pinName = GPIO_PINS_OUT_OF_RANGE,
}
};
Later in the code the gpio is initialized:
// Init LED1, SW1.
GPIO_DRV_Init(inputPin, outputPin);
Then the GPIO Peripheral Driver routines can be used:
// Turn LED1 on.
GPIO_DRV_ClearPinOutput(kGpioLED1);
Summary: Many ways to implement GPIO and organize then individually or as a group.....or come up with your own method just by using the HAL drivers.
Regards,
David