Adafruit Library
Public Member Functions | List of all members
Adafruit_Floppy Class Reference

A helper class for chattin with PC & Shugart floppy drives. More...

#include <Adafruit_Floppy.h>

Inheritance diagram for Adafruit_Floppy:
Adafruit_FloppyBase

Public Member Functions

 Adafruit_Floppy (int8_t densitypin, int8_t indexpin, int8_t selectpin, int8_t motorpin, int8_t directionpin, int8_t steppin, int8_t wrdatapin, int8_t wrgatepin, int8_t track0pin, int8_t protectpin, int8_t rddatapin, int8_t sidepin, int8_t readypin)
 Create a hardware interface to a floppy drive. More...
 
void end () override
 Disables floppy communication, allowing pins to be used for general input and output.
 
void soft_reset (void) override
 Set back the object and pins to initial state.
 
void select (bool selected) override
 Whether to select this drive. More...
 
bool spin_motor (bool motor_on) override
 Turn on or off the floppy motor, if on we wait till we get an index pulse! More...
 
bool goto_track (int track) override
 Seek to the desired track, requires the motor to be spun up! More...
 
bool side (int head) override
 Which head/side to read from. More...
 
int track (void) override
 The current track location, based on internal caching. More...
 
int get_side (void) override
 Current head in use, based on internal caching. More...
 
void step (bool dir, uint8_t times)
 Step the track motor. More...
 
bool set_density (bool high_density) override
 Set the density for flux reading and writing. More...
 
bool get_write_protect () override
 Check whether the floppy in the drive is write protected. More...
 
bool get_track0_sense () override
 Check whether the track0 sensor is active. More...
 
bool get_ready_sense () override
 Check whether the ready output is active. More...
 
- Public Member Functions inherited from Adafruit_FloppyBase
bool begin (void)
 Initializes the GPIO pins but do not start the motor or anything. More...
 
size_t decode_track_mfm (uint8_t *sectors, size_t n_sectors, uint8_t *sector_validity, const uint8_t *pulses, size_t n_pulses, float nominal_bit_time_us, bool clear_validity=false, uint8_t *logical_track=nullptr)
 Decode one track of previously captured MFM data. More...
 
size_t encode_track_mfm (const uint8_t *sectors, size_t n_sectors, uint8_t *pulses, size_t max_pulses, float nominal_bit_time_us, uint8_t logical_track)
 Encode one track of previously captured MFM data. More...
 
size_t capture_track (volatile uint8_t *pulses, size_t max_pulses, int32_t *falling_index_offset, bool store_greaseweazle=false, uint32_t capture_ms=0, uint32_t index_wait_ms=250) __attribute__((optimize("O3")))
 Capture one track's worth of flux transitions, between two falling index pulses. More...
 
bool write_track (uint8_t *pulses, size_t n_pulses, bool store_greaseweazle=false, bool use_index=true) __attribute__((optimize("O3")))
 Write one track of flux pulse data, starting at the index pulse. More...
 
void print_pulse_bins (uint8_t *pulses, size_t n_pulses, uint8_t max_bins=64, bool is_gw_format=false, uint32_t min_bin_size=100)
 Pretty print a simple histogram of flux transitions. More...
 
void print_pulses (uint8_t *pulses, size_t n_pulses, bool is_gw_format=false)
 Pretty print the counts in a list of flux transitions. More...
 
uint32_t getSampleFrequency (void)
 Get the sample rate that we read and emit pulses at, platform and implementation-dependant. More...
 

Additional Inherited Members

- Public Attributes inherited from Adafruit_FloppyBase
int8_t led_pin = -1
 Debug LED output for tracing.
 
uint16_t select_delay_us = 10
 delay after drive select (usecs)
 
uint16_t step_delay_us = 10000
 delay between head steps (usecs)
 
uint16_t settle_delay_ms = 15
 settle delay after seek (msecs)
 
uint16_t motor_delay_ms = 1000
 delay after motor on (msecs)
 
uint16_t watchdog_delay_ms
 quiescent time until drives reset (msecs) More...
 
uint8_t bus_type = BUSTYPE_IBMPC
 what kind of floppy drive we're using
 
Stream * debug_serial = nullptr
 optional debug stream for serial output
 
- Protected Member Functions inherited from Adafruit_FloppyBase
 Adafruit_FloppyBase (int indexpin, int wrdatapin, int wrgatepin, int rddatapin, bool is_apple2=false)
 Create a hardware interface to a floppy drive. More...
 
bool read_index ()
 Poll the status of the index pulse. More...
 

Detailed Description

A helper class for chattin with PC & Shugart floppy drives.

Constructor & Destructor Documentation

◆ Adafruit_Floppy()

Adafruit_Floppy::Adafruit_Floppy ( int8_t  densitypin,
int8_t  indexpin,
int8_t  selectpin,
int8_t  motorpin,
int8_t  directionpin,
int8_t  steppin,
int8_t  wrdatapin,
int8_t  wrgatepin,
int8_t  track0pin,
int8_t  protectpin,
int8_t  rddatapin,
int8_t  sidepin,
int8_t  readypin 
)

Create a hardware interface to a floppy drive.

Parameters
densitypinA pin connected to the floppy Density Select input
indexpinA pin connected to the floppy Index Sensor output
selectpinA pin connected to the floppy Drive Select input
motorpinA pin connected to the floppy Motor Enable input
directionpinA pin connected to the floppy Stepper Direction input
steppinA pin connected to the floppy Stepper input
wrdatapinA pin connected to the floppy Write Data input
wrgatepinA pin connected to the floppy Write Gate input
track0pinA pin connected to the floppy Track 00 Sensor output
protectpinA pin connected to the floppy Write Protect Sensor output
rddatapinA pin connected to the floppy Read Data output
sidepinA pin connected to the floppy Side Select input
readypinA pin connected to the floppy Ready/Disk Change output

Member Function Documentation

◆ select()

void Adafruit_Floppy::select ( bool  selected)
overridevirtual

Whether to select this drive.

Parameters
selectedTrue to select/enable

Implements Adafruit_FloppyBase.

◆ spin_motor()

bool Adafruit_Floppy::spin_motor ( bool  motor_on)
overridevirtual

Turn on or off the floppy motor, if on we wait till we get an index pulse!

Parameters
motor_onTrue to turn on motor, False to turn it off
Returns
False if turning motor on and no index pulse found, true otherwise

Implements Adafruit_FloppyBase.

◆ goto_track()

bool Adafruit_Floppy::goto_track ( int  track_num)
overridevirtual

Seek to the desired track, requires the motor to be spun up!

Parameters
track_numThe track to step to
Returns
True If we were able to get to the track location

Implements Adafruit_FloppyBase.

◆ side()

bool Adafruit_Floppy::side ( int  head)
overridevirtual

Which head/side to read from.

Parameters
headHead 0 or 1
Returns
true if the head can be selected, false otherwise
Note
If _sidepin is no pin, then only head 0 can be selected

Implements Adafruit_FloppyBase.

◆ track()

int Adafruit_Floppy::track ( void  )
overridevirtual

The current track location, based on internal caching.

Returns
The cached track location

Implements Adafruit_FloppyBase.

◆ get_side()

int Adafruit_Floppy::get_side ( void  )
overridevirtual

Current head in use, based on internal caching.

Returns
Head 0 or 1

Implements Adafruit_FloppyBase.

◆ step()

void Adafruit_Floppy::step ( bool  dir,
uint8_t  times 
)

Step the track motor.

Parameters
dirSTEP_OUT or STEP_IN depending on desired direction
timesHow many steps to take

◆ set_density()

bool Adafruit_Floppy::set_density ( bool  high_density)
overridevirtual

Set the density for flux reading and writing.

Parameters
high_densityfalse for low density, true for high density
Returns
True if the drive interface supports the given density.

Implements Adafruit_FloppyBase.

◆ get_write_protect()

bool Adafruit_Floppy::get_write_protect ( )
overridevirtual

Check whether the floppy in the drive is write protected.

Returns
False if the floppy is writable, true otherwise

Implements Adafruit_FloppyBase.

◆ get_track0_sense()

bool Adafruit_Floppy::get_track0_sense ( )
overridevirtual

Check whether the track0 sensor is active.

Returns
True if the track0 sensor is active, false otherwise
Note
On devices without a track0 sensor, this returns true when track()==0

Implements Adafruit_FloppyBase.

◆ get_ready_sense()

bool Adafruit_Floppy::get_ready_sense ( )
overridevirtual

Check whether the ready output is active.

Returns
True if the ready sensor is active, false otherwise
Note
On devices without a ready sensor, this always returns true

Implements Adafruit_FloppyBase.


The documentation for this class was generated from the following files: