@@ -47,8 +47,6 @@ void common_hal_fourwire_fourwire_construct(fourwire_fourwire_obj_t *self,
4747 self -> polarity = polarity ;
4848 self -> phase = phase ;
4949
50- common_hal_digitalio_digitalinout_construct (& self -> chip_select , chip_select );
51- common_hal_digitalio_digitalinout_switch_to_output (& self -> chip_select , true, DRIVE_MODE_PUSH_PULL );
5250
5351 self -> command .base .type = & mp_type_NoneType ;
5452 if (command != NULL ) {
@@ -66,7 +64,14 @@ void common_hal_fourwire_fourwire_construct(fourwire_fourwire_obj_t *self,
6664 common_hal_fourwire_fourwire_reset (self );
6765 }
6866
69- common_hal_never_reset_pin (chip_select );
67+ self -> chip_select .base .type = & mp_type_NoneType ;
68+ if (chip_select != NULL ) {
69+ self -> chip_select .base .type = & digitalio_digitalinout_type ;
70+ common_hal_digitalio_digitalinout_construct (& self -> chip_select , chip_select );
71+ common_hal_digitalio_digitalinout_switch_to_output (& self -> chip_select , true, DRIVE_MODE_PUSH_PULL );
72+ common_hal_never_reset_pin (chip_select );
73+ }
74+
7075}
7176
7277void common_hal_fourwire_fourwire_deinit (fourwire_fourwire_obj_t * self ) {
@@ -107,7 +112,9 @@ bool common_hal_fourwire_fourwire_begin_transaction(mp_obj_t obj) {
107112 }
108113 common_hal_busio_spi_configure (self -> bus , self -> frequency , self -> polarity ,
109114 self -> phase , 8 );
110- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
115+ if (self -> chip_select .base .type != & mp_type_NoneType ) {
116+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
117+ }
111118 return true;
112119}
113120
@@ -146,10 +153,12 @@ void common_hal_fourwire_fourwire_send(mp_obj_t obj, display_byte_type_t data_ty
146153 if (bits > 0 ) {
147154 buffer = buffer << (8 - bits );
148155 common_hal_busio_spi_write (self -> bus , & buffer , 1 );
149- // toggle CS to discard superfluous bits
150- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
151- common_hal_mcu_delay_us (1 );
152- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
156+ if (self -> chip_select .base .type != & mp_type_NoneType ) {
157+ // toggle CS to discard superfluous bits
158+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
159+ common_hal_mcu_delay_us (1 );
160+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
161+ }
153162 }
154163 } else {
155164 common_hal_digitalio_digitalinout_set_value (& self -> command , data_type == DISPLAY_DATA );
@@ -158,9 +167,11 @@ void common_hal_fourwire_fourwire_send(mp_obj_t obj, display_byte_type_t data_ty
158167 // IC latches commands based on it.
159168 for (size_t i = 0 ; i < data_length ; i ++ ) {
160169 common_hal_busio_spi_write (self -> bus , & data [i ], 1 );
161- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
162- common_hal_mcu_delay_us (1 );
163- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
170+ if (self -> chip_select .base .type != & mp_type_NoneType ) {
171+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
172+ common_hal_mcu_delay_us (1 );
173+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , false);
174+ }
164175 }
165176 } else {
166177 common_hal_busio_spi_write (self -> bus , data , data_length );
@@ -170,7 +181,9 @@ void common_hal_fourwire_fourwire_send(mp_obj_t obj, display_byte_type_t data_ty
170181
171182void common_hal_fourwire_fourwire_end_transaction (mp_obj_t obj ) {
172183 fourwire_fourwire_obj_t * self = MP_OBJ_TO_PTR (obj );
173- common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
184+ if (self -> chip_select .base .type != & mp_type_NoneType ) {
185+ common_hal_digitalio_digitalinout_set_value (& self -> chip_select , true);
186+ }
174187 common_hal_busio_spi_unlock (self -> bus );
175188}
176189
0 commit comments