26 #include "../config.h" |
26 #include "../config.h" |
27 #include "mbselib.h" |
27 #include "mbselib.h" |
28 |
28 |
29 #ifdef HAVE_WIRINGPI_H |
29 #ifdef HAVE_WIRINGPI_H |
30 |
30 |
31 int lcdHandle; |
31 int lcdHandle; |
|
32 static unsigned char lcdbuf[MAX_LCDS][20][4]; |
|
33 |
|
34 struct lcdDataStruct |
|
35 { |
|
36 int bits, rows, cols ; |
|
37 int rsPin, strbPin ; |
|
38 int dataPins [8] ; |
|
39 int cx, cy ; |
|
40 }; |
|
41 extern struct lcdDataStruct *lcds [MAX_LCDS]; |
|
42 |
|
43 |
|
44 /* |
|
45 * Some LCD functions are extended shadow copies of the wiringPi functions. |
|
46 * The difference is that the lcdbuf will be updated with the contents on |
|
47 * the hardware display. This copy can then be used for a remote display |
|
48 */ |
32 |
49 |
33 |
50 |
34 /* |
51 /* |
35 * setBacklight: |
52 * setBacklight: |
36 ********************************************************************************* |
53 ********************************************************************************* |
49 ********************************************************************************* |
66 ********************************************************************************* |
50 */ |
67 */ |
51 |
68 |
52 int initLCD (int cols, int rows) |
69 int initLCD (int cols, int rows) |
53 { |
70 { |
54 if (!((rows == 1) || (rows == 2) || (rows == 4))) |
71 int x, y; |
55 { |
|
56 fprintf (stderr, "rows must be 1, 2 or 4\n") ; |
|
57 return EXIT_FAILURE ; |
|
58 } |
|
59 |
72 |
60 if (!((cols == 16) || (cols == 20))) |
73 if (!((rows == 1) || (rows == 2) || (rows == 4))) { |
61 { |
74 fprintf (stderr, "rows must be 1, 2 or 4\n") ; |
62 fprintf (stderr, "cols must be 16 or 20\n") ; |
75 return EXIT_FAILURE ; |
63 return EXIT_FAILURE ; |
76 } |
64 } |
|
65 |
77 |
66 pcf8574Setup (AF_BASE, 0x27) ; |
78 if (!((cols == 16) || (cols == 20))) { |
|
79 fprintf (stderr, "cols must be 16 or 20\n") ; |
|
80 return EXIT_FAILURE ; |
|
81 } |
67 |
82 |
68 setBacklight (1) ; |
83 pcf8574Setup(AF_BASE, 0x27) ; |
|
84 pinMode (AF_RW, OUTPUT) ; |
|
85 digitalWrite (AF_RW, LOW) ; // Not used with wiringPi - always in write mode |
69 |
86 |
70 pinMode (AF_RW, OUTPUT) ; |
87 /* |
71 digitalWrite (AF_RW, LOW) ; // Not used with wiringPi - always in write mode |
88 * The other control pins are initialised with lcdInit () |
|
89 */ |
|
90 lcdHandle = lcdInit (rows, cols, 4, AF_RS, AF_E, AF_DB4, AF_DB5, AF_DB6, AF_DB7, 0, 0, 0, 0) ; |
|
91 if (lcdHandle < 0) { |
|
92 fprintf (stderr, "lcdInit failed\n") ; |
|
93 return -1 ; |
|
94 } |
72 |
95 |
73 // The other control pins are initialised with lcdInit () |
96 lcdClear (lcdHandle) ; |
|
97 for (x = 0; x < 20; x++) |
|
98 for (y = 0; y < 4; y++) |
|
99 lcdbuf[lcdHandle][x][y] = ' '; |
74 |
100 |
75 lcdHandle = lcdInit (rows, cols, 4, AF_RS, AF_E, AF_DB4, AF_DB5, AF_DB6, AF_DB7, 0, 0, 0, 0) ; |
101 setBacklight (1) ; |
76 |
102 |
77 if (lcdHandle < 0) |
103 return 0 ; |
78 { |
104 } |
79 fprintf (stderr, "lcdInit failed\n") ; |
|
80 return -1 ; |
|
81 } |
|
82 |
105 |
83 lcdClear (lcdHandle) ; |
106 |
84 return 0 ; |
107 |
|
108 void mb_lcdPutchar(const int fd, unsigned char data) |
|
109 { |
|
110 struct lcdDataStruct *lcd = lcds[fd]; |
|
111 |
|
112 /* |
|
113 * Write to our buffer first, then to the wiringPi driver. |
|
114 * Writing to wiringPi updates the cursor position. |
|
115 */ |
|
116 lcdbuf[fd][lcd->cx][lcd->cy] = data; |
|
117 lcdPutchar(fd, data); |
85 } |
118 } |
|
119 |
|
120 |
|
121 |
|
122 void mb_lcdPuts(const int fd, const char *string) |
|
123 { |
|
124 while (*string) |
|
125 mb_lcdPutchar (fd, *string++); |
|
126 } |
|
127 |
|
128 |
|
129 |
|
130 void mb_lcdClear(const int fd) |
|
131 { |
|
132 int x, y; |
|
133 |
|
134 lcdClear(fd); |
|
135 for (x = 0; x < 20; x++) |
|
136 for (y = 0; y < 4; y++) |
|
137 lcdbuf[fd][x][y] = ' '; |
|
138 } |
|
139 |
|
140 |
86 |
141 |
87 #endif |
142 #endif |
88 |
143 |