EVE 1.0
led.h
Go to the documentation of this file.
1 #ifndef DRIVER_LED_H
2 #define DRIVER_LED_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2014, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief Driver for Leds
36  *
37  * @author AMO, Jetro as
38  */ /******************************************************************/
39 
40 #include <core/mwork.h>
41 
42 /** \defgroup led LED driver
43  * \ingroup abstract
44  * \{
45  *
46  * Totally 32 LEDs can be updated.
47  * Functionality included if LED_ENABLED is set true:
48  * - Initialization of led function
49  * - Setting of LEDs, off, on or flashing.
50  * (several flashing pattern can be defined).
51  * - Led counting (number of count and timing is selectable).
52  *
53  * if flashing functions are wanted LED_FLASHING_ENABLED must be set true and
54  * the number of flashing pattern must be defined by NUMBER_OF_FLASHING_PATTERN.
55  * Each flashing pattern must be defined in table "struct led_flash_t LedFlashing[]" in Board.c.
56  * if counting function is wanted LED_COUNTING_ENABLED must be set true.
57  *
58  * Output function for setting each led is based of the inline code UpdateLeds().
59  *
60  */
61 
62 /***********************************************************************
63  * Global defines
64 ***********************************************************************/
65 
66 /** Indexes of the Time array in the struct led_counting_t */
67 enum {
68  COUNTING_ON, //!< Time in processor ticks LED(s) is on
69  COUNTING_OFF, //!< Time in processor ticks LED(s) is off
70  COUNTING_PAUSE, //!< Pause time in processor ticks between flashing series
71  NUMBER_OF_COUNTING_TIMES //!< Gives array size
72 };
73 
74 /** Parameters for LED counting */
76 {
77  uint16_t Time[NUMBER_OF_COUNTING_TIMES]; //!< 1/1.024 ms resolution, use MWORK_MSEC(). If Time[COUNTING_PAUSE] = 0, the flashing is stopped after one sequence
78  uint8_t Count; //!< Number of flashes per flashing serie
79  bool Invert; //!< If TRUE, the flashing is inverted (ON<->OFF)
80 };
81 
82 /** Constant flashing parameters */
84 {
85  uint16_t OnTime; //!< Time the LED is on, 1/1.024 ms resolution, use MWORK_MSEC()
86  uint16_t OffTime; //!< Time the LED is off, 1/1.024 ms resolution, use MWORK_MSEC()
87 };
88 
89 /** Input parameters for LedSet() function */
90 enum {
91  LED_OFF = 0x00, //!< Set LED(s) off
92  LED_ON = 0x01, //!< Set LED(s) on
93  LED_FLASHING = 0x02, //!< Set LED(s) to constant flashing
94  LED_INVERT_FLASHING = 0x80, //!< Set LED(s) to constant invert flashing
95 };
96 
97 /**
98  * \name Functions called from application programs
99  * \{
100  */
101 /**********************************************************************/
102 /**
103  * @brief Initialize LED driver.
104  * Must be called before LedSet() or LedCounting() can be called.
105  ***********************************************************************/
106 extern void LedInit(void);
107 
108 /**********************************************************************/
109 /**
110  * @brief Sets LED(s) function (on/off/flash).
111  *
112  * @param Leds Each bit position (0-31) represent a LED.
113  * New function can be set for several Leds in one
114  * function call.
115  * If no LEDs are already flashing, the flashing
116  * sequence is restarted.
117  *
118  * @param Function Select LED functionality:
119  * LED_OFF
120  * LED_ON
121  * LED_FLASHING + type of LED flashing pattern (0 to max 99)
122  * + optional LED_INVERT_FLASHING if inverted flashing
123  * pattern is wanted
124  ***********************************************************************/
125 extern void LedSet(uint32_t Leds, uint32_t Function);
126 
127 /**********************************************************************/
128 /**
129  * @brief Sets LED(s) to counting function.
130  *
131  * @param Leds Each bit position (0-31) represent a LED.
132  * New function can be set for several Leds in one
133  * function call.
134  * The counting sequence is stopped by LedSet(LED_OFF)
135  *
136  * @param Function Select LED funtionality:
137  * .Count - number of counts (0-255)
138  * .Invert - true is invert, else false
139  * .Time[COUNTING_ON] - counting pulse on time,
140  * .Time[COUNTING_OFF] - counting pulse off time
141  * .Time[COUNTING_PAUSE]- pause between counting sequences, set to 0
142  * if only one counting sequence is wanted
143  * .Time[] is 1/1.024 ms resolution, use MWORK_MSEC().
144  ***********************************************************************/
145 static inline void LedCounting(uint32_t Leds, const struct led_counting_t * Function)
146 {
147  LedSet(Leds, (uint32_t)Function);
148 }
149 
150 /** \} */
151 
152 /** \name Application' LED configuration and supplied functions.
153  * \{
154  * The following is the LED driver setup for application's board.h and
155  * board.c files.
156  */
157 
158 #ifdef LED_DRIVER_DOXYGEN
159 
160 #define LED_FLASHING_ENABLED true/false //!< If true, LED driver supports flashing
161 
162 #define LED_COUNTING_ENABLED true/false //!< If true, LED driver supports sequence flashing
163 
164 #define NUMBER_OF_FLASHING_PATTERN Number //!< Number == How many flashing patterns defined?
165 
166 const struct led_flash_t LedFlashing[NUMBER_OF_FLASHING_PATTERN]; //!< User's array of \ref led_flash_t defines flashing patterns
167 
168 /**********************************************************************/
169 /**
170  * \brief User supplied function to update LEDs.
171  *
172  * The function must be provided to LED driver in board.h and allows application
173  * to use for example GPIO expanders instead of processor' GPIO to drive LEDs.
174  *
175  * LED bit positions are abstract and application can map them to physical GPIO
176  * if required. So for example if application requests to turn LED #2 on, then
177  * the driver calls this UpdateLeds() callback with bit #2 settled.
178  *
179  * \param BitLedOn Bit values (on/off) for all 32 LEDs
180  *
181  **********************************************************************/
182 static void UpdateLeds(uint32_t BitLedOn);
183 
184 #endif
185 
186 /** \} */
187 
188 /** \} led */
189 
190 #endif
Header file for the EVE millisecond-scale work scheduling.
Set LED(s) on.
Definition: led.h:92
Set LED(s) off.
Definition: led.h:91
uint16_t OnTime
Time the LED is on, 1/1.024 ms resolution, use MWORK_MSEC()
Definition: led.h:85
Time in processor ticks LED(s) is on.
Definition: led.h:68
Pause time in processor ticks between flashing series.
Definition: led.h:70
Gives array size.
Definition: led.h:71
#define NUMBER_OF_FLASHING_PATTERN
Number == How many flashing patterns defined?
Definition: led.h:164
Set LED(s) to constant invert flashing.
Definition: led.h:94
static void UpdateLeds(uint32_t BitLedOn)
User supplied function to update LEDs.
static void LedCounting(uint32_t Leds, const struct led_counting_t *Function)
Sets LED(s) to counting function.
Definition: led.h:145
uint16_t Time[NUMBER_OF_COUNTING_TIMES]
1/1.024 ms resolution, use MWORK_MSEC(). If Time[COUNTING_PAUSE] = 0, the flashing is stopped after o...
Definition: led.h:77
void LedInit(void)
Initialize LED driver. Must be called before LedSet() or LedCounting() can be called.
bool Invert
If TRUE, the flashing is inverted (ON<->OFF)
Definition: led.h:79
Set LED(s) to constant flashing.
Definition: led.h:93
uint16_t OffTime
Time the LED is off, 1/1.024 ms resolution, use MWORK_MSEC()
Definition: led.h:86
void LedSet(uint32_t Leds, uint32_t Function)
Sets LED(s) function (on/off/flash).
Time in processor ticks LED(s) is off.
Definition: led.h:69
uint8_t Count
Number of flashes per flashing serie.
Definition: led.h:78
const struct led_flash_t LedFlashing[NUMBER_OF_FLASHING_PATTERN]
User&#39;s array of led_flash_t defines flashing patterns.
Definition: led.h:166