Skip to content

Commit

Permalink
Merge pull request #28 from adafruit/floppsy_rp2040
Browse files Browse the repository at this point in the history
Floppsy rp2040
  • Loading branch information
jepler authored Feb 22, 2024
2 parents ddc643a + a803feb commit 9efcde1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_ADAFRUIT_FLOPPSY_RP2040)
// Yay built in pin definitions!
#else
#error "Please set up pin definitions!"
#endif
Expand All @@ -67,6 +69,11 @@ void setup() {
Serial.begin(115200);
while (!Serial) delay(100);

#if defined(FLOPPY_DIRECTION_PIN)
pinMode(FLOPPY_DIRECTION_PIN, OUTPUT);
digitalWrite(FLOPPY_DIRECTION_PIN, HIGH);
#endif

Serial.println("its time for a nice floppy transfer!");
Serial.print("Sample freqency ");
Serial.print(floppy.getSampleFrequency() / 1e6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_ADAFRUIT_FLOPPSY_RP2040)
// Yay built in pin definitions!
#else
#error "Please set up pin definitions!"
#endif
Expand All @@ -59,7 +61,7 @@ Adafruit_Floppy floppy(DENSITY_PIN, INDEX_PIN, SELECT_PIN,
PROT_PIN, READ_PIN, SIDE_PIN, READY_PIN);

// You can select IBMPC1440K or IBMPC360K (check adafruit_floppy_disk_t options!)
Adafruit_MFM_Floppy mfm_floppy(&floppy, IBMPC360K);
Adafruit_MFM_Floppy mfm_floppy(&floppy, IBMPC1440K);


uint32_t time_stamp = 0;
Expand All @@ -69,6 +71,11 @@ void setup() {
Serial.begin(115200);
while (!Serial) delay(100);

#if defined(FLOPPY_DIRECTION_PIN)
pinMode(FLOPPY_DIRECTION_PIN, OUTPUT);
digitalWrite(FLOPPY_DIRECTION_PIN, HIGH);
#endif

delay(500); // wait for serial to open
Serial.println("its time for a nice floppy transfer!");

Expand Down Expand Up @@ -130,4 +137,4 @@ void loop() {
}

delay(1000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_ADAFRUIT_FLOPPSY_RP2040)
// Yay built in pin definitions!
#else
#error "Please set up pin definitions!"
#endif
Expand All @@ -85,19 +87,27 @@ void setup() {
yield();
}

#if defined(FLOPPY_DIRECTION_PIN)
pinMode(FLOPPY_DIRECTION_PIN, OUTPUT);
digitalWrite(FLOPPY_DIRECTION_PIN, HIGH);
#endif

Serial.println("Floppy FAT directory listing demo");

// Init floppy drive - must spin up and find index
if (! mfm_floppy.begin()) {
Serial.println("Floppy didn't initialize - check wiring and diskette!");
while (1) yield();
}

// Init file system on the flash
fatfs.begin(&mfm_floppy);

if (!root.open("/")) {
Serial.println("open root failed");
while (1) yield();
}

// Open next file in root.
// Warning, openNext starts at the current directory position
// so a rewind of the directory may be required.
Expand Down Expand Up @@ -150,4 +160,4 @@ void loop() {
char c = dataFile.read();
Serial.print(c);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
#define READ_PIN 9 // IDC 30
#define SIDE_PIN 8 // IDC 32
#define READY_PIN 7 // IDC 34
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
#define DENSITY_PIN 2 // IDC 2
#define INDEX_PIN 3 // IDC 8
Expand All @@ -49,13 +46,16 @@
#define READ_PIN 12 // IDC 30
#define SIDE_PIN 13 // IDC 32
#define READY_PIN 14 // IDC 34
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_ADAFRUIT_FLOPPSY_RP2040)
// Yay built in pin definitions!
#else
#error "Please set up pin definitions!"
#endif

#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif


Adafruit_USBD_MSC usb_msc;

Expand All @@ -75,6 +75,11 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);

#if defined(FLOPPY_DIRECTION_PIN)
pinMode(FLOPPY_DIRECTION_PIN, OUTPUT);
digitalWrite(FLOPPY_DIRECTION_PIN, HIGH);
#endif

#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
// Manual begin() is required on core without built-in support for TinyUSB such as
// - mbed rp2040
Expand Down Expand Up @@ -157,4 +162,4 @@ void msc_flush_callback (void)
{
Serial.println("flush\n");
// nothing to do
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This example will ERASE TRACK 0 on a floppy disk to test if flux writing
// is functioning
// DO NOT RUN IT ON A FLOPPY YOU WISH TO KEEP DATA!
// IT MUST BE REFORMATTED AFTER WRITING!

#include <Adafruit_Floppy.h>

#if defined(ADAFRUIT_FEATHER_M4_EXPRESS)
Expand Down Expand Up @@ -28,9 +33,6 @@
#define READ_PIN 9 // IDC 30
#define SIDE_PIN 8 // IDC 32
#define READY_PIN 7 // IDC 34
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
#define DENSITY_PIN 2 // IDC 2
#define INDEX_PIN 3 // IDC 8
Expand All @@ -45,13 +47,17 @@
#define READ_PIN 12 // IDC 30
#define SIDE_PIN 13 // IDC 32
#define READY_PIN 14 // IDC 34
#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif
#elif defined(ARDUINO_ADAFRUIT_FLOPPSY_RP2040)
// Yay built in pin definitions!
#else
#error "Please set up pin definitions!"
#endif

#ifndef USE_TINYUSB
#error "Please set Adafruit TinyUSB under Tools > USB Stack"
#endif


Adafruit_Floppy floppy(DENSITY_PIN, INDEX_PIN, SELECT_PIN,
MOTOR_PIN, DIR_PIN, STEP_PIN,
WRDATA_PIN, WRGATE_PIN, TRK0_PIN,
Expand All @@ -67,6 +73,11 @@ void setup() {
Serial.begin(115200);
while (!Serial) delay(100);

#if defined(FLOPPY_DIRECTION_PIN)
pinMode(FLOPPY_DIRECTION_PIN, OUTPUT);
digitalWrite(FLOPPY_DIRECTION_PIN, HIGH);
#endif

Serial.println("its time for a nice floppy transfer!");
floppy.debug_serial = &Serial;

Expand All @@ -87,9 +98,20 @@ void setup() {
while (1) yield();
}
Serial.println("done!");

}

void loop() {
// Flush input of serial port
while (Serial.available()) Serial.read();

// Warn them again!
Serial.println("Are you SURE you want to run the write test?");
Serial.println("THIS WILL PERMANENTLY ERASE ANY DATA ON THE FLOPPY DISK!!!");
Serial.println("Type Y to continue...");
while (! Serial.available()) yield();
if (Serial.read() != 'Y') return;

int32_t index_pulse_offset;
uint32_t captured_flux = floppy.capture_track(flux_transitions, sizeof(flux_transitions), &index_pulse_offset, true);

Expand Down Expand Up @@ -131,4 +153,4 @@ void loop() {
floppy.write_track(flux_transitions, sizeof(flux_transitions), true);

yield();
}
}

0 comments on commit 9efcde1

Please sign in to comment.