1313#include <stdio.h>
1414#include <string.h>
1515
16- #include <contiki.h>
17-
1816#include "../core.h"
1917
2018#include <pbdrv/display.h>
2119#include <pbdrv/gpio.h>
2220#include <pbio/error.h>
21+ #include <pbio/os.h>
2322#include <pbio/util.h>
2423
2524#include <tiam1808/edma.h>
@@ -112,8 +111,6 @@ static const pbdrv_gpio_t pin_lcd_reset = PBDRV_GPIO_EV3_PIN(12, 31, 28, 5, 0);
112111
113112static volatile spi_status_t spi_status = SPI_STATUS_ERROR ;
114113
115- PROCESS (pbdrv_display_ev3_init_process , "st7586s" );
116-
117114/**
118115 * Number of column triplets. Each triplet is 3 columns of pixels, as detailed
119116 * below in the description of the display buffer.
@@ -350,7 +347,7 @@ static const pbdrv_display_st7586s_action_t init_script[] = {
350347void pbdrv_display_ev3_spi1_tx_complete (uint32_t status ) {
351348 SPIIntDisable (SOC_SPI_1_REGS , SPI_DMA_REQUEST_ENA_INT );
352349 spi_status = SPI_STATUS_COMPLETE ;
353- process_poll ( & pbdrv_display_ev3_init_process );
350+ pbio_os_request_poll ( );
354351}
355352
356353/**
@@ -412,7 +409,7 @@ void pbdrv_display_st7586s_write_data_begin(uint8_t *data, uint32_t size) {
412409 *
413410 * Pinmux and common EDMA handlers are already set up in platform.c.
414411 */
415- void pbdrv_display_init (void ) {
412+ static void pbdrv_display_ev3_spi_init (void ) {
416413
417414 // GPIO Mux. CS is in GPIO mode (manual control).
418415 pbdrv_gpio_alt (& pin_spi1_mosi , SYSCFG_PINMUX5_PINMUX5_23_20_SPI1_SIMO0 );
@@ -445,32 +442,27 @@ void pbdrv_display_init(void) {
445442
446443 // Enable the SPI controller.
447444 SPIEnable (SOC_SPI_1_REGS );
448-
449- // Start SPI process and ask pbdrv to wait until it is initialized.
450- pbdrv_init_busy_up ();
451- process_start (& pbdrv_display_ev3_init_process );
452445}
453446
447+ static pbio_os_process_t pbdrv_display_ev3_process ;
448+
454449/**
455450 * Display driver process. Initializes the display and updates the display
456- * with the user frame buffer at a regular interval if the user data was
457- * updated.
451+ * with the user frame buffer if the user data was updated.
458452 */
459- PROCESS_THREAD ( pbdrv_display_ev3_init_process , ev , data ) {
453+ static pbio_error_t pbdrv_display_ev3_process_thread ( pbio_os_state_t * state , void * context ) {
460454
461- static struct etimer etimer ;
455+ static pbio_os_timer_t timer ;
462456 static uint32_t script_index ;
463457 static uint8_t payload ;
464458
465- PROCESS_BEGIN ( );
459+ PBIO_OS_ASYNC_BEGIN ( state );
466460
467461 #if ST7586S_DO_RESET_AND_INIT
468462 pbdrv_gpio_out_low (& pin_lcd_reset );
469- etimer_set (& etimer , 10 );
470- PROCESS_WAIT_EVENT_UNTIL (ev == PROCESS_EVENT_TIMER && etimer_expired (& etimer ));
463+ PBIO_OS_AWAIT_MS (state , & timer , 10 );
471464 pbdrv_gpio_out_high (& pin_lcd_reset );
472- etimer_set (& etimer , 120 );
473- PROCESS_WAIT_EVENT_UNTIL (ev == PROCESS_EVENT_TIMER && etimer_expired (& etimer ));
465+ PBIO_OS_AWAIT_MS (state , & timer , 120 );
474466 #endif // ST7586S_DO_RESET_AND_INIT
475467
476468 // For every action in the init script, either send a command or data, or
@@ -480,8 +472,7 @@ PROCESS_THREAD(pbdrv_display_ev3_init_process, ev, data) {
480472
481473 if (action -> type == ST7586S_ACTION_DELAY ) {
482474 // Simple delay.
483- etimer_set (& etimer , action -> payload );
484- PROCESS_WAIT_EVENT_UNTIL (ev == PROCESS_EVENT_TIMER && etimer_expired (& etimer ));
475+ PBIO_OS_AWAIT_MS (state , & timer , action -> payload );
485476 } else {
486477 // Send command or data.
487478 payload = action -> payload ;
@@ -491,7 +482,7 @@ PROCESS_THREAD(pbdrv_display_ev3_init_process, ev, data) {
491482 pbdrv_gpio_out_low (& pin_lcd_a0 );
492483 }
493484 pbdrv_display_st7586s_write_data_begin (& payload , sizeof (payload ));
494- PROCESS_WAIT_EVENT_UNTIL ( ev == PROCESS_EVENT_POLL && spi_status == SPI_STATUS_COMPLETE );
485+ PBIO_OS_AWAIT_UNTIL ( state , spi_status == SPI_STATUS_COMPLETE );
495486 pbdrv_gpio_out_high (& pin_lcd_cs );
496487 }
497488 }
@@ -503,35 +494,49 @@ PROCESS_THREAD(pbdrv_display_ev3_init_process, ev, data) {
503494 pbdrv_display_load_indexed_bitmap (pbdrv_display_pybricks_logo );
504495 pbdrv_display_st7586s_encode_user_frame ();
505496 pbdrv_display_st7586s_write_data_begin (st7586s_send_buf , sizeof (st7586s_send_buf ));
506- PROCESS_WAIT_EVENT_UNTIL ( ev == PROCESS_EVENT_POLL && spi_status == SPI_STATUS_COMPLETE );
497+ PBIO_OS_AWAIT_UNTIL ( state , spi_status == SPI_STATUS_COMPLETE );
507498 pbdrv_gpio_out_high (& pin_lcd_cs );
508499
509500 // Done initializing.
510501 pbdrv_init_busy_down ();
511502
512- // Regularly update the display with the user frame buffer, if changed.
513- etimer_set (& etimer , 40 );
503+ // Update the display with the user frame buffer, if changed.
514504 for (;;) {
515- PROCESS_WAIT_EVENT_UNTIL (ev == PROCESS_EVENT_TIMER && etimer_expired (& etimer ));
516- if (pbdrv_display_user_frame_update_requested ) {
517- pbdrv_display_user_frame_update_requested = false;
518- pbdrv_display_st7586s_encode_user_frame ();
519- pbdrv_display_st7586s_write_data_begin (st7586s_send_buf , sizeof (st7586s_send_buf ));
520- PROCESS_WAIT_EVENT_UNTIL (ev == PROCESS_EVENT_POLL && spi_status == SPI_STATUS_COMPLETE );
521- pbdrv_gpio_out_high (& pin_lcd_cs );
522- }
523- etimer_reset (& etimer );
505+ PBIO_OS_AWAIT_UNTIL (state , pbdrv_display_user_frame_update_requested );
506+ pbdrv_display_user_frame_update_requested = false;
507+ pbdrv_display_st7586s_encode_user_frame ();
508+ pbdrv_display_st7586s_write_data_begin (st7586s_send_buf , sizeof (st7586s_send_buf ));
509+ PBIO_OS_AWAIT_UNTIL (state , spi_status == SPI_STATUS_COMPLETE );
510+ pbdrv_gpio_out_high (& pin_lcd_cs );
524511 }
525512
526- PROCESS_END ( );
513+ PBIO_OS_ASYNC_END ( PBIO_SUCCESS );
527514}
528515
529- pbio_image_t * pbdrv_display_get_image (void ) {
530- static pbio_image_t image ;
531- pbio_image_init (& image , (uint8_t * )pbdrv_display_user_frame ,
516+ /**
517+ * Image corresponding to the display.
518+ */
519+ static pbio_image_t display_image ;
520+
521+ /**
522+ * Initialize the display driver.
523+ */
524+ void pbdrv_display_init (void ) {
525+ // Initialize SPI.
526+ pbdrv_display_ev3_spi_init ();
527+
528+ // Initialize image.
529+ pbio_image_init (& display_image , (uint8_t * )pbdrv_display_user_frame ,
532530 PBDRV_CONFIG_DISPLAY_NUM_COLS , PBDRV_CONFIG_DISPLAY_NUM_ROWS ,
533531 PBDRV_CONFIG_DISPLAY_NUM_COLS );
534- return & image ;
532+
533+ // Start display process and ask pbdrv to wait until it is initialized.
534+ pbdrv_init_busy_up ();
535+ pbio_os_process_start (& pbdrv_display_ev3_process , pbdrv_display_ev3_process_thread , NULL );
536+ }
537+
538+ pbio_image_t * pbdrv_display_get_image (void ) {
539+ return & display_image ;
535540}
536541
537542uint8_t pbdrv_display_get_max_value (void ) {
@@ -540,6 +545,7 @@ uint8_t pbdrv_display_get_max_value(void) {
540545
541546void pbdrv_display_update (void ) {
542547 pbdrv_display_user_frame_update_requested = true;
548+ pbio_os_request_poll ();
543549}
544550
545551#endif // PBDRV_CONFIG_DISPLAY_EV3
0 commit comments