2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <ao_seven_segment.h>
20 #include <ao_lcd_stm.h>
37 static const uint8_t ao_segments[] = {
44 (1 << AO_SEGMENT_6), /* 0 */
52 (0 << AO_SEGMENT_6), /* 1 */
60 (1 << AO_SEGMENT_6), /* 2 */
68 (1 << AO_SEGMENT_6), /* 3 */
76 (0 << AO_SEGMENT_6), /* 4 */
84 (1 << AO_SEGMENT_6), /* 5 */
92 (1 << AO_SEGMENT_6), /* 6 */
100 (0 << AO_SEGMENT_6), /* 7 */
102 (1 << AO_SEGMENT_0) |
103 (1 << AO_SEGMENT_1) |
104 (1 << AO_SEGMENT_2) |
105 (1 << AO_SEGMENT_3) |
106 (1 << AO_SEGMENT_4) |
107 (1 << AO_SEGMENT_5) |
108 (1 << AO_SEGMENT_6), /* 8 */
110 (1 << AO_SEGMENT_0) |
111 (1 << AO_SEGMENT_1) |
112 (1 << AO_SEGMENT_2) |
113 (1 << AO_SEGMENT_3) |
114 (0 << AO_SEGMENT_4) |
115 (1 << AO_SEGMENT_5) |
116 (1 << AO_SEGMENT_6), /* 9 */
118 (1 << AO_SEGMENT_0) |
119 (1 << AO_SEGMENT_1) |
120 (1 << AO_SEGMENT_2) |
121 (1 << AO_SEGMENT_3) |
122 (1 << AO_SEGMENT_4) |
123 (1 << AO_SEGMENT_5) |
124 (0 << AO_SEGMENT_6), /* A */
126 (0 << AO_SEGMENT_0) |
127 (1 << AO_SEGMENT_1) |
128 (0 << AO_SEGMENT_2) |
129 (1 << AO_SEGMENT_3) |
130 (1 << AO_SEGMENT_4) |
131 (1 << AO_SEGMENT_5) |
132 (1 << AO_SEGMENT_6), /* b */
134 (1 << AO_SEGMENT_0) |
135 (1 << AO_SEGMENT_1) |
136 (0 << AO_SEGMENT_2) |
137 (0 << AO_SEGMENT_3) |
138 (1 << AO_SEGMENT_4) |
139 (0 << AO_SEGMENT_5) |
140 (1 << AO_SEGMENT_6), /* c */
142 (0 << AO_SEGMENT_0) |
143 (0 << AO_SEGMENT_1) |
144 (1 << AO_SEGMENT_2) |
145 (1 << AO_SEGMENT_3) |
146 (1 << AO_SEGMENT_4) |
147 (1 << AO_SEGMENT_5) |
148 (1 << AO_SEGMENT_6), /* d */
150 (1 << AO_SEGMENT_0) |
151 (1 << AO_SEGMENT_1) |
152 (0 << AO_SEGMENT_2) |
153 (1 << AO_SEGMENT_3) |
154 (1 << AO_SEGMENT_4) |
155 (0 << AO_SEGMENT_5) |
156 (1 << AO_SEGMENT_6), /* E */
158 (1 << AO_SEGMENT_0) |
159 (1 << AO_SEGMENT_1) |
160 (0 << AO_SEGMENT_2) |
161 (1 << AO_SEGMENT_3) |
162 (1 << AO_SEGMENT_4) |
163 (0 << AO_SEGMENT_5) |
164 (0 << AO_SEGMENT_6), /* F */
168 ao_seven_segment_set(uint8_t digit, uint8_t value)
173 if (value == AO_SEVEN_SEGMENT_CLEAR)
176 segments = ao_segments[value & 0xf];
178 /* Check for decimal point */
180 segments |= (1 << AO_SEGMENT_7);
183 for (s = 0; s <= 7; s++)
184 ao_lcd_set(digit, s, !!(segments & (1 << s)));
189 ao_seven_segment_clear(void)
197 ao_seven_segment_show(void)
199 uint8_t digit, value;
201 digit = ao_cmd_lex_i;
203 value = ao_cmd_lex_i;
204 ao_seven_segment_set(digit, value);
208 static const struct ao_cmds ao_seven_segment_cmds[] = {
209 { ao_seven_segment_show, "S <digit> <value>\0Set LCD digit" },
215 ao_seven_segment_init(void)
218 ao_cmd_register(ao_seven_segment_cmds);