From b0fcab53ad7df17203a6b758615734716da33d57 Mon Sep 17 00:00:00 2001 From: NeoZng Date: Tue, 14 Feb 2023 11:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=83=A8=E5=88=86le?= =?UTF-8?q?d=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++- bsp/pwm/bsp_pwm.h | 2 +- modules/led/led.c | 44 ++++++++++++++++++++++++++++ modules/led/led.h | 33 +++++++++++++++++++++ modules/{led => led_task}/led.md | 0 modules/{led => led_task}/led_task.c | 0 modules/{led => led_task}/led_task.h | 0 7 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 modules/led/led.c create mode 100644 modules/led/led.h rename modules/{led => led_task}/led.md (100%) rename modules/{led => led_task}/led_task.c (100%) rename modules/{led => led_task}/led_task.h (100%) diff --git a/Makefile b/Makefile index 59c0c40..cd6af8b 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,8 @@ modules/imu/BMI088driver.c \ modules/imu/BMI088Middleware.c \ modules/imu/ins_task.c \ modules/ist8310/ist8310.c \ -modules/led/led_task.c \ +modules/led_task/led_task.c \ +modules/led/led.c \ modules/master_machine/master_process.c \ modules/master_machine/seasky_protocol.c \ modules/motor/DJImotor/dji_motor.c \ @@ -251,6 +252,7 @@ C_INCLUDES = \ -Imodules/imu \ -Imodules/ist8310 \ -Imodules/led \ +-Imodules/led_task \ -Imodules/master_machine \ -Imodules/motor/DJImotor \ -Imodules/motor/LKmotor \ diff --git a/bsp/pwm/bsp_pwm.h b/bsp/pwm/bsp_pwm.h index 654e9a3..f12a9ac 100644 --- a/bsp/pwm/bsp_pwm.h +++ b/bsp/pwm/bsp_pwm.h @@ -26,7 +26,7 @@ typedef struct uint32_t channel; // 通道 uint32_t period; // 周期 uint32_t pulse; // 脉宽 - void (*callback)(struct pwm_ins_temp *); // DMA传输完成回调函数 + void (*callback)(PWMInstance*); // DMA传输完成回调函数 void *id; // 实例ID } PWM_Init_Config_s; diff --git a/modules/led/led.c b/modules/led/led.c new file mode 100644 index 0000000..50c3f5e --- /dev/null +++ b/modules/led/led.c @@ -0,0 +1,44 @@ +#include "led.h" +#include "stdlib.h" +#include "string.h" +#include "user_lib.h" + +static uint8_t idx; +static LEDInstance* bsp_led_ins[LED_MAX_NUM] = {NULL}; + +LEDInstance *LEDRegister(LED_Init_Config_s *led_config) +{ + LEDInstance *led_ins = (LEDInstance *)zero_malloc(sizeof(LEDInstance)); + // 剩下的值暂时都被置零 + led_ins->led_pwm=GPIORegister(&led_config->pwm_config); + led_ins->led_switch=led_config->init_swtich; + + bsp_led_ins[idx++] = led_ins; + return led_ins; +} + +void LEDSet(LEDInstance *_led,uint8_t alpha,uint8_t color_value,uint8_t brightness) +{ + +} + + +void LEDSwitch(LEDInstance *_led,uint8_t led_switch) +{ + if(led_switch==1) + { + _led->led_switch=1; + } + else + { + _led->led_switch=0; + // PWMSetPeriod(_led,0); + } +} + + +void LEDShow() +{ + +} + diff --git a/modules/led/led.h b/modules/led/led.h new file mode 100644 index 0000000..0be2506 --- /dev/null +++ b/modules/led/led.h @@ -0,0 +1,33 @@ +#ifndef _LED_H_ +#define _LED_H_ + +#include "stdint.h" +#include "bsp_pwm.h" + +#define LED_MAX_NUM 3 + +typedef struct +{ + PWMInstance* led_pwm; + uint8_t led_alpha; // 透明度,通过pwm频率改变 + uint8_t led_brightness; // 亮度,通过电压改变(如果可以,使用dac) + uint8_t led_color; // rgb value,0-255 + uint8_t led_switch // 开关,on1 off0 + // void (*action_callback)(void); // led动作回调函数 +} LEDInstance; + +typedef struct +{ + PWM_Init_Config_s pwm_config; + uint8_t init_swtich; // 初始化开关 +} LED_Init_Config_s; + +LEDInstance* LEDRegister(LED_Init_Config_s* led_config); + +void LEDSet(LEDInstance *_led,uint8_t alpha,uint8_t color_value,uint8_t brightness); + +void LEDSwitch(LEDInstance *_led,uint8_t led_switch); + +void LEDShow(); + +#endif // !_LED_H_ diff --git a/modules/led/led.md b/modules/led_task/led.md similarity index 100% rename from modules/led/led.md rename to modules/led_task/led.md diff --git a/modules/led/led_task.c b/modules/led_task/led_task.c similarity index 100% rename from modules/led/led_task.c rename to modules/led_task/led_task.c diff --git a/modules/led/led_task.h b/modules/led_task/led_task.h similarity index 100% rename from modules/led/led_task.h rename to modules/led_task/led_task.h