annotate Scan/STLcd/lcd_scan.c @ 351:38395a57cf52

Adding 16-bit brightness control to LCD backlight
author Jacob Alexander <haata@kiibohd.com>
date Sat, 01 Aug 2015 21:59:43 -0700
parents 136e47478441
children 99b567a3b1f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1 /* Copyright (C) 2015 by Jacob Alexander
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
2 *
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 * This file is free software: you can redistribute it and/or modify
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
4 * it under the terms of the GNU General Public License as published by
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
5 * the Free Software Foundation, either version 3 of the License, or
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
6 * (at your option) any later version.
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 *
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8 * This file is distributed in the hope that it will be useful,
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
11 * GNU General Public License for more details.
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
12 *
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
14 * along with this file. If not, see <http://www.gnu.org/licenses/>.
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 */
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 // ----- Includes -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 // Compiler Includes
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 #include <Lib/ScanLib.h>
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // Project Includes
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23 #include <cli.h>
351
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
24 #include <kll.h>
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 #include <led.h>
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26 #include <print.h>
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
28 // Local Includes
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
29 #include "lcd_scan.h"
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
30
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
31
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 // ----- Defines -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35 #define LCD_TOTAL_VISIBLE_PAGES 4
332
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
36 #define LCD_PAGE_LEN 128
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
39
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40 // ----- Macros -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42 // Number of entries in the SPI0 TxFIFO
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 #define SPI0_TxFIFO_CNT ( ( SPI0_SR & SPI_SR_TXCTR ) >> 12 )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
45
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
47 // ----- Structs -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
48
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
49 // ----- Function Declarations -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
50
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51 // CLI Functions
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
52 void cliFunc_lcdCmd( char* args );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
53 void cliFunc_lcdInit( char* args );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
54 void cliFunc_lcdTest( char* args );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58 // ----- Variables -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
59
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60 // Full Toggle State
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
61 uint8_t cliFullToggleState = 0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
62
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
63 // Normal/Reverse Toggle State
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64 uint8_t cliNormalReverseToggleState = 0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
65
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
66 // Scan Module command dictionary
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
67 CLIDict_Entry( lcdCmd, "Send byte via SPI, second argument enables a0. Defaults to control." );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
68 CLIDict_Entry( lcdInit, "Re-initialize the LCD display." );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
69 CLIDict_Entry( lcdTest, "Test out the LCD display." );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
71 CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
72 CLIDict_Item( lcdCmd ),
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
73 CLIDict_Item( lcdInit ),
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74 CLIDict_Item( lcdTest ),
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75 { 0, 0, 0 } // Null entry for dictionary end
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
76 };
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
77
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
78
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
80 // ----- Interrupt Functions -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
82
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
83
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 // ----- Functions -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86 inline void SPI_setup()
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
88 // Enable SPI internal clock
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89 SIM_SCGC6 |= SIM_SCGC6_SPI0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91 // Setup MOSI (SOUT) and SCLK (SCK)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
92 PORTC_PCR6 = PORT_PCR_DSE | PORT_PCR_MUX(2);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(2);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
94
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
95 // Setup SS (PCS)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96 PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_MUX(2);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98 // Master Mode, CS0
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(1);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101 // DSPI Clock and Transfer Attributes
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
102 // Frame Size: 8 bits
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
103 // MSB First
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
104 // CLK Low by default
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
105 SPI0_CTAR0 = SPI_CTAR_FMSZ(7)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
106 | SPI_CTAR_ASC(7)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
107 | SPI_CTAR_DT(7)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
108 | SPI_CTAR_CSSCK(7)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
109 | SPI_CTAR_PBR(0) | SPI_CTAR_BR(7);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
110 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
111
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
112 // Write buffer to SPI FIFO
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
113 void SPI_write( uint8_t *buffer, uint8_t len )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
114 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
115
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
116 for ( uint8_t byte = 0; byte < len; byte++ )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
117 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
118 // Wait for SPI TxFIFO to have 4 or fewer entries
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
119 while ( !( SPI0_SR & SPI_SR_TFFF ) )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
120 delayMicroseconds(10);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
121
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
122 // Write byte to TxFIFO
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
123 // CS0, CTAR0
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
124 SPI0_PUSHR = ( buffer[ byte ] & 0xff ) | SPI_PUSHR_PCS(1);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
125
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
126 // Indicate transfer has completed
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
127 while ( !( SPI0_SR & SPI_SR_TCF ) );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
128 SPI0_SR |= SPI_SR_TCF;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
129 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
130 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
131
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
132 // Write to a control register
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
133 void LCD_writeControlReg( uint8_t byte )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
134 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
135 // Wait for TxFIFO to be empt
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
136 while ( SPI0_TxFIFO_CNT != 0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
137
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
138 // Set A0 low to enter control register mode
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
139 GPIOC_PCOR |= (1<<7);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
140
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
141 // Write byte to SPI FIFO
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
142 SPI_write( &byte, 1 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
143
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
144 // Wait for TxFIFO to be empty
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
145 while ( SPI0_TxFIFO_CNT != 0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
146
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
147 // Make sure data has transferred
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
148 delayMicroseconds(10); // XXX Adjust if SPI speed changes
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
149
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
150 // Set A0 high to go back to display register mode
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
151 GPIOC_PSOR |= (1<<7);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
152 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
153
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
154 // Write to display register
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
155 // Pages 0-7 normal display
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
156 // Page 8 icon buffer
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
157 void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
158 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
159 // Set the register page
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
160 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
161
332
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
162 // Set display start line
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
163 LCD_writeControlReg( 0x40 );
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
164
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
165 // Reset Column Address
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
166 LCD_writeControlReg( 0x10 );
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
167 LCD_writeControlReg( 0x00 );
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
168
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
169 // Write buffer to SPI
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
170 SPI_write( buffer, len );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
171 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
172
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
173 inline void LCD_clearPage( uint8_t page )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
174 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
175 // Set the register page
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
176 LCD_writeControlReg( 0xB0 | ( 0x0F & page ) );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
177
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
178 // Set display start line
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
179 LCD_writeControlReg( 0x40 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
180
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
181 // Reset Column Address
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
182 LCD_writeControlReg( 0x10 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
183 LCD_writeControlReg( 0x00 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
184
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
185 for ( uint8_t page_reg = 0; page_reg < LCD_PAGE_LEN; page_reg++ )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
186 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
187 uint8_t byte = 0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
188
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
189 // Write buffer to SPI
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
190 SPI_write( &byte, 1 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
191 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
192
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
193 // Wait for TxFIFO to be empty
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
194 while ( SPI0_TxFIFO_CNT != 0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
195 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
196
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
197 // Clear Display
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
198 void LCD_clear()
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
199 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
200 // Setup each page
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
201 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
202 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
203 LCD_clearPage( page );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
204 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
205
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
206 // Reset Page, Start Line, and Column Address
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
207 // Page
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
208 LCD_writeControlReg( 0xB0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
209
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
210 // Start Line
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
211 LCD_writeControlReg( 0x40 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
212
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
213 // Reset Column Address
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
214 LCD_writeControlReg( 0x10 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
215 LCD_writeControlReg( 0x00 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
216 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
217
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
218 // Intialize display
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
219 void LCD_initialize()
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
220 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
221 // ADC Select (Normal)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
222 LCD_writeControlReg( 0xA0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
223
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
224 // LCD Off
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
225 LCD_writeControlReg( 0xAE );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
226
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
227 // COM Scan Output Direction
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
228 LCD_writeControlReg( 0xC0 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
229
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
230 // LCD Bias (1/6 bias)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
231 LCD_writeControlReg( 0xA2 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
232
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
233 // Power Supply Operating Mode (Internal Only)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
234 LCD_writeControlReg( 0x2F );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
235
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
236 // Internal Rb/Ra Ratio
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
237 LCD_writeControlReg( 0x26 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
238
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
239 // Reset
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
240 LCD_writeControlReg( 0xE2 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
241
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
242 // Electric volume mode set, and value
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
243 LCD_writeControlReg( 0x81 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
244 LCD_writeControlReg( 0x00 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
245
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
246 // LCD On
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
247 LCD_writeControlReg( 0xAF );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
248
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
249 // Clear Display RAM
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
250 LCD_clear();
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
251 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
252
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
253 // Setup
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
254 inline void LCD_setup()
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
255 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
256 // Register Scan CLI dictionary
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
257 CLI_registerDictionary( lcdCLIDict, lcdCLIDictName );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
258
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
259 // Initialize SPI
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
260 SPI_setup();
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
261
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
262 // Setup Register Control Signal (A0)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
263 // Start in display register mode (1)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
264 GPIOC_PDDR |= (1<<7);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
265 PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
266 GPIOC_PSOR |= (1<<7);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
267
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
268 // Setup LCD Reset pin (RST)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
269 // 0 - Reset, 1 - Normal Operation
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
270 // Start in normal mode (1)
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
271 GPIOC_PDDR |= (1<<8);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
272 PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
273 GPIOC_PSOR |= (1<<8);
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
274
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
275 // Run LCD intialization sequence
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
276 LCD_initialize();
347
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 332
diff changeset
277
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 332
diff changeset
278 // Setup Backlight
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 332
diff changeset
279 // TODO Expose default settings
351
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
280 SIM_SCGC6 |= SIM_SCGC6_FTM0;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
281 FTM0_CNT = 0; // Reset counter
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
282
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
283 // PWM Period
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
284 // 16-bit maximum
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
285 FTM0_MOD = 0xFFFF;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
286
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
287 // Set FTM to PWM output - Edge Aligned, Low-true pulses
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
288 FTM0_C0SC = 0x24; // MSnB:MSnA = 10, ELSnB:ELSnA = 01
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
289 FTM0_C1SC = 0x24;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
290 FTM0_C2SC = 0x24;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
291
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
292 // Base FTM clock selection (72 MHz system clock)
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
293 // Pre-scalar calculations
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
294 // 0 - 72 MHz - Highest power usage/best result
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
295 // 1 - 36 MHz
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
296 // 2 - 18 MHz
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
297 // 3 - 9 MHz - Slightly visible flicker (peripheral vision)
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
298 // 4 - 4 500 kHz - Visible flickering
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
299 // 5 - 2 250 kHz
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
300 // 6 - 1 125 kHz
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
301 // 7 - 562 500 Hz
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
302 // System clock, /w prescalar setting
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
303 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS( STLcdBacklightPrescalar_define );
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
304
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
305 /* Write frequency TODO API
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
306 FTM0_SC = 0;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
307 FTM0_CNT = 0;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
308 FTM0_MOD = mod;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
309 FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(prescale);
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
310 */
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
311
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
312 // Red
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
313 FTM0_C0V = STLcdBacklightRed_define;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
314 PORTC_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4);
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
315
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
316 // Green
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
317 FTM0_C1V = STLcdBacklightGreen_define;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
318 PORTC_PCR2 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4);
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
319
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
320 // Blue
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
321 FTM0_C2V = STLcdBacklightBlue_define;
38395a57cf52 Adding 16-bit brightness control to LCD backlight
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
322 PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4);
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
323 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
324
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
325
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
326 // LCD State processing loop
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
327 inline uint8_t LCD_scan()
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
328 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
329 // NOP - Screen Refresh
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
330 //LCD_writeControlReg( 0xE3 );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
331 return 0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
332 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
333
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
334
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
335
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
336 // ----- CLI Command Functions -----
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
337
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
338 void cliFunc_lcdInit( char* args )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
339 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
340 print( NL ); // No \r\n by default after the command is entered
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
341 LCD_initialize();
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
342 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
343
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
344 void cliFunc_lcdTest( char* args )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
345 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
346 print( NL ); // No \r\n by default after the command is entered
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
347
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
348 //LCD_initialize();
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
349 // Test pattern
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
350 uint8_t pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
332
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
351
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
352
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
353 uint8_t logo[] = {
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
358 };
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
359 //uint8_t pattern[] = { 0xFF, 0x00, 0x96, 0xFF, 0x00, 0xFF, 0x00 };
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
360
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
361 // Write to page D0
332
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
362 //LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) );
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
363
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
364 for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ )
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
365 {
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
366 LCD_writeDisplayReg( page, &logo[page * LCD_PAGE_LEN], LCD_PAGE_LEN );
2e0074f75855 Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
367 }
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
368 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
369
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
370 void cliFunc_lcdCmd( char* args )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
371 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
372 char* curArgs;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
373 char* arg1Ptr;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
374 char* arg2Ptr = args;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
375
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
376 print( NL ); // No \r\n by default after the command is entered
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
377
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
378 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
379 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
380
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
381 // No args
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
382 if ( *arg1Ptr == '\0' )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
383 return;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
384
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
385 // SPI Command
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
386 uint8_t cmd = (uint8_t)numToInt( arg1Ptr );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
387
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
388 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
389 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
390
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
391 // Single Arg
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
392 if ( *arg1Ptr == '\0' )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
393 goto cmd;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
394
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
395 // TODO Deal with a0
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
396 cmd:
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
397 info_msg("Sending - ");
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
398 printHex( cmd );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
399 print( NL );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
400 LCD_writeControlReg( cmd );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
401 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
402