Mercurial > louis > kiibohd-controller
annotate Scan/STLcd/lcd_scan.c @ 389:fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
- Rx buffers weren't fast enough, had to use DMA :D
- Basic LCD remote capabilities are working, single node
- Multi-node broadcast seems to have a bug still
- DMA ring buffer allowed for significant processing simplification
* There is an overrun risk, but the buffer is large and generally there isn't too much data being sent (just very quickly)
- Split out LCD layer stack capability into itself and an "exact" version used for updating remote nodes
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Thu, 15 Oct 2015 00:16:36 -0700 |
parents | dbbdedccc275 |
children | 23a1868b4ac2 |
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 | |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
28 // Interconnect module if compiled in |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
29 #if defined(ConnectEnabled_define) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
30 #include <connect_scan.h> |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
31 #endif |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
32 |
331 | 33 // Local Includes |
34 #include "lcd_scan.h" | |
35 | |
36 | |
37 | |
38 // ----- Defines ----- | |
39 | |
40 #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
|
41 #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
|
42 #define LCD_PAGE_LEN 128 |
331 | 43 |
44 | |
45 | |
46 // ----- Macros ----- | |
47 | |
48 // Number of entries in the SPI0 TxFIFO | |
49 #define SPI0_TxFIFO_CNT ( ( SPI0_SR & SPI_SR_TXCTR ) >> 12 ) | |
50 | |
51 | |
52 | |
53 // ----- Structs ----- | |
54 | |
55 // ----- Function Declarations ----- | |
56 | |
57 // 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
|
58 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
|
59 void cliFunc_lcdColor( char* args ); |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
60 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
|
61 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
|
62 void cliFunc_lcdTest ( char* args ); |
331 | 63 |
64 | |
65 | |
66 // ----- Variables ----- | |
67 | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
68 // Default Image - Displays on startup |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
69 const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
70 |
331 | 71 // Full Toggle State |
72 uint8_t cliFullToggleState = 0; | |
73 | |
74 // Normal/Reverse Toggle State | |
75 uint8_t cliNormalReverseToggleState = 0; | |
76 | |
77 // Scan Module command dictionary | |
78 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
|
79 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
|
80 CLIDict_Entry( lcdDisp, "Write byte(s) to given page starting at given address. i.e. 0x1 0x5 0xFF 0x00" ); |
331 | 81 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); |
82 CLIDict_Entry( lcdTest, "Test out the LCD display." ); | |
83 | |
84 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { | |
85 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
|
86 CLIDict_Item( lcdColor ), |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
87 CLIDict_Item( lcdDisp ), |
331 | 88 CLIDict_Item( lcdInit ), |
89 CLIDict_Item( lcdTest ), | |
90 { 0, 0, 0 } // Null entry for dictionary end | |
91 }; | |
92 | |
93 | |
94 | |
95 // ----- Interrupt Functions ----- | |
96 | |
97 | |
98 | |
99 // ----- Functions ----- | |
100 | |
101 inline void SPI_setup() | |
102 { | |
103 // Enable SPI internal clock | |
104 SIM_SCGC6 |= SIM_SCGC6_SPI0; | |
105 | |
106 // Setup MOSI (SOUT) and SCLK (SCK) | |
107 PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
108 PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
109 | |
110 // Setup SS (PCS) | |
111 PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(2); | |
112 | |
113 // Master Mode, CS0 | |
114 SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(1); | |
115 | |
116 // DSPI Clock and Transfer Attributes | |
117 // Frame Size: 8 bits | |
118 // MSB First | |
119 // CLK Low by default | |
120 SPI0_CTAR0 = SPI_CTAR_FMSZ(7) | |
121 | SPI_CTAR_ASC(7) | |
122 | SPI_CTAR_DT(7) | |
123 | SPI_CTAR_CSSCK(7) | |
124 | SPI_CTAR_PBR(0) | SPI_CTAR_BR(7); | |
125 } | |
126 | |
127 // Write buffer to SPI FIFO | |
128 void SPI_write( uint8_t *buffer, uint8_t len ) | |
129 { | |
130 | |
131 for ( uint8_t byte = 0; byte < len; byte++ ) | |
132 { | |
133 // Wait for SPI TxFIFO to have 4 or fewer entries | |
134 while ( !( SPI0_SR & SPI_SR_TFFF ) ) | |
135 delayMicroseconds(10); | |
136 | |
137 // Write byte to TxFIFO | |
138 // CS0, CTAR0 | |
139 SPI0_PUSHR = ( buffer[ byte ] & 0xff ) | SPI_PUSHR_PCS(1); | |
140 | |
141 // Indicate transfer has completed | |
142 while ( !( SPI0_SR & SPI_SR_TCF ) ); | |
143 SPI0_SR |= SPI_SR_TCF; | |
144 } | |
145 } | |
146 | |
147 // Write to a control register | |
148 void LCD_writeControlReg( uint8_t byte ) | |
149 { | |
150 // Wait for TxFIFO to be empt | |
151 while ( SPI0_TxFIFO_CNT != 0 ); | |
152 | |
153 // Set A0 low to enter control register mode | |
154 GPIOC_PCOR |= (1<<7); | |
155 | |
156 // Write byte to SPI FIFO | |
157 SPI_write( &byte, 1 ); | |
158 | |
159 // Wait for TxFIFO to be empty | |
160 while ( SPI0_TxFIFO_CNT != 0 ); | |
161 | |
162 // Make sure data has transferred | |
163 delayMicroseconds(10); // XXX Adjust if SPI speed changes | |
164 | |
165 // Set A0 high to go back to display register mode | |
166 GPIOC_PSOR |= (1<<7); | |
167 } | |
168 | |
169 // Write to display register | |
170 // Pages 0-7 normal display | |
171 // Page 8 icon buffer | |
172 void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len ) | |
173 { | |
174 // Set the register page | |
175 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
176 | |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
177 // Set display start line |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
178 LCD_writeControlReg( 0x40 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
179 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
180 // Reset Column Address |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
181 LCD_writeControlReg( 0x10 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
182 LCD_writeControlReg( 0x00 ); |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
183 |
331 | 184 // Write buffer to SPI |
185 SPI_write( buffer, len ); | |
186 } | |
187 | |
188 inline void LCD_clearPage( uint8_t page ) | |
189 { | |
190 // Set the register page | |
191 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); | |
192 | |
193 // Set display start line | |
194 LCD_writeControlReg( 0x40 ); | |
195 | |
196 // Reset Column Address | |
197 LCD_writeControlReg( 0x10 ); | |
198 LCD_writeControlReg( 0x00 ); | |
199 | |
200 for ( uint8_t page_reg = 0; page_reg < LCD_PAGE_LEN; page_reg++ ) | |
201 { | |
202 uint8_t byte = 0; | |
203 | |
204 // Write buffer to SPI | |
205 SPI_write( &byte, 1 ); | |
206 } | |
207 | |
208 // Wait for TxFIFO to be empty | |
209 while ( SPI0_TxFIFO_CNT != 0 ); | |
210 } | |
211 | |
212 // Clear Display | |
213 void LCD_clear() | |
214 { | |
215 // Setup each page | |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
216 for ( uint8_t page = 0; page < LCD_TOTAL_PAGES; page++ ) |
331 | 217 { |
218 LCD_clearPage( page ); | |
219 } | |
220 | |
221 // Reset Page, Start Line, and Column Address | |
222 // Page | |
223 LCD_writeControlReg( 0xB0 ); | |
224 | |
225 // Start Line | |
226 LCD_writeControlReg( 0x40 ); | |
227 | |
228 // Reset Column Address | |
229 LCD_writeControlReg( 0x10 ); | |
230 LCD_writeControlReg( 0x00 ); | |
231 } | |
232 | |
233 // Intialize display | |
234 void LCD_initialize() | |
235 { | |
236 // ADC Select (Normal) | |
237 LCD_writeControlReg( 0xA0 ); | |
238 | |
239 // LCD Off | |
240 LCD_writeControlReg( 0xAE ); | |
241 | |
242 // COM Scan Output Direction | |
243 LCD_writeControlReg( 0xC0 ); | |
244 | |
245 // LCD Bias (1/6 bias) | |
246 LCD_writeControlReg( 0xA2 ); | |
247 | |
248 // Power Supply Operating Mode (Internal Only) | |
249 LCD_writeControlReg( 0x2F ); | |
250 | |
251 // Internal Rb/Ra Ratio | |
252 LCD_writeControlReg( 0x26 ); | |
253 | |
254 // Reset | |
255 LCD_writeControlReg( 0xE2 ); | |
256 | |
257 // Electric volume mode set, and value | |
258 LCD_writeControlReg( 0x81 ); | |
259 LCD_writeControlReg( 0x00 ); | |
260 | |
261 // LCD On | |
262 LCD_writeControlReg( 0xAF ); | |
263 | |
264 // Clear Display RAM | |
265 LCD_clear(); | |
266 } | |
267 | |
268 // Setup | |
269 inline void LCD_setup() | |
270 { | |
271 // Register Scan CLI dictionary | |
272 CLI_registerDictionary( lcdCLIDict, lcdCLIDictName ); | |
273 | |
274 // Initialize SPI | |
275 SPI_setup(); | |
276 | |
277 // Setup Register Control Signal (A0) | |
278 // Start in display register mode (1) | |
279 GPIOC_PDDR |= (1<<7); | |
280 PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
281 GPIOC_PSOR |= (1<<7); | |
282 | |
283 // Setup LCD Reset pin (RST) | |
284 // 0 - Reset, 1 - Normal Operation | |
285 // Start in normal mode (1) | |
286 GPIOC_PDDR |= (1<<8); | |
287 PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
288 GPIOC_PSOR |= (1<<8); | |
289 | |
290 // Run LCD intialization sequence | |
291 LCD_initialize(); | |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
292 |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
293 // Write default image to LCD |
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
294 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
|
295 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
|
296 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
332
diff
changeset
|
297 // Setup Backlight |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
298 SIM_SCGC6 |= SIM_SCGC6_FTM0; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
299 FTM0_CNT = 0; // Reset counter |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
300 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
301 // PWM Period |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
302 // 16-bit maximum |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
303 FTM0_MOD = 0xFFFF; |
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 // 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
|
306 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
|
307 FTM0_C1SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
308 FTM0_C2SC = 0x24; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
309 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
310 // 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
|
311 // @ 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
|
312 // 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
|
313 // 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
|
314 // 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
|
315 // 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
|
316 // 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
|
317 // 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
|
318 // 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
|
319 // 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
|
320 // 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
|
321 // 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
|
322 // 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
|
323 // 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
|
324 |
351
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
325 // System clock, /w prescalar setting |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
326 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
|
327 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
328 // Red |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
329 FTM0_C0V = STLcdBacklightRed_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
330 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
|
331 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
332 // Green |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
333 FTM0_C1V = STLcdBacklightGreen_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
334 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
|
335 |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
336 // Blue |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
337 FTM0_C2V = STLcdBacklightBlue_define; |
38395a57cf52
Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
338 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); |
331 | 339 } |
340 | |
341 | |
342 // LCD State processing loop | |
343 inline uint8_t LCD_scan() | |
344 { | |
345 return 0; | |
346 } | |
347 | |
348 | |
349 | |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
350 // ----- Capabilities ----- |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
351 |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
352 // Takes 1 8 bit length and 4 16 bit arguments, each corresponding to a layer index |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
353 // Ordered from top to bottom |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
354 // The first argument indicates how many numbers to display (max 4), set to 0 to load default image |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
355 uint16_t LCD_layerStackExact[4]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
356 uint8_t LCD_layerStackExact_size = 0; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
357 typedef struct LCD_layerStackExact_args { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
358 uint8_t numArgs; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
359 uint16_t layers[4]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
360 } LCD_layerStackExact_args; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
361 void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
362 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
363 // Display capability name |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
364 if ( stateType == 0xFF && state == 0xFF ) |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
365 { |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
366 print("LCD_layerStackExact_capability(num,layer1,layer2,layer3,layer4)"); |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
367 return; |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
368 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
369 |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
370 // Read arguments |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
371 LCD_layerStackExact_args *stack_args = (LCD_layerStackExact_args*)args; |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
372 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
373 // Number data for LCD |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
374 const uint8_t numbers[10][128] = { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
375 { STLcdNumber0_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
376 { STLcdNumber1_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
377 { STLcdNumber2_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
378 { STLcdNumber3_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
379 { STLcdNumber4_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
380 { STLcdNumber5_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
381 { STLcdNumber6_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
382 { STLcdNumber7_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
383 { STLcdNumber8_define }, |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
384 { STLcdNumber9_define }, |
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 |
367
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
387 // Color data for numbers |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
388 const uint16_t colors[10][3] = { |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
389 { STLcdNumber0Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
390 { STLcdNumber1Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
391 { STLcdNumber2Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
392 { STLcdNumber3Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
393 { STLcdNumber4Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
394 { STLcdNumber5Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
395 { STLcdNumber6Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
396 { STLcdNumber7Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
397 { STLcdNumber8Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
398 { STLcdNumber9Color_define }, |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
399 }; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
400 |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
401 // Only display if there are layers active |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
402 if ( stack_args->numArgs > 0 ) |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
403 { |
367
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
404 // Set the color according to the "top-of-stack" layer |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
405 uint16_t layerIndex = stack_args->layers[0]; |
367
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
406 FTM0_C0V = colors[ layerIndex ][0]; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
407 FTM0_C1V = colors[ layerIndex ][1]; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
408 FTM0_C2V = colors[ layerIndex ][2]; |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
409 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
410 // Iterate through each of the pages |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
411 // 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
|
412 // 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
|
413 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
|
414 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
415 // Set the register page |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
416 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
417 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
418 // Set starting address |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
419 LCD_writeControlReg( 0x10 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
420 LCD_writeControlReg( 0x00 ); |
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 // Write data |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
423 for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
424 { |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
425 layerIndex = stack_args->layers[ layer ]; |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
426 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
427 // Default to 0, if over 9 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
428 if ( layerIndex > 9 ) |
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 layerIndex = 0; |
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 // Write page of number to display |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
434 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
|
435 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
436 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
437 // Blank out rest of display |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
438 uint8_t data = 0; |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
439 for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ ) |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
440 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
441 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
|
442 { |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
443 SPI_write( &data, 1 ); |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
444 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
445 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
446 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
447 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
448 else |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
449 { |
367
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
450 // Set default backlight |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
451 FTM0_C0V = STLcdBacklightRed_define; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
452 FTM0_C1V = STLcdBacklightGreen_define; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
453 FTM0_C2V = STLcdBacklightBlue_define; |
8a6c2d410ad9
Adding color association to layers
Jacob Alexander <haata@kiibohd.com>
parents:
366
diff
changeset
|
454 |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
455 // Write default image |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
456 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
|
457 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
|
458 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
459 } |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
460 |
389
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
461 // Determines the current layer stack, and sets the LCD output accordingly |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
462 // Will only work on a master node when using the interconnect (use LCD_layerStackExact_capability instead) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
463 uint16_t LCD_layerStack_prevSize = 0; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
464 uint16_t LCD_layerStack_prevTop = 0; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
465 void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args ) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
466 { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
467 // Display capability name |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
468 if ( stateType == 0xFF && state == 0xFF ) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
469 { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
470 print("LCD_layerStack_capability()"); |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
471 return; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
472 } |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
473 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
474 // Parse the layer stack, top to bottom |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
475 extern uint16_t macroLayerIndexStack[]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
476 extern uint16_t macroLayerIndexStackSize; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
477 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
478 // Ignore if the stack size hasn't changed and the top of the stack is the same |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
479 if ( macroLayerIndexStackSize == LCD_layerStack_prevSize |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
480 && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop ) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
481 { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
482 return; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
483 } |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
484 LCD_layerStack_prevSize = macroLayerIndexStackSize; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
485 LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
486 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
487 LCD_layerStackExact_args stack_args; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
488 memset( stack_args.layers, 0, sizeof( stack_args.layers ) ); |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
489 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
490 // Use the LCD_layerStackExact_capability to set the LCD using the determined stack |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
491 // Construct argument set for capability |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
492 stack_args.numArgs = macroLayerIndexStackSize; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
493 for ( uint16_t layer = 1; layer <= macroLayerIndexStackSize; layer++ ) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
494 { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
495 stack_args.layers[ layer - 1 ] = macroLayerIndexStack[ macroLayerIndexStackSize - layer ]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
496 } |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
497 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
498 // Only deal with the interconnect if it has been compiled in |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
499 #if defined(ConnectEnabled_define) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
500 if ( Connect_master ) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
501 { |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
502 // generatedKeymap.h |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
503 extern const Capability CapabilitiesList[]; |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
504 |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
505 // Broadcast layerStackExact remote capability (0xFF is the broadcast id) |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
506 Connect_send_RemoteCapability( |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
507 0xFF, |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
508 LCD_layerStackExact_capability_index, |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
509 state, |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
510 stateType, |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
511 CapabilitiesList[ LCD_layerStackExact_capability_index ].argCount, |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
512 (uint8_t*)&stack_args |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
513 ); |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
514 } |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
515 #endif |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
516 // Call LCD_layerStackExact directly |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
517 LCD_layerStackExact_capability( state, stateType, (uint8_t*)&stack_args ); |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
518 } |
fc2c2a1e9615
Adding basic remote capabilities + UART Rx DMA buffers
Jacob Alexander <haata@kiibohd.com>
parents:
377
diff
changeset
|
519 |
366
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
520 |
95ae53b1e088
Adding basic support for LCDLayerDisplay using capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
521 |
331 | 522 // ----- CLI Command Functions ----- |
523 | |
524 void cliFunc_lcdInit( char* args ) | |
525 { | |
526 LCD_initialize(); | |
527 } | |
528 | |
529 void cliFunc_lcdTest( char* args ) | |
530 { | |
353
c6613db89cbe
Adding capability to set default image on LCD
Jacob Alexander <haata@kiibohd.com>
parents:
352
diff
changeset
|
531 // Write default image |
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
331
diff
changeset
|
532 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
|
533 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); |
331 | 534 } |
535 | |
536 void cliFunc_lcdCmd( char* args ) | |
537 { | |
538 char* curArgs; | |
539 char* arg1Ptr; | |
540 char* arg2Ptr = args; | |
541 | |
542 print( NL ); // No \r\n by default after the command is entered | |
543 | |
544 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
545 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
546 | |
547 // No args | |
548 if ( *arg1Ptr == '\0' ) | |
549 return; | |
550 | |
551 // SPI Command | |
552 uint8_t cmd = (uint8_t)numToInt( arg1Ptr ); | |
553 | |
554 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list | |
555 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
556 | |
557 // Single Arg | |
558 if ( *arg1Ptr == '\0' ) | |
559 goto cmd; | |
560 | |
561 // TODO Deal with a0 | |
562 cmd: | |
563 info_msg("Sending - "); | |
564 printHex( cmd ); | |
565 print( NL ); | |
566 LCD_writeControlReg( cmd ); | |
567 } | |
568 | |
352
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
569 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
|
570 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
575 // Colors |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
576 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
|
577 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
578 // 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
|
579 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
|
580 { |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
581 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
|
582 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
|
583 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
584 // 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
|
585 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
|
586 return; |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
587 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
588 // 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
|
589 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
|
590 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
591 |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
592 // 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
|
593 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
|
594 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
|
595 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
|
596 } |
99b567a3b1f2
Adding cli API call to set LCD backlight brightness (16 bit per channel)
Jacob Alexander <haata@kiibohd.com>
parents:
351
diff
changeset
|
597 |
354
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
598 void cliFunc_lcdDisp( char* args ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
599 { |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
600 char* curArgs; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
601 char* arg1Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
602 char* arg2Ptr = args; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
603 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
604 // First process page and starting address |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
605 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
606 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
607 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
608 // 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
|
609 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
610 return; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
611 uint8_t page = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
612 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
613 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
614 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
615 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
616 // 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
|
617 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
618 return; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
619 uint8_t address = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
620 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
621 // Set the register page |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
622 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
623 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
624 // Set starting address |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
625 LCD_writeControlReg( 0x10 | ( ( 0xF0 & address ) >> 4 ) ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
626 LCD_writeControlReg( 0x00 | ( 0x0F & address )); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
627 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
628 // Process all args |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
629 for ( ;; ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
630 { |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
631 curArgs = arg2Ptr; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
632 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
633 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
634 // 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
|
635 if ( *arg1Ptr == '\0' ) |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
636 break; |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
637 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
638 uint8_t value = numToInt( arg1Ptr ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
639 |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
640 // Write buffer to SPI |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
641 SPI_write( &value, 1 ); |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
642 } |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
643 } |
40bbbc667399
Adding API to set pixels on LCD screen
Jacob Alexander <haata@kiibohd.com>
parents:
353
diff
changeset
|
644 |