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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static const uint16_t ao_lcd_font[] = {
22 #include "ao_lcd_font.h"
36 static const uint8_t ao_bit_src[] = {
43 static const uint8_t ao_bit_dst[6][4] = {
53 ao_draw_glyph(uint8_t pos, uint16_t glyph) {
54 uint8_t col, seg, src, dst;
57 for (col = 0; col < 4; col++) {
58 for (seg = 0; seg < 4; seg++) {
59 src = ao_bit_src[(col << 2) | seg];
60 dst = ao_bit_dst[pos][seg];
61 ram = stm_lcd.ram[col * 2];
63 ram |= (uint32_t) ((glyph >> src) & 1) << dst;
64 stm_lcd.ram[col*2] = ram;
69 #define AO_LCD_FONT_COLON (1 << 14)
70 #define AO_LCD_FONT_DECIMAL (1 << 15)
73 ao_lcd_font_char(uint8_t pos, char c, uint16_t flags) {
76 if (c < ' ' || c > 127)
78 ao_draw_glyph(pos, ao_lcd_font[c - ' '] | flags);
82 ao_lcd_font_string(char *s) {
87 while (pos < 6 && (c = *s++)) {
91 flags |= AO_LCD_FONT_COLON;
93 flags |= AO_LCD_FONT_DECIMAL;
98 ao_lcd_font_char(pos++, c, flags);
101 ao_lcd_font_char(pos++, ' ', 0);
102 stm_lcd.sr = (1 << STM_LCD_SR_UDR);
106 ao_lcd_font_text(void)
111 while (ao_cmd_lex_c != '\n' && c < sizeof (string) - 1) {
112 string[c++] = ao_cmd_lex_c;
116 ao_lcd_font_string(string);
119 const struct ao_cmds ao_lcd_font_cmds[] = {
120 { ao_lcd_font_text, "t <string>\0Write <string> to LCD" },
125 ao_lcd_font_init(void)
127 ao_cmd_register(ao_lcd_font_cmds);