altos: Move TeleMetrum v2.0 to using internal eeprom for config
[fw/altos] / src / core / ao_config.c
index 82faf32bbb904b22517fb814f86d829f30231d3f..a30ec64a5e8a9d0c1c4c8ea59d7766e363ae5ea2 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "ao.h"
 #include "ao_log.h"
-#include <ao_storage.h>
+#include <ao_config.h>
 #if HAS_FLIGHT
 #include <ao_sample.h>
 #include <ao_data.h>
@@ -59,13 +59,13 @@ __xdata uint8_t ao_config_mutex;
 static void
 _ao_config_put(void)
 {
-       ao_storage_setup();
-       ao_storage_erase(ao_storage_config);
-       ao_storage_write(ao_storage_config, &ao_config, sizeof (ao_config));
+       ao_config_setup();
+       ao_config_erase();
+       ao_config_write(0, &ao_config, sizeof (ao_config));
 #if HAS_FLIGHT
        ao_log_write_erase(0);
 #endif
-       ao_storage_flush();
+       ao_config_flush();
 }
 
 void
@@ -97,8 +97,8 @@ _ao_config_get(void)
         * but ao_storage_setup *also* sets ao_storage_config, which we
         * need before calling ao_storage_read here
         */
-       ao_storage_setup();
-       ao_storage_read(ao_storage_config, &ao_config, sizeof (ao_config));
+       ao_config_setup();
+       ao_config_read(0, &ao_config, sizeof (ao_config));
 #endif
        if (ao_config.major != AO_CONFIG_MAJOR) {
                ao_config.major = AO_CONFIG_MAJOR;
@@ -127,8 +127,10 @@ _ao_config_get(void)
                        ao_config.radio_cal = ao_radio_cal;
 #endif
                /* Fixups for minor version 4 */
+#if HAS_FLIGHT
                if (minor < 4)
                        ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
+#endif
                /* Fixupes for minor version 5 */
                if (minor < 5)
                        ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
@@ -465,7 +467,7 @@ void
 ao_config_log_set(void) __reentrant
 {
        uint16_t        block = (uint16_t) (ao_storage_block >> 10);
-       uint16_t        config = (uint16_t) (ao_storage_config >> 10);
+       uint16_t        log_max = (uint16_t) (ao_storage_log_max >> 10);
 
        ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
@@ -474,8 +476,8 @@ ao_config_log_set(void) __reentrant
                printf("Storage must be empty before changing log size\n");
        else if (block > 1024 && (ao_cmd_lex_i & (block - 1)))
                printf("Flight log size must be multiple of %d kB\n", block);
-       else if (ao_cmd_lex_i > config)
-               printf("Flight log max %d kB\n", config);
+       else if (ao_cmd_lex_i > log_max)
+               printf("Flight log max %d kB\n", log_max);
        else {
                _ao_config_edit_start();
                ao_config.flight_log_max = (uint32_t) ao_cmd_lex_i << 10;
@@ -655,7 +657,7 @@ static void
 ao_config_show(void) __reentrant;
 
 static void
-ao_config_write(void) __reentrant;
+ao_config_save(void) __reentrant;
 
 __code struct ao_config_var ao_config_vars[] = {
 #if HAS_FLIGHT
@@ -714,7 +716,7 @@ __code struct ao_config_var ao_config_vars[] = {
          ao_config_show,               0 },
 #if HAS_EEPROM
        { "w\0Write to eeprom",
-         ao_config_write,              0 },
+         ao_config_save,               0 },
 #endif
        { "?\0Help",
          ao_config_help,               0 },
@@ -766,7 +768,7 @@ ao_config_show(void) __reentrant
 
 #if HAS_EEPROM
 static void
-ao_config_write(void) __reentrant
+ao_config_save(void) __reentrant
 {
        uint8_t saved = 0;
        ao_mutex_get(&ao_config_mutex);