@@ -405,39 +405,43 @@ static uint32_t mask_and_rotate(const mcu_pin_obj_t *first_pin, uint32_t bit_cou
405405}
406406
407407typedef struct {
408- uint32_t pins_we_use , in_pin_count , out_pin_count ;
409- bool has_jmp_pin , auto_push , auto_pull , has_in_pin , has_out_pin , has_set_pin ;
410- bool tx_fifo , rx_fifo , in_loaded , out_loaded , in_used , out_used ;
408+ struct {
409+ uint32_t pins_we_use , in_pin_count , out_pin_count ;
410+ bool has_jmp_pin , auto_push , auto_pull , has_in_pin , has_out_pin , has_set_pin ;
411+ } inputs ;
412+ struct {
413+ bool tx_fifo , rx_fifo , in_loaded , out_loaded , in_used , out_used ;
414+ } outputs ;
411415} introspect_t ;
412416
413417static void consider_instruction (introspect_t * state , uint16_t full_instruction , qstr what_program , size_t i ) {
414418 uint16_t instruction = full_instruction & 0xe000 ;
415419 if (instruction == 0x8000 ) {
416420 if ((full_instruction & 0xe080 ) == pio_instr_bits_push ) {
417- state -> rx_fifo = true;
418- state -> in_loaded = true;
421+ state -> outputs . rx_fifo = true;
422+ state -> outputs . in_loaded = true;
419423 } else { // pull otherwise.
420- state -> tx_fifo = true;
421- state -> out_loaded = true;
424+ state -> outputs . tx_fifo = true;
425+ state -> outputs . out_loaded = true;
422426 }
423427 }
424428 if (instruction == pio_instr_bits_jmp ) {
425429 uint16_t condition = (full_instruction & 0x00e0 ) >> 5 ;
426- if ((condition == 0x6 ) && !state -> has_jmp_pin ) {
430+ if ((condition == 0x6 ) && !state -> inputs . has_jmp_pin ) {
427431 mp_raise_ValueError_varg (translate ("Missing jmp_pin. %q[%u] jumps on pin" ), what_program , i );
428432 }
429433 }
430434 if (instruction == pio_instr_bits_wait ) {
431435 uint16_t wait_source = (full_instruction & 0x0060 ) >> 5 ;
432436 uint16_t wait_index = full_instruction & 0x001f ;
433- if (wait_source == 0 && (state -> pins_we_use & (1 << wait_index )) == 0 ) { // GPIO
437+ if (wait_source == 0 && (state -> inputs . pins_we_use & (1 << wait_index )) == 0 ) { // GPIO
434438 mp_raise_ValueError_varg (translate ("%q[%u] uses extra pin" ), what_program , i );
435439 }
436440 if (wait_source == 1 ) { // Input pin
437- if (!state -> has_in_pin ) {
441+ if (!state -> inputs . has_in_pin ) {
438442 mp_raise_ValueError_varg (translate ("Missing first_in_pin. %q[%u] waits based on pin" ), what_program , i );
439443 }
440- if (wait_index >= state -> in_pin_count ) {
444+ if (wait_index >= state -> inputs . in_pin_count ) {
441445 mp_raise_ValueError_varg (translate ("%q[%u] waits on input outside of count" ), what_program , i );
442446 }
443447 }
@@ -446,58 +450,58 @@ static void consider_instruction(introspect_t *state, uint16_t full_instruction,
446450 uint16_t source = (full_instruction & 0x00e0 ) >> 5 ;
447451 uint16_t bit_count = full_instruction & 0x001f ;
448452 if (source == 0 ) {
449- if (!state -> has_in_pin ) {
453+ if (!state -> inputs . has_in_pin ) {
450454 mp_raise_ValueError_varg (translate ("Missing first_in_pin. %q[%u] shifts in from pin(s)" ), what_program , i );
451455 }
452- if (bit_count > state -> in_pin_count ) {
456+ if (bit_count > state -> inputs . in_pin_count ) {
453457 mp_raise_ValueError_varg (translate ("%q[%u] shifts in more bits than pin count" ), what_program , i );
454458 }
455459 }
456- if (state -> auto_push ) {
457- state -> in_loaded = true;
458- state -> rx_fifo = true;
460+ if (state -> inputs . auto_push ) {
461+ state -> outputs . in_loaded = true;
462+ state -> outputs . rx_fifo = true;
459463 }
460- state -> in_used = true;
464+ state -> outputs . in_used = true;
461465 }
462466 if (instruction == pio_instr_bits_out ) {
463467 uint16_t bit_count = full_instruction & 0x001f ;
464468 uint16_t destination = (full_instruction & 0x00e0 ) >> 5 ;
465469 // Check for pins or pindirs destination.
466470 if (destination == 0x0 || destination == 0x4 ) {
467- if (!state -> has_out_pin ) {
471+ if (!state -> inputs . has_out_pin ) {
468472 mp_raise_ValueError_varg (translate ("Missing first_out_pin. %q[%u] shifts out to pin(s)" ), what_program , i );
469473 }
470- if (bit_count > state -> out_pin_count ) {
474+ if (bit_count > state -> inputs . out_pin_count ) {
471475 mp_raise_ValueError_varg (translate ("%q[%u] shifts out more bits than pin count" ), what_program , i );
472476 }
473477 }
474- if (state -> auto_pull ) {
475- state -> out_loaded = true;
476- state -> tx_fifo = true;
478+ if (state -> inputs . auto_pull ) {
479+ state -> outputs . out_loaded = true;
480+ state -> outputs . tx_fifo = true;
477481 }
478- state -> out_used = true;
482+ state -> outputs . out_used = true;
479483 }
480484 if (instruction == pio_instr_bits_set ) {
481485 uint16_t destination = (full_instruction & 0x00e0 ) >> 5 ;
482486 // Check for pins or pindirs destination.
483- if ((destination == 0x00 || destination == 0x4 ) && !state -> has_set_pin ) {
487+ if ((destination == 0x00 || destination == 0x4 ) && !state -> inputs . has_set_pin ) {
484488 mp_raise_ValueError_varg (translate ("Missing first_set_pin. %q[%u] sets pin(s)" ), what_program , i );
485489 }
486490 }
487491 if (instruction == pio_instr_bits_mov ) {
488492 uint16_t source = full_instruction & 0x0007 ;
489493 uint16_t destination = (full_instruction & 0x00e0 ) >> 5 ;
490494 // Check for pins or pindirs destination.
491- if (destination == 0x0 && !state -> has_out_pin ) {
495+ if (destination == 0x0 && !state -> inputs . has_out_pin ) {
492496 mp_raise_ValueError_varg (translate ("Missing first_out_pin. %q[%u] writes pin(s)" ), what_program , i );
493497 }
494- if (source == 0x0 && !state -> has_in_pin ) {
498+ if (source == 0x0 && !state -> inputs . has_in_pin ) {
495499 mp_raise_ValueError_varg (translate ("Missing first_in_pin. %q[%u] reads pin(s)" ), what_program , i );
496500 }
497501 if (destination == 0x6 ) {
498- state -> in_loaded = true;
502+ state -> outputs . in_loaded = true;
499503 } else if (destination == 0x7 ) {
500- state -> out_loaded = true;
504+ state -> outputs . out_loaded = true;
501505 }
502506 }
503507}
@@ -539,24 +543,26 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
539543
540544 // Look through the program to see what we reference and make sure it was provided.
541545 introspect_t state = {
542- .pins_we_use = pins_we_use ,
543- .has_jmp_pin = jmp_pin != NULL ,
544- .has_in_pin = first_in_pin != NULL ,
545- .has_out_pin = first_out_pin != NULL ,
546- .has_set_pin = first_set_pin != NULL ,
547- .in_pin_count = in_pin_count ,
548- .out_pin_count = out_pin_count ,
549- .auto_pull = auto_pull ,
550- .auto_push = auto_push ,
546+ .inputs = {
547+ .pins_we_use = pins_we_use ,
548+ .has_jmp_pin = jmp_pin != NULL ,
549+ .has_in_pin = first_in_pin != NULL ,
550+ .has_out_pin = first_out_pin != NULL ,
551+ .has_set_pin = first_set_pin != NULL ,
552+ .in_pin_count = in_pin_count ,
553+ .out_pin_count = out_pin_count ,
554+ .auto_pull = auto_pull ,
555+ .auto_push = auto_push ,
556+ }
551557 };
552558 consider_program (& state , program , program_len , MP_QSTR_program );
553559 consider_program (& state , init , init_len , MP_QSTR_init );
554560 consider_program (& state , may_exec , may_exec_len , MP_QSTR_may_exec );
555561
556- if (!state .in_loaded && state .in_used ) {
562+ if (!state .outputs . in_loaded && state . outputs .in_used ) {
557563 mp_raise_ValueError_varg (translate ("Program does IN without loading ISR" ));
558564 }
559- if (!state .out_loaded && state .out_used ) {
565+ if (!state .outputs . out_loaded && state . outputs .out_used ) {
560566 mp_raise_ValueError_varg (translate ("Program does OUT without loading OSR" ));
561567 }
562568
@@ -609,7 +615,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
609615 first_sideset_pin , sideset_pin_count ,
610616 initial_pin_state , initial_pin_direction ,
611617 jmp_pin ,
612- pins_we_use , state .tx_fifo , state .rx_fifo ,
618+ pins_we_use , state .outputs . tx_fifo , state . outputs .rx_fifo ,
613619 auto_pull , pull_threshold , out_shift_right ,
614620 wait_for_txstall ,
615621 auto_push , push_threshold , in_shift_right ,
0 commit comments