LEDs.h 2.58 KB
Newer Older
Sebastian Neuser's avatar
Sebastian Neuser committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
///\file
///\brief   Driver for the two RGB LEDs on the ProgBob board

#ifndef LEDS_H
#define LEDS_H

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>


///\brief   Bitmask for the left red LED
#define LEDS_LED_LR         (1 << 4)

///\brief   Bitmask for the left green LED
#define LEDS_LED_LG         (1 << 6)

///\brief   Bitmask for the left blue LED
#define LEDS_LED_LB         (1 << 5)

///\brief   Bitmask for all left LEDs
#define LEDS_MASK_LEFT      (LEDS_LED_LR | LEDS_LED_LG | LEDS_LED_LB)

///\brief   DDR register for left LEDs
#define LEDS_DDR_LEFT       DDRC

///\brief   PORT register for left LEDs
#define LEDS_PORT_LEFT      PORTC

///\brief   Bitmask for the right red LED
#define LEDS_LED_RR         (1 << 5)

///\brief   Bitmask for the right green LED
#define LEDS_LED_RG         (1 << 7)

///\brief   Bitmask for the right blue LED
#define LEDS_LED_RB         (1 << 6)

///\brief   Bitmask for all left LEDs
#define LEDS_MASK_RIGHT     (LEDS_LED_RR | LEDS_LED_RG | LEDS_LED_RB)

///\brief   DDR register for right LEDs
#define LEDS_DDR_RIGHT      DDRB

///\brief   PORT register for right LEDs
#define LEDS_PORT_RIGHT     PORTB


///\brief   Available RGB LEDs
enum leds_led {
    LEDS_LED_LEFT,
    LEDS_LED_RIGHT,
};

///\brief   Colors used to indicate things
enum leds_color {
    LEDS_COLOR_BOB3_CONNECTED       = 0x008800, ///< green: BOB3 board connected
    LEDS_COLOR_BOB3_NOT_CONNECTED   = 0xaa0000, ///< red: BOB3 board not connected
    LEDS_COLOR_BOB3_PROGRAMMING     = 0x880088, ///< magenta: USB interface is busy
    LEDS_COLOR_USB_ENUMERATING      = 0xaa8800, ///< yellow: USB interface is enumerating
    LEDS_COLOR_USB_ERROR            = 0xaa0000, ///< red: Error in USB interface
    LEDS_COLOR_USB_NOT_READY        = 0x0000aa, ///< blue: USB interface is not ready
    LEDS_COLOR_USB_READY            = 0x008800, ///< green: USB interface is ready
};


///\brief   En-/disables LED fading
///\param   disable
///             if `true`, fading of LED intensity is paused
void leds_disable_fading(bool disable);

///\brief   Configures LED GPIOS as output and sets up a timer interrupt for PWM generation.
void leds_init(void);

///\brief   Sets an LED's color
///\param   led
///             the LED to configure
///\param   color
///             the color to set as 0xRRGGBB
void leds_set_color(enum leds_led led, uint32_t color);

///\brief   Sets an LED's intensity fade frequency
///\param   led
///             the LED to configure
///\param   frequency
///             frequency in [Hz]; `0` disables fading
void leds_set_fade_frequency(enum leds_led led, uint8_t frequency);


#endif