diff --git a/.flake8 b/.flake8 index 9f41f6e..aa524c2 100644 --- a/.flake8 +++ b/.flake8 @@ -9,7 +9,8 @@ builtins = pen, tick, init, - reset, + _reset, + _logo, play, clip, blend, diff --git a/micropython/examples/picosystem/launcher.py b/micropython/examples/picosystem/launcher.py index 2a0d9cd..4e04922 100644 --- a/micropython/examples/picosystem/launcher.py +++ b/micropython/examples/picosystem/launcher.py @@ -1,7 +1,9 @@ -import os -import math -import time -import gc +backlight(0) + +import os # noqa: E402 +import math # noqa: E402 +import time # noqa: E402 +import gc # noqa: E402 last_note = 0 @@ -11,7 +13,7 @@ notes = [ - (None, 100), ("G6", 10), ("E6", 30), ("A6", 10), ("G6", 30), (None, 100), ("B7", 1), ("C7", 1) + (None, 100), ("G6", 10), ("E6", 30), ("A6", 10), ("G6", 30), (None, 50), ("B7", 1), ("C7", 1) ] intro = Voice() intro.envelope(attack=50, decay=10, sustain=70, release=2000) @@ -76,6 +78,9 @@ def update(tick): selected %= filecount target_angle = -get_item_angle(selected) + if tick <= 75: + backlight(tick) + def draw(tick): global current_angle, intro_melody @@ -86,9 +91,10 @@ def draw(tick): if intro_melody: pen(15, 15, 15) + _logo() label = "".join(["", "Pi", "co", "Sys", "tem"][0:min(note_idx, 5)]) label_width = text_width(label) - text(label, int(60 - (label_width / 2)), 60) + text(label, int(60 - (label_width / 2)), 90) return pen(10, 10, 10) @@ -134,5 +140,5 @@ def draw(tick): del locals()[k] gc.collect() -reset() +_reset() __import__(__launch_file__) diff --git a/micropython/modules/picosystem/picosystem.c b/micropython/modules/picosystem/picosystem.c index bb02179..beec268 100755 --- a/micropython/modules/picosystem/picosystem.c +++ b/micropython/modules/picosystem/picosystem.c @@ -68,6 +68,7 @@ const mp_obj_type_t PicosystemVoice_type = { MP_DEFINE_CONST_FUN_OBJ_0(picosystem_init_obj, picosystem_init); MP_DEFINE_CONST_FUN_OBJ_0(picosystem_reset_obj, picosystem_reset); MP_DEFINE_CONST_FUN_OBJ_0(picosystem_tick_obj, picosystem_tick); +MP_DEFINE_CONST_FUN_OBJ_0(picosystem_logo_obj, picosystem_logo); // stats.cpp diff --git a/micropython/modules/picosystem/picosystem.cpp b/micropython/modules/picosystem/picosystem.cpp index e65982b..78b8149 100644 --- a/micropython/modules/picosystem/picosystem.cpp +++ b/micropython/modules/picosystem/picosystem.cpp @@ -33,7 +33,7 @@ uint32_t last_ms = time(); uint32_t tick = 0; -static bool done_splash = false; +static bool done_audio_init = false; mp_obj_t update_callback_obj = mp_const_none; mp_obj_t draw_callback_obj = mp_const_none; @@ -62,6 +62,23 @@ mp_obj_t picosystem_reset() { return mp_const_none; } +mp_obj_t picosystem_logo() { + const uint8_t *s = _picosystem_logo; + + for(int y = 35; y < 85; y++) { + for(int x = 19; x < 101; x+=8) { + for(int bit = 0; bit < 8; bit++) { + if(*s & (0b10000000 >> bit)) { + pixel(x + bit, y); + } + } + s++; + } + } + + return mp_const_none; +} + mp_obj_t picosystem_init() { MP_STATE_PORT(picosystem_framebuffer) = m_new(color_t, 120 * 120); @@ -78,41 +95,27 @@ mp_obj_t picosystem_init() { _fsin_lut[i] = sin((_PI * 2.0f) * (float(i) / 256.0f)); } - if(!done_splash) { // Squash splash on soft-reset. It's painful! + if(!done_audio_init) { _start_audio(); // HACK! we really should figure out *what* soft-reset rp2_pio_deinit and machine_pin_deinit is breaking // Set the LED to green, just for gentle reassurance - led(0, 128, 0); - -#ifndef NO_STARTUP_LOGO - // fade in logo by ramping up backlight - pen(0, 0, 0); clear(); - pen(15, 15, 15); _logo(); - for(int i = 0; i < 75; i++) { - backlight(i); - _wait_vsync(); - _flip(); - } - - sleep(300); // ...and breathe out... - - // fade out logo in 16 colour steps - for(int i = 15; i >= 0; i--) { - pen(0, 0, 0); clear(); - pen(i, i, i); _logo(); - _wait_vsync(); - _flip(); - - sleep(20); - } -#endif - done_splash = true; + led(0, 64, 0); + + done_audio_init = true; } - backlight(75); - sleep(300); + // Keep the screen off... + backlight(0); + // Screen buffer is initialized clear; just flip it. + _flip(); + // Wait for the DMA transfer to finish + while (_is_flipping()); + // wait for the screen to update + _wait_vsync(); + _wait_vsync(); - pen(0, 0, 0); clear(); + // Turn the screen on + backlight(75); // call users init() function so they can perform any needed // setup for world state etc diff --git a/micropython/modules/picosystem/picosystem.h b/micropython/modules/picosystem/picosystem.h index f5bf49d..ddf1881 100644 --- a/micropython/modules/picosystem/picosystem.h +++ b/micropython/modules/picosystem/picosystem.h @@ -56,6 +56,7 @@ extern const mp_obj_type_t PicosystemVoice_type; extern mp_obj_t picosystem_init(); extern mp_obj_t picosystem_tick(); extern mp_obj_t picosystem_reset(); +extern mp_obj_t picosystem_logo(); // stats.cpp extern mp_obj_t picosystem_stats();