libpynq (release 5EWC0-2023 version 0.2.2 of 2023-09-24 22:22)
Loading...
Searching...
No Matches
LED library

Macros

#define NUM_LED_COLORS   3 /* # colors per color LED (RGB) */
 
#define NUM_LEDS   (NUM_GREEN_LEDS + NUM_COLOR_LEDS)
 
#define LED_OFF   0
 
#define LED_ON   255
 

Enumerations

enum  green_led_index_t {
  LED0 , LED1 , LED2 , LED3 ,
  NUM_GREEN_LEDS
}
 
enum  color_led_index_t { COLOR_LED0 , COLOR_LED1 , NUM_COLOR_LEDS }
 

Functions

void leds_init_onoff (void)
 
void green_leds_init_pwm (void)
 
void color_leds_init_pwm (void)
 
void leds_destroy (void)
 
void green_led_onoff (const int led, const int onoff)
 
void green_led_on (const int led)
 
void green_led_off (const int led)
 
void color_led_red_onoff (const int onoff)
 
void color_led_green_onoff (const int onoff)
 
void color_led_blue_onoff (const int onoff)
 
void color_led_onoff (const int red_onoff, const int green_onoff, const int blue_onoff)
 
void color_led_on (void)
 
void color_led_off (void)
 

Detailed Description

Wrappers to simplify the use of LEDs.

LEDs can be used in three modes:

  1. on/off mode for all green LEDs and all color LEDs
  2. PWM mode for green LEDs (PWM0..PWM3 are rounted to green LEDs 0..3)
  3. PWM mode for color LED 0 (PWM0..PWM3 are routed to color LED 0)

An example of how to use this library.

#include <libpynq.h>
int main (void)
{
// initialise all I/O
for (int led = 0; led < NUM_GREEN_LEDS; led++)
sleep_msec(500);
for (int led = 0; led < NUM_GREEN_LEDS; led++)
// clean up after use
leds_destroy(); // switches all leds off
return EXIT_SUCCESS;
}
void gpio_reset(void)
Reset all GPIO pins.
Definition gpio.c:62
void leds_init_onoff(void)
Initialize the green LEDs for on/off use.
Definition leds.c:37
void green_led_off(const int led)
Same as green_led_onoff(led, LED_OFF). Works in all modes.
Definition leds.c:147
void green_led_on(const int led)
Same as green_led_onoff(led, LED_ON). Works in all modes.
Definition leds.c:146
void leds_destroy(void)
Definition leds.c:96
@ NUM_GREEN_LEDS
Definition leds.h:85
void sleep_msec(int msec)
Wait for msec milliseconds.
Definition util.c:32
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
Definition libpynq.c:35

LEDs can also be used through GPIO (see gpio.h and pinmap.h). Note that GPIO numbering (SWB_LD0..SWB_LD3) is then used instead of 0..NUM_GREEN_LEDS-1 (LED0..LED3). In the PWM mode for color LED 0, SWB_PWM0..SWB_PWM3 are routed to color LED 0 (GPIO SWB_LD4R, SWB_LD4G, SWB_LD4B).

Macro Definition Documentation

◆ LED_OFF

#define LED_OFF   0

Definition at line 102 of file leds.h.

◆ LED_ON

#define LED_ON   255

Definition at line 103 of file leds.h.

◆ NUM_LED_COLORS

#define NUM_LED_COLORS   3 /* # colors per color LED (RGB) */

Definition at line 100 of file leds.h.

◆ NUM_LEDS

#define NUM_LEDS   (NUM_GREEN_LEDS + NUM_COLOR_LEDS)

Definition at line 101 of file leds.h.

Enumeration Type Documentation

◆ color_led_index_t

Enum of color LEDs. Functions for color LEDs use a led number from 0..NUM_COLOR_LEDS-1. Alternatively, you can use COLOR_LEDi instead of just i if you find that clearer.

Enumerator
COLOR_LED0 
COLOR_LED1 
NUM_COLOR_LEDS 

Definition at line 94 of file leds.h.

◆ green_led_index_t

Enum of green LEDs. Functions for green LEDs use a led number from 0..NUM_GREEN_LEDS-1. Alternatively, you can use LEDi instead of just i if you find that clearer.

Enumerator
LED0 
LED1 
LED2 
LED3 
NUM_GREEN_LEDS 

Definition at line 80 of file leds.h.

Function Documentation

◆ color_led_blue_onoff()

void color_led_blue_onoff ( const int  onoff)

Switches on/off the blue component of color LED 0.

Parameters
onoffIf the LEDs are in onoff mode then onoff must be either LED_ON or LED_OFF. If the LEDs are in one of the PWM modes then onoff must be 0.255.
Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 195 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ color_led_green_onoff()

void color_led_green_onoff ( const int  onoff)

Switches on/off the green component of color LED 0.

Parameters
onoffIf the LEDs are in onoff mode then onoff must be either LED_ON or LED_OFF. If the LEDs are in one of the PWM modes then onoff must be 0.255.
Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 172 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ color_led_off()

void color_led_off ( void  )

Set color LED 0 to black. Same as color_led_onoff(LED_OFF, LED_OFF, LED_OFF).

Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 226 of file leds.c.

Here is the call graph for this function:

◆ color_led_on()

void color_led_on ( void  )

Set color LED 0 to white. Same as color_led_onoff(LED_ON, LED_ON, LED_ON).

Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 225 of file leds.c.

Here is the call graph for this function:

◆ color_led_onoff()

void color_led_onoff ( const int  red_onoff,
const int  green_onoff,
const int  blue_onoff 
)

Switches on/off the red/green/blue components of color LED 0.

Parameters
onoffIf the LEDs are in onoff mode then *_onoff must be either LED_ON or LED_OFF. If the LEDs are in one of the PWM modes then *_onoff must be 0.255.
Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 218 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ color_led_red_onoff()

void color_led_red_onoff ( const int  onoff)

Switches on/off the red component of color LED 0.

Parameters
onoffIf the LEDs are in onoff mode then onoff must be either LED_ON or LED_OFF. If the LEDs are in one of the PWM modes then onoff must be 0.255.
Warning
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 148 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ color_leds_init_pwm()

void color_leds_init_pwm ( void  )

Initialize the color LEDs for use with variable intensity. The LED intensity can range from 0.255.

Warning
Fails with program exit when LEDs have already been to another mode.

Definition at line 79 of file leds.c.

Here is the call graph for this function:

◆ green_led_off()

void green_led_off ( const int  led)

Same as green_led_onoff(led, LED_OFF). Works in all modes.

Parameters
ledThe green LED.
Warning
Fails with program exit when led is outside valid range.
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 147 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ green_led_on()

void green_led_on ( const int  led)

Same as green_led_onoff(led, LED_ON). Works in all modes.

Parameters
ledThe green LED.
Warning
Fails with program exit when led is outside valid range.
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 146 of file leds.c.

Here is the call graph for this function:

◆ green_led_onoff()

void green_led_onoff ( const int  led,
const int  onoff 
)
Parameters
ledThe green LED.
onoffIf the LEDs are in onoff mode then onoff must be either LED_ON or LED_OFF. If the LEDs are in one of the PWM modes then onoff must be 0.255.
Warning
Fails with program exit when led is outside valid range.
Fails with program exit when LEDs were not initialized with the correct mode.

Definition at line 117 of file leds.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ green_leds_init_pwm()

void green_leds_init_pwm ( void  )

Initialize the green LEDs for use with variable intensity. The LED intensity can range from 0.255.

Warning
Fails with program exit when LEDs have already been to another mode.

Definition at line 58 of file leds.c.

Here is the call graph for this function:

◆ leds_destroy()

void leds_destroy ( void  )

Unitialize the LEDs, such that the mode of the LEDs can be changed. Switch all lEDs off.

Definition at line 96 of file leds.c.

Here is the call graph for this function:

◆ leds_init_onoff()

void leds_init_onoff ( void  )

Initialize the green LEDs for on/off use.

Warning
Fails with program exit when LEDs have already been to another mode.

Definition at line 37 of file leds.c.

Here is the call graph for this function: