From 1d035e1127adfc8d558375d34934242e2ff93351 Mon Sep 17 00:00:00 2001 From: xqq27 <834160466@qq.com> Date: Mon, 28 Apr 2025 23:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=8A=E6=97=A5=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=86=85=E5=AE=B9=EF=BC=9Aled1=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=BA=9B=E5=86=85=E5=AE=B9=E5=9C=A8mw=5Fled?= =?UTF-8?q?=E9=87=8C=E3=80=82=E6=88=91=E5=8F=91=E7=8E=B0=EF=BC=8Cled?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E5=86=85=E5=AE=B9=E4=B8=8D=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E5=86=99=E5=9C=A8bsp=5Fgpio=E5=86=85=EF=BC=8C?= =?UTF-8?q?=E8=99=BD=E7=84=B6=E4=BB=96=E4=BB=AC=E9=83=BD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BA=86=E5=BA=95=E5=B1=82=E7=9A=84gpio=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E4=BB=96=E4=BB=AC=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E6=98=AF=E5=85=B3=E4=BA=8Eled=E7=9A=84=E3=80=82?= =?UTF-8?q?=E6=88=91=E8=A7=89=E5=BE=97=E5=8F=AF=E4=BB=A5=E8=BF=9B=E4=B8=80?= =?UTF-8?q?=E6=AD=A5=E6=8A=BD=E8=B1=A1=E4=B8=80=E4=B8=8Bio=E7=9A=84?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E3=80=81=E8=AF=BB=E5=8F=96=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E8=BF=99=E4=B8=AA=E4=B9=9F=E8=A6=81=E5=92=8C=E5=85=B6=E4=BB=96?= =?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7=9A=84=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A6=82=E2=80=9C?= =?UTF-8?q?=E5=BC=80=E7=81=AF=E2=80=9D=E2=80=9C=E5=BC=80=E7=94=B5=E6=9C=BA?= =?UTF-8?q?=E2=80=9D=EF=BC=8C=E7=84=B6=E5=90=8E=E5=90=84=E8=87=AA=E7=9A=84?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E5=B1=82middleware=E5=88=86=E5=88=AB?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=90=84=E8=87=AA=E7=9A=84=E6=9D=BF=E7=BA=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8C=85bsp=EF=BC=8C=E8=BF=99=E6=A0=B7?= =?UTF-8?q?=E6=84=9F=E8=A7=89=E6=9B=B4=E7=8B=AC=E7=AB=8B=E3=80=81=E6=9B=B4?= =?UTF-8?q?=E8=A7=A3=E8=80=A6=EF=BC=8C=E5=8D=B3=E4=BE=BF=E6=8D=A2=E8=8A=AF?= =?UTF-8?q?=E7=89=87=E5=B0=B1=E7=BB=9F=E4=B8=80=E6=8A=8A=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84bsp=E6=94=B9=E6=8E=89=E5=B0=B1=E5=A5=BD=E4=BA=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/.vscode/extensions.json | 5 + Code/bsp/src/bsp_led.c | 253 ----------------------------------- Code/middleware/Led/mw_led.c | 16 ++- Code/middleware/Led/mw_led.h | 4 +- 4 files changed, 18 insertions(+), 260 deletions(-) create mode 100644 Code/.vscode/extensions.json delete mode 100644 Code/bsp/src/bsp_led.c diff --git a/Code/.vscode/extensions.json b/Code/.vscode/extensions.json new file mode 100644 index 0000000..b610f74 --- /dev/null +++ b/Code/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "cschlosser.doxdocgen" + ] +} \ No newline at end of file diff --git a/Code/bsp/src/bsp_led.c b/Code/bsp/src/bsp_led.c deleted file mode 100644 index 8fc3275..0000000 --- a/Code/bsp/src/bsp_led.c +++ /dev/null @@ -1,253 +0,0 @@ -/* -********************************************************************************************************* -* -* 模块名称 : LED指示灯驱动模块 -* 文件名称 : bsp_led.c -* 版 本 : V1.0 -* 说 明 : 驱动LED指示灯 -* -* 修改记录 : -* 版本号 日期 作者 说明 -* V1.0 2013-02-01 armfly 正式发布 -* -* Copyright (C), 2013-2014, 安富莱电子 www.armfly.com -* -********************************************************************************************************* -*/ - -#include "bsp.h" - -/* - 该程序适用于安富莱STM32-X4、STM32-F4开发板 - - 如果用于其它硬件,请修改GPIO定义和 IsKeyDown1 - IsKeyDown8 函数 - - 如果用户的LED指示灯个数小于4个,可以将多余的LED全部定义为和第1个LED一样,并不影响程序功能 -*/ - -#ifdef STM32F103C8T6 /* STM32F103C8T6 开发板 */ - /* - STM32F103C8 LED口线分配: - LED1 : PC13 (低电平点亮,高电平熄灭) - LED2 : - LED3 : - LED4 : - */ - /* 按键口对应的RCC时钟 */ - #define RCC_ALL_LED (RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB) - - #define GPIO_PORT_LED1 GPIOC - #define GPIO_PIN_LED1 GPIO_Pin_13 - - #define GPIO_PORT_LED2 GPIOB - #define GPIO_PIN_LED2 GPIO_Pin_9 - - // #define GPIO_PORT_LED2 GPIOE - // #define GPIO_PIN_LED2 GPIO_Pin_3 - - // #define GPIO_PORT_LED3 GPIOE - // #define GPIO_PIN_LED3 GPIO_Pin_4 - - // #define GPIO_PORT_LED4 GPIOE - // #define GPIO_PIN_LED4 GPIO_Pin_5 - -#endif - -#ifdef STM32_F4 - /* STM32_F4 */ - /* - 安富莱STM32-V5 开发板LED口线分配: - LD1 : PI10/TP_NCS (低电平点亮,高电平熄灭) - LD2 : PF7/NRF24L01_CSN (低电平点亮,高电平熄灭) - LD3 : PF8/SF_CS (低电平点亮,高电平熄灭) - LD4 : PC2/NRF905_CSN/VS1053_XCS (低电平点亮,高电平熄灭) - */ - - /* 按键口对应的RCC时钟 */ - #define RCC_ALL_LED (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOI) - - #define GPIO_PORT_LED1 GPIOI - #define GPIO_PIN_LED1 GPIO_Pin_10 - - #define GPIO_PORT_LED2 GPIOF - #define GPIO_PIN_LED2 GPIO_Pin_7 - - #define GPIO_PORT_LED3 GPIOF - #define GPIO_PIN_LED3 GPIO_Pin_8 - - #define GPIO_PORT_LED4 GPIOC - #define GPIO_PIN_LED4 GPIO_Pin_2 -#endif - -/* -********************************************************************************************************* -* 函 数 名: bsp_InitLed -* 功能说明: 配置LED指示灯相关的GPIO, 该函数被 bsp_Init() 调用。 -* 形 参: 无 -* 返 回 值: 无 -********************************************************************************************************* -*/ -void bsp_InitLed(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - /* 打开GPIO时钟 */ - RCC_APB2PeriphClockCmd(RCC_ALL_LED, ENABLE); - - /* - 配置所有的LED指示灯GPIO为推挽输出模式 - 由于将GPIO设置为输出时,GPIO输出寄存器的值缺省是0,因此会驱动LED点亮. - 这是我不希望的,因此在改变GPIO为输出前,先关闭LED指示灯 - */ - bsp_LedOff(LED1); - bsp_LedOff(LED2); - - /* LED 1*/ - GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED1; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 设为 输出推挽模式 */ - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* IO口最大速度 */ - GPIO_Init(GPIO_PORT_LED1, &GPIO_InitStructure); - /* LED 2*/ - GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED2; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 设为 输出推挽模式 */ - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* IO口最大速度 */ - GPIO_Init(GPIO_PORT_LED2, &GPIO_InitStructure); -} - -/* -********************************************************************************************************* -* 函 数 名: bsp_LedOn -* 功能说明: 点亮指定的LED指示灯。 -* 形 参: _no : 指示灯序号,范围 1 - 4 -* 返 回 值: 无 -********************************************************************************************************* -*/ -void bsp_LedOn(uint8_t _no) -{ - _no--; - - if (_no == (LED1-1)) - { - // STM32F103C8T6开发板 1是亮,0是灭 - // GPIO_PORT_LED1->BRR = GPIO_PIN_LED1; - GPIO_PORT_LED1->BSRR |= GPIO_PIN_LED1; - } - // else if (_no == 1) - // { - // GPIO_PORT_LED2->BSRRH = GPIO_PIN_LED2; - // } - // else if (_no == 2) - // { - // GPIO_PORT_LED3->BSRRH = GPIO_PIN_LED3; - // } - // else if (_no == 3) - // { - // GPIO_PORT_LED4->BSRRH = GPIO_PIN_LED4; - // } -} - -/* -********************************************************************************************************* -* 函 数 名: bsp_LedOff -* 功能说明: 熄灭指定的LED指示灯。 -* 形 参: _no : 指示灯序号,范围 1 - 4 -* 返 回 值: 无 -********************************************************************************************************* -*/ -void bsp_LedOff(uint8_t _no) -{ - _no--; - - if (_no == (LED1-1)) - { - // STM32F103C8T6开发板 1是亮,0是灭 - GPIO_PORT_LED1->BRR = GPIO_PIN_LED1; - } - // else if (_no == 1) - // { - // GPIO_PORT_LED2->BSRRL = GPIO_PIN_LED2; - // } - // else if (_no == 2) - // { - // GPIO_PORT_LED3->BSRRL = GPIO_PIN_LED3; - // } - // else if (_no == 3) - // { - // GPIO_PORT_LED4->BSRRL = GPIO_PIN_LED4; - // } -} - -/* -********************************************************************************************************* -* 函 数 名: bsp_LedToggle -* 功能说明: 翻转指定的LED指示灯。 -* 形 参: _no : 指示灯序号,范围 1 - 4 -* 返 回 值: 按键代码 -********************************************************************************************************* -*/ -void bsp_LedToggle(uint8_t _no) -{ - if (_no == (LED1)) - { - GPIO_PORT_LED1->ODR ^= GPIO_PIN_LED1; - } - else if (_no == 2) - { - GPIO_PORT_LED2->ODR ^= GPIO_PIN_LED2; - } - // else if (_no == 3) - // { - // GPIO_PORT_LED3->ODR ^= GPIO_PIN_LED3; - // } - // else if (_no == 4) - // { - // GPIO_PORT_LED4->ODR ^= GPIO_PIN_LED4; - // } -} - -/* -********************************************************************************************************* -* 函 数 名: bsp_IsLedOn -* 功能说明: 判断LED指示灯是否已经点亮。 -* 形 参: _no : 指示灯序号,范围 1 - 4 -* 返 回 值: 1表示已经点亮,0表示未点亮 -********************************************************************************************************* -*/ -uint8_t bsp_IsLedOn(uint8_t _no) -{ - if (_no == (LED1-1)) - { - if ((GPIO_PORT_LED1->ODR & GPIO_PIN_LED1) == 0) - { - return 1; - } - return 0; - } - // else if (_no == 2) - // { - // if ((GPIO_PORT_LED2->ODR & GPIO_PIN_LED2) == 0) - // { - // return 1; - // } - // return 0; - // } - // else if (_no == 3) - // { - // if ((GPIO_PORT_LED3->ODR & GPIO_PIN_LED3) == 0) - // { - // return 1; - // } - // return 0; - // } - // else if (_no == 4) - // { - // if ((GPIO_PORT_LED4->ODR & GPIO_PIN_LED4) == 0) - // { - // return 1; - // } - // return 0; - // } - - return 0; -} - -/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/ diff --git a/Code/middleware/Led/mw_led.c b/Code/middleware/Led/mw_led.c index 2f01aa5..3ce118c 100644 --- a/Code/middleware/Led/mw_led.c +++ b/Code/middleware/Led/mw_led.c @@ -51,7 +51,14 @@ void mw_led1_off(void) bsp_led_off(LED1); } /* led2 基础函数包 */ - +void mw_led2_on(void) +{ + bsp_led_on(LED2); +} +void mw_led2_off(void) +{ + bsp_led_off(LED2); +} /************************************************************************************* * @brief Led driver installation. * @@ -62,10 +69,9 @@ void mw_led_drv_init(void) { led_type_enum e_val; /* led0 installation */ - led_drv_buf[Led0].led_drv = Led0; - led_drv_buf[Led0].init = mw_led0_init; - led_drv_buf[Led0].on = mw_led0_on; - led_drv_buf[Led0].off = mw_led0_off; + led_drv_buf[Led1].led_drv = LED1; + led_drv_buf[Led1].on = mw_led0_on; + led_drv_buf[Led1].off = mw_led0_off; /* init all led peripherals */ for(e_val = Led0; e_val < led_num; e_val++) { diff --git a/Code/middleware/Led/mw_led.h b/Code/middleware/Led/mw_led.h index 1a4bc11..829da34 100644 --- a/Code/middleware/Led/mw_led.h +++ b/Code/middleware/Led/mw_led.h @@ -12,8 +12,8 @@ typedef struct { - uint8_t led_drv; - void (*init)(void); + led_type_enum led_drv; + // void (*init)(void); void (*on)(void); void (*off)(void); }mw_led_t;