forked from keyboardio/KeyboardioScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardioScanner.h
73 lines (56 loc) · 1.31 KB
/
KeyboardioScanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <Arduino.h>
#include "wire-protocol-constants.h"
struct cRGB {
uint8_t b;
uint8_t g;
uint8_t r;
};
#define LED_BANKS 4
#define LEDS_PER_HAND 32
#define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND/LED_BANKS
typedef union {
cRGB leds[LEDS_PER_HAND];
byte bytes[LED_BANKS][LED_BYTES_PER_BANK];
} LEDData_t;
// Same datastructure as on the other side
typedef union {
struct {
uint8_t row: 2,
col: 3,
keyState: 1,
keyEventsWaiting: 1,
eventReported: 1;
};
uint8_t val;
} key_t;
typedef union {
uint8_t rows[4];
uint32_t all;
} keydata_t;
// config options
// used to configure interrupts, configuration for a particular controller
class KeyboardioScanner {
public:
KeyboardioScanner(byte setAd01);
~KeyboardioScanner();
int readVersion();
byte setKeyscanInterval(byte delay);
int readKeyscanInterval();
byte setLEDSPIFrequency(byte frequency);
int readLEDSPIFrequency();
void sendLEDData();
void setOneLEDTo(byte led, cRGB color);
void setAllLEDsTo(cRGB color);
keydata_t getKeyData();
bool readKeys();
LEDData_t ledData;
uint8_t controllerAddress();
private:
int addr;
int ad01;
keydata_t keyData;
byte nextLEDBank = 0;
void sendLEDBank(byte bank);
int readRegister(uint8_t cmd);
};