@@ -158,11 +158,11 @@ void systemBus::op_readex()
158158 {
159159 size_t bytesrd;
160160 Debug_printf (" op_readex: open successful %s\r\n " , szNamedMount);
161-
161+
162162 memset (blk_buffer,0 ,MEDIA_BLOCK_SIZE);
163163 bytesrd = fread (blk_buffer,1 ,MEDIA_BLOCK_SIZE,pNamedObjFp);
164164 if (bytesrd!=MEDIA_BLOCK_SIZE || feof (pNamedObjFp))
165- {
165+ {
166166 Debug_printf (" op_readex: closed named object %s\r\n " ,szNamedMount);
167167 fclose (pNamedObjFp);
168168 pNamedObjFp = NULL ;
@@ -173,12 +173,12 @@ void systemBus::op_readex()
173173 else
174174 {
175175 Debug_printf (" op_readex: open failed %s\r\n " , szNamedMount);
176- fnDwCom. write (0xF4 );
176+ _port-> write (0xF4 );
177177 return ;
178178 }
179179 }
180180 else
181- {
181+ {
182182 if (true ==bDragon && drive_num>=5 ) drive_num = drive_num-5 ;
183183 Debug_printf (" OP_READ: DRIVE %3u - SECTOR %8lu\n " , drive_num, lsn);
184184
@@ -211,16 +211,16 @@ void systemBus::op_readex()
211211 blk_size = MEDIA_BLOCK_SIZE;
212212 use_media_buffer = false ;
213213 }
214-
214+
215215 if (bDragon)
216216 {
217217 Debug_printf (" dragon read\n " );
218218 if (d->read (lsn, sector_data))
219219 {
220220 Debug_printf (" Read error\n " );
221- fnDwCom. write (0xF4 );
222- fnDwCom. flush ();
223- fnDwCom. flush_input ();
221+ _port-> write (0xF4 );
222+ _port-> flushOutput ();
223+ _port-> discardInput ();
224224 return ;
225225 }
226226 }
@@ -662,44 +662,25 @@ void systemBus::service()
662662 _port->setDSR (!hasUpdate);
663663 }
664664
665- if (fnDwCom. available ())
665+ if (_port-> available ())
666666 _drivewire_process_cmd ();
667667
668668 // dload.dload_process();
669669}
670670
671- // Setup DRIVEWIRE bus
672- void systemBus::setup ()
673- {
674671#ifdef ESP_PLATFORM
675- // Create a queue to handle parallel event from ISR
676- drivewire_evt_queue = xQueueCreate (10 , sizeof (uint32_t ));
677- bDragon = false ;
678-
679- // Start task
680- // xTaskCreate(drivewire_intr_task, "drivewire_intr_task", 2048, NULL, 10, NULL);
681- // xTaskCreatePinnedToCore(drivewire_intr_task, "drivewire_intr_task", 4096, this, 10, NULL, 0);
682-
683- #ifdef CONFIG_IDF_TARGET_ESP32S3
684- // Configure UART to RP2040
685- #ifdef FORCE_UART_BAUD
686- Debug_printv (" FORCE_UART_BAUD set to %u" , FORCE_UART_BAUD);
687- _drivewireBaud = FORCE_UART_BAUD;
688- #else /* !FORCE_UART_BAUD */
689- _drivewireBaud = 115200 ;
690- #endif /* FORCE_UART_BAUD */
691-
692- #else /* !CONFIG_IDF_TARGET_ESP32S3 */
693- // Setup interrupt for cassette motor pin
694- gpio_config_t io_conf = {
695- .pin_bit_mask = (1ULL << PIN_CASS_MOTOR), // bit mask of the pins that you want to set
672+ void systemBus::configureGPIO ()
673+ {
674+ // Setup interrupt for cassette motor pin
675+ gpio_config_t io_conf = {
676+ .pin_bit_mask = (1ULL << PIN_CASS_MOTOR), // bit mask of the pins that you want to set
696677 .mode = GPIO_MODE_INPUT, // set as input mode
697678 .pull_up_en = GPIO_PULLUP_DISABLE, // disable pull-up mode
698679 .pull_down_en = GPIO_PULLDOWN_ENABLE, // enable pull-down mode
699680 .intr_type = GPIO_INTR_POSEDGE // interrupt on positive edge
700- };
681+ };
701682
702- _cassetteDev = new drivewireCassette ();
683+ _cassetteDev = new drivewireCassette ();
703684
704685 // configure GPIO with the given settings
705686 gpio_config (&io_conf);
@@ -718,46 +699,78 @@ void systemBus::setup()
718699 fnSystem.set_pin_mode (PIN_EPROM_A14, gpio_mode_t ::GPIO_MODE_INPUT, SystemManager::pull_updown_t ::PULL_NONE);
719700 fnSystem.set_pin_mode (PIN_EPROM_A15, gpio_mode_t ::GPIO_MODE_INPUT, SystemManager::pull_updown_t ::PULL_NONE);
720701
721- #ifdef FORCE_UART_BAUD
722- Debug_printv (" FORCE_UART_BAUD set to %u" ,FORCE_UART_BAUD);
723- _drivewireBaud = FORCE_UART_BAUD;
724- #else /* !FORCE_UART_BAUD */
725- if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_LOW && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_LOW)
702+ return ;
703+ }
704+
705+ int systemBus::readBaudSwitch ()
706+ {
707+ if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_LOW
708+ && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_LOW)
726709 {
727- _drivewireBaud = 38400 ; // Coco1 ROM Image
728710 Debug_printv (" A14 Low, A15 Low, 38400 baud" );
711+ return 38400 ; // Coco1 ROM Image
729712 }
730- else if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_HIGH && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_LOW)
713+
714+ if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_HIGH
715+ && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_LOW)
731716 {
732- _drivewireBaud = 57600 ; // Coco2 ROM Image
733717 Debug_printv (" A14 High, A15 Low, 57600 baud" );
718+ return 57600 ; // Coco2 ROM Image
734719 }
735- else if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_LOW && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_HIGH)
720+
721+ if (fnSystem.digital_read (PIN_EPROM_A14) == DIGI_LOW
722+ && fnSystem.digital_read (PIN_EPROM_A15) == DIGI_HIGH)
736723 {
737- _drivewireBaud = 115200 ; // Coco3 ROM Image
738724 Debug_printv (" A14 Low, A15 High, 115200 baud" );
725+ return 115200 ; // Coco3 ROM Image
739726 }
740- else
741- {
742- _drivewireBaud = 57600 ; // Dragon
743- bDragon = true ;
744- Debug_printv (" A14 and A15 High, (DRAGON) 57600 baud" );
745- }
746727
747- #endif /* FORCE_UART_BAUD */
728+ Debug_printv (" A14 and A15 High, defaulting to 57600 baud" );
729+ return 57600 ; // Default or no switch
730+ }
731+ #endif /* ESP_PLATFORM */
732+
733+ // Setup DRIVEWIRE bus
734+ void systemBus::setup ()
735+ {
736+ #ifdef ESP_PLATFORM
737+ // Create a queue to handle parallel event from ISR
738+ drivewire_evt_queue = xQueueCreate (10 , sizeof (uint32_t ));
739+ bDragon = false ;
740+
741+ #ifdef CONFIG_IDF_TARGET_ESP32S3
742+ // Configure UART to RP2040
743+ #ifdef FORCE_UART_BAUD
744+ Debug_printv (" FORCE_UART_BAUD set to %u" , FORCE_UART_BAUD);
745+ _drivewireBaud = FORCE_UART_BAUD;
746+ #else /* !FORCE_UART_BAUD */
747+ _drivewireBaud = 115200 ;
748+ #endif /* FORCE_UART_BAUD */
749+
750+ #else /* ! CONFIG_IDF_TARGET_ESP32S3 */
751+ configureGPIO ();
752+ #ifdef FORCE_UART_BAUD
753+ Debug_printv (" FORCE_UART_BAUD set to %u" ,FORCE_UART_BAUD);
754+ _drivewireBaud = FORCE_UART_BAUD;
755+ #else /* !FORCE_UART_BAUD */
756+ _drivewireBaud = readBaudSwitch ();
757+ #endif /* FORCE_UART_BAUD */
748758#endif /* CONFIG_IDF_TARGET_ESP32S3 */
749759#else /* !ESP_PLATFORM */
750760 // FujiNet-PC specific
751761 _drivewireBaud = Config.get_serial_baud ();
752762#endif /* !ESP_PLATFORM */
763+
753764 if (Config.get_boip_enabled ())
754765 {
755766 _becker.begin (Config.get_boip_host (), _drivewireBaud);
756767 _port = &_becker;
757768 }
758769 else
759770 {
760- _serial.begin (ChannelConfig ().baud (_drivewireBaud).deviceID (DW_UART_DEVICE)
771+ _serial.begin (ChannelConfig ()
772+ .baud (_drivewireBaud)
773+ .deviceID (DW_UART_DEVICE)
761774 .readTimeout (500 )
762775#ifdef ESP_PLATFORM
763776 .inverted (DW_UART_DEVICE == UART_NUM_2)
@@ -768,10 +781,8 @@ void systemBus::setup()
768781
769782 _port->discardInput ();
770783 Debug_printv (" DRIVEWIRE MODE" );
771- szNamedMount[0 ]=(uint8_t )0 ;
772- pNamedObjFp = NULL ;
773784
774- // jeff hack to see if the S3 is getting serial data
785+ // jeff hack to see if the S3 is getting serial data
775786 // Debug_println("now receiving data...");
776787 // uint8_t b[] = {' '};
777788 // while(1)
@@ -782,7 +793,7 @@ void systemBus::setup()
782793 // Debug_printf("%c\n",b[0]);
783794 // }
784795 // }
785- // end jeff hack
796+ // end jeff hack
786797
787798}
788799
0 commit comments