diff --git a/CHANGELOG.md b/CHANGELOG.md index 6186e38c..2c0f45a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - **NEW**: new ops: `CV.CAL` and `CV.CAL.RESET` to calibrate CV outputs - **FIX**: N.CS scales 7 & 8 were incorrectly swapped; make them consistent with N.S and docs - **FIX**: libavr32 update: support CDC grid size detection (e.g. zero), increase HID message buffer +- **NEW**: apply VCV Rack compatibility patches, so branches off main can be used in both hardware and software ## v4.0.0 diff --git a/docs/whats_new.md b/docs/whats_new.md index 2a142e45..cd1cddff 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -29,6 +29,7 @@ - **NEW**: new ops: `CV.CAL` and `CV.CAL.RESET` to calibrate CV outputs - **FIX**: N.CS scales 7 & 8 were incorrectly swapped; make them consistent with N.S and docs - **FIX**: libavr32 update: support CDC grid size detection (e.g. zero), increase HID message buffer +- **NEW**: apply VCV Rack compatibility patches, so branches off main can be used in both hardware and software ## v4.0.0 diff --git a/module/flash.c b/module/flash.c index bb10a359..5d4efd46 100644 --- a/module/flash.c +++ b/module/flash.c @@ -12,33 +12,14 @@ #include "teletype.h" #define FIRSTRUN_KEY 0x22 -#define BUTTON_STATE_SIZE (GRID_BUTTON_COUNT >> 3) -typedef struct { - uint8_t button_states[BUTTON_STATE_SIZE]; - uint8_t fader_states[GRID_FADER_COUNT]; -} grid_data_t; static grid_data_t grid_data; -// NVRAM data structure located in the flash array. -typedef const struct { - scene_script_t scripts[EDITABLE_SCRIPT_COUNT]; - scene_pattern_t patterns[PATTERN_COUNT]; - grid_data_t grid_data; - char text[SCENE_TEXT_LINES][SCENE_TEXT_CHARS]; -} nvram_scene_t; - -typedef const struct { - nvram_scene_t scenes[SCENE_SLOTS]; - uint8_t last_scene; - tele_mode_t last_mode; - uint8_t fresh; - cal_data_t cal; - device_config_t device_config; -} nvram_data_t; - - +#if defined(__AVR32__) static __attribute__((__section__(".flash_nvram"))) nvram_data_t f; +#else +nvram_data_t f; +#endif static void pack_grid(scene_state_t *scene); static void unpack_grid(scene_state_t *scene); diff --git a/module/flash.h b/module/flash.h index 8673e635..b81a990b 100644 --- a/module/flash.h +++ b/module/flash.h @@ -8,6 +8,29 @@ #include "teletype.h" #define SCENE_SLOTS 32 +#define BUTTON_STATE_SIZE (GRID_BUTTON_COUNT >> 3) + +typedef struct { + uint8_t button_states[BUTTON_STATE_SIZE]; + uint8_t fader_states[GRID_FADER_COUNT]; +} grid_data_t; + +// NVRAM data structure located in the flash array. +typedef struct { + scene_script_t scripts[EDITABLE_SCRIPT_COUNT]; // Exclude TEMP script + scene_pattern_t patterns[PATTERN_COUNT]; + grid_data_t grid_data; + char text[SCENE_TEXT_LINES][SCENE_TEXT_CHARS]; +} nvram_scene_t; + +typedef struct { + nvram_scene_t scenes[SCENE_SLOTS]; + uint8_t last_scene; + tele_mode_t last_mode; + uint8_t fresh; + cal_data_t cal; + device_config_t device_config; +} nvram_data_t; u8 is_flash_fresh(void); void flash_prepare(void); diff --git a/module/main.c b/module/main.c index e54ec81b..d8acde9a 100644 --- a/module/main.c +++ b/module/main.c @@ -173,11 +173,11 @@ static void handler_AppCustom(int32_t data); static void empty_event_handlers(void); void assign_main_event_handlers(void); static void assign_msc_event_handlers(void); -static void check_events(void); +void check_events(void); // key handling -static void process_keypress(uint8_t key, uint8_t mod_key, bool is_held_key, - bool is_release); +void process_keypress(uint8_t key, uint8_t mod_key, bool is_held_key, + bool is_release); static bool process_global_keys(uint8_t key, uint8_t mod_key, bool is_held_key); // start/stop monome polling/refresh timers @@ -189,6 +189,8 @@ static void render_init(void); static void exit_screensaver(void); static void update_device_config(u8 refresh); +void initialize_module(void); + //////////////////////////////////////////////////////////////////////////////// // timer callbacks @@ -1184,7 +1186,7 @@ void reset_midi_counter() { //////////////////////////////////////////////////////////////////////////////// // main -int main(void) { +void initialize_module(void) { sysclk_init(); init_dbg_rs232(FMCK_HZ); @@ -1300,7 +1302,10 @@ int main(void) { run_script(&scene_state, INIT_SCRIPT); scene_state.initializing = false; +} +int main(void) { + initialize_module(); #ifdef TELETYPE_PROFILE uint32_t count = 0; #endif