comparison Scan/STLcd/lcd_scan.c @ 352:99b567a3b1f2

Adding cli API call to set LCD backlight brightness (16 bit per channel)
author Jacob Alexander <haata@kiibohd.com>
date Sat, 01 Aug 2015 22:47:34 -0700
parents 38395a57cf52
children c6613db89cbe
comparison
equal deleted inserted replaced
351:38395a57cf52 352:99b567a3b1f2
47 // ----- Structs ----- 47 // ----- Structs -----
48 48
49 // ----- Function Declarations ----- 49 // ----- Function Declarations -----
50 50
51 // CLI Functions 51 // CLI Functions
52 void cliFunc_lcdCmd( char* args ); 52 void cliFunc_lcdCmd ( char* args );
53 void cliFunc_lcdInit( char* args ); 53 void cliFunc_lcdColor( char* args );
54 void cliFunc_lcdTest( char* args ); 54 void cliFunc_lcdInit ( char* args );
55 void cliFunc_lcdTest ( char* args );
55 56
56 57
57 58
58 // ----- Variables ----- 59 // ----- Variables -----
59 60
63 // Normal/Reverse Toggle State 64 // Normal/Reverse Toggle State
64 uint8_t cliNormalReverseToggleState = 0; 65 uint8_t cliNormalReverseToggleState = 0;
65 66
66 // Scan Module command dictionary 67 // Scan Module command dictionary
67 CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." ); 68 CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." );
69 CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. 0xFFF 0x1444 0x32" );
68 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); 70 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." );
69 CLIDict_Entry( lcdTest, "Test out the LCD display." ); 71 CLIDict_Entry( lcdTest, "Test out the LCD display." );
70 72
71 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { 73 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = {
72 CLIDict_Item( lcdCmd ), 74 CLIDict_Item( lcdCmd ),
75 CLIDict_Item( lcdColor ),
73 CLIDict_Item( lcdInit ), 76 CLIDict_Item( lcdInit ),
74 CLIDict_Item( lcdTest ), 77 CLIDict_Item( lcdTest ),
75 { 0, 0, 0 } // Null entry for dictionary end 78 { 0, 0, 0 } // Null entry for dictionary end
76 }; 79 };
77 80
288 FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01 291 FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01
289 FTM0_C1SC = 0x24; 292 FTM0_C1SC = 0x24;
290 FTM0_C2SC = 0x24; 293 FTM0_C2SC = 0x24;
291 294
292 // Base FTM clock selection (72 MHz system clock) 295 // Base FTM clock selection (72 MHz system clock)
296 // @ 0xFFFF period, 72 MHz / 0xFFFF * 2 = Actual period
297 // Higher pre-scalar will use the most power (also look the best)
293 // Pre-scalar calculations 298 // Pre-scalar calculations
294 // 0 - 72 MHz - Highest power usage/best result 299 // 0 - 72 MHz -> 549 Hz
295 // 1 - 36 MHz 300 // 1 - 36 MHz -> 275 Hz
296 // 2 - 18 MHz 301 // 2 - 18 MHz -> 137 Hz
297 // 3 - 9 MHz - Slightly visible flicker (peripheral vision) 302 // 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
298 // 4 - 4 500 kHz - Visible flickering 303 // 4 - 4 500 kHz -> 34 Hz (Visible flickering)
299 // 5 - 2 250 kHz 304 // 5 - 2 250 kHz -> 17 Hz
300 // 6 - 1 125 kHz 305 // 6 - 1 125 kHz -> 9 Hz
301 // 7 - 562 500 Hz 306 // 7 - 562 500 Hz -> 4 Hz
307 // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
308 // Which will reduce the brightness range
309
302 // System clock, /w prescalar setting 310 // System clock, /w prescalar setting
303 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define ); 311 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
312 // Red 313 // Red
313 FTM0_C0V = STLcdBacklightRed_define; 314 FTM0_C0V = STLcdBacklightRed_define;
314 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); 315 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4);
315 316
398 printHex( cmd ); 399 printHex( cmd );
399 print( NL ); 400 print( NL );
400 LCD_writeControlReg( cmd ); 401 LCD_writeControlReg( cmd );
401 } 402 }
402 403
404 void cliFunc_lcdColor( char* args )
405 {
406 char* curArgs;
407 char* arg1Ptr;
408 char* arg2Ptr = args;
409
410 // Colors
411 uint16_t rgb[3]; // Red, Green, Blue
412
413 // Parse integers from 3 arguments
414 for ( uint8_t color = 0; color < 3; color++ )
415 {
416 curArgs = arg2Ptr;
417 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
418
419 // Give up if not enough args given
420 if ( *arg1Ptr == '\0' )
421 return;
422
423 // Convert argument to integer
424 rgb[ color ] = numToInt( arg1Ptr );
425 }
426
427 // Set PWM channels
428 FTM0_C0V = rgb[0];
429 FTM0_C1V = rgb[1];
430 FTM0_C2V = rgb[2];
431
432 print( NL ); // No \r\n by default after the command is entered
433 }
434