From: b Date: Sat, 1 Feb 2025 18:19:46 +0000 (+0100) Subject: interrupt ADSR/wave drawing for any AIX/CTRL communication handling, don't reinitiali... X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;ds=sidebyside;p=klavirko%2Fui interrupt ADSR/wave drawing for any AIX/CTRL communication handling, don't reinitialise interrupted drawing --- diff --git a/aix.c b/aix.c index bd44f64..8b0d7ad 100644 --- a/aix.c +++ b/aix.c @@ -13,6 +13,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "klavirko-ui.h" #include "aix.h" +#include "main.h" #include "debug.h" #include "wave.h" #include "gui.h" @@ -55,6 +56,8 @@ inline void int_aix_rx (void) // received byte from AIX else { aix_buffer[aix_buffer_w] = data; + // if (data == '\n') + data_waiting |= DATA_FLAG_AIX; // advance the pointer ADVANCE_BP(aix_buffer_w, N_AIX_BUFFER); } @@ -119,6 +122,7 @@ void handle_aix (void) while (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_BUFFER)) // data waiting in buffer { + data_waiting &= (~DATA_FLAG_AIX); // get data; advance pointer data = aix_buffer[aix_buffer_r]; ADVANCE_BP(aix_buffer_r, N_AIX_BUFFER); diff --git a/aix.h b/aix.h index 8f209e9..c131144 100644 --- a/aix.h +++ b/aix.h @@ -94,6 +94,3 @@ inline void setup_aix(void); void debug_aix (const uint8_t blocking); // print AIX state extern uint16_t aix_data[N_AIX_DATA]; - -extern volatile uint8_t aix_buffer_r; -extern volatile uint8_t aix_buffer_w; diff --git a/ctrl.c b/ctrl.c index 8b795db..8fce602 100644 --- a/ctrl.c +++ b/ctrl.c @@ -14,6 +14,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include "klavirko-ui.h" #include "ctrl.h" +#include "main.h" #include "wave.h" #include "debug.h" #include "gui.h" @@ -27,7 +28,7 @@ volatile uint8_t ctrl_rxbuffer_w = 0; uint8_t ctrl_txbuffer_w = 0; volatile uint8_t ctrl_error = 0; - uint8_t ctrl_state = CTRL_WAIT; +volatile uint8_t ctrl_state = CTRL_WAIT; uint8_t ctrl_retry = 0; volatile uint16_t ctrl_timeout = 0; @@ -52,6 +53,14 @@ inline void ctrl_watchdog(void) ++ctrl_timeout; } +inline void int_ctrl_tx(void) // CTRL got free to send +{ + if (ctrl_state == CTRL_SEND) // still something to send + data_waiting |= DATA_FLAG_CTRL_OUT; + else + data_waiting &= ~(DATA_FLAG_CTRL_OUT); +} + inline void int_ctrl_rx(void) // received byte from CTRL { uint8_t data; @@ -62,6 +71,8 @@ inline void int_ctrl_rx(void) // received byte from CTRL ctrl_error |= ERR_OVERFLOW; else { + // if (data=='\n') + data_waiting |= DATA_FLAG_CTRL_IN; ctrl_rxbuffer[ctrl_rxbuffer_w] = data; ADVANCE_BP(ctrl_rxbuffer_w, N_CTRL_RXBUFFER); } @@ -119,6 +130,7 @@ inline void setup_ctrl (void) CTRL_TX__SS = 1; CTRL_RX__SS = 1; + CTRL_TX__MK = 0; CTRL_RX__MK = 0; CTRL_RX__MKE = 0; } @@ -283,6 +295,7 @@ void handle_ctrl (void) ctrl_txbuffer[ctrl_txbuffer_w] = io; ADVANCE_BP(ctrl_txbuffer_w, N_CTRL_TXBUFFER); } + data_waiting &= ~(DATA_FLAG_CTRL_OUT); if (NOT_EMPTY_BP(ctrl_txbuffer_w, ctrl_txbuffer_r, N_CTRL_TXBUFFER)) // data in output buffer { @@ -323,6 +336,7 @@ void handle_ctrl (void) while (NOT_EMPTY_BP(ctrl_rxbuffer_w, ctrl_rxbuffer_r, N_CTRL_RXBUFFER)) // data in input buffer { + data_waiting &= ~(DATA_FLAG_CTRL_IN); // get the byte, advance the pointer io = ctrl_rxbuffer[ctrl_rxbuffer_r]; ADVANCE_BP(ctrl_rxbuffer_r, N_CTRL_RXBUFFER); diff --git a/ctrl.h b/ctrl.h index a4fedab..fd5dc9b 100644 --- a/ctrl.h +++ b/ctrl.h @@ -1,6 +1,6 @@ /* COMMUNICATING WITH MAIN CONTROLLER */ /* -Copyright 2021 Balthasar Szczepański +Copyright 2021, 2025 Balthasar Szczepański Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -87,6 +87,7 @@ extern uint8_t midi_id_out; extern uint8_t midi_pedal_en; inline void ctrl_watchdog (void) LOWTEXT; +inline void int_ctrl_tx (void) LOWTEXT_INT; // CTRL got free to send inline void int_ctrl_rx (void) LOWTEXT_INT; // received byte from CTR inline void int_ctrl_err (void) LOWTEXT_INT; // received error from CTR inline void setup_ctrl (void); diff --git a/lcd.c b/lcd.c index 7863597..14ef0ad 100644 --- a/lcd.c +++ b/lcd.c @@ -1001,7 +1001,9 @@ void handle_lcd (void) if (draw_wave_active) { - lcd_setup_drawing(LCD_GRAY, draw_x, HALFSCREEN_PIXELS-1, 0, 9); + // lcd_setup_drawing(LCD_GRAY, draw_x, HALFSCREEN_PIXELS-1, 0, 9); + if (draw_x == 0) + lcd_setup_drawing(LCD_GRAY, 0, HALFSCREEN_PIXELS-1, 0, 9); while (draw_wave_active) { x = convert_wave((int8_t)draw_wave_data[draw_x]); @@ -1147,7 +1149,7 @@ void handle_lcd (void) return; } // interrupt drawing to handle AIX communication - if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA)) + if (data_waiting) return; } draw_x = 0; @@ -1155,7 +1157,9 @@ void handle_lcd (void) else if (draw_adsr_active) { - lcd_setup_drawing(LCD_GRAY, HALFSCREEN_PIXELS+draw_x, FULLSCREEN_PIXELS-1, 0, 9); + // lcd_setup_drawing(LCD_GRAY, HALFSCREEN_PIXELS+draw_x, FULLSCREEN_PIXELS-1, 0, 9); + if (draw_x == 0) + lcd_setup_drawing(LCD_GRAY, HALFSCREEN_PIXELS, FULLSCREEN_PIXELS-1, 0, 9); while (draw_adsr_active) { x = draw_adsr_data[draw_x]; @@ -1300,7 +1304,7 @@ void handle_lcd (void) return; } // interrupt drawing to handle communication - if (NOT_EMPTY_BP(aix_buffer_w, aix_buffer_r, N_AIX_DATA)) + if (data_waiting) return; } draw_x = 0; diff --git a/main.c b/main.c index a1c34fb..2c53fc0 100644 --- a/main.c +++ b/main.c @@ -38,6 +38,7 @@ const uint8_t REVERSE_BITS[256] = { // reverse order of bits in a byte }; volatile uint32_t main_timer = 0; +volatile uint8_t data_waiting = 0; inline void int_main_timer (void) { diff --git a/main.h b/main.h index 0cade12..57f0490 100644 --- a/main.h +++ b/main.h @@ -10,6 +10,10 @@ Redistribution and use in source and binary forms, with or without modification, THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define DATA_FLAG_AIX 0b0001 +#define DATA_FLAG_CTRL_IN 0b0100 +#define DATA_FLAG_CTRL_OUT 0b1000 + #include #include "klavirko-ui.h" @@ -35,3 +39,4 @@ uint8_t make_hex_string ( // create hexadecimal text representation of number extern const uint8_t REVERSE_BITS[256]; // reverse order of bits in a byte extern volatile uint32_t main_timer; // milliseconds since start +extern volatile uint8_t data_waiting ; // data flags diff --git a/vector_table.c b/vector_table.c index 42b85ce..08fd781 100644 --- a/vector_table.c +++ b/vector_table.c @@ -1,5 +1,5 @@ /* -Copyright 2021 Balthasar Szczepański +Copyright 2021, 2025 Balthasar Szczepański Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -53,7 +53,7 @@ const void *Vectors[] __attribute__ ((section (".vects"))) = { FALLBACK_INT, // INT_CSI00/INT_IIC00/INT_ST0 (0x1E) int_aix_rx,///////INT_CSI01/INT_IIC01/INT_SR0 (0x20) int_aix_err,//////INT_SRE0/INT_TM01H (0x22) - FALLBACK_INT, // INT_ST1 (0x24) + int_ctrl_tx,//////INT_ST1 (0x24) int_ctrl_rx,//////INT_CSI11/INT_IIC11/INT_SR1 (0x26) int_ctrl_err,/////INT_SRE1/INT_TM03H (0x28) FALLBACK_INT, // INT_IICA0 (0x2A)