gpio.h 16.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
/***********************************************************************************************************************
* Copyright (C) All rights reserved.
***********************************************************************************************************************/

/***********************************************************************************************************************
* @file    gpio.h
* @brief   This file implements device driver for GPIO module.
* @version 1.0.0
* @date    2019/12/24
***********************************************************************************************************************/
#ifndef GPIO_H
#define GPIO_H
#ifndef __CORE_CM0PLUS_H_GENERIC
#include "common.h"
#endif

/***********************************************************************************************************************
Macro definitions (Register bit)
***********************************************************************************************************************/

/***********************************************************************************************************************
Macro definitions
***********************************************************************************************************************/
typedef enum
{
    GPIO_WAKEUP_MODE = 0U,
    GPIO_SLEEP_MODE,

} GPIO_Config_Mode_en_t;
    
/***********************************************************************************************************************
Typedef definitions
***********************************************************************************************************************/
typedef enum {
	PORT0 = 0,
	PORT1,
	PORT2,
	PORT3,
	PORT4,
	PORT5,
	PORT6,
	PORT7,
	PORT8,
	PORT9,
	PORT10,
	PORT11,
	PORT12,
	PORT13,
	PORT14,
	PORT15,
	
}PORT_TypeDef;

typedef enum {
	PIN0 = 0,
	PIN1,
	PIN2,
	PIN3,
	PIN4,
	PIN5,
	PIN6,
	PIN7,
	
}PIN_TypeDef;

typedef enum {
	INPUT = 0,
	PULLUP_INPUT,
	TTL_INPUT,
	ANALOG_INPUT,
	OUTPUT,
	OPENDRAIN_OUTPUT,
	
}PIN_ModeDef;

#define PIN_MASK_0                 ((uint8_t)(0x01))  /*!< Pin 0 selected    */
#define PIN_MASK_1                 ((uint8_t)(0x02))  /*!< Pin 1 selected    */
#define PIN_MASK_2                 ((uint8_t)(0x04))  /*!< Pin 2 selected    */
#define PIN_MASK_3                 ((uint8_t)(0x08))  /*!< Pin 3 selected    */
#define PIN_MASK_4                 ((uint8_t)(0x10))  /*!< Pin 4 selected    */
#define PIN_MASK_5                 ((uint8_t)(0x20))  /*!< Pin 5 selected    */
#define PIN_MASK_6                 ((uint8_t)(0x40))  /*!< Pin 6 selected    */
#define PIN_MASK_7                 ((uint8_t)(0x80))  /*!< Pin 7 selected    */


/****************************************************************************************************************************************************
GPIO重映射
****************************************************************************************************************************************************/

/*===================================================================================================================================================
PORT0 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   ABS_N_In                      PORT0,    PIN0        /* 62       IN      0       ABS输入*/
#define   CHECK_KL15_In                 PORT0,    PIN1        /* 61       IN      0       KL15电源检测    */
#define   CAN0_TX                       PORT0,    PIN2        /* 60       OUT     1       */
#define   CAN0_RX                       PORT0,    PIN3        /* 59       IN      0       */
#define   LightModeCtrl                 PORT0,    PIN4        /* 58       OUT     0       档位背光控制*/
#define   LeftTurn_P_In                 PORT0,    PIN5        /* 31       IN      0       左转向*/
#define   HighBeam_P_In                 PORT0,    PIN6        /* 30       IN      0       远光输入*/

/*===================================================================================================================================================
PORT1 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   SEG_LCD_CSB                 PORT1,    PIN0        /* 46       OUT     0       LCD_CSB*/
#define   SEG_LCD_SCL                 PORT1,    PIN1        /* 45       OUT     0       LCD_SCL*/
#define   SEG_LCD_SD                  PORT1,    PIN2        /* 44       OUT     0       LCD_SD*/
#define   SEG_LCD_CSB1                PORT1,    PIN3        /* 43       OUT     0       LCD_CSB1*/
#define   IIC2_SDA_LDR                PORT1,    PIN4        /* 42       OUT     0       光敏SDA */
#define   IIC2_SCL_LDR                PORT1,    PIN5        /* 41       OUT     0       光敏SCL*/
#define   RevSpeed_In                 PORT1,    PIN6        /* 40       IN      0       转速传感器信号输入*/
#define   SEG_LCD_SCL1                PORT1,    PIN7        /* 39       IN      0       LCD_SCL1*/ 

/*===================================================================================================================================================
PORT2 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   AVREFP_In                   PORT2,    PIN0        /* 56       IN      0       参考电压正(模拟输入)*/
#define   AVREFM_In                   PORT2,    PIN1        /* 55       IN      0       参考电压地(模拟输入)*/
#define   CHECK_KL30_In               PORT2,    PIN2        /* 54       IN      0       KL30电压输入(模拟输入)*/
#define   CHECK_KL15ad_In             PORT2,    PIN3        /* 53       IN      0       */
#define   Fuel_Vref_In                PORT2,    PIN4        /* 52       IN      0       燃油电阻参考电压输入(模拟输入)*/
#define   Fuel1_In                    PORT2,    PIN5        /* 51       IN      0       燃油电阻1输入(模拟输入)*/
//#define   NotUsed                     PORT2,    PIN6        /* 50       IN     0       */ 
#define   Fuel_Vcc_en                 PORT2,    PIN7        /* 49       OUT     0       燃油电源控制*/

/*===================================================================================================================================================
PORT3 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   TirePressure_N_In           PORT3,    PIN0        /* 32       IN      0       胎压*/
#define   Backlight_P_In              PORT3,    PIN1        /* 21       IN      0       背光输入*/

/*===================================================================================================================================================
PORT4 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   SWDIO                       PORT4,    PIN0        /* 05       IN      0       */
#define   L_BD433CTRL_OUT             PORT4,    PIN1        /* 04       OUT     1       L_BD433CTRL_OUT*/
#define   AutoStarStop_N_In           PORT4,    PIN2        /* 03       IN      0       自动启停*/
#define   OBD_N_In                    PORT4,    PIN3        /* 02       IN      0       OBD*/

/*===================================================================================================================================================
PORT5 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   PWM_BL                        PORT5,    PIN0        /* 33       OUT     0       背光PWM*/
#define   OilPressure_N_In              PORT5 ,   PIN1        /* 34       IN      0       机油压力*/
#define   RightTurn_P_In                PORT5,    PIN2        /* 35       IN      0       右转输入*/
#define   VCC5V_LED_EN                  PORT5,    PIN3        /* 36       OUT     1       VCC5V LED AW21036供电*/
#define   VCC5V_AW39112DNR_EN           PORT5,    PIN4        /* 37       OUT     1       VCC5V_光敏使能*/
#define   SEG_LCD_SD1                   PORT5,    PIN5        /* 38       OUT     0       LCD_SD1*/


/*===================================================================================================================================================
PORT6 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   	MCU_TOUCH_SCL               PORT6,    PIN0        /* 17       OUT     1       触摸SCL*/
#define   	MCU_TOUCH_SDA               PORT6,    PIN1        /* 18       OUT     1       触摸SDA*/
//#define   NotUsed                     PORT6,    PIN2        /* 19       IN      0       */
//#define   NotUsed                     PORT6,    PIN3        /* 20       IN      0       */

/*===================================================================================================================================================
PORT7 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   IIC_SCL_24G16                 PORT7,    PIN0        /* 29       OUT      1       EErom_SCL*/
#define   IIC_SDA_24G16                 PORT7,    PIN1        /* 28       OUT      1       EErom_SDA*/
#define   LightVehTensCtrl              PORT7,    PIN2		  /* 27       OUT      0       车速十位*/
#define   SEG_LED_CSB                   PORT7,    PIN3        /* 26       OUT      0       SDB*/
#define   SEG_LED_SD                    PORT7,    PIN4        /* 25       OUT      0       SDA*/
#define   SEG_LED_SCL                   PORT7,    PIN5        /* 24       OUT      0       SCL*/
#define   LightVehHundredsCtrl          PORT7,    PIN6        /* 23       OUT      0       车速百位*/
#define   VCC3V3_TOUCH_EN               PORT7,    PIN7        /* 22       OUT      1       3V3触摸使能*/

/*===================================================================================================================================================
PORT12 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   CAN0_STB                    PORT12,   PIN0        /* 01       OUT     1       */
#define   MCU_XI                      PORT12,   PIN1        /* 11       IN      0       */
#define   MCU_XO                      PORT12,   PIN2        /* 10       OUT     1       */
#define   X32768_IN                   PORT12,   PIN3        /* 08       IN      0       */
#define   X32768_OUT                  PORT12,   PIN4        /* 07       OUT     1       */

/*===================================================================================================================================================
PORT13 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
//#define   NotUsed                     	PORT13,   PIN0        /* 57       IN      0       */
#define   MCU_TOUCH_OUT                 PORT13,   PIN6        /* 16       OUT     1      触摸_INT*/
#define   SWCLK                         PORT13,   PIN7        /* 09       IN      0       */

/*===================================================================================================================================================
PORT14 端口配置
-----------------------------------------------------------------------------------------------------------------------------------------------------
          | 名称                     |      端口                |  引脚  |  方向  |  初值    |  说明
===================================================================================================================================================*/
#define   TLight_OUT                     PORT14,   PIN0        /* 64       OUT     0       T指示灯(W)_OUT*/
#define   LightBATTCtrl                  PORT14,   PIN1        /* 63       OUT     0       电压背光控制*/
//#define   NotUsed                       PORT14,   PIN6        /* 47       IN      0       */
//#define   NotUsed                       PORT14,   PIN7        /* 48       IN      0       */

/***********************************************************************************************************************
Global functions
***********************************************************************************************************************/
void GPIO_Output_Enable(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_Input_Enable(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_PullUp_Enable(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_PullUp_Disable(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_Nch_OpenDrain(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_Ttl_Input(__IO uint8_t *port, uint8_t pinMsk);
void GPIO_Set_Value(__IO uint8_t *port, uint8_t value);
uint8_t GPIO_Get_Value(__IO uint8_t *port);

void PORT_Init(PORT_TypeDef PORTx,PIN_TypeDef PINx,PIN_ModeDef MODEx);
void PORT_SetBit(PORT_TypeDef PORTx,PIN_TypeDef PINx);
void PORT_ClrBit(PORT_TypeDef PORTx,PIN_TypeDef PINx);
void PORT_ToggleBit(PORT_TypeDef PORTx,PIN_TypeDef PINx);
uint8_t PORT_GetBit(PORT_TypeDef PORTx,PIN_TypeDef PINx);

void GPIO_Init(GPIO_Config_Mode_en_t enGPIOConfigMode);
#endif