forked from andygock/glcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glcd.h
311 lines (259 loc) · 8.08 KB
/
glcd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/**
\file glcd.h
\brief GLCD Library main header file. This file must be included into project.
\author Andy Gock
*/
/*
Copyright (c) 2012, Andy Gock
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Andy Gock nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GLCD_H
#define _GLCD_H
#if defined(GLCD_DEVICE_AVR8)
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "devices/AVR8.h"
#if !defined(GLCD_USE_AVR_DELAY)
extern void delay_ms(uint32_t ms);
#else
/* Use AVR __delay_ms() function */
#include <util/delay.h>
#define delay_ms(t) _delay_ms(t)
#endif
#elif defined(GLCD_DEVICE_LPC111X)
#include <LPC11xx.h>
#include "devices/LPC111x.h"
extern void delay_ms(uint32_t ms);
#define PROGMEM
#elif defined(GLCD_DEVICE_LPC11UXX)
#include <LPC11Uxx.h>
#include "devices/LPC11Uxx.h"
extern void delay_ms(uint32_t ms);
#define PROGMEM
#elif defined(GLCD_DEVICE_STM32F0XX)
#include <stm32f0xx.h>
#include <stm32f0xx_gpio.h>
#include "devices/inc/STM32F0xx.h"
extern void delay_ms(uint32_t ms);
#define PROGMEM
#elif defined(GLCD_DEVICE_STM32F10X)
#include <stm32f10x.h>
#include <stm32f10x_gpio.h>
#include "devices/inc/STM32F10x.h"
extern void delay_ms(uint32_t ms);
#define PROGMEM
#elif defined(GLCD_DEVICE_STM32F4XX)
#include <stm32f4xx.h>
#include "devices/STM32F4.h"
extern void delay_ms(uint32_t ms);
#define PROGMEM
#elif defined(GLCD_DEVICE_PIC24H)
#define FCY (FOSC/2)
#include <stdint.h>
#include <xc.h>
#include <libpic30.h>
#include "devices/PIC24H.h"
#define PROGMEM
#define delay_ms(t) __delay_ms(t)
#elif defined(GLCD_DEVICE_PIC32)
#include "devices/PIC32.h"
#define PROGMEM
extern void delay_ms(unsigned int ms);
#else
#error "Device not supported or defined"
#endif
#if defined(GLCD_CONTROLLER_PCD8544)
#include "controllers/PCD8544.h"
#elif defined(GLCD_CONTROLLER_ST7565R)
#include "controllers/ST7565R.h"
#elif defined(GLCD_CONTROLLER_NT75451)
#include "controllers/NT75451.h"
#else
#error "Controller not supported or defined"
#endif
/* Macros */
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
/* Defining new types */
/**
* Font table type
*/
typedef enum {
STANG,
MIKRO,
GLCD_UTILS
} font_table_type_t;
/**
* Bounding box for pixels that need to be updated
*/
typedef struct {
uint8_t x_min;
uint8_t y_min;
uint8_t x_max;
uint8_t y_max;
} glcd_BoundingBox_t;
#include <stdint.h>
#include "glcd_devices.h"
#include "glcd_controllers.h"
#include "glcd_graphics.h"
#include "glcd_graphs.h"
#include "glcd_text_tiny.h"
#include "glcd_text.h"
#include "unit_tests.h"
/**
* \name Colour Constants
* @{
*/
#define BLACK 1
#define WHITE 0
/**@}*/
/**
* \name LCD Dimensions
* @{
*/
/*
* Set to custom value, or leave at 0 for automatic assignment.
* For custom dimensions, users can define this in their compiler options.
*/
#if !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT)
/**
* User specified GLCD width in pixels
* Set to 0 for automatic assignment based on controller.
*/
#define GLCD_LCD_WIDTH 0
/**
* User specified GLCD height in pixels
* Set to 0 for automatic assignment based on controller.
*/
#define GLCD_LCD_HEIGHT 0
/* Automatic assignment of width and height, if required. */
#if !GLCD_LCD_WIDTH && !GLCD_LCD_HEIGHT
#undef GLCD_LCD_WIDTH
#undef GLCD_LCD_HEIGHT
#if defined(GLCD_CONTROLLER_PCD8544)
/* 84x48 is standard for the popular Nokia LCD */
#define GLCD_LCD_WIDTH 84
#define GLCD_LCD_HEIGHT 48
#elif defined(GLCD_CONTROLLER_ST7565R) || defined(GLCD_CONTROLLER_NT75451)
/* 128x64 is the most popular for this, so we'll use that as default */
#define GLCD_LCD_WIDTH 128
#define GLCD_LCD_HEIGHT 64
#else
#define GLCD_LCD_WIDTH 128
#define GLCD_LCD_HEIGHT 64
#endif
#endif
#endif /* !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT) */
/*
* GLCD_NUMBER_OF_BANKS is typically GLCD_LCD_HEIGHT/8
* Don't adjust these below unless required.
*/
#define GLCD_NUMBER_OF_BANKS (GLCD_LCD_WIDTH / 8)
#define GLCD_NUMBER_OF_COLS GLCD_LCD_WIDTH
/**@}*/
#if !defined(GLCD_RESET_TIME)
/** Reset duration by glcd_reset(), in milliseconds */
#define GLCD_RESET_TIME 1
#endif
/* Global variables used for GLCD library */
extern uint8_t glcd_buffer[GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8];
extern glcd_BoundingBox_t glcd_bbox;
extern uint8_t *glcd_buffer_selected;
extern glcd_BoundingBox_t *glcd_bbox_selected;
/** \name Base Functions
* @{
*/
/**
* Update bounding box.
*
* The bounding box defines a rectangle in which needs to be refreshed next time
* glcd_write() is called. glcd_write() only writes to those pixels inside the bounding box plus any
* surrounding pixels which are required according to the bank/column write method of the controller.
*
* Define a rectangle here, and it will be <em>added</em> to the existing bounding box.
*
* \param xmin Minimum x value of rectangle
* \param ymin Minimum y value of rectangle
* \param xmax Maximum x value of rectangle
* \param ymax Maximum y value of rectangle
* \see glcd_bbox
* \see glcd_bbox_selected
*/
void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax);
/**
* Reset the bounding box.
* After resetting the bounding box, no pixels are marked as needing refreshing.
*/
void glcd_reset_bbox(void);
/**
* Same as glcd_reset_bbox()
*/
void glcd_bbox_reset(void);
/**
* Marks the entire display for re-writing.
*/
void glcd_bbox_refresh(void);
/**
* Clear the display. This will clear the buffer and physically write and commit it to the LCD
*/
void glcd_clear(void);
/**
* Clear the display buffer only. This does not physically write the changes to the LCD
*/
void glcd_clear_buffer(void);
/**
* Select screen buffer and bounding box structure.
* This should be selected at initialisation. There are future plans to support multiple screen buffers
* but this not yet available.
* \param buffer Pointer to screen buffer
* \param bbox Pointer to bounding box object.
* \see glcd_BoundingBox_t
*/
void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox);
/**
* Scroll entire screne buffer by x and y pixels. (not implemented yet)
* \note Items scrolled off the extents of the display dimensions will be lost.
*
* \param x X distance to scroll
* \param y Y distance to scroll
*/
void glcd_scroll(int8_t x, int8_t y);
/**
* Scroll screen buffer up by 8 pixels.
* This is designed to be used in conjunciton with tiny text functions which are 8 bits high.
* \see Tiny Text
*/
void glcd_scroll_line(void);
/** @}*/
typedef struct {
const char *font_table;
uint8_t width;
uint8_t height;
char start_char;
char end_char;
font_table_type_t table_type;
} glcd_FontConfig_t;
extern uint8_t *glcd_buffer_selected;
extern glcd_BoundingBox_t *glcd_bbox_selected;
extern glcd_FontConfig_t font_current;
#endif