blob: 15778787de9f7e7052dba3510abbdea7f45773c2 [file] [log] [blame]
zongqiang.zhang0c6a0882019-08-07 14:48:21 +08001/**
2 \file glcd.h
3 \brief GLCD Library main header file. This file must be included into project.
4 \author Andy Gock
5 */
6
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#include "stm32f10x.h"
39#include "glcd_spi.h"
40#include "ST7565R.h"
41
42
43extern void delay_ms(uint32_t ms);
44#define PROGMEM
45
46
47/* Macros */
48
49#define swap(a, b) { uint8_t t = a; a = b; b = t; }
50
51/* Defining new types */
52
53/**
54 * Font table type
55 */
56typedef enum {
57 STANG,
58 MIKRO,
59 GLCD_UTILS
60} font_table_type_t;
61
62/**
63 * Bounding box for pixels that need to be updated
64 */
65typedef struct {
66 uint8_t x_min;
67 uint8_t y_min;
68 uint8_t x_max;
69 uint8_t y_max;
70} glcd_BoundingBox_t;
71
72#include <stdint.h>
73#include "glcd_graphics.h"
74#include "glcd_graphs.h"
75#include "glcd_text_tiny.h"
76#include "glcd_text.h"
77#include "unit_tests.h"
78#include "font5x7.h"
79#include "Earthbound_12x19_48to57.h"
80#include "Liberation_Sans15x21_Numbers.h"
81
82/**
83 * \name Colour Constants
84 * @{
85 */
86#define BLACK 1
87#define WHITE 0
88/**@}*/
89
90/**
91 * \name LCD Dimensions
92 * @{
93 */
94#if !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT)
95
96 /**
97 * User specified GLCD width in pixels
98 * Set to 0 for automatic assignment based on controller.
99 */
100 #define GLCD_LCD_WIDTH 128
101
102 /**
103 * User specified GLCD height in pixels
104 * Set to 0 for automatic assignment based on controller.
105 */
106
107 #define GLCD_LCD_HEIGHT 64
108
109 /* Automatic assignment of width and height, if required. */
110 #if !GLCD_LCD_WIDTH && !GLCD_LCD_HEIGHT
111 #undef GLCD_LCD_WIDTH
112 #undef GLCD_LCD_HEIGHT
113 #if defined(GLCD_CONTROLLER_PCD8544)
114 /* 84x48 is standard for the popular Nokia LCD */
115 #define GLCD_LCD_WIDTH 84
116 #define GLCD_LCD_HEIGHT 48
117 #elif defined(GLCD_CONTROLLER_ST7565R) || defined(GLCD_CONTROLLER_NT75451)
118 /* 128x64 is the most popular for this, so we'll use that as default */
119 #define GLCD_LCD_WIDTH 128
120 #define GLCD_LCD_HEIGHT 64
121 #else
122 #define GLCD_LCD_WIDTH 128
123 #define GLCD_LCD_HEIGHT 64
124 #endif
125 #endif
126
127#endif /* !defined(GLCD_LCD_WIDTH) || !defined(GLCD_LCD_HEIGHT) */
128
129/*
130 * GLCD_NUMBER_OF_BANKS is typically GLCD_LCD_HEIGHT/8
131 * Don't adjust these below unless required.
132 */
133#define GLCD_NUMBER_OF_BANKS (GLCD_LCD_WIDTH / 8)
134#define GLCD_NUMBER_OF_COLS GLCD_LCD_WIDTH
135
136/**@}*/
137
138#if !defined(GLCD_RESET_TIME)
139 /** Reset duration by glcd_reset(), in milliseconds */
140 #define GLCD_RESET_TIME 2
141#endif
142/*
143 * Set to custom value, or leave at 0 for automatic assignment.
144 * For custom dimensions, users can define this in their compiler options.
145 */
146
147/* Global variables used for GLCD library */
148extern uint8_t glcd_buffer[GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8];
149extern glcd_BoundingBox_t glcd_bbox;
150extern uint8_t *glcd_buffer_selected;
151extern glcd_BoundingBox_t *glcd_bbox_selected;
152
153/** \name Base Functions
154 * @{
155 */
156
157/**
158 * Update bounding box.
159 *
160 * The bounding box defines a rectangle in which needs to be refreshed next time
161 * glcd_write() is called. glcd_write() only writes to those pixels inside the bounding box plus any
162 * surrounding pixels which are required according to the bank/column write method of the controller.
163 *
164 * Define a rectangle here, and it will be <em>added</em> to the existing bounding box.
165 *
166 * \param xmin Minimum x value of rectangle
167 * \param ymin Minimum y value of rectangle
168 * \param xmax Maximum x value of rectangle
169 * \param ymax Maximum y value of rectangle
170 * \see glcd_bbox
171 * \see glcd_bbox_selected
172 */
173void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax);
174
175/**
176 * Reset the bounding box.
177 * After resetting the bounding box, no pixels are marked as needing refreshing.
178 */
179void glcd_reset_bbox(void);
180
181/**
182 * Same as glcd_reset_bbox()
183 */
184void glcd_bbox_reset(void);
185
186/**
187 * Marks the entire display for re-writing.
188 */
189void glcd_bbox_refresh(void);
190
191/**
192 * Clear the display. This will clear the buffer and physically write and commit it to the LCD
193 */
194void glcd_clear(void);
195
196/**
197 * Clear the display buffer only. This does not physically write the changes to the LCD
198 */
199void glcd_clear_buffer(void);
200
201/**
202 * Select screen buffer and bounding box structure.
203 * This should be selected at initialisation. There are future plans to support multiple screen buffers
204 * but this not yet available.
205 * \param buffer Pointer to screen buffer
206 * \param bbox Pointer to bounding box object.
207 * \see glcd_BoundingBox_t
208 */
209void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox);
210
211/**
212 * Scroll entire screne buffer by x and y pixels. (not implemented yet)
213 * \note Items scrolled off the extents of the display dimensions will be lost.
214 *
215 * \param x X distance to scroll
216 * \param y Y distance to scroll
217 */
218void glcd_scroll(int8_t x, int8_t y);
219
220/**
221 * Scroll screen buffer up by 8 pixels.
222 * This is designed to be used in conjunciton with tiny text functions which are 8 bits high.
223 * \see Tiny Text
224 */
225void glcd_scroll_line(void);
226
227void glcd_set_reverse_sta(uint8_t sta);
228uint8_t glcd_get_reverse_sta(void);
229
230void glcd_HW_init(void);
231
232void glcd_write(void);
233
234/** @}*/
235
236typedef struct {
237 const char *font_table;
238 uint8_t width;
239 uint8_t height;
240 char start_char;
241 char end_char;
242 font_table_type_t table_type;
243} glcd_FontConfig_t;
244
245
246
247extern uint8_t *glcd_buffer_selected;
248extern glcd_BoundingBox_t *glcd_bbox_selected;
249extern glcd_FontConfig_t font_current;
250
251#endif