/*************************************** ******************************* File Name: led. c Main Function Description: halInitLed (void) function to implement LED initialization; halSetLed (HalBoardLed) The function is used to set the LED to be bright. halClearLed (HalBoardLed) is used to set the led and disable it. halToggleLed (HalBoardLed) is used to set the LED to flash. **************************************** ******************************/ # Include PLATFORM_HEADER # Include BOARD_HEADER # Include "hal/micro/led. h" # Include "hal/micro/micro-common.h" # Include "hal/micro/cortexm3/micro-common.h" // Macro definition, PA-related registers # Define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR) # Define GPIO_PxSET_BASE (GPIO_PASET_ADDR) # Define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR) // Register pin offset # Define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR) /*************************************** *********************************** Function Description: initializes the LED. Input parameter: None Output parameter: None **************************************** *********************************/ Void halInitLed (void) { // Configure the pins for LED1 and LED2 HalGpioConfig (LED_D1, GPIOCFG_OUT ); HalGpioConfig (LED_D2, GPIOCFG_OUT ); // Disable LED1 and LED2 HalClearLed (LED_D1 ); HalClearLed (LED_D2 ); } /*************************************** *********************************** Function Description: clears the corresponding port of the LED to enable it. Input parameter: LED lamp ID, that is, the corresponding LED lamp Port Output parameter: None **************************************** *********************************/ Void halSetLed (HalBoardLed) { If (led/8 <3) { * (Volatile int32u *) (GPIO_PxCLR_BASE + (GPIO_Px_OFFSET * (led/8 )))) = BIT (led & 7 ); } } /*************************************** *********************************** Function Description: sets the port register value of the LED lamp to disable it. Input parameter: LED lamp ID, that is, the corresponding LED lamp Port Output parameter: None **************************************** *********************************/ Void halClearLed (HalBoardLed) { If (led/8 <3) { * (Volatile int32u *) (GPIO_PxSET_BASE + (GPIO_Px_OFFSET * (led/8 )))) = BIT (led & 7 ); } } /*************************************** *********************************** Function Description: completes the setting of the LED light so that it is switched from the light to the light or from the light to the light. Input parameter: led id, that is, the port corresponding to the LED Output parameter: None **************************************** *********************************/ Void halToggleLed (HalBoardLed) { // Atomic operation ATOMIC ( If (led/8 <3) { * (Volatile int32u *) (GPIO_PxOUT_BASE + (GPIO_Px_OFFSET * (led/8 )))) ^ = BIT (led & 7 ); } ) } |