GLCD Library
A C Library for Embedded Applications
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
text_tiny.c
Go to the documentation of this file.
1 
7 /*
8  Copyright (c) 2012, Andy Gock
9 
10  All rights reserved.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of Andy Gock nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
27  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #include "glcd.h"
36 
37 #if defined(GLCD_DEVICE_AVR8)
38 void glcd_tiny_set_font(PGM_P font_table, uint8_t width, uint8_t height, char start_char, char end_char)
39 #else
40 void glcd_tiny_set_font(const char * font_table, uint8_t width, uint8_t height, char start_char, char end_char)
41 #endif
42 {
43  font_current.font_table = font_table;
44  font_current.width = width;
45  font_current.height = height;
46  font_current.start_char = start_char;
47  font_current.end_char = end_char;
49 }
50 
51 void glcd_tiny_draw_char(uint8_t x, uint8_t line, char c)
52 {
53  uint8_t i;
54 
55  /* Only works for fonts < 8 bits in height */
56  if (font_current.height >= 8) {
57  return;
58  }
59  if (c < font_current.start_char || c > font_current.end_char) {
60  c = '.';
61  }
62  if ( line >= GLCD_LCD_HEIGHT / (font_current.height + 1) ) {
63  return;
64  }
65  if ( (x+font_current.width) >= GLCD_LCD_WIDTH ) {
66  return;
67  }
68 
70 
71  for ( i = 0; i < font_current.width; i++ ) {
72 #if defined(GLCD_DEVICE_AVR8)
73  glcd_buffer_selected[x + (line * GLCD_LCD_WIDTH)] = pgm_read_byte( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i );
74 #else
76 #endif
77  x++;
78  }
79 }
80 
81 void glcd_tiny_draw_string(uint8_t x, uint8_t line, char *str)
82 {
83  if (font_current.height >= 8) {
84  return;
85  }
86  while (*str) {
87  glcd_tiny_draw_char(x, line, *str++);
88  x += (font_current.width + 1);
89  if ((x + font_current.width + 1) > GLCD_LCD_WIDTH) {
90  x = 0; /* Ran out of this line */
91  line++;
92  }
93  if (line >= (GLCD_LCD_HEIGHT/(font_current.height + 1)))
94  return; /* Ran out of space :( */
95  }
96 }
97 
98 #if defined(GLCD_DEVICE_AVR8)
99 void glcd_tiny_draw_string_P(uint8_t x, uint8_t line, PGM_P str)
100 #else
101 void glcd_tiny_draw_string_P(uint8_t x, uint8_t line, const char *str)
102 #endif
103 {
104  if (font_current.height >= 8) {
105  return;
106  }
107  while (1) {
108 #if defined(GLCD_DEVICE_AVR8)
109  char c = pgm_read_byte(str++);
110 #else
111  char c = *(str++);
112 #endif
113  if (!c)
114  return;
115 
116  glcd_tiny_draw_char(x, line, c);
117 
118  x += (font_current.width + 1);
119  if ((x + font_current.width + 1) > GLCD_LCD_WIDTH) {
120  x = 0; /* Ran out of this line */
121  line++;
122  }
123  if (line >= (GLCD_LCD_HEIGHT/(font_current.height + 1)))
124  return; /* Ran out of space :( */
125  }
126 }
127 
130  glcd_tiny_draw_string(0, (GLCD_LCD_HEIGHT/8-1), str);
131  glcd_write();
132 }
133 
134 void glcd_tiny_draw_string_ammend_P(const char *str) {
137  glcd_write();
138 }
139 
140 void glcd_tiny_invert_line(uint8_t line)
141 {
142  glcd_invert_area(0,line*8,GLCD_LCD_WIDTH-1,8);
143 }
144 
145 void glcd_tiny_draw_char_xy(uint8_t x, uint8_t y, char c)
146 {
147  uint8_t i;
148  uint8_t xvar, yvar;
149  uint8_t dat;
150 
151  /* Only works for fonts < 8 bits in height */
152 
153  /* Check all important bounds requirements are okay */
155  return;
156  }
157  if (c < font_current.start_char || c > font_current.end_char) {
158  c = '.';
159  }
160 
161  xvar = x;
162 
163  for ( i = 0; i < font_current.width; i++ ) {
164 #if defined(GLCD_DEVICE_AVR8)
165  dat = pgm_read_byte( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i );
166 #else
167  dat = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i );
168 #endif
169  for (yvar = 0; yvar < font_current.height; yvar++) {
170  glcd_set_pixel(xvar,y+yvar, (dat & (1<<yvar) ? 1 : 0) );
171  }
172  xvar++;
173  }
174 
176 
177 }
#define GLCD_LCD_WIDTH
User specified GLCD width in pixels Set to 0 for automatic assignment based on controller.
Definition: glcd.h:140
char end_char
Definition: glcd.h:258
uint8_t width
Definition: glcd.h:255
void glcd_write(void)
Update the display within the specified bounding box.
void glcd_tiny_invert_line(uint8_t line)
Invert all contents of line number.
Definition: text_tiny.c:140
glcd_FontConfig_t font_current
Definition: text.c:40
void glcd_tiny_draw_string_P(uint8_t x, uint8_t line, const char *str)
Write flash string to display buffer in tiny 5x7 font.
Definition: text_tiny.c:101
void glcd_scroll_line(void)
Scroll screen buffer up by 8 pixels.
Definition: glcd.c:153
void glcd_tiny_draw_string_ammend(char *str)
Write string to bottom row of display.
Definition: text_tiny.c:128
const char * font_table
Definition: glcd.h:254
void glcd_tiny_draw_char_xy(uint8_t x, uint8_t y, char c)
Write character to LCD in tiny 5x7 font to specified X, Y location.
Definition: text_tiny.c:145
#define GLCD_LCD_HEIGHT
User specified GLCD height in pixels Set to 0 for automatic assignment based on controller.
Definition: glcd.h:141
void glcd_tiny_set_font(const char *font_table, uint8_t width, uint8_t height, char start_char, char end_char)
Set font to be used from now on.
Definition: text_tiny.c:40
uint8_t * glcd_buffer_selected
Pointer to screen buffer currently in use.
Definition: glcd.c:60
void glcd_tiny_draw_string_ammend_P(const char *str)
Write string from flash memory to bottom row of display.
Definition: text_tiny.c:134
enum font_table_type table_type
Definition: glcd.h:259
Definition: glcd.h:251
void glcd_tiny_draw_char(uint8_t x, uint8_t line, char c)
Write character to LCD in tiny 5x7 font.
Definition: text_tiny.c:51
void glcd_invert_area(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
Invert pixels in a retangular area.
Definition: graphics.c:267
void glcd_tiny_draw_string(uint8_t x, uint8_t line, char *str)
Write string to display buffer in tiny 5x7 font.
Definition: text_tiny.c:81
void glcd_set_pixel(uint8_t x, uint8_t y, uint8_t color)
Set pixel to specified colour.
Definition: graphics.c:46
char start_char
Definition: glcd.h:257
uint8_t height
Definition: glcd.h:256
GLCD Library main header file.
void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax)
Update bounding box.
Definition: glcd.c:69