137 lines
3.7 KiB
C
137 lines
3.7 KiB
C
/*
|
|
* ivec_mcal_gpio.c
|
|
*
|
|
* Created on: 22-Jan-2024
|
|
* Author: saar
|
|
*/
|
|
|
|
#include "../Include/ivec_mcal_gpio.h"
|
|
|
|
|
|
/*=======================================================================================PRIVATE_MEMBERS======================================================================================*/
|
|
|
|
static uint32_t GPIOInitCounter = 0;
|
|
|
|
/*=============================================================================================================================================================================================
|
|
API
|
|
==============================================================================================================================================================================================*/
|
|
|
|
/**
|
|
* @brief Initializes all the GPIO pins.
|
|
*
|
|
* @returns 0 on success, -1 on failure.
|
|
*/
|
|
int8_t u8MCAL_gpioInit(void)
|
|
{
|
|
if (GPIOInitCounter == 0)
|
|
{
|
|
GPIOInitCounter = 1;
|
|
//#define TOUCH_BUTTON_PORT (GPIOB)
|
|
//#define TOUCH_BUTTON_PIN_17_PIN (DL_GPIO_PIN_17)
|
|
//#define TOUCH_BUTTON_PIN_17_IOMUX (IOMUX_PINCM43)
|
|
// DL_GPIO_initDigitalInput(IOMUX_PINCM43);
|
|
// DL_GPIO_initDigitalInputFeatures(IOMUX_PINCM43, DL_GPIO_INVERSION_DISABLE, \
|
|
// DL_GPIO_RESISTOR_NONE, DL_GPIO_HYSTERESIS_DISABLE, DL_GPIO_WAKEUP_DISABLE);
|
|
DL_GPIO_initDigitalOutput(TM1650_SDA_PIN_IOMUX);
|
|
DL_GPIO_initDigitalOutput(TM1650_SCL_PIN_IOMUX);
|
|
DL_GPIO_setPins(TM1650_PORT, TM1650_SDA_PIN_PIN | TM1650_SCL_PIN_PIN);
|
|
DL_GPIO_enableOutput(TM1650_PORT, TM1650_SDA_PIN_PIN | TM1650_SCL_PIN_PIN);
|
|
return 0;
|
|
}
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* @brief De-initializes the GPIO pins.
|
|
*
|
|
* @param GPIOx The GPIO port to de-initialize.
|
|
* @param GPIO_Pin param is void.
|
|
*
|
|
* @returns 0 on success -1 on failure.
|
|
*/
|
|
int8_t u8MCAL_gpioDeInit(GPIO_Regs *GPIOx, uint32_t GPIO_Pin)
|
|
{
|
|
if (GPIOInitCounter == 1)
|
|
{
|
|
GPIOInitCounter = 0;
|
|
(void) GPIO_Pin;
|
|
DL_GPIO_disablePower(GPIOx);
|
|
return 0;
|
|
}
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* @brief Writes a value to a GPIO pin.
|
|
*
|
|
* @param port The GPIO port to write to.
|
|
* @param pin The pin to write to.
|
|
* @param state The value to write to the pin.
|
|
*
|
|
* @returns None
|
|
*/
|
|
void vMCAL_gpioWrite(void* port, uint32_t pin, uint32_t state)
|
|
{
|
|
if(state)
|
|
{
|
|
DL_GPIO_setPins(port, pin);
|
|
}
|
|
else
|
|
{
|
|
DL_GPIO_clearPins(port, pin);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Reads the value of a GPIO pin.
|
|
*
|
|
* @param port The port of the pin to read.
|
|
* @param pin The pin to read.
|
|
*
|
|
* @returns The value of the pin.
|
|
*/
|
|
uint32_t u32MCAL_gpioRead(void* port, uint32_t pin)
|
|
{
|
|
return (DL_GPIO_readPins(port, pin));
|
|
}
|
|
|
|
/**
|
|
* @brief Toggles a GPIO pin.
|
|
*
|
|
* @param port The GPIO port to toggle.
|
|
* @param pin The GPIO pin to toggle.
|
|
*
|
|
* @returns None
|
|
*/
|
|
void vMCAL_gpioToggle(void *port, uint32_t pin)
|
|
{
|
|
DL_GPIO_togglePins(port, pin);
|
|
}
|
|
|
|
/**
|
|
* @brief Sets the direction of a GPIO pin.
|
|
*
|
|
* @param port The port of the GPIO pin.
|
|
* @param pin The pin number of the GPIO pin.
|
|
* @param direction The direction of the GPIO pin. direction -> 0 = GPIO_IN, 1 = GPIO_OUT
|
|
*
|
|
* @returns None
|
|
*/
|
|
void vMCAL_setGpioDirection(uint32_t pincmIndex, bool direction)
|
|
{
|
|
|
|
if(direction)
|
|
{
|
|
DL_GPIO_initDigitalOutput(pincmIndex);
|
|
}
|
|
else
|
|
{
|
|
DL_GPIO_initDigitalInput(pincmIndex);
|
|
}
|
|
}
|
|
|
|
/*____________________________________________________________________________________________________________________________________________________________________________________________*/
|
|
|