/*
 * user_config.h
 *
 *  Created on: Jun 12, 2019
 *      Author: true
 */

#ifndef INC_USER_CONFIG_H_
#define INC_USER_CONFIG_H_



#include "math/checksum.h"



// some global options
#define FLASH_RSVD_PAGES				5			// 3 for bootloader, 2 for userdata
#define FLASH_UCONF_BYTES				128			// basically assumed everywhere

#define MISC_WIGGLE_RATE				(7 - 4);
#define MISC_WIGGLE_SHIFT				4

// system state stuff
#define SYS_OLED_ROTATE_X				(1 << 0)
#define SYS_OLED_ROTATE_Y				(1 << 1)
#define SYS_OLED_REVERSE_CHARS			(1 << 2)

// user configuration stuff
#define UCONF_VER						0x01

#define UCONF_FLAGS_AUTOROTATE_ENA		(1 << 0)

#define UCONF_FLAGS_FAVOR_SPEED			(1 << 4)	// todo: increase clock rather than reduce framerate
#define UCONF_FLAGS_LEDS_ENABLE			(1 << 5)
#define UCONF_FLAGS_SHOW_CPU_USAGE		(1 << 6)
#define UCONF_FLAGS_SHOW_ACCEL_ANGLE	(1 << 7)

#define UCONF_FRAMERATE_FULL			64			// this is set/used at runtime, makes no difference in saved config
#define UCONF_FRAMERATE_HALF			128

#define UCONF_NAME_MAXLEN				15

#define UCONF_NAME_MODE_ROTATE180		(1 << 0)	// force flipping the display over
#define UCONF_NAME_MODE_AUTOROTATE		(1 << 1)	// automatically flip the display
#define UCONF_NAME_MODE_HALFWIDTH		(1 << 2)	// render only every other line of fonts
#define UCONF_NAME_MODE_COLOR_INVERT	(1 << 3)	// use pixel invert instead of set

#define UCONF_NAME_DISP_MASK			0x30
#define UCONF_NAME_DISP_COUNT			4
#define UCONF_NAME_DISP_OFFSET			4
#define UCONF_NAME_DISP_STATIC_HORIZ	0x00			// unchanging name
#define UCONF_NAME_DISP_STATIC_VERT		0x10			// unchanging name, each char rotated 90deg
#define UCONF_NAME_DISP_WIGGLE			0x20			// sine-wiggling name
#define UCONF_NAME_DISP_CHAR_ROTATE		0x30			// auto-rotating characters



// this must/should equal 128 bytes for assumptions in code to work out
typedef struct UserConf {
	uint8_t  ver;
	uint16_t iter;
	uint8_t  flags;
	uint8_t  framemod;
	uint8_t  nameconf;
	uint8_t  font_idx;
	int8_t   char_spacing;
	uint8_t  name[UCONF_NAME_MAXLEN + 1];
	uint8_t  name2[UCONF_NAME_MAXLEN + 1];
	uint8_t  favcolor_hue;
	uint8_t  favcolor_sat;
	uint8_t  favcolor_val;
	uint8_t  altcolor_hue;
	uint8_t  altcolor_sat;
	uint8_t  altcolor_val;
	uint8_t  ledprog_active;		// currently used for a single mode
	uint8_t  ledprog[5][14];
	uint8_t  padding[10];
	uint8_t  checksum;
} UserConf;



extern UserConf xdata uconf;
extern uint8_t sysflags;



void uconf_load();
void uconf_write();



#endif /* INC_USER_CONFIG_H_ */
