[MCU framework][BSP layer][cx32l003][bsp_led] LED configuration and use

Publisher:TranquilSilenceLatest update time:2022-09-22 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LED is a semiconductor device. In fact, everyone is familiar with LED. The indicator lights of various electrical appliances, mobile phone keyboard lights, LED LCD screen backlights, high-brightness LED flashlights, etc., all emit light through LED. LED has two main uses, one is as an indicator light; the other is lighting. LEDs used for lighting are generally high-power LEDs, which require a large voltage and current to work properly. What we are going to use here is a low-power LED used as an indicator light. Common low-power LEDs will emit light when a voltage of about 3V is added to its positive and negative poles. When it emits light normally, the current is about 2~5mA. It should be noted here that LEDs have positive and negative poles, and they will not emit light if connected in reverse. In addition, the voltage should not be too high, otherwise the LED will burn out.


/********************************************************************************

* @file    bsp_led.c

* @author jianqiang.xue

* @version V1.0.0

* @date    2021-04-03

* @brief LED control

********************************************************************************/


/* Includes ------------------------------------------------------------------*/

#include "RTE_Components.h"

#include CMSIS_device_header


#include "bsp_gpio.h"

#include "bsp_led.h"

/* Private Includes ----------------------------------------------------------*/

#include "business_gpio.h"

#include "business_function.h"


/* Private Define ------------------------------------------------------------*/


#define LEDx_GPIO_CLK_ENABLE(__INDEX__)

do                                     

{                                       

    if ((__INDEX__) == 0)               

        BS_LED0_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 1)         

        BS_LED1_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 2)         

        BS_LED2_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 3)         

        BS_LED3_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 4)         

        BS_LED4_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 5)         

        BS_LED5_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 6)         

        BS_LED6_GPIO_CLK_ENABLE();     

    else if ((__INDEX__) == 7)         

        BS_LED7_GPIO_CLK_ENABLE();     

} while (0U)


/* Private Variables ---------------------------------------------------------*/

#if BS_LEDN != 0

static GPIO_Type *g_led_port[BS_LEDN] = {

#if (BS_LEDN > 0)

    BS_LED0_GPIO_PORT

#endif

#if (BS_LEDN > 1)

    ,BS_LED1_GPIO_PORT

#endif

#if (BS_LEDN > 2)

    ,BS_LED2_GPIO_PORT

#endif

#if (BS_LEDN > 3)

    ,BS_LED3_GPIO_PORT

#endif

#if (BS_LEDN > 4)

    ,BS_LED4_GPIO_PORT

#endif

#if (BS_LEDN > 5)

    ,BS_LED5_GPIO_PORT

#endif

#if (BS_LEDN > 6)

    ,BS_LED6_GPIO_PORT

#endif

#if (BS_LEDN > 7)

    ,BS_LED7_GPIO_PORT

#endif

};


static const uint16_t g_led_pin[BS_LEDN] = {

#if (BS_LEDN > 0)

    BS_LED0_PIN

#endif

#if (BS_LEDN > 1)

    ,BS_LED1_PIN

#endif

#if (BS_LEDN > 2)

    ,BS_LED2_PIN

#endif

#if (BS_LEDN > 3)

    ,BS_LED3_PIN

#endif

#if (BS_LEDN > 4)

    ,BS_LED4_PIN

#endif

#if (BS_LEDN > 5)

    ,BS_LED5_PIN

#endif

#if (BS_LEDN > 6)

    ,BS_LED6_PIN

#endif

#if (BS_LEDN > 7)

    ,BS_LED7_PIN

#endif

};


static const bool g_led_light_state[BS_LEDN] = {

#if (BS_LEDN > 0)

    BS_LED0_LIGHT_LEVEL

#endif

#if (BS_LEDN > 1)

    ,BS_LED1_LIGHT_LEVEL

#endif

#if (BS_LEDN > 2)

    ,BS_LED2_LIGHT_LEVEL

#endif

#if (BS_LEDN > 3)

    ,BS_LED3_LIGHT_LEVEL

#endif

#if (BS_LEDN > 4)

    ,BS_LED4_LIGHT_LEVEL

#endif

#if (BS_LEDN > 5)

    ,BS_LED5_LIGHT_LEVEL

#endif

#if (BS_LEDN > 6)

    ,BS_LED6_LIGHT_LEVEL

#endif

#if (BS_LEDN > 7)

    ,BS_LED7_LIGHT_LEVEL

#endif

};


/* Public Function Prototypes -----------------------------------------------*/

/**

 * @brief led initialization enable pin clock configuration as push-free output

 * @note   

 * @retval None

 */

void bsp_led_init(void)

{

    uint8_t i;


    for (i = 0; i < BS_LEDN; i++)

    {

        /* Enable the GPIO_LED Clock */

        LEDx_GPIO_CLK_ENABLE(i);


        /* Configure the GPIO_LED pin */

        bsp_gpio_init_output(g_led_port[i], g_led_pin[i], BSP_GPIO_PIN_OUT_PP);


        /* Reset PIN to switch off the LED */

        bsp_gpio_set_pin(g_led_port[i], g_led_pin[i], (bsp_gpio_pin_state_t)!g_led_light_state[i]);

    }

}


/**

 * @brief led deinitialization configures the pin as a floating input

 * @note   NULL

 * @retval None

 */

void bsp_led_deinit(void)

{

    uint8_t i;


    if (BS_LEDN == 0)

    {

        return;

    }


    for (i = 0; i < BS_LEDN; i++)

    {

        /* Turn off LED */

        bsp_gpio_set_pin(g_led_port[i], g_led_pin[i], (bsp_gpio_pin_state_t)!g_led_light_state[i]);

        /* DeInit the GPIO_LED pin */

        bsp_gpio_deinit(g_led_port[i], g_led_pin[i]);

    }

}


/**

 * @brief Light up the LED

 * @note   NULL

 * @param ch: LED group number

 * @retval None

 */

void bsp_led_on(bsp_led_t ch)

{

    if (ch >= BS_LEDN)

    {

        return;

    }

    bsp_gpio_set_pin(g_led_port[ch], g_led_pin[ch], (bsp_gpio_pin_state_t)!g_led_light_state[ch]);

}


/**

 * @brief Turn off LED

 * @note   NULL

 * @param ch: LED group number

 * @retval None

 */

void bsp_led_off(bsp_led_t ch)

{

    if (ch >= BS_LEDN)

    {

        return;

    }

    bsp_gpio_set_pin(g_led_port[ch], g_led_pin[ch], (bsp_gpio_pin_state_t)!g_led_light_state[ch]);

}


/**

 * @brief Flip LED

 * @note   NULL

 * @param ch: LED group number

 * @retval None

 */

void bsp_led_toggle(bsp_led_t ch)

{

    if (ch >= BS_LEDN)

    {

        return;

    }

    bsp_gpio_set_toggle(g_led_port[ch], g_led_pin[ch]);

}

#else

void bsp_led_init(void)

{

}

void bsp_led_deinit(void)

{

}

void bsp_led_on(bsp_led_t ch)

{

}

void bsp_led_off(bsp_led_t ch)

{

}

void bsp_led_toggle(bsp_led_t ch)

{

}

#endif


/********************************************************************************

* @file    bsp_led.h

* @author jianqiang.xue

* @version V1.0.0

* @date    2021-04-03

* @brief   NULL

********************************************************************************/


#ifndef __BSP_LED_H

#define __BSP_LED_H


/* Includes ------------------------------------------------------------------*/

#include


/* Public enum ---------------------------------------------------------------*/

typedef enum

{

    BSP_LED_0 = 0,

    BSP_LED_1,

    BSP_LED_2,

    BSP_LED_3,

    BSP_LED_4,

    BSP_LED_5,

    BSP_LED_6,

    BSP_LED_7

} bsp_led_t;


/* Public Function Prototypes ------------------------------------------------*/


void bsp_led_init(void);

void bsp_led_deinit(void);


void bsp_led_on(bsp_led_t ch);

void bsp_led_off(bsp_led_t ch);

void bsp_led_toggle(bsp_led_t ch);


#endif

Reference address:[MCU framework][BSP layer][cx32l003][bsp_led] LED configuration and use

Previous article:[MCU framework][bsp layer][cx32l003][bsp_key] KEY configuration and use
Next article:[MCU framework][bsp layer][cx32l003][bsp_flash] FLASH configuration and use

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号