From 2576befb80bd6b9c04fdc113b4d547ef9adfe26b Mon Sep 17 00:00:00 2001 From: NeoZng Date: Thu, 2 Feb 2023 14:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0bsp=20gpio=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 ++ basic_framework.ioc | 5 +++- bsp/gpio/bsp_gpio.c | 49 ++++++++++++++++++++++++++++++++++++++ bsp/gpio/bsp_gpio.h | 36 ++++++++++++++++++++++++++++ modules/ist8310/ist8310.c | 1 + modules/ist8310/ist8310.h | 5 ++++ modules/ist8310/ist8310.md | 0 modules/oled/oled.md | 0 8 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 modules/ist8310/ist8310.md create mode 100644 modules/oled/oled.md diff --git a/Makefile b/Makefile index dba6bf5..9de7503 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ bsp/pwm/bsp_pwm.c \ bsp/bsp_legacy_support/bsp_temperature.c \ bsp/bsp_legacy_support/bsp_buzzer.c \ bsp/bsp_legacy_support/bsp_led.c \ +bsp/gpio/bsp_gpio.c \ bsp/spi/bsp_spi.c \ bsp/iic/bsp_iic.c \ bsp/can/bsp_can.c \ @@ -229,6 +230,7 @@ C_INCLUDES = \ -Ibsp/dwt \ -Ibsp/can \ -Ibsp/usart \ +-Ibsp/gpio \ -Ibsp/spi \ -Ibsp/iic \ -Ibsp/log \ diff --git a/basic_framework.ioc b/basic_framework.ioc index 917b0ac..2b502f5 100644 --- a/basic_framework.ioc +++ b/basic_framework.ioc @@ -293,6 +293,8 @@ NVIC.DMA2_Stream5_IRQn=true\:5\:0\:false\:false\:true\:false\:false\:true\:true NVIC.DMA2_Stream6_IRQn=true\:5\:0\:true\:false\:true\:true\:false\:true\:true NVIC.DMA2_Stream7_IRQn=true\:5\:0\:true\:false\:true\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.EXTI3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.EXTI4_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.ForceEnableDMAVector=true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.I2C2_ER_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true @@ -440,11 +442,12 @@ PG3.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING PG3.GPIO_PuPd=GPIO_PULLUP PG3.Locked=true PG3.Signal=GPXTI3 -PG6.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label +PG6.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label PG6.GPIO_Label=MAG_RST PG6.GPIO_PuPd=GPIO_PULLUP PG6.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM PG6.Locked=true +PG6.PinState=GPIO_PIN_SET PG6.Signal=GPIO_Output PG9.Locked=true PG9.Mode=Asynchronous diff --git a/bsp/gpio/bsp_gpio.c b/bsp/gpio/bsp_gpio.c index e69de29..48f0365 100644 --- a/bsp/gpio/bsp_gpio.c +++ b/bsp/gpio/bsp_gpio.c @@ -0,0 +1,49 @@ +#include "bsp_gpio.h" +#include "memory.h" +#include "stdlib.h" + +static uint8_t idx; +static GPIOInstance* gpio_instance[GPIO_MX_DEVICE_NUM] = {NULL}; + +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + +} + + +GPIOInstance *GPIORegister(GPIO_Init_Config_s *GPIO_config) +{ + GPIOInstance *ins=(GPIOInstance*)malloc(sizeof(GPIOInstance)); + memset(ins,0,sizeof(GPIOInstance)); + + ins->GPIOx=GPIO_config->GPIOx; + ins->GPIO_Pin=GPIO_config->GPIO_Pin; + ins->id=GPIO_config->id; + ins->gpio_model_callback=GPIO_config->gpio_model_callback; + + gpio_instance[idx++]=ins; + return ins; +} + +// ----------------- GPIO API ----------------- +// 都是对HAL的形式上的封装,后续考虑增加GPIO state变量,可以直接读取state + +void GPIOToggel(GPIOInstance *_instance) +{ + HAL_GPIO_TogglePin(_instance->GPIOx,_instance->GPIO_Pin); +} + +void GPIOSet(GPIOInstance *_instance) +{ + HAL_GPIO_WritePin(_instance->GPIOx,_instance->GPIO_Pin,GPIO_PIN_SET); +} + +void GPIOReset(GPIOInstance *_instance) +{ + HAL_GPIO_WritePin(_instance->GPIOx,_instance->GPIO_Pin,GPIO_PIN_RESET); +} + +GPIO_PinState GPIORead(GPIOInstance *_instance) +{ + return HAL_GPIO_ReadPin(_instance->GPIOx,_instance->GPIO_Pin); +} diff --git a/bsp/gpio/bsp_gpio.h b/bsp/gpio/bsp_gpio.h index 2305d3a..7d5272e 100644 --- a/bsp/gpio/bsp_gpio.h +++ b/bsp/gpio/bsp_gpio.h @@ -1,2 +1,38 @@ #include "gpio.h" +#include "stdint.h" +#define GPIO_MX_DEVICE_NUM 10 + +/** + * @brief GPIO实例结构体定义 + * + */ +typedef struct tmpgpio +{ + GPIO_TypeDef *GPIOx; + uint16_t GPIO_Pin; + void* id; + void (*gpio_model_callback)(struct tmpgpio*); // 随便取个名字当临时声明 +} GPIOInstance; + +/** + * @brief GPIO初始化配置结构体定义 + * + */ +typedef struct +{ + GPIO_TypeDef *GPIOx; + uint16_t GPIO_Pin; + void* id; + void (*gpio_model_callback)(GPIOInstance*); +} GPIO_Init_Config_s; + +GPIOInstance* GPIORegister(GPIO_Init_Config_s* GPIO_config); + +void GPIOToggel(GPIOInstance* _instance); + +void GPIOSet(GPIOInstance* _instance); + +void GPIOReset(GPIOInstance* _instance); + +GPIO_PinState GPIORead(GPIOInstance* _instance); \ No newline at end of file diff --git a/modules/ist8310/ist8310.c b/modules/ist8310/ist8310.c index e69de29..85ccfd0 100644 --- a/modules/ist8310/ist8310.c +++ b/modules/ist8310/ist8310.c @@ -0,0 +1 @@ +#include "ist8310.h" diff --git a/modules/ist8310/ist8310.h b/modules/ist8310/ist8310.h index e69de29..f87285b 100644 --- a/modules/ist8310/ist8310.h +++ b/modules/ist8310/ist8310.h @@ -0,0 +1,5 @@ +#pragma once + +#include "bsp_i2c.h" +#include "stdint.h" + diff --git a/modules/ist8310/ist8310.md b/modules/ist8310/ist8310.md new file mode 100644 index 0000000..e69de29 diff --git a/modules/oled/oled.md b/modules/oled/oled.md new file mode 100644 index 0000000..e69de29