Fix time conversion from ms to ticks.
[bertos.git] / bertos / hw / hw_led_7seg.h
1 /**
2  * \file hw_led_7seg.h
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  * -->
31  *
32  * \brief led 7 segment display low-level
33  *
34  * This file has the functions that must be
35  * implemented to drive the 7 segments display by your
36  * hardware
37  *
38  * \author Fabio Bizzi <fbizzi@bizzi.org>
39  *
40  * Example implementation for AtMEGA 1280
41  * (Arduino MEGA) with a 4 digit display.
42  * We use PORTA to connect the 8 pins of
43  * the 7 segments display and 4 bit of
44  * PORTC to select which digit of the
45  * display we have to write on.
46  *
47  * \code
48  *  7 Seg LED Pin
49  *  ----------------
50  *  LED SEGMENT
51  *  ----------------
52  *  DP G F E D C B A
53  *  7  6 5 4 3 2 1 0
54  *  ----------------
55  *  PORT A Pin
56  *  ----------------
57  *
58  *  7 Seg Display Selection
59  *  ----------------
60  *  Display Nr.
61  *  ----------------
62  *  N N N N 3 2 1 0
63  *  7 6 5 4 3 2 1 0
64  *  ----------------
65  *  PORT C Pin
66  *  ----------------
67  * \endcode
68  *
69  * The implementation of the sseg_on procedure that set the PROPER PIN of PORT C
70  * to enable the requested digit of the display, after write the encoded character
71  * to PORT A
72  *
73  * \code
74  *
75  * INLINE void sseg_on(uint8_t dgt, uint8_t n_dgt)
76  * {
77  *  switch (n_dgt)
78  *  {
79  * //Common Cathode
80  * #ifdef CONFIG_LED_7SEG_CCAT
81  *
82  *              case 0:
83  *                      PORTC &= ~(BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
84  *                      PORTC |= BV(PORTC0);
85  *                      break;
86  *              case 1:
87  *                      PORTC &= ~(BV(PORTC0) | BV(PORTC2) | BV(PORTC3));
88  *                      PORTC |= BV(PORTC1);
89  *                      break;
90  *              case 2:
91  *                      PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC3));
92  *                      PORTC |= BV(PORTC2);
93  *                      break;
94  *              case 3:
95  *                      PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2));
96  *                      PORTC |= BV(PORTC3);
97  *                      break;
98  *
99  * //Common Anode
100  * #else
101  *
102  *              case 0:
103  *                      PORTC |= (BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
104  *                      PORTC &= ~(BV(PORTC0));
105  *                      break;
106  *              case 1:
107  *                      PORTC |= (BV(PORTC0) | BV(PORTC2) | BV(PORTC3));
108  *                      PORTC &= ~(BV(PORTC1));
109  *                      break;
110  *              case 2:
111  *                      PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC3));
112  *                      PORTC &= ~(BV(PORTC2));
113  *                      break;
114  *              case 3:
115  *                      PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2));
116  *                      PORTC &= ~(BV(PORTC3));
117  *                      break;
118  *
119  * #endif
120  *
121  *      }
122  *      //Write the charater
123  *      PORTA = dgt;
124  * }
125  *
126  * \endcode
127  *
128  * The implementation of the sseg_init procedure that set the DIRECTION of PORT C
129  * and PORT A to output
130  *
131  * \code
132  *
133  * INLINE void sseg_init(void)
134  * {
135  * //Initialize PIN Direction to OUTPUT
136  *      DDRA = 0xFF;
137  *      DDRC |= (BV(DDC0) | BV(DDC1) | BV(DDC2) | BV(DDC3));
138  *      //Set the display OFF
139  *      SSEG_OFF();
140  * }
141  *
142  * \endcode
143  *
144  * The implementation of the sseg_off procedure that set the reset PORT A
145  * to clean the display and turn off all the pin of PORT C that drive the
146  * display's digits
147  *
148  * \code
149  *
150  * INLINE void sseg_off(void)
151  * {
152  * //Set the display OFF
153  * //Common Cathode
154  * #ifdef CONFIG_LED_7SEG_CCAT
155  *    PORTA = 0x00;
156  *    PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
157  * //Common Anode
158  * #else
159  *    PORTA = 0xFF;
160  *    PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
161  * #endif
162  *
163  * }
164  *
165  * \endcode
166  *
167  */
168
169 #ifndef HW_LED_7SEG_H
170 #define HW_LED_7SEG_H
171
172 #include "cfg/cfg_led_7seg.h"
173
174 /*
175  * INLINE HW Functions
176  */
177
178 /**
179  * \brief Clean the display
180  *
181  * This is the procedure that clean the display in HW mode.
182  * you have to write it according with your hardware and micro.
183  */
184 INLINE void sseg_off(void)
185 {
186 /* Set the display OFF */
187 #ifdef CONFIG_LED_7SEG_CCAT
188 /* You have to implment it */
189 /* Common Cathode */
190 #else
191 /* You have to implment it */
192 /* Common Anode */
193 #endif
194 }
195
196 /**
197  * \brief writes the character to the single digit of the display
198  *
199  * This is the procedure that writes the character to the single digit
200  * of the display, you have to write it according with your hardware and micro.
201  *
202  *      \param dgt the character that has to be displayed
203  *      \param n_dgt the digit where to disply the character of the display's digits.
204  */
205 INLINE void sseg_on(uint8_t dgt, uint8_t n_dgt)
206 {
207         (void) dgt;
208         (void) n_dgt;
209 #ifdef CONFIG_LED_7SEG_CCAT
210 /* Common Cathode */
211 /* You have to implment it */
212 #else
213 /* Common Anode */
214 /* You have to implment it */
215 #endif
216 }
217
218 /**
219  * \brief initalize the HW regsiters
220  *
221  * This is the procedure that initalize the HW regsiters.
222  * you have to write it according with your hardware and micro.
223  */
224 INLINE void sseg_init(void)
225 {
226         /* Initialize PIN Direction to OUTPUT*/
227         /* You have to implment it */
228         /* Set the display OFF */
229         sseg_off();
230 }
231
232 #endif /* HW_LED_7SEG_H */
233