Mercurial > louis > kiibohd-controller
comparison Scan/STLcd/lcd_scan.c @ 351:38395a57cf52
Adding 16-bit brightness control to LCD backlight
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 01 Aug 2015 21:59:43 -0700 |
parents | 136e47478441 |
children | 99b567a3b1f2 |
comparison
equal
deleted
inserted
replaced
350:b02fc17eb027 | 351:38395a57cf52 |
---|---|
19 // Compiler Includes | 19 // Compiler Includes |
20 #include <Lib/ScanLib.h> | 20 #include <Lib/ScanLib.h> |
21 | 21 |
22 // Project Includes | 22 // Project Includes |
23 #include <cli.h> | 23 #include <cli.h> |
24 #include <kll.h> | |
24 #include <led.h> | 25 #include <led.h> |
25 #include <print.h> | 26 #include <print.h> |
26 | 27 |
27 // Local Includes | 28 // Local Includes |
28 #include "lcd_scan.h" | 29 #include "lcd_scan.h" |
274 // Run LCD intialization sequence | 275 // Run LCD intialization sequence |
275 LCD_initialize(); | 276 LCD_initialize(); |
276 | 277 |
277 // Setup Backlight | 278 // Setup Backlight |
278 // TODO Expose default settings | 279 // TODO Expose default settings |
279 // TODO Setup PWM | 280 SIM_SCGC6 |= SIM_SCGC6_FTM0; |
280 GPIOC_PDDR |= (1<<1); | 281 FTM0_CNT = 0; // Reset counter |
281 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | 282 |
282 GPIOC_PCOR |= (1<<1); | 283 // PWM Period |
283 GPIOC_PDDR |= (1<<2); | 284 // 16-bit maximum |
284 PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | 285 FTM0_MOD = 0xFFFF; |
285 GPIOC_PCOR |= (1<<2); | 286 |
286 GPIOC_PDDR |= (1<<3); | 287 // Set FTM to PWM output - Edge Aligned, Low-true pulses |
287 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | 288 FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01 |
288 GPIOC_PCOR |= (1<<3); | 289 FTM0_C1SC = 0x24; |
290 FTM0_C2SC = 0x24; | |
291 | |
292 // Base FTM clock selection (72 MHz system clock) | |
293 // Pre-scalar calculations | |
294 // 0 - 72 MHz - Highest power usage/best result | |
295 // 1 - 36 MHz | |
296 // 2 - 18 MHz | |
297 // 3 - 9 MHz - Slightly visible flicker (peripheral vision) | |
298 // 4 - 4 500 kHz - Visible flickering | |
299 // 5 - 2 250 kHz | |
300 // 6 - 1 125 kHz | |
301 // 7 - 562 500 Hz | |
302 // System clock, /w prescalar setting | |
303 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define ); | |
304 | |
305 /* Write frequency TODO API | |
306 FTM0_SC = 0; | |
307 FTM0_CNT = 0; | |
308 FTM0_MOD = mod; | |
309 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(prescale); | |
310 */ | |
311 | |
312 // Red | |
313 FTM0_C0V = STLcdBacklightRed_define; | |
314 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); | |
315 | |
316 // Green | |
317 FTM0_C1V = STLcdBacklightGreen_define; | |
318 PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); | |
319 | |
320 // Blue | |
321 FTM0_C2V = STLcdBacklightBlue_define; | |
322 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); | |
289 } | 323 } |
290 | 324 |
291 | 325 |
292 // LCD State processing loop | 326 // LCD State processing loop |
293 inline uint8_t LCD_scan() | 327 inline uint8_t LCD_scan() |