Compare commits

..

No commits in common. "ea3f6ae9e0b622f0d2b54b1d43873bee5c811af7" and "917d2b43615f8a347ddac74ee3716e637ffe72e0" have entirely different histories.

17 changed files with 91 additions and 220 deletions

View File

@ -22,9 +22,9 @@
* - there is no ack on address. code always assumes slave is responding.
*/
#define i2c_init() i2cm_init()
#define i2c_start() { SetSysClock(SYSCLK_FREQ_USEI2C); i2cm_start(); }
#define i2c_start() SetSysClock(SYSCLK_FREQ_USEI2C); i2cm_start()
#define i2c_restart() i2cm_restart()
#define i2c_stop() { i2cm_stop(); SetSysClock(SYSCLK_FREQ_NORMAL); }
#define i2c_stop() SetSysClock(SYSCLK_FREQ_NORMAL); i2cm_stop()
#define i2c_rd(ack) i2cm_rd(ack)
#define i2c_wr(dat) i2cm_wr(dat)
#define i2c_addr(a, w) i2c_start(); i2cm_addr(a, w)

View File

@ -184,9 +184,8 @@ uint8_t i2cm_wr(uint8_t dat)
SCL_OUTLO(); bit_delay_lo();
}
SDA_IN_HI(); __nop(); // slave will now try to ack
SDA_IN_HI();
SCL_IN_HI(); bit_delay_hi();
while (!SCL_GET()); // nothing should stretch here, but...
ack = SDA_GET();

View File

@ -58,7 +58,7 @@ uint8_t eep16_is_ready()
uint8_t ack;
i2c_start();
ack = i2c_wr(EEPROM_I2C_ADDR | 0);
ack = i2c_wr(EEPROM_I2C_ADDR | 1);
i2c_stop();
if (ack) return 0;

View File

@ -85,21 +85,6 @@ void btn_commit_hold()
ch32sub_write(REG_BTN1_REPEAT_HI, val, sizeof(val));
}
int8_t btn_get_idx(uint8_t map_idx)
{
uint8_t *map;
if (map_idx >= BTN_COUNT) return -1;
if (sysflags & SYS_OLED_ROTATE_X) {
map = btn_map_rot;
} else {
map = btn_map_upr;
}
return map[map_idx] & 0x7f;
}
__HIGH_CODE
void btn_intr()

View File

@ -39,8 +39,6 @@ extern uint8_t btn_held;
void btn_intr();
void btn_commit_hold();
int8_t btn_get_idx(uint8_t map_idx);
#endif /* USER_UI_BTN_H_ */

View File

@ -1,5 +1,5 @@
/*
* menu.h
* $Id: menu.h 495 2021-07-22 20:53:39Z true $
* begin 20190527 true
*/
@ -82,12 +82,12 @@ void menu_0_disp(uint8_t idx);
void menu_0_enter(uint8_t idx);
// menu_1_name
extern const MenuItem menu_1_name_setup;
extern const MenuItem menu_1;
void menu_1_disp(uint8_t idx);
void menu_1_enter(uint8_t idx);
// menu_2_led
extern const MenuItem menu_2_led_setup;
extern const MenuItem menu_2;
void menu_2_disp(uint8_t idx);
void menu_2_enter(uint8_t idx);
@ -96,12 +96,12 @@ extern const MenuItem menu_3_snek;
void snek_disp(uint8_t idx);
// menu_5_options
extern const MenuItem menu_5_options;
extern const MenuItem menu_5;
void menu_5_disp(uint8_t idx);
void menu_5_enter(uint8_t idx);
// menu_6_about
extern const MenuItem menu_6_about;
extern const MenuItem menu_6;
void menu_6_disp(uint8_t idx);

View File

@ -26,10 +26,10 @@ void menu_tick()
menu->dispfn(menu_idx);
// // do we flip the display?
if ((menu == &menu_6_about) && (menu_idx == 5)) { // about > accelerometer
if ((menu == &menu_6) && (menu_idx == 5)) { // about > accelerometer
// accelerometer page never flips
ssd1306_set_flipmirror(0);
} else if (menu != &menu_none) { // not nametag
} else if (menu != &menu_none) { // not nametag
if (sysflags & SYS_OLED_ROTATE_X) {
ssd1306_set_flipmirror(1);
} else {
@ -173,8 +173,8 @@ void menu_draw_buttons(uint8_t mode, uint8_t mask)
case MENU_BTNSTYLE_MAIN: {
switch (mask) {
case 0: strcpy(button_txt[1], "Resume"); break;
//case 3:
//case 4: strcpy(button_txt[1], "Play"); break;
case 3:
case 4: strcpy(button_txt[1], "Play"); break;
default: strcpy(button_txt[1], "Select"); break;
}
strcpy(button_txt[3], " ");

View File

@ -15,31 +15,31 @@
const MenuItem menu_none = {1, 0, 0, 0, &menu_none_disp, &menu_start};
// root menu
// exit (nametag), name setup, led setup, messages, i2c sniffer, options, about
// exit, snek, morble, set name, leds, options, about
const MenuItem menu_0 = {7, MENU_FLAG_SCROLL,
0, 0, &menu_0_disp, &menu_0_enter};
// name menu
// set name, display mode, flip mode, font select, char spacing, y-offset, half-width, color invert
const MenuItem menu_1_name_setup = {8, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
const MenuItem menu_1 = {8, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
(MenuItem *)&menu_0, 1, &menu_1_disp, &menu_1_enter};
// led menu
// edge mode, edge setup, eyes mode, eyes setup, favcolor hue, sat, val, altcolor hue, sat, val
const MenuItem menu_2_led_setup = {10, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
const MenuItem menu_2 = {10, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
(MenuItem *)&menu_0, 2, &menu_2_disp, &menu_2_enter};
// snek menu
//const MenuItem menu_3_snek = {1, MENU_FLAG_NONE, //MENU_FLAG_SAVE_ON_EXIT,
// (MenuItem *)&menu_0, 3, &snek_disp, NULL};
const MenuItem menu_3_snek = {1, MENU_FLAG_NONE, //MENU_FLAG_SAVE_ON_EXIT,
(MenuItem *)&menu_0, 3, &snek_disp, NULL};
// options menu
// leds on/off, sleep time, dim time, sleep threshold, wake threshold, recal lightsense, factory reset, show cpu usage, show accel "angle",
const MenuItem menu_5_options = {9, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
// leds on/off, sleep on/off, sleep threshold, wake threshold, recal lightsense, factory reset, show cpu usage, show accel "angle",
const MenuItem menu_5 = {8, MENU_FLAG_SCROLL | MENU_FLAG_SAVE_ON_EXIT,
(MenuItem *)&menu_0, 5, &menu_5_disp, &menu_5_enter};
// about menu
// credits, leds, leds, leds, accel, cpu usage/uptime, light/temp, errors, font test
const MenuItem menu_6_about = {9, MENU_FLAG_SCROLL,
const MenuItem menu_6 = {10, MENU_FLAG_SCROLL,
(MenuItem *)&menu_0, 6, &menu_6_disp, 0};

View File

@ -1,9 +1,8 @@
/*
* menu0_main.c
* menu_entry_0.c
* begin 20190527 true
*
* main menu functions
* nametag display
*/
#include "menu.h"
@ -20,7 +19,6 @@
#include <stdio.h>
#define ROTATE_TARGET_WIDTH 40
#define ROTATE_TARGET_HEIGHT 32
@ -37,7 +35,6 @@
#define DEMOWAVE_ADD2 25
uint8_t rotsrc_fb[(ROTATE_TARGET_WIDTH * (ROTATE_TARGET_HEIGHT >> 3)) + 1];
uint8_t rotdst_fb[(ROTATE_TARGET_WIDTH * (ROTATE_TARGET_HEIGHT >> 3)) + 1];
@ -49,7 +46,6 @@ uint8_t wiggle = 1;
int8_t waves = 0;
static void menu_none_init()
{
rotsrc.width = rotdst.width = ROTATE_TARGET_WIDTH;
@ -320,7 +316,7 @@ __HIGH_CODE
void menu_0_disp(uint8_t idx)
{
char txt[14];
// uint8_t w;
uint8_t w;
ssd1306fb_set_color(SSD1306_STATE_SET_PIXEL);
@ -333,25 +329,14 @@ void menu_0_disp(uint8_t idx)
case 0: strcpy(txt, "Nametag!"); break;
case 1: strcpy(txt, "Name Setup"); break;
case 2: strcpy(txt, "RGB Setup"); break;
case 3: strcpy(txt, "Messages"); break;
case 4: {
ssd1306fb_set_cursor(32, 9);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "I", 1);
ssd1306fb_set_cursor(39, 8);
ssd1306fb_draw_str(font_Dialog_plain_8, "2", 1);
ssd1306fb_set_cursor(45, 9);
strcpy(txt, "C Sniffer");
break;
}
case 3: strcpy(txt, "Snek"); break;
case 4: strcpy(txt, "Morble"); break;
case 5: strcpy(txt, "Options"); break;
case 6: strcpy(txt, "About & Dbg"); break;
}
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, txt, 1);
// disabled / incomplete entries
/*
switch (idx) {
case 4: {
w = ssd1306fb_get_str_width(font_DejaVu_Sans_Mono_Bold_11, txt, strlen(txt), 1);
@ -359,7 +344,6 @@ void menu_0_disp(uint8_t idx)
ssd1306fb_draw_hline(32, w + 32, 17);
}
}
*/
// draw extras
menu_draw_tabs(idx);
@ -374,28 +358,29 @@ void menu_0_enter(uint8_t idx)
return;
}
case 1: {
menu = (MenuItem *)&menu_1_name_setup;
menu = (MenuItem *)&menu_1;
menu_idx = 0;
return;
}
case 2: {
menu = (MenuItem *)&menu_2_led_setup;
menu = (MenuItem *)&menu_2;
menu_idx = 0;
return;
}
case 3: {
menu = (MenuItem *)&menu_3_snek;
return;
}
case 4: {
return;
}
case 5: {
menu = (MenuItem *)&menu_5_options;
menu = (MenuItem *)&menu_5;
menu_idx = 0;
return;
}
case 6: {
menu = (MenuItem *)&menu_6_about;
menu = (MenuItem *)&menu_6;
menu_idx = 0;
return;
}

View File

@ -1,5 +1,5 @@
/*
* menu5_options.c
* menu_entry_5.c
* begin 20190613 true
*
* settings menu functions
@ -19,20 +19,18 @@
#define LI_ENABLE_LEDS 0
#define LI_NO_MOVE_SLP_TIME 1
#define LI_NO_MOVE_DIM_TIME 2
#define LI_NO_MOVE_THRESH 3
#define LI_WAKEUP_THRESH 4
#define LI_LSENS_DARK_CAL 5
#define LI_FACTORY_RESET 6
#define LI_DEBUG_SHOW_CPU 7
#define LI_DEBUG_SHOW_ACCEL 8
#define LI_NO_MOVE_TIMEOUT 1
#define LI_NO_MOVE_THRESH 2
#define LI_WAKEUP_THRESH 3
#define LI_LSENS_DARK_CAL 4
#define LI_FACTORY_RESET 5
#define LI_DEBUG_SHOW_CPU 6
#define LI_DEBUG_SHOW_ACCEL 7
const uint16_t sleep_times[] = {
0,
60,
300,
600,
900,
@ -46,6 +44,7 @@ static uint8_t factory_reset;
__HIGH_CODE
void menu_5_disp(uint8_t idx)
{
int8_t w, x;
@ -62,7 +61,7 @@ void menu_5_disp(uint8_t idx)
strcpy(txt, (uconf.flags & UCONF_FLAGS_LEDS_ENABLE) ? "On" : "Off");
break;
}
case LI_NO_MOVE_SLP_TIME: {
case LI_NO_MOVE_TIMEOUT: {
ssd1306fb_draw_str(font_table[0].font, "No Movement Sleep Time", 0);
if (uconf.sleep_timeout) {
sprintf(txt, "%dmin", (uconf.sleep_timeout / 60));
@ -71,15 +70,6 @@ void menu_5_disp(uint8_t idx)
}
break;
}
case LI_NO_MOVE_DIM_TIME: {
ssd1306fb_draw_str(font_table[0].font, "No Move LED Autodim Time", 0);
if (uconf.dim_timeout) {
sprintf(txt, "%dmin", (uconf.dim_timeout / 60));
} else {
strcpy(txt, "Off");
}
break;
}
case LI_NO_MOVE_THRESH: {
ssd1306fb_draw_str(font_table[0].font, "No Movement Threshold", 0);
strcpy(txt, "Normal");
@ -101,47 +91,20 @@ void menu_5_disp(uint8_t idx)
break;
}
case LI_FACTORY_RESET: {
uint32_t iter;
// todo: implement manual button checking here after getting button orientation code working
// yes, this means reset speed depends on framerate lol
if (btn_pushed & (1 << 2)) {
factory_reset++;
} else factory_reset = 0;
if (factory_reset >= 32) {
// do the factory reset
iter = uconf.iter;
uconf_defaults();
// we do store the old iteration value so long as it isn't
// too high in order to keep track of nvmem writes.
// if the value is unnaturally high, we'll reset to zero.
// if it's corrupt in any way, enjoy your false write count.
if (iter < 0xffffff) {
uconf.iter = iter;
}
uconf_clear();
// while it isn't necesasry to write an initial config
// as the code will determine there is no valid config
// and load defaults if the nvmem is empty,
// we're doing it to write the iter value.
uconf_write();
// aaaand it's gone
SYS_ResetExecute();
while (1);
// todo: reboot?
}
ssd1306fb_draw_str(font_table[0].font, "Hold Set to Factory Reset...", 0);
txt[0] = 0;
ssd1306fb_draw_rect(52, 18, 52 + 31, 31);
for (w = 0; w < factory_reset; w++) {
ssd1306fb_draw_vline(53 + w, 18, 31);
ssd1306fb_draw_rect(50, 18, 86, 31);
for (w = 0; w < (factory_reset >> 1); w++) {
ssd1306fb_draw_vline(50 + w, 18, 31);
}
break;
}
@ -176,7 +139,6 @@ void menu_5_disp(uint8_t idx)
void menu_5_enter(uint8_t idx)
{
int i, j;
uint16_t *t;
switch (idx) {
case LI_ENABLE_LEDS: {
@ -187,16 +149,13 @@ void menu_5_enter(uint8_t idx)
}
break;
}
case LI_NO_MOVE_SLP_TIME:
case LI_NO_MOVE_DIM_TIME: {
t = (idx == LI_NO_MOVE_SLP_TIME) ? &uconf.sleep_timeout : &uconf.dim_timeout;
case LI_NO_MOVE_TIMEOUT: {
j = sizeof(sleep_times) / sizeof(sleep_times[0]);
for (i = 0; i < j; i++) {
if (*t == sleep_times[i]) {
if (uconf.sleep_timeout == sleep_times[i]) {
i++;
i %= j;
*t = sleep_times[i];
uconf.sleep_timeout = sleep_times[i];
j = 0xff;
break;
}
@ -204,7 +163,7 @@ void menu_5_enter(uint8_t idx)
// couldn't find a match, so set default
if (j != 0xff) {
*t = sleep_times[4];
uconf.sleep_timeout = sleep_times[4];
}
break;
}

View File

@ -27,19 +27,6 @@
#define MCU_SRAM 24+2
#define LI_ABOUT 0
#define LI_CONTACT 1
#define LI_LED_1_4 2
#define LI_LED_5_8 3
#define LI_LED_9_12 4
#define LI_ACCELEROMETER 5
#define LI_CPU_USAGE 6
#define LI_MISC_STATS 7
#define LI_ERROR_COUNTERS 8
#define LI_FONT_GLYPH_TEST 9
uint8_t font_index = 0;
uint8_t font_glyph = 0;
@ -91,7 +78,7 @@ void menu_6_font_prev(uint8_t idx)
*/
}
static void menu_6_accel_reset(uint8_t idx)
void menu_6_accel_reset(uint8_t idx)
{
// todo: figure out what this does
movement_worst = 0;
@ -127,7 +114,7 @@ void menu_6_disp(uint8_t idx)
// which item selected?
switch (idx) {
case LI_ABOUT: { // about
case 0: { // about
ssd1306fb_set_cursor(11, 0);
ssd1306fb_draw_str(font_DSEG14_Classic_18, "GAT", 1);
ssd1306fb_set_cursor(11, 22);
@ -149,7 +136,7 @@ void menu_6_disp(uint8_t idx)
break;
}
case LI_CONTACT: { // manual
case 1: { // manual
ssd1306fb_set_cursor(11, 0);
ssd1306fb_draw_str(font_Dialog_plain_8, "Manual and code at", 1);
ssd1306fb_set_cursor(11, 11);
@ -159,7 +146,7 @@ void menu_6_disp(uint8_t idx)
break;
}
case LI_LED_1_4: { // led 1-4
case 2: { // led 1-4
ssd1306fb_set_cursor(54, 4);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "LED", 1);
ssd1306fb_set_cursor(54, 15);
@ -176,7 +163,7 @@ void menu_6_disp(uint8_t idx)
}
break;
}
case LI_LED_5_8: { // led 5-8
case 3: { // led 5-8
ssd1306fb_set_cursor(54, 4);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "LED", 1);
ssd1306fb_set_cursor(54, 15);
@ -193,7 +180,7 @@ void menu_6_disp(uint8_t idx)
}
break;
}
case LI_LED_9_12: { // led 9-12
case 4: { // led 9-12
ssd1306fb_set_cursor(54, 4);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "LED", 1);
ssd1306fb_set_cursor(53, 15);
@ -214,7 +201,7 @@ void menu_6_disp(uint8_t idx)
}
break;
}
case LI_ACCELEROMETER: { // accelerometer
case 5: { // accelerometer
ssd1306fb_set_cursor(10, -1);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "Accelerometer", 1);
@ -242,7 +229,7 @@ void menu_6_disp(uint8_t idx)
break;
}
case LI_CPU_USAGE: { // cpu stats
case 6: { // cpu stats
sprintf(txt, "CPU Load: %3u%%", cpu_pct);
ssd1306fb_set_cursor(10, -1);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, txt, 1);
@ -256,20 +243,20 @@ void menu_6_disp(uint8_t idx)
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
break;
}
case LI_MISC_STATS: { // misc stats
case 7: { // misc stats
ssd1306fb_set_cursor(10, -1);
ssd1306fb_draw_str(font_Dialog_plain_8, "Light: ", 1);
oled.cursor_x = 39;
//sprintf(txt, "%d lo, %02d + %d", lsens_get_dark_threshold(), lsens_get_coarse(), lsens_get_fine());
//ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
ssd1306fb_draw_str(font_Dialog_plain_8, "not yet implemented", 0);
sprintf(txt, "%d lo, %02d + %d", lsens_get_dark_threshold(), lsens_get_coarse(), lsens_get_fine());
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
ssd1306fb_set_cursor(10, 7);
ssd1306fb_draw_str(font_Dialog_plain_8, "Temp:", 1);
ssd1306fb_draw_str(font_Dialog_plain_8, "Temp: Batt:", 1);
oled.cursor_x = 42;
// todo: implement temperature sensing
// sprintf(txt, "%d.%dC", temp_degc, temp_degc_decimal);
ssd1306fb_draw_str(font_Dialog_plain_8, "not yet implemented", 0);
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
oled.cursor_x = 98;
// battery reading support is not supported on this target
@ -278,18 +265,18 @@ void menu_6_disp(uint8_t idx)
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
ssd1306fb_set_cursor(10, 16);
ssd1306fb_draw_str(font_Dialog_plain_8, "EEPROM Conf Writes: ", 0);
ssd1306fb_draw_str(font_Dialog_plain_8, "Flash Conf Writes: ", 0);
sprintf(txt, "%lu", uconf.iter);
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 1);
ssd1306fb_set_cursor(10, 24);
ssd1306fb_draw_str(font_Dialog_plain_8, "CH592 ", 0);
sprintf(txt, "F%dK / R%dK", MCU_FLASH, MCU_SRAM);
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0);
ssd1306fb_draw_str(font_Dialog_plain_8, "MCU: ", 1);
sprintf(txt, "%dK / %dK", MCU_FLASH, MCU_SRAM);
ssd1306fb_draw_str(font_Dialog_plain_8, txt, 1);
break;
}
case LI_ERROR_COUNTERS: { // error counters
case 8: { // error counters
ssd1306fb_set_cursor(10, -1);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "Error Counters", 1);
@ -313,7 +300,7 @@ void menu_6_disp(uint8_t idx)
break;
}
case LI_FONT_GLYPH_TEST: {
case 9: {
ssd1306fb_set_cursor(10, -1);
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "Font Test", 1);
@ -338,21 +325,20 @@ void menu_6_disp(uint8_t idx)
// buttons
switch (idx) {
case LI_ABOUT:
case LI_CONTACT:
case LI_LED_1_4:
case LI_LED_5_8:
case LI_LED_9_12:
case LI_CPU_USAGE: {
case 0:
case 1:
case 2:
case 3:
case 4: {
menu_btn_use_std();
break;
}
case LI_ACCELEROMETER: {
case 5: {
menu_btn_use_std();
btn[2].cb_push = menu_6_accel_reset;
break;
}
case LI_FONT_GLYPH_TEST: {
case 9: {
menu_6_btn_use();
menu_draw_buttons(MENU_BTNSTYLE_ABOUT, 0x0c);
break;

View File

View File

@ -11,7 +11,6 @@
#include "led/rgbled.h"
#include <string.h>
#include <stdio.h>
@ -37,14 +36,14 @@ void uconf_defaults()
{
int i;
memset(&uconf, 0x00, sizeof(uconf));
uconf.ver = UCONF_VER;
uconf.flags = UCONF_FLAGS_LEDS_ENABLE;
uconf.framemod = UCONF_FRAMERATE_FULL;
uconf.nameconf = UCONF_NAME_DISP_DEMOWAVE1 | UCONF_NAME_MODE_AUTOROTATE | UCONF_NAME_MODE_COLOR_INVERT;
// UCONF_NAME_DISP_DEMOWAVES1 | UCONF_NAME_MODE_AUTOROTATE | UCONF_NAME_MODE_COLOR_INVERT;
if (uconf_flash_offset == 0xf0) {
uconf.iter = 0;
}
uconf.font_idx = 5;
uconf.char_spacing = 2;
uconf.y_offset = 0;
@ -75,7 +74,6 @@ void uconf_defaults()
uconf.checksum = checksum_gen((uint8_t *)&uconf, sizeof(uconf) - 2);
}
// returns 0 if valid
static int8_t uconf_validate()
{
// blank check
@ -100,56 +98,21 @@ static int8_t uconf_validate()
void uconf_load()
{
uint8_t i;
uint32_t iter = 0;
uconf_flash_offset = FLASH_RSVD_PAGES;
for (i = 0; i < FLASH_RSVD_PAGES; i++) {
// search nv data for latest user config
eep16_read(i * FLASH_UCONF_BYTES, (uint8_t *)&uconf, FLASH_UCONF_BYTES);
if (!uconf_validate()) {
if (uconf.iter > iter) {
// this page has the highest iter value, so is the latest we've found so far
uconf_flash_offset = i;
iter = uconf.iter;
}
}
}
if (uconf_flash_offset >= FLASH_RSVD_PAGES) {
// flash has no valid data whatsoever
// load some defaults into RAM and ignore flash for now
uconf_defaults();
} else {
// reload the latest save data found
// find last page of valid config from flash
uconf_flash_offset = (FLASH_RSVD_PAGES - 1) - i;
eep16_read(uconf_flash_offset * FLASH_UCONF_BYTES, (uint8_t *)&uconf, FLASH_UCONF_BYTES);
}
}
void uconf_clear()
{
uint8_t i;
uint8_t c[128];
uint16_t fsize;
uint16_t faddr;
memset(&c, 0xff, sizeof(c));
uconf_flash_offset = FLASH_RSVD_PAGES;
for (i = 0; i < FLASH_RSVD_PAGES; i++) {
// write config data
fsize = FLASH_UCONF_BYTES;
faddr = i * FLASH_UCONF_BYTES;
while (fsize) {
while (!eep16_is_ready());
eep16_write(faddr, c, (fsize > 128) ? 128 : fsize);
if (fsize <= 128) break;
fsize -= 128;
faddr += 128;
if (!uconf_validate()) {
// valid data
return;
}
}
// flash has no valid data whatsoever
// don't worry about flash setup; that is done during writing
uconf_flash_offset = 0xf0;
uconf_defaults();
}
void uconf_write()

View File

@ -84,10 +84,9 @@ typedef struct UserConf {
uint8_t padding0; // 52
uint8_t ledprog_rgb[16]; // 68
uint8_t ledprog_rgb_data[16][8]; // 196
uint8_t padding1[48]; // 244
uint16_t lsens_dark_thresh; // 246
uint16_t menu_timeout; // 248
uint16_t dim_timeout; // 250
uint8_t padding1[50]; // 246
uint16_t lsens_dark_thresh; // 248
uint16_t menu_timeout; // 250
uint16_t sleep_timeout; // 252
uint16_t tempcx10_offset; // 253-254
uint16_t checksum; // 255-256
@ -106,12 +105,9 @@ extern uint8_t temp_degc_decimal;
// non-volatile functions
void uconf_load();
void uconf_write();
void uconf_clear();
// volatile functions
void uconf_defaults();