// Project Includes
#include <cli.h>
-#include <kll.h>
+#include <kll_defs.h>
#include <led.h>
#include <print.h>
+// Interconnect module if compiled in
+#if defined(ConnectEnabled_define)
+#include <connect_scan.h>
+#endif
+
// Local Includes
#include "lcd_scan.h"
// ----- Defines -----
#define LCD_TOTAL_VISIBLE_PAGES 4
+#define LCD_TOTAL_PAGES 9
#define LCD_PAGE_LEN 128
// CLI Functions
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;
// 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
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 );
}
// 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
- // TODO Expose default settings
SIM_SCGC6 |= SIM_SCGC6_FTM0;
FTM0_CNT = 0; // Reset counter
FTM0_C2SC = 0x24;
// Base FTM clock selection (72 MHz system clock)
- // @ 0xFFFF period, 72 MHz / 0xFFFF * 2 = Actual period
+ // @ 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
// LCD State processing loop
inline uint8_t LCD_scan()
{
- // NOP - Screen Refresh
- //LCD_writeControlReg( 0xE3 );
return 0;
}
-// ----- CLI Command Functions -----
+// ----- Capabilities -----
-void cliFunc_lcdInit( char* args )
+// Takes 1 8 bit length and 4 16 bit arguments, each corresponding to a layer index
+// Ordered from top to bottom
+// The first argument indicates how many numbers to display (max 4), set to 0 to load default image
+uint16_t LCD_layerStackExact[4];
+uint8_t LCD_layerStackExact_size = 0;
+typedef struct LCD_layerStackExact_args {
+ uint8_t numArgs;
+ uint16_t layers[4];
+} LCD_layerStackExact_args;
+void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t *args )
{
- print( NL ); // No \r\n by default after the command is entered
- LCD_initialize();
+ // Display capability name
+ if ( stateType == 0xFF && state == 0xFF )
+ {
+ print("LCD_layerStackExact_capability(num,layer1,layer2,layer3,layer4)");
+ return;
+ }
+
+ // Read arguments
+ LCD_layerStackExact_args *stack_args = (LCD_layerStackExact_args*)args;
+
+ // Number data for LCD
+ const uint8_t numbers[10][128] = {
+ { STLcdNumber0_define },
+ { STLcdNumber1_define },
+ { STLcdNumber2_define },
+ { STLcdNumber3_define },
+ { STLcdNumber4_define },
+ { STLcdNumber5_define },
+ { STLcdNumber6_define },
+ { STLcdNumber7_define },
+ { STLcdNumber8_define },
+ { STLcdNumber9_define },
+ };
+
+ // Color data for numbers
+ const uint16_t colors[10][3] = {
+ { STLcdNumber0Color_define },
+ { STLcdNumber1Color_define },
+ { STLcdNumber2Color_define },
+ { STLcdNumber3Color_define },
+ { STLcdNumber4Color_define },
+ { STLcdNumber5Color_define },
+ { STLcdNumber6Color_define },
+ { STLcdNumber7Color_define },
+ { STLcdNumber8Color_define },
+ { STLcdNumber9Color_define },
+ };
+
+ // Only display if there are layers active
+ if ( stack_args->numArgs > 0 )
+ {
+ // Set the color according to the "top-of-stack" layer
+ uint16_t layerIndex = stack_args->layers[0];
+ FTM0_C0V = colors[ layerIndex ][0];
+ FTM0_C1V = colors[ layerIndex ][1];
+ FTM0_C2V = colors[ layerIndex ][2];
+
+ // Iterate through each of the pages
+ // XXX Many of the values here are hard-coded
+ // Eventually a proper font rendering engine should take care of things like this... -HaaTa
+ for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
+ {
+ // Set the register page
+ LCD_writeControlReg( 0xB0 | ( 0x0F & page ) );
+
+ // Set starting address
+ LCD_writeControlReg( 0x10 );
+ LCD_writeControlReg( 0x00 );
+
+ // Write data
+ for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ )
+ {
+ layerIndex = stack_args->layers[ layer ];
+
+ // Default to 0, if over 9
+ if ( layerIndex > 9 )
+ {
+ layerIndex = 0;
+ }
+
+ // Write page of number to display
+ SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 );
+ }
+
+ // Blank out rest of display
+ uint8_t data = 0;
+ for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ )
+ {
+ for ( uint8_t byte = 0; byte < 32; byte++ )
+ {
+ SPI_write( &data, 1 );
+ }
+ }
+ }
+ }
+ else
+ {
+ // Set default backlight
+ FTM0_C0V = STLcdBacklightRed_define;
+ FTM0_C1V = STLcdBacklightGreen_define;
+ FTM0_C2V = STLcdBacklightBlue_define;
+
+ // Write default image
+ for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
+ LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN );
+ }
}
-void cliFunc_lcdTest( char* args )
+// Determines the current layer stack, and sets the LCD output accordingly
+// Will only work on a master node when using the interconnect (use LCD_layerStackExact_capability instead)
+uint16_t LCD_layerStack_prevSize = 0;
+uint16_t LCD_layerStack_prevTop = 0;
+void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args )
{
- print( NL ); // No \r\n by default after the command is entered
+ // Display capability name
+ if ( stateType == 0xFF && state == 0xFF )
+ {
+ print("LCD_layerStack_capability()");
+ return;
+ }
- //LCD_initialize();
- // Test pattern
- uint8_t pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+ // Parse the layer stack, top to bottom
+ extern uint16_t macroLayerIndexStack[];
+ extern uint16_t macroLayerIndexStackSize;
+ // Ignore if the stack size hasn't changed and the top of the stack is the same
+ if ( macroLayerIndexStackSize == LCD_layerStack_prevSize
+ && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )
+ {
+ return;
+ }
+ LCD_layerStack_prevSize = macroLayerIndexStackSize;
+ LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1];
-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 };
+ LCD_layerStackExact_args stack_args;
+ memset( stack_args.layers, 0, sizeof( stack_args.layers ) );
- // Write to page D0
- //LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) );
+ // Use the LCD_layerStackExact_capability to set the LCD using the determined stack
+ // Construct argument set for capability
+ stack_args.numArgs = macroLayerIndexStackSize;
+ for ( uint16_t layer = 1; layer <= macroLayerIndexStackSize; layer++ )
+ {
+ stack_args.layers[ layer - 1 ] = macroLayerIndexStack[ macroLayerIndexStackSize - layer ];
+ }
- for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
+ // Only deal with the interconnect if it has been compiled in
+#if defined(ConnectEnabled_define)
+ if ( Connect_master )
{
- LCD_writeDisplayReg( page, &logo[page * LCD_PAGE_LEN], LCD_PAGE_LEN );
+ // generatedKeymap.h
+ extern const Capability CapabilitiesList[];
+
+ // Broadcast layerStackExact remote capability (0xFF is the broadcast id)
+ Connect_send_RemoteCapability(
+ 0xFF,
+ LCD_layerStackExact_capability_index,
+ state,
+ stateType,
+ CapabilitiesList[ LCD_layerStackExact_capability_index ].argCount,
+ (uint8_t*)&stack_args
+ );
}
+#endif
+ // Call LCD_layerStackExact directly
+ LCD_layerStackExact_capability( state, stateType, (uint8_t*)&stack_args );
+}
+
+
+
+// ----- CLI Command Functions -----
+
+void cliFunc_lcdInit( char* args )
+{
+ LCD_initialize();
+}
+
+void cliFunc_lcdTest( char* args )
+{
+ // Write default image
+ for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
+ LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN );
}
void cliFunc_lcdCmd( char* args )
FTM0_C0V = rgb[0];
FTM0_C1V = rgb[1];
FTM0_C2V = rgb[2];
+}
- print( NL ); // No \r\n by default after the command is entered
+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 );
+ }
}