2016-01-04 02:37:22 +00:00
|
|
|
/* Copyright (C) 2014-2016 by Jacob Alexander
|
2015-03-22 00:12:41 +00:00
|
|
|
*
|
|
|
|
* This file is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this file. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ----- Includes -----
|
|
|
|
|
|
|
|
// Compiler Includes
|
|
|
|
#include <Lib/ScanLib.h>
|
|
|
|
|
|
|
|
// Project Includes
|
|
|
|
#include <cli.h>
|
2015-08-04 04:42:01 +00:00
|
|
|
#include <kll_defs.h>
|
2015-03-22 00:12:41 +00:00
|
|
|
#include <led.h>
|
|
|
|
#include <print.h>
|
2016-01-03 18:21:10 +00:00
|
|
|
#include <pixel.h>
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2015-10-16 17:02:01 +00:00
|
|
|
// Interconnect module if compiled in
|
|
|
|
#if defined(ConnectEnabled_define)
|
|
|
|
#include <connect_scan.h>
|
|
|
|
#endif
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
// Local Includes
|
2016-01-03 18:21:10 +00:00
|
|
|
#include "i2c.h"
|
2015-03-22 00:12:41 +00:00
|
|
|
#include "led_scan.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----- Defines -----
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// TODO Make this a kll define
|
|
|
|
// I2C transfers are more efficient if all 144 don't have to be updated
|
|
|
|
// (and most implementations don't use all the channels)
|
|
|
|
// Ergodox tested @ 83fps /w 38
|
|
|
|
// Whitefox tested @ 45fps /w 71
|
2015-11-12 09:21:32 +00:00
|
|
|
#define LED_BufferLength 144
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
#define LED_EnableBufferLength 18
|
|
|
|
#define LED_FrameBuffersMax 4
|
|
|
|
#define LED_TotalChannels (LED_BufferLength * ISSI_Chips_define)
|
2015-11-12 09:21:32 +00:00
|
|
|
|
|
|
|
// ISSI Addresses
|
|
|
|
// IS31FL3731 (max 4 channels per bus)
|
|
|
|
#if 1
|
|
|
|
#define ISSI_Ch1 0xE8
|
|
|
|
#define ISSI_Ch2 0xEA
|
|
|
|
#define ISSI_Ch3 0xEC
|
|
|
|
#define ISSI_Ch4 0xEE
|
|
|
|
|
|
|
|
// IS31FL3732 (max 16 channels per bus)
|
|
|
|
#else
|
|
|
|
#define ISSI_Ch1 0xB0
|
|
|
|
#define ISSI_Ch2 0xB2
|
|
|
|
#define ISSI_Ch3 0xB4
|
|
|
|
#define ISSI_Ch4 0xB6
|
|
|
|
#endif
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// ----- Macros -----
|
|
|
|
|
|
|
|
#define LED_MaskDefine(ch) \
|
|
|
|
{ \
|
|
|
|
ISSI_Ch##ch, /* I2C address */ \
|
|
|
|
0x00, /* Starting register address */ \
|
|
|
|
{ ISSILedMask##ch##_define }, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LED_BrightnessDefine(ch) \
|
|
|
|
{ \
|
|
|
|
ISSI_Ch##ch, /* I2C address */ \
|
|
|
|
0x24, /* Starting register address */ \
|
|
|
|
{ ISSILedBrightness##ch##_define }, \
|
|
|
|
}
|
2015-10-16 17:02:01 +00:00
|
|
|
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// ----- Structs -----
|
|
|
|
|
|
|
|
typedef struct LED_Buffer {
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t i2c_addr;
|
|
|
|
uint16_t reg_addr;
|
|
|
|
uint16_t buffer[LED_BufferLength];
|
2015-03-22 00:12:41 +00:00
|
|
|
} LED_Buffer;
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
typedef struct LED_EnableBuffer {
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t i2c_addr;
|
|
|
|
uint16_t reg_addr;
|
|
|
|
uint16_t buffer[LED_EnableBufferLength];
|
2015-11-12 09:21:32 +00:00
|
|
|
} LED_EnableBuffer;
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----- Function Declarations -----
|
|
|
|
|
|
|
|
// CLI Functions
|
2016-01-03 18:21:10 +00:00
|
|
|
void cliFunc_i2cSend ( char* args );
|
|
|
|
void cliFunc_ledCtrl ( char* args );
|
2016-01-04 00:16:41 +00:00
|
|
|
void cliFunc_ledReset ( char* args );
|
|
|
|
void cliFunc_ledSpeed ( char* args );
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----- Variables -----
|
|
|
|
|
|
|
|
// Scan Module command dictionary
|
|
|
|
CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
|
2015-10-10 05:28:31 +00:00
|
|
|
CLIDict_Entry( ledCtrl, "Basic LED control. Args: <mode> <amount> [<index>]" );
|
2016-01-04 00:16:41 +00:00
|
|
|
CLIDict_Entry( ledReset, "Reset ISSI chips." );
|
|
|
|
CLIDict_Entry( ledSpeed, "ISSI frame rate 0-63, 1 is fastest. f - display fps" );
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
|
|
|
|
CLIDict_Item( i2cSend ),
|
2015-10-10 05:28:31 +00:00
|
|
|
CLIDict_Item( ledCtrl ),
|
2016-01-04 00:16:41 +00:00
|
|
|
CLIDict_Item( ledReset ),
|
|
|
|
CLIDict_Item( ledSpeed ),
|
2015-03-22 00:12:41 +00:00
|
|
|
{ 0, 0, 0 } // Null entry for dictionary end
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
volatile LED_Buffer LED_pageBuffer[ ISSI_Chips_define ];
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
uint8_t LED_FrameBuffersReady; // Starts at maximum, reset on interrupt from ISSI
|
|
|
|
volatile uint8_t LED_FrameBufferReset; // INTB interrupt received, reset available buffer count when ready
|
|
|
|
uint8_t LED_FrameBufferPage; // Current page of the buffer
|
|
|
|
uint8_t LED_FrameBufferStart; // Whether or not a start signal can be sent
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
uint8_t LED_displayFPS; // Display fps to cli
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Enable mask and default brightness for ISSI chip channel
|
|
|
|
const LED_EnableBuffer LED_ledEnableMask[ISSI_Chips_define] = {
|
|
|
|
LED_MaskDefine( 1 ),
|
|
|
|
#if ISSI_Chips_define >= 2
|
|
|
|
LED_MaskDefine( 2 ),
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 3
|
|
|
|
LED_MaskDefine( 3 ),
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 4
|
|
|
|
LED_MaskDefine( 4 ),
|
|
|
|
#endif
|
2015-04-14 07:40:48 +00:00
|
|
|
};
|
|
|
|
|
2015-08-02 23:28:21 +00:00
|
|
|
// Default LED brightness
|
2015-11-12 09:21:32 +00:00
|
|
|
const LED_Buffer LED_defaultBrightness[ISSI_Chips_define] = {
|
|
|
|
LED_BrightnessDefine( 1 ),
|
|
|
|
#if ISSI_Chips_define >= 2
|
|
|
|
LED_BrightnessDefine( 2 ),
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 3
|
|
|
|
LED_BrightnessDefine( 3 ),
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 4
|
|
|
|
LED_BrightnessDefine( 4 ),
|
|
|
|
#endif
|
2015-03-22 00:12:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
#if ISSI_Chips_define >= 5
|
|
|
|
#error "Invalid number of ISSI Chips"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// ----- Interrupt Functions -----
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
void portb_isr()
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Check for ISSI INTB IRQ
|
|
|
|
if ( PORTB_ISFR & (1 << 17) )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Set frame buffer replenish condition
|
|
|
|
LED_FrameBufferReset = 1;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Clear IRQ
|
|
|
|
PORTB_ISFR |= (1 << 17);
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----- Functions -----
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
void LED_zeroPages( uint8_t addr, uint8_t startPage, uint8_t numPages, uint8_t startReg, uint8_t endReg )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Clear Page
|
2015-03-22 00:12:41 +00:00
|
|
|
// Max length of a page + chip id + reg start
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t clearPage[2 + 0xB4] = { 0 };
|
|
|
|
clearPage[0] = addr;
|
|
|
|
clearPage[1] = startReg;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// Iterate through given pages, zero'ing out the given register regions
|
|
|
|
for ( uint8_t page = startPage; page < startPage + numPages; page++ )
|
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Page Setup
|
|
|
|
uint16_t pageSetup[] = { addr, 0xFD, page };
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// Setup page
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
2015-03-22 00:12:41 +00:00
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// Zero out page
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( clearPage, 2 + endReg - startReg ) == -1 )
|
2015-03-22 00:12:41 +00:00
|
|
|
delay(1);
|
|
|
|
}
|
2016-01-03 18:21:10 +00:00
|
|
|
|
|
|
|
// Wait until finished zero'ing
|
|
|
|
while ( i2c_busy() )
|
|
|
|
delay(1);
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
void LED_sendPage( uint8_t addr, uint16_t *buffer, uint32_t len, uint8_t page )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
/*
|
|
|
|
info_msg("I2C Send Page Addr: ");
|
|
|
|
printHex( addr );
|
|
|
|
print(" Len: ");
|
|
|
|
printHex( len );
|
|
|
|
print(" Page: ");
|
|
|
|
printHex( page );
|
|
|
|
print( NL );
|
|
|
|
*/
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
// Page Setup
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t pageSetup[] = { addr, 0xFD, page };
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// Setup page
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
2015-03-22 00:12:41 +00:00
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// Write page to I2C Tx Buffer
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( buffer, len ) == -1 )
|
2015-03-22 00:12:41 +00:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Write register on all ISSI chips
|
|
|
|
// Prepare pages first, then attempt write register with a minimal delay between chips
|
|
|
|
void LED_syncReg( uint8_t reg, uint8_t val, uint8_t page )
|
|
|
|
{
|
|
|
|
uint16_t pageSetup[] = { 0, 0xFD, page };
|
|
|
|
|
|
|
|
// Setup each of the pages
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
pageSetup[0] = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
|
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reg Write Setup
|
|
|
|
uint16_t writeData[] = { 0, reg, val };
|
|
|
|
|
|
|
|
// Write to all the registers
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
writeData[0] = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
|
|
|
|
// Delay very little to help with synchronization
|
|
|
|
while ( i2c_send( writeData, sizeof( writeData ) / 2 ) == -1 )
|
|
|
|
delayMicroseconds(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delay until written
|
|
|
|
while ( i2c_busy() )
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Write address
|
|
|
|
void LED_writeReg( uint8_t addr, uint8_t reg, uint8_t val, uint8_t page )
|
2015-04-14 07:40:48 +00:00
|
|
|
{
|
|
|
|
// Page Setup
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t pageSetup[] = { addr, 0xFD, page };
|
2015-04-14 07:40:48 +00:00
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
// Reg Write Setup
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t writeData[] = { addr, reg, val };
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-04-14 07:40:48 +00:00
|
|
|
// Setup page
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
2015-04-14 07:40:48 +00:00
|
|
|
delay(1);
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Write register
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( writeData, sizeof( writeData ) / 2 ) == -1 )
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// Delay until written
|
|
|
|
while ( i2c_busy() )
|
2015-04-14 07:40:48 +00:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Read address
|
2016-01-03 18:21:10 +00:00
|
|
|
// TODO Not working?
|
|
|
|
uint8_t LED_readReg( uint8_t addr, uint8_t reg, uint8_t page )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2015-10-10 05:28:31 +00:00
|
|
|
// Software shutdown must be enabled to read registers
|
2015-11-12 09:21:32 +00:00
|
|
|
LED_writeReg( addr, 0x0A, 0x00, 0x0B );
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
// Page Setup
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t pageSetup[] = { addr, 0xFD, page };
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// Setup page
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
2015-03-22 00:12:41 +00:00
|
|
|
delay(1);
|
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
// Register Setup
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t regSetup[] = { addr, reg };
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Configure register
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_send( regSetup, sizeof( regSetup ) / 2 ) == -1 )
|
2015-11-12 09:21:32 +00:00
|
|
|
delay(1);
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Register Read Command
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t regReadCmd[] = { addr | 0x1, I2C_READ };
|
|
|
|
uint8_t recv_data;
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// Request single register byte
|
2016-01-03 18:21:10 +00:00
|
|
|
while ( i2c_read( regReadCmd, sizeof( regReadCmd ) / 2, &recv_data ) == -1 )
|
2015-11-12 09:21:32 +00:00
|
|
|
delay(1);
|
2015-10-10 05:28:31 +00:00
|
|
|
|
|
|
|
// Disable software shutdown
|
2015-11-12 09:21:32 +00:00
|
|
|
LED_writeReg( addr, 0x0A, 0x01, 0x0B );
|
2016-01-03 18:21:10 +00:00
|
|
|
|
|
|
|
return recv_data;
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
void LED_reset()
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Reset frame buffer used count
|
|
|
|
LED_FrameBuffersReady = LED_FrameBuffersMax;
|
|
|
|
|
|
|
|
// Starting page for the buffers
|
|
|
|
LED_FrameBufferPage = 4;
|
|
|
|
|
|
|
|
// Initially do not allow autoplay to restart
|
|
|
|
LED_FrameBufferStart = 0;
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Disable FPS by default
|
|
|
|
LED_displayFPS = 0;
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
// Clear LED Pages
|
|
|
|
// Enable LEDs based upon mask
|
2015-11-12 09:21:32 +00:00
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_zeroPages( addr, 0x00, 8, 0x00, 0xB4 ); // LED Registers
|
2016-01-03 18:21:10 +00:00
|
|
|
|
|
|
|
// For each page
|
|
|
|
for ( uint8_t pg = 0; pg < LED_FrameBuffersMax * 2; pg++ )
|
|
|
|
{
|
|
|
|
LED_sendPage(
|
|
|
|
addr,
|
|
|
|
(uint16_t*)&LED_ledEnableMask[ ch ],
|
|
|
|
sizeof( LED_EnableBuffer ) / 2,
|
|
|
|
pg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup ISSI auto frame play, but do not start yet
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
// CNS 1 loop, FNS 4 frames - 0x14
|
|
|
|
LED_writeReg( addr, 0x02, 0x14, 0x0B );
|
|
|
|
|
|
|
|
// Default refresh speed - TxA
|
|
|
|
// T is typically 11ms
|
|
|
|
// A is 1 to 64 (where 0 is 64)
|
|
|
|
LED_writeReg( addr, 0x03, ISSI_AnimationSpeed_define, 0x0B );
|
|
|
|
|
|
|
|
// Set MODE to Auto Frame Play
|
|
|
|
LED_writeReg( addr, 0x00, 0x08, 0x0B );
|
2015-11-12 09:21:32 +00:00
|
|
|
}
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-02-22 03:56:52 +00:00
|
|
|
// Do not disable software shutdown of ISSI chip unless current is high enough
|
|
|
|
// Require at least 150 mA
|
|
|
|
// May be enabled/disabled at a later time
|
|
|
|
if ( Output_current_available() >= 150 )
|
2015-11-12 09:21:32 +00:00
|
|
|
{
|
2016-02-22 03:56:52 +00:00
|
|
|
// Disable Software shutdown of ISSI chip
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_writeReg( addr, 0x0A, 0x01, 0x0B );
|
|
|
|
}
|
2015-11-12 09:21:32 +00:00
|
|
|
}
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Setup
|
|
|
|
inline void LED_setup()
|
|
|
|
{
|
|
|
|
// Register Scan CLI dictionary
|
|
|
|
CLI_registerDictionary( ledCLIDict, ledCLIDictName );
|
|
|
|
|
|
|
|
// Initialize I2C
|
|
|
|
i2c_setup();
|
|
|
|
|
|
|
|
// Setup LED_pageBuffer addresses and brightness section
|
|
|
|
LED_pageBuffer[0].i2c_addr = ISSI_Ch1;
|
|
|
|
LED_pageBuffer[0].reg_addr = 0x24;
|
|
|
|
#if ISSI_Chips_define >= 2
|
|
|
|
LED_pageBuffer[1].i2c_addr = ISSI_Ch2;
|
|
|
|
LED_pageBuffer[1].reg_addr = 0x24;
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 3
|
|
|
|
LED_pageBuffer[2].i2c_addr = ISSI_Ch3;
|
|
|
|
LED_pageBuffer[2].reg_addr = 0x24;
|
|
|
|
#endif
|
|
|
|
#if ISSI_Chips_define >= 4
|
|
|
|
LED_pageBuffer[3].i2c_addr = ISSI_Ch4;
|
|
|
|
LED_pageBuffer[3].reg_addr = 0x24;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Enable Hardware shutdown (pull low)
|
|
|
|
GPIOB_PDDR |= (1<<16);
|
|
|
|
PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
|
|
|
GPIOB_PCOR |= (1<<16);
|
|
|
|
|
|
|
|
// Zero out Frame Registers
|
|
|
|
// This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_zeroPages( addr, 0x0B, 1, 0x00, 0x0C ); // Control Registers
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable Hardware shutdown of ISSI chip (pull high)
|
|
|
|
GPIOB_PSOR |= (1<<16);
|
|
|
|
|
|
|
|
// Prepare pin to read INTB interrupt of ISSI chip (Active Low)
|
|
|
|
// Enable interrupt to detect falling edge
|
|
|
|
// Uses external pullup resistor
|
|
|
|
GPIOB_PDDR |= ~(1<<17);
|
|
|
|
PORTB_PCR17 = PORT_PCR_IRQC(0xA) | PORT_PCR_PFE | PORT_PCR_MUX(1);
|
|
|
|
LED_FrameBufferReset = 0; // Clear frame buffer reset condition for ISSI
|
|
|
|
|
|
|
|
// Enable PORTB interrupt
|
|
|
|
NVIC_ENABLE_IRQ( IRQ_PORTB );
|
|
|
|
|
|
|
|
// Reset LED sequencing
|
|
|
|
LED_reset();
|
|
|
|
}
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// LED Linked Send
|
|
|
|
// Call-back for i2c write when updating led display
|
|
|
|
uint8_t LED_chipSend;
|
|
|
|
void LED_linkedSend()
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Check if we've updated all the ISSI chips for this frame
|
|
|
|
if ( LED_chipSend >= ISSI_Chips_define )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Increment the buffer page
|
|
|
|
// And reset if necessary
|
|
|
|
if ( ++LED_FrameBufferPage >= LED_FrameBuffersMax * 2 )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_FrameBufferPage = 0;
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Now ready to update the frame buffer
|
|
|
|
Pixel_FrameState = FrameState_Update;
|
|
|
|
return;
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Update ISSI Frame State
|
|
|
|
Pixel_FrameState = FrameState_Sending;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Debug
|
|
|
|
/*
|
|
|
|
dbug_msg("Linked Send: chip(");
|
|
|
|
printHex( LED_chipSend );
|
|
|
|
print(") frame(");
|
|
|
|
printHex( LED_FrameBufferPage );
|
|
|
|
print(") addr(");
|
|
|
|
printHex( LED_pageBuffer[0].i2c_addr );
|
|
|
|
print(") reg(");
|
|
|
|
printHex( LED_pageBuffer[0].reg_addr );
|
|
|
|
print(") len(");
|
|
|
|
printHex( sizeof( LED_Buffer ) / 2 );
|
|
|
|
print(") data[]" NL "(");
|
|
|
|
for ( uint8_t c = 0; c < 9; c++ )
|
|
|
|
//for ( uint8_t c = 0; c < sizeof( LED_Buffer ) / 2 - 2; c++ )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
printHex( LED_pageBuffer[0].buffer[c] );
|
|
|
|
print(" ");
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
2016-01-03 18:21:10 +00:00
|
|
|
print(")" NL);
|
|
|
|
*/
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Send, and recursively call this function when finished
|
|
|
|
while ( i2c_send_sequence(
|
|
|
|
(uint16_t*)&LED_pageBuffer[ LED_chipSend ],
|
|
|
|
sizeof( LED_Buffer ) / 2,
|
|
|
|
0,
|
|
|
|
LED_linkedSend,
|
|
|
|
0
|
|
|
|
) == -1 )
|
|
|
|
delay(1);
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Increment chip position
|
|
|
|
LED_chipSend++;
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// LED State processing loop
|
|
|
|
uint32_t LED_timePrev = 0;
|
2016-02-22 03:56:52 +00:00
|
|
|
unsigned int LED_currentEvent = 0;
|
2016-01-03 18:21:10 +00:00
|
|
|
inline void LED_scan()
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-02-22 03:56:52 +00:00
|
|
|
// Check for current change event
|
|
|
|
if ( LED_currentEvent )
|
|
|
|
{
|
|
|
|
// TODO dim LEDs in low power mode instead of shutting off
|
|
|
|
if ( LED_currentEvent < 150 )
|
|
|
|
{
|
|
|
|
// Enable Software shutdown of ISSI chip
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_writeReg( addr, 0x0A, 0x00, 0x0B );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Disable Software shutdown of ISSI chip
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_writeReg( addr, 0x0A, 0x01, 0x0B );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LED_currentEvent = 0;
|
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Check to see if frame buffers are ready to replenish
|
|
|
|
if ( LED_FrameBufferReset )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_FrameBufferReset = 0;
|
2016-01-04 00:16:41 +00:00
|
|
|
// Delay, in order to synchronize chips
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_FrameBufferStart = 1;
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// FPS Display
|
|
|
|
if ( LED_displayFPS )
|
|
|
|
{
|
|
|
|
dbug_msg("4frames/");
|
|
|
|
printInt32( systick_millis_count - LED_timePrev );
|
|
|
|
LED_timePrev = systick_millis_count;
|
|
|
|
print( "ms" NL );
|
|
|
|
}
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Make sure there are buffers available
|
|
|
|
if ( LED_FrameBuffersReady == 0 )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
// Only start if we haven't already
|
|
|
|
// And if we've finished updating the buffers
|
|
|
|
if ( !LED_FrameBufferStart || Pixel_FrameState == FrameState_Sending )
|
|
|
|
return;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Start Auto Frame Play on either frame 1 or 5
|
|
|
|
uint8_t frame = LED_FrameBufferPage == 0 ? 4 : 0;
|
|
|
|
LED_syncReg( 0x00, 0x08 | frame, 0x0B );
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_FrameBufferStart = 0;
|
|
|
|
LED_FrameBuffersReady = LED_FrameBuffersMax;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-22 00:12:41 +00:00
|
|
|
/*
|
2016-01-03 18:21:10 +00:00
|
|
|
else
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
dbug_msg(":/ - Start(");
|
|
|
|
printHex( LED_FrameBufferStart );
|
|
|
|
print(") BuffersReady(");
|
|
|
|
printHex( LED_FrameBuffersReady );
|
|
|
|
print(") State(");
|
|
|
|
printHex( Pixel_FrameState );
|
|
|
|
print(")"NL);
|
|
|
|
}
|
|
|
|
*/
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Only send frame to ISSI chip if buffers are ready
|
|
|
|
if ( Pixel_FrameState != FrameState_Ready )
|
|
|
|
return;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_FrameBuffersReady--;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Set the page of all the ISSI chips
|
|
|
|
// This way we can easily link the buffers to send the brightnesses in the background
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
// Page Setup
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
uint16_t pageSetup[] = { addr, 0xFD, LED_FrameBufferPage };
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Send each update
|
|
|
|
while ( i2c_send( pageSetup, sizeof( pageSetup ) / 2 ) == -1 )
|
|
|
|
delay(1);
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
// Send current set of buffers
|
|
|
|
// Uses interrupts to send to all the ISSI chips
|
|
|
|
// Pixel_FrameState will be updated when complete
|
|
|
|
LED_chipSend = 0; // Start with chip 0
|
|
|
|
LED_linkedSend();
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-22 03:56:52 +00:00
|
|
|
// Called by parent Scan Module whenver the available current has changed
|
|
|
|
// current - mA
|
|
|
|
void LED_currentChange( unsigned int current )
|
|
|
|
{
|
|
|
|
// Delay action till next LED scan loop (as this callback sometimes occurs during interrupt requests)
|
|
|
|
LED_currentEvent = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
// ----- Capabilities -----
|
|
|
|
|
|
|
|
// Basic LED Control Capability
|
|
|
|
typedef enum LedControlMode {
|
|
|
|
// Single LED Modes
|
|
|
|
LedControlMode_brightness_decrease,
|
|
|
|
LedControlMode_brightness_increase,
|
|
|
|
LedControlMode_brightness_set,
|
|
|
|
// Set all LEDs (index argument not required)
|
|
|
|
LedControlMode_brightness_decrease_all,
|
|
|
|
LedControlMode_brightness_increase_all,
|
|
|
|
LedControlMode_brightness_set_all,
|
|
|
|
} LedControlMode;
|
|
|
|
|
|
|
|
typedef struct LedControl {
|
|
|
|
LedControlMode mode; // XXX Make sure to adjust the .kll capability if this variable is larger than 8 bits
|
|
|
|
uint8_t amount;
|
|
|
|
uint16_t index;
|
|
|
|
} LedControl;
|
|
|
|
|
|
|
|
void LED_control( LedControl *control )
|
|
|
|
{
|
|
|
|
// Configure based upon the given mode
|
2015-11-12 09:21:32 +00:00
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
2015-10-10 05:28:31 +00:00
|
|
|
{
|
2015-11-12 09:21:32 +00:00
|
|
|
// TODO Perhaps do gamma adjustment?
|
|
|
|
switch ( control->mode )
|
2015-10-10 05:28:31 +00:00
|
|
|
{
|
2015-11-12 09:21:32 +00:00
|
|
|
case LedControlMode_brightness_decrease:
|
2015-10-10 05:28:31 +00:00
|
|
|
// Don't worry about rolling over, the cycle is quick
|
2015-11-12 09:21:32 +00:00
|
|
|
LED_pageBuffer[ ch ].buffer[ control->index ] -= control->amount;
|
|
|
|
break;
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
case LedControlMode_brightness_increase:
|
2015-10-10 05:28:31 +00:00
|
|
|
// Don't worry about rolling over, the cycle is quick
|
2015-11-12 09:21:32 +00:00
|
|
|
LED_pageBuffer[ ch ].buffer[ control->index ] += control->amount;
|
|
|
|
break;
|
2015-10-10 05:28:31 +00:00
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
case LedControlMode_brightness_set:
|
|
|
|
LED_pageBuffer[ ch ].buffer[ control->index ] = control->amount;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LedControlMode_brightness_decrease_all:
|
|
|
|
for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
|
|
|
|
{
|
|
|
|
// Don't worry about rolling over, the cycle is quick
|
|
|
|
LED_pageBuffer[ ch ].buffer[ channel ] -= control->amount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LedControlMode_brightness_increase_all:
|
|
|
|
for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
|
|
|
|
{
|
|
|
|
// Don't worry about rolling over, the cycle is quick
|
|
|
|
LED_pageBuffer[ ch ].buffer[ channel ] += control->amount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LedControlMode_brightness_set_all:
|
|
|
|
for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
|
|
|
|
{
|
|
|
|
LED_pageBuffer[ ch ].buffer[ channel ] = control->amount;
|
|
|
|
}
|
|
|
|
break;
|
2015-10-10 05:28:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync LED buffer with ISSI chip buffer
|
|
|
|
// TODO Support multiple frames
|
2015-11-12 09:21:32 +00:00
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
LED_sendPage( LED_pageBuffer[ ch ].i2c_addr, (uint16_t*)&LED_pageBuffer[ ch ], sizeof( LED_Buffer ) / 2, 0 );
|
2015-11-12 09:21:32 +00:00
|
|
|
}
|
2015-10-10 05:28:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 17:02:01 +00:00
|
|
|
uint8_t LED_control_timer = 0;
|
2015-10-10 05:28:31 +00:00
|
|
|
void LED_control_capability( uint8_t state, uint8_t stateType, uint8_t *args )
|
|
|
|
{
|
|
|
|
// Display capability name
|
|
|
|
if ( stateType == 0xFF && state == 0xFF )
|
|
|
|
{
|
|
|
|
print("LED_control_capability(mode,amount,index)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only use capability on press
|
|
|
|
// TODO Analog
|
|
|
|
if ( stateType == 0x00 && state == 0x03 ) // Not on release
|
|
|
|
return;
|
|
|
|
|
2015-10-16 17:02:01 +00:00
|
|
|
// XXX
|
|
|
|
// ISSI Chip locks up if we spam updates too quickly (might be an I2C bug on this side too -HaaTa)
|
|
|
|
// Make sure we only send an update every 30 milliseconds at most
|
|
|
|
// It may be possible to optimize speed even further, but will likely require serious time with a logic analyzer
|
|
|
|
|
|
|
|
uint8_t currentTime = (uint8_t)systick_millis_count;
|
|
|
|
int8_t compare = (int8_t)(currentTime - LED_control_timer) & 0x7F;
|
|
|
|
if ( compare < 30 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LED_control_timer = currentTime;
|
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
// Set the input structure
|
|
|
|
LedControl *control = (LedControl*)args;
|
|
|
|
|
2015-10-16 17:02:01 +00:00
|
|
|
// Interconnect broadcasting
|
|
|
|
#if defined(ConnectEnabled_define)
|
|
|
|
uint8_t send_packet = 0;
|
|
|
|
uint8_t ignore_node = 0;
|
|
|
|
|
|
|
|
// By default send to the *next* node, which will determine where to go next
|
|
|
|
extern uint8_t Connect_id; // connect_scan.c
|
|
|
|
uint8_t addr = Connect_id + 1;
|
|
|
|
|
|
|
|
switch ( control->mode )
|
|
|
|
{
|
|
|
|
// Calculate the led address to send
|
|
|
|
// If greater than the Total hannels
|
|
|
|
// Set address - Total channels
|
|
|
|
// Otherwise, ignore
|
|
|
|
case LedControlMode_brightness_decrease:
|
|
|
|
case LedControlMode_brightness_increase:
|
|
|
|
case LedControlMode_brightness_set:
|
|
|
|
// Ignore if led is on this node
|
|
|
|
if ( control->index < LED_TotalChannels )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Calculate new led index
|
|
|
|
control->index -= LED_TotalChannels;
|
|
|
|
|
|
|
|
ignore_node = 1;
|
|
|
|
send_packet = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Broadcast to all nodes
|
|
|
|
// XXX Do not set broadcasting address
|
|
|
|
// Will send command twice
|
|
|
|
case LedControlMode_brightness_decrease_all:
|
|
|
|
case LedControlMode_brightness_increase_all:
|
|
|
|
case LedControlMode_brightness_set_all:
|
|
|
|
send_packet = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only send interconnect remote capability packet if necessary
|
|
|
|
if ( send_packet )
|
|
|
|
{
|
|
|
|
// generatedKeymap.h
|
|
|
|
extern const Capability CapabilitiesList[];
|
|
|
|
|
|
|
|
// Broadcast layerStackExact remote capability (0xFF is the broadcast id)
|
|
|
|
Connect_send_RemoteCapability(
|
|
|
|
addr,
|
|
|
|
LED_control_capability_index,
|
|
|
|
state,
|
|
|
|
stateType,
|
|
|
|
CapabilitiesList[ LED_control_capability_index ].argCount,
|
|
|
|
args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is nothing to do on this node, ignore
|
|
|
|
if ( ignore_node )
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Modify led state of this node
|
2015-10-10 05:28:31 +00:00
|
|
|
LED_control( control );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-22 00:12:41 +00:00
|
|
|
// ----- CLI Command Functions -----
|
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
// TODO Currently not working correctly
|
2015-03-22 00:12:41 +00:00
|
|
|
void cliFunc_i2cSend( char* args )
|
|
|
|
{
|
|
|
|
char* curArgs;
|
|
|
|
char* arg1Ptr;
|
|
|
|
char* arg2Ptr = args;
|
|
|
|
|
|
|
|
// Buffer used after interpretting the args, will be sent to I2C functions
|
|
|
|
// NOTE: Limited to 8 bytes currently (can be increased if necessary
|
|
|
|
#define i2cSend_BuffLenMax 8
|
2016-01-03 18:21:10 +00:00
|
|
|
uint16_t buffer[ i2cSend_BuffLenMax ];
|
|
|
|
uint8_t bufferLen = 0;
|
2015-03-22 00:12:41 +00:00
|
|
|
|
|
|
|
// No \r\n by default after the command is entered
|
|
|
|
print( NL );
|
|
|
|
info_msg("Sending: ");
|
|
|
|
|
|
|
|
// Parse args until a \0 is found
|
|
|
|
while ( bufferLen < i2cSend_BuffLenMax )
|
|
|
|
{
|
|
|
|
curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If | is found, end sequence and start new one
|
|
|
|
if ( *arg1Ptr == '|' )
|
|
|
|
{
|
|
|
|
print("| ");
|
2016-01-03 18:21:10 +00:00
|
|
|
i2c_send( buffer, bufferLen );
|
2015-03-22 00:12:41 +00:00
|
|
|
bufferLen = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Interpret the argument
|
|
|
|
buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
// Print out the arg
|
|
|
|
dPrint( arg1Ptr );
|
|
|
|
print(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
print( NL );
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
i2c_send( buffer, bufferLen );
|
2015-04-14 07:40:48 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
/*
|
2015-08-02 23:28:21 +00:00
|
|
|
void cliFunc_ledWPage( char* args )
|
|
|
|
{
|
|
|
|
char* curArgs;
|
|
|
|
char* arg1Ptr;
|
|
|
|
char* arg2Ptr = args;
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
// First specify the write address
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
return;
|
|
|
|
uint8_t addr = numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
// Next process page and starting address
|
2015-08-02 23:28:21 +00:00
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
return;
|
2015-11-12 09:21:32 +00:00
|
|
|
uint8_t page[] = { addr, 0xFD, numToInt( arg1Ptr ) };
|
2015-08-02 23:28:21 +00:00
|
|
|
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
return;
|
2015-11-12 09:21:32 +00:00
|
|
|
uint8_t data[] = { addr, numToInt( arg1Ptr ), 0 };
|
2015-08-02 23:28:21 +00:00
|
|
|
|
|
|
|
// Set the register page
|
|
|
|
while ( I2C_Send( page, sizeof( page ), 0 ) == 0 )
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// Process all args
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
data[2] = numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
// Write register location and data to I2C
|
|
|
|
while ( I2C_Send( data, sizeof( data ), 0 ) == 0 )
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// Increment address
|
|
|
|
data[1]++;
|
|
|
|
}
|
|
|
|
}
|
2016-01-04 00:16:41 +00:00
|
|
|
*/
|
2015-08-02 23:28:21 +00:00
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
void cliFunc_ledReset( char* args )
|
2015-04-14 07:40:48 +00:00
|
|
|
{
|
|
|
|
print( NL ); // No \r\n by default after the command is entered
|
|
|
|
|
2015-11-12 09:21:32 +00:00
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
LED_zeroPages( LED_ledEnableMask[ ch ].i2c_addr, 0x0B, 1, 0x00, 0x0C ); // Control Registers
|
2016-01-04 00:16:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear buffers
|
|
|
|
for ( uint8_t buf = 0; buf < ISSI_Chips_define; buf++ )
|
|
|
|
{
|
|
|
|
memset( (void*)LED_pageBuffer[ buf ].buffer, 0, LED_BufferLength * 2 );
|
2015-11-12 09:21:32 +00:00
|
|
|
}
|
2016-01-04 00:16:41 +00:00
|
|
|
|
|
|
|
LED_reset();
|
2015-04-14 07:40:48 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
void cliFunc_ledSpeed( char* args )
|
2015-03-22 00:12:41 +00:00
|
|
|
{
|
|
|
|
print( NL ); // No \r\n by default after the command is entered
|
2015-11-12 09:21:32 +00:00
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
char* curArgs;
|
|
|
|
char* arg1Ptr;
|
|
|
|
char* arg2Ptr = args;
|
|
|
|
uint8_t speed = ISSI_AnimationSpeed_define;
|
|
|
|
|
|
|
|
// Process speed argument if given
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Check if f argument was given
|
|
|
|
switch ( *arg1Ptr )
|
2016-01-03 18:21:10 +00:00
|
|
|
{
|
2016-01-04 00:16:41 +00:00
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
info_msg("FPS Toggle");
|
|
|
|
LED_displayFPS = !LED_displayFPS;
|
|
|
|
return;
|
2016-01-03 18:21:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr != '\0' )
|
2016-01-03 18:21:10 +00:00
|
|
|
{
|
2016-01-04 00:16:41 +00:00
|
|
|
speed = numToInt( arg1Ptr );
|
2016-01-03 18:21:10 +00:00
|
|
|
}
|
2016-01-04 00:16:41 +00:00
|
|
|
// Default to default speed
|
|
|
|
else
|
2016-01-03 18:21:10 +00:00
|
|
|
{
|
2016-01-04 00:16:41 +00:00
|
|
|
info_msg("Setting default speed: ");
|
|
|
|
printInt8( speed );
|
2016-01-03 18:21:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 00:16:41 +00:00
|
|
|
|
|
|
|
// Set refresh speed per ISSI chip
|
2015-11-12 09:21:32 +00:00
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
2016-01-03 18:21:10 +00:00
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
|
|
|
|
// Default refresh speed - TxA
|
|
|
|
// T is typically 11ms
|
|
|
|
// A is 1 to 64 (where 0 is 64)
|
|
|
|
LED_writeReg( addr, 0x03, speed, 0x0B );
|
2015-11-12 09:21:32 +00:00
|
|
|
}
|
2015-03-22 00:12:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 05:28:31 +00:00
|
|
|
void cliFunc_ledCtrl( char* args )
|
|
|
|
{
|
|
|
|
char* curArgs;
|
|
|
|
char* arg1Ptr;
|
|
|
|
char* arg2Ptr = args;
|
|
|
|
LedControl control;
|
|
|
|
|
|
|
|
// First process mode
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
return;
|
|
|
|
control.mode = numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
|
|
|
|
// Next process amount
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
|
|
|
|
// Stop processing args if no more are found
|
|
|
|
if ( *arg1Ptr == '\0' )
|
|
|
|
return;
|
|
|
|
control.amount = numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
|
|
|
|
// Finally process led index, if it exists
|
|
|
|
// Default to 0
|
|
|
|
curArgs = arg2Ptr;
|
|
|
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
|
|
|
control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr );
|
|
|
|
|
|
|
|
// Process request
|
|
|
|
LED_control( &control );
|
|
|
|
}
|
|
|
|
|
2016-01-03 18:21:10 +00:00
|
|
|
void cliFunc_ledNFrame( char* args )
|
|
|
|
{
|
|
|
|
// TODO REMOVEME
|
|
|
|
LED_FrameBufferStart = 1;
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
LED_FrameBufferReset = 0;
|
|
|
|
LED_FrameBuffersReady = LED_FrameBuffersMax;
|
|
|
|
LED_FrameBufferStart = 1;
|
|
|
|
*/
|
|
|
|
//LED_FrameBuffersReady++;
|
|
|
|
//LED_FrameBufferStart = 1;
|
|
|
|
//uint8_t addr = LED_pageBuffer[ 0 ].i2c_addr;
|
|
|
|
//LED_writeReg( addr, 0x00, 0x08, 0x0B );
|
|
|
|
|
|
|
|
//LED_FrameBuffersReady--;
|
|
|
|
|
|
|
|
// Iterate over available buffers
|
|
|
|
// Each pass can only send one buffer (per chip)
|
|
|
|
for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ )
|
|
|
|
{
|
|
|
|
// XXX It is more efficient to only send positions that are used
|
|
|
|
// However, this may actually have more addressing overhead
|
|
|
|
// For simplicity, just sending the full 144 positions per ISSI chip
|
|
|
|
uint8_t addr = LED_pageBuffer[ ch ].i2c_addr;
|
|
|
|
LED_sendPage(
|
|
|
|
addr,
|
|
|
|
(uint16_t*)&LED_pageBuffer[ ch ],
|
|
|
|
sizeof( LED_Buffer ) / 2,
|
|
|
|
LED_FrameBufferPage
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increment the buffer page
|
|
|
|
// And reset if necessary
|
|
|
|
if ( ++LED_FrameBufferPage >= LED_FrameBuffersMax * 2 )
|
|
|
|
{
|
|
|
|
LED_FrameBufferPage = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|