hdo  beta
/home/mrazik/Documents/web/old/hdo/at91lib/utility/led.c
00001 /* ----------------------------------------------------------------------------
00002  *         ATMEL Microcontroller Software Support 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2008, 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 //         Headers
00032 //------------------------------------------------------------------------------
00033 
00034 #include "led.h"
00035 #include <board.h>
00036 #include <pio/pio.h>
00037 
00038 //------------------------------------------------------------------------------
00039 //         Local Variables
00040 //------------------------------------------------------------------------------
00041 
00042 #ifdef PINS_LEDS
00043 static const Pin pinsLeds[] = {PINS_LEDS};
00044 static const unsigned int numLeds = PIO_LISTSIZE(pinsLeds);
00045 #endif
00046 
00047 //------------------------------------------------------------------------------
00048 //         Global Functions
00049 //------------------------------------------------------------------------------
00050 
00051 //------------------------------------------------------------------------------
00056 //------------------------------------------------------------------------------
00057 unsigned char LED_Configure(unsigned int led)
00058 {
00059 #ifdef PINS_LEDS
00060     // Check that LED exists
00061     if (led >= numLeds) {
00062 
00063         return 0;
00064     }
00065 
00066     // Configure LED
00067     return (PIO_Configure(&pinsLeds[led], 1));
00068 #else
00069     return 0;
00070 #endif
00071 }
00072 
00073 //------------------------------------------------------------------------------
00077 //------------------------------------------------------------------------------
00078 unsigned char LED_Set(unsigned int led)
00079 {
00080 #ifdef PINS_LEDS
00081     // Check if LED exists
00082     if (led >= numLeds) {
00083 
00084         return 0;
00085     }
00086 
00087     // Turn LED on
00088     if (pinsLeds[led].type == PIO_OUTPUT_0) {
00089 
00090         PIO_Set(&pinsLeds[led]);
00091     }
00092     else {
00093 
00094         PIO_Clear(&pinsLeds[led]);
00095     }
00096 
00097     return 1;
00098 #else
00099     return 0;
00100 #endif
00101 }
00102 
00103 //------------------------------------------------------------------------------
00107 //------------------------------------------------------------------------------
00108 unsigned char LED_Clear(unsigned int led)
00109 {
00110 #ifdef PINS_LEDS
00111     // Check if LED exists
00112     if (led >= numLeds) {
00113 
00114         return 0;
00115     }
00116 
00117     // Turn LED off
00118     if (pinsLeds[led].type == PIO_OUTPUT_0) {
00119 
00120         PIO_Clear(&pinsLeds[led]);
00121     }
00122     else {
00123 
00124         PIO_Set(&pinsLeds[led]);
00125     }
00126 
00127     return 1;
00128 #else
00129     return 0;
00130 #endif
00131 }
00132 
00133 //------------------------------------------------------------------------------
00137 //------------------------------------------------------------------------------
00138 unsigned char LED_Toggle(unsigned int led)
00139 {
00140 #ifdef PINS_LEDS
00141     // Check if LED exists
00142     if (led >= numLeds) {
00143 
00144         return 0;
00145     }
00146 
00147     // Toggle LED
00148     if (PIO_GetOutputDataStatus(&pinsLeds[led])) {
00149 
00150         PIO_Clear(&pinsLeds[led]);
00151     }
00152     else {
00153 
00154         PIO_Set(&pinsLeds[led]);
00155     }
00156 
00157     return 1;
00158 #else
00159     return 0;
00160 #endif
00161 }
00162