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 Driver
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));
74 * sevenseg_unlock(&display);
75 * sevenseg_setBlink(&display,false,0);
76 * sevenseg_setRunonce(&display,false);
77 * sevenseg_setRunspeed(&display,10);
78 * if ((sevenseg_print(&display, "made with bertos.")) != 0)
80 * sevenseg_lock(&display);
83 * $WIZ$ module_name = "led_7seg"
84 * $WIZ$ module_depends = "timer"
85 * $WIZ$ module_configuration = "bertos/cfg/cfg_led_7seg.h"
86 * $WIZ$ module_hw = "bertos/hw/hw_led_7seg.h"
89 #ifndef DRV_LED_7SEG_H
90 #define DRV_LED_7SEG_H
92 #include "cfg/cfg_led_7seg.h"
93 #include <drv/timer.h>
94 #include <mware/event.h>
97 * Numbers and Letters Table
98 * Segments definitions
101 * These tables contain all the printable
102 * characters on a 7 segment digit encoded
103 * for common cathode and common anode
106 * 0, 1, 2, 3, 4, 5, 6, 7, 8,
107 * 9, ., -, A, B, C, D, E, F,
108 * G, H, I, J, K, L, M, N, O,
109 * P, Q, R, S, T, U, V, W, X,
112 * Follows the Segments definitions for the
113 * graphic digits routines and the macro that
114 * set the graphic digit with the appropriate
118 #if CONFIG_LED_7SEG_CCAT
119 static const uint8_t segstable[] =
121 0x3f, 0x6, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x7, 0x7f,
122 0x6f, 0x80, 0x40, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,
123 0x3d, 0x74, 0x30, 0x1e, 0x75, 0x38, 0x15, 0x37, 0x3f,
124 0x73, 0x67, 0x50, 0x6d, 0x78, 0x3e, 0x2a, 0x6a, 0x76,
127 #define SEGMENT_EMPTY (0x00)
128 #define SEGMENT_A (0x01)
129 #define SEGMENT_B (0x02)
130 #define SEGMENT_C (0x04)
131 #define SEGMENT_D (0x08)
132 #define SEGMENT_E (0x10)
133 #define SEGMENT_F (0x20)
134 #define SEGMENT_G (0x40)
135 #define SEGMENT_P (0x80)
136 #define SET_SEGMENT(var, segment) (var |= segment)
138 static const uint8_t segstable[] =
140 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80,
141 0x90, 0x7f, 0xbf, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e,
142 0xc2, 0x8b, 0xcf, 0xe1, 0x8a, 0xc7, 0xea, 0xc8, 0xc0,
143 0x8c, 0x98, 0xaf, 0x92, 0x87, 0xc1, 0xd5, 0x95, 0x89,
146 #define SEGMENT_EMPTY (0xFF)
147 #define SEGMENT_A (0xFE)
148 #define SEGMENT_B (0xFD)
149 #define SEGMENT_C (0xFB)
150 #define SEGMENT_D (0xF7)
151 #define SEGMENT_E (0xEF)
152 #define SEGMENT_F (0xDF)
153 #define SEGMENT_G (0xBF)
154 #define SEGMENT_P (0x7F)
155 #define SET_SEGMENT(var, segment) (var &= segment)
159 * Context data for Display functions
162 typedef struct SevenSeg
164 /** The String to be displayed */
165 uint8_t string[CONFIG_LED_7SEG_STRLEN];
166 /** The length of the string to be displayed */
167 unsigned int string_len;
170 /** Has to blink only one digit? */
172 /** Has to be displayed only one time? */
174 /** Scrolling speed */
176 /** Working scrolling speed */
177 unsigned int curspeed;
178 /** Is it printed at least one time? */
180 /** Working current position */
182 /** Working current digit */
183 unsigned int curdigit;
184 /** Is the structure in edit? */
188 /* Functions prototypes */
191 * This is the procedure that fills the seven_seg structure with the translated
192 * string to display. It swaps also the structures to display the new text when
193 * all the data is ready to display.
195 int sevenseg_print(SevenSeg *SS, const char *sstring);
198 * This is the procedure that inits all the structures that rules the 7 segments
199 * display and set the timer for the proper print/refresh of the text.
201 void sevenseg_init(SevenSeg *SS);
204 * This is the procedure that does a short print of all segments of all
205 * digits of the display.
207 void sevenseg_test(SevenSeg *SS);
210 * This is the procedure that check if the print of the current text is run
211 * almost one time and we're ready to print a new text.
213 bool sevenseg_isReady(SevenSeg *SS);
216 * This is the procedure that check if the print of the current text is run
217 * almost one time and then set the status of the display to "unlocked".
219 bool sevenseg_unlock(SevenSeg *SS);
222 * This is the procedure that lock the display and permit
223 * the print of the text.
225 bool sevenseg_lock(SevenSeg *SS);
228 * This is the procedure that set the blinking of the display.
229 * You can choose to blink all the display or only a single
232 bool sevenseg_setBlink(SevenSeg *SS, bool blink, uint8_t digit);
235 * This is the procedure that set if the text has to be displayed
238 bool sevenseg_setRunonce(SevenSeg *SS, bool runonce);
241 * This is the procedure that set the scrolling speed of the text
242 * if the text is longer than the display digits or the
243 * duration of the display if the text is smaller or equal the
244 * length of display digits.
246 bool sevenseg_setRunspeed(SevenSeg *SS, unsigned int r_speed);
249 * This is the procedure that blanks the text to be displayed
250 * and so on clear the display.
252 bool sevenseg_clear(SevenSeg *SS);
254 #endif /* DRV_LED_7SEG_H */
255 /** \} */ //defgroup drivers