@@ -38,7 +38,7 @@ const uint PIO_CLK_DIV_INIT = 2;
3838
3939const uint PIO_CLK_DIV_RUN = 1 ;
4040
41- const uint PIN_SDIO_UNDEFINED = 31u ;
41+ const uint PIN_SDIO_UNDEFINED = 48u ;
4242
4343const uint DAT_FIFO_DEPTH = 8 ;
4444const uint CMD0_RETRIES = 10 ;
@@ -260,6 +260,26 @@ static void pioEnd() {
260260static bool pioInit () {
261261 uint pin[] = {g_clkPin, g_cmdPin, g_dat0Pin,
262262 g_dat0Pin + 1 , g_dat0Pin + 2 , g_dat0Pin + 3 };
263+
264+ uint lowest_pin = pin[0 ];
265+ uint highest_pin = pin[0 ];
266+ uint gpio_base = 0 ;
267+ for (uint i = 0 ; i < 6U ; i++) {
268+ if (pin[i] < lowest_pin) {
269+ lowest_pin = pin[i];
270+ }
271+ if (pin[i] > highest_pin) {
272+ highest_pin = pin[i];
273+ }
274+ }
275+ if (highest_pin - lowest_pin > 31 ) {
276+ sdError (PIO_ERROR_ADD_PROGRAM);
277+ return false ;
278+ }
279+ if (highest_pin > 31 ) {
280+ gpio_base = 16 ;
281+ }
282+
263283 if (g_wrRespOffset < 0 ) {
264284 uint16_t patched_inst[rd_data_program.length ]; // NOLINT
265285 struct pio_program tmp_program;
@@ -280,6 +300,9 @@ static bool pioInit() {
280300 sdError (PIO_ERROR_ADD_PROGRAM);
281301 goto fail;
282302 }
303+ if (gpio_base > 0 ) {
304+ pio_set_gpio_base (g_pio, gpio_base);
305+ }
283306 g_sm0 = pio_claim_unused_sm (g_pio, false );
284307 if (g_sm0 < 0 ) {
285308 sdError (PIO_ERROR_ADD_PROGRAM);
@@ -327,7 +350,7 @@ static bool pioInit() {
327350 }
328351
329352 g_pio->input_sync_bypass |=
330- (1 << g_clkPin) | (1 << g_cmdPin) | (0XF << g_dat0Pin);
353+ (1 << ( g_clkPin-gpio_base)) | (1 << ( g_cmdPin-gpio_base)) | (0XF << ( g_dat0Pin-gpio_base) );
331354 pio_sm_set_consecutive_pindirs (g_pio, g_sm0, g_clkPin, 1 , true );
332355 pio_sm_set_consecutive_pindirs (g_pio, g_sm0, g_cmdPin, 1 , true );
333356 pio_sm_set_consecutive_pindirs (g_pio, g_sm0, g_dat0Pin, 4 , false );
0 commit comments