当前位置:网站首页>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***********/
边栏推荐
- Voir le changement technologique à travers la Légion Huawei (5): Smart Park
- MySQL export SQL script file
- Pandora IOT development board learning (HAL Library) - Experiment 1 running lantern (RGB) experiment (learning notes)
- iptables目标TPROXY
- List介绍
- 经典面试题:负责的模块,针对这些功能点你是怎么设计测试用例的?【杭州多测师】【杭州多测师_王sir】...
- 第一届中国数字藏品大会即将召开
- LeetCode Algorithm 86. Separate linked list
- 59 websites programmers need to know
- 深潜Kotlin协程(十八):冷热数据流
猜你喜欢

LVGL 8.2 Image

8行代码实现快速排序,简单易懂图解!

软件测试工程师面试基础题(应届生和测试小菜必备)最基础的面试题

电商两位大佬花边新闻刷屏,代表电商回归正常,将有利于实体经济

Every time I look at my colleagues' interface documents, I get confused and have a lot of problems...

Review of mathematical knowledge: curve integral of the second type

Deep dive kotlin synergy (16): Channel

Criu enables hot migration

19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
![[STL source code analysis] iterator](/img/e8/7c69cf6e96ecfa053494397a21eff0.jpg)
[STL source code analysis] iterator
随机推荐
Pytorch notes: validation, model eval V.S torch. no_ grad
LVGL 8.2 Image
透過華為軍團看科技之變(五):智慧園區
WireGuard简单配置
电化学氧气传感器寿命、工作原理及应用介绍
LVGL 8.2 re-coloring
pytorch 筆記 torch.nn.BatchNorm1d
[rust daily] the first rust monthly magazine on January 22, 2021 invites everyone to participate
同事的接口文档我每次看着就头大,毛病多多。。。
在IPhone12的推理延迟仅为1.6 ms!Snap等详析Transformer结构延迟,并用NAS搜出移动设备的高效网络结构...
The intelligent DNA molecular nano robot model is coming
[proteus simulation] Arduino uno led simulated traffic light
LVGL 8.2 Simple Image button
Sarsa笔记
基于HAL库的LED驱动库
My in-depth remote office experience | community essay solicitation
Google 辟谣放弃 TensorFlow,它还活着!
程序员需知的 59 个网站
科普达人丨漫画图解什么是eRDMA?
Lvgl 8.2 picture scaling and rotation