comparison 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
comparison
equal deleted inserted replaced
388:3ddab7faf67d 389:fc2c2a1e9615
23 #include <cli.h> 23 #include <cli.h>
24 #include <kll_defs.h> 24 #include <kll_defs.h>
25 #include <led.h> 25 #include <led.h>
26 #include <print.h> 26 #include <print.h>
27 27
28 // Interconnect module if compiled in
29 #if defined(ConnectEnabled_define)
30 #include <connect_scan.h>
31 #endif
32
28 // Local Includes 33 // Local Includes
29 #include "lcd_scan.h" 34 #include "lcd_scan.h"
30 35
31 36
32 37
342 347
343 348
344 349
345 // ----- Capabilities ----- 350 // ----- Capabilities -----
346 351
347 uint16_t LCD_layerStack_prevSize = 0; 352 // Takes 1 8 bit length and 4 16 bit arguments, each corresponding to a layer index
348 uint16_t LCD_layerStack_prevTop = 0; 353 // Ordered from top to bottom
349 void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args ) 354 // The first argument indicates how many numbers to display (max 4), set to 0 to load default image
355 uint16_t LCD_layerStackExact[4];
356 uint8_t LCD_layerStackExact_size = 0;
357 typedef struct LCD_layerStackExact_args {
358 uint8_t numArgs;
359 uint16_t layers[4];
360 } LCD_layerStackExact_args;
361 void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t *args )
350 { 362 {
351 // Display capability name 363 // Display capability name
352 if ( stateType == 0xFF && state == 0xFF ) 364 if ( stateType == 0xFF && state == 0xFF )
353 { 365 {
354 print("LCD_layerStack_capability"); 366 print("LCD_layerStackExact_capability(num,layer1,layer2,layer3,layer4)");
355 return; 367 return;
356 } 368 }
357 369
358 // Parse the layer stack, top to bottom 370 // Read arguments
359 extern uint16_t macroLayerIndexStack[]; 371 LCD_layerStackExact_args *stack_args = (LCD_layerStackExact_args*)args;
360 extern uint16_t macroLayerIndexStackSize;
361
362 // Ignore if the stack size hasn't changed and the top of the stack is the same
363 if ( macroLayerIndexStackSize == LCD_layerStack_prevSize
364 && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )
365 {
366 return;
367 }
368 LCD_layerStack_prevSize = macroLayerIndexStackSize;
369 LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1];
370 372
371 // Number data for LCD 373 // Number data for LCD
372 const uint8_t numbers[10][128] = { 374 const uint8_t numbers[10][128] = {
373 { STLcdNumber0_define }, 375 { STLcdNumber0_define },
374 { STLcdNumber1_define }, 376 { STLcdNumber1_define },
395 { STLcdNumber8Color_define }, 397 { STLcdNumber8Color_define },
396 { STLcdNumber9Color_define }, 398 { STLcdNumber9Color_define },
397 }; 399 };
398 400
399 // Only display if there are layers active 401 // Only display if there are layers active
400 if ( macroLayerIndexStackSize > 0 ) 402 if ( stack_args->numArgs > 0 )
401 { 403 {
402 // Set the color according to the "top-of-stack" layer 404 // Set the color according to the "top-of-stack" layer
403 uint16_t layerIndex = macroLayerIndexStack[ macroLayerIndexStackSize - 1 ]; 405 uint16_t layerIndex = stack_args->layers[0];
404 FTM0_C0V = colors[ layerIndex ][0]; 406 FTM0_C0V = colors[ layerIndex ][0];
405 FTM0_C1V = colors[ layerIndex ][1]; 407 FTM0_C1V = colors[ layerIndex ][1];
406 FTM0_C2V = colors[ layerIndex ][2]; 408 FTM0_C2V = colors[ layerIndex ][2];
407 409
408 // Iterate through each of the pages 410 // Iterate through each of the pages
416 // Set starting address 418 // Set starting address
417 LCD_writeControlReg( 0x10 ); 419 LCD_writeControlReg( 0x10 );
418 LCD_writeControlReg( 0x00 ); 420 LCD_writeControlReg( 0x00 );
419 421
420 // Write data 422 // Write data
421 for ( uint16_t layer = 1; layer <= macroLayerIndexStackSize; layer++ ) 423 for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ )
422 { 424 {
423 layerIndex = macroLayerIndexStack[ macroLayerIndexStackSize - layer ]; 425 layerIndex = stack_args->layers[ layer ];
424 426
425 // Default to 0, if over 9 427 // Default to 0, if over 9
426 if ( layerIndex > 9 ) 428 if ( layerIndex > 9 )
427 { 429 {
428 layerIndex = 0; 430 layerIndex = 0;
432 SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 ); 434 SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 );
433 } 435 }
434 436
435 // Blank out rest of display 437 // Blank out rest of display
436 uint8_t data = 0; 438 uint8_t data = 0;
437 for ( uint8_t c = 0; c < 4 - macroLayerIndexStackSize; c++ ) 439 for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ )
438 { 440 {
439 for ( uint8_t byte = 0; byte < 32; byte++ ) 441 for ( uint8_t byte = 0; byte < 32; byte++ )
440 { 442 {
441 SPI_write( &data, 1 ); 443 SPI_write( &data, 1 );
442 } 444 }
454 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) 456 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
455 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); 457 LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN );
456 } 458 }
457 } 459 }
458 460
461 // Determines the current layer stack, and sets the LCD output accordingly
462 // Will only work on a master node when using the interconnect (use LCD_layerStackExact_capability instead)
463 uint16_t LCD_layerStack_prevSize = 0;
464 uint16_t LCD_layerStack_prevTop = 0;
465 void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args )
466 {
467 // Display capability name
468 if ( stateType == 0xFF && state == 0xFF )
469 {
470 print("LCD_layerStack_capability()");
471 return;
472 }
473
474 // Parse the layer stack, top to bottom
475 extern uint16_t macroLayerIndexStack[];
476 extern uint16_t macroLayerIndexStackSize;
477
478 // Ignore if the stack size hasn't changed and the top of the stack is the same
479 if ( macroLayerIndexStackSize == LCD_layerStack_prevSize
480 && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )
481 {
482 return;
483 }
484 LCD_layerStack_prevSize = macroLayerIndexStackSize;
485 LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1];
486
487 LCD_layerStackExact_args stack_args;
488 memset( stack_args.layers, 0, sizeof( stack_args.layers ) );
489
490 // Use the LCD_layerStackExact_capability to set the LCD using the determined stack
491 // Construct argument set for capability
492 stack_args.numArgs = macroLayerIndexStackSize;
493 for ( uint16_t layer = 1; layer <= macroLayerIndexStackSize; layer++ )
494 {
495 stack_args.layers[ layer - 1 ] = macroLayerIndexStack[ macroLayerIndexStackSize - layer ];
496 }
497
498 // Only deal with the interconnect if it has been compiled in
499 #if defined(ConnectEnabled_define)
500 if ( Connect_master )
501 {
502 // generatedKeymap.h
503 extern const Capability CapabilitiesList[];
504
505 // Broadcast layerStackExact remote capability (0xFF is the broadcast id)
506 Connect_send_RemoteCapability(
507 0xFF,
508 LCD_layerStackExact_capability_index,
509 state,
510 stateType,
511 CapabilitiesList[ LCD_layerStackExact_capability_index ].argCount,
512 (uint8_t*)&stack_args
513 );
514 }
515 #endif
516 // Call LCD_layerStackExact directly
517 LCD_layerStackExact_capability( state, stateType, (uint8_t*)&stack_args );
518 }
519
459 520
460 521
461 // ----- CLI Command Functions ----- 522 // ----- CLI Command Functions -----
462 523
463 void cliFunc_lcdInit( char* args ) 524 void cliFunc_lcdInit( char* args )