80 lines
1.4 KiB
C
80 lines
1.4 KiB
C
|
|
|||
|
|
|||
|
#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;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* <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);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|