121 lines
3.9 KiB
C
121 lines
3.9 KiB
C
/**
|
|
* @copyright 2017 Indie Semiconductor.
|
|
*
|
|
* This file is proprietary to Indie Semiconductor.
|
|
* All rights reserved. Reproduction or distribution, in whole
|
|
* or in part, is forbidden except by express written permission
|
|
* of Indie Semiconductor.
|
|
*
|
|
* @file gpio_device.c
|
|
* @Author: Jack.Pan
|
|
* @E-mail:jack.pan@indiemicro.com
|
|
* @Date: 2020/09/10
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <gpio_device.h>
|
|
#include <isrfuncs.h>
|
|
|
|
#ifdef GPIO_SFRS
|
|
static gpio_cb_func_t gpioCallback[3][8]= {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,};
|
|
void GPIO_Handler(void)
|
|
{
|
|
for (uint8_t i = (uint8_t)GPIO_PORT_0; i<= (uint8_t)GPIO_PORT_7; i++ ){
|
|
if (GPIO_SFRS->GPIOA[i].ACTDET == 1U){
|
|
if (gpioCallback[GROUP_GPIOA][i] !=NULL){
|
|
gpioCallback[GROUP_GPIOA][i]();
|
|
}
|
|
GPIO_SFRS->GPIOA[i].CLR = 1U;
|
|
}
|
|
if (GPIO_SFRS->GPIOB[i].ACTDET == 1U){
|
|
if (gpioCallback[GROUP_GPIOB][i] !=NULL){
|
|
gpioCallback[GROUP_GPIOB][i]();
|
|
}
|
|
GPIO_SFRS->GPIOB[i].CLR = 1U;
|
|
}
|
|
if (GPIO_SFRS->GPIOC[i].ACTDET == 1U){
|
|
if (gpioCallback[GROUP_GPIOC][i] !=NULL){
|
|
gpioCallback[GROUP_GPIOC][i]();
|
|
}
|
|
GPIO_SFRS->GPIOC[i].CLR = 1U;
|
|
}
|
|
}
|
|
}
|
|
|
|
void GPIO_Init(GpioGroup_t group,GpioPort_t port, GpioDir_t dir,GpioPullMode_t pullMode)
|
|
{
|
|
IOCTRLA_SFRS->PORT_GROUP_MUX[group] &= ~(0x0FUL << (4U*(uint8_t)port));
|
|
|
|
if (pullMode == GPIO_PULL_NONE){
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PU &= ~(1U << (uint8_t)port);
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PD &= ~(1U << (uint8_t)port);
|
|
}else if (pullMode == GPIO_PULL_UP){
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PU |= (1 << (uint8_t)port);
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PD &= ~(1 << (uint8_t)port);
|
|
}else if (pullMode == GPIO_PULL_DOWN){
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PU &= ~(1 << (uint8_t)port);
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PD |= (1 << (uint8_t)port);
|
|
}else{
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PU |= (1 << (uint8_t)port);
|
|
IOCTRLA_SFRS->CTRL_MODE[group].PD |= (1 << (uint8_t)port);
|
|
}
|
|
|
|
IOCTRLA_SFRS->CTRL_MODE[group].RE |= (1 << (uint8_t)port);
|
|
|
|
if (group == GROUP_GPIOA){
|
|
GPIO_SFRS->GPIOA[port].DIR = dir;
|
|
}else if(group == GROUP_GPIOB){
|
|
GPIO_SFRS->GPIOB[port].DIR = dir;
|
|
}else{
|
|
GPIO_SFRS->GPIOC[port].DIR = dir;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void GPIO_RegisterIRQ(GpioGroup_t group,GpioPort_t port, GpioISREdge_t edge, gpio_cb_func_t callback)
|
|
{
|
|
gpioCallback[(uint8_t)group][(uint8_t)port] = callback;
|
|
if (group == GROUP_GPIOA){
|
|
GPIO_SFRS->GPIOA[(uint8_t)port].EDGE = (uint8_t)edge;
|
|
GPIO_SFRS->GPIOA[(uint8_t)port].CLR = 1U;
|
|
GPIO_SFRS->GPIOA[(uint8_t)port].IE = 1U;
|
|
}else if (group == GROUP_GPIOB){
|
|
GPIO_SFRS->GPIOB[(uint8_t)port].EDGE = (uint8_t)edge;
|
|
GPIO_SFRS->GPIOB[(uint8_t)port].CLR = 1U;
|
|
GPIO_SFRS->GPIOB[(uint8_t)port].IE = 1U;
|
|
}else{
|
|
GPIO_SFRS->GPIOC[(uint8_t)port].EDGE = (uint8_t)edge;
|
|
GPIO_SFRS->GPIOC[(uint8_t)port].CLR = 1U;
|
|
GPIO_SFRS->GPIOC[(uint8_t)port].IE = 1U;
|
|
}
|
|
NVIC_EnableIRQ(GPIO_IRQn);
|
|
}
|
|
|
|
void GPIO_UnRegisterIRQ(GpioGroup_t group,GpioPort_t port)
|
|
{
|
|
gpioCallback[(uint8_t)group][(uint8_t)port] = NULL;
|
|
}
|
|
|
|
void GPIO_Set(GpioGroup_t group,GpioPort_t port, GpioSetState_t state)
|
|
{
|
|
if (state == GPIO_LOW){
|
|
GPIO_SFRS->GPIO_SET[group].DATACLR = 1U << (uint8_t)port;
|
|
}else{
|
|
GPIO_SFRS->GPIO_SET[group].DATASET = 1U << (uint8_t)port;
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t GPIO_Read(GpioGroup_t group,GpioPort_t port)
|
|
{
|
|
uint8_t data = GPIO_SFRS->GPIO_SET[group].DATA &(1U << (uint8_t)port);
|
|
return (uint8_t)(data != 0U);
|
|
}
|
|
|
|
#endif |