Initial support for the ICPad

- Basic support for up to 4 ISSI chips (and partial support for 16 chip configurations)
- Initial USB mux support
  * Required USB re-init procedure
- Initial interconnect mux support
  * Required some state reset commands
This commit is contained in:
Jacob Alexander 2015-11-12 22:21:32 +13:00
parent 11a44f0ea1
commit a25aa84513
16 changed files with 845 additions and 112 deletions

169
Scan/ICPad/defaultMap.kll Normal file
View file

@ -0,0 +1,169 @@
Name = ICPad;
Version = 0.1;
Author = "HaaTa (Jacob Alexander) 2015";
KLL = 0.3d;
# Modified Date
Date = 2015-10-21;
S0x00 : U"Esc";
S0x01 : U"1";
S0x02 : U"2";
S0x03 : U"3";
S0x04 : U"4";
S0x05 : U"5";
S0x06 : U"6";
S0x07 : U"7";
S0x08 : U"8";
S0x09 : U"9";
S0x0A : U"0";
S0x0B : U"Minus";
S0x0C : U"Equal";
S0x0D : U"Hash";
S0x0E : U"Backspace";
S0x0F : U"BackTick";
S0x10 : U"Tab";
S0x11 : U"Q";
S0x12 : U"W";
S0x13 : U"E";
S0x14 : U"R";
S0x15 : U"T";
S0x16 : U"Y";
S0x17 : U"U";
S0x18 : U"I";
S0x19 : U"O";
S0x1A : U"P";
S0x1B : U"LBrace";
S0x1C : U"RBrace";
S0x1D : U"Backslash";
S0x1E : U"Delete";
S0x1F : U"CapsLock";
S0x20 : U"A";
S0x21 : U"S";
S0x22 : U"D";
S0x23 : U"F";
S0x24 : U"G";
S0x25 : U"H";
S0x26 : U"J";
S0x27 : U"K";
S0x28 : U"L";
S0x29 : U"Semicolon";
S0x2A : U"Quote";
S0x2B : U"App";
S0x2C : U"Enter";
S0x2D : U"PageUp";
S0x2E : U"LShift";
S0x2F : U"ISO Slash";
S0x30 : U"Z";
S0x31 : U"X";
S0x32 : U"C";
S0x33 : U"V";
S0x34 : U"B";
S0x35 : U"N";
S0x36 : U"M";
S0x37 : U"Comma";
S0x38 : U"Period";
S0x39 : U"Slash";
S0x3A : U"RShift";
S0x3B : U"Up";
S0x3C : U"PageDown";
S0x3D : U"Ctrl";
S0x3E : U"Function1";
S0x3F : U"LAlt";
S0x40 : U"Space";
S0x41 : U"RAlt";
S0x42 : U"Gui";
S0x43 : U"Menu";
S0x44 : U"Left";
S0x45 : U"Down";
S0x46 : U"Right";
# Defines available to the ICPad Scan Module
# Available ISSI Chips
ISSI_Chips = 2;
# LED Default Enable Mask Override
#
# Each LED is represented by a single bit
# See (http://www.issi.com/WW/pdf/31FL3731C.pdf) for details
ISSILedMask1 = "
0xFF, 0xFF, /* C1-1 -> C1-16 */
0xFE, 0xFE, /* C2-1 -> C2-16 */
0xFE, 0xFE, /* C3-1 -> C3-16 */
0x06, 0x06, /* C4-1 -> C4-16 */
0x00, 0x00, /* C5-1 -> C5-16 */
0x60, 0x60, /* C6-1 -> C6-16 */
0x7F, 0x7F, /* C7-1 -> C7-16 */
0x7F, 0x7F, /* C8-1 -> C8-16 */
0xFF, 0xFF, /* C9-1 -> C9-16 */
";
ISSILedMask2 = "
0xFF, 0x00, /* C1-1 -> C1-16 */
0xFE, 0x00, /* C2-1 -> C2-16 */
0xFE, 0x00, /* C3-1 -> C3-16 */
0x06, 0x00, /* C4-1 -> C4-16 */
0x00, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, /* C6-1 -> C6-16 */
0x0F, 0x00, /* C7-1 -> C7-16 */
0x0F, 0x00, /* C8-1 -> C8-16 */
0x0F, 0x00, /* C9-1 -> C9-16 */
";
# LED Brightness Override
#
# Each LED channel supports 256 levels (8-bit control)
# By default, LEDs are set to 0 brightness
ISSILedBrightness1 = "
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* C1-1 -> C1-16 */
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* C2-1 -> C2-16 */
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* C3-1 -> C3-16 */
0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, /* C6-1 -> C6-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, /* C7-1 -> C7-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, /* C8-1 -> C8-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* C9-1 -> C9-16 */
";
ISSILedBrightness2 = "
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */
0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */
";
# Misc
ISSILedBrightness1 = "
0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, /* C1-1 -> C1-16 */
0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, /* C2-1 -> C2-16 */
0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, /* C3-1 -> C3-16 */
0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, /* C6-1 -> C6-16 */
0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, /* C7-1 -> C7-16 */
0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x00, /* C8-1 -> C8-16 */
0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, /* C9-1 -> C9-16 */
";
ISSILedBrightness2 = "
0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */
0x00, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */
0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */
0x00, 0xA0, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */
0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */
0x44, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */
0x77, 0x77, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */
";

56
Scan/ICPad/matrix.h Normal file
View file

@ -0,0 +1,56 @@
/* Copyright (C) 2014-2015 by Jacob Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// ----- Includes -----
// Project Includes
#include <matrix_setup.h>
// ----- Matrix Definition -----
// Freescale ARM MK20's support GPIO PTA, PTB, PTC, PTD and PTE 0..31
// Not all chips have access to all of these pins (most don't have 160 pins :P)
//
// NOTE:
// Before using a pin, make sure it supports being a GPIO *and* doesn't have a default pull-up/pull-down
// Checking this is completely on the ownness of the user
// MDErgo1
//
// Column (Strobe) - 9 Total
// PTB2,3,18,19
// PTC0,9..11
// PTD0
//
// Rows (Sense) - 5 Total
// PTD1,4..7
// Define Rows (Sense) and Columns (Strobes)
GPIO_Pin Matrix_cols[] = { gpio(B,2), gpio(B,3), gpio(B,18), gpio(B,19), gpio(C,0), gpio(C,8), gpio(C,9), gpio(C,10), gpio(C,11) };
GPIO_Pin Matrix_rows[] = { gpio(D,0), gpio(D,1), gpio(D,4), gpio(D,5), gpio(D,6), gpio(D,7), gpio(C,1), gpio(C,2) };
// Define type of scan matrix
Config Matrix_type = Config_Pulldown;

114
Scan/ICPad/pinout Normal file
View file

@ -0,0 +1,114 @@
Pin Usage
=========
mk20dx256vlh7
----
|Keys|
----
* Strobe (Columns)
PTB2
PTB3
PTB18
PTB19
PTC0
PTC8
PTC9
PTC10
PTC11
* Sense (Rows)
PTD0
PTD1
PTD4
PTD5
PTD6
PTD7
PTC1
PTC2
-----
|Clock|
-----
PTA18 <-> PTA19
---
|I2C|
---
* IS31FL3731C
PTB0 - SCL0 (add header pin, label as SCL0)
PTB1 - SDA0 (add header pin, label as SDA0)
PTB17 - INTB Chip 1
PTB16 - SDB (tied to all Chips, hardware shutdown)
---
|DAC|
---
DAC0 (N/C)
----
|UART|
----
* Comm - For bi-directional communication between halves
PTA1 - RX0 (Master Side)
PTA2 - TX0 (Master Side)
PTE1 - RX1 (Slave Side)
PTE0 - TX1 (Slave Side)
PTD2 - RX2 (UART Debug Header)
PTD3 - TX2 (UART Debug Header)
-----
|Debug|
-----
* SWD - (Main reflash header)
PTA0 (Pull-down)
PTA3 (Pull-up)
* LEDs
PTA5 (LED only for PCB, not Teensy)
* UARTs
PTD2 - RX2 (UART Debug Header, label as RX2)
PTD3 - TX2 (UART Debug Header, label as TX2)
------
|Unused|
------
* GPIO
PTA4
PTA12
PTA13
PTC3
PTC4
PTC5
PTC6
PTC7
* Analog
TODO

106
Scan/ICPad/scan_loop.c Normal file
View file

@ -0,0 +1,106 @@
/* Copyright (C) 2014-2015 by Jacob Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// ----- Includes -----
// Compiler Includes
#include <Lib/ScanLib.h>
// Project Includes
#include <cli.h>
#include <connect_scan.h>
#include <led.h>
#include <led_scan.h>
#include <print.h>
#include <matrix_scan.h>
#include <macro.h>
#include <output_com.h>
#include <port_scan.h>
// Local Includes
#include "scan_loop.h"
// ----- Function Declarations -----
// ----- Variables -----
// Number of scans since the last USB send
uint16_t Scan_scanCount = 0;
// ----- Functions -----
// Setup
inline void Scan_setup()
{
// Setup Port Swap module
Port_setup();
// Setup UART Connect, if Output_Available, this is the master node
Connect_setup( Output_Available );
// Setup GPIO pins for matrix scanning
Matrix_setup();
// Setup ISSI chip to control the leds
LED_setup();
// Reset scan count
Scan_scanCount = 0;
}
// Main Detection Loop
inline uint8_t Scan_loop()
{
// Port Swap detection
Port_scan();
// Scan Matrix
Matrix_scan( Scan_scanCount++ );
// Process any interconnect commands
Connect_scan();
// Process any LED events
LED_scan();
return 0;
}
// Signal from Macro Module that all keys have been processed (that it knows about)
inline void Scan_finishedWithMacro( uint8_t sentKeys )
{
}
// Signal from Output Module that all keys have been processed (that it knows about)
inline void Scan_finishedWithOutput( uint8_t sentKeys )
{
// Reset scan loop indicator (resets each key debounce state)
// TODO should this occur after USB send or Macro processing?
Scan_scanCount = 0;
}

40
Scan/ICPad/scan_loop.h Normal file
View file

@ -0,0 +1,40 @@
/* Copyright (C) 2014-2015 by Jacob Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// ----- Includes -----
// Compiler Includes
#include <stdint.h>
// ----- Functions -----
// Functions to be called by main.c
void Scan_setup( void );
uint8_t Scan_loop( void );
// Call-backs
void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module
void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module

33
Scan/ICPad/setup.cmake Normal file
View file

@ -0,0 +1,33 @@
###| CMake Kiibohd Controller Scan Module |###
#
# Written by Jacob Alexander in 2015 for the Kiibohd Controller
#
# Released into the Public Domain
#
###
###
# Required Sub-modules
#
AddModule ( Scan ISSILed )
AddModule ( Scan MatrixARM )
AddModule ( Scan PortSwap )
AddModule ( Scan UARTConnect )
###
# Module C files
#
set ( Module_SRCS
scan_loop.c
)
###
# Compiler Family Compatibility
#
set ( ModuleCompatibility
arm
)