annotate Scan/ISSILed/led_scan.c @ 390:a3825c7fc651

Adding remote capability LED control - Works for all nodes in chain - Synchronized to 30 ms update rate (required for ISSI chip) * Interconnect cannot handle full update speed from Scan module * Though it should be able to handle quite a bit more than 30 ms updates
author Jacob Alexander <haata@kiibohd.com>
date Fri, 16 Oct 2015 10:02:01 -0700
parents 82ce1988fefe
children 23a1868b4ac2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1 /* Copyright (C) 2014-2015 by Jacob Alexander
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
2 *
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 * This file is free software: you can redistribute it and/or modify
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
4 * it under the terms of the GNU General Public License as published by
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
5 * the Free Software Foundation, either version 3 of the License, or
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
6 * (at your option) any later version.
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 *
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8 * This file is distributed in the hope that it will be useful,
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
11 * GNU General Public License for more details.
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
12 *
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
14 * along with this file. If not, see <http://www.gnu.org/licenses/>.
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 */
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 // ----- Includes -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 // Compiler Includes
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 #include <Lib/ScanLib.h>
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // Project Includes
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23 #include <cli.h>
357
86b937945313 Fixing CMake dependency checking for kll_defs.h
Jacob Alexander <haata@kiibohd.com>
parents: 356
diff changeset
24 #include <kll_defs.h>
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 #include <led.h>
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26 #include <print.h>
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
28 // Interconnect module if compiled in
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
29 #if defined(ConnectEnabled_define)
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
30 #include <connect_scan.h>
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
31 #endif
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
32
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 // Local Includes
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34 #include "led_scan.h"
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38 // ----- Defines -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
39
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40 #define I2C_TxBufferLength 300
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41 #define I2C_RxBufferLength 8
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 #define LED_BufferLength 144
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
45 // TODO Needs to be defined per keyboard
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
46 #define LED_TotalChannels 144
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
47
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
48
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
49
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
50 // ----- Structs -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
52 typedef struct I2C_Buffer {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
53 uint16_t head;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
54 uint16_t tail;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55 uint8_t sequencePos;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56 uint16_t size;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57 uint8_t *buffer;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58 } I2C_Buffer;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
59
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60 typedef struct LED_Buffer {
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
61 uint8_t i2c_addr;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
62 uint8_t reg_addr;
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
63 uint8_t buffer[LED_BufferLength];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64 } LED_Buffer;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
65
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
66
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
67
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
68 // ----- Function Declarations -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
69
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70 // CLI Functions
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
71 void cliFunc_i2cRecv ( char* args );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
72 void cliFunc_i2cSend ( char* args );
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
73 void cliFunc_ledCtrl ( char* args );
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
74 void cliFunc_ledRPage( char* args );
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
75 void cliFunc_ledStart( char* args );
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
76 void cliFunc_ledTest ( char* args );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
77 void cliFunc_ledWPage( char* args );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
78 void cliFunc_ledZero ( char* args );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
80 uint8_t I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
82 uint16_t I2C_BufferLen( I2C_Buffer *buffer );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
83 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87 // ----- Variables -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
88
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89 // Scan Module command dictionary
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90 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." );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
92 CLIDict_Entry( ledCtrl, "Basic LED control. Args: <mode> <amount> [<index>]" );
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
93 CLIDict_Entry( ledRPage, "Read the given register page." );
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
94 CLIDict_Entry( ledStart, "Disable software shutdown." );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
95 CLIDict_Entry( ledTest, "Test out the led pages." );
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
96 CLIDict_Entry( ledWPage, "Write to given register page starting at address. i.e. 0x2 0x24 0xF0 0x12" );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100 CLIDict_Item( i2cRecv ),
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101 CLIDict_Item( i2cSend ),
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
102 CLIDict_Item( ledCtrl ),
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
103 CLIDict_Item( ledRPage ),
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
104 CLIDict_Item( ledStart ),
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
105 CLIDict_Item( ledTest ),
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
106 CLIDict_Item( ledWPage ),
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
107 CLIDict_Item( ledZero ),
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
108 { 0, 0, 0 } // Null entry for dictionary end
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
109 };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
110
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
111
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
112
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
113 // Before sending the sequence, I2C_TxBuffer_CurLen is assigned and as each byte is sent, it is decremented
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
114 // Once I2C_TxBuffer_CurLen reaches zero, a STOP on the I2C bus is sent
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
115 volatile uint8_t I2C_TxBufferPtr[ I2C_TxBufferLength ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
116 volatile uint8_t I2C_RxBufferPtr[ I2C_TxBufferLength ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
117
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
118 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
119 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
120
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
121 LED_Buffer LED_pageBuffer;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
122
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
123 // A bit mask determining which LEDs are enabled in the ISSI chip
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
124 const uint8_t LED_ledEnableMask1[] = {
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
125 0xE8, // I2C address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
126 0x00, // Starting register address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
127 ISSILedMask1_define
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
128 };
341
66eccdd9ced5 Code cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
129
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
130 // Default LED brightness
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
131 const uint8_t LED_defaultBrightness1[] = {
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
132 0xE8, // I2C address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
133 0x24, // Starting register address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
134 ISSILedBrightness1_define
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
135 };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
136
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
137
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
138
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
139 // ----- Interrupt Functions -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
140
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
141 void i2c0_isr()
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
142 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
143 cli(); // Disable Interrupts
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
144
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
145 uint8_t status = I2C0_S; // Read I2C Bus status
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
146
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
147 // Master Mode Transmit
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
148 if ( I2C0_C1 & I2C_C1_TX )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
149 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
150 // Check current use of the I2C bus
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
151 // Currently sending data
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
152 if ( I2C_TxBuffer.sequencePos > 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
153 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
154 // Make sure slave sent an ACK
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
155 if ( status & I2C_S_RXAK )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
156 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
157 // NACK Detected, disable interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
158 erro_print("I2C NAK detected...");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
159 I2C0_C1 = I2C_C1_IICEN;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
160
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
161 // Abort Tx Buffer
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
162 I2C_TxBuffer.head = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
163 I2C_TxBuffer.tail = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
164 I2C_TxBuffer.sequencePos = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
165 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
166 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
167 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
168 // Transmit byte
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
169 I2C0_D = I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
170 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
171 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
172 // Receiving data
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
173 else if ( I2C_RxBuffer.sequencePos > 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
174 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
175 // Master Receive, addr sent
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
176 if ( status & I2C_S_ARBL )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
177 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
178 // Arbitration Lost
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
179 erro_print("Arbitration lost...");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
180 // TODO Abort Rx
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
181
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
182 I2C0_C1 = I2C_C1_IICEN;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
183 I2C0_S = I2C_S_ARBL | I2C_S_IICIF; // Clear ARBL flag and interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
184 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
185 if ( status & I2C_S_RXAK )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
186 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
187 // Slave Address NACK Detected, disable interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
188 erro_print("Slave Address I2C NAK detected...");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
189 // TODO Abort Rx
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
190
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
191 I2C0_C1 = I2C_C1_IICEN;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
192 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
193 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
194 {
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
195 dbug_msg("Attempting to read byte - ");
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
196 printHex( I2C_RxBuffer.sequencePos );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
197 print( NL );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
198 I2C0_C1 = I2C_RxBuffer.sequencePos == 1
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
199 ? I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK // Single byte read
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
200 : I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST; // Multi-byte read
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
201 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
202 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
203 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
204 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
205 /*
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
206 dbug_msg("STOP - ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
207 printHex( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
208 print(NL);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
209 */
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
210
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
211 // Delay around STOP to make sure it actually happens...
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
212 delayMicroseconds( 1 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
213 I2C0_C1 = I2C_C1_IICEN; // Send STOP
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
214 delayMicroseconds( 7 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
215
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
216 // If there is another sequence, start sending
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
217 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) < I2C_TxBuffer.size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
218 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
219 // Clear status flags
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
220 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
221
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
222 // Wait...till the master dies
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
223 while ( I2C0_S & I2C_S_BUSY );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
224
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
225 // Enable I2C interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
226 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
227
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
228 // Transmit byte
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
229 I2C0_D = I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
230 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
231 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
232 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
233 // Master Mode Receive
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
234 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
235 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
236 // XXX Do we need to handle 2nd last byte?
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
237 //I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK; // No STOP, Rx, NAK on recv
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
238
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
239 // Last byte
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
240 if ( I2C_TxBuffer.sequencePos <= 1 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
241 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
242 // Change to Tx mode
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
243 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
244
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
245 // Grab last byte
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
246 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
247
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
248 delayMicroseconds( 1 ); // Should be enough time before issuing the stop
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
249 I2C0_C1 = I2C_C1_IICEN; // Send STOP
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
250 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
251 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
252 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
253 // Retrieve data
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
254 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
255 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
256 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
257
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
258 I2C0_S = I2C_S_IICIF; // Clear interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
259
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
260 sei(); // Re-enable Interrupts
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
261 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
262
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
263
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
264
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
265 // ----- Functions -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
266
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
267 inline void I2C_setup()
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
268 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
269 // Enable I2C internal clock
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
270 SIM_SCGC4 |= SIM_SCGC4_I2C0; // Bus 0
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
271
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
272 // External pull-up resistor
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
273 PORTB_PCR0 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
274 PORTB_PCR1 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
275
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
276 // SCL Frequency Divider
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
277 // 400kHz -> 120 (0x85) @ 48 MHz F_BUS
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
278 I2C0_F = 0x85;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
279 I2C0_FLT = 4;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
280 I2C0_C1 = I2C_C1_IICEN;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
281 I2C0_C2 = I2C_C2_HDRS; // High drive select
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
282
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
283 // Enable I2C Interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
284 NVIC_ENABLE_IRQ( IRQ_I2C0 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
285 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
286
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
287 void LED_zeroPages( uint8_t startPage, uint8_t numPages, uint8_t startReg, uint8_t endReg )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
288 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
289 // Page Setup
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
290 uint8_t pageSetup[] = { 0xE8, 0xFD, 0x00 };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
291
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
292 // Max length of a page + chip id + reg start
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
293 uint8_t fullPage[ 0xB4 + 2 ] = { 0 }; // Max size of page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
294 fullPage[0] = 0xE8; // Set chip id
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
295 fullPage[1] = startReg; // Set start reg
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
296
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
297 // Iterate through given pages, zero'ing out the given register regions
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
298 for ( uint8_t page = startPage; page < startPage + numPages; page++ )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
299 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
300 // Set page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
301 pageSetup[2] = page;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
302
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
303 // Setup page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
304 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
305 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
306
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
307 // Zero out page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
308 while ( I2C_Send( fullPage, endReg - startReg + 2, 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
309 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
310 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
311 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
312
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
313 void LED_sendPage( uint8_t *buffer, uint8_t len, uint8_t page )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
314 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
315 // Page Setup
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
316 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
317
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
318 // Setup page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
319 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
320 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
321
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
322 // Write page to I2C Tx Buffer
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
323 while ( I2C_Send( buffer, len, 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
324 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
325
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
326 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
327
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
328 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
329 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
330 // Page Setup
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
331 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
332
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
333 // Reg Write Setup
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
334 uint8_t writeData[] = { 0xE8, reg, val };
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
335
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
336 // Setup page
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
337 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
338 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
339
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
340 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
341 delay(1);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
342 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
343
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
344 void LED_readPage( uint8_t len, uint8_t page )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
345 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
346 // Software shutdown must be enabled to read registers
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
347 LED_writeReg( 0x0A, 0x00, 0x0B );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
348
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
349 // Page Setup
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
350 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
351
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
352 // Setup page
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
353 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
354 delay(1);
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
355
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
356 // Register Setup
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
357 uint8_t regSetup[] = { 0xE8, 0x00 };
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
358
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
359 // Read each register in the page
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
360 for ( uint8_t reg = 0; reg < len; reg++ )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
361 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
362 // Update register to read
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
363 regSetup[1] = reg;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
364
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
365 // Configure register
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
366 while ( I2C_Send( regSetup, sizeof( regSetup ), 0 ) == 0 )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
367 delay(1);
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
368
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
369 // Register Read Command
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
370 uint8_t regReadCmd[] = { 0xE9 };
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
371
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
372 // Request single register byte
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
373 while ( I2C_Send( regReadCmd, sizeof( regReadCmd ), 1 ) == 0 )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
374 delay(1);
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
375 dbug_print("NEXT");
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
376 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
377
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
378 // Disable software shutdown
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
379 LED_writeReg( 0x0A, 0x01, 0x0B );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
380 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
381
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
382 // Setup
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
383 inline void LED_setup()
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
384 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
385 // Register Scan CLI dictionary
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
386 CLI_registerDictionary( ledCLIDict, ledCLIDictName );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
387
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
388 // Initialize I2C
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
389 I2C_setup();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
390
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
391 // Zero out Frame Registers
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
392 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
393 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
394
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
395 // Disable Hardware shutdown of ISSI chip (pull high)
341
66eccdd9ced5 Code cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
396 GPIOB_PDDR |= (1<<16);
66eccdd9ced5 Code cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
397 PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
66eccdd9ced5 Code cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 331
diff changeset
398 GPIOB_PSOR |= (1<<16);
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
399
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
400 // Clear LED Pages
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
401 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
402
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
403 // Enable LEDs based upon mask
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
404 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
405
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
406 // Set default brightness
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
407 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
408
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
409 // Disable Software shutdown of ISSI chip
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
410 LED_writeReg( 0x0A, 0x01, 0x0B );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
411 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
412
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
413
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
414 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
415 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
416 uint8_t reTurn = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
417
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
418 // If sendLen is greater than buffer fail right away
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
419 if ( sendLen > buffer->size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
420 return 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
421
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
422 // Calculate new tail to determine if buffer has enough space
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
423 // The first element specifies the expected number of bytes from the slave (+1)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
424 // The second element in the new buffer is the length of the buffer sequence (+1)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
425 uint16_t newTail = buffer->tail + sendLen + 2;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
426 if ( newTail >= buffer->size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
427 newTail -= buffer->size;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
428
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
429 if ( I2C_BufferLen( buffer ) < sendLen + 2 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
430 return 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
431
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
432 /*
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
433 print("|");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
434 printHex( sendLen + 2 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
435 print("|");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
436 printHex( *tail );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
437 print("@");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
438 printHex( newTail );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
439 print("@");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
440 */
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
441
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
442 // If buffer is clean, return 1, otherwise 2
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
443 reTurn = buffer->head == buffer->tail ? 1 : 2;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
444
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
445 // Add to buffer, already know there is enough room (simplifies adding logic)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
446 uint8_t bufferHeaderPos = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
447 for ( uint16_t c = 0; c < sendLen; c++ )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
448 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
449 // Add data to buffer
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
450 switch ( bufferHeaderPos )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
451 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
452 case 0:
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
453 buffer->buffer[ buffer->tail ] = recvLen;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
454 bufferHeaderPos++;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
455 c--;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
456 break;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
457
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
458 case 1:
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
459 buffer->buffer[ buffer->tail ] = sendLen;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
460 bufferHeaderPos++;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
461 c--;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
462 break;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
463
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
464 default:
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
465 buffer->buffer[ buffer->tail ] = data[ c ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
466 break;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
467 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
468
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
469 // Check for wrap-around case
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
470 if ( buffer->tail + 1 >= buffer->size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
471 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
472 buffer->tail = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
473 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
474 // Normal case
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
475 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
476 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
477 buffer->tail++;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
478 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
479 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
480
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
481 return reTurn;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
482 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
483
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
484
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
485 inline uint16_t I2C_BufferLen( I2C_Buffer *buffer )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
486 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
487 // Tail >= Head
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
488 if ( buffer->tail >= buffer->head )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
489 return buffer->head + buffer->size - buffer->tail;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
490
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
491 // Head > Tail
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
492 return buffer->head - buffer->tail;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
493 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
494
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
495
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
496 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
497 {
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
498 dbug_msg("DATA: ");
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
499 printHex( byte );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
500
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
501 // Make sure buffer isn't full
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
502 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
503 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
504 warn_msg("I2C_BufferPush failed, buffer full: ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
505 printHex( byte );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
506 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
507 return;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
508 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
509
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
510 // Check for wrap-around case
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
511 if ( buffer->tail + 1 >= buffer->size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
512 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
513 buffer->tail = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
514 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
515 // Normal case
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
516 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
517 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
518 buffer->tail++;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
519 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
520
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
521 // Add byte to buffer
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
522 buffer->buffer[ buffer->tail ] = byte;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
523 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
524
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
525
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
526 uint8_t I2C_TxBufferPop()
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
527 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
528 // Return 0xFF if no buffer left (do not rely on this)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
529 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) >= I2C_TxBuffer.size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
530 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
531 erro_msg("No buffer to pop an entry from... ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
532 printHex( I2C_TxBuffer.head );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
533 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
534 printHex( I2C_TxBuffer.tail );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
535 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
536 printHex( I2C_TxBuffer.sequencePos );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
537 print(NL);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
538 return 0xFF;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
539 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
540
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
541 // If there is currently no sequence being sent, the first entry in the RingBuffer is the length
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
542 if ( I2C_TxBuffer.sequencePos == 0 )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
543 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
544 I2C_TxBuffer.sequencePos = 0xFF; // So this doesn't become an infinite loop
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
545 I2C_RxBuffer.sequencePos = I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
546 I2C_TxBuffer.sequencePos = I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
547 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
548
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
549 uint8_t data = I2C_TxBuffer.buffer[ I2C_TxBuffer.head ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
550
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
551 // Prune head
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
552 I2C_TxBuffer.head++;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
553
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
554 // Wrap-around case
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
555 if ( I2C_TxBuffer.head >= I2C_TxBuffer.size )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
556 I2C_TxBuffer.head = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
557
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
558 // Decrement buffer sequence (until next stop will be sent)
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
559 I2C_TxBuffer.sequencePos--;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
560
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
561 /*
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
562 dbug_msg("Popping: ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
563 printHex( data );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
564 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
565 printHex( I2C_TxBuffer.head );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
566 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
567 printHex( I2C_TxBuffer.tail );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
568 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
569 printHex( I2C_TxBuffer.sequencePos );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
570 print(NL);
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
571 */
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
572 return data;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
573 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
574
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
575
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
576 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
577 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
578 // Check head and tail pointers
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
579 // If full, return 0
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
580 // If empty, start up I2C Master Tx
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
581 // If buffer is non-empty and non-full, just append to the buffer
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
582 switch ( I2C_BufferCopy( data, sendLen, recvLen, (I2C_Buffer*)&I2C_TxBuffer ) )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
583 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
584 // Not enough buffer space...
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
585 case 0:
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
586 /*
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
587 erro_msg("Not enough Tx buffer space... ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
588 printHex( I2C_TxBuffer.head );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
589 print(":");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
590 printHex( I2C_TxBuffer.tail );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
591 print("+");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
592 printHex( sendLen );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
593 print("|");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
594 printHex( I2C_TxBuffer.size );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
595 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
596 */
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
597 return 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
598
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
599 // Empty buffer, initialize I2C
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
600 case 1:
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
601 // Clear status flags
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
602 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
603
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
604 // Check to see if we already have control of the bus
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
605 if ( I2C0_C1 & I2C_C1_MST )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
606 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
607 // Already the master (ah yeah), send a repeated start
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
608 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_RSTA | I2C_C1_TX;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
609 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
610 // Otherwise, seize control
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
611 else
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
612 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
613 // Wait...till the master dies
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
614 while ( I2C0_S & I2C_S_BUSY );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
615
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
616 // Now we're the master (ah yisss), get ready to send stuffs
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
617 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
618 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
619
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
620 // Enable I2C interrupt
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
621 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
622
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
623 // Depending on what type of transfer, the first byte is configured for R or W
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
624 I2C0_D = I2C_TxBufferPop();
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
625
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
626 return 1;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
627 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
628
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
629 // Dirty buffer, I2C already initialized
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
630 return 2;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
631 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
632
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
633
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
634
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
635 // LED State processing loop
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
636 inline uint8_t LED_scan()
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
637 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
638
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
639 // I2C Busy
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
640 // S & I2C_S_BUSY
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
641 //I2C_S_BUSY
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
642
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
643 return 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
644 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
645
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
646
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
647
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
648 // ----- Capabilities -----
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
649
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
650 // Basic LED Control Capability
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
651 typedef enum LedControlMode {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
652 // Single LED Modes
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
653 LedControlMode_brightness_decrease,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
654 LedControlMode_brightness_increase,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
655 LedControlMode_brightness_set,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
656 // Set all LEDs (index argument not required)
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
657 LedControlMode_brightness_decrease_all,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
658 LedControlMode_brightness_increase_all,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
659 LedControlMode_brightness_set_all,
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
660 } LedControlMode;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
661
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
662 typedef struct LedControl {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
663 LedControlMode mode; // XXX Make sure to adjust the .kll capability if this variable is larger than 8 bits
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
664 uint8_t amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
665 uint16_t index;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
666 } LedControl;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
667
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
668 void LED_control( LedControl *control )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
669 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
670 // Only send if we've completed all other transactions
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
671 /*
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
672 if ( I2C_TxBuffer.sequencePos > 0 )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
673 return;
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
674 */
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
675
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
676 // Configure based upon the given mode
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
677 // TODO Perhaps do gamma adjustment?
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
678 switch ( control->mode )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
679 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
680 case LedControlMode_brightness_decrease:
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
681 // Don't worry about rolling over, the cycle is quick
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
682 LED_pageBuffer.buffer[ control->index ] -= control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
683 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
684
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
685 case LedControlMode_brightness_increase:
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
686 // Don't worry about rolling over, the cycle is quick
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
687 LED_pageBuffer.buffer[ control->index ] += control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
688 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
689
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
690 case LedControlMode_brightness_set:
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
691 LED_pageBuffer.buffer[ control->index ] = control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
692 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
693
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
694 case LedControlMode_brightness_decrease_all:
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
695 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
696 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
697 // Don't worry about rolling over, the cycle is quick
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
698 LED_pageBuffer.buffer[ channel ] -= control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
699 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
700 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
701
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
702 case LedControlMode_brightness_increase_all:
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
703 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
704 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
705 // Don't worry about rolling over, the cycle is quick
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
706 LED_pageBuffer.buffer[ channel ] += control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
707 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
708 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
709
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
710 case LedControlMode_brightness_set_all:
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
711 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
712 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
713 LED_pageBuffer.buffer[ channel ] = control->amount;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
714 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
715 break;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
716 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
717
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
718 // Sync LED buffer with ISSI chip buffer
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
719 // TODO Support multiple frames
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
720 LED_pageBuffer.i2c_addr = 0xE8; // Chip 1
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
721 LED_pageBuffer.reg_addr = 0x24; // Brightness section
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
722 LED_sendPage( (uint8_t*)&LED_pageBuffer, sizeof( LED_Buffer ), 0 );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
723 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
724
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
725 uint8_t LED_control_timer = 0;
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
726 void LED_control_capability( uint8_t state, uint8_t stateType, uint8_t *args )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
727 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
728 // Display capability name
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
729 if ( stateType == 0xFF && state == 0xFF )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
730 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
731 print("LED_control_capability(mode,amount,index)");
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
732 return;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
733 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
734
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
735 // Only use capability on press
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
736 // TODO Analog
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
737 if ( stateType == 0x00 && state == 0x03 ) // Not on release
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
738 return;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
739
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
740 // XXX
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
741 // ISSI Chip locks up if we spam updates too quickly (might be an I2C bug on this side too -HaaTa)
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
742 // Make sure we only send an update every 30 milliseconds at most
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
743 // It may be possible to optimize speed even further, but will likely require serious time with a logic analyzer
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
744
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
745 uint8_t currentTime = (uint8_t)systick_millis_count;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
746 int8_t compare = (int8_t)(currentTime - LED_control_timer) & 0x7F;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
747 if ( compare < 30 )
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
748 {
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
749 return;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
750 }
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
751 LED_control_timer = currentTime;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
752
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
753 // Set the input structure
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
754 LedControl *control = (LedControl*)args;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
755
390
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
756 // Interconnect broadcasting
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
757 #if defined(ConnectEnabled_define)
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
758 uint8_t send_packet = 0;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
759 uint8_t ignore_node = 0;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
760
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
761 // By default send to the *next* node, which will determine where to go next
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
762 extern uint8_t Connect_id; // connect_scan.c
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
763 uint8_t addr = Connect_id + 1;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
764
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
765 switch ( control->mode )
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
766 {
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
767 // Calculate the led address to send
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
768 // If greater than the Total hannels
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
769 // Set address - Total channels
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
770 // Otherwise, ignore
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
771 case LedControlMode_brightness_decrease:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
772 case LedControlMode_brightness_increase:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
773 case LedControlMode_brightness_set:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
774 // Ignore if led is on this node
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
775 if ( control->index < LED_TotalChannels )
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
776 break;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
777
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
778 // Calculate new led index
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
779 control->index -= LED_TotalChannels;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
780
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
781 ignore_node = 1;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
782 send_packet = 1;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
783 break;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
784
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
785 // Broadcast to all nodes
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
786 // XXX Do not set broadcasting address
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
787 // Will send command twice
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
788 case LedControlMode_brightness_decrease_all:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
789 case LedControlMode_brightness_increase_all:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
790 case LedControlMode_brightness_set_all:
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
791 send_packet = 1;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
792 break;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
793 }
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
794
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
795 // Only send interconnect remote capability packet if necessary
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
796 if ( send_packet )
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
797 {
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
798 // generatedKeymap.h
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
799 extern const Capability CapabilitiesList[];
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
800
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
801 // Broadcast layerStackExact remote capability (0xFF is the broadcast id)
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
802 Connect_send_RemoteCapability(
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
803 addr,
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
804 LED_control_capability_index,
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
805 state,
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
806 stateType,
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
807 CapabilitiesList[ LED_control_capability_index ].argCount,
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
808 args
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
809 );
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
810 }
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
811
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
812 // If there is nothing to do on this node, ignore
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
813 if ( ignore_node )
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
814 return;
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
815 #endif
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
816
a3825c7fc651 Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents: 384
diff changeset
817 // Modify led state of this node
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
818 LED_control( control );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
819 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
820
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
821
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
822
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
823 // ----- CLI Command Functions -----
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
824
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
825 // TODO Currently not working correctly
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
826 void cliFunc_i2cSend( char* args )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
827 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
828 char* curArgs;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
829 char* arg1Ptr;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
830 char* arg2Ptr = args;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
831
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
832 // Buffer used after interpretting the args, will be sent to I2C functions
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
833 // NOTE: Limited to 8 bytes currently (can be increased if necessary
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
834 #define i2cSend_BuffLenMax 8
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
835 uint8_t buffer[ i2cSend_BuffLenMax ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
836 uint8_t bufferLen = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
837
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
838 // No \r\n by default after the command is entered
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
839 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
840 info_msg("Sending: ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
841
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
842 // Parse args until a \0 is found
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
843 while ( bufferLen < i2cSend_BuffLenMax )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
844 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
845 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
846 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
847
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
848 // Stop processing args if no more are found
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
849 if ( *arg1Ptr == '\0' )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
850 break;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
851
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
852 // If | is found, end sequence and start new one
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
853 if ( *arg1Ptr == '|' )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
854 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
855 print("| ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
856 I2C_Send( buffer, bufferLen, 0 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
857 bufferLen = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
858 continue;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
859 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
860
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
861 // Interpret the argument
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
862 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
863
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
864 // Print out the arg
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
865 dPrint( arg1Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
866 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
867 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
868
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
869 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
870
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
871 I2C_Send( buffer, bufferLen, 0 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
872 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
873
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
874 void cliFunc_i2cRecv( char* args )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
875 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
876 char* curArgs;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
877 char* arg1Ptr;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
878 char* arg2Ptr = args;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
879
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
880 // Buffer used after interpretting the args, will be sent to I2C functions
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
881 // NOTE: Limited to 8 bytes currently (can be increased if necessary
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
882 #define i2cSend_BuffLenMax 8
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
883 uint8_t buffer[ i2cSend_BuffLenMax ];
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
884 uint8_t bufferLen = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
885
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
886 // No \r\n by default after the command is entered
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
887 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
888 info_msg("Sending: ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
889
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
890 // Parse args until a \0 is found
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
891 while ( bufferLen < i2cSend_BuffLenMax )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
892 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
893 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
894 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
895
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
896 // Stop processing args if no more are found
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
897 if ( *arg1Ptr == '\0' )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
898 break;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
899
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
900 // If | is found, end sequence and start new one
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
901 if ( *arg1Ptr == '|' )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
902 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
903 print("| ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
904 I2C_Send( buffer, bufferLen, 0 );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
905 bufferLen = 0;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
906 continue;
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
907 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
908
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
909 // Interpret the argument
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
910 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
911
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
912 // Print out the arg
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
913 dPrint( arg1Ptr );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
914 print(" ");
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
915 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
916
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
917 print( NL );
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
918
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
919 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
920 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
921
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
922 // TODO Currently not working correctly
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
923 void cliFunc_ledRPage( char* args )
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
924 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
925 // Parse number from argument
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
926 // NOTE: Only first argument is used
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
927 char* arg1Ptr;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
928 char* arg2Ptr;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
929 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
930
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
931 // Default to 0 if no argument is given
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
932 uint8_t page = 0;
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
933
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
934 if ( arg1Ptr[0] != '\0' )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
935 {
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
936 page = (uint8_t)numToInt( arg1Ptr );
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
937 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
938
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
939 // No \r\n by default after the command is entered
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
940 print( NL );
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
941
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
942 LED_readPage( 0x1, page );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
943 //LED_readPage( 0xB4, page );
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
944 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
945
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
946 void cliFunc_ledWPage( char* args )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
947 {
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
948 char* curArgs;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
949 char* arg1Ptr;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
950 char* arg2Ptr = args;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
951
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
952 // First process page and starting address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
953 curArgs = arg2Ptr;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
954 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
955
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
956 // Stop processing args if no more are found
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
957 if ( *arg1Ptr == '\0' )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
958 return;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
959 uint8_t page[] = { 0xE8, 0xFD, numToInt( arg1Ptr ) };
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
960
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
961 curArgs = arg2Ptr;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
962 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
963
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
964 // Stop processing args if no more are found
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
965 if ( *arg1Ptr == '\0' )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
966 return;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
967 uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 };
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
968
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
969 // Set the register page
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
970 while ( I2C_Send( page, sizeof( page ), 0 ) == 0 )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
971 delay(1);
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
972
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
973 // Process all args
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
974 for ( ;; )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
975 {
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
976 curArgs = arg2Ptr;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
977 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
978
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
979 // Stop processing args if no more are found
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
980 if ( *arg1Ptr == '\0' )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
981 break;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
982
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
983 data[2] = numToInt( arg1Ptr );
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
984
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
985 // Write register location and data to I2C
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
986 while ( I2C_Send( data, sizeof( data ), 0 ) == 0 )
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
987 delay(1);
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
988
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
989 // Increment address
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
990 data[1]++;
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
991 }
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
992 }
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
993
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
994 void cliFunc_ledStart( char* args )
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
995 {
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
996 print( NL ); // No \r\n by default after the command is entered
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
997 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
998 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
999 LED_writeReg( 0x0A, 0x01, 0x0B );
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
1000 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
331
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
1001
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
1002 }
9e31d92caf12 Initial STLcd code.
Jacob Alexander <haata@kiibohd.com>
parents: 330
diff changeset
1003
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1004 void cliFunc_ledTest( char* args )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1005 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1006 print( NL ); // No \r\n by default after the command is entered
356
58d2c5bf95eb Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
1007 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
315
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1008 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1009
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1010 void cliFunc_ledZero( char* args )
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1011 {
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1012 print( NL ); // No \r\n by default after the command is entered
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1013 LED_zeroPages( 0x00, 8, 0x24, 0xB4 ); // Only PWMs
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1014 }
bcdc04cb8e2e Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1015
384
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1016 void cliFunc_ledCtrl( char* args )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1017 {
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1018 char* curArgs;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1019 char* arg1Ptr;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1020 char* arg2Ptr = args;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1021 LedControl control;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1022
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1023 // First process mode
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1024 curArgs = arg2Ptr;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1025 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1026
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1027 // Stop processing args if no more are found
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1028 if ( *arg1Ptr == '\0' )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1029 return;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1030 control.mode = numToInt( arg1Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1031
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1032
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1033 // Next process amount
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1034 curArgs = arg2Ptr;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1035 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1036
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1037 // Stop processing args if no more are found
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1038 if ( *arg1Ptr == '\0' )
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1039 return;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1040 control.amount = numToInt( arg1Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1041
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1042
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1043 // Finally process led index, if it exists
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1044 // Default to 0
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1045 curArgs = arg2Ptr;
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1046 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1047 control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1048
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1049 // Process request
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1050 LED_control( &control );
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1051 }
82ce1988fefe Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents: 357
diff changeset
1052