#ifndef AW410K_H_
#define AW410K_H_

#define LDR_PIN				28
#define LDR_ADC				2

#define AW410K_VID		0x04F2
#define AW410K_PID		0x1968
#define RGB_ITF			1
#define RGB_REPORT_ID	0
#define NUM_KEYS		107
#define BUF_SIZE		64
#define ADC_MAX			4096
#define ADC_MAX_LOG2	log2(ADC_MAX)

enum {
	RGG_MODE_INVALID=0,
	RGB_MODE_SOLID,
	RGB_MODE_ADAPTIVE,
	RGB_MODE_MUTE,
};

struct key {
	unsigned char name[15];
	uint8_t val;
	uint8_t red;
	uint8_t green;
	uint8_t blue;
	uint8_t mode;
};

void get_light();
void rgb_task(uint8_t dev_addr);
void startADC();
bool forward_report(uint8_t instance, uint8_t const* report, uint16_t len);
void parse_colors(char * data, uint16_t len);
void get_color(char * data, uint16_t len);
void save_rgb_config(void);
bool load_rgb_config(void);

#define KEY_ESC			0xB0
#define KEY_F1			0x98
#define KEY_F2			0x90
#define KEY_F3			0x88
#define KEY_F4			0x80
#define KEY_F5			0x70
#define KEY_F6			0x68
#define KEY_F7			0x60
#define KEY_F8			0x58
#define KEY_F9			0x50
#define KEY_F10			0x48
#define KEY_F11			0x40
#define KEY_F12			0x38
#define KEY_SYSRQ		0x30 // printscreen
#define KEY_SCROLLLOCK	0x28
#define KEY_PAUSE		0x20
#define KEY_MUTE		0x18
#define KEY_VOLUMEDOWN	0x10
#define KEY_VOLUMEUP	0x08
#define KEY_GRAVE		0xB1 // ` and ~
#define KEY_1			0xA1
#define KEY_2			0x99
#define KEY_3			0x91
#define KEY_4			0x89
#define KEY_5			0x81
#define KEY_6			0x79
#define KEY_7			0x71
#define KEY_8			0x69
#define KEY_9			0x61
#define KEY_0			0x59
#define KEY_MINUS		0x51
#define KEY_EQUAL		0x49
#define KEY_BACKSPACE	0x39
#define KEY_INSERT		0x31
#define KEY_HOME		0x29
#define KEY_PAGEUP		0x21
#define KEY_NUMLOCK		0x19
#define KEY_KPSLASH		0x11
#define KEY_KPASTERISK	0x09
#define KEY_KPMINUS		0x01
#define KEY_TAB			0xB2
#define KEY_Q			0xA2
#define KEY_W			0x9A
#define KEY_E			0x92
#define KEY_R			0x8A
#define KEY_T			0x82
#define KEY_Y			0x7A
#define KEY_U			0x72
#define KEY_I			0x6A
#define KEY_O			0x62
#define KEY_P			0x5A
#define KEY_LEFTBRACE	0x52
#define KEY_RIGHTBRACE	0x4A
#define KEY_BACKSLASH	0x42
#define KEY_DELETE		0x32
#define KEY_END			0x2A 
#define KEY_PAGEDOWN	0x22
#define KEY_KP7			0x1A
#define KEY_KP8			0x12
#define KEY_KP9			0x0A
#define KEY_KPPLUS		0x03
#define KEY_CAPSLOCK	0xB3
#define KEY_A			0xA3
#define KEY_S			0x9B
#define KEY_D			0x93
#define KEY_F			0x8B
#define KEY_G			0x83
#define KEY_H			0x7B
#define KEY_J			0x73
#define KEY_K			0x6B
#define KEY_L			0x63
#define KEY_SEMICOLON	0x5B
#define KEY_APOSTROPHE	0x53
#define KEY_ENTER		0x43
#define KEY_KP4			0x1B
#define KEY_KP5			0x13
#define KEY_KP6			0x0B
#define KEY_LEFTSHIFT	0xB4
#define KEY_Z			0xA4
#define KEY_X			0x9C
#define KEY_C			0x94
#define KEY_V			0x8C
#define KEY_B			0x84
#define KEY_N			0x7C
#define KEY_M			0x74
#define KEY_COMMA		0x6C
#define KEY_DOT			0x64
#define KEY_SLASH		0x5C
#define KEY_RIGHTSHIFT	0x4C
#define KEY_UP			0x2C
#define KEY_KP1			0x1C
#define KEY_KP2			0x14
#define KEY_KP3			0x0C
#define KEY_KPENTER		0x05
#define KEY_LEFTCTRL	0xB5
#define KEY_LEFTMETA	0xAD
#define KEY_LEFTALT		0xA5
#define KEY_SPACE		0x85
#define KEY_RIGHTALT	0x65
#define KEY_RIGHTMETA	0x5D // FN
#define KEY_MENU		0x55
#define KEY_RIGHTCTRL	0x4D
#define KEY_LEFT		0x35
#define KEY_DOWN		0x2D
#define KEY_RIGHT		0x25
#define KEY_KP0			0x1D
#define KEY_KPDOT		0x0D

#define INIT_KEY(name, code) {name, code, 0x80, 0x80, 0x80, RGB_MODE_ADAPTIVE}
#define INIT_KEY_MUTE(name, code) {name, code, 0x80, 0x80, 0x80, RGB_MODE_MUTE}

#define CFG_SIGNATURE	0xa22e

#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES - FLASH_BLOCK_SIZE - FLASH_SECTOR_SIZE)

#endif
