00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2011, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 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[] = {PIN_LED_0, PIN_LED_1}; 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 // Check that LED exists 00063 if ( dwLed >= numLeds) { 00064 return 0; 00065 } 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 /* Check if LED exists */ 00083 if ( dwLed >= numLeds ) { 00084 return 0; 00085 } 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 00094 return 1; 00095 #else 00096 return 0; 00097 #endif 00098 } 00099 00100 /** 00101 * Turns a LED off. 00102 * 00103 * \param led Number of the LED to turn off. 00104 * \return 1 if the LED has been turned off; 0 otherwise. 00105 */ 00106 extern uint32_t LED_Clear( uint32_t dwLed ) 00107 { 00108 #ifdef PINS_LEDS 00109 /* Check if LED exists */ 00110 if ( dwLed >= numLeds ) { 00111 return 0; 00112 } 00113 00114 /* Turn LED off */ 00115 if ( pinsLeds[dwLed].type == PIO_OUTPUT_0 ) { 00116 PIO_Clear( &pinsLeds[dwLed] ); 00117 } else { 00118 PIO_Set( &pinsLeds[dwLed] ); 00119 } 00120 00121 return 1; 00122 #else 00123 return 0; 00124 #endif 00125 } 00126 00127 /** 00128 * Toggles the current state of a LED. 00129 * 00130 * \param led Number of the LED to toggle. 00131 * \return 1 if the LED has been toggled; otherwise 0. 00132 */ 00133 extern uint32_t LED_Toggle( uint32_t dwLed ) 00134 { 00135 #ifdef PINS_LEDS 00136 /* Check if LED exists */ 00137 if ( dwLed >= numLeds ) { 00138 return 0; 00139 } 00140 00141 /* Toggle LED */ 00142 if ( PIO_GetOutputDataStatus( &pinsLeds[dwLed] ) ) { 00143 PIO_Clear( &pinsLeds[dwLed] ); 00144 } else { 00145 PIO_Set( &pinsLeds[dwLed] ); 00146 } 00147 00148 return 1; 00149 #else 00150 return 0; 00151 #endif 00152 } 00153