@@ -214,18 +214,68 @@ ZTEST(spi_loopback, test_spi_complete_multiple)
214
214
buffer_print_tx2 , buffer_print_rx2 );
215
215
}
216
216
217
- ZTEST ( spi_loopback , test_spi_complete_loop )
217
+ void spi_loopback_test_mode ( struct spi_dt_spec * spec , bool cpol , bool cpha )
218
218
{
219
- struct spi_dt_spec * spec = loopback_specs [spec_idx ];
220
219
const struct spi_buf_set tx = spi_loopback_setup_xfer (tx_bufs_pool , 1 ,
221
220
buffer_tx , BUF_SIZE );
222
221
const struct spi_buf_set rx = spi_loopback_setup_xfer (rx_bufs_pool , 1 ,
223
222
buffer_rx , BUF_SIZE );
223
+ uint32_t original_op = spec -> config .operation ;
224
+
225
+ if (cpol ) {
226
+ spec -> config .operation |= SPI_MODE_CPOL ;
227
+ } else {
228
+ spec -> config .operation &= ~SPI_MODE_CPOL ;
229
+ }
230
+
231
+ if (cpha ) {
232
+ spec -> config .operation |= SPI_MODE_CPHA ;
233
+ } else {
234
+ spec -> config .operation &= ~SPI_MODE_CPHA ;
235
+ }
224
236
225
237
spi_loopback_transceive (spec , & tx , & rx );
226
238
239
+ spec -> config .operation = original_op ;
240
+
227
241
spi_loopback_compare_bufs (buffer_tx , buffer_rx , BUF_SIZE ,
228
- buffer_print_tx , buffer_print_rx );
242
+ buffer_print_tx , buffer_print_rx );
243
+ }
244
+
245
+ ZTEST (spi_loopback , test_spi_complete_loop_mode_0 )
246
+ {
247
+ struct spi_dt_spec * spec = loopback_specs [spec_idx ];
248
+ struct spi_dt_spec * spec_copy = & spec_copies [0 ];
249
+ * spec_copy = * spec ;
250
+
251
+ spi_loopback_test_mode (spec_copy , false, false);
252
+ }
253
+
254
+ ZTEST (spi_loopback , test_spi_complete_loop_mode_1 )
255
+ {
256
+ struct spi_dt_spec * spec = loopback_specs [spec_idx ];
257
+ struct spi_dt_spec * spec_copy = & spec_copies [1 ];
258
+ * spec_copy = * spec ;
259
+
260
+ spi_loopback_test_mode (spec_copy , false, true);
261
+ }
262
+
263
+ ZTEST (spi_loopback , test_spi_complete_loop_mode_2 )
264
+ {
265
+ struct spi_dt_spec * spec = loopback_specs [spec_idx ];
266
+ struct spi_dt_spec * spec_copy = & spec_copies [2 ];
267
+ * spec_copy = * spec ;
268
+
269
+ spi_loopback_test_mode (spec_copy , true, false);
270
+ }
271
+
272
+ ZTEST (spi_loopback , test_spi_complete_loop_mode_3 )
273
+ {
274
+ struct spi_dt_spec * spec = loopback_specs [spec_idx ];
275
+ struct spi_dt_spec * spec_copy = & spec_copies [3 ];
276
+ * spec_copy = * spec ;
277
+
278
+ spi_loopback_test_mode (spec_copy , true, true);
229
279
}
230
280
231
281
ZTEST (spi_loopback , test_spi_null_tx_buf )
0 commit comments