/ Adafruit_Floppy.h
Adafruit_Floppy.h
1 #ifndef ADAFRUIT_FLOPPY_H 2 #define ADAFRUIT_FLOPPY_H 3 4 #include "Arduino.h" 5 #include <Adafruit_SPIDevice.h> 6 7 #define MAX_TRACKS 80 8 #define STEP_OUT HIGH 9 #define STEP_IN LOW 10 #define MAX_FLUX_PULSE_PER_TRACK \ 11 (uint32_t)(500000UL / 5 * \ 12 1.5) // 500khz / 5 hz per track rotation, 1.5 rotations 13 14 #define BUSTYPE_IBMPC 1 15 #define BUSTYPE_SHUGART 2 16 17 /**************************************************************************/ 18 /*! 19 @brief A helper class for chattin with floppy drives 20 */ 21 /**************************************************************************/ 22 class Adafruit_Floppy { 23 public: 24 Adafruit_Floppy(int8_t densitypin, int8_t indexpin, int8_t selectpin, 25 int8_t motorpin, int8_t directionpin, int8_t steppin, 26 int8_t wrdatapin, int8_t wrgatepin, int8_t track0pin, 27 int8_t protectpin, int8_t rddatapin, int8_t sidepin, 28 int8_t readypin); 29 void begin(void); 30 void soft_reset(void); 31 32 void select(bool selected); 33 bool spin_motor(bool motor_on); 34 bool goto_track(uint8_t track); 35 void side(uint8_t head); 36 int8_t track(void); 37 void step(bool dir, uint8_t times); 38 39 uint32_t capture_track(uint8_t *pulses, uint32_t max_pulses) 40 __attribute__((optimize("O3"))); 41 void print_pulse_bins(uint8_t *pulses, uint32_t num_pulses, 42 uint8_t max_bins = 64); 43 void print_pulses(uint8_t *pulses, uint32_t num_pulses); 44 45 int8_t led_pin = LED_BUILTIN; ///< Debug LED output for tracing 46 47 uint16_t select_delay_us = 10; ///< delay after drive select (usecs) 48 uint16_t step_delay_us = 10000; ///< delay between head steps (usecs) 49 uint16_t settle_delay_ms = 15; ///< settle delay after seek (msecs) 50 uint16_t motor_delay_ms = 1000; ///< delay after motor on (msecs) 51 uint16_t watchdog_delay_ms = 52 1000; ///< quiescent time until drives reset (msecs) 53 uint8_t bus_type = BUSTYPE_IBMPC; ///< what kind of floppy drive we're using 54 55 Stream *debug_serial = NULL; ///< optional debug stream for serial output 56 57 private: 58 void wait_for_index_pulse_low(void); 59 60 // theres a lot of GPIO! 61 int8_t _densitypin, _indexpin, _selectpin, _motorpin, _directionpin, _steppin, 62 _wrdatapin, _wrgatepin, _track0pin, _protectpin, _rddatapin, _sidepin, 63 _readypin; 64 65 int8_t _track = -1; 66 67 #ifdef BUSIO_USE_FAST_PINIO 68 BusIO_PortReg *indexPort; 69 BusIO_PortMask indexMask; 70 #endif 71 }; 72 73 #endif