@@ -50,7 +50,7 @@ Head Selection:
5050*/
5151
5252#define MAJOR_VERSION 1
53- #define MINOR_VERSION 0
53+ #define MINOR_VERSION 1
5454
5555
5656#define PIN_LED_PAULAIO 17 // Data from/to paula
@@ -416,8 +416,7 @@ void __not_in_flash_func(pinMonitor)(uint gpio, uint32_t events) {
416416 case PIN_SELECT :
417417 isSelected = (events & GPIO_IRQ_EDGE_FALL ) != 0 ;
418418 // Motor state is latched on select
419- if (isSelected) isMotorActive = gpio_get (PIN_MOTOR ) == 0 ;
420- gpio_set_dir (PIN_READDATA , isSelected ? GPIO_OUT : GPIO_IN );
419+ if (isSelected) isMotorActive = gpio_get (PIN_MOTOR ) == 0 ;
421420 gpio_set_dir (PIN_TRACK0 , isSelected ? GPIO_OUT : GPIO_IN );
422421 gpio_set_dir (PIN_WRITEPROTECT , isSelected ? GPIO_OUT : GPIO_IN );
423422 gpio_set_dir (PIN_DISKCHANGE , isSelected ? GPIO_OUT : GPIO_IN );
@@ -491,16 +490,13 @@ void setupDriveSelectPIO(uint selectPin, uint readyPin) {
491490
492491 sm_config_set_in_pins (&c, selectPin);
493492 sm_config_set_set_pins (&c, readyPin, 1 );
494-
495- // Full speed - we want minimum latency
496493 sm_config_set_clkdiv (&c, 1 .0f );
497494
498495 pio_gpio_init (pioDriveSelect.pio , readyPin);
499- pio_sm_set_consecutive_pindirs (pioDriveSelect.pio , pioDriveSelect.sm , readyPin, 1 , true ); // ready = output
500- // selectPin stays as input, no pindirs change needed
496+ pio_sm_set_pins_with_mask (pioDriveSelect.pio , pioDriveSelect.sm , 0 , 1u << readyPin);
497+ pio_sm_set_consecutive_pindirs (pioDriveSelect. pio , pioDriveSelect. sm , readyPin, 1 , false );
501498
502499 pio_sm_init (pioDriveSelect.pio , pioDriveSelect.sm , offset, &c);
503- pio_sm_exec (pioDriveSelect.pio , pioDriveSelect.sm , pio_encode_set (pio_pins, 1 ));
504500 pio_sm_set_enabled (pioDriveSelect.pio , pioDriveSelect.sm , true );
505501}
506502
@@ -775,7 +771,7 @@ void preparePacketsToTransmit() {
775771 return ;
776772 }
777773 lastPicoCounter++;
778-
774+
779775 // Pointer to whre data starts
780776 uint8_t * headerStart = (uint8_t *)&PacketBackup[ PAULA_INDEX_PADDING + 4 ];
781777 uint8_t * dataStart = headerStart + (sizeof (DataHeader)*2 );
@@ -1013,18 +1009,22 @@ uint32_t readFromPaula() {
10131009void setupWritingPIO (uint pin) {
10141010#ifdef PICO_RP2350
10151011 uint offset = pio_add_program (pioFloppyTX.pio , &floppy_tx_pico2_program);
1012+ pio_sm_config c = floppy_tx_pico2_program_get_default_config (offset);
10161013#else
10171014 uint offset = pio_add_program (pioFloppyTX.pio , &floppy_tx_program);
1018- #endif
10191015 pio_sm_config c = floppy_tx_program_get_default_config (offset);
1016+ #endif
10201017 sm_config_set_out_shift (&c, false , true , 16 ); // shift left, autopull, 16 bits
10211018 sm_config_set_set_pins (&c, pin, 1 );
10221019 sm_config_set_clkdiv (&c, 8 ); // 125MHz/8 = 15.625MHz
10231020
1024- pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , pin, 1 , true );
10251021 pio_gpio_init (pioFloppyTX.pio , pin);
10261022 pio_sm_init (pioFloppyTX.pio , pioFloppyTX.sm , offset, &c);
1027- pio_sm_set_enabled (pioFloppyTX.pio , pioFloppyTX.sm , true );
1023+
1024+ // After init - output value permanently 0, start high-Z
1025+ pio_sm_set_pins_with_mask (pioFloppyTX.pio , pioFloppyTX.sm , 0 , 1u << pin);
1026+ pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , pin, 1 , false );
1027+ // Don't enable - only enable when transmitting
10281028}
10291029
10301030// Core 1 MAIN
@@ -1064,12 +1064,17 @@ void core1Main() {
10641064 while ((currentTrack == track) && (currentSide == isLowerSide ()) && (isSelected) && (isMotorActive) && gpio_get (PIN_RESET )) {
10651065 // Start transmission
10661066 gpio_put (PIN_INDEX , 0 ); // index is used to help sync the data stream
1067+ pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , PIN_READDATA , 1 , true );
1068+ pio_sm_set_enabled (pioFloppyTX.pio , pioFloppyTX.sm , true );
10671069 dma_channel_configure (dma_chan, &cfg, &pioFloppyTX.pio ->txf [pioFloppyTX.sm ],IoBuffer,bufferUsed,true );
10681070 sleep_us (3000 ); // wait 3ms, this allows the index to work properly.
10691071 gpio_put (PIN_INDEX , 1 );
10701072 // Wait for one of these states to change
1071- while ((currentTrack == track) && (currentSide == isLowerSide () && (isSelected) && (isMotorActive) && gpio_get (PIN_RESET ) && dma_channel_is_busy (dma_chan) ));
1073+ while ((currentTrack == track) && (currentSide == isLowerSide ()) && (isSelected) && (isMotorActive) && gpio_get (PIN_RESET ) && dma_channel_is_busy (dma_chan));
10721074 dma_channel_abort (dma_chan);
1075+ pio_sm_clear_fifos (pioFloppyTX.pio , pioFloppyTX.sm );
1076+ pio_sm_set_enabled (pioFloppyTX.pio , pioFloppyTX.sm , false );
1077+ pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , PIN_READDATA , 1 , false );
10731078 }
10741079 gpio_put (PIN_LED_PAULAIO , 0 );
10751080 }
@@ -1109,13 +1114,18 @@ void core1Main() {
11091114 while ((!isLowerSide ()) && (isSelected) && gpio_get (PIN_RESET ) && isMotorActive && (currentTrack == track)) {
11101115 // Start transmission
11111116 gpio_put (PIN_INDEX , 0 ); // index is used to help sync the data stream
1117+ pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , PIN_READDATA , 1 , true );
1118+ pio_sm_set_enabled (pioFloppyTX.pio , pioFloppyTX.sm , true );
11121119 dma_channel_configure (dma_chan, &cfg, &pioFloppyTX.pio ->txf [pioFloppyTX.sm ], (paulaMode == PaulaMode::pmEthernet) ? PacketBackup : IoBuffer,bufferUsed,true );
11131120 sleep_us (1000 ); // wait 1ms, this allows the index to work properly.
11141121 gpio_put (PIN_INDEX , 1 );
11151122
11161123 // Wait for one of these states to change
1117- while ((!isLowerSide ()) && (isSelected) && dma_channel_is_busy (dma_chan ) && gpio_get (PIN_RESET ) && isMotorActive && (currentTrack == track ));
1124+ while ((currentTrack == track) && ( !isLowerSide ()) && (isSelected) && (isMotorActive ) && gpio_get (PIN_RESET ) && dma_channel_is_busy (dma_chan ));
11181125 dma_channel_abort (dma_chan);
1126+ pio_sm_clear_fifos (pioFloppyTX.pio , pioFloppyTX.sm );
1127+ pio_sm_set_enabled (pioFloppyTX.pio , pioFloppyTX.sm , false );
1128+ pio_sm_set_consecutive_pindirs (pioFloppyTX.pio , pioFloppyTX.sm , PIN_READDATA , 1 , false );
11191129 }
11201130 gpio_put (PIN_LED_PAULAIO , 0 );
11211131 }
@@ -1399,9 +1409,11 @@ int main() {
13991409 // Prep compress and encode each packet for transmission
14001410 if (settings.flags & FLAGS_PICO_COMPRESSION ) {
14011411 // Experimental LZ4 compressor
1402- // compressedRxQueue.packets[compressedRxQueue.writeIndex].length = lz4Compress(rxQueue.packets[rxQueue.readIndex].data, rxQueue.packets[rxQueue.readIndex].length, outputPosition, true, (uint16_t*)Core0RunBuffer);
1412+ // size_t realSize;
1413+ // compressedRxQueue.packets[compressedRxQueue.writeIndex].length = lz4Compress(rxQueue.packets[rxQueue.readIndex].data, rxQueue.packets[rxQueue.readIndex].length, outputPosition, true, (uint16_t*)Core0RunBuffer, &realSize);
1414+
14031415 compressedRxQueue.packets [compressedRxQueue.writeIndex ].length = rleCompress (rxQueue.packets [rxQueue.readIndex ].data , rxQueue.packets [rxQueue.readIndex ].length , outputPosition, true , Core0RunBuffer);
1404- hdr.compressedSize = SWAP16 (compressedRxQueue.packets [compressedRxQueue.writeIndex ].length );
1416+ hdr.compressedSize = SWAP16 (compressedRxQueue.packets [compressedRxQueue.writeIndex ].length /* realSize */ );
14051417 // WORD padding
14061418 if (compressedRxQueue.packets [compressedRxQueue.writeIndex ].length &1 ) {
14071419 *(outputPosition+compressedRxQueue.packets [compressedRxQueue.writeIndex ].length ) = 0 ;
0 commit comments