当前位置:网站首页>LED driver library based on Hal Library
LED driver library based on Hal Library
2022-06-30 10:56:00 【Coder_ Ja】
led.h
/** ******************************************************************************** * @file led.h * @brief This document contains some led Definition of basic operation function , Include LED Liang Liang 、 destroy , flashing * @author Jia Yasen * @date 2022-5-23 * @version V0.0.1 * @copyright Etherealize ******************************************************************************** * @attention 1. The functions in this document are based on HAL library , because LED The initialization of is based on GPIO The initialization ,GPIO The initialization * Directly in CubeMX Middle configuration , use CubeMX Generated GPIO Initialization function to initialize . * 2. Because the corresponding pins of different boards are different , Before use, it is necessary to modify according to the schematic diagram LED Pin correspondence and LED * The on-off state corresponds to the high and low levels of the pins ******************************************************************************** */
#ifndef __LED_H__
#define __LED_H__
/*-----------------------------Includes---------------------------------------*/
// Modify according to the chip model used
#include "stm32f1xx_hal.h"
/*-----------------------------Define-----------------------------------------*/
// Definition LED Of GPIO Group and pin numbers ; It needs to be modified according to the schematic diagram of the board before use
#define LED1_PORT GPIOx
#define LED1_PIN GPIO_PIN_x
// If more than one LED You can add definitions
// Definition LED Pin level status corresponding to on and off , Different circuit designs correspond to different , Before use, it is necessary to modify according to the schematic diagram
#define LED_STATE_ON GPIO_PIN_RESET
#define LED_STATE_OFF GPIO_PIN_SET
/*-----------------------------TypeDef----------------------------------------*/
typedef struct
{
GPIO_TypeDef* led_port;
uint16_t led_pin;
}LED_TypeDef;
/*-----------------------------variables--------------------------------------*/
// Declared as an external variable , This allows you to use this variable in the file that references the header file
// If you need to use more than one LED Then define
extern LED_TypeDef LED1;
/*-----------------------------Function---------------------------------------*/
void LED_Init(void);
void LED_ON(LED_TypeDef LED_Ptr);
void LED_OFF(LED_TypeDef LED_Ptr);
void LED_Blink(LED_TypeDef LED_Ptr, uint32_t Delay);
#endif
/************************ (C) COPYRIGHT Etherealize*****END OF FILE***********/
led.c
/** ******************************************************************************** * @file led.c * @brief led Operation source file , The overall operation is through a LED Structure to achieve * @author Jia Yasen * @date 2022-5-23 * @version V0.0.1 * @copyright Etherealize ******************************************************************************** */
/*-----------------------------Includes---------------------------------------*/
#include "led.h"
/*-----------------------------variables--------------------------------------*/
// If you need to use more than one LED, You can define more LED Structure
//LED_TypeDef* LED1_Ptr;
// If you define a structure pointer , You need to make room for the pointer , Just defining a pointer won't open up space . You can define the structure directly
// Defining a structure opens up space , When you need to modify the value of a structure in a function , Just deliver the address
LED_TypeDef LED1;
/*-----------------------------Function---------------------------------------*/
/** * @brief LED Structure pointer initialization * @param[in] None * @return None * @details When using, manually modify the pointer to be assigned and its corresponding value */
void LED_Init(void)
{
// initialization LED Corresponding GPIO Group number and pin serial number
LED1.led_port = LED1_PORT;
LED1.led_port = LED1_PIN;
}
/** * @brief Lighten up LED * @param[in] LED To operate LED Structure * @return None * @details Because there is no need to change the value in the structure , Just read , So you don't have to pass a pointer , Just pass the structure */
void LED_ON(LED_TypeDef LED)
{
// The pin is set to the corresponding bit
HAL_GPIO_WritePin(LED.led_port, LED.led_pin, LED_STATE_ON);
}
/** * @brief Extinguish LED * @param[in] LED To operate LED Structure * @return None * @details Because there is no need to change the value in the structure , Just read , So you don't have to pass a pointer , Just pass the structure */
void LED_OFF(LED_TypeDef LED)
{
// The pin is set to the corresponding bit
HAL_GPIO_WritePin(LED.led_port, LED.led_pin, LED_STATE_OFF);
}
/** * @brief LED flashing * @param[in] LED To operate LED Structure * Delay LED Half cycle of flicker (ms), That is, the duration of a light or dark , Once on + Dark is a blinking cycle . * @return None * @attention If you want to achieve LED Continuous flashing effect , You need to put this function in an infinite loop */
void LED_Blink(LED_TypeDef LED, uint32_t Delay)
{
LED_ON(LED);// Lighten up LED
HAL_Delay(Delay);// The on state lasts Delay ms
LED_OFF(LED);// Extinguish LED
HAL_Delay(Delay);// The dark state continues Delay ms
}
/************************ (C) COPYRIGHT Etherealize*****END OF FILE***********/
边栏推荐
- 软件测试工程师面试基础题(应届生和测试小菜必备)最基础的面试题
- 再测云原生数据库性能:PolarDB依旧最强,TDSQL-C、GaussDB变化不大
- List introduction
- LVGL 8.2 menu from a drop-down list
- LVGL 8.2 Simple Image button
- 智能DNA分子纳米机器人模型来了
- 【深度学习】深度学习检测小目标常用方法
- MATLAB image histogram equalization, namely spatial filtering
- 程序员需知的 59 个网站
- LeetCode Algorithm 86. Separate linked list
猜你喜欢
随机推荐
List introduction
历史上的今天:微软收购 PowerPoint 开发商;SGI 和 MIPS 合并
如何解决跨域
File sharing server
LVGL 8.2 Checkboxes as radio buttons
From introduction to mastery of MySQL 50 lectures (32) -scylladb production environment cluster building
文件共享服务器
nvm、nrm、npx使用(安装、基本命令、参数、curl、wget)
LVGL8.2 Simple Checkboxes
CSDN blog operation team 2022 H1 summary
LVGL 8.2 Image
& and - > priority
LVGL 8.2图片缩放及旋转
Memory escape analysis
Matplotlib notes: contour & Contour
中国将强制统一充电接口,苹果如不低头,iPhone将被踢出中国市场
Typescript – classes in Es5, inheritance, static methods
科普达人丨漫画图解什么是eRDMA?
无心剑中译狄金森《灵魂择其伴侣》
The intelligent DNA molecular nano robot model is coming








