SAMV71 Xplained Ultra Software Package 1.5

led.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /**
00031  * \file
00032  */
00033 
00034 /*-----------------------------------------------------------------------------
00035  *         Headers
00036  *----------------------------------------------------------------------------*/
00037 
00038 #include "board.h"
00039 
00040 /*------------------------------------------------------------------------------
00041  *         Local Variables
00042  *----------------------------------------------------------------------------*/
00043 
00044 #ifdef PINS_LEDS
00045     static const Pin pinsLeds[] = PINS_LEDS;
00046     static const uint32_t numLeds = PIO_LISTSIZE(pinsLeds);
00047 #endif
00048 
00049 /*------------------------------------------------------------------------------
00050  *         Global Functions
00051  *----------------------------------------------------------------------------*/
00052 
00053 /**
00054  *  Configures the pin associated with the given LED number. If the LED does
00055  *  not exist on the board, the function does nothing.
00056  *  \param led  Number of the LED to configure.
00057  *  \return 1 if the LED exists and has been configured; otherwise 0.
00058  */
00059 extern uint32_t LED_Configure(uint32_t dwLed)
00060 {
00061 #ifdef PINS_LEDS
00062 
00063     // Check that LED exists
00064     if (dwLed >= numLeds)
00065         return 0;
00066 
00067     // Configure LED
00068     return (PIO_Configure(&pinsLeds[dwLed], 1));
00069 #else
00070     return 0;
00071 #endif
00072 }
00073 
00074 /**
00075  *  Turns the given LED on if it exists; otherwise does nothing.
00076  *  \param led  Number of the LED to turn on.
00077  *  \return 1 if the LED has been turned on; 0 otherwise.
00078  */
00079 extern uint32_t LED_Set(uint32_t dwLed)
00080 {
00081 #ifdef PINS_LEDS
00082 
00083     /* Check if LED exists */
00084     if (dwLed >= numLeds)
00085         return 0;
00086 
00087     /* Turn LED on */
00088     if (pinsLeds[dwLed].type == PIO_OUTPUT_0)
00089         PIO_Set(&pinsLeds[dwLed]);
00090     else
00091         PIO_Clear(&pinsLeds[dwLed]);
00092 
00093     return 1;
00094 #else
00095     return 0;
00096 #endif
00097 }
00098 
00099 /**
00100  *  Turns a LED off.
00101  *
00102  *  \param led  Number of the LED to turn off.
00103  *  \return 1 if the LED has been turned off; 0 otherwise.
00104  */
00105 extern uint32_t LED_Clear(uint32_t dwLed)
00106 {
00107 #ifdef PINS_LEDS
00108 
00109     /* Check if LED exists */
00110     if (dwLed >= numLeds)
00111         return 0;
00112 
00113     /* Turn LED off */
00114     if (pinsLeds[dwLed].type == PIO_OUTPUT_0)
00115         PIO_Clear(&pinsLeds[dwLed]);
00116     else
00117         PIO_Set(&pinsLeds[dwLed]);
00118 
00119     return 1;
00120 #else
00121     return 0;
00122 #endif
00123 }
00124 
00125 /**
00126  *  Toggles the current state of a LED.
00127  *
00128  *  \param led  Number of the LED to toggle.
00129  *  \return 1 if the LED has been toggled; otherwise 0.
00130  */
00131 extern uint32_t LED_Toggle(uint32_t dwLed)
00132 {
00133 #ifdef PINS_LEDS
00134 
00135     /* Check if LED exists */
00136     if (dwLed >= numLeds)
00137         return 0;
00138 
00139     /* Toggle LED */
00140     if (PIO_GetOutputDataStatus(&pinsLeds[dwLed]))
00141         PIO_Clear(&pinsLeds[dwLed]);
00142     else
00143         PIO_Set(&pinsLeds[dwLed]);
00144 
00145     return 1;
00146 #else
00147     return 0;
00148 #endif
00149 }
00150 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines