From 3c9681392ea2c5e13e15c5d94af6590e0ce497eb Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 19 Dec 2024 10:01:48 +0100 Subject: [PATCH] feat(arm07): use rx not empty as not busy flag --- arm07/src/main.c | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/arm07/src/main.c b/arm07/src/main.c index 8a7ea1c..f0ebeef 100644 --- a/arm07/src/main.c +++ b/arm07/src/main.c @@ -383,17 +383,12 @@ void main() pin_set(&pin_csn); pin_into_output_pushpull(&pin_csn); - timer_init(&spi_csn_timer, TIM4, 4); - timer_set_refresh(&spi_csn_timer, 1); - timer_configure(&spi_csn_timer, 0, 10000, 0); - timer_enable_interrupt(&spi_csn_timer, true, false); - spi_init(&matrix_spi, pin_csn, SPI1, 1); spi_master_configure_speed(&matrix_spi, 7); spi_master_configure(&matrix_spi, false, false, false, SPI_MSB_FIRST, SPI_FRAME_16_BIT); - spi_enable_interrupt(&matrix_spi, true, false); + spi_enable_interrupt(&matrix_spi, false, true); spi_master_enable(&matrix_spi, true); } @@ -403,7 +398,6 @@ void main() matrix_enable(&matrix, true); matrix_set_buffer(&matrix, MATRIX_SLOT0, images[current_image]); - timer_init(&matrix_timer, TIM3, 3); timer_set_refresh(&matrix_timer, 20); timer_configure(&matrix_timer, 0, 60000, 0); @@ -482,36 +476,14 @@ void TIM3_handler(void) { bool spi_can_transmit_flag = true; void SPI1_handler(void) { - /* if (spi_can_receive(&matrix_spi)) { */ - /* buffered_transceiver_trigger_receive(&matrix_tx, 1); */ - /* } */ - if (spi_can_transmit(&matrix_spi)) { - // - spi_can_transmit_flag = false; - timer_set_counter(&spi_csn_timer, 0); - timer_enable(&spi_csn_timer); - - // Disable interrupt so cpu is not locked - spi_enable_interrupt(&matrix_spi, false, false); - } -} - -void TIM4_handler(void) { - timer_clear_update_interrupt(&spi_csn_timer); + // using can receive as not busy interrupt + if (spi_can_receive(&matrix_spi)) { + uint16_t tmp; + spi_receive(&matrix_spi, &tmp, 1); - if (!(matrix_spi.periph->SR & SPI_SR_BSY)) { - // puse CSN. spi_pulse_csn(&matrix_spi); - - // Allow sending... spi_can_transmit_flag = true; - - // Disable this timer until transmission is done again - timer_disable(&spi_csn_timer); - - // Transmit only after the pulse. SPI is enabled again. buffered_transceiver_trigger_transmit(&matrix_tx, 1); - } } @@ -541,7 +513,7 @@ uint16_t spi_generic_receive(void *peripheral, void *buffer, uint16_t spi_generic_transmit(void *peripheral, void *data, uint16_t size) { // enable the interrupt so that we can send the rest uint16_t ret = spi_transmit((spi_t*)peripheral, data, size); - spi_enable_interrupt((spi_t*)peripheral, true, false); + spi_can_transmit_flag = false; return ret; } -- 2.48.1