/* ################################################################### ** This component module is generated by Processor Expert. Do not modify it. ** Filename : C21.h ** Project : FRDM-K64F_Generator ** Processor : MK64FN1M0VLL12 ** Component : SDK_BitIO ** Version : Component 01.030, Driver 01.00, CPU db: 3.00.000 ** Compiler : GNU C Compiler ** Date/Time : 2024-07-29, 05:47, # CodeGen: 836 ** Abstract : ** GPIO component usable with NXP SDK ** Settings : ** Component name : C21 ** SDK : McuLib ** GPIO Name : GPIOA ** PORT Name : PORTA ** Pin Number : 0 ** Pin Symbol : LED_RED ** Do Pin Muxing : no ** Init Direction : Output ** Pull Resistor : no pull resistor ** Init Value : 0 ** Contents : ** GetDir - bool C21_GetDir(void); ** SetDir - void C21_SetDir(bool Dir); ** SetInput - void C21_SetInput(void); ** SetOutput - void C21_SetOutput(void); ** GetVal - bool C21_GetVal(void); ** PutVal - void C21_PutVal(bool Val); ** ClrVal - void C21_ClrVal(void); ** SetVal - void C21_SetVal(void); ** NegVal - void C21_NegVal(void); ** Init - void C21_Init(void); ** Deinit - void C21_Deinit(void); ** ** * Copyright (c) 2015-2024, Erich Styger ** * Web: https://mcuoneclipse.com ** * SourceForge: https://sourceforge.net/projects/mcuoneclipse ** * Git: https://github.com/ErichStyger/McuOnEclipse_PEx ** * All rights reserved. ** * ** * Redistribution and use in source and binary forms, with or without modification, ** * are permitted provided that the following conditions are met: ** * ** * - Redistributions of source code must retain the above copyright notice, this list ** * of conditions and the following disclaimer. ** * ** * - Redistributions in binary form must reproduce the above copyright notice, this ** * list of conditions and the following disclaimer in the documentation and/or ** * other materials provided with the distribution. ** * ** * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ** * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ** * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ** * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ** * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ** * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ** * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ** * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ###################################################################*/ /*! ** @file C21.h ** @version 01.00 ** @brief ** GPIO component usable with NXP SDK */ /*! ** @addtogroup C21_module C21 module documentation ** @{ */ /* MODULE C21. */ #include "C21.h" #if McuLib_CONFIG_NXP_SDK_2_0_USED #if C21_CONFIG_DO_PIN_MUXING #if McuLib_CONFIG_CPU_IS_LPC #include "fsl_iocon.h" /* include SDK header file for I/O connection muxing */ #else /* Kinetis */ #include "fsl_port.h" /* include SDK header file for port muxing */ #endif #endif #include "fsl_gpio.h" /* include SDK header file for GPIO */ #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_KINETIS_1_3 #include "fsl_gpio_driver.h" /* include SDK header file for GPIO */ #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_S32K #include "pins_gpio_hw_access.h" #include "pins_driver.h" /* include SDK header file for GPIO */ #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_NORDIC_NRF5 #include "nrf_gpio.h" #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO #include "McuGPIO.h" #else #error "Unsupported SDK!" #endif #if McuLib_CONFIG_NXP_SDK_2_0_USED static const gpio_pin_config_t C21_configOutput = { kGPIO_DigitalOutput, /* use as output pin */ C21_CONFIG_INIT_PIN_VALUE, /* initial value */ }; static const gpio_pin_config_t C21_configInput = { kGPIO_DigitalInput, /* use as input pin */ C21_CONFIG_INIT_PIN_VALUE, /* initial value */ }; #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_KINETIS_1_3 const gpio_output_pin_user_config_t C21_OutputConfig[] = { { .pinName = C21_CONFIG_PIN_SYMBOL, .config.outputLogic = C21_CONFIG_INIT_PIN_VALUE, #if FSL_FEATURE_PORT_HAS_SLEW_RATE .config.slewRate = kPortSlowSlewRate, #endif #if FSL_FEATURE_PORT_HAS_OPEN_DRAIN .config.isOpenDrainEnabled = true, #endif #if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH .config.driveStrength = kPortLowDriveStrength, #endif }, { .pinName = GPIO_PINS_OUT_OF_RANGE, } }; const gpio_input_pin_user_config_t C21_InputConfig[] = { { .pinName = C21_CONFIG_PIN_SYMBOL, #if FSL_FEATURE_PORT_HAS_PULL_ENABLE #if C21_CONFIG_PULL_RESISTOR==0 /* 0: no pull resistor, 1: pull-up, 2: pull-down, 3: pull-up or no pull, 4: pull-down or no pull: 4: autoselect-pull */ .config.isPullEnable = false, #else .config.isPullEnable = true, #endif #endif #if FSL_FEATURE_PORT_HAS_PULL_SELECTION #if C21_CONFIG_PULL_RESISTOR==1 .config.pullSelect = kPortPullUp, #else .config.pullSelect = kPortPullDown, #endif #endif #if FSL_FEATURE_PORT_HAS_PASSIVE_FILTER .config.isPassiveFilterEnabled = true, #endif #if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER .config.isDigitalFilterEnabled = true, #endif #if FSL_FEATURE_GPIO_HAS_INTERRUPT_VECTOR .config.interrupt = kPortIntDisabled #endif }, { .pinName = GPIO_PINS_OUT_OF_RANGE, } }; #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO static McuGPIO_Handle_t pin; #endif static bool C21_isOutput = false; /* ** =================================================================== ** Method : ClrVal (component SDK_BitIO) ** ** Description : ** Clears the pin value (sets it to a low level) ** Parameters : None ** Returns : Nothing ** =================================================================== */ void C21_ClrVal(void) { #if McuLib_CONFIG_NXP_SDK_2_0_USED #if McuLib_CONFIG_CPU_IS_LPC GPIO_PortClear(C21_CONFIG_GPIO_NAME, C21_CONFIG_PORT_NAME, 1< input */ PINS_DRV_SetPinsDirection(C21_CONFIG_PORT_NAME, val); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_NORDIC_NRF5 nrf_gpio_cfg_input(C21_CONFIG_PIN_NUMBER, NRF_GPIO_PIN_NOPULL); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO McuGPIO_SetAsInput(pin); #endif C21_isOutput = false; } /* ** =================================================================== ** Method : SetOutput (component SDK_BitIO) ** ** Description : ** Sets the pin as output ** Parameters : None ** Returns : Nothing ** =================================================================== */ void C21_SetOutput(void) { #if McuLib_CONFIG_CPU_IS_LPC GPIO_PinInit(C21_CONFIG_GPIO_NAME, C21_CONFIG_PORT_NAME, C21_CONFIG_PIN_NUMBER, &C21_configOutput); #elif McuLib_CONFIG_NXP_SDK_2_0_USED GPIO_PinInit(C21_CONFIG_GPIO_NAME, C21_CONFIG_PIN_NUMBER, &C21_configOutput); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_KINETIS_1_3 GPIO_DRV_SetPinDir(C21_CONFIG_PIN_SYMBOL, kGpioDigitalOutput); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_S32K pins_channel_type_t val; val = PINS_GPIO_GetPinsDirection(C21_CONFIG_PORT_NAME); /* bit 0: pin is input; 1: pin is output */ val |= (1< output */ PINS_DRV_SetPinsDirection(C21_CONFIG_PORT_NAME, val); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_NORDIC_NRF5 nrf_gpio_cfg_output(C21_CONFIG_PIN_NUMBER); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO McuGPIO_SetAsOutput(pin, false /* don't care */); #endif C21_isOutput = true; } /* ** =================================================================== ** Method : PutVal (component SDK_BitIO) ** ** Description : ** Sets the pin value ** Parameters : ** NAME - DESCRIPTION ** Val - Value to set. FALSE/logical '0' or ** TRUE/logical '1' ** Returns : Nothing ** =================================================================== */ void C21_PutVal(bool Val) { #if McuLib_CONFIG_CPU_IS_LPC if (Val) { GPIO_PortSet(C21_CONFIG_GPIO_NAME, C21_CONFIG_PORT_NAME, 1<_ */ _IOCON_PIO_FUNC0 | /* Selects pull-up function */ _IOCON_PIO_MODE_PULLUP | /* Standard mode, output slew rate control is enabled */ _IOCON_PIO_SLEW_STANDARD | /* Input function is not inverted */ _IOCON_PIO_INV_DI | /* Enables digital function */ _IOCON_PIO_DIGITAL_EN | /* Open drain is disabled */ _IOCON_PIO_OPENDRAIN_DI); #if (McuLib_CONFIG_CPU_IS_LPC && McuLib_CONFIG_CORTEX_M==0) IOCON_PinMuxSet(C21_CONFIG_PORT_NAME, C21_CONFIG_PIN_NUMBER, port_pin_config); #else IOCON_PinMuxSet(IOCON, C21_CONFIG_PORT_NAME, C21_CONFIG_PIN_NUMBER, port_pin_config); #endif #else PORT_SetPinMux(C21_CONFIG_PORT_NAME, C21_CONFIG_PIN_NUMBER, kPORT_MuxAsGpio); /* mux as GPIO */ #endif #endif #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_KINETIS_1_3 /*! Pin Muxing not implemented */ GPIO_DRV_Init(C21_InputConfig, C21_OutputConfig); #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_S32K /* the following needs to be called in the application first: PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr); */ #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_NORDIC_NRF5 /* nothing needed */ #elif McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO McuGPIO_Config_t config; McuGPIO_GetDefaultConfig(&config); config.hw.pin = C21_CONFIG_PIN_NUMBER; config.isInput = true; pin = McuGPIO_InitGPIO(&config); #endif #if C21_CONFIG_INIT_PIN_DIRECTION == C21_CONFIG_INIT_PIN_DIRECTION_INPUT C21_SetInput(); #elif C21_CONFIG_INIT_PIN_DIRECTION == C21_CONFIG_INIT_PIN_DIRECTION_OUTPUT C21_SetOutput(); #endif } /* ** =================================================================== ** Method : Deinit (component SDK_BitIO) ** ** Description : ** Driver de-initialization method ** Parameters : None ** Returns : Nothing ** =================================================================== */ void C21_Deinit(void) { #if McuLib_CONFIG_SDK_VERSION_USED == McuLib_CONFIG_SDK_RPI_PICO pin = McuGPIO_DeinitGPIO(pin); #endif } /* END C21. */ /*! ** @} */