2525#define QSPI_DMA_BUFFER_COUNT (2U)
2626#define QSPI_DMA_BUFFER_SIZE (16U * 1024U)
2727#define QSPI_COLOR_TIMEOUT_MS (1000U)
28- #if defined(CIRCUITPY_LCD_POWER )
29- #define CIRCUITPY_QSPIBUS_PANEL_POWER_PIN CIRCUITPY_LCD_POWER
30- #endif
31-
32- #ifndef CIRCUITPY_LCD_POWER_ON_LEVEL
33- #define CIRCUITPY_LCD_POWER_ON_LEVEL (1)
34- #endif
35-
3628static void qspibus_release_dma_buffers (qspibus_qspibus_obj_t * self ) {
3729 for (size_t i = 0 ; i < QSPI_DMA_BUFFER_COUNT ; i ++ ) {
3830 if (self -> dma_buffer [i ] != NULL ) {
@@ -279,7 +271,6 @@ void common_hal_qspibus_qspibus_construct(
279271 self -> cs_pin = cs -> number ;
280272 self -> dcx_pin = (dcx != NULL ) ? dcx -> number : -1 ;
281273 self -> reset_pin = (reset != NULL ) ? reset -> number : -1 ;
282- self -> power_pin = -1 ;
283274 self -> frequency = frequency ;
284275 self -> bus_initialized = false;
285276 self -> in_transaction = false;
@@ -319,7 +310,7 @@ void common_hal_qspibus_qspibus_construct(
319310 qspibus_release_dma_buffers (self );
320311 vSemaphoreDelete (self -> transfer_done_sem );
321312 self -> transfer_done_sem = NULL ;
322- mp_raise_OSError_msg_varg (MP_ERROR_TEXT ("%q failure: %d " ), MP_QSTR_SPI , ( int ) err );
313+ mp_raise_ValueError_varg (MP_ERROR_TEXT ("%q in use " ), MP_QSTR_SPI );
323314 }
324315
325316 const esp_lcd_panel_io_spi_config_t io_config = {
@@ -358,21 +349,6 @@ void common_hal_qspibus_qspibus_construct(
358349 gpio_set_level ((gpio_num_t )self -> dcx_pin , 1 );
359350 }
360351
361- #ifdef CIRCUITPY_QSPIBUS_PANEL_POWER_PIN
362- const mcu_pin_obj_t * power = CIRCUITPY_QSPIBUS_PANEL_POWER_PIN ;
363- if (power != NULL ) {
364- if (!common_hal_mcu_pin_is_free (power )) {
365- mp_raise_ValueError_varg (MP_ERROR_TEXT ("%q in use" ), MP_QSTR_LCD_POWER );
366- }
367- self -> power_pin = power -> number ;
368- claim_pin (power );
369- gpio_set_direction ((gpio_num_t )self -> power_pin , GPIO_MODE_OUTPUT );
370- gpio_set_level ((gpio_num_t )self -> power_pin , CIRCUITPY_LCD_POWER_ON_LEVEL ? 1 : 0 );
371- // Panel power rail needs extra settle time before reset/init commands.
372- vTaskDelay (pdMS_TO_TICKS (200 ));
373- }
374- #endif
375-
376352 if (reset != NULL ) {
377353 claim_pin (reset );
378354
@@ -420,9 +396,6 @@ void common_hal_qspibus_qspibus_deinit(qspibus_qspibus_obj_t *self) {
420396 if (self -> dcx_pin >= 0 ) {
421397 reset_pin_number (self -> dcx_pin );
422398 }
423- if (self -> power_pin >= 0 ) {
424- reset_pin_number (self -> power_pin );
425- }
426399 if (self -> reset_pin >= 0 ) {
427400 reset_pin_number (self -> reset_pin );
428401 }
@@ -446,7 +419,7 @@ void common_hal_qspibus_qspibus_write_command(
446419 raise_deinited_error ();
447420 }
448421 if (self -> in_transaction ) {
449- mp_raise_RuntimeError (MP_ERROR_TEXT ("Bus in display transaction " ));
422+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Internal error " ));
450423 }
451424
452425 // If caller stages command-only operations repeatedly, flush the previous
@@ -467,7 +440,7 @@ void common_hal_qspibus_qspibus_write_data(
467440 raise_deinited_error ();
468441 }
469442 if (self -> in_transaction ) {
470- mp_raise_RuntimeError (MP_ERROR_TEXT ("Bus in display transaction " ));
443+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Internal error " ));
471444 }
472445 if (len == 0 ) {
473446 if (self -> has_pending_command ) {
@@ -477,7 +450,7 @@ void common_hal_qspibus_qspibus_write_data(
477450 return ;
478451 }
479452 if (!self -> has_pending_command ) {
480- mp_raise_ValueError (MP_ERROR_TEXT ("No pending command " ));
453+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Internal error " ));
481454 }
482455
483456 if (qspibus_is_color_payload_command (self -> pending_command )) {
@@ -545,7 +518,7 @@ void common_hal_qspibus_qspibus_send(
545518 raise_deinited_error ();
546519 }
547520 if (!self -> in_transaction ) {
548- mp_raise_RuntimeError (MP_ERROR_TEXT ("Begin transaction first " ));
521+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Internal error " ));
549522 }
550523
551524 if (data_type == DISPLAY_COMMAND ) {
@@ -564,7 +537,7 @@ void common_hal_qspibus_qspibus_send(
564537 // Zero-length data write after a no-data command is benign.
565538 return ;
566539 }
567- mp_raise_ValueError (MP_ERROR_TEXT ("No pending command " ));
540+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Internal error " ));
568541 }
569542
570543 if (data_length == 0 ) {
@@ -593,6 +566,16 @@ void common_hal_qspibus_qspibus_end_transaction(mp_obj_t obj) {
593566 self -> in_transaction = false;
594567}
595568
569+ void common_hal_qspibus_qspibus_flush (mp_obj_t obj ) {
570+ qspibus_qspibus_obj_t * self = MP_OBJ_TO_PTR (obj );
571+ if (!self -> bus_initialized ) {
572+ return ;
573+ }
574+ if (!qspibus_wait_all_transfers_done (self , pdMS_TO_TICKS (QSPI_COLOR_TIMEOUT_MS ))) {
575+ qspibus_reset_transfer_state (self );
576+ }
577+ }
578+
596579void common_hal_qspibus_qspibus_collect_ptrs (mp_obj_t obj ) {
597580 (void )obj ;
598581}
0 commit comments