/* * gpio.h * * Created on: 2021Äê6ÔÂ26ÈÕ * Author: graydon */ #ifndef DRV_GPIO_H_ #define DRV_GPIO_H_ #ifdef __cplusplus extern "C" { #endif #include struct gpio_regs; typedef volatile struct gpio_regs GPIO_TypeDef; #define GPIOA ((GPIO_TypeDef*)0x31004000) #define GPIOB ((GPIO_TypeDef*)0x31004080) #define GPIOC ((GPIO_TypeDef*)0x31004100) #define GPIO_Pin0 (1) #define GPIO_Pin1 (1<<1) #define GPIO_Pin2 (1<<2) #define GPIO_Pin3 (1<<3) #define GPIO_Pin4 (1<<4) #define GPIO_Pin5 (1<<5) #define GPIO_Pin6 (1<<6) #define GPIO_Pin7 (1<<7) #define GPIO_Pin8 (1<<8) #define GPIO_Pin9 (1<<9) #define GPIO_Pin10 (1<<10) #define GPIO_Pin11 (1<<11) #define GPIO_Pin12 (1<<12) #define GPIO_Pin13 (1<<13) #define GPIO_Pin14 (1<<14) #define GPIO_Pin15 (1<<15) /* * For single function ports (no multiplexing is needed), leave the PORT_MUX bits at 0 (default). For all PORT_MUX bit fields: 00 = default/reset peripheral option, 01 = first alternate peripheral option, 10 = second alternate peripheral option, 11 = third alternate peripheral option. */ typedef enum { MODE_0,//gpio_mode, MODE_1,//peripheral_mode MODE_2, MODE_3, }GPIO_Pin_Mode; typedef enum { GPIO_IN, GPIO_OUT }GPIO_Direction; typedef enum { GPIO_LOW, GPIO_HIGH }GPIO_Level; void GPIO_Init(GPIO_TypeDef* GPIOx , uint32_t GPIO_Pin, GPIO_Pin_Mode mode); void GPIO_Set_Direction(GPIO_TypeDef* GPIOx , uint32_t GPIO_Pin, GPIO_Direction dir); void GPIO_SetOutPut(GPIO_TypeDef* GPIOx , uint32_t GPIO_Pin, GPIO_Level value); GPIO_Level GPIO_ToggleInput(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin); #ifdef __cplusplus } #endif #endif /* DRV_GPIO_H_ */