/********************************** (C) COPYRIGHT ******************************* * File Name : LED.h * Author : WCH * Version : V1.0 * Date : 2016/04/12 * Description : ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * Attention: This software (modified or not) and binary are used for * microcontroller manufactured by Nanjing Qinheng Microelectronics. *******************************************************************************/ /******************************************************************************/ #ifndef __LED_H #define __LED_H #ifdef __cplusplus extern "C" { #endif /********************************************************************* * CONSTANTS */ /* LEDS - The LED number is the same as the bit position */ #define HAL_LED_R 0x01 #define HAL_LED_G 0x02 #define HAL_LED_Y 0x04 // BEEP #define HAL_LED_BEEP 0x08 #define HAL_LED_ALL (HAL_LED_R | HAL_LED_G | HAL_LED_Y | HAL_LED_BEEP) /* Modes */ #define HAL_LED_MODE_OFF 0x00 #define HAL_LED_MODE_ON 0x01 #define HAL_LED_MODE_BLINK 0x02 #define HAL_LED_MODE_FLASH 0x04 #define HAL_LED_MODE_TOGGLE 0x08 /* Defaults */ #define HAL_LED_DEFAULT_MAX_LEDS 4 #define HAL_LED_DEFAULT_DUTY_CYCLE 5 #define HAL_LED_DEFAULT_FLASH_COUNT 50 #define HAL_LED_DEFAULT_FLASH_TIME 1000 /********************************************************************* * TYPEDEFS */ /* 连接一个LED用于监控演示程序的进度,低电平LED亮 */ /* 1 - LED */ #define LEDR_BV BV(4) // PA4 #define LEDG_BV BV(5) // PA5 #define LEDY_BV BV(15) // PA15 #define BEEP_BV BV(14) // PA14 #define LEDR_OUT (R32_PA_OUT) #define LEDG_OUT (R32_PA_OUT) #define LEDY_OUT (R32_PA_OUT) #define BEEP_OUT (R32_PA_OUT) #define LEDR_DDR (R32_PA_DIR |= LEDR_BV) #define LEDG_DDR (R32_PA_DIR |= LEDG_BV) #define LEDY_DDR (R32_PA_DIR |= LEDY_BV) #define BEEP_DDR (R32_PA_DIR |= BEEP_BV) #define HAL_TURN_OFF_LEDR() (LEDR_OUT &= (~LEDR_BV)) #define HAL_TURN_OFF_LEDG() (LEDG_OUT &= (~LEDG_BV)) #define HAL_TURN_OFF_LEDY() (LEDY_OUT &= (~LEDY_BV)) #define HAL_TURN_OFF_BEEP() (BEEP_OUT |= BEEP_BV) #define HAL_TURN_ON_LEDR() (LEDR_OUT |= LEDR_BV) #define HAL_TURN_ON_LEDG() (LEDG_OUT |= LEDG_BV) #define HAL_TURN_ON_LEDY() (LEDY_OUT |= LEDY_BV) #define HAL_TURN_ON_BEEP() (BEEP_OUT |= BEEP_BV) #define HAL_STATE_LEDR() GPIOA_ReadPortPin(LEDR_BV) #define HAL_STATE_LEDG() GPIOA_ReadPortPin(LEDG_BV) #define HAL_STATE_LEDY() GPIOA_ReadPortPin(LEDY_BV) #define HAL_STATE_BEEP() GPIOA_ReadPortPin(BEEP_BV) /********************************************************************* * GLOBAL VARIABLES */ /** * @brief Initialize LED Service. */ void HAL_LedInit(void); /** * @brief update time LED Service. */ void HalLedUpdate(void); /** * @brief Turn ON/OFF/TOGGLE given LEDs * * @param led - bit mask value of leds to be turned ON/OFF/TOGGLE * @param mode - BLINK, FLASH, TOGGLE, ON, OFF */ extern uint8_t HalLedSet(uint8_t led, uint8_t mode); /** * @brief Blink the leds * * @param led - bit mask value of leds to be turned ON/OFF/TOGGLE * @param numBlinks - number of blinks * @param percent - the percentage in each period where the led will be on * @param period - length of each cycle in milliseconds */ extern void HalLedBlink(uint8_t leds, uint8_t cnt, uint8_t duty, uint16_t time); /** * @brief Put LEDs in sleep state - store current values */ extern void HalLedEnterSleep(void); /** * @brief Retore LEDs from sleep state */ extern void HalLedExitSleep(void); /** * @brief Return LED state */ extern uint8_t HalLedGetState(void); /********************************************************************* *********************************************************************/ #ifdef __cplusplus } #endif #endif