led.h
Go to the documentation of this file.
1#ifndef LED_H
2#define LED_H
3
4#include <stdint.h>
5#include "check.h"
6
7/**
8 * \addtogroup LED LED access
9 *
10 * \brief Interface to the board's 8 LEDs
11 *
12 * @{
13 * \file led.h
14 * \version \$Rev: 7715 $
15 */
16
17/**
18 * \brief LED identifiers
19 */
20 typedef enum {
21 RED0 = 0, /**< Upper red led **/
22 YELLOW0 = 1, /**< Upper yellow led **/
23 GREEN0 = 2, /**< Upper green led **/
24 BLUE0 = 3, /**< Upper blue led **/
25 RED1 = 4, /**< Lower red led **/
26 YELLOW1 = 5, /**< Lower yellow led **/
27 GREEN1 = 6, /**< Lower green led **/
28 BLUE1 = 7 /**< Lower blue led **/
29} __attribute__ ((__packed__)) LED;
30
31 CHECK_ENUM_SIZE(LED, 1)
32
33/**
34 * \brief Activates a specific LED
35 *
36 * \param led LED ID
37 *
38 * \return 0 on success, negative value on error
39 *
40 * \retval 0 success
41 * \retval -1 invalid LED ID
42 */
43int8_t sb_led_on(LED led);
44
45/**
46 * \brief Deactivates a specific LED
47 *
48 * \param led LED ID
49 *
50 * \return 0 on success, negative value on error
51 *
52 * \retval 0 success
53 * \retval -1 invalid LED ID
54 */
55int8_t sb_led_off(LED led);
56
57/**
58 * \brief Toggles a specific LED
59 *
60 * \param led LED ID
61 *
62 * \return 0 on success, negative value on error
63 *
64 * \retval 0 success
65 * \retval -1 invalid LED ID
66 */
67int8_t sb_led_toggle(LED led);
68
69/**
70 * \brief Uses the LED array as a level indicator
71 *
72 * Allows the array of LEDs to be used as a (fill) level, progress
73 * or similar indicator. The 8 LEDs are used to display a ratio of
74 * a max-value<=255 in 9 steps.
75 *
76 * \param level level value
77 * \param max maximum possible value
78 *
79 * \return the number of LEDs turned on on success, negative value on error
80 *
81 * \retval >=0 success
82 * \retval -1 level exceeds max
83 * \retval -2 max is 0
84 */
85int8_t sb_led_showLevel(uint8_t level, uint8_t max);
86
87/**
88 * \brief Sets all LEDs according to a bitfield
89 *
90 * The bitfield contains one bit for each LED (the least significant bit
91 * corresponds to `RED0`, the most significant bit `BLUE1`). A set bit
92 * enables and a cleared bit disables the corresponding LED.
93 * \image html led_mask.png
94 * \param mask 8-bit bitfield describing the desired LED states
95 */
96 void sb_led_setMask(uint8_t mask);
97
98/** @}*/
99
100#endif
101
check.h
CHECK_ENUM_SIZE
#define CHECK_ENUM_SIZE(VAR, LEN)
Definition: check.h:71
sb_led_off
int8_t sb_led_off(LED led)
Deactivates a specific LED.
sb_led_toggle
int8_t sb_led_toggle(LED led)
Toggles a specific LED.
sb_led_setMask
void sb_led_setMask(uint8_t mask)
Sets all LEDs according to a bitfield.
sb_led_on
int8_t sb_led_on(LED led)
Activates a specific LED.
LED
LED
LED identifiers.
Definition: led.h:20
sb_led_showLevel
int8_t sb_led_showLevel(uint8_t level, uint8_t max)
Uses the LED array as a level indicator.
GREEN1
@ GREEN1
Definition: led.h:27
YELLOW1
@ YELLOW1
Definition: led.h:26
BLUE0
@ BLUE0
Definition: led.h:24
RED0
@ RED0
Definition: led.h:21
GREEN0
@ GREEN0
Definition: led.h:23
RED1
@ RED1
Definition: led.h:25
YELLOW0
@ YELLOW0
Definition: led.h:22
BLUE1
@ BLUE1
Definition: led.h:28