@@ -47,8 +47,6 @@ void common_hal_fourwire_fourwire_construct(fourwire_fourwire_obj_t *self,
47
47
self -> polarity = polarity ;
48
48
self -> phase = phase ;
49
49
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 );
52
50
53
51
self -> command .base .type = & mp_type_NoneType ;
54
52
if (command != NULL ) {
@@ -66,7 +64,14 @@ void common_hal_fourwire_fourwire_construct(fourwire_fourwire_obj_t *self,
66
64
common_hal_fourwire_fourwire_reset (self );
67
65
}
68
66
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
+
70
75
}
71
76
72
77
void 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) {
107
112
}
108
113
common_hal_busio_spi_configure (self -> bus , self -> frequency , self -> polarity ,
109
114
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
+ }
111
118
return true;
112
119
}
113
120
@@ -146,10 +153,12 @@ void common_hal_fourwire_fourwire_send(mp_obj_t obj, display_byte_type_t data_ty
146
153
if (bits > 0 ) {
147
154
buffer = buffer << (8 - bits );
148
155
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
+ }
153
162
}
154
163
} else {
155
164
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
158
167
// IC latches commands based on it.
159
168
for (size_t i = 0 ; i < data_length ; i ++ ) {
160
169
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
+ }
164
175
}
165
176
} else {
166
177
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
170
181
171
182
void common_hal_fourwire_fourwire_end_transaction (mp_obj_t obj ) {
172
183
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
+ }
174
187
common_hal_busio_spi_unlock (self -> bus );
175
188
}
176
189
0 commit comments