3434#include "tick.h"
3535
3636void common_hal_displayio_fourwire_construct (displayio_fourwire_obj_t * self ,
37- const mcu_pin_obj_t * clock , const mcu_pin_obj_t * data , const mcu_pin_obj_t * command ,
38- const mcu_pin_obj_t * chip_select , const mcu_pin_obj_t * reset , uint16_t width ,
39- uint16_t height , int16_t colstart , int16_t rowstart , uint16_t color_depth ,
40- uint8_t set_column_command , uint8_t set_row_command , uint8_t write_ram_command ) {
37+ busio_spi_obj_t * spi , const mcu_pin_obj_t * command ,
38+ const mcu_pin_obj_t * chip_select , const mcu_pin_obj_t * reset ) {
4139
42- common_hal_busio_spi_construct ( & self -> bus , clock , data , mp_const_none ) ;
43- common_hal_busio_spi_never_reset (& self -> bus );
40+ self -> bus = spi ;
41+ common_hal_busio_spi_never_reset (self -> bus );
4442
4543 common_hal_digitalio_digitalinout_construct (& self -> command , command );
4644 common_hal_digitalio_digitalinout_switch_to_output (& self -> command , true, DRIVE_MODE_PUSH_PULL );
@@ -53,93 +51,27 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
5351 never_reset_pin_number (command -> number );
5452 never_reset_pin_number (chip_select -> number );
5553 never_reset_pin_number (reset -> number );
56-
57- self -> width = width ;
58- self -> height = height ;
59- self -> color_depth = color_depth ;
60- self -> set_column_command = set_column_command ;
61- self -> set_row_command = set_row_command ;
62- self -> write_ram_command = write_ram_command ;
63- self -> current_group = NULL ;
64- self -> colstart = colstart ;
65- self -> rowstart = rowstart ;
6654}
6755
68- bool common_hal_displayio_fourwire_begin_transaction (displayio_fourwire_obj_t * self ) {
69- if (!common_hal_busio_spi_try_lock (& self -> bus )) {
56+ bool common_hal_displayio_fourwire_begin_transaction (mp_obj_t obj ) {
57+ displayio_fourwire_obj_t * self = MP_OBJ_TO_PTR (obj );
58+ if (!common_hal_busio_spi_try_lock (self -> bus )) {
7059 return false;
7160 }
7261 // TODO(tannewt): Stop hardcoding SPI frequency, polarity and phase.
73- common_hal_busio_spi_configure (& self -> bus , 48000000 , 0 , 0 , 8 );
62+ common_hal_busio_spi_configure (self -> bus , 12000000 , 0 , 0 , 8 );
7463 common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
7564 return true;
7665}
7766
78- void common_hal_displayio_fourwire_send (displayio_fourwire_obj_t * self , bool command , uint8_t * data , uint32_t data_length ) {
67+ void common_hal_displayio_fourwire_send (mp_obj_t obj , bool command , uint8_t * data , uint32_t data_length ) {
68+ displayio_fourwire_obj_t * self = MP_OBJ_TO_PTR (obj );
7969 common_hal_digitalio_digitalinout_set_value (& self -> command , !command );
80- common_hal_busio_spi_write (& self -> bus , data , data_length );
70+ common_hal_busio_spi_write (self -> bus , data , data_length );
8171}
8272
83- void common_hal_displayio_fourwire_end_transaction (displayio_fourwire_obj_t * self ) {
73+ void common_hal_displayio_fourwire_end_transaction (mp_obj_t obj ) {
74+ displayio_fourwire_obj_t * self = MP_OBJ_TO_PTR (obj );
8475 common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
85- common_hal_busio_spi_unlock (& self -> bus );
86- }
87-
88- void common_hal_displayio_fourwire_show (displayio_fourwire_obj_t * self , displayio_group_t * root_group ) {
89- self -> current_group = root_group ;
90- common_hal_displayio_fourwire_refresh_soon (self );
91- }
92-
93- void common_hal_displayio_fourwire_refresh_soon (displayio_fourwire_obj_t * self ) {
94- self -> refresh = true;
95- }
96-
97- int32_t common_hal_displayio_fourwire_wait_for_frame (displayio_fourwire_obj_t * self ) {
98- uint64_t last_refresh = self -> last_refresh ;
99- while (last_refresh == self -> last_refresh ) {
100- MICROPY_VM_HOOK_LOOP
101- }
102- return 0 ;
103- }
104-
105- void displayio_fourwire_start_region_update (displayio_fourwire_obj_t * self , uint16_t x0 , uint16_t y0 , uint16_t x1 , uint16_t y1 ) {
106- // TODO(tannewt): Handle displays with single byte bounds.
107- common_hal_displayio_fourwire_begin_transaction (self );
108- uint16_t data [2 ];
109- common_hal_displayio_fourwire_send (self , true, & self -> set_column_command , 1 );
110- data [0 ] = __builtin_bswap16 (x0 + self -> colstart );
111- data [1 ] = __builtin_bswap16 (x1 - 1 + self -> colstart );
112- common_hal_displayio_fourwire_send (self , false, (uint8_t * ) data , 4 );
113- common_hal_displayio_fourwire_send (self , true, & self -> set_row_command , 1 );
114- data [0 ] = __builtin_bswap16 (y0 + 1 + self -> rowstart );
115- data [1 ] = __builtin_bswap16 (y1 + self -> rowstart );
116- common_hal_displayio_fourwire_send (self , false, (uint8_t * ) data , 4 );
117- common_hal_displayio_fourwire_send (self , true, & self -> write_ram_command , 1 );
118- }
119-
120- bool displayio_fourwire_send_pixels (displayio_fourwire_obj_t * self , uint32_t * pixels , uint32_t length ) {
121- // TODO: Set this up so its async and 32 bit DMA transfers.
122- common_hal_displayio_fourwire_send (self , false, (uint8_t * ) pixels , length * 4 );
123- return true;
124- }
125-
126- void displayio_fourwire_finish_region_update (displayio_fourwire_obj_t * self ) {
127- common_hal_displayio_fourwire_end_transaction (self );
128- }
129-
130- bool displayio_fourwire_frame_queued (displayio_fourwire_obj_t * self ) {
131- // Refresh at ~30 fps.
132- return (ticks_ms - self -> last_refresh ) > 32 ;
133- }
134-
135- bool displayio_fourwire_refresh_queued (displayio_fourwire_obj_t * self ) {
136- return self -> refresh || (self -> current_group != NULL && displayio_group_needs_refresh (self -> current_group ));
137- }
138-
139- void displayio_fourwire_finish_refresh (displayio_fourwire_obj_t * self ) {
140- if (self -> current_group != NULL ) {
141- displayio_group_finish_refresh (self -> current_group );
142- }
143- self -> refresh = false;
144- self -> last_refresh = ticks_ms ;
76+ common_hal_busio_spi_unlock (self -> bus );
14577}
0 commit comments