GLCD Library
A C Library for Embedded Applications
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
glcd.c
Go to the documentation of this file.
1 
8 /*
9  Copyright (c) 2012, Andy Gock
10 
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of Andy Gock nor the
21  names of its contributors may be used to endorse or promote products
22  derived from this software without specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 
36 #include <string.h>
37 #include <stdio.h>
38 #include "glcd.h"
39 
50 
56 
61 
66 
69 void glcd_update_bbox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax)
70 {
71  /* Keep and check bounding box within limits of LCD screen dimensions */
72  if (xmin > (GLCD_LCD_WIDTH-1)) {
73  xmin = GLCD_LCD_WIDTH-1;
74  }
75  if (xmax > (GLCD_LCD_WIDTH-1)) {
76  xmax = GLCD_LCD_WIDTH-1;
77  }
78 
79  if (ymin > (GLCD_LCD_HEIGHT-1)) {
80  ymin = GLCD_LCD_HEIGHT-1;
81  }
82  if (ymax > (GLCD_LCD_HEIGHT-1)) {
83  ymax = GLCD_LCD_HEIGHT-1;
84  }
85 
86  /* Update the bounding box size */
87  if (xmin < glcd_bbox_selected->x_min) {
88  glcd_bbox_selected->x_min = xmin;
89  }
90  if (xmax > glcd_bbox_selected->x_max) {
91  glcd_bbox_selected->x_max = xmax;
92  }
93  if (ymin < glcd_bbox_selected->y_min) {
94  glcd_bbox_selected->y_min = ymin;
95  }
96  if (ymax > glcd_bbox_selected->y_max) {
97  glcd_bbox_selected->y_max = ymax;
98  }
99 }
100 
102 {
103  /* Used after physically writing to the LCD */
104  glcd_bbox_selected->x_min = GLCD_LCD_WIDTH - 1;
105  glcd_bbox_selected->x_max = 0;
106  glcd_bbox_selected->y_min = GLCD_LCD_HEIGHT -1;
107  glcd_bbox_selected->y_max = 0;
108 }
109 
111  glcd_reset_bbox();
112 }
113 
115  /* Marks bounding box as entire screen, so on next glcd_write(), it writes the entire buffer to the LCD */
116  glcd_bbox_selected->x_min = 0;
117  glcd_bbox_selected->x_max = GLCD_LCD_WIDTH - 1;
118  glcd_bbox_selected->y_min = 0;
119  glcd_bbox_selected->y_max = GLCD_LCD_HEIGHT -1;
120 }
121 
122 void glcd_clear(void) {
125  glcd_write();
126 }
127 
128 void glcd_clear_buffer(void) {
131 }
132 
133 void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox)
134 {
135  glcd_buffer_selected = buffer;
136  glcd_bbox_selected = bbox;
137 }
138 
139 void glcd_scroll(int8_t x, int8_t y)
140 {
143  uint8_t row;
144 
145  for (row=0; row<(GLCD_LCD_HEIGHT / 8); row++) {
146  uint8_t x;
147  for (x=0; x<GLCD_LCD_WIDTH; x++) {
148 
149  }
150  }
151 }
152 
154 {
155  uint8_t y;
156  uint8_t number_of_rows = GLCD_LCD_HEIGHT / 8;
157  for (y=0; y<number_of_rows; y++) {
158  if (y < (number_of_rows - 1)) {
159  /* All lines except the last */
160  memcpy(glcd_buffer_selected + y*GLCD_LCD_WIDTH, glcd_buffer_selected + y*GLCD_LCD_WIDTH + GLCD_LCD_WIDTH, GLCD_LCD_WIDTH);
161  } else {
162  /* Last line, clear it */
163  memset(glcd_buffer_selected + (number_of_rows - 1)*GLCD_LCD_WIDTH, 0x00, GLCD_LCD_WIDTH);
164  }
165  }
167 }
168 
#define GLCD_LCD_WIDTH
User specified GLCD width in pixels Set to 0 for automatic assignment based on controller.
Definition: glcd.h:140
glcd_BoundingBox_t * glcd_bbox_selected
Pointer to bounding box currently in use.
Definition: glcd.c:65
void glcd_write(void)
Update the display within the specified bounding box.
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
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
uint8_t y_max
Definition: glcd.h:166
void glcd_bbox_refresh()
Marks the entire display for re-writing.
Definition: glcd.c:114
uint8_t y_min
Definition: glcd.h:164
#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
void glcd_clear_buffer(void)
Clear the display buffer only.
Definition: glcd.c:128
uint8_t x_min
Definition: glcd.h:163
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
GLCD Library main header file.
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