uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions | Variables
leds.c File Reference

Handling of the on-board LEDs. More...

#include "gpio.h"
#include "leds.h"
#include <avr/interrupt.h>
Include dependency graph for leds.c:

Functions

static void apply_led (struct led *const led, bool value)
 Enables or disables an LED by writing the corresponding GPIO output register. More...
 
static void set_or_update_blinking_led_state (struct led_state *const state, uint8_t prescaler)
 Initializes or updates an LED's blinking mode. More...
 
void init_leds_module (void)
 Module initialization procedure. More...
 
void register_led (struct led *const led)
 Add an LED to the cyclic processed LEDs. More...
 
void blink_led (struct led *const led, const uint8_t prescaler)
 Lets an LED blink in a fixed interval. More...
 
void flash_led (struct led *const led)
 Briefly flashes an LED. More...
 
void flash_led_multiple (struct led *const led, const uint8_t count)
 Briefly flashes an LED. More...
 
void set_led (struct led *const led, const bool value)
 Enables or disables an LED. More...
 
void toggle_led (struct led *const led)
 Toggles an LED. More...
 
static void update_flashing_led (uint8_t index)
 
void update_leds (void)
 State machine task that updates the LEDs. More...
 

Variables

static struct ledleds [32] = { 0, }
 Internal array of pointers to known leds. More...
 
static uint8_t registered_leds_count = 0
 Number of registered LEDs. More...
 
static const struct gpio_pin green_led_pin
 The GPIO pin the green LED is connected to. More...
 
static struct led green_led
 The green on-board LED. More...
 
static const struct gpio_pin red_led_pin
 The GPIO pin the red LED is connected to. More...
 
static struct led red_led
 The red on-board LED. More...
 
struct ledled_green = &green_led
 The green onboard LED. More...
 
struct ledled_red = &red_led
 The green onboard LED. More...
 

Detailed Description

Handling of the on-board LEDs.

Function Documentation

◆ apply_led()

static void apply_led ( struct led *const  led,
bool  value 
)
inlinestatic

Enables or disables an LED by writing the corresponding GPIO output register.

Parameters
ledthe LED to enable / disable
valuetrue enables the LED; false disables it

◆ blink_led()

void blink_led ( struct led led,
uint8_t  prescaler 
)

Lets an LED blink in a fixed interval.

The prescaler parameter controls the blinking frequency: Every prescaler th time the update_leds procedure is called, the LED is toggled.

Parameters
ledthe LED that should blink
prescalercontrols the blinking frequency
See also
led
update_leds

◆ flash_led()

void flash_led ( struct led led)

Briefly flashes an LED.

Parameters
ledthe LED that should flash
See also
led

◆ flash_led_multiple()

void flash_led_multiple ( struct led led,
uint8_t  count 
)

Briefly flashes an LED.

Parameters
ledthe LED that should flash
countthe LED will flash this many times
See also
led

◆ init_leds_module()

void init_leds_module ( void  )

Module initialization procedure.

Writes relevant AVR GPIO configuration for the onboard LEDs

◆ register_led()

void register_led ( struct led const)

Add an LED to the cyclic processed LEDs.

Writes relevant AVR GPIO configuration for the given LEDs and adds the given pointer that contains the corresponding gpio_pin

◆ set_led()

void set_led ( struct led led,
bool  enable 
)

Enables or disables an LED.

Parameters
ledthe LED that should be enabled/disabled
enabletrue switches the LED on; false swithes off
See also
led

◆ set_or_update_blinking_led_state()

static void set_or_update_blinking_led_state ( struct led_state *const  state,
uint8_t  prescaler 
)
static

Initializes or updates an LED's blinking mode.

Aborts if neither mode nor prescaler have changed

Parameters
statestate variable of the led
prescalerPrescaler for the blinking frequency

◆ toggle_led()

void toggle_led ( struct led led)

Toggles an LED.

Parameters
ledthe LED that should be toggled
See also
led

◆ update_flashing_led()

static void update_flashing_led ( uint8_t  index)
static

◆ update_leds()

void update_leds ( void  )

State machine task that updates the LEDs.

This task must be included in the state machine tasks for the blink and flash modes to work.

See also
init_state_machine

Variable Documentation

◆ green_led

struct led green_led
static
Initial value:
= {
.pin = &green_led_pin,
}
static const struct gpio_pin green_led_pin
The GPIO pin the green LED is connected to.
Definition: leds.c:40

The green on-board LED.

◆ green_led_pin

const struct gpio_pin green_led_pin
static
Initial value:
= {
.port = &PORTE,
.bit = 1
}

The GPIO pin the green LED is connected to.

◆ led_green

struct led* led_green = &green_led

The green onboard LED.

◆ led_red

struct led* led_red = &red_led

The green onboard LED.

◆ leds

struct led* leds[32] = { 0, }
static

Internal array of pointers to known leds.

◆ red_led

struct led red_led
static
Initial value:
= {
.pin = &red_led_pin,
}
static const struct gpio_pin red_led_pin
The GPIO pin the red LED is connected to.
Definition: leds.c:51

The red on-board LED.

◆ red_led_pin

const struct gpio_pin red_led_pin
static
Initial value:
= {
.port = &PORTE,
.bit = 0
}

The GPIO pin the red LED is connected to.

◆ registered_leds_count

uint8_t registered_leds_count = 0
static

Number of registered LEDs.