@@ -98,68 +98,18 @@ STATIC mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
98
98
hd = -1 ;
99
99
}
100
100
101
- int clk = (int )args [ARG_sclk ].u_int ;
102
- int mosi = (int )args [ARG_mosi ].u_int ;
103
- int miso = (int )args [ARG_miso ].u_int ;
104
- int cs = (int )args [ARG_cs ].u_int ;
105
- int host = (int )args [ARG_host ].u_int ;
106
-
107
- int temp_host ;
108
-
109
- if (
110
- mosi == SPI_IOMUX_PIN_NUM_MOSI &&
111
- clk == SPI_IOMUX_PIN_NUM_CLK &&
112
- (miso == -1 || miso == SPI_IOMUX_PIN_NUM_MISO ) &&
113
- (cs == -1 || cs == SPI_IOMUX_PIN_NUM_CS ) &&
114
- (hd == -1 || hd == SPI_IOMUX_PIN_NUM_HD ) &&
115
- (wp == -1 || wp == SPI_IOMUX_PIN_NUM_WP )
116
- ) {
117
- flags |= SPICOMMON_BUSFLAG_IOMUX_PINS ;
118
- temp_host = SPI1_HOST ;
119
- } else if (
120
- mosi == SPI2_IOMUX_PIN_NUM_MOSI &&
121
- clk == SPI2_IOMUX_PIN_NUM_CLK &&
122
- (miso == -1 || miso == SPI2_IOMUX_PIN_NUM_MISO ) &&
123
- (cs == -1 || cs == SPI2_IOMUX_PIN_NUM_CS ) &&
124
- (hd == -1 || hd == SPI2_IOMUX_PIN_NUM_HD ) &&
125
- (wp == -1 || wp == SPI2_IOMUX_PIN_NUM_WP )
126
- ) {
127
- flags |= SPICOMMON_BUSFLAG_IOMUX_PINS ;
128
- temp_host = SPI2_HOST ;
129
- }
130
- #ifdef SPI3_IOMUX_PIN_NUM_MISO
131
- else if (
132
- mosi == SPI3_IOMUX_PIN_NUM_MOSI &&
133
- clk == SPI3_IOMUX_PIN_NUM_CLK &&
134
- (miso == -1 || miso == SPI3_IOMUX_PIN_NUM_MISO ) &&
135
- (cs == -1 || cs == SPI3_IOMUX_PIN_NUM_CS ) &&
136
- (hd == -1 || hd == SPI3_IOMUX_PIN_NUM_HD ) &&
137
- (wp == -1 || wp == SPI3_IOMUX_PIN_NUM_WP )
138
- ) {
139
- flags |= SPICOMMON_BUSFLAG_IOMUX_PINS ;
140
- temp_host = SPI3_HOST ;
141
- }
142
- #endif
143
- else {
144
- flags |= SPICOMMON_BUSFLAG_GPIO_PINS ;
145
- temp_host = -1 ;
146
- }
147
-
148
- if (temp_host == -1 && host == -1 ) {
149
- mp_raise_msg (& mp_type_ValueError , MP_ERROR_TEXT ("Unable to determine SPI host, please supply a host number" ));
150
- } else if (host == -1 ) {
151
- host = temp_host ;
152
- }
153
-
154
101
self -> callback = mp_const_none ;
155
102
103
+ int host = (int )args [ARG_host ].u_int ;
104
+ if (host == -1 ) host = 1 ;
105
+
156
106
self -> host = host ;
157
107
self -> bus_handle = (esp_lcd_spi_bus_handle_t )((uint32_t )host );
158
108
self -> panel_io_handle .panel_io = NULL ;
159
109
160
- self -> bus_config .sclk_io_num = clk ;
161
- self -> bus_config .mosi_io_num = mosi ;
162
- self -> bus_config .miso_io_num = miso ;
110
+ self -> bus_config .sclk_io_num = ( int ) args [ ARG_sclk ]. u_int ;
111
+ self -> bus_config .mosi_io_num = ( int ) args [ ARG_mosi ]. u_int ;
112
+ self -> bus_config .miso_io_num = ( int ) args [ ARG_miso ]. u_int ;
163
113
self -> bus_config .quadwp_io_num = wp ;
164
114
self -> bus_config .quadhd_io_num = hd ;
165
115
self -> bus_config .data4_io_num = -1 ;
@@ -168,7 +118,7 @@ STATIC mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
168
118
self -> bus_config .data7_io_num = -1 ;
169
119
self -> bus_config .flags = flags ;
170
120
171
- self -> panel_io_config .cs_gpio_num = cs ;
121
+ self -> panel_io_config .cs_gpio_num = ( int ) args [ ARG_cs ]. u_int ;
172
122
self -> panel_io_config .dc_gpio_num = (int )args [ARG_dc ].u_int ;
173
123
self -> panel_io_config .spi_mode = (int )args [ARG_spi_mode ].u_int ;
174
124
self -> panel_io_config .pclk_hz = (unsigned int )args [ARG_freq ].u_int ;
@@ -203,19 +153,6 @@ mp_lcd_err_t spi_del(mp_obj_t obj)
203
153
if (ret != 0 ) {
204
154
mp_raise_msg_varg (& mp_type_ValueError , MP_ERROR_TEXT ("%d(spi_bus_free)" ), ret );
205
155
}
206
-
207
- gpio_pad_select_gpio (self -> bus_config .miso_io_num );
208
- gpio_matrix_out (self -> bus_config .miso_io_num , SIG_GPIO_OUT_IDX , false, false);
209
- gpio_set_direction (self -> bus_config .miso_io_num , GPIO_MODE_INPUT );
210
-
211
- gpio_pad_select_gpio (self -> bus_config .mosi_io_num );
212
- gpio_matrix_out (self -> bus_config .mosi_io_num , SIG_GPIO_OUT_IDX , false, false);
213
- gpio_set_direction (self -> bus_config .mosi_io_num , GPIO_MODE_INPUT );
214
-
215
- gpio_pad_select_gpio (self -> bus_config .sclk_io_num );
216
- gpio_matrix_out (self -> bus_config .sclk_io_num , SIG_GPIO_OUT_IDX , false, false);
217
- gpio_set_direction (self -> bus_config .sclk_io_num , GPIO_MODE_INPUT );
218
-
219
156
return ret ;
220
157
}
221
158
@@ -232,7 +169,7 @@ mp_lcd_err_t spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
232
169
233
170
size_t max_trans_size ;
234
171
235
- if ((self -> buffer_flags ^ MALLOC_CAP_DMA ) && (self -> buf2 != NULL )) {
172
+ if ((self -> buffer_flags & MALLOC_CAP_DMA ) && (self -> buf2 != NULL )) {
236
173
max_trans_size = SPI_LL_DMA_MAX_BIT_LEN / 8 ;
237
174
} else {
238
175
max_trans_size = SPI_LL_CPU_MAX_BIT_LEN / 8 ;
@@ -246,7 +183,19 @@ mp_lcd_err_t spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
246
183
247
184
self -> panel_io_config .trans_queue_depth = 10 ;
248
185
249
- mp_lcd_err_t ret = spi_bus_initialize (self -> host , & self -> bus_config , SPI_DMA_CH_AUTO );
186
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
187
+ int dma_chan = SPI_DMA_CH_AUTO ;
188
+ #else
189
+ int dma_chan = 0 ;
190
+
191
+ if (self -> host == SPI2_HOST ) {
192
+ dma_chan = 1 ;
193
+ } else {
194
+ dma_chan = 2 ;
195
+ }
196
+ #endif
197
+
198
+ mp_lcd_err_t ret = spi_bus_initialize (self -> host , & self -> bus_config , dma_chan );
250
199
if (ret != 0 ) {
251
200
mp_raise_msg_varg (& mp_type_ValueError , MP_ERROR_TEXT ("%d(spi_bus_initialize)" ), ret );
252
201
}
0 commit comments