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.
20 #include "ao_lcd_font.h"
22 static const uint16_t ao_lcd_font[] = {
23 #include "ao_lcd_font_bits.h"
37 static const uint8_t ao_bit_src[] = {
44 static const uint8_t ao_bit_dst[6][4] = {
54 ao_draw_glyph(uint8_t pos, uint16_t glyph) {
55 uint8_t col, seg, src, dst;
58 for (col = 0; col < 4; col++) {
59 for (seg = 0; seg < 4; seg++) {
60 src = ao_bit_src[(col << 2) | seg];
61 dst = ao_bit_dst[pos][seg];
62 ram = stm_lcd.ram[col * 2];
64 ram |= (uint32_t) ((glyph >> src) & 1) << dst;
65 stm_lcd.ram[col*2] = ram;
70 #define AO_LCD_FONT_COLON (1 << 14)
71 #define AO_LCD_FONT_DECIMAL (1 << 15)
74 ao_lcd_font_char(uint8_t pos, char c, uint16_t flags) {
77 if (c < ' ' || c > 127)
79 ao_draw_glyph(pos, ao_lcd_font[c - ' '] | flags);
83 ao_lcd_font_string(char *s) {
88 while (pos < 6 && (c = *s++)) {
92 flags |= AO_LCD_FONT_COLON;
94 flags |= AO_LCD_FONT_DECIMAL;
99 ao_lcd_font_char(pos++, c, flags);
102 ao_lcd_font_char(pos++, ' ', 0);
103 stm_lcd.sr = (1 << STM_LCD_SR_UDR);
107 ao_lcd_font_text(void)
112 while (ao_cmd_lex_c != '\n' && c < sizeof (string) - 1) {
113 string[c++] = ao_cmd_lex_c;
117 ao_lcd_font_string(string);
120 static const struct ao_cmds ao_lcd_font_cmds[] = {
121 { ao_lcd_font_text, "t <string>\0Write <string> to LCD" },
126 ao_lcd_font_init(void)
128 ao_cmd_register(ao_lcd_font_cmds);