2017-07-18 11:15:10 +08:00
|
|
|
|
// <20><>װgpio<69>ӿ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ls1c_public.h"
|
|
|
|
|
#include "ls1c_regs.h"
|
|
|
|
|
#include "ls1c_gpio.h"
|
|
|
|
|
#include "ls1c_pin.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>gpio<EFBFBD><EFBFBD>CFG<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @ret CFG<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
volatile unsigned int *gpio_get_cfg_reg(unsigned int gpio)
|
|
|
|
|
{
|
|
|
|
|
volatile unsigned int *gpio_cfgx = NULL; // GPIO_CFGx<47>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
unsigned int port = GPIO_GET_PORT(gpio);
|
|
|
|
|
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
gpio_cfgx = (volatile unsigned int *)LS1C_GPIO_CFG0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
gpio_cfgx = (volatile unsigned int *)LS1C_GPIO_CFG1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
gpio_cfgx = (volatile unsigned int *)LS1C_GPIO_CFG2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
gpio_cfgx = (volatile unsigned int *)LS1C_GPIO_CFG3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
gpio_cfgx = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gpio_cfgx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>gpio<EFBFBD><EFBFBD>EN<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @ret EN<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
volatile unsigned int *gpio_get_en_reg(unsigned int gpio)
|
|
|
|
|
{
|
|
|
|
|
volatile unsigned int *gpio_enx = NULL; // GPIO_ENx<4E>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
unsigned int port = GPIO_GET_PORT(gpio);
|
|
|
|
|
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
gpio_enx = (volatile unsigned int *)LS1C_GPIO_EN0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
gpio_enx = (volatile unsigned int *)LS1C_GPIO_EN1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
gpio_enx = (volatile unsigned int *)LS1C_GPIO_EN2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
gpio_enx = (volatile unsigned int *)LS1C_GPIO_EN3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
gpio_enx = NULL;
|
|
|
|
|
return gpio_enx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gpio_enx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* gpio<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>ȡֵ<EFBFBD><EFBFBD>Χ[0, 127]
|
|
|
|
|
* @mode gpio<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD>ģʽ(<EFBFBD><EFBFBD><EFBFBD>롢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>gpio50<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* gpio_init(50, gpio_mode_output);
|
|
|
|
|
*/
|
|
|
|
|
void gpio_init(unsigned int gpio, gpio_mode_t mode)
|
|
|
|
|
{
|
|
|
|
|
volatile unsigned int *gpio_enx = NULL; // GPIO_ENx<4E>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
unsigned int pin = GPIO_GET_PIN(gpio);
|
|
|
|
|
|
|
|
|
|
// <20><>pin<69><6E>Ϊ<EFBFBD><CEAA>ͨGPIO
|
|
|
|
|
pin_set_purpose(gpio, PIN_PURPOSE_GPIO);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>gpio<69><6F><EFBFBD><EFBFBD>ģʽ(<28><><EFBFBD>롢<EFBFBD><EBA1A2><EFBFBD><EFBFBD>)
|
|
|
|
|
gpio_enx = gpio_get_en_reg(gpio);
|
|
|
|
|
if (gpio_mode_output == mode) // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
reg_clr_one_bit(gpio_enx, pin);
|
|
|
|
|
}
|
|
|
|
|
else // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
reg_set_one_bit(gpio_enx, pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>gpio<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>ȡֵ<EFBFBD><EFBFBD>Χ[0, 127]
|
|
|
|
|
* @level <EFBFBD><EFBFBD>ƽֵ
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>gpio50<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
|
|
|
|
|
* gpio_set(50, gpio_level_low);
|
|
|
|
|
*/
|
|
|
|
|
void gpio_set(unsigned int gpio, gpio_level_t level)
|
|
|
|
|
{
|
|
|
|
|
volatile unsigned int *gpio_outx = NULL; // GPIO_OUTx<54>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
unsigned int port = GPIO_GET_PORT(gpio);
|
|
|
|
|
unsigned int pin = GPIO_GET_PIN(gpio);
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: // <20><>ȷ<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD>ֱ<EFA3AC>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
if (gpio_level_low == level)
|
|
|
|
|
{
|
|
|
|
|
reg_clr_one_bit(gpio_outx, pin);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reg_set_one_bit(gpio_outx, pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>gpio<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ֵ
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>ȡֵ<EFBFBD><EFBFBD>Χ[0,127]
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ȡgpio50<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>ֵ
|
|
|
|
|
* gpio_level_t level;
|
|
|
|
|
* level = gpio_get(50);
|
|
|
|
|
*/
|
|
|
|
|
unsigned int gpio_get(unsigned int gpio)
|
|
|
|
|
{
|
|
|
|
|
volatile unsigned int *gpio_inx = NULL; // GPIO_INx<4E>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
unsigned int port = GPIO_GET_PORT(gpio);
|
|
|
|
|
unsigned int pin = GPIO_GET_PIN(gpio);
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD>ֱ<EFA3AC>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ
|
|
|
|
|
return reg_get_bit(gpio_inx, pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-07-20 17:35:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @gpio gpio<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @type <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD> or <EFBFBD>½<EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
|
|
|
|
|
{
|
2017-09-06 12:11:46 +08:00
|
|
|
|
volatile unsigned int *int_pol = NULL; // <20>жϼ<D0B6><CFBC><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|
|
|
|
volatile unsigned int *int_edge = NULL; // <20>жϱ<D0B6><CFB1><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
2017-07-20 17:35:03 +08:00
|
|
|
|
unsigned int port = GPIO_GET_PORT(gpio);
|
|
|
|
|
unsigned int pin = GPIO_GET_PIN(gpio);
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0: // GPIO[31:0]
|
|
|
|
|
int_pol = (volatile unsigned int *)LS1C_INT2_POL;
|
|
|
|
|
int_edge = (volatile unsigned int *)LS1C_INT2_EDGE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1: // GPIO[63:32]
|
|
|
|
|
int_pol = (volatile unsigned int *)LS1C_INT3_POL;
|
|
|
|
|
int_edge = (volatile unsigned int *)LS1C_INT3_EDGE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2: // GPIO[95:64]
|
|
|
|
|
int_pol = (volatile unsigned int *)LS1C_INT4_POL;
|
|
|
|
|
int_edge = (volatile unsigned int *)LS1C_INT4_EDGE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case IRQ_TYPE_EDGE_RISING:
|
|
|
|
|
*int_pol |= (1 << pin);
|
|
|
|
|
*int_edge |= (1 << pin);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IRQ_TYPE_EDGE_FALLING:
|
|
|
|
|
*int_pol &= ~(1 << pin);
|
|
|
|
|
*int_edge |= (1 << pin);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IRQ_TYPE_LEVEL_HIGH:
|
|
|
|
|
*int_pol |= (1 << pin);
|
|
|
|
|
*int_edge &= ~(1 << pin);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IRQ_TYPE_LEVEL_LOW:
|
|
|
|
|
*int_pol &= ~(1 << pin);
|
|
|
|
|
*int_edge &= ~(1 << pin);
|
|
|
|
|
break;
|
2017-09-06 12:11:46 +08:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-07-20 17:35:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
|