Background:
I have a cheap game controller that uses some kind of custom communication protocol, the closest I have found similar to it is MicroWire or half-duplex SPI
There are two controllers, one is the primary which connects to a computer over USB, and poll the secondary using what I think a custom protocol.
Of course the two chips are black blobs, so there is no way to get any information about how do they work.
1. There are two wires, clock and data
2. clock and data are idle high
3. primary controller generate the clock (25kHz)
4. when the clock ticks, second controller will take control of the bus and send 8 bytes, sampled on the falling edge
5. then the primary controller takes control and send 2 bytes (mostly to control the rumble motor and perhaps acknowledgment)
6. primary controller will tick twice, so a total of 90 clock cycles
7. idle for 10-13 microsecond, then repeat.
I have successfully mapped all the buttons to individual bits like this:
struct ControllerData {
uint8_t x;
uint8_t y;
uint8_t rx;
uint8_t ry;
uint8_t Key1 : 1;
uint8_t Key2 : 1;
uint8_t Key3 : 1;
uint8_t Key4 : 1;
uint8_t L1 : 1;
uint8_t R1 : 1;
uint8_t L2 : 1;
uint8_t R2 : 1;
uint8_t Start : 1;
uint8_t Select : 1;
uint8_t LThumb : 1;
uint8_t RThumb : 1;
uint8_t Up : 1;
uint8_t Down : 1;
uint8_t Left : 1;
uint8_t Right : 1;
uint8_t _pad0 : 4;
uint8_t curr_mode : 1; // LED on/off
uint8_t _pad1 : 8; // error detection?
uint8_t _pad2 : 3; // // error detection?
};
Can anyone recognize what kind of error detection is this?
my only problem is figuring out what kind of error detection/CRC it uses.
my guess is that the last 8-11 bits are used for that.
I have tried to focus on cases where all the bits are 0 except for a single bit and observe the change, and what I have noticed is that the last 11 bits will change drastically.
mainly these cases:
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB
00 00 00 00 00 01 4A 1F
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 00 40 CA 0A
00 00 00 00 00 80 4A 08
00 00 00 00 01 00 4A 73
00 00 00 00 02 00 4A FB
00 00 00 00 04 00 2A AB
00 00 00 00 08 00 EA 0B
00 00 00 00 10 00 0A 0A
this is all the patterns that I have gathered, it includes almost all possible combinations (single button, multiple buttons, analog sticks, ...etc)
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB
00 00 00 00 00 01 4A 1F
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 00 40 CA 0A
00 00 00 00 00 80 4A 08
00 00 00 00 01 00 4A 73
00 00 00 00 02 00 4A FB
00 00 00 00 04 00 2A AB
00 00 00 00 08 00 EA 0B
00 00 00 00 10 00 0A 0A
00 00 7C 00 00 00 8A 70
00 00 CC 00 00 00 AA 0B
00 00 EC 00 00 00 8A E9
00 00 FC 50 00 00 2A 21
00 00 FC 7C 00 00 2A EC
00 0C FC 00 00 00 2A 12
00 10 FC 00 00 00 8A 9E
00 84 00 48 00 00 8A 3F
00 FC 00 48 00 00 EA 7E
34 84 7C 80 00 64 5A FD
70 84 7C 80 00 00 8A C8
74 00 00 00 00 00 4A F3
74 00 00 68 00 00 AA 21
74 00 00 80 00 00 6A 0F
74 00 7C 80 00 00 8A B4
74 84 00 00 00 00 6A 1A
74 84 00 04 00 00 AA DB
74 84 00 10 00 00 CA DD
74 84 00 50 00 00 EA 03
74 84 00 80 00 00 4A E6
74 84 00 FC 00 00 CA 32
74 84 60 80 00 03 4A BC
74 84 68 80 00 02 CA A0
74 84 7C 00 04 00 CA C1
74 84 7C 80 00 00 9A FD
74 84 7C 80 00 00 AA 5D
74 84 7C 80 00 01 8A 89
74 84 7C 80 00 04 8A CD
74 84 7C 80 00 08 8A 3D
74 84 7C 80 00 10 EA 9D
74 84 7C 80 00 14 CA 0D
74 84 7C 80 00 20 4A 9D
74 84 7C 80 00 30 0A 5D
74 84 7C 80 00 40 0A 9C
74 84 7C 80 00 50 4A 5C
74 84 7C 80 00 60 EA 5C
74 84 7C 80 00 80 8A 9E
74 84 7C 80 00 90 CA 5E
74 84 7C 80 00 98 DA 9E
74 84 7C 80 00 C0 2A 5F
74 84 7C 80 00 F0 8A 5F
74 84 7C 80 01 00 8A E5
74 84 7C 80 01 00 BA 45
74 84 7C 80 01 08 AA 85
74 84 7C 80 02 00 8A 6D
74 84 7C 80 02 08 AA 0D
74 84 7C 80 02 40 2A AC
74 84 7C 80 02 50 6A 6C
74 84 7C 80 02 70 8A AC
74 84 7C 80 03 00 AA D5
74 84 7C 80 03 08 BA 15
74 84 7C 80 04 00 EA 3D
74 84 7C 80 04 08 CA 5D
74 84 7C 80 05 00 CA 85
74 84 7C 80 06 00 CA 0D
74 84 7C 80 06 A0 0A 0E
74 84 7C 80 07 00 EA B5
74 84 7C 80 08 00 2A 9D
74 84 7C 80 08 08 0A FD
74 84 7C 80 09 00 0A 25
74 84 7C 80 09 90 6A 26
74 84 7C 80 0A 00 0A AD
74 84 7C 80 0C 08 7A 3D
74 84 7C 80 0C 90 0A FE
74 84 7C 80 0F 00 6A 75
74 84 7C 80 10 00 CA 9C
74 84 7C FC 00 00 2A 89
74 84 C8 FC 00 00 6A 36
74 84 FC 00 00 00 AA E9
74 84 FC 80 00 00 8A 15
74 84 FC FC 00 00 0A C1
74 FC 7C FC 00 00 4A C8
7C 84 7C 80 00 0C 8A C7
80 FC 7C 80 08 00 4A 87
C8 00 00 FC 00 00 6A 7B
CC 84 00 80 00 00 EA D3
FC 00 00 00 00 00 4A FA
FC 00 00 78 00 00 0A EF
FC 00 00 7C 00 00 CA 2E
FC 00 00 80 00 00 6A 06
FC 00 7C FC 00 00 0A 69
FC 00 84 00 00 00 0A 76
FC 00 FC 00 00 00 8A 09
FC 00 FC 8C 00 00 8A F7
FC 84 00 80 00 00 4A EF
FC 84 7C 80 00 00 AA 54
FC 84 7C 80 00 01 8A 80
FC 84 FC FC 00 00 0A C8
FC FC 00 48 00 00 CA 4F
FC FC 00 FC 00 00 AA 7A
FC FC 7C 80 00 00 CA 15