X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Scan%2FSTLcd%2Flcd_scan.c;h=a7d7d44a09c9fbeb09520f65951bd1cb93871e43;hb=0013d7a4f31d35ad054369037e20b683085c6116;hp=b5123c97334d5082515cc932876867b06b91192d;hpb=a6657c8aed1cd73fd361f93c0f8506e281e7c5e0;p=kiibohd-controller.git diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index b5123c9..a7d7d44 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -21,6 +21,7 @@ // Project Includes #include +#include #include #include @@ -32,6 +33,7 @@ // ----- Defines ----- #define LCD_TOTAL_VISIBLE_PAGES 4 +#define LCD_TOTAL_PAGES 9 #define LCD_PAGE_LEN 128 @@ -48,14 +50,19 @@ // ----- Function Declarations ----- // CLI Functions -void cliFunc_lcdCmd( char* args ); -void cliFunc_lcdInit( char* args ); -void cliFunc_lcdTest( char* args ); +void cliFunc_lcdCmd ( char* args ); +void cliFunc_lcdColor( char* args ); +void cliFunc_lcdDisp ( char* args ); +void cliFunc_lcdInit ( char* args ); +void cliFunc_lcdTest ( char* args ); // ----- Variables ----- +// Default Image - Displays on startup +const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; + // Full Toggle State uint8_t cliFullToggleState = 0; @@ -64,11 +71,15 @@ uint8_t cliNormalReverseToggleState = 0; // Scan Module command dictionary CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." ); +CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. 0xFFF 0x1444 0x32" ); +CLIDict_Entry( lcdDisp, "Write byte(s) to given page starting at given address. i.e. 0x1 0x5 0xFF 0x00" ); CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); CLIDict_Entry( lcdTest, "Test out the LCD display." ); CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdCmd ), + CLIDict_Item( lcdColor ), + CLIDict_Item( lcdDisp ), CLIDict_Item( lcdInit ), CLIDict_Item( lcdTest ), { 0, 0, 0 } // Null entry for dictionary end @@ -197,7 +208,7 @@ inline void LCD_clearPage( uint8_t page ) void LCD_clear() { // Setup each page - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + for ( uint8_t page = 0; page < LCD_TOTAL_PAGES; page++ ) { LCD_clearPage( page ); } @@ -258,7 +269,6 @@ inline void LCD_setup() // Initialize SPI SPI_setup(); - // Setup Register Control Signal (A0) // Start in display register mode (1) GPIOC_PDDR |= (1<<7); @@ -274,14 +284,59 @@ inline void LCD_setup() // Run LCD intialization sequence LCD_initialize(); + + // Write default image to LCD + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + LCD_writeDisplayReg( page, (uint8_t*)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); + + // Setup Backlight + SIM_SCGC6 |= SIM_SCGC6_FTM0; + FTM0_CNT = 0; // Reset counter + + // PWM Period + // 16-bit maximum + FTM0_MOD = 0xFFFF; + + // Set FTM to PWM output - Edge Aligned, Low-true pulses + FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01 + FTM0_C1SC = 0x24; + FTM0_C2SC = 0x24; + + // Base FTM clock selection (72 MHz system clock) + // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period + // Higher pre-scalar will use the most power (also look the best) + // Pre-scalar calculations + // 0 - 72 MHz -> 549 Hz + // 1 - 36 MHz -> 275 Hz + // 2 - 18 MHz -> 137 Hz + // 3 - 9 MHz -> 69 Hz (Slightly visible flicker) + // 4 - 4 500 kHz -> 34 Hz (Visible flickering) + // 5 - 2 250 kHz -> 17 Hz + // 6 - 1 125 kHz -> 9 Hz + // 7 - 562 500 Hz -> 4 Hz + // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced + // Which will reduce the brightness range + + // System clock, /w prescalar setting + FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define ); + + // Red + FTM0_C0V = STLcdBacklightRed_define; + PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); + + // Green + FTM0_C1V = STLcdBacklightGreen_define; + PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); + + // Blue + FTM0_C2V = STLcdBacklightBlue_define; + PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); } // LCD State processing loop inline uint8_t LCD_scan() { - // NOP - Screen Refresh - //LCD_writeControlReg( 0xE3 ); return 0; } @@ -291,34 +346,14 @@ inline uint8_t LCD_scan() void cliFunc_lcdInit( char* args ) { - print( NL ); // No \r\n by default after the command is entered LCD_initialize(); } void cliFunc_lcdTest( char* args ) { - print( NL ); // No \r\n by default after the command is entered - - //LCD_initialize(); - // Test pattern - uint8_t pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - - -uint8_t logo[] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - //uint8_t pattern[] = { 0xFF, 0x00, 0x96, 0xFF, 0x00, 0xFF, 0x00 }; - - // Write to page D0 - //LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) ); - + // Write default image for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) - { - LCD_writeDisplayReg( page, &logo[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); - } + LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); } void cliFunc_lcdCmd( char* args ) @@ -354,3 +389,79 @@ cmd: LCD_writeControlReg( cmd ); } +void cliFunc_lcdColor( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + + // Colors + uint16_t rgb[3]; // Red, Green, Blue + + // Parse integers from 3 arguments + for ( uint8_t color = 0; color < 3; color++ ) + { + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Give up if not enough args given + if ( *arg1Ptr == '\0' ) + return; + + // Convert argument to integer + rgb[ color ] = numToInt( arg1Ptr ); + } + + // Set PWM channels + FTM0_C0V = rgb[0]; + FTM0_C1V = rgb[1]; + FTM0_C2V = rgb[2]; +} + +void cliFunc_lcdDisp( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + + // First process page and starting address + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + uint8_t page = numToInt( arg1Ptr ); + + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + uint8_t address = numToInt( arg1Ptr ); + + // Set the register page + LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); + + // Set starting address + LCD_writeControlReg( 0x10 | ( ( 0xF0 & address ) >> 4 ) ); + LCD_writeControlReg( 0x00 | ( 0x0F & address )); + + // Process all args + for ( ;; ) + { + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + break; + + uint8_t value = numToInt( arg1Ptr ); + + // Write buffer to SPI + SPI_write( &value, 1 ); + } +} +