forked from dsigma/glcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glcd.h
250 lines (195 loc) · 7.03 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
/**
\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
#define GLCD_DEVICE_STM32F4XX_CHIBIOS
#define GLCD_CONTROLLER_SHARP_LS013B7DH03
#define GLCD_USE_SPI_UART 0
#define CHIBIOS_SPI_PEREPHERIAL &SPID5
#define CHIBIOS_UART_SPI_PEREPHERIAL &UARTD3
#define GLCD_LSB_STRAIGT_BUFFER_PACKING 1
#define GLCD_MSB_BUFFER_PACKING 0
#if 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_STM32F4XX_CHIBIOS)
//Allows you to use a UART peripheral as a SPI bus (STM32 can do this).
#define GLCD_USE_CORTEX_M3_INSTRUCTIONS TRUE
#if GLCD_USE_SPI_UART
#ifndef CHIBIOS_UART_SPI_PEREPHERIAL
#error "You must define CHIBIOS_UART_SPI_PEREPHERIAL somewhere, E.G. #define CHIBIOS_UART_SPI_PEREPHERIAL &UARTD3"
#endif
#else
#ifndef CHIBIOS_SPI_PEREPHERIAL
#error "You must define CHIBIOS_SPI_PEREPHERIAL somewhere, E.G. #define CHIBIOS_SPI_PEREPHERIAL &SPID1"
#endif
#endif
#define delay_ms(t) chThdSleepMilliseconds(t)
#include "devices/STM32F4_ChibiOS.h"
#define PROGMEM
#else
#error "Device not supported"
#endif
#if defined(GLCD_CONTROLLER_SHARP_LS013B7DH03)
/* Note: you must either externally toggle the VCOM pin at at least 1hz, or configure the chip
* and toggle the vcom bit in the SPI payload. This code assumes external toggling.
*/
#include "controllers/sharp_LS013B7DH03.h"
#define USE_SPI_MULTIBYTE
#define BLACK 0
#define WHITE 1
#if defined(GLCD_USE_PARALLEL)
#error "The SHARP_LS013B7DH03 must use SPI"
#endif
void glcd_write_bounded(const int ymin, const int ymax);
#else
#error "Controller not supported"
#endif
#define swap(a, b) { uint8_t t = a; a = b; b = 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 LCD Dimensions
* @{
*/
/* Automatic assignment of width and height, if required. */
#if defined(GLCD_CONTROLLER_SHARP_LS013B7DH03)
#define GLCD_LCD_WIDTH 128
#define GLCD_LCD_HEIGHT 128
#endif
/*
* 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
#define MODIFIED_ROWS_SIZE ((GLCD_LCD_WIDTH / 8) + 1)
/**
* 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;
uint8_t modified_rows_bitmask[MODIFIED_ROWS_SIZE];
uint8_t modified_rows_bitmask2[MODIFIED_ROWS_SIZE];//Used by UART LCD export
} glcd_BoundingBox_t;
typedef struct {
uint32_t start_row_buffer_index;
uint32_t buffer_index;
uint8_t bitmask;
} buffer_packing_struct_t;
typedef enum {
GLCD_SCREEN_ROTATION_0_DEGREES = 0,
GLCD_SCREEN_ROTATION_90_DEGREES = 90,
GLCD_SCREEN_ROTATION_180_DEGREES = 180,
GLCD_SCREEN_ROTATION_270_DEGREES = 270
} glcd_screen_rotation_mode_t;
/* Global variables used for GLCD library */
extern uint8_t glcd_buffer[(GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8) + 1];
extern glcd_BoundingBox_t glcd_bbox;
extern glcd_screen_rotation_mode_t glcd_screen_rotation;
/** \name Base Functions
* @{
*/
void glcd_get_buffer_pos(uint8_t x, uint8_t y, buffer_packing_struct_t *bps);
uint8_t glcd_get_foreground_color(void);
uint8_t glcd_get_background_color(void);
void glcd_set_foreground_color(uint8_t color);
void glcd_mark_export_row_clean(const uint8_t row_number);
bool glcd_is_export_row_dirty(const uint8_t row_number);
uint8_t* glcd_get_export_row_pointer(const uint8_t row_number);
/**
* 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
*/
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);
/**
* 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);
void glcd_set_screen_rotation(const glcd_screen_rotation_mode_t mode);
glcd_screen_rotation_mode_t glcd_get_screen_rotation(void);
/**
* FIXME document this
*/
uint8_t glcd_reverse_significant_bits(uint32_t value);
/** @}*/
enum font_table_type { STANG, MIKRO };
typedef struct {
const char *font_table;
uint8_t width;
uint8_t height;
char start_char;
char end_char;
enum font_table_type table_type;
} glcd_FontConfig_t;
extern glcd_FontConfig_t font_current;
#endif