Christina Quast | 8be71e4 | 2014-12-02 13:06:01 +0100 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------------
|
| 2 | * ATMEL Microcontroller Software Support
|
| 3 | * ----------------------------------------------------------------------------
|
| 4 | * Copyright (c) 2008, Atmel Corporation
|
| 5 | *
|
| 6 | * All rights reserved.
|
| 7 | *
|
| 8 | * Redistribution and use in source and binary forms, with or without
|
| 9 | * modification, are permitted provided that the following conditions are met:
|
| 10 | *
|
| 11 | * - Redistributions of source code must retain the above copyright notice,
|
| 12 | * this list of conditions and the disclaimer below.
|
| 13 | *
|
| 14 | * Atmel's name may not be used to endorse or promote products derived from
|
| 15 | * this software without specific prior written permission.
|
| 16 | *
|
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 | * ----------------------------------------------------------------------------
|
| 28 | */
|
| 29 |
|
| 30 | /**
|
| 31 | * \file
|
| 32 | */
|
| 33 |
|
| 34 | /*------------------------------------------------------------------------------
|
| 35 | * Headers
|
| 36 | *------------------------------------------------------------------------------*/
|
| 37 |
|
| 38 | #include "board.h"
|
| 39 |
|
| 40 | /*------------------------------------------------------------------------------
|
| 41 | * Local Variables
|
| 42 | *------------------------------------------------------------------------------*/
|
| 43 |
|
| 44 | #ifdef PINS_LEDS
|
| 45 | static const Pin pinsLeds[] = { PINS_LEDS } ;
|
| 46 | static const uint32_t numLeds = PIO_LISTSIZE( pinsLeds ) ;
|
| 47 | #endif
|
| 48 |
|
| 49 | /*------------------------------------------------------------------------------
|
| 50 | * Global Functions
|
| 51 | *------------------------------------------------------------------------------*/
|
| 52 |
|
| 53 | /**
|
| 54 | * Configures the pin associated with the given LED number. If the LED does
|
| 55 | * not exist on the board, the function does nothing.
|
| 56 | * \param led Number of the LED to configure.
|
| 57 | * \return 1 if the LED exists and has been configured; otherwise 0.
|
| 58 | */
|
| 59 | extern uint32_t LED_Configure( uint32_t dwLed )
|
| 60 | {
|
| 61 | #ifdef PINS_LEDS
|
| 62 | // Check that LED exists
|
| 63 | if ( dwLed >= numLeds)
|
| 64 | {
|
| 65 |
|
| 66 | return 0;
|
| 67 | }
|
| 68 |
|
| 69 | // Configure LED
|
| 70 | return ( PIO_Configure( &pinsLeds[dwLed], 1 ) ) ;
|
| 71 | #else
|
| 72 | return 0 ;
|
| 73 | #endif
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * Turns the given LED on if it exists; otherwise does nothing.
|
| 78 | * \param led Number of the LED to turn on.
|
| 79 | * \return 1 if the LED has been turned on; 0 otherwise.
|
| 80 | */
|
| 81 | extern uint32_t LED_Set( uint32_t dwLed )
|
| 82 | {
|
| 83 | #ifdef PINS_LEDS
|
| 84 | /* Check if LED exists */
|
| 85 | if ( dwLed >= numLeds )
|
| 86 | {
|
| 87 | return 0 ;
|
| 88 | }
|
| 89 |
|
| 90 | /* Turn LED on */
|
| 91 | if ( pinsLeds[dwLed].type == PIO_OUTPUT_0 )
|
| 92 | {
|
| 93 |
|
| 94 | PIO_Set( &pinsLeds[dwLed] ) ;
|
| 95 | }
|
| 96 | else
|
| 97 | {
|
| 98 | PIO_Clear( &pinsLeds[dwLed] ) ;
|
| 99 | }
|
| 100 |
|
| 101 | return 1 ;
|
| 102 | #else
|
| 103 | return 0 ;
|
| 104 | #endif
|
| 105 | }
|
| 106 |
|
| 107 | /**
|
| 108 | * Turns a LED off.
|
| 109 | *
|
| 110 | * \param led Number of the LED to turn off.
|
| 111 | * \return 1 if the LED has been turned off; 0 otherwise.
|
| 112 | */
|
| 113 | extern uint32_t LED_Clear( uint32_t dwLed )
|
| 114 | {
|
| 115 | #ifdef PINS_LEDS
|
| 116 | /* Check if LED exists */
|
| 117 | if ( dwLed >= numLeds )
|
| 118 | {
|
| 119 | return 0 ;
|
| 120 | }
|
| 121 |
|
| 122 | /* Turn LED off */
|
| 123 | if ( pinsLeds[dwLed].type == PIO_OUTPUT_0 )
|
| 124 | {
|
| 125 | PIO_Clear( &pinsLeds[dwLed] ) ;
|
| 126 | }
|
| 127 | else
|
| 128 | {
|
| 129 | PIO_Set( &pinsLeds[dwLed] ) ;
|
| 130 | }
|
| 131 |
|
| 132 | return 1 ;
|
| 133 | #else
|
| 134 | return 0 ;
|
| 135 | #endif
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * Toggles the current state of a LED.
|
| 140 | *
|
| 141 | * \param led Number of the LED to toggle.
|
| 142 | * \return 1 if the LED has been toggled; otherwise 0.
|
| 143 | */
|
| 144 | extern uint32_t LED_Toggle( uint32_t dwLed )
|
| 145 | {
|
| 146 | #ifdef PINS_LEDS
|
| 147 | /* Check if LED exists */
|
| 148 | if ( dwLed >= numLeds )
|
| 149 | {
|
| 150 | return 0 ;
|
| 151 | }
|
| 152 |
|
| 153 | /* Toggle LED */
|
| 154 | if ( PIO_GetOutputDataStatus( &pinsLeds[dwLed] ) )
|
| 155 | {
|
| 156 | PIO_Clear( &pinsLeds[dwLed] ) ;
|
| 157 | }
|
| 158 | else
|
| 159 | {
|
| 160 | PIO_Set( &pinsLeds[dwLed] ) ;
|
| 161 | }
|
| 162 |
|
| 163 | return 1 ;
|
| 164 | #else
|
| 165 | return 0 ;
|
| 166 | #endif
|
| 167 | }
|
| 168 |
|