-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.h
164 lines (151 loc) · 4.11 KB
/
config.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <avr/eeprom.h>
#include <util/crc16.h>
// Include everything for use in configuration
#include "usbemani.h"
#define EEPROM_BYTE(x) (const uint8_t *)(x)
#define EEPROM_WORD(x) (const uint16_t *)(x)
#define EEPROM_ADDR(x) (const void *)(x)
typedef enum {
CONFIG_DATASOURCE_ALWAYS = 0x00, // Index doesn't matter
CONFIG_DATASOURCE_DIGITAL = 0x10, // 0-15
CONFIG_DATASOURCE_ANALOG = 0x20, // 0-11
CONFIG_DATASOURCE_ANALOG_DIGI = 0x30, // 0-11 (+DIGITAL bit)
CONFIG_DATASOURCE_ENCODER = 0x40, // 0-4
CONFIG_DATASOURCE_ENCODER_CCW = 0x50,
CONFIG_DATASOURCE_ENCODER_CW = 0x60,
CONFIG_DATASOURCE_ENCODER_DIR = 0x70,
CONFIG_DATASOURCE_OUTPUT = 0x80, // 0-15
CONFIG_DATASOURCE_INDEX = 0x0F,
CONFIG_DATASOURCE_SOURCE = 0xF0,
CONFIG_DATASOURCE_NC = 0xFF,
} CONFIG_DATASOURCE;
typedef enum {
// Color Providers
CONFIG_COLOR_PROVIDER_HUE = 0,
CONFIG_COLOR_PROVIDER_HUECYCLE,
CONFIG_COLOR_PROVIDER_HUERANDOM,
CONFIG_COLOR_PROVIDER_RAINBOW,
CONFIG_COLOR_PROVIDER = 0x0F,
// Effects
CONFIG_EFFECT_SINGLECOLOR = 0x00,
CONFIG_EFFECT_MULTICOLOR = 0x10,
CONFIG_EFFECT_CYCLEONPRESS = 0x20,
CONFIG_EFFECT_ONLYONPRESS = 0x30,
CONFIG_EFFECT_SPLASH = 0x40,
CONFIG_EFFECT = 0xF0,
} CONFIG_RGB_EFFECT;
typedef enum {
CONFIG_RGB_FRAMEPROCESS_CLEAR,
CONFIG_RGB_FRAMEPROCESS_FADE,
CONFIG_RGB_FRAMEPROCESS_FADERANDOM
} CONFIG_RGB_FRAMEPROCESS;
//// Structs
// Header
typedef struct {
char string[8];
uint16_t crc16_device;
uint16_t crc16_user;
} ConfigHeader_t;
// Device Config
typedef struct {
PS2_PIN pin;
PS2_INVERT invert;
} ConfigDevice_PS2_t;
typedef struct {
RGB_PIN pin;
uint8_t quantity;
} ConfigDevice_RGB_t;
typedef struct {
INPUT_PIN_INDEX pin[16];
} ConfigDevice_Input_t;
typedef struct {
INPUT_PIN_INDEX pin[16];
} ConfigDevice_Output_t;
typedef struct {
INPUT_PIN_INDEX pin_a;
INPUT_PIN_INDEX pin_b;
uint16_t ppr;
} ConfigDevice_Encoder_t;
typedef struct {
ANALOG_PIN_INDEX pin[12];
} ConfigDevice_Analog_t;
typedef struct {
ConfigDevice_PS2_t PS2;
ConfigDevice_RGB_t RGB;
ConfigDevice_Input_t Input;
ConfigDevice_Output_t Output;
ConfigDevice_Encoder_t Encoder[5];
ConfigDevice_Analog_t Analog;
} ConfigDevice_t;
// User Config
typedef struct {
union {
struct { CONFIG_DATASOURCE map[24]; };
struct {
CONFIG_DATASOURCE map_lx_neg;
CONFIG_DATASOURCE map_rx_neg;
CONFIG_DATASOURCE map_ly_neg;
CONFIG_DATASOURCE map_ry_neg;
CONFIG_DATASOURCE map_lx_pos;
CONFIG_DATASOURCE map_rx_pos;
CONFIG_DATASOURCE map_ly_pos;
CONFIG_DATASOURCE map_ry_pos;
CONFIG_DATASOURCE map_button[16];
};
};
} ConfigUser_USBMap_t;
typedef struct {
CONFIG_DATASOURCE source;
PS2_INPUT output;
} ConfigUser_PS2Map_t;
typedef struct {
uint8_t hid_timeout;
CONFIG_DATASOURCE channels[16];
} ConfigUser_Out_t;
typedef struct {
uint16_t hold_time;
uint16_t target_max;
uint16_t target_rot;
} ConfigUser_Encoder_t;
typedef struct {
uint8_t trigger;
uint8_t release;
} ConfigUser_Analog_t;
typedef struct {
CONFIG_RGB_FRAMEPROCESS fade_process;
uint8_t fade_rate;
uint8_t splash_fade_rate;
uint8_t splash_bounds_start;
uint8_t splash_bounds_end;
} ConfigUser_RGB_t;
typedef struct {
CONFIG_DATASOURCE trigger; // Trigger for effect
CONFIG_RGB_EFFECT effect;
uint8_t start;
uint8_t size;
union {
struct { uint8_t hue; uint8_t hue_delta; }; // Hue, HueCycle
struct { uint8_t quantity; CONFIG_DATASOURCE source; }; // RainbowVariable
};
} ConfigUser_Effect_t;
typedef struct {
ConfigUser_USBMap_t USBMap;
ConfigUser_PS2Map_t PS2Map[16];
ConfigUser_Out_t Out;
ConfigUser_Encoder_t Encoder[5];
ConfigUser_Analog_t Analog[12];
ConfigUser_RGB_t RGB;
ConfigUser_Effect_t Effect[32];
} ConfigUser_t;
// Encapsulating Struct
typedef struct {
ConfigHeader_t Header;
ConfigDevice_t Device;
ConfigUser_t User;
} Config_t;
#define CONFIG_HEADER "USBEMANI"
void Config_LoadFromEEPROM(void);