Mercurial > louis > kiibohd-controller
annotate Scan/STLcd/lcd_scan.c @ 366:95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
- Requires lcdFuncMap.kll instead of stdFuncMap.kll
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Tue, 18 Aug 2015 01:10:44 -0700 |
parents | 86b937945313 |
children | 8a6c2d410ad9 |
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> | |
357
86b937945313
Fixing CMake dependency checking for kll_defs.h
Jacob Alexander <haata@kiibohd.com>
parents:
354
diff
changeset
|
24 #include <kll_defs.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 | |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
36 #define LCD_TOTAL_PAGES 9 |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
37 #define LCD_PAGE_LEN 128 |
331 | 38 |
39 | |
40 | |
41 // ----- Macros ----- | |
42 | |
43 // Number of entries in the SPI0 TxFIFO | |
44 #define SPI0_TxFIFO_CNT ( ( SPI0_SR & SPI_SR_TXCTR ) >> 12 ) | |
45 | |
46 | |
47 | |
48 // ----- Structs ----- | |
49 | |
50 // ----- Function Declarations ----- | |
51 | |
52 // 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
|
53 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
|
54 void cliFunc_lcdColor( char* args ); |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
55 void cliFunc_lcdDisp ( char* args ); |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
56 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
|
57 void cliFunc_lcdTest ( char* args ); |
331 | 58 |
59 | |
60 | |
61 // ----- Variables ----- | |
62 | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
63 // Default Image - Displays on startup |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
64 const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
65 |
331 | 66 // Full Toggle State |
67 uint8_t cliFullToggleState = 0; | |
68 | |
69 // Normal/Reverse Toggle State | |
70 uint8_t cliNormalReverseToggleState = 0; | |
71 | |
72 // Scan Module command dictionary | |
73 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
|
74 CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. 0xFFF 0x1444 0x32" ); |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
75 CLIDict_Entry( lcdDisp, "Write byte(s) to given page starting at given address. i.e. 0x1 0x5 0xFF 0x00" ); |
331 | 76 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); |
77 CLIDict_Entry( lcdTest, "Test out the LCD display." ); | |
78 | |
79 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { | |
80 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
|
81 CLIDict_Item( lcdColor ), |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
82 CLIDict_Item( lcdDisp ), |
331 | 83 CLIDict_Item( lcdInit ), |
84 CLIDict_Item( lcdTest ), | |
85 { 0, 0, 0 } // Null entry for dictionary end | |
86 }; | |
87 | |
88 | |
89 | |
90 // ----- Interrupt Functions ----- | |
91 | |
92 | |
93 | |
94 // ----- Functions ----- | |
95 | |
96 inline void SPI_setup() | |
97 { | |
98 // Enable SPI internal clock | |
99 SIM_SCGC6 |= SIM_SCGC6_SPI0; | |
100 | |
101 // Setup MOSI (SOUT) and SCLK (SCK) | |
102 PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
103 PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
104 | |
105 // Setup SS (PCS) | |
106 PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
107 | |
108 // Master Mode, CS0 | |
109 SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(1); | |
110 | |
111 // DSPI Clock and Transfer Attributes | |
112 // Frame Size: 8 bits | |
113 // MSB First | |
114 // CLK Low by default | |
115 SPI0_CTAR0 = SPI_CTAR_FMSZ(7) | |
116 | SPI_CTAR_ASC(7) | |
117 | SPI_CTAR_DT(7) | |
118 | SPI_CTAR_CSSCK(7) | |
119 | SPI_CTAR_PBR(0) | SPI_CTAR_BR(7); | |
120 } | |
121 | |
122 // Write buffer to SPI FIFO | |
123 void SPI_write( uint8_t *buffer, uint8_t len ) | |
124 { | |
125 | |
126 for ( uint8_t byte = 0; byte < len; byte++ ) | |
127 { | |
128 // Wait for SPI TxFIFO to have 4 or fewer entries | |
129 while ( !( SPI0_SR & SPI_SR_TFFF ) ) | |
130 delayMicroseconds(10); | |
131 | |
132 // Write byte to TxFIFO | |
133 // CS0, CTAR0 | |
134 SPI0_PUSHR = ( buffer[ byte ] & 0xff ) | SPI_PUSHR_PCS(1); | |
135 | |
136 // Indicate transfer has completed | |
137 while ( !( SPI0_SR & SPI_SR_TCF ) ); | |
138 SPI0_SR |= SPI_SR_TCF; | |
139 } | |
140 } | |
141 | |
142 // Write to a control register | |
143 void LCD_writeControlReg( uint8_t byte ) | |
144 { | |
145 // Wait for TxFIFO to be empt | |
146 while ( SPI0_TxFIFO_CNT != 0 ); | |
147 | |
148 // Set A0 low to enter control register mode | |
149 GPIOC_PCOR |= (1<<7); | |
150 | |
151 // Write byte to SPI FIFO | |
152 SPI_write( &byte, 1 ); | |
153 | |
154 // Wait for TxFIFO to be empty | |
155 while ( SPI0_TxFIFO_CNT != 0 ); | |
156 | |
157 // Make sure data has transferred | |
158 delayMicroseconds(10); // XXX Adjust if SPI speed changes | |
159 | |
160 // Set A0 high to go back to display register mode | |
161 GPIOC_PSOR |= (1<<7); | |
162 } | |
163 | |
164 // Write to display register | |
165 // Pages 0-7 normal display | |
166 // Page 8 icon buffer | |
167 void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len ) | |
168 { | |
169 // Set the register page | |
170 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
171 | |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
172 // Set display start line |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
173 LCD_writeControlReg( 0x40 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
174 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
175 // Reset Column Address |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
176 LCD_writeControlReg( 0x10 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
177 LCD_writeControlReg( 0x00 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
178 |
331 | 179 // Write buffer to SPI |
180 SPI_write( buffer, len ); | |
181 } | |
182 | |
183 inline void LCD_clearPage( uint8_t page ) | |
184 { | |
185 // Set the register page | |
186 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
187 | |
188 // Set display start line | |
189 LCD_writeControlReg( 0x40 ); | |
190 | |
191 // Reset Column Address | |
192 LCD_writeControlReg( 0x10 ); | |
193 LCD_writeControlReg( 0x00 ); | |
194 | |
195 for ( uint8_t page_reg = 0; page_reg < LCD_PAGE_LEN; page_reg++ ) | |
196 { | |
197 uint8_t byte = 0; | |
198 | |
199 // Write buffer to SPI | |
200 SPI_write( &byte, 1 ); | |
201 } | |
202 | |
203 // Wait for TxFIFO to be empty | |
204 while ( SPI0_TxFIFO_CNT != 0 ); | |
205 } | |
206 | |
207 // Clear Display | |
208 void LCD_clear() | |
209 { | |
210 // Setup each page | |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
211 for ( uint8_t page = 0; page < LCD_TOTAL_PAGES; page++ ) |
331 | 212 { |
213 LCD_clearPage( page ); | |
214 } | |
215 | |
216 // Reset Page, Start Line, and Column Address | |
217 // Page | |
218 LCD_writeControlReg( 0xB0 ); | |
219 | |
220 // Start Line | |
221 LCD_writeControlReg( 0x40 ); | |
222 | |
223 // Reset Column Address | |
224 LCD_writeControlReg( 0x10 ); | |
225 LCD_writeControlReg( 0x00 ); | |
226 } | |
227 | |
228 // Intialize display | |
229 void LCD_initialize() | |
230 { | |
231 // ADC Select (Normal) | |
232 LCD_writeControlReg( 0xA0 ); | |
233 | |
234 // LCD Off | |
235 LCD_writeControlReg( 0xAE ); | |
236 | |
237 // COM Scan Output Direction | |
238 LCD_writeControlReg( 0xC0 ); | |
239 | |
240 // LCD Bias (1/6 bias) | |
241 LCD_writeControlReg( 0xA2 ); | |
242 | |
243 // Power Supply Operating Mode (Internal Only) | |
244 LCD_writeControlReg( 0x2F ); | |
245 | |
246 // Internal Rb/Ra Ratio | |
247 LCD_writeControlReg( 0x26 ); | |
248 | |
249 // Reset | |
250 LCD_writeControlReg( 0xE2 ); | |
251 | |
252 // Electric volume mode set, and value | |
253 LCD_writeControlReg( 0x81 ); | |
254 LCD_writeControlReg( 0x00 ); | |
255 | |
256 // LCD On | |
257 LCD_writeControlReg( 0xAF ); | |
258 | |
259 // Clear Display RAM | |
260 LCD_clear(); | |
261 } | |
262 | |
263 // Setup | |
264 inline void LCD_setup() | |
265 { | |
266 // Register Scan CLI dictionary | |
267 CLI_registerDictionary( lcdCLIDict, lcdCLIDictName ); | |
268 | |
269 // Initialize SPI | |
270 SPI_setup(); | |
271 | |
272 // Setup Register Control Signal (A0) | |
273 // Start in display register mode (1) | |
274 GPIOC_PDDR |= (1<<7); | |
275 PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
276 GPIOC_PSOR |= (1<<7); | |
277 | |
278 // Setup LCD Reset pin (RST) | |
279 // 0 - Reset, 1 - Normal Operation | |
280 // Start in normal mode (1) | |
281 GPIOC_PDDR |= (1<<8); | |
282 PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
283 GPIOC_PSOR |= (1<<8); | |
284 | |
285 // Run LCD intialization sequence | |
286 LCD_initialize(); | |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
287 |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
288 // Write default image to LCD |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
289 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
|
290 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
|
291 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
292 // Setup Backlight |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
293 SIM_SCGC6 |= SIM_SCGC6_FTM0; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
294 FTM0_CNT = 0; // Reset counter |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
295 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
296 // PWM Period |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
297 // 16-bit maximum |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
298 FTM0_MOD = 0xFFFF; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
299 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
300 // 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
|
301 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
|
302 FTM0_C1SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
303 FTM0_C2SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
304 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
305 // Base FTM clock selection (72 MHz system clock) |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
306 // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
307 // 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
|
308 // 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
|
309 // 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
|
310 // 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
|
311 // 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
|
312 // 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
|
313 // 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
|
314 // 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
|
315 // 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
|
316 // 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
|
317 // 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
|
318 // 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
|
319 |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
320 // System clock, /w prescalar setting |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
321 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
|
322 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
323 // Red |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
324 FTM0_C0V = STLcdBacklightRed_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
325 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
|
326 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
327 // Green |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
328 FTM0_C1V = STLcdBacklightGreen_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
329 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
|
330 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
331 // Blue |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
332 FTM0_C2V = STLcdBacklightBlue_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
333 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); |
331 | 334 } |
335 | |
336 | |
337 // LCD State processing loop | |
338 inline uint8_t LCD_scan() | |
339 { | |
340 return 0; | |
341 } | |
342 | |
343 | |
344 | |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
345 // ----- Capabilities ----- |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
346 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
347 uint16_t LCD_layerStack_prevSize = 0; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
348 void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
349 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
350 // Display capability name |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
351 if ( stateType == 0xFF && state == 0xFF ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
352 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
353 print("LCD_layerStack_capability"); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
354 return; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
355 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
356 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
357 // Parse the layer stack, top to bottom |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
358 extern uint16_t macroLayerIndexStack[]; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
359 extern uint16_t macroLayerIndexStackSize; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
360 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
361 // Only process if the stack size has changed |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
362 if ( macroLayerIndexStackSize == LCD_layerStack_prevSize ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
363 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
364 return; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
365 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
366 LCD_layerStack_prevSize = macroLayerIndexStackSize; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
367 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
368 // Number data for LCD |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
369 const uint8_t numbers[10][128] = { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
370 { STLcdNumber0_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
371 { STLcdNumber1_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
372 { STLcdNumber2_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
373 { STLcdNumber3_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
374 { STLcdNumber4_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
375 { STLcdNumber5_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
376 { STLcdNumber6_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
377 { STLcdNumber7_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
378 { STLcdNumber8_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
379 { STLcdNumber9_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
380 }; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
381 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
382 // Only display if there are layers active |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
383 if ( macroLayerIndexStackSize > 0 ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
384 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
385 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
386 // Iterate through each of the pages |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
387 // XXX Many of the values here are hard-coded |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
388 // Eventually a proper font rendering engine should take care of things like this... -HaaTa |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
389 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
390 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
391 // Set the register page |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
392 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
393 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
394 // Set starting address |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
395 LCD_writeControlReg( 0x10 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
396 LCD_writeControlReg( 0x00 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
397 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
398 // Write data |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
399 for ( uint16_t layer = 1; layer <= macroLayerIndexStackSize; layer++ ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
400 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
401 uint16_t layerIndex = macroLayerIndexStack[ macroLayerIndexStackSize - layer ]; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
402 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
403 // Default to 0, if over 9 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
404 if ( layerIndex > 9 ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
405 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
406 layerIndex = 0; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
407 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
408 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
409 // Write page of number to display |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
410 SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
411 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
412 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
413 // Blank out rest of display |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
414 uint8_t data = 0; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
415 for ( uint8_t c = 0; c < 4 - macroLayerIndexStackSize; c++ ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
416 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
417 for ( uint8_t byte = 0; byte < 32; byte++ ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
418 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
419 SPI_write( &data, 1 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
420 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
421 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
422 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
423 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
424 else |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
425 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
426 // Write default image |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
427 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
428 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
429 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
430 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
431 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
432 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
433 |
331 | 434 // ----- CLI Command Functions ----- |
435 | |
436 void cliFunc_lcdInit( char* args ) | |
437 { | |
438 LCD_initialize(); | |
439 } | |
440 | |
441 void cliFunc_lcdTest( char* args ) | |
442 { | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
443 // Write default image |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
444 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
|
445 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); |
331 | 446 } |
447 | |
448 void cliFunc_lcdCmd( char* args ) | |
449 { | |
450 char* curArgs; | |
451 char* arg1Ptr; | |
452 char* arg2Ptr = args; | |
453 | |
454 print( NL ); // No \r\n by default after the command is entered | |
455 | |
456 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
457 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
458 | |
459 // No args | |
460 if ( *arg1Ptr == '\0' ) | |
461 return; | |
462 | |
463 // SPI Command | |
464 uint8_t cmd = (uint8_t)numToInt( arg1Ptr ); | |
465 | |
466 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
467 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
468 | |
469 // Single Arg | |
470 if ( *arg1Ptr == '\0' ) | |
471 goto cmd; | |
472 | |
473 // TODO Deal with a0 | |
474 cmd: | |
475 info_msg("Sending - "); | |
476 printHex( cmd ); | |
477 print( NL ); | |
478 LCD_writeControlReg( cmd ); | |
479 } | |
480 | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
481 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
|
482 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
487 // Colors |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
488 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
|
489 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
490 // 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
|
491 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
|
492 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
493 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
|
494 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
|
495 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
496 // 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
|
497 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
|
498 return; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
499 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
500 // 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
|
501 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
|
502 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
503 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
504 // 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
|
505 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
|
506 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
|
507 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
|
508 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
509 |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
510 void cliFunc_lcdDisp( char* args ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
511 { |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
512 char* curArgs; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
513 char* arg1Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
514 char* arg2Ptr = args; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
515 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
516 // First process page and starting address |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
517 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
518 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
519 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
520 // Stop processing args if no more are found |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
521 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
522 return; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
523 uint8_t page = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
524 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
525 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
526 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
527 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
528 // Stop processing args if no more are found |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
529 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
530 return; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
531 uint8_t address = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
532 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
533 // Set the register page |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
534 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
535 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
536 // Set starting address |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
537 LCD_writeControlReg( 0x10 | ( ( 0xF0 & address ) >> 4 ) ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
538 LCD_writeControlReg( 0x00 | ( 0x0F & address )); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
539 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
540 // Process all args |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
541 for ( ;; ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
542 { |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
543 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
544 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
545 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
546 // Stop processing args if no more are found |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
547 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
548 break; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
549 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
550 uint8_t value = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
551 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
552 // Write buffer to SPI |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
553 SPI_write( &value, 1 ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
554 } |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
555 } |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
556 |