Mercurial > louis > kiibohd-controller
annotate Scan/ISSILed/led_scan.c @ 420:23a1868b4ac2
Adding dynamic USB power support
- Each scan module now has a current change callback which passes the available current as a parameter
- No longer attempts to use the max 500 mA immediately, starts with 100 mA then goes to 500 mA after enumeration
- If enumeration fails due to bMaxPower of 500 mA, then attempt again at 100 mA (might also be possible to go even lower to 20 mA in certain cases)
- Now working with the Apple Ipad (no over-power messages)
- Fixed Wake-up behaviour on Apple Ipad (and likely other iOS devices)
- More effecient set_feature/clear_feature handling (device handler)
- Initial power handling via Interconnect (still needs work to get it more dynamic)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 21 Feb 2016 19:56:52 -0800 |
parents | a3825c7fc651 |
children | cbcdb7a16b7c |
rev | line source |
---|---|
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
1 /* Copyright (C) 2014-2016 by Jacob Alexander |
315
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 | 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 | 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 | 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 | 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 | 396 GPIOB_PDDR |= (1<<16); |
397 PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); | |
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 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
409 // Do not disable software shutdown of ISSI chip unless current is high enough |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
410 // Require at least 150 mA |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
411 // May be enabled/disabled at a later time |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
412 if ( Output_current_available() >= 150 ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
413 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
414 // Disable Software shutdown of ISSI chip |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
415 LED_writeReg( 0x0A, 0x01, 0x0B ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
416 } |
315
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
419 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 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
|
421 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
422 uint8_t reTurn = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
424 // If sendLen is greater than buffer fail right away |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
425 if ( sendLen > buffer->size ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
426 return 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
427 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
428 // 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
|
429 // 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
|
430 // 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
|
431 uint16_t newTail = buffer->tail + sendLen + 2; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
432 if ( newTail >= buffer->size ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
433 newTail -= buffer->size; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
434 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
435 if ( I2C_BufferLen( buffer ) < sendLen + 2 ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
436 return 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
437 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
438 /* |
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 printHex( sendLen + 2 ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
441 print("|"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
442 printHex( *tail ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
443 print("@"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
444 printHex( newTail ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
445 print("@"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 */ |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
448 // If buffer is clean, return 1, otherwise 2 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
449 reTurn = buffer->head == buffer->tail ? 1 : 2; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 // 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
|
452 uint8_t bufferHeaderPos = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
453 for ( uint16_t c = 0; c < sendLen; c++ ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
454 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
455 // Add data to buffer |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
456 switch ( bufferHeaderPos ) |
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 0: |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 buffer->buffer[ buffer->tail ] = recvLen; |
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 case 1: |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
465 buffer->buffer[ buffer->tail ] = sendLen; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
466 bufferHeaderPos++; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
467 c--; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 break; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
469 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 default: |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 buffer->buffer[ buffer->tail ] = data[ c ]; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 break; |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
475 // Check for wrap-around case |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
476 if ( buffer->tail + 1 >= buffer->size ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
478 buffer->tail = 0; |
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 // Normal case |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
481 else |
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 buffer->tail++; |
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 } |
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 return reTurn; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
488 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
489 |
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 inline uint16_t I2C_BufferLen( I2C_Buffer *buffer ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
492 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
493 // Tail >= Head |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
494 if ( buffer->tail >= buffer->head ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
495 return buffer->head + buffer->size - buffer->tail; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
496 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
497 // Head > Tail |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 return buffer->head - buffer->tail; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
499 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
500 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
502 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 { |
331 | 504 dbug_msg("DATA: "); |
505 printHex( byte ); | |
506 | |
315
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
507 // Make sure buffer isn't full |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 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
|
509 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
510 warn_msg("I2C_BufferPush failed, buffer full: "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 printHex( byte ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 return; |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
516 // Check for wrap-around case |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
517 if ( buffer->tail + 1 >= buffer->size ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
518 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
519 buffer->tail = 0; |
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 // Normal case |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
522 else |
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 buffer->tail++; |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
527 // Add byte to buffer |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
528 buffer->buffer[ buffer->tail ] = byte; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 } |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
532 uint8_t I2C_TxBufferPop() |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
533 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
534 // 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
|
535 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
|
536 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 erro_msg("No buffer to pop an entry from... "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 printHex( I2C_TxBuffer.head ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
540 printHex( I2C_TxBuffer.tail ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
541 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 printHex( I2C_TxBuffer.sequencePos ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 print(NL); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
544 return 0xFF; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
545 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
546 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
547 // 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
|
548 if ( I2C_TxBuffer.sequencePos == 0 ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
549 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
550 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
|
551 I2C_RxBuffer.sequencePos = I2C_TxBufferPop(); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
552 I2C_TxBuffer.sequencePos = I2C_TxBufferPop(); |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
555 uint8_t data = I2C_TxBuffer.buffer[ I2C_TxBuffer.head ]; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
556 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
557 // Prune head |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
558 I2C_TxBuffer.head++; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
559 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 // Wrap-around case |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 if ( I2C_TxBuffer.head >= I2C_TxBuffer.size ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
562 I2C_TxBuffer.head = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
563 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
564 // Decrement buffer sequence (until next stop will be sent) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
565 I2C_TxBuffer.sequencePos--; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
566 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
567 /* |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
568 dbug_msg("Popping: "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 printHex( data ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
570 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
571 printHex( I2C_TxBuffer.head ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
572 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
573 printHex( I2C_TxBuffer.tail ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
574 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
575 printHex( I2C_TxBuffer.sequencePos ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
576 print(NL); |
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 return data; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
579 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
580 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
581 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
582 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
|
583 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
584 // Check head and tail pointers |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
585 // If full, return 0 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 // If empty, start up I2C Master Tx |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
587 // 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
|
588 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
|
589 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
590 // Not enough buffer space... |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
591 case 0: |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
592 /* |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 erro_msg("Not enough Tx buffer space... "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
594 printHex( I2C_TxBuffer.head ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
595 print(":"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
596 printHex( I2C_TxBuffer.tail ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 print("+"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
598 printHex( sendLen ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
599 print("|"); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
600 printHex( I2C_TxBuffer.size ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
602 */ |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
603 return 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
604 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
605 // Empty buffer, initialize I2C |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
606 case 1: |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
607 // Clear status flags |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
608 I2C0_S = I2C_S_IICIF | I2C_S_ARBL; |
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 // 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
|
611 if ( I2C0_C1 & I2C_C1_MST ) |
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 // Already the master (ah yeah), send a repeated start |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
614 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
|
615 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
616 // Otherwise, seize control |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
617 else |
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 // Wait...till the master dies |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 while ( I2C0_S & I2C_S_BUSY ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 // 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
|
623 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
|
624 } |
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 // Enable I2C interrupt |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 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
|
628 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 // 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
|
630 I2C0_D = I2C_TxBufferPop(); |
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 return 1; |
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 // Dirty buffer, I2C already initialized |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
636 return 2; |
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 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
640 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
641 // LED State processing loop |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
642 inline uint8_t LED_scan() |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
643 { |
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 // I2C Busy |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
646 // S & I2C_S_BUSY |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
647 //I2C_S_BUSY |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
649 return 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
650 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
652 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
653 // Called by parent Scan Module whenver the available current has changed |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
654 // current - mA |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
655 void LED_currentChange( unsigned int current ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
656 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
657 // TODO dim LEDs in low power mode instead of shutting off |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
658 if ( current < 150 ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
659 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
660 // Enabled Software shutdown of ISSI chip |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
661 LED_writeReg( 0x0A, 0x00, 0x0B ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
662 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
663 else |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
664 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
665 // Disable Software shutdown of ISSI chip |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
666 LED_writeReg( 0x0A, 0x01, 0x0B ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
667 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
668 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
669 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
390
diff
changeset
|
670 |
315
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
671 |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
672 // ----- Capabilities ----- |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
673 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
674 // Basic LED Control Capability |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
675 typedef enum LedControlMode { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
676 // Single LED Modes |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
677 LedControlMode_brightness_decrease, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
678 LedControlMode_brightness_increase, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
679 LedControlMode_brightness_set, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
680 // Set all LEDs (index argument not required) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
681 LedControlMode_brightness_decrease_all, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
682 LedControlMode_brightness_increase_all, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
683 LedControlMode_brightness_set_all, |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
684 } LedControlMode; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
685 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
686 typedef struct LedControl { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
687 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
|
688 uint8_t amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
689 uint16_t index; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
690 } LedControl; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
691 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
692 void LED_control( LedControl *control ) |
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 // 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
|
695 /* |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
696 if ( I2C_TxBuffer.sequencePos > 0 ) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
697 return; |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
698 */ |
384
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 // Configure based upon the given mode |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
701 // TODO Perhaps do gamma adjustment? |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
702 switch ( control->mode ) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
703 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
704 case LedControlMode_brightness_decrease: |
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[ control->index ] -= control->amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
707 break; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
708 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
709 case LedControlMode_brightness_increase: |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
710 // 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
|
711 LED_pageBuffer.buffer[ control->index ] += control->amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
712 break; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
713 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
714 case LedControlMode_brightness_set: |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
715 LED_pageBuffer.buffer[ control->index ] = control->amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
716 break; |
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 case LedControlMode_brightness_decrease_all: |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
719 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
|
720 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
721 // 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
|
722 LED_pageBuffer.buffer[ channel ] -= control->amount; |
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 break; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
725 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
726 case LedControlMode_brightness_increase_all: |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
727 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
|
728 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
729 // 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
|
730 LED_pageBuffer.buffer[ channel ] += control->amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
731 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
732 break; |
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 case LedControlMode_brightness_set_all: |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
735 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
|
736 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
737 LED_pageBuffer.buffer[ channel ] = control->amount; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
738 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
739 break; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
740 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
741 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
742 // Sync LED buffer with ISSI chip buffer |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
743 // TODO Support multiple frames |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
744 LED_pageBuffer.i2c_addr = 0xE8; // Chip 1 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
745 LED_pageBuffer.reg_addr = 0x24; // Brightness section |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
746 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
|
747 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
748 |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
749 uint8_t LED_control_timer = 0; |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
750 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
|
751 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
752 // Display capability name |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
753 if ( stateType == 0xFF && state == 0xFF ) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
754 { |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
755 print("LED_control_capability(mode,amount,index)"); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
756 return; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
757 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
758 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
759 // Only use capability on press |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
760 // TODO Analog |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
761 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
|
762 return; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
763 |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
764 // XXX |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
765 // 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
|
766 // 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
|
767 // 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
|
768 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
769 uint8_t currentTime = (uint8_t)systick_millis_count; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
770 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
|
771 if ( compare < 30 ) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
772 { |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
773 return; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
774 } |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
775 LED_control_timer = currentTime; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
776 |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
777 // Set the input structure |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
778 LedControl *control = (LedControl*)args; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
779 |
390
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
780 // Interconnect broadcasting |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
781 #if defined(ConnectEnabled_define) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
782 uint8_t send_packet = 0; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
783 uint8_t ignore_node = 0; |
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 // 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
|
786 extern uint8_t Connect_id; // connect_scan.c |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
787 uint8_t addr = Connect_id + 1; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
788 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
789 switch ( control->mode ) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
790 { |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
791 // Calculate the led address to send |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
792 // If greater than the Total hannels |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
793 // Set address - Total channels |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
794 // Otherwise, ignore |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
795 case LedControlMode_brightness_decrease: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
796 case LedControlMode_brightness_increase: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
797 case LedControlMode_brightness_set: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
798 // Ignore if led is on this node |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
799 if ( control->index < LED_TotalChannels ) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
800 break; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
801 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
802 // Calculate new led index |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
803 control->index -= LED_TotalChannels; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
804 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
805 ignore_node = 1; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
806 send_packet = 1; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
807 break; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
808 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
809 // Broadcast to all nodes |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
810 // XXX Do not set broadcasting address |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
811 // Will send command twice |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
812 case LedControlMode_brightness_decrease_all: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
813 case LedControlMode_brightness_increase_all: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
814 case LedControlMode_brightness_set_all: |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
815 send_packet = 1; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
816 break; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
817 } |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
818 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
819 // Only send interconnect remote capability packet if necessary |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
820 if ( send_packet ) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
821 { |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
822 // generatedKeymap.h |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
823 extern const Capability CapabilitiesList[]; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
824 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
825 // Broadcast layerStackExact remote capability (0xFF is the broadcast id) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
826 Connect_send_RemoteCapability( |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
827 addr, |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
828 LED_control_capability_index, |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
829 state, |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
830 stateType, |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
831 CapabilitiesList[ LED_control_capability_index ].argCount, |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
832 args |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
833 ); |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
834 } |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
835 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
836 // 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
|
837 if ( ignore_node ) |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
838 return; |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
839 #endif |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
840 |
a3825c7fc651
Adding remote capability LED control
Jacob Alexander <haata@kiibohd.com>
parents:
384
diff
changeset
|
841 // Modify led state of this node |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
842 LED_control( control ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
843 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
844 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
845 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
846 |
315
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
847 // ----- CLI Command Functions ----- |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
848 |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
849 // TODO Currently not working correctly |
315
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
850 void cliFunc_i2cSend( char* args ) |
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 char* curArgs; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
853 char* arg1Ptr; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
854 char* arg2Ptr = args; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
855 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
856 // 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
|
857 // 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
|
858 #define i2cSend_BuffLenMax 8 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
859 uint8_t buffer[ i2cSend_BuffLenMax ]; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
860 uint8_t bufferLen = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
861 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
862 // 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
|
863 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
864 info_msg("Sending: "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
865 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
866 // Parse args until a \0 is found |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
867 while ( bufferLen < i2cSend_BuffLenMax ) |
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 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
|
870 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
871 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
872 // Stop processing args if no more are found |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
873 if ( *arg1Ptr == '\0' ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
874 break; |
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 // If | is found, end sequence and start new one |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
877 if ( *arg1Ptr == '|' ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
878 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
879 print("| "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
880 I2C_Send( buffer, bufferLen, 0 ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
881 bufferLen = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
882 continue; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
883 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
884 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
885 // Interpret the argument |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
886 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
887 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
888 // Print out the arg |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 dPrint( arg1Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
890 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
891 } |
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 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
894 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
895 I2C_Send( buffer, bufferLen, 0 ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
896 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
897 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
898 void cliFunc_i2cRecv( char* args ) |
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 char* curArgs; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
901 char* arg1Ptr; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
902 char* arg2Ptr = args; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
903 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
904 // 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
|
905 // 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
|
906 #define i2cSend_BuffLenMax 8 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
907 uint8_t buffer[ i2cSend_BuffLenMax ]; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
908 uint8_t bufferLen = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
909 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
910 // 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
|
911 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
912 info_msg("Sending: "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
913 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
914 // Parse args until a \0 is found |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
915 while ( bufferLen < i2cSend_BuffLenMax ) |
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 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
|
918 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
919 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
920 // Stop processing args if no more are found |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
921 if ( *arg1Ptr == '\0' ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
922 break; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
923 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
924 // If | is found, end sequence and start new one |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
925 if ( *arg1Ptr == '|' ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
926 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
927 print("| "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
928 I2C_Send( buffer, bufferLen, 0 ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
929 bufferLen = 0; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
930 continue; |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
931 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
932 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
933 // Interpret the argument |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
934 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
935 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
936 // Print out the arg |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
937 dPrint( arg1Ptr ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
938 print(" "); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
939 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
940 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
941 print( NL ); |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
942 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
943 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
|
944 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
945 |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
946 // TODO Currently not working correctly |
356
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
947 void cliFunc_ledRPage( char* args ) |
331 | 948 { |
949 // Parse number from argument | |
950 // NOTE: Only first argument is used | |
951 char* arg1Ptr; | |
952 char* arg2Ptr; | |
953 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | |
954 | |
955 // Default to 0 if no argument is given | |
956 uint8_t page = 0; | |
957 | |
958 if ( arg1Ptr[0] != '\0' ) | |
959 { | |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
960 page = (uint8_t)numToInt( arg1Ptr ); |
331 | 961 } |
962 | |
963 // No \r\n by default after the command is entered | |
964 print( NL ); | |
965 | |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
966 LED_readPage( 0x1, page ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
967 //LED_readPage( 0xB4, page ); |
331 | 968 } |
969 | |
356
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
970 void cliFunc_ledWPage( char* args ) |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
971 { |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
972 char* curArgs; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
973 char* arg1Ptr; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
974 char* arg2Ptr = args; |
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 // First process page and starting address |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
977 curArgs = arg2Ptr; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
978 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
979 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
980 // 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
|
981 if ( *arg1Ptr == '\0' ) |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
982 return; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
983 uint8_t page[] = { 0xE8, 0xFD, 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 curArgs = arg2Ptr; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
986 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
987 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
988 // 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
|
989 if ( *arg1Ptr == '\0' ) |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
990 return; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
991 uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 }; |
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 // Set the register page |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
994 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
|
995 delay(1); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
996 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
997 // Process all args |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
998 for ( ;; ) |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
999 { |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1000 curArgs = arg2Ptr; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1001 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1002 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1003 // 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
|
1004 if ( *arg1Ptr == '\0' ) |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1005 break; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1006 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1007 data[2] = numToInt( arg1Ptr ); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1008 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1009 // Write register location and data to I2C |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1010 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
|
1011 delay(1); |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1012 |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1013 // Increment address |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1014 data[1]++; |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1015 } |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1016 } |
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1017 |
331 | 1018 void cliFunc_ledStart( char* args ) |
1019 { | |
1020 print( NL ); // No \r\n by default after the command is entered | |
1021 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers | |
1022 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers | |
1023 LED_writeReg( 0x0A, 0x01, 0x0B ); | |
356
58d2c5bf95eb
Adding ISSILed API calls and default brightness
Jacob Alexander <haata@kiibohd.com>
parents:
341
diff
changeset
|
1024 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 ); |
331 | 1025 |
1026 } | |
1027 | |
315
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1028 void cliFunc_ledTest( char* args ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1029 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1030 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
|
1031 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
|
1032 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1033 |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1034 void cliFunc_ledZero( char* args ) |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1035 { |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1036 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
|
1037 LED_zeroPages( 0x00, 8, 0x24, 0xB4 ); // Only PWMs |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1038 } |
bcdc04cb8e2e
Initial LED support for ISSI IS31FL3731C
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1039 |
384
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1040 void cliFunc_ledCtrl( char* args ) |
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 char* curArgs; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1043 char* arg1Ptr; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1044 char* arg2Ptr = args; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1045 LedControl control; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1046 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1047 // First process mode |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1048 curArgs = arg2Ptr; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1049 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1050 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1051 // 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
|
1052 if ( *arg1Ptr == '\0' ) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1053 return; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1054 control.mode = numToInt( arg1Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1055 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1056 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1057 // Next process amount |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1058 curArgs = arg2Ptr; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1059 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1060 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1061 // 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
|
1062 if ( *arg1Ptr == '\0' ) |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1063 return; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1064 control.amount = numToInt( arg1Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1065 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1066 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1067 // Finally process led index, if it exists |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1068 // Default to 0 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1069 curArgs = arg2Ptr; |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1070 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1071 control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1072 |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1073 // Process request |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1074 LED_control( &control ); |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1075 } |
82ce1988fefe
Adding basic ISSI led brightness control capabilities
Jacob Alexander <haata@kiibohd.com>
parents:
357
diff
changeset
|
1076 |