1 // hd-two-line.cxx - description. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
7 #include "hd-two-line.h"
11 hd_two_line :: init() {
12 put( LCD_IR, 0x38 ); // 2-lines, 5x8 font
13 put( LCD_IR, 1 ); // clear display
14 put( LCD_IR, 0x3 ); // return home
15 put( LCD_IR, 0xc ); // enable display
18 static char logo[] = { 0x3, 0x4, 0x9, 0xa, 0xa,
19 0xa, 0xa, 0x9, 0x4, 0x3, 0x0, 0x0, 0x0,
20 0x0, 0x0, 0x0, 0x18, 0x4, 0x13, 0x0b, 0x0,
21 0x0, 0xa, 0x13, 0x4, 0x18 };
24 hd_two_line :: draw_logo() {
27 put( LCD_IR, 0x43 ); // set AC to CGRAM char 0 line 3
29 for( i=0; i<26; i++ ) // create logo
30 put( LCD_DR, logo[i] );
32 put( LCD_IR, 0x80 ); // select DDRAM address 0
34 put( LCD_DR, 0 ); // write first line
43 put( LCD_IR, 0xc0 ); // select start of second line
45 put( LCD_DR, 1 ); // write second line
54 cout << "should see \"Cygnus rules!\" " << endl;
56 // This is for later, when the display is shifted
57 put( LCD_IR, 0x88 ); // select DDRAM address 8
59 put( LCD_DR, 0xf3 ); // infinity
60 put( LCD_DR, 0xfc ); // house?
62 put( LCD_IR, 0xa6 ); // select DDRAM address 0x26
64 put( LCD_DR, 0xec ); // cent
65 put( LCD_DR, 0xed ); // pound
67 put( LCD_IR, 0xc8 ); // select DDRAM address 0x48
69 put( LCD_DR, 0x5c ); // yen
70 put( LCD_DR, 0xf2 ); // theta
72 put( LCD_IR, 0xe6 ); // select DDRAM address 0x66
74 put( LCD_DR, 0xe8 ); // sqrt
75 put( LCD_DR, 0xf7 ); // pi
79 hd_two_line :: enable_cursor() {
80 put( LCD_IR, 0x82 ); // set DDRAM address to pos 2
81 put( LCD_IR, 0x0e ); // enable cursor display
83 cout << "cursor should be visible in line 1 pos 2" << endl;
87 hd_two_line :: move_cursor() {
88 put( LCD_IR, 0xc7 ); // set DDRAM address to pos 1
89 put( LCD_IR, 0x0f ); // enable cursor display
91 cout << "cursor and char should be blinking in line 2 pos 7" << endl;
95 hd_two_line :: shift_cursor_left() {
96 put( LCD_IR, 0x10 ); // shift cursor left
98 cout << "cursor and char should be blinking in line 2 pos 6" << endl;
102 hd_two_line :: shift_cursor_right() {
103 put( LCD_IR, 0x0d ); // disable cursor (leave blinking on)
104 put( LCD_IR, 0x14 ); // shift cursor right
106 cout << "char should be blinking in line 2 pos 7" << endl;
111 hd_two_line :: shift_display_left() {
112 put( LCD_IR, 0x18 ); // shift display left
114 cout << "display should be shifted left by one" << endl;
118 hd_two_line :: shift_display_right() {
119 put( LCD_IR, 0x1c ); // shift display right
121 cout << "display should be shifted right by one" << endl;
125 hd_two_line :: disable_display() {
128 cout << "display should be disabled " << endl;
132 hd_two_line :: enable_display() {
133 put( LCD_IR, 0x0c ); // leaves blink and cursor off
135 cout << "display is now enabled " << endl;
139 hd_two_line :: run( host_int_4 ) {
140 switch( curr_state() ) {
143 yield( DRAW_LOGO, 0 );
148 yield( NO_DISPLAY, 200000 );
153 yield( SET_CURSOR, 100000 );
159 yield( MOVE_CURSOR, 200000 );
164 yield( SHIFT_CURSOR_LEFT, 500000 );
167 case SHIFT_CURSOR_LEFT:
169 yield( SHIFT_CURSOR_RIGHT, 500000 );
172 case SHIFT_CURSOR_RIGHT:
173 shift_cursor_right();
174 yield( SHIFT_DISPLAY_LEFT, 500000 );
178 case SHIFT_DISPLAY_LEFT:
179 shift_display_left();
181 if( shift_count == 2 ) {
182 yield( SHIFT_DISPLAY_RIGHT, 200000 );
186 yield( SHIFT_DISPLAY_LEFT, 200000 );
189 case SHIFT_DISPLAY_RIGHT:
190 shift_display_right();
192 if( shift_count == 4 )
193 yield( DONE, 200000 );
195 yield( SHIFT_DISPLAY_RIGHT, 200000 );
206 cout << "all tests complete: fail count " << fail_count << endl;
211 static vector<string>
212 HD44780UTesterListTypes() {
213 vector<string> types;
214 types.push_back(string("hd44780u-tester"));
219 HD44780UTesterCreate( const string& typeName ) {
220 if(typeName == "hd44780u-tester")
221 return new hd_two_line();
227 HD44780UTesterDelete( component* c ) {
228 delete dynamic_cast<hd_two_line*>(c);
233 extern const component_library hd2l_tester_component_library;
235 const component_library hd2l_tester_component_library DLLEXPORT =
237 COMPONENT_LIBRARY_MAGIC,
238 & HD44780UTesterListTypes,
239 & HD44780UTesterCreate,
240 & HD44780UTesterDelete