led.h File Reference


Detailed Description

AT32UC3A EVK1100 board LEDs support package.

This file contains definitions and services related to the LED features of the EVK1100 board.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file led.h.

#include "compiler.h"

Include dependency graph for led.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

Identifiers of LEDs to Use with LED Functions
#define LED0   0x01
#define LED1   0x02
#define LED2   0x04
#define LED3   0x08
#define LED4   0x10
#define LED5   0x20
#define LED6   0x40
#define LED7   0x80

Functions

void LED_Display (U32 leds)
 Sets the state of all LEDs.
void LED_Display_Field (U32 field, U32 leds)
 Sets as a bit-field the state of the specified LEDs.
void LED_Display_Mask (U32 mask, U32 leds)
 Sets the state of the specified LEDs.
U8 LED_Get_Intensity (U32 led)
 Gets the intensity of the specified LED.
void LED_Off (U32 leds)
 Turns off the specified LEDs.
void LED_On (U32 leds)
 Turns on the specified LEDs.
U32 LED_Read_Display (void)
 Gets the last state of all LEDs set through the LED API.
U32 LED_Read_Display_Field (U32 field)
 Gets as a bit-field the last state of the specified LEDs set through the LED API.
U32 LED_Read_Display_Mask (U32 mask)
 Gets the last state of the specified LEDs set through the LED API.
void LED_Set_Intensity (U32 leds, U8 intensity)
 Sets the intensity of the specified LEDs.
Bool LED_Test (U32 leds)
 Tests the last state of the specified LEDs set through the LED API.
void LED_Toggle (U32 leds)
 Toggles the specified LEDs.


Define Documentation

#define LED0   0x01

Definition at line 57 of file led.h.

#define LED1   0x02

Definition at line 58 of file led.h.

#define LED2   0x04

Definition at line 59 of file led.h.

#define LED3   0x08

Definition at line 60 of file led.h.

#define LED4   0x10

Definition at line 61 of file led.h.

#define LED5   0x20

Definition at line 62 of file led.h.

#define LED6   0x40

Definition at line 63 of file led.h.

#define LED7   0x80

Definition at line 64 of file led.h.


Function Documentation

void LED_Display ( U32  leds  ) 

Sets the state of all LEDs.

Parameters:
leds New state of all LEDs (1 bit per LED).
Note:
The pins of all LEDs are set to GPIO output mode.

Definition at line 94 of file led.c.

References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.

00095 {
00096   tLED_DESCRIPTOR *led_descriptor;
00097   volatile avr32_gpio_port_t *led_gpio_port;
00098 
00099   leds &= (1 << LED_COUNT) - 1;
00100   LED_State = leds;
00101   for (led_descriptor = &LED_DESCRIPTOR[0];
00102        led_descriptor < LED_DESCRIPTOR + LED_COUNT;
00103        led_descriptor++)
00104   {
00105     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00106     if (leds & 1)
00107     {
00108       led_gpio_port->ovrc  = led_descriptor->GPIO.PIN_MASK;
00109     }
00110     else
00111     {
00112       led_gpio_port->ovrs  = led_descriptor->GPIO.PIN_MASK;
00113     }
00114     led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
00115     led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
00116     leds >>= 1;
00117   }
00118 }

void LED_Display_Field ( U32  field,
U32  leds 
)

Sets as a bit-field the state of the specified LEDs.

Parameters:
field LEDs of which to set the state (1 bit per LED).
leds New state of the specified LEDs (1 bit per LED, beginning with the first specified LED).
Note:
The pins of the specified LEDs are set to GPIO output mode.

Definition at line 232 of file led.c.

References LED_Display_Mask().

00233 {
00234   LED_Display_Mask(field, leds << ctz(field));
00235 }

Here is the call graph for this function:

void LED_Display_Mask ( U32  mask,
U32  leds 
)

Sets the state of the specified LEDs.

Parameters:
mask LEDs of which to set the state (1 bit per LED).
leds New state of the specified LEDs (1 bit per LED).
Note:
The pins of the specified LEDs are set to GPIO output mode.

Definition at line 127 of file led.c.

References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.

Referenced by LED_Display_Field().

00128 {
00129   tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
00130   volatile avr32_gpio_port_t *led_gpio_port;
00131   U8 led_shift;
00132 
00133   mask &= (1 << LED_COUNT) - 1;
00134   Wr_bits(LED_State, mask, leds);
00135   while (mask)
00136   {
00137     led_shift = 1 + ctz(mask);
00138     led_descriptor += led_shift;
00139     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00140     leds >>= led_shift - 1;
00141     if (leds & 1)
00142     {
00143       led_gpio_port->ovrc  = led_descriptor->GPIO.PIN_MASK;
00144     }
00145     else
00146     {
00147       led_gpio_port->ovrs  = led_descriptor->GPIO.PIN_MASK;
00148     }
00149     led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
00150     led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
00151     leds >>= 1;
00152     mask >>= led_shift;
00153   }
00154 }

U8 LED_Get_Intensity ( U32  led  ) 

Gets the intensity of the specified LED.

Parameters:
led LED of which to get the intensity (1 bit per LED; only the least significant set bit is used).
Returns:
Intensity of the specified LED (0x00 to 0xFF).
Warning:
The PWM channel of the specified LED is supposed to be used only by this module.
Note:
The GPIO pin configuration of all LEDs is left unchanged.

Definition at line 238 of file led.c.

References tLED_DESCRIPTOR::CHANNEL, LED_COUNT, and tLED_DESCRIPTOR::PWM.

00239 {
00240   tLED_DESCRIPTOR *led_descriptor;
00241 
00242   // Check that the argument value is valid.
00243   led = ctz(led);
00244   led_descriptor = &LED_DESCRIPTOR[led];
00245   if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0;
00246 
00247   // Return the duty cycle value if the LED PWM channel is enabled, else 0.
00248   return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ?
00249            AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0;
00250 }

void LED_Off ( U32  leds  ) 

Turns off the specified LEDs.

Parameters:
leds LEDs to turn off (1 bit per LED).
Note:
The pins of the specified LEDs are set to GPIO output mode.

Definition at line 163 of file led.c.

References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.

00164 {
00165   tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
00166   volatile avr32_gpio_port_t *led_gpio_port;
00167   U8 led_shift;
00168 
00169   leds &= (1 << LED_COUNT) - 1;
00170   Clr_bits(LED_State, leds);
00171   while (leds)
00172   {
00173     led_shift = 1 + ctz(leds);
00174     led_descriptor += led_shift;
00175     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00176     led_gpio_port->ovrs  = led_descriptor->GPIO.PIN_MASK;
00177     led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
00178     led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
00179     leds >>= led_shift;
00180   }
00181 }

void LED_On ( U32  leds  ) 

Turns on the specified LEDs.

Parameters:
leds LEDs to turn on (1 bit per LED).
Note:
The pins of the specified LEDs are set to GPIO output mode.

Definition at line 184 of file led.c.

References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.

00185 {
00186   tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
00187   volatile avr32_gpio_port_t *led_gpio_port;
00188   U8 led_shift;
00189 
00190   leds &= (1 << LED_COUNT) - 1;
00191   Set_bits(LED_State, leds);
00192   while (leds)
00193   {
00194     led_shift = 1 + ctz(leds);
00195     led_descriptor += led_shift;
00196     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00197     led_gpio_port->ovrc  = led_descriptor->GPIO.PIN_MASK;
00198     led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
00199     led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
00200     leds >>= led_shift;
00201   }
00202 }

U32 LED_Read_Display ( void   ) 

Gets the last state of all LEDs set through the LED API.

Returns:
State of all LEDs (1 bit per LED).
Note:
The GPIO pin configuration of all LEDs is left unchanged.

Definition at line 88 of file led.c.

References LED_State.

00089 {
00090   return LED_State;
00091 }

U32 LED_Read_Display_Field ( U32  field  ) 

Gets as a bit-field the last state of the specified LEDs set through the LED API.

Parameters:
field LEDs of which to get the state (1 bit per LED).
Returns:
State of the specified LEDs (1 bit per LED, beginning with the first specified LED).
Note:
The GPIO pin configuration of all LEDs is left unchanged.

Definition at line 226 of file led.c.

References LED_State.

00227 {
00228   return Rd_bitfield(LED_State, field);
00229 }

U32 LED_Read_Display_Mask ( U32  mask  ) 

Gets the last state of the specified LEDs set through the LED API.

Parameters:
mask LEDs of which to get the state (1 bit per LED).
Returns:
State of the specified LEDs (1 bit per LED).
Note:
The GPIO pin configuration of all LEDs is left unchanged.

Definition at line 121 of file led.c.

References LED_State.

00122 {
00123   return Rd_bits(LED_State, mask);
00124 }

void LED_Set_Intensity ( U32  leds,
U8  intensity 
)

Sets the intensity of the specified LEDs.

Parameters:
leds LEDs of which to set the intensity (1 bit per LED).
intensity New intensity of the specified LEDs (0x00 to 0xFF).
Warning:
The PWM channels of the specified LEDs are supposed to be used only by this module.
Note:
The pins of the specified LEDs are set to PWM output mode.

Definition at line 253 of file led.c.

References tLED_DESCRIPTOR::CHANNEL, tLED_DESCRIPTOR::FUNCTION, tLED_DESCRIPTOR::GPIO, LED_COUNT, tLED_DESCRIPTOR::PIN_MASK, tLED_DESCRIPTOR::PORT, and tLED_DESCRIPTOR::PWM.

00254 {
00255   tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
00256   volatile avr32_pwm_channel_t *led_pwm_channel;
00257   volatile avr32_gpio_port_t *led_gpio_port;
00258   U8 led_shift;
00259 
00260   // For each specified LED...
00261   for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift)
00262   {
00263     // Select the next specified LED and check that it has a PWM channel.
00264     led_shift = 1 + ctz(leds);
00265     led_descriptor += led_shift;
00266     if (led_descriptor->PWM.CHANNEL < 0) continue;
00267 
00268     // Initialize or update the LED PWM channel.
00269     led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL];
00270     if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)))
00271     {
00272       led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) &
00273                              ~(AVR32_PWM_CALG_MASK |
00274                                AVR32_PWM_CPOL_MASK |
00275                                AVR32_PWM_CPD_MASK);
00276       led_pwm_channel->cprd = 0x000000FF;
00277       led_pwm_channel->cdty = intensity;
00278       AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL;
00279     }
00280     else
00281     {
00282       AVR32_PWM.isr;
00283       while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL)));
00284       led_pwm_channel->cupd = intensity;
00285     }
00286 
00287     // Switch the LED pin to its PWM function.
00288     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00289     if (led_descriptor->PWM.FUNCTION & 0x1)
00290     {
00291       led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK;
00292     }
00293     else
00294     {
00295       led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK;
00296     }
00297     if (led_descriptor->PWM.FUNCTION & 0x2)
00298     {
00299       led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK;
00300     }
00301     else
00302     {
00303       led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK;
00304     }
00305     led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK;
00306   }
00307 }

Bool LED_Test ( U32  leds  ) 

Tests the last state of the specified LEDs set through the LED API.

Parameters:
leds LEDs of which to test the state (1 bit per LED).
Returns:
TRUE if at least one of the specified LEDs has a state on, else FALSE.
Note:
The GPIO pin configuration of all LEDs is left unchanged.

Definition at line 157 of file led.c.

References LED_State.

00158 {
00159   return Tst_bits(LED_State, leds);
00160 }

void LED_Toggle ( U32  leds  ) 

Toggles the specified LEDs.

Parameters:
leds LEDs to toggle (1 bit per LED).
Note:
The pins of the specified LEDs are set to GPIO output mode.

Definition at line 205 of file led.c.

References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.

00206 {
00207   tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
00208   volatile avr32_gpio_port_t *led_gpio_port;
00209   U8 led_shift;
00210 
00211   leds &= (1 << LED_COUNT) - 1;
00212   Tgl_bits(LED_State, leds);
00213   while (leds)
00214   {
00215     led_shift = 1 + ctz(leds);
00216     led_descriptor += led_shift;
00217     led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
00218     led_gpio_port->ovrt  = led_descriptor->GPIO.PIN_MASK;
00219     led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
00220     led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
00221     leds >>= led_shift;
00222   }
00223 }


Generated on Wed May 7 14:40:10 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008