当前位置:网站首页>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***********/
边栏推荐
- pytorch 筆記 torch.nn.BatchNorm1d
- DQN笔记
- Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
- Collectors.toMap应用
- The two e-commerce bigwigs' lacy news screens represent the return of e-commerce to normal, which will be beneficial to the real economy
- 文件共享服务器
- Cp2112 teaching example of using USB to IIC communication
- 微信推出图片大爆炸功能;苹果自研 5G 芯片或已失败;微软解决导致 Edge 停止响应的 bug|极客头条...
- MySQL从入门到精通50讲(三十二)-ScyllaDB生产环境集群搭建
- List介绍
猜你喜欢

Sarsa笔记

Pytorch Notebook. Nn. Batchnorm1d

CSDN blog operation team 2022 H1 summary

nvm、nrm、npx使用(安装、基本命令、参数、curl、wget)

China will force a unified charging interface. If Apple does not bow its head, iPhone will be kicked out of the Chinese market

Q-Learning笔记

File sharing server

7 大轻量易用的工具,给开发者减压提效,助力企业敏捷上云 | Techo Day 精彩回顾...

Mysql database foundation: views and variables

Matplotlib notes: contour & Contour
随机推荐
About Library (function library), dynamic library and static library
js常见问题
[rust daily] several new libraries were released on January 23, 2021
Pycharm项目使用pyinstalle打包过程中问题及解决方案
LeetCode Algorithm 86. Separate linked list
Q-Learning笔记
ArrayList and sequence table
第一届中国数字藏品大会即将召开
LVGL 8.2 menu from a drop-down list
05_Node js 文件管理模块 fs
pytorch 笔记:validation ,model.eval V.S torch.no_grad
IDEA 又出新神器,一套代码适应多端!
Pytorch notes: validation, model eval V.S torch. no_ grad
iptables目标TPROXY
Gd32 RT thread RTC driver function
[STL source code analysis] container (to be supplemented)
蚂蚁金服笔试题:需求文档有什么可以量化的【杭州多测师】【杭州多测师_王sir】...
LVGL 8.2 menu from a drop-down list
Classic interview question: responsible modules, how do you design test cases for these function points? [Hangzhou multi surveyors] [Hangzhou multi surveyors \wang Sir]
Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)