GLCD Library
A C Library for Embedded Applications
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
glcd.h
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 #ifndef _GLCD_H
36 #define _GLCD_H
37 
38 #if defined(GLCD_DEVICE_AVR8)
39  #include <avr/pgmspace.h>
40  #include <avr/io.h>
41  #include <avr/interrupt.h>
42  #include "devices/AVR8.h"
43 
44  #if !defined(GLCD_USE_AVR_DELAY)
45  extern void delay_ms(uint32_t ms);
46  #else
47  /* Use AVR __delay_ms() function */
48  #include <util/delay.h>
49  #define delay_ms(t) _delay_ms(t)
50  #endif
51 
52 #elif defined(GLCD_DEVICE_LPC111X)
53  #include <LPC11xx.h>
54  #include "devices/LPC111x.h"
55  extern void delay_ms(uint32_t ms);
56  #define PROGMEM
57 
58 #elif defined(GLCD_DEVICE_LPC11UXX)
59  #include <LPC11Uxx.h>
60  #include "devices/LPC11Uxx.h"
61  extern void delay_ms(uint32_t ms);
62  #define PROGMEM
63 
64 #elif defined(GLCD_DEVICE_STM32F0XX)
65  #include <stm32f0xx.h>
66  #include <stm32f0xx_gpio.h>
67  #include "devices/inc/STM32F0xx.h"
68  extern void delay_ms(uint32_t ms);
69  #define PROGMEM
70 
71 #else
72  #error "Device not supported"
73 
74 #endif
75 
76 #if defined(GLCD_CONTROLLER_PCD8544)
77  #include "controllers/PCD8544.h"
78 
79 #elif defined(GLCD_CONTROLLER_ST7565R)
80  #include "controllers/ST7565R.h"
81 
82 #elif defined(GLCD_CONTROLLER_NT75451)
83  #include "controllers/NT75451.h"
84 
85 #else
86  #error "Controller not supported"
87 
88 #endif
89 
90 #define swap(a, b) { uint8_t t = a; a = b; b = t; }
91 
92 #include <stdint.h>
93 #include "glcd_devices.h"
94 #include "glcd_controllers.h"
95 #include "glcd_graphics.h"
96 #include "glcd_graphs.h"
97 #include "glcd_text_tiny.h"
98 #include "glcd_text.h"
99 #include "unit_tests.h"
100 
105 #define BLACK 1
106 #define WHITE 0
107 
114 /* Set to custom value, or leave at 0 for automatic assignment. */
115 
120 #define GLCD_LCD_WIDTH 0
121 
127 #define GLCD_LCD_HEIGHT 0
128 
129 /* Automatic assignment of width and height, if required. */
130 #if !GLCD_LCD_WIDTH && !GLCD_LCD_HEIGHT
131  #undef GLCD_LCD_WIDTH
132  #undef GLCD_LCD_HEIGHT
133  #if defined(GLCD_CONTROLLER_PCD8544)
134  #define GLCD_LCD_WIDTH 84
135  #define GLCD_LCD_HEIGHT 48
136  #elif defined(GLCD_CONTROLLER_ST7565R) || defined(GLCD_CONTROLLER_NT75451)
137  #define GLCD_LCD_WIDTH 128
138  #define GLCD_LCD_HEIGHT 64
139  #else
140  #define GLCD_LCD_WIDTH 128
141  #define GLCD_LCD_HEIGHT 64
142  #endif
143 #endif
144 
145 /*
146  * GLCD_NUMBER_OF_BANKS is typically GLCD_LCD_HEIGHT/8
147  * Don't adjust these below unless required.
148  */
149 #define GLCD_NUMBER_OF_BANKS (GLCD_LCD_WIDTH / 8)
150 #define GLCD_NUMBER_OF_COLS GLCD_LCD_WIDTH
151 
154 #if !defined(GLCD_RESET_TIME)
155 
156 #define GLCD_RESET_TIME 1
157 #endif
158 
162 typedef struct {
163  uint8_t x_min;
164  uint8_t y_min;
165  uint8_t x_max;
166  uint8_t y_max;
168 
169 /* Global variables used for GLCD library */
170 extern uint8_t glcd_buffer[GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8];
172 extern uint8_t *glcd_buffer_selected;
174 
195 void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax);
196 
201 void glcd_reset_bbox(void);
202 
206 void glcd_bbox_reset(void);
207 
211 void glcd_bbox_refresh(void);
212 
216 void glcd_clear(void);
217 
221 void glcd_clear_buffer(void);
222 
231 void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox);
232 
240 void glcd_scroll(int8_t x, int8_t y);
241 
247 void glcd_scroll_line(void);
248 
252 
253 typedef struct {
254  const char *font_table;
255  uint8_t width;
256  uint8_t height;
258  char end_char;
259  enum font_table_type table_type;
261 
262 extern uint8_t *glcd_buffer_selected;
265 
266 #endif
#define GLCD_LCD_WIDTH
User specified GLCD width in pixels Set to 0 for automatic assignment based on controller.
Definition: glcd.h:140
Constants and definitions for NT75451 controller.
font_table_type
Definition: glcd.h:251
char end_char
Definition: glcd.h:258
uint8_t width
Definition: glcd.h:255
glcd_BoundingBox_t * glcd_bbox_selected
Pointer to bounding box currently in use.
Definition: glcd.c:65
glcd_FontConfig_t font_current
Definition: text.c:40
Bounding box for pixels that need to be updated.
Definition: glcd.h:162
void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox)
Select screen buffer and bounding box structure.
Definition: glcd.c:133
Functions specific to certain devices (microcontrollers).
void glcd_scroll_line(void)
Scroll screen buffer up by 8 pixels.
Definition: glcd.c:153
glcd_BoundingBox_t glcd_bbox
Keeps track of bounding box of area on LCD which need to be updated next reresh cycle.
Definition: glcd.c:55
GLCD Library - Tiny Text functions.
Constants relating to ST7565R LCD controller.
uint8_t y_max
Definition: glcd.h:166
void glcd_bbox_refresh()
Marks the entire display for re-writing.
Definition: glcd.c:114
Various test functions to demonstrate features of the library.
Definition: glcd.h:251
uint8_t y_min
Definition: glcd.h:164
const char * font_table
Definition: glcd.h:254
Implmentation of NXP LPC11Uxx microcontrollers.
Pinouts and driver config for NXP LPC111x ARM Cortex-M0 MCUs.
#define GLCD_LCD_HEIGHT
User specified GLCD height in pixels Set to 0 for automatic assignment based on controller.
Definition: glcd.h:141
uint8_t * glcd_buffer_selected
Pointer to screen buffer currently in use.
Definition: glcd.c:60
void glcd_bbox_reset()
Same as glcd_reset_bbox()
Definition: glcd.c:110
GLCD Library - Graph drawing functions.
Definition: glcd.h:251
Pinouts to Atmel AVR 8-bit AVRs.
GLCD Library - Text functions.
void glcd_clear_buffer(void)
Clear the display buffer only.
Definition: glcd.c:128
Constants relating to PCD8544 LCD Controller (Nokia 5110 LCD).
uint8_t x_min
Definition: glcd.h:163
Functions specific to STM32 F0 ARM Cortex-M0 devices.
void glcd_clear(void)
Clear the display.
Definition: glcd.c:122
uint8_t glcd_buffer[GLCD_LCD_WIDTH *GLCD_LCD_HEIGHT/8]
Screen buffer.
Definition: glcd.c:49
char start_char
Definition: glcd.h:257
uint8_t height
Definition: glcd.h:256
Graphics routines.
void glcd_reset_bbox()
Reset the bounding box.
Definition: glcd.c:101
void glcd_scroll(int8_t x, int8_t y)
Scroll entire screne buffer by x and y pixels.
Definition: glcd.c:139
uint8_t x_max
Definition: glcd.h:165
void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax)
Update bounding box.
Definition: glcd.c:69
Functions specific to certain graphic LCD controllers.