Initial STLcd code.
- Basic screen initialization and clear is working - Currently SPI is set to a low speed for easy logic analyzer debugging
This commit is contained in:
parent
e41444304b
commit
8942ab63d5
@ -130,6 +130,28 @@ void main()
|
|||||||
PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
GPIOB_PSOR |= (1<<16);
|
GPIOB_PSOR |= (1<<16);
|
||||||
*/
|
*/
|
||||||
|
// RST
|
||||||
|
GPIOC_PDDR |= (1<<8);
|
||||||
|
PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PSOR |= (1<<8);
|
||||||
|
/*
|
||||||
|
// CS1B
|
||||||
|
GPIOC_PDDR |= (1<<4);
|
||||||
|
PORTC_PCR4 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PCOR |= (1<<4);
|
||||||
|
*/
|
||||||
|
// Backlight
|
||||||
|
GPIOC_PDDR |= (1<<1);
|
||||||
|
PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PCOR |= (1<<1);
|
||||||
|
GPIOC_PDDR |= (1<<2);
|
||||||
|
PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PCOR |= (1<<2);
|
||||||
|
GPIOC_PDDR |= (1<<3);
|
||||||
|
PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PCOR |= (1<<3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
flash_prepare_flashing();
|
flash_prepare_flashing();
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
###| CMAKE Kiibohd Controller |###
|
###| CMAKE Kiibohd Controller |###
|
||||||
#
|
#
|
||||||
# Jacob Alexander 2011-2014
|
# Jacob Alexander 2011-2015
|
||||||
# Due to this file's usefulness:
|
# Due to this file's usefulness:
|
||||||
#
|
#
|
||||||
# Released into the Public Domain
|
# Released into the Public Domain
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* Teensyduino Core Library
|
/* Teensyduino Core Library
|
||||||
* http://www.pjrc.com/teensy/
|
* http://www.pjrc.com/teensy/
|
||||||
* Copyright (c) 2013 PJRC.COM, LLC.
|
* Copyright (c) 2013 PJRC.COM, LLC.
|
||||||
* Modified by Jacob Alexander 2014
|
* Modified by Jacob Alexander 2014-2015
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -1343,6 +1343,10 @@
|
|||||||
#define SPI_SR_TFFF (uint32_t)0x02000000 // Transmit FIFO Fill Flag
|
#define SPI_SR_TFFF (uint32_t)0x02000000 // Transmit FIFO Fill Flag
|
||||||
#define SPI_SR_RFOF (uint32_t)0x00080000 // Receive FIFO Overflow Flag
|
#define SPI_SR_RFOF (uint32_t)0x00080000 // Receive FIFO Overflow Flag
|
||||||
#define SPI_SR_RFDF (uint32_t)0x00020000 // Receive FIFO Drain Flag
|
#define SPI_SR_RFDF (uint32_t)0x00020000 // Receive FIFO Drain Flag
|
||||||
|
#define SPI_SR_TXCTR (uint32_t)0x0000F000 // Transmit FIFO Counter
|
||||||
|
#define SPI_SR_TXNXTPTR (uint32_t)0x00000F00 // Transmit Next, Pointer
|
||||||
|
#define SPI_SR_RXCTR (uint32_t)0x000000F0 // Receive FIFO Counter
|
||||||
|
#define SPI_SR_POPNXTPTR (uint32_t)0x0000000F // Pop Next, Pointer
|
||||||
#define SPI0_RSER *(volatile uint32_t *)0x4002C030 // DSPI DMA/Interrupt Request Select and Enable Register
|
#define SPI0_RSER *(volatile uint32_t *)0x4002C030 // DSPI DMA/Interrupt Request Select and Enable Register
|
||||||
#define SPI_RSER_TCF_RE (uint32_t)0x80000000 // Transmission Complete Request Enable
|
#define SPI_RSER_TCF_RE (uint32_t)0x80000000 // Transmission Complete Request Enable
|
||||||
#define SPI_RSER_EOQF_RE (uint32_t)0x10000000 // DSPI Finished Request Request Enable
|
#define SPI_RSER_EOQF_RE (uint32_t)0x10000000 // DSPI Finished Request Request Enable
|
||||||
|
@ -56,9 +56,10 @@ typedef struct LED_Buffer {
|
|||||||
// ----- Function Declarations -----
|
// ----- Function Declarations -----
|
||||||
|
|
||||||
// CLI Functions
|
// CLI Functions
|
||||||
void cliFunc_echo( char* args );
|
|
||||||
void cliFunc_i2cRecv( char* args );
|
void cliFunc_i2cRecv( char* args );
|
||||||
void cliFunc_i2cSend( char* args );
|
void cliFunc_i2cSend( char* args );
|
||||||
|
void cliFunc_ledPage( char* args );
|
||||||
|
void cliFunc_ledStart( char* args );
|
||||||
void cliFunc_ledTest( char* args );
|
void cliFunc_ledTest( char* args );
|
||||||
void cliFunc_ledZero( char* args );
|
void cliFunc_ledZero( char* args );
|
||||||
|
|
||||||
@ -74,12 +75,16 @@ uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen );
|
|||||||
// Scan Module command dictionary
|
// Scan Module command dictionary
|
||||||
CLIDict_Entry( i2cRecv, "Send I2C sequence of bytes and expect a reply of 1 byte on the last sequence." NL "\t\tUse |'s to split sequences with a stop." );
|
CLIDict_Entry( i2cRecv, "Send I2C sequence of bytes and expect a reply of 1 byte on the last sequence." NL "\t\tUse |'s to split sequences with a stop." );
|
||||||
CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
|
CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
|
||||||
|
CLIDict_Entry( ledPage, "Read the given register page." );
|
||||||
|
CLIDict_Entry( ledStart, "Disable software shutdown." );
|
||||||
CLIDict_Entry( ledTest, "Test out the led pages." );
|
CLIDict_Entry( ledTest, "Test out the led pages." );
|
||||||
CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
|
CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
|
||||||
|
|
||||||
CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
|
CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
|
||||||
CLIDict_Item( i2cRecv ),
|
CLIDict_Item( i2cRecv ),
|
||||||
CLIDict_Item( i2cSend ),
|
CLIDict_Item( i2cSend ),
|
||||||
|
CLIDict_Item( ledPage ),
|
||||||
|
CLIDict_Item( ledStart ),
|
||||||
CLIDict_Item( ledTest ),
|
CLIDict_Item( ledTest ),
|
||||||
CLIDict_Item( ledZero ),
|
CLIDict_Item( ledZero ),
|
||||||
{ 0, 0, 0 } // Null entry for dictionary end
|
{ 0, 0, 0 } // Null entry for dictionary end
|
||||||
@ -97,7 +102,9 @@ volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_
|
|||||||
|
|
||||||
LED_Buffer LED_pageBuffer;
|
LED_Buffer LED_pageBuffer;
|
||||||
|
|
||||||
|
/*
|
||||||
// A bit mask determining which LEDs are enabled in the ISSI chip
|
// A bit mask determining which LEDs are enabled in the ISSI chip
|
||||||
|
// All channel mask example
|
||||||
// 0x00 -> 0x11
|
// 0x00 -> 0x11
|
||||||
const uint8_t LED_ledEnableMask[] = {
|
const uint8_t LED_ledEnableMask[] = {
|
||||||
0xE8, // I2C address
|
0xE8, // I2C address
|
||||||
@ -112,7 +119,58 @@ const uint8_t LED_ledEnableMask[] = {
|
|||||||
0xFF, 0xFF, // C8-1 -> C8-16
|
0xFF, 0xFF, // C8-1 -> C8-16
|
||||||
0xFF, 0xFF, // C9-1 -> C9-16
|
0xFF, 0xFF, // C9-1 -> C9-16
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// A bit mask determining which LEDs are enabled in the ISSI chip
|
||||||
|
// Infinity ErgoDox full mask
|
||||||
|
// 0x00 -> 0x11
|
||||||
|
const uint8_t LED_ledEnableMask[] = {
|
||||||
|
0xE8, // I2C address
|
||||||
|
0x00, // Starting register address
|
||||||
|
0xFC, 0xFC, // C1-1 -> C1-16
|
||||||
|
0xFB, 0xFB, // C2-1 -> C2-16
|
||||||
|
0xFF, 0xFF, // C3-1 -> C3-16
|
||||||
|
0xFE, 0xFE, // C4-1 -> C4-16
|
||||||
|
0x7F, 0x7F, // C5-1 -> C5-16
|
||||||
|
0xFF, 0xFF, // C6-1 -> C6-16
|
||||||
|
0xCF, 0xCF, // C7-1 -> C7-16
|
||||||
|
0xC7, 0xC7, // C8-1 -> C8-16
|
||||||
|
0x43, 0x43, // C9-1 -> C9-16
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
const uint8_t LED_ledEnableMask[] = {
|
||||||
|
0xE8, // I2C address
|
||||||
|
0x00, // Starting register address
|
||||||
|
0x00, 0x00, // C1-1 -> C1-16
|
||||||
|
//0xEC, 0xEC, // C1-1 -> C1-16
|
||||||
|
0x00, 0x00, // C2-1 -> C2-16
|
||||||
|
0x00, 0x00, // C3-1 -> C3-16
|
||||||
|
0x00, 0x00, // C4-1 -> C4-16
|
||||||
|
0x00, 0x00, // C5-1 -> C5-16
|
||||||
|
0x00, 0x00, // C6-1 -> C6-16
|
||||||
|
0x08, 0x08, // C7-1 -> C7-16
|
||||||
|
0x00, 0x00, // C8-1 -> C8-16
|
||||||
|
0x00, 0x00, // C9-1 -> C9-16
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// XXX Pre-fill example of buffers
|
||||||
|
const uint8_t examplePage[] = {
|
||||||
|
0xE8, // I2C address
|
||||||
|
0x24, // Starting register address
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C1-1 -> C1-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C2-1 -> C2-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C3-1 -> C3-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C4-1 -> C4-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C5-1 -> C5-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C6-1 -> C6-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C7-1 -> C7-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C8-1 -> C8-16
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C9-1 -> C9-16
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
// XXX Pre-fill example of buffers
|
// XXX Pre-fill example of buffers
|
||||||
const uint8_t examplePage[] = {
|
const uint8_t examplePage[] = {
|
||||||
0xE8, // I2C address
|
0xE8, // I2C address
|
||||||
@ -127,6 +185,7 @@ const uint8_t examplePage[] = {
|
|||||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, // C8-1 -> C8-16
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, // C8-1 -> C8-16
|
||||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, // C9-1 -> C9-16
|
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, // C9-1 -> C9-16
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -317,6 +376,34 @@ void LED_sendPage( uint8_t *buffer, uint8_t len, uint8_t page )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LED_readPage( uint8_t len, uint8_t page )
|
||||||
|
{
|
||||||
|
// Page Setup
|
||||||
|
uint8_t pageSetup[] = { 0xE8, 0xFD, page };
|
||||||
|
|
||||||
|
// Setup page
|
||||||
|
while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
|
||||||
|
delay(1);
|
||||||
|
|
||||||
|
// Register Setup
|
||||||
|
uint8_t regSetup[] = { 0xE8, 0x00 };
|
||||||
|
|
||||||
|
// Setup starting register
|
||||||
|
while ( I2C_Send( regSetup, sizeof( regSetup ), 0 ) == 0 )
|
||||||
|
delay(1);
|
||||||
|
|
||||||
|
// Register Read Command
|
||||||
|
uint8_t regReadCmd[] = { 0xE9 };
|
||||||
|
|
||||||
|
// Read each register in the page
|
||||||
|
for ( uint8_t reg = 0; reg < len; reg++ )
|
||||||
|
{
|
||||||
|
// Request register data
|
||||||
|
while ( I2C_Send( regReadCmd, sizeof( regReadCmd ), 0 ) == 0 )
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
|
void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
|
||||||
{
|
{
|
||||||
// Page Setup
|
// Page Setup
|
||||||
@ -342,6 +429,7 @@ inline void LED_setup()
|
|||||||
// Initialize I2C
|
// Initialize I2C
|
||||||
I2C_setup();
|
I2C_setup();
|
||||||
|
|
||||||
|
/* TODO Make work
|
||||||
// Zero out Frame Registers
|
// Zero out Frame Registers
|
||||||
// This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
|
// This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
|
||||||
LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
|
LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
|
||||||
@ -359,6 +447,7 @@ inline void LED_setup()
|
|||||||
|
|
||||||
// Disable Software shutdown of ISSI chip
|
// Disable Software shutdown of ISSI chip
|
||||||
LED_writeReg( 0x0A, 0x01, 0x0B );
|
LED_writeReg( 0x0A, 0x01, 0x0B );
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -446,6 +535,9 @@ inline uint16_t I2C_BufferLen( I2C_Buffer *buffer )
|
|||||||
|
|
||||||
void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
|
void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
|
||||||
{
|
{
|
||||||
|
dbug_msg("DATA: ");
|
||||||
|
printHex( byte );
|
||||||
|
|
||||||
// Make sure buffer isn't full
|
// Make sure buffer isn't full
|
||||||
if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
|
if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
|
||||||
{
|
{
|
||||||
@ -691,6 +783,38 @@ void cliFunc_i2cRecv( char* args )
|
|||||||
I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
|
I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cliFunc_ledPage( char* args )
|
||||||
|
{
|
||||||
|
// Parse number from argument
|
||||||
|
// NOTE: Only first argument is used
|
||||||
|
char* arg1Ptr;
|
||||||
|
char* arg2Ptr;
|
||||||
|
CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
|
||||||
|
|
||||||
|
// Default to 0 if no argument is given
|
||||||
|
uint8_t page = 0;
|
||||||
|
|
||||||
|
if ( arg1Ptr[0] != '\0' )
|
||||||
|
{
|
||||||
|
page = (uint8_t)numToInt( arg1Ptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
// No \r\n by default after the command is entered
|
||||||
|
print( NL );
|
||||||
|
|
||||||
|
LED_readPage( 0xB4, page );
|
||||||
|
}
|
||||||
|
|
||||||
|
void cliFunc_ledStart( char* args )
|
||||||
|
{
|
||||||
|
print( NL ); // No \r\n by default after the command is entered
|
||||||
|
LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
|
||||||
|
//LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
|
||||||
|
LED_writeReg( 0x0A, 0x01, 0x0B );
|
||||||
|
LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void cliFunc_ledTest( char* args )
|
void cliFunc_ledTest( char* args )
|
||||||
{
|
{
|
||||||
print( NL ); // No \r\n by default after the command is entered
|
print( NL ); // No \r\n by default after the command is entered
|
||||||
|
336
Scan/STLcd/lcd_scan.c
Normal file
336
Scan/STLcd/lcd_scan.c
Normal file
@ -0,0 +1,336 @@
|
|||||||
|
/* Copyright (C) 2015 by Jacob Alexander
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
#include <led.h>
|
||||||
|
#include <print.h>
|
||||||
|
|
||||||
|
// Local Includes
|
||||||
|
#include "lcd_scan.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Defines -----
|
||||||
|
|
||||||
|
#define LCD_TOTAL_VISIBLE_PAGES 4
|
||||||
|
#define LCD_PAGE_LEN 132
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Macros -----
|
||||||
|
|
||||||
|
// Number of entries in the SPI0 TxFIFO
|
||||||
|
#define SPI0_TxFIFO_CNT ( ( SPI0_SR & SPI_SR_TXCTR ) >> 12 )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Structs -----
|
||||||
|
|
||||||
|
// ----- Function Declarations -----
|
||||||
|
|
||||||
|
// CLI Functions
|
||||||
|
void cliFunc_lcdCmd( char* args );
|
||||||
|
void cliFunc_lcdInit( char* args );
|
||||||
|
void cliFunc_lcdTest( char* args );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Variables -----
|
||||||
|
|
||||||
|
// Full Toggle State
|
||||||
|
uint8_t cliFullToggleState = 0;
|
||||||
|
|
||||||
|
// Normal/Reverse Toggle State
|
||||||
|
uint8_t cliNormalReverseToggleState = 0;
|
||||||
|
|
||||||
|
// Scan Module command dictionary
|
||||||
|
CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." );
|
||||||
|
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( lcdInit ),
|
||||||
|
CLIDict_Item( lcdTest ),
|
||||||
|
{ 0, 0, 0 } // Null entry for dictionary end
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Interrupt Functions -----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Functions -----
|
||||||
|
|
||||||
|
inline void SPI_setup()
|
||||||
|
{
|
||||||
|
// Enable SPI internal clock
|
||||||
|
SIM_SCGC6 |= SIM_SCGC6_SPI0;
|
||||||
|
|
||||||
|
// Setup MOSI (SOUT) and SCLK (SCK)
|
||||||
|
PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(2);
|
||||||
|
PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(2);
|
||||||
|
|
||||||
|
// Setup SS (PCS)
|
||||||
|
PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(2);
|
||||||
|
|
||||||
|
// Master Mode, CS0
|
||||||
|
SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(1);
|
||||||
|
|
||||||
|
// DSPI Clock and Transfer Attributes
|
||||||
|
// Frame Size: 8 bits
|
||||||
|
// MSB First
|
||||||
|
// CLK Low by default
|
||||||
|
SPI0_CTAR0 = SPI_CTAR_FMSZ(7)
|
||||||
|
| SPI_CTAR_ASC(7)
|
||||||
|
| SPI_CTAR_DT(7)
|
||||||
|
| SPI_CTAR_CSSCK(7)
|
||||||
|
| SPI_CTAR_PBR(0) | SPI_CTAR_BR(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write buffer to SPI FIFO
|
||||||
|
void SPI_write( uint8_t *buffer, uint8_t len )
|
||||||
|
{
|
||||||
|
|
||||||
|
for ( uint8_t byte = 0; byte < len; byte++ )
|
||||||
|
{
|
||||||
|
// Wait for SPI TxFIFO to have 4 or fewer entries
|
||||||
|
while ( !( SPI0_SR & SPI_SR_TFFF ) )
|
||||||
|
delayMicroseconds(10);
|
||||||
|
|
||||||
|
// Write byte to TxFIFO
|
||||||
|
// CS0, CTAR0
|
||||||
|
SPI0_PUSHR = ( buffer[ byte ] & 0xff ) | SPI_PUSHR_PCS(1);
|
||||||
|
|
||||||
|
// Indicate transfer has completed
|
||||||
|
while ( !( SPI0_SR & SPI_SR_TCF ) );
|
||||||
|
SPI0_SR |= SPI_SR_TCF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to a control register
|
||||||
|
void LCD_writeControlReg( uint8_t byte )
|
||||||
|
{
|
||||||
|
// Wait for TxFIFO to be empt
|
||||||
|
while ( SPI0_TxFIFO_CNT != 0 );
|
||||||
|
|
||||||
|
// Set A0 low to enter control register mode
|
||||||
|
GPIOC_PCOR |= (1<<7);
|
||||||
|
|
||||||
|
// Write byte to SPI FIFO
|
||||||
|
SPI_write( &byte, 1 );
|
||||||
|
|
||||||
|
// Wait for TxFIFO to be empty
|
||||||
|
while ( SPI0_TxFIFO_CNT != 0 );
|
||||||
|
|
||||||
|
// Make sure data has transferred
|
||||||
|
delayMicroseconds(10); // XXX Adjust if SPI speed changes
|
||||||
|
|
||||||
|
// Set A0 high to go back to display register mode
|
||||||
|
GPIOC_PSOR |= (1<<7);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to display register
|
||||||
|
// Pages 0-7 normal display
|
||||||
|
// Page 8 icon buffer
|
||||||
|
void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len )
|
||||||
|
{
|
||||||
|
// Set the register page
|
||||||
|
LCD_writeControlReg( 0xB0 | ( 0x0F & page ) );
|
||||||
|
|
||||||
|
// Write buffer to SPI
|
||||||
|
SPI_write( buffer, len );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void LCD_clearPage( uint8_t page )
|
||||||
|
{
|
||||||
|
// Set the register page
|
||||||
|
LCD_writeControlReg( 0xB0 | ( 0x0F & page ) );
|
||||||
|
|
||||||
|
// Set display start line
|
||||||
|
LCD_writeControlReg( 0x40 );
|
||||||
|
|
||||||
|
// Reset Column Address
|
||||||
|
LCD_writeControlReg( 0x10 );
|
||||||
|
LCD_writeControlReg( 0x00 );
|
||||||
|
|
||||||
|
for ( uint8_t page_reg = 0; page_reg < LCD_PAGE_LEN; page_reg++ )
|
||||||
|
{
|
||||||
|
uint8_t byte = 0;
|
||||||
|
|
||||||
|
// Write buffer to SPI
|
||||||
|
SPI_write( &byte, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for TxFIFO to be empty
|
||||||
|
while ( SPI0_TxFIFO_CNT != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear Display
|
||||||
|
void LCD_clear()
|
||||||
|
{
|
||||||
|
// Setup each page
|
||||||
|
for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
|
||||||
|
{
|
||||||
|
LCD_clearPage( page );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset Page, Start Line, and Column Address
|
||||||
|
// Page
|
||||||
|
LCD_writeControlReg( 0xB0 );
|
||||||
|
|
||||||
|
// Start Line
|
||||||
|
LCD_writeControlReg( 0x40 );
|
||||||
|
|
||||||
|
// Reset Column Address
|
||||||
|
LCD_writeControlReg( 0x10 );
|
||||||
|
LCD_writeControlReg( 0x00 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intialize display
|
||||||
|
void LCD_initialize()
|
||||||
|
{
|
||||||
|
// ADC Select (Normal)
|
||||||
|
LCD_writeControlReg( 0xA0 );
|
||||||
|
|
||||||
|
// LCD Off
|
||||||
|
LCD_writeControlReg( 0xAE );
|
||||||
|
|
||||||
|
// COM Scan Output Direction
|
||||||
|
LCD_writeControlReg( 0xC0 );
|
||||||
|
|
||||||
|
// LCD Bias (1/6 bias)
|
||||||
|
LCD_writeControlReg( 0xA2 );
|
||||||
|
|
||||||
|
// Power Supply Operating Mode (Internal Only)
|
||||||
|
LCD_writeControlReg( 0x2F );
|
||||||
|
|
||||||
|
// Internal Rb/Ra Ratio
|
||||||
|
LCD_writeControlReg( 0x26 );
|
||||||
|
|
||||||
|
// Reset
|
||||||
|
LCD_writeControlReg( 0xE2 );
|
||||||
|
|
||||||
|
// Electric volume mode set, and value
|
||||||
|
LCD_writeControlReg( 0x81 );
|
||||||
|
LCD_writeControlReg( 0x00 );
|
||||||
|
|
||||||
|
// LCD On
|
||||||
|
LCD_writeControlReg( 0xAF );
|
||||||
|
|
||||||
|
// Clear Display RAM
|
||||||
|
LCD_clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
inline void LCD_setup()
|
||||||
|
{
|
||||||
|
// Register Scan CLI dictionary
|
||||||
|
CLI_registerDictionary( lcdCLIDict, lcdCLIDictName );
|
||||||
|
|
||||||
|
// Initialize SPI
|
||||||
|
SPI_setup();
|
||||||
|
|
||||||
|
|
||||||
|
// Setup Register Control Signal (A0)
|
||||||
|
// Start in display register mode (1)
|
||||||
|
GPIOC_PDDR |= (1<<7);
|
||||||
|
PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PSOR |= (1<<7);
|
||||||
|
|
||||||
|
// Setup LCD Reset pin (RST)
|
||||||
|
// 0 - Reset, 1 - Normal Operation
|
||||||
|
// Start in normal mode (1)
|
||||||
|
GPIOC_PDDR |= (1<<8);
|
||||||
|
PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
|
||||||
|
GPIOC_PSOR |= (1<<8);
|
||||||
|
|
||||||
|
// Run LCD intialization sequence
|
||||||
|
LCD_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// LCD State processing loop
|
||||||
|
inline uint8_t LCD_scan()
|
||||||
|
{
|
||||||
|
// NOP - Screen Refresh
|
||||||
|
//LCD_writeControlReg( 0xE3 );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- CLI Command Functions -----
|
||||||
|
|
||||||
|
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 pattern[] = { 0xFF, 0x00, 0x96, 0xFF, 0x00, 0xFF, 0x00 };
|
||||||
|
|
||||||
|
// Write to page D0
|
||||||
|
LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void cliFunc_lcdCmd( char* args )
|
||||||
|
{
|
||||||
|
char* curArgs;
|
||||||
|
char* arg1Ptr;
|
||||||
|
char* arg2Ptr = args;
|
||||||
|
|
||||||
|
print( NL ); // No \r\n by default after the command is entered
|
||||||
|
|
||||||
|
curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
|
||||||
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
||||||
|
|
||||||
|
// No args
|
||||||
|
if ( *arg1Ptr == '\0' )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// SPI Command
|
||||||
|
uint8_t cmd = (uint8_t)numToInt( arg1Ptr );
|
||||||
|
|
||||||
|
curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
|
||||||
|
CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
|
||||||
|
|
||||||
|
// Single Arg
|
||||||
|
if ( *arg1Ptr == '\0' )
|
||||||
|
goto cmd;
|
||||||
|
|
||||||
|
// TODO Deal with a0
|
||||||
|
cmd:
|
||||||
|
info_msg("Sending - ");
|
||||||
|
printHex( cmd );
|
||||||
|
print( NL );
|
||||||
|
LCD_writeControlReg( cmd );
|
||||||
|
}
|
||||||
|
|
34
Scan/STLcd/lcd_scan.h
Normal file
34
Scan/STLcd/lcd_scan.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright (C) 2015 by Jacob Alexander
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LCD_SCAN_H
|
||||||
|
#define __LCD_SCAN_H
|
||||||
|
|
||||||
|
// ----- Includes -----
|
||||||
|
|
||||||
|
// Compiler Includes
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Functions -----
|
||||||
|
|
||||||
|
void LCD_setup();
|
||||||
|
uint8_t LCD_scan();
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __LCD_SCAN_H
|
||||||
|
|
31
Scan/STLcd/setup.cmake
Normal file
31
Scan/STLcd/setup.cmake
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
###| CMake Kiibohd Controller Scan Module |###
|
||||||
|
#
|
||||||
|
# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
|
||||||
|
#
|
||||||
|
# Released into the Public Domain
|
||||||
|
#
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Sub-module flag, cannot be included stand-alone
|
||||||
|
#
|
||||||
|
set ( SubModule 1 )
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Module C files
|
||||||
|
#
|
||||||
|
|
||||||
|
set( Module_SRCS
|
||||||
|
lcd_scan.c
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Compiler Family Compatibility
|
||||||
|
#
|
||||||
|
set( ModuleCompatibility
|
||||||
|
arm
|
||||||
|
)
|
||||||
|
|
Reference in New Issue
Block a user