4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
32 * \author Fabio Bizzi <fbizzi@bizzi.org>
34 * \defgroup SevenSegDisplay 7 Segments LED Displays Driver
38 * \brief 7 segments LED displays (headers)
40 * Here you find the prototypes and the data structures that
41 * format and holds the text that has to be displayed by the
44 * The main function is the sevenseg_print()
45 * that is called by your software to display the text, also
46 * important is the sevenseg_init() that initialize the data
47 * structures and set the refresh timer, you need to call
48 * this procedure just one time in the init procedure of
49 * your software before any use of the sevenseg_print().
53 * To use succesfully the display you have to follow these steps:
55 * \li Create the structure and init the display
56 * \li Check if the display is ready to accept a new print with
57 * the function sevenseg_isReady()
58 * \li Unlock the display with the function sevenseg_unlock()
59 * NOTE: when the display is unlocked the displaying of any
60 * text is stopped but the data (text and attributes like text
61 * position, blinking etc etc) are not erased.
62 * \li Set the wanted text attributes with sevenseg_set* functions
63 * \li Print the wanted text with sevenseg_print()
64 * \li Lock the display with sevenseg_lock()
66 * When the display is locked the displaying of the text starts.
70 * static Seven_Seg display;
72 * sevenseg_init(&display);
73 * while (!sevenseg_isReady(&display))
75 * sevenseg_unlock(&display);
76 * sevenseg_setBlink(&display,false,0);
77 * sevenseg_setRunonce(&display,false);
78 * sevenseg_setRunspeed(&display,10);
79 * if ((sevenseg_print(&display, "made with bertos.")) != 0)
81 * sevenseg_lock(&display);
84 * $WIZ$ module_name = "led_7seg"
85 * $WIZ$ module_depends = "timer"
86 * $WIZ$ module_configuration = "bertos/cfg/cfg_led_7seg.h"
87 * $WIZ$ module_hw = "bertos/hw/hw_led_7seg.h"
90 #ifndef DRV_LED_7SEG_H
91 #define DRV_LED_7SEG_H
93 #include "cfg/cfg_led_7seg.h"
94 #include <drv/timer.h>
95 #include <mware/event.h>
98 * \name Numbers and Letters Table.
99 * \note These tables contain all the printable
100 * characters on a 7 segment digit encoded
101 * for common cathode and common anode
104 * 0, 1, 2, 3, 4, 5, 6, 7, 8,
105 * 9, ., -, A, B, C, D, E, F,
106 * G, H, I, J, K, L, M, N, O,
107 * P, Q, R, S, T, U, V, W, X,
112 #if CONFIG_LED_7SEG_CCAT
113 static const uint8_t segstable[] =
115 0x3f, 0x6, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x7, 0x7f,
116 0x6f, 0x80, 0x40, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,
117 0x3d, 0x74, 0x30, 0x1e, 0x75, 0x38, 0x15, 0x37, 0x3f,
118 0x73, 0x67, 0x50, 0x6d, 0x78, 0x3e, 0x2a, 0x6a, 0x76,
122 static const uint8_t segstable[] =
124 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80,
125 0x90, 0x7f, 0xbf, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e,
126 0xc2, 0x8b, 0xcf, 0xe1, 0x8a, 0xc7, 0xea, 0xc8, 0xc0,
127 0x8c, 0x98, 0xaf, 0x92, 0x87, 0xc1, 0xd5, 0x95, 0x89,
134 * Context data for Display functions
137 typedef struct SevenSeg
139 /** The String to be displayed */
140 uint8_t string[CONFIG_LED_7SEG_STRLEN];
141 /** The length of the string to be displayed */
142 unsigned int string_len;
145 /** Has to blink only one digit? */
147 /** Has to be displayed only one time? */
149 /** Scrolling speed */
151 /** Working scrolling speed */
152 unsigned int curspeed;
153 /** Is it printed at least one time? */
155 /** Working current position */
157 /** Working current digit */
158 unsigned int curdigit;
159 /** Is the structure in edit? */
163 /* Functions prototypes */
166 * This is the procedure that fills the seven_seg structure with the translated
167 * string to display. It swaps also the structures to display the new text when
168 * all the data is ready to display.
170 int sevenseg_print(SevenSeg *SS, const char *sstring);
173 * This is the procedure that inits all the structures that rules the 7 segments
174 * display and set the timer for the proper print/refresh of the text.
176 void sevenseg_init(SevenSeg *SS);
179 * This is the procedure that does a short print of all segments of all
180 * digits of the display.
182 void sevenseg_test(SevenSeg *SS);
185 * This is the procedure that check if the print of the current text is run
186 * almost one time and we're ready to print a new text.
188 bool sevenseg_isReady(SevenSeg *SS);
191 * This is the procedure that check if the print of the current text is run
192 * almost one time and then set the status of the display to "unlocked".
194 bool sevenseg_unlock(SevenSeg *SS);
197 * This is the procedure that lock the display and permit
198 * the print of the text.
200 bool sevenseg_lock(SevenSeg *SS);
203 * This is the procedure that set the blinking of the display.
204 * You can choose to blink all the display or only a single
207 bool sevenseg_setBlink(SevenSeg *SS, bool blink, uint8_t digit);
210 * This is the procedure that set if the text has to be displayed
213 bool sevenseg_setRunonce(SevenSeg *SS, bool runonce);
216 * This is the procedure that set the scrolling speed of the text
217 * if the text is longer than the display digits or the
218 * duration of the display if the text is smaller or equal the
219 * length of display digits.
221 bool sevenseg_setRunspeed(SevenSeg *SS, unsigned int r_speed);
224 * This is the procedure that blanks the text to be displayed
225 * and so on clear the display.
227 bool sevenseg_clear(SevenSeg *SS);
229 #endif /* DRV_LED_7SEG_H */
230 /** \} */ //defgroup drivers