rt-thread/bsp/essemi/es8p508x/libraries/Library/Include/lib_gpio.h

244 lines
7.0 KiB
C
Raw Normal View History

2019-11-07 10:00:14 +08:00
/***************************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lib_gpio.h
*<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD> Liut
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> V1.00
*<EFBFBD><EFBFBD> <EFBFBD>ڣ<EFBFBD> 2017/07/14
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> GPIOģ<EFBFBD><EFBFBD>ⲿ<EFBFBD>жϡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϿ<EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
*<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ES8P508xоƬ
<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><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
***************************************************************/
#ifndef __LIBGPIO_H__
#define __LIBGPIO_H__
#include "ES8P508x.h"
#include "type.h"
/*״̬<D7B4><CCAC><EFBFBD><EFBFBD>*/
/*<2A>˿ڶ<CBBF><DAB6><EFBFBD>*/
typedef enum
{
GPIOA = 0x0 ,
GPIOB = 0x1 ,
}GPIO_TYPE;
/*<2A><><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD>*/
typedef enum
{
GPIO_Pin_0 = 0x00,
GPIO_Pin_1 = 0x01,
GPIO_Pin_2 = 0x02,
GPIO_Pin_3 = 0x03,
GPIO_Pin_4 = 0x04,
GPIO_Pin_5 = 0x05,
GPIO_Pin_6 = 0x06,
GPIO_Pin_7 = 0x07,
GPIO_Pin_8 = 0x08,
GPIO_Pin_9 = 0x09,
GPIO_Pin_10 = 0x0A,
GPIO_Pin_11 = 0x0B,
GPIO_Pin_12 = 0x0C,
GPIO_Pin_13 = 0x0D,
GPIO_Pin_14 = 0x0E,
GPIO_Pin_15 = 0x0F,
GPIO_Pin_16 = 0x10,
GPIO_Pin_17 = 0x11,
GPIO_Pin_18 = 0x12,
GPIO_Pin_19 = 0x13,
GPIO_Pin_20 = 0x14,
GPIO_Pin_21 = 0x15,
GPIO_Pin_22 = 0x16,
GPIO_Pin_23 = 0x17,
GPIO_Pin_24 = 0x18,
GPIO_Pin_25 = 0x19,
GPIO_Pin_26 = 0x1A,
GPIO_Pin_27 = 0x1B,
GPIO_Pin_28 = 0x1C,
GPIO_Pin_29 = 0x1D,
GPIO_Pin_30 = 0x1E,
GPIO_Pin_31 = 0x1F,
}GPIO_TYPE_PIN;
/* <20><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ѡ<EFBFBD><D1A1> */
typedef enum
{
GPIO_Func_0 = 0x0 ,
GPIO_Func_1 = 0x1 ,
GPIO_Func_2 = 0x2 ,
GPIO_Func_3 = 0x3 ,
}GPIO_TYPE_FUNC;
/* <20><><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD>ѡ<EFBFBD><D1A1> */
typedef enum
{
GPIO_Dir_Out = 0x0 ,
GPIO_Dir_In = 0x1 ,
}GPIO_TYPE_DIR;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1> */
typedef enum
{
GPIO_DS_Output_Normal = 0, // <20><>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_DS_Output_Strong = 1, // ǿ<><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} GPIO_TYPE_DS;
/* <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD> */
typedef enum {
GPIO_Pin_Signal_Digital = 0, // <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>
GPIO_Pin_Signal_Analog = 1, // ģ<><C4A3><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>
} GPIO_Pin_Signal;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> */
typedef enum {
GPIO_PUE_Input_Disable = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ
GPIO_PUE_Input_Enable = 1, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
} GPIO_PUE_Input;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> */
typedef enum {
GPIO_PDE_Input_Disable = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ
GPIO_PDE_Input_Enable = 1, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
} GPIO_PDE_Input;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>©ʹ<C2A9><CAB9>λ */
typedef enum {
GPIO_ODE_Output_Disable = 0, // <20><>©<EFBFBD><C2A9>ֹ
GPIO_ODE_Output_Enable = 1, // <20><>©ʹ<C2A9><CAB9>
} GPIO_ODE_Output;
/* GPIO<49><4F>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ýṹ<C3BD><EFBFBD><E5B6A8> */
typedef struct
{
GPIO_Pin_Signal GPIO_Signal; /* <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>ź<EFBFBD><C5BA><EFBFBD><EFBFBD>ͣ<EFBFBD>ֻ<EFBFBD><D6BB>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
GPIO_TYPE_FUNC GPIO_Func; //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ѡ<EFBFBD><D1A1>
GPIO_TYPE_DIR GPIO_Direction; //<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
GPIO_PUE_Input GPIO_PUEN; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
GPIO_PDE_Input GPIO_PDEN; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
GPIO_ODE_Output GPIO_OD; //<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>©ʹ<C2A9><CAB9>
GPIO_TYPE_DS GPIO_DS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}GPIO_InitStruType;
/* PINT */
typedef enum
{
PINT0 = 0x0 ,
PINT1 = 0x1 ,
PINT2 = 0x2 ,
PINT3 = 0x3 ,
PINT4 = 0x4 ,
PINT5 = 0x5 ,
PINT6 = 0x6 ,
PINT7 = 0x7 ,
}PINT_TYPE;
/* PINT SEL */
typedef enum
{
PINT_SEL0 = 0x0 ,
PINT_SEL1 = 0x1 ,
PINT_SEL2 = 0x2 ,
PINT_SEL3 = 0x3 ,
PINT_SEL4 = 0x4 ,
PINT_SEL5 = 0x5 ,
PINT_SEL6 = 0x6 ,
PINT_SEL7 = 0x7 ,
}PINT_TYPE_SEL;
/* PINT Trigger */
typedef enum
{
PINT_Trig_Rise = 0x0 ,
PINT_Trig_Fall = 0x1 ,
PINT_Trig_High = 0x2 ,
PINT_Trig_Low = 0x3 ,
PINT_Trig_Change = 0x4 ,
}PINT_TYPE_TRIG;
/* PINT<4E>жϱ<D0B6>־ */
typedef enum
{
PINT_IT_PINT0 = 0x01 ,
PINT_IT_PINT1 = 0x02 ,
PINT_IT_PINT2 = 0x04 ,
PINT_IT_PINT3 = 0x08 ,
PINT_IT_PINT4 = 0x10 ,
PINT_IT_PINT5 = 0x20 ,
PINT_IT_PINT6 = 0x40 ,
PINT_IT_PINT7 = 0x80 ,
PINT_IT_PINTAll = 0xFF ,
}PINT_TYPE_IT;
/* PINTʹ<54>ܿ<EFBFBD><DCBF><EFBFBD> */
#define PINT0_Enable() (GPIO->PINTIE.PINTIE |= 0X1)
#define PINT1_Enable() (GPIO->PINTIE.PINTIE |= 0x2)
#define PINT2_Enable() (GPIO->PINTIE.PINTIE |= 0x4)
#define PINT3_Enable() (GPIO->PINTIE.PINTIE |= 0x8)
#define PINT4_Enable() (GPIO->PINTIE.PINTIE |= 0x10)
#define PINT5_Enable() (GPIO->PINTIE.PINTIE |= 0x20)
#define PINT6_Enable() (GPIO->PINTIE.PINTIE |= 0x40)
#define PINT7_Enable() (GPIO->PINTIE.PINTIE |= 0x80)
#define PINT0_Disable() (GPIO->PINTIE.PINTIE &= ~0x01)
#define PINT1_Disable() (GPIO->PINTIE.PINTIE &= ~0x02)
#define PINT2_Disable() (GPIO->PINTIE.PINTIE &= ~0x04)
#define PINT3_Disable() (GPIO->PINTIE.PINTIE &= ~0x08)
#define PINT4_Disable() (GPIO->PINTIE.PINTIE &= ~0x10)
#define PINT5_Disable() (GPIO->PINTIE.PINTIE &= ~0x20)
#define PINT6_Disable() (GPIO->PINTIE.PINTIE &= ~0x40)
#define PINT7_Disable() (GPIO->PINTIE.PINTIE &= ~0x80)
/* PINT<4E><54><EFBFBD><EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD> */
#define PINT0_MaskEnable() (GPIO->PINTIE.PMASK |= 0X01)
#define PINT1_MaskEnable() (GPIO->PINTIE.PMASK |= 0x02)
#define PINT2_MaskEnable() (GPIO->PINTIE.PMASK |= 0x04)
#define PINT3_MaskEnable() (GPIO->PINTIE.PMASK |= 0x08)
#define PINT4_MaskEnable() (GPIO->PINTIE.PMASK |= 0x10)
#define PINT5_MaskEnable() (GPIO->PINTIE.PMASK |= 0x20)
#define PINT6_MaskEnable() (GPIO->PINTIE.PMASK |= 0x40)
#define PINT7_MaskEnable() (GPIO->PINTIE.PMASK |= 0x80)
#define PINT0_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x01)
#define PINT1_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x02)
#define PINT2_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x04)
#define PINT3_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x08)
#define PINT4_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x10)
#define PINT5_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x20)
#define PINT6_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x40)
#define PINT7_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x80)
/* PINT<4E><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6><CFB1><EFBFBD> */
#define PINT_ClearAllITPending() (GPIO->PIF.Word = (uint32_t)0xff)
void GPIO_Init(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_InitStruType* GPIO_InitStruct);
void GPIO_Write(GPIO_TYPE GPIOx, uint32_t Value);
uint32_t GPIO_Read(GPIO_TYPE GPIOx);
PinStatus GPIO_ReadBit(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx);
void GPIOA_SetBit(GPIO_TYPE_PIN PINx);
void GPIOA_ResetBit(GPIO_TYPE_PIN PINx);
void GPIOA_ToggleBit(GPIO_TYPE_PIN PINx);
void GPIOB_SetBit(GPIO_TYPE_PIN PINx);
void GPIOB_ResetBit(GPIO_TYPE_PIN PINx);
void GPIOB_ToggleBit(GPIO_TYPE_PIN PINx);
void GPIOA_SetDirection(GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir_Type);
void GPIOB_SetDirection(GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir_Type);
void PINT_Config(PINT_TYPE PINTx, PINT_TYPE_SEL SELx, PINT_TYPE_TRIG TRIGx);
void GPIO_SetSingalTypeFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_Pin_Signal GPIO_Signal);
void GPIO_SetDirRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir);
void GPIO_SetODERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_ODE_Output ODE);
void GPIO_SetDSRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_DS DS);
void GPIO_SetPUERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_PUE_Input PUE);
void GPIO_SetPDERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_PDE_Input PDE);
void GPIO_SetFuncxRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_FUNC Func);
FlagStatus PINT_GetIFStatus(PINT_TYPE_IT PINT_Flag);
FlagStatus PINT_GetITStatus(PINT_TYPE_IT PINT_Flag);
void PINT_ClearITPendingBit(PINT_TYPE_IT PINT_Flag);
#endif