/*
 * flash.h: flashing user config and system option bytes
 *
 * file creation: 20231019 0129
 */

#ifndef _INC_FLASH_H
#define _INC_FLASH_H



#define FLASH_HSI_4MHz		(uint32_t *)0x1FFF0F1C
#define FLASH_HSI_8MHz		(uint32_t *)0x1FFF0F30
#define FLASH_HSI_16MHz		(uint32_t *)0x1FFF0F44
#define FLASH_HSI_22_12MHz	(uint32_t *)0x1FFF0F58
#define FLASH_HSI_24MHz		(uint32_t *)0x1FFF0F6C


#define UCONF_FLASH_SIZE	512
#define UCONF_FLASH_START	(FLASH_END + 1) - UCONF_FLASH_SIZE

#define UCONF_SIZE			64		// size in bytes
#define UCONF_COUNT			(UCONF_FLASH_SIZE / UCONF_SIZE)

#define UCONF_KEY			0x3713



typedef struct UConf {
	uint16_t conf_key;				// should read 0x3713
	uint8_t  cont_buzzer;			// continuity buzzer on/off
	uint8_t  cont_sensitivity;		// continuity sensitivity high/low
	uint16_t cont_shorted;			// ADC counts when probes shorted in continuity mode
	uint16_t diode_shorted;			// unused, unneeded
	uint32_t rsvd_1[4];
	uint32_t rsvd_2[8];
	uint32_t update_cntr;			// increment every update of config
	uint32_t crc32;					// CRC of preceding 60 bytes
} UConf;							// 64 bytes



extern struct UConf conf;



void flash_init();

void flash_load_conf();
void flash_commit_conf();



#endif /* _INC_FLASH_H */