3 * @author Copyright(C) 2012 Shinichiro Nakamura
4 * @brief BlueTank ACB-BF592 Application Sample Codes.
8 * ===============================================================
10 * ===============================================================
11 * Copyright (c) 2012 Shinichiro Nakamura
13 * Permission is hereby granted, free of charge, to any person
14 * obtaining a copy of this software and associated documentation
15 * files (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use,
17 * copy, modify, merge, publish, distribute, sublicense, and/or
18 * sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
27 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 * ===============================================================
36 #include <cdefBF592-A.h>
39 #include "bfin_util.h"
43 *pPORTFIO_DIR |= (PF0 | PF1 | PF2 | PF3 | PF4 | PF5); \
49 *pPORTFIO_SET = PF2; \
51 *pPORTFIO_CLEAR = PF2; \
54 *pPORTFIO_SET = PF3; \
56 *pPORTFIO_CLEAR = PF3; \
59 *pPORTFIO_SET = PF4; \
61 *pPORTFIO_CLEAR = PF4; \
64 *pPORTFIO_SET = PF5; \
66 *pPORTFIO_CLEAR = PF5; \
70 #define RS_ON() (*pPORTFIO_SET = PF0)
71 #define RS_OFF() (*pPORTFIO_CLEAR = PF0)
72 #define E_ON() (*pPORTFIO_SET = PF1)
73 #define E_OFF() (*pPORTFIO_CLEAR = PF1)
75 #define DELAY_US(N) bfin_util_usleep(N)
77 static void write_command(unsigned char c)
79 DATA((c >> 4) & 0x0f);
86 DATA((c >> 0) & 0x0f);
106 * Function set (Interface is 8bits long.)
108 DATA(0x03); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(20000);
109 DATA(0x03); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(5000);
110 DATA(0x03); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(100);
115 DATA(0x02); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
116 DATA(0x02); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
117 DATA(0x08); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
121 * Display ON/OFF Control
123 DATA(0x00); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
124 DATA(0x0C); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
130 DATA(0x00); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
131 DATA(0x01); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
137 DATA(0x00); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
138 DATA(0x06); DELAY_US(1); E_ON(); DELAY_US(1); E_OFF(); DELAY_US(1000);
149 void lcd_cursor_at_home(void)
156 void lcd_entry_mode_set(bool increment, bool shifted)
160 | (increment ? (1 << 1) : (0 << 1))
161 | (shifted ? (1 << 0) : (0 << 0)));
165 void lcd_display(bool display, bool cursor, bool blink)
169 | (display ? (1 << 2) : (0 << 2))
170 | (cursor ? (1 << 1) : (0 << 1))
171 | (blink ? (1 << 0) : (0 << 0)));
175 void lcd_cursor_shift(Direction dir)
180 | ((Right == dir) ? (1 << 2) : (0 << 2)));
184 void lcd_display_shift(Direction dir)
189 | ((Right == dir) ? (1 << 2) : (0 << 2)));
193 void lcd_goto(uint8_t x, uint8_t y)
195 uint8_t addr = (y * 0xc0) + x;
202 void lcd_putc(char c)
209 void lcd_puts(char *str)
217 void lcd_font_init(FontSet *fs)
220 for (i = 0; i < LCD_FONT_CHARS; i++) {
221 for (j = 0; j < LCD_FONT_HEIGHT; j++) {
222 fs->fontlist[i].data[j] = 0x00;
227 void lcd_font_set_pixel(
228 FontSet *fs, UserFont index,
229 const int x, const int y, const int on)
231 if (LCD_FONT_WIDTH <= x) {
234 if (LCD_FONT_HEIGHT <= y) {
238 fs->fontlist[(int)index].data[y] |=
239 (1 << (LCD_FONT_WIDTH - x - 1));
241 fs->fontlist[(int)index].data[y] &=
242 ~(1 << (LCD_FONT_WIDTH - x - 1));
253 void lcd_font_draw_line(
254 FontSet *fs, UserFont index,
261 * Bresenham's line algorithm
263 bool steep = abs(y2 - y1) > abs(x2 - x1);
272 int deltax = x2 - x1;
273 int deltay = abs(y2 - y1);
274 int error = deltax / 2;
282 for (x = x1; x <= x2; x++) {
284 lcd_font_set_pixel(fs, index, y, x, on);
286 lcd_font_set_pixel(fs, index, x, y, on);
288 error = error - deltay;
291 error = error + deltax;
296 void lcd_font_setup_single(FontSet *fs, UserFont index)
298 uint8_t addr = 8 * (int)index;
299 int i = (int)index, j;
300 for (j = 0; j < LCD_FONT_HEIGHT; j++) {
302 write_command(0x40 | (addr & 0x3f));
306 write_command(fs->fontlist[i].data[j]);
313 void lcd_font_setup_all(FontSet *fs)
317 for (i = 0; i < LCD_FONT_CHARS; i++) {
318 for (j = 0; j < LCD_FONT_HEIGHT; j++) {
320 write_command(0x40 | (addr & 0x3f));
324 write_command(fs->fontlist[i].data[j]);