Mercurial > louis > kiibohd-controller
annotate Scan/STLcd/lcd_scan.c @ 353:c6613db89cbe
Adding capability to set default image on LCD
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 01 Aug 2015 23:13:19 -0700 |
parents | 99b567a3b1f2 |
children | 40bbbc667399 |
rev | line source |
---|---|
331 | 1 /* Copyright (C) 2015 by Jacob Alexander |
2 * | |
3 * This file is free software: you can redistribute it and/or modify | |
4 * it under the terms of the GNU General Public License as published by | |
5 * the Free Software Foundation, either version 3 of the License, or | |
6 * (at your option) any later version. | |
7 * | |
8 * This file is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * You should have received a copy of the GNU General Public License | |
14 * along with this file. If not, see <http://www.gnu.org/licenses/>. | |
15 */ | |
16 | |
17 // ----- Includes ----- | |
18 | |
19 // Compiler Includes | |
20 #include <Lib/ScanLib.h> | |
21 | |
22 // Project Includes | |
23 #include <cli.h> | |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
24 #include <kll.h> |
331 | 25 #include <led.h> |
26 #include <print.h> | |
27 | |
28 // Local Includes | |
29 #include "lcd_scan.h" | |
30 | |
31 | |
32 | |
33 // ----- Defines ----- | |
34 | |
35 #define LCD_TOTAL_VISIBLE_PAGES 4 | |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
36 #define LCD_PAGE_LEN 128 |
331 | 37 |
38 | |
39 | |
40 // ----- Macros ----- | |
41 | |
42 // Number of entries in the SPI0 TxFIFO | |
43 #define SPI0_TxFIFO_CNT ( ( SPI0_SR & SPI_SR_TXCTR ) >> 12 ) | |
44 | |
45 | |
46 | |
47 // ----- Structs ----- | |
48 | |
49 // ----- Function Declarations ----- | |
50 | |
51 // CLI Functions | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
52 void cliFunc_lcdCmd ( char* args ); |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
53 void cliFunc_lcdColor( char* args ); |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
54 void cliFunc_lcdInit ( char* args ); |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
55 void cliFunc_lcdTest ( char* args ); |
331 | 56 |
57 | |
58 | |
59 // ----- Variables ----- | |
60 | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
61 // Default Image - Displays on startup |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
62 const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
63 |
331 | 64 // Full Toggle State |
65 uint8_t cliFullToggleState = 0; | |
66 | |
67 // Normal/Reverse Toggle State | |
68 uint8_t cliNormalReverseToggleState = 0; | |
69 | |
70 // Scan Module command dictionary | |
71 CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." ); | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
72 CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. 0xFFF 0x1444 0x32" ); |
331 | 73 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); |
74 CLIDict_Entry( lcdTest, "Test out the LCD display." ); | |
75 | |
76 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { | |
77 CLIDict_Item( lcdCmd ), | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
78 CLIDict_Item( lcdColor ), |
331 | 79 CLIDict_Item( lcdInit ), |
80 CLIDict_Item( lcdTest ), | |
81 { 0, 0, 0 } // Null entry for dictionary end | |
82 }; | |
83 | |
84 | |
85 | |
86 // ----- Interrupt Functions ----- | |
87 | |
88 | |
89 | |
90 // ----- Functions ----- | |
91 | |
92 inline void SPI_setup() | |
93 { | |
94 // Enable SPI internal clock | |
95 SIM_SCGC6 |= SIM_SCGC6_SPI0; | |
96 | |
97 // Setup MOSI (SOUT) and SCLK (SCK) | |
98 PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
99 PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
100 | |
101 // Setup SS (PCS) | |
102 PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
103 | |
104 // Master Mode, CS0 | |
105 SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(1); | |
106 | |
107 // DSPI Clock and Transfer Attributes | |
108 // Frame Size: 8 bits | |
109 // MSB First | |
110 // CLK Low by default | |
111 SPI0_CTAR0 = SPI_CTAR_FMSZ(7) | |
112 | SPI_CTAR_ASC(7) | |
113 | SPI_CTAR_DT(7) | |
114 | SPI_CTAR_CSSCK(7) | |
115 | SPI_CTAR_PBR(0) | SPI_CTAR_BR(7); | |
116 } | |
117 | |
118 // Write buffer to SPI FIFO | |
119 void SPI_write( uint8_t *buffer, uint8_t len ) | |
120 { | |
121 | |
122 for ( uint8_t byte = 0; byte < len; byte++ ) | |
123 { | |
124 // Wait for SPI TxFIFO to have 4 or fewer entries | |
125 while ( !( SPI0_SR & SPI_SR_TFFF ) ) | |
126 delayMicroseconds(10); | |
127 | |
128 // Write byte to TxFIFO | |
129 // CS0, CTAR0 | |
130 SPI0_PUSHR = ( buffer[ byte ] & 0xff ) | SPI_PUSHR_PCS(1); | |
131 | |
132 // Indicate transfer has completed | |
133 while ( !( SPI0_SR & SPI_SR_TCF ) ); | |
134 SPI0_SR |= SPI_SR_TCF; | |
135 } | |
136 } | |
137 | |
138 // Write to a control register | |
139 void LCD_writeControlReg( uint8_t byte ) | |
140 { | |
141 // Wait for TxFIFO to be empt | |
142 while ( SPI0_TxFIFO_CNT != 0 ); | |
143 | |
144 // Set A0 low to enter control register mode | |
145 GPIOC_PCOR |= (1<<7); | |
146 | |
147 // Write byte to SPI FIFO | |
148 SPI_write( &byte, 1 ); | |
149 | |
150 // Wait for TxFIFO to be empty | |
151 while ( SPI0_TxFIFO_CNT != 0 ); | |
152 | |
153 // Make sure data has transferred | |
154 delayMicroseconds(10); // XXX Adjust if SPI speed changes | |
155 | |
156 // Set A0 high to go back to display register mode | |
157 GPIOC_PSOR |= (1<<7); | |
158 } | |
159 | |
160 // Write to display register | |
161 // Pages 0-7 normal display | |
162 // Page 8 icon buffer | |
163 void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len ) | |
164 { | |
165 // Set the register page | |
166 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
167 | |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
168 // Set display start line |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
169 LCD_writeControlReg( 0x40 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
170 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
171 // Reset Column Address |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
172 LCD_writeControlReg( 0x10 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
173 LCD_writeControlReg( 0x00 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
174 |
331 | 175 // Write buffer to SPI |
176 SPI_write( buffer, len ); | |
177 } | |
178 | |
179 inline void LCD_clearPage( uint8_t page ) | |
180 { | |
181 // Set the register page | |
182 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
183 | |
184 // Set display start line | |
185 LCD_writeControlReg( 0x40 ); | |
186 | |
187 // Reset Column Address | |
188 LCD_writeControlReg( 0x10 ); | |
189 LCD_writeControlReg( 0x00 ); | |
190 | |
191 for ( uint8_t page_reg = 0; page_reg < LCD_PAGE_LEN; page_reg++ ) | |
192 { | |
193 uint8_t byte = 0; | |
194 | |
195 // Write buffer to SPI | |
196 SPI_write( &byte, 1 ); | |
197 } | |
198 | |
199 // Wait for TxFIFO to be empty | |
200 while ( SPI0_TxFIFO_CNT != 0 ); | |
201 } | |
202 | |
203 // Clear Display | |
204 void LCD_clear() | |
205 { | |
206 // Setup each page | |
207 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) | |
208 { | |
209 LCD_clearPage( page ); | |
210 } | |
211 | |
212 // Reset Page, Start Line, and Column Address | |
213 // Page | |
214 LCD_writeControlReg( 0xB0 ); | |
215 | |
216 // Start Line | |
217 LCD_writeControlReg( 0x40 ); | |
218 | |
219 // Reset Column Address | |
220 LCD_writeControlReg( 0x10 ); | |
221 LCD_writeControlReg( 0x00 ); | |
222 } | |
223 | |
224 // Intialize display | |
225 void LCD_initialize() | |
226 { | |
227 // ADC Select (Normal) | |
228 LCD_writeControlReg( 0xA0 ); | |
229 | |
230 // LCD Off | |
231 LCD_writeControlReg( 0xAE ); | |
232 | |
233 // COM Scan Output Direction | |
234 LCD_writeControlReg( 0xC0 ); | |
235 | |
236 // LCD Bias (1/6 bias) | |
237 LCD_writeControlReg( 0xA2 ); | |
238 | |
239 // Power Supply Operating Mode (Internal Only) | |
240 LCD_writeControlReg( 0x2F ); | |
241 | |
242 // Internal Rb/Ra Ratio | |
243 LCD_writeControlReg( 0x26 ); | |
244 | |
245 // Reset | |
246 LCD_writeControlReg( 0xE2 ); | |
247 | |
248 // Electric volume mode set, and value | |
249 LCD_writeControlReg( 0x81 ); | |
250 LCD_writeControlReg( 0x00 ); | |
251 | |
252 // LCD On | |
253 LCD_writeControlReg( 0xAF ); | |
254 | |
255 // Clear Display RAM | |
256 LCD_clear(); | |
257 } | |
258 | |
259 // Setup | |
260 inline void LCD_setup() | |
261 { | |
262 // Register Scan CLI dictionary | |
263 CLI_registerDictionary( lcdCLIDict, lcdCLIDictName ); | |
264 | |
265 // Initialize SPI | |
266 SPI_setup(); | |
267 | |
268 // Setup Register Control Signal (A0) | |
269 // Start in display register mode (1) | |
270 GPIOC_PDDR |= (1<<7); | |
271 PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
272 GPIOC_PSOR |= (1<<7); | |
273 | |
274 // Setup LCD Reset pin (RST) | |
275 // 0 - Reset, 1 - Normal Operation | |
276 // Start in normal mode (1) | |
277 GPIOC_PDDR |= (1<<8); | |
278 PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
279 GPIOC_PSOR |= (1<<8); | |
280 | |
281 // Run LCD intialization sequence | |
282 LCD_initialize(); | |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
283 |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
284 // Write default image to LCD |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
285 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
286 LCD_writeDisplayReg( page, (uint8_t*)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
287 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
288 // Setup Backlight |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
289 // TODO Expose default settings |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
290 SIM_SCGC6 |= SIM_SCGC6_FTM0; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
291 FTM0_CNT = 0; // Reset counter |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
292 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
293 // PWM Period |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
294 // 16-bit maximum |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
295 FTM0_MOD = 0xFFFF; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
296 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
297 // Set FTM to PWM output - Edge Aligned, Low-true pulses |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
298 FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
299 FTM0_C1SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
300 FTM0_C2SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
301 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
302 // Base FTM clock selection (72 MHz system clock) |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
303 // @ 0xFFFF period, 72 MHz / 0xFFFF * 2 = Actual period |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
304 // Higher pre-scalar will use the most power (also look the best) |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
305 // Pre-scalar calculations |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
306 // 0 - 72 MHz -> 549 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
307 // 1 - 36 MHz -> 275 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
308 // 2 - 18 MHz -> 137 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
309 // 3 - 9 MHz -> 69 Hz (Slightly visible flicker) |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
310 // 4 - 4 500 kHz -> 34 Hz (Visible flickering) |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
311 // 5 - 2 250 kHz -> 17 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
312 // 6 - 1 125 kHz -> 9 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
313 // 7 - 562 500 Hz -> 4 Hz |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
314 // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
315 // Which will reduce the brightness range |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
316 |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
317 // System clock, /w prescalar setting |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
318 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define ); |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
319 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
320 // Red |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
321 FTM0_C0V = STLcdBacklightRed_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
322 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
323 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
324 // Green |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
325 FTM0_C1V = STLcdBacklightGreen_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
326 PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
327 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
328 // Blue |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
329 FTM0_C2V = STLcdBacklightBlue_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
330 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); |
331 | 331 } |
332 | |
333 | |
334 // LCD State processing loop | |
335 inline uint8_t LCD_scan() | |
336 { | |
337 // NOP - Screen Refresh | |
338 //LCD_writeControlReg( 0xE3 ); | |
339 return 0; | |
340 } | |
341 | |
342 | |
343 | |
344 // ----- CLI Command Functions ----- | |
345 | |
346 void cliFunc_lcdInit( char* args ) | |
347 { | |
348 LCD_initialize(); | |
349 } | |
350 | |
351 void cliFunc_lcdTest( char* args ) | |
352 { | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
353 // Write default image |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
354 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
355 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); |
331 | 356 } |
357 | |
358 void cliFunc_lcdCmd( char* args ) | |
359 { | |
360 char* curArgs; | |
361 char* arg1Ptr; | |
362 char* arg2Ptr = args; | |
363 | |
364 print( NL ); // No \r\n by default after the command is entered | |
365 | |
366 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
367 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
368 | |
369 // No args | |
370 if ( *arg1Ptr == '\0' ) | |
371 return; | |
372 | |
373 // SPI Command | |
374 uint8_t cmd = (uint8_t)numToInt( arg1Ptr ); | |
375 | |
376 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
377 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
378 | |
379 // Single Arg | |
380 if ( *arg1Ptr == '\0' ) | |
381 goto cmd; | |
382 | |
383 // TODO Deal with a0 | |
384 cmd: | |
385 info_msg("Sending - "); | |
386 printHex( cmd ); | |
387 print( NL ); | |
388 LCD_writeControlReg( cmd ); | |
389 } | |
390 | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
391 void cliFunc_lcdColor( char* args ) |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
392 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
393 char* curArgs; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
394 char* arg1Ptr; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
395 char* arg2Ptr = args; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
396 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
397 // Colors |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
398 uint16_t rgb[3]; // Red, Green, Blue |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
399 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
400 // Parse integers from 3 arguments |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
401 for ( uint8_t color = 0; color < 3; color++ ) |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
402 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
403 curArgs = arg2Ptr; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
404 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
405 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
406 // Give up if not enough args given |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
407 if ( *arg1Ptr == '\0' ) |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
408 return; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
409 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
410 // Convert argument to integer |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
411 rgb[ color ] = numToInt( arg1Ptr ); |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
412 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
413 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
414 // Set PWM channels |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
415 FTM0_C0V = rgb[0]; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
416 FTM0_C1V = rgb[1]; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
417 FTM0_C2V = rgb[2]; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
418 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
419 |