2017-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __OPENLOONGSON_GPIO_H
|
|
|
|
|
#define __OPENLOONGSON_GPIO_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>о1c<31><63>gpio<69>ǰ<EFBFBD><C7B0><EFBFBD>0,1,2,3,4...<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ŵģ<C5B5>
|
|
|
|
|
// <20><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ÿ32<33><32>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>32<33><32>gpio<69><6F><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>"port"<22><>ÿ<EFBFBD><C3BF>gpio<69><6F>ÿ<EFBFBD><C3BF><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"pin"
|
|
|
|
|
// port = gpio / 32
|
|
|
|
|
// pin = gpio % 32
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>GPIO50<35><30>port=1,pin=18
|
|
|
|
|
#define GPIO_GET_PORT(gpio) ((gpio) / 32)
|
|
|
|
|
#define GPIO_GET_PIN(gpio) ((gpio) % 32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// gpio<69>Ĺ<EFBFBD><C4B9><EFBFBD>ģʽ--<2D><><EFBFBD>롢<EFBFBD><EBA1A2><EFBFBD><EFBFBD>
|
|
|
|
|
typedef enum{
|
|
|
|
|
gpio_mode_output = 0, // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
gpio_mode_input = 1 // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
}gpio_mode_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// gpio<69>ߵ͵<DFB5>ƽֵ
|
|
|
|
|
typedef enum{
|
|
|
|
|
gpio_level_low = 0, // <20>͵<EFBFBD>ƽ
|
|
|
|
|
gpio_level_high = 1 // <20>ߵ<EFBFBD>ƽ
|
|
|
|
|
}gpio_level_t;
|
|
|
|
|
|
|
|
|
|
|
2017-07-20 17:35:03 +08:00
|
|
|
|
typedef enum {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
IRQ_TYPE_EDGE_RISING = 0x00000001,
|
|
|
|
|
// <20>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
IRQ_TYPE_EDGE_FALLING = 0x00000002,
|
|
|
|
|
IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
|
|
|
|
|
// <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
|
|
|
|
IRQ_TYPE_LEVEL_HIGH = 0x00000004,
|
|
|
|
|
// <20>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
|
|
|
|
IRQ_TYPE_LEVEL_LOW = 0x00000008,
|
|
|
|
|
IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
|
|
|
|
|
}gpio_irq_type_t;
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <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);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|