add RP2040 support

This commit is contained in:
lady ada 2022-01-01 21:00:41 -05:00
parent 9baf11f48f
commit cede24b032
4 changed files with 60 additions and 24 deletions

View file

@ -20,7 +20,7 @@ jobs:
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py metro_m4
run: python3 ci/build_platform.py feather_m4_express_tinyusb feather_rp2040
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

View file

@ -1,7 +1,18 @@
#include "Adafruit_Floppy.h"
// We need to read and write some pins at optimized speeds - use raw registers
// or native SDK API!
#ifdef BUSIO_USE_FAST_PINIO
#define read_index() (*indexPort & indexMask)
#define read_data() (*dataPort & dataMask)
#define set_debug_led() (*ledPort |= ledMask)
#define clr_debug_led() (*ledPort &= ~ledMask)
#elif defined(ARDUINO_ARCH_RP2040)
#define read_index() gpio_get(_indexpin)
#define read_data() gpio_get(_rddatapin)
#define set_debug_led() gpio_put(led_pin, 1)
#define clr_debug_led() gpio_put(led_pin, 0)
#endif
/**************************************************************************/
/*!
@ -84,8 +95,10 @@ void Adafruit_Floppy::soft_reset(void) {
pinMode(_readypin, INPUT_PULLUP);
pinMode(_rddatapin, INPUT_PULLUP);
#ifdef BUSIO_USE_FAST_PINIO
indexPort = (BusIO_PortReg *)portInputRegister(digitalPinToPort(_indexpin));
indexMask = digitalPinToBitMask(_indexpin);
#endif
select_delay_us = 10;
step_delay_us = 10000;
@ -93,6 +106,11 @@ void Adafruit_Floppy::soft_reset(void) {
motor_delay_ms = 1000;
watchdog_delay_ms = 1000;
bus_type = BUSTYPE_IBMPC;
if (led_pin >= 0) {
pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, LOW);
}
}
/**************************************************************************/
@ -258,12 +276,14 @@ uint32_t Adafruit_Floppy::capture_track(uint8_t *pulses, uint32_t max_pulses) {
uint8_t *pulses_ptr = pulses;
uint8_t *pulses_end = pulses + max_pulses;
#ifdef BUSIO_USE_FAST_PINIO
BusIO_PortReg *dataPort, *ledPort;
BusIO_PortMask dataMask, ledMask;
dataPort = (BusIO_PortReg *)portInputRegister(digitalPinToPort(_rddatapin));
dataMask = digitalPinToBitMask(_rddatapin);
ledPort = (BusIO_PortReg *)portOutputRegister(digitalPinToPort(led_pin));
ledMask = digitalPinToBitMask(led_pin);
#endif
memset(pulses, 0, max_pulses); // zero zem out
@ -306,12 +326,12 @@ uint32_t Adafruit_Floppy::capture_track(uint8_t *pulses, uint32_t max_pulses) {
while (!read_data()) {
pulse_count++;
}
*ledPort |= ledMask;
set_debug_led();
// while pulse is high, keep counting up
while (read_data())
pulse_count++;
*ledPort &= ~ledMask;
clr_debug_led();
pulses_ptr[0] = min(255, pulse_count);
pulses_ptr++;

View file

@ -63,8 +63,10 @@ private:
int8_t _track = -1;
#ifdef BUSIO_USE_FAST_PINIO
BusIO_PortReg *indexPort;
BusIO_PortMask indexMask;
#endif
};
#endif

View file

@ -2,31 +2,44 @@
// Only tested on SAMD51 chipsets. TURN ON 180MHZ OVERCLOCK AND FASTEST OPTIMIZE!
#define DENSITY_PIN 5 // IDC 2
// IDC 4 no connect
// IDC 6 no connect
#define INDEX_PIN 6 // IDC 8
// IDC 10 no connect
#define SELECT_PIN A5 // IDC 12
// IDC 14 no connect
#define MOTOR_PIN 9 // IDC 16
#define DIR_PIN 10 // IDC 18
#define STEP_PIN 11 // IDC 20
#define READY_PIN A0 // IDC 22
#define SIDE_PIN A1 // IDC
#define READ_PIN 12
#define PROT_PIN A3
#define TRK0_PIN A4
#define WRDATA_PIN -1
#define WRGATE_PIN -1
#if defined(ADAFRUIT_FEATHER_M4_EXPRESS)
#define DENSITY_PIN 5 // IDC 2
#define INDEX_PIN 6 // IDC 8
#define SELECT_PIN A5 // IDC 12
#define MOTOR_PIN 9 // IDC 16
#define DIR_PIN 10 // IDC 18
#define STEP_PIN 11 // IDC 20
#define WRDATA_PIN -1 // IDC 22 (not used during read)
#define WRGATE_PIN -1 // IDC 24 (not used during read)
#define TRK0_PIN A4 // IDC 26
#define PROT_PIN A3 // IDC 28
#define READ_PIN 12 // IDC 30
#define SIDE_PIN A1 // IDC 32
#define READY_PIN A0 // IDC 34
#elif defined (ARDUINO_ADAFRUIT_FEATHER_RP2040)
#define DENSITY_PIN 7 // IDC 2
#define INDEX_PIN 8 // IDC 8
#define SELECT_PIN 25 // IDC 12
#define MOTOR_PIN 9 // IDC 16
#define DIR_PIN 10 // IDC 18
#define STEP_PIN 11 // IDC 20
#define WRDATA_PIN -1 // IDC 22 (not used during read)
#define WRGATE_PIN -1 // IDC 24 (not used during read)
#define TRK0_PIN 24 // IDC 26
#define PROT_PIN A3 // IDC 28
#define READ_PIN 12 // IDC 30
#define SIDE_PIN A1 // IDC 32
#define READY_PIN A0 // IDC 34
#else
#error "Please set up pin definitions!"
#endif
Adafruit_Floppy floppy(DENSITY_PIN, INDEX_PIN, SELECT_PIN,
MOTOR_PIN, DIR_PIN, STEP_PIN,
WRDATA_PIN, WRGATE_PIN, TRK0_PIN,
PROT_PIN, READ_PIN, SIDE_PIN, READY_PIN);
// WARNING! there are 100K max flux pulses per track!
// WARNING! there are 150K max flux pulses per track!
uint8_t flux_transitions[MAX_FLUX_PULSE_PER_TRACK];
uint32_t time_stamp = 0;
@ -47,7 +60,7 @@ void setup() {
}
Serial.print("Seeking track...");
if (! floppy.goto_track(1)) {
if (! floppy.goto_track(0)) {
Serial.println("Failed to seek to track");
while (1) yield();
}
@ -62,7 +75,7 @@ void loop() {
Serial.println(" flux transitions");
//floppy.print_pulses(flux_transitions, captured_flux);
floppy.print_pulse_bins(flux_transitions, captured_flux);
floppy.print_pulse_bins(flux_transitions, captured_flux, 255);
if ((millis() - time_stamp) > 1000) {
Serial.print("Ready? ");
@ -73,4 +86,5 @@ void loop() {
Serial.println(digitalRead(TRK0_PIN) ? "No" : "Yes");
time_stamp = millis();
}
yield();
}