Adafruit Library
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Adafruit_FloppyBase Class Referenceabstract

An abstract base class for chattin with floppy drives. More...

#include <Adafruit_Floppy.h>

Inheritance diagram for Adafruit_FloppyBase:
Adafruit_Apple2Floppy Adafruit_Floppy

Public Member Functions

bool begin (void)
 Initializes the GPIO pins but do not start the motor or anything. More...
 
virtual void end ()
 Disables floppy communication, allowing pins to be used for general input and output.
 
virtual void soft_reset (void)
 Initializes the GPIO pins but do not start the motor or anything.
 
virtual void select (bool selected)=0
 Whether to select this drive. More...
 
virtual bool spin_motor (bool motor_on)=0
 Turn on or off the floppy motor, if on we wait till we get an index pulse! More...
 
virtual bool goto_track (int track_num)=0
 Seek to the desired track, requires the motor to be spun up! More...
 
virtual bool side (int head)=0
 Which head/side to read from. More...
 
virtual int get_side ()=0
 Current head in use, based on internal caching. More...
 
virtual int track (void)=0
 The current track location, based on internal caching. More...
 
virtual bool get_write_protect ()=0
 Check whether the floppy in the drive is write protected. More...
 
virtual bool get_track0_sense ()=0
 Check whether the track0 sensor is active. More...
 
virtual bool get_ready_sense ()=0
 Check whether the ready output is active. More...
 
virtual bool set_density (bool high_density)=0
 Set the density for flux reading and writing. 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...
 

Public Attributes

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

 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

An abstract base class for chattin with floppy drives.

Constructor & Destructor Documentation

◆ Adafruit_FloppyBase()

Adafruit_FloppyBase::Adafruit_FloppyBase ( int  indexpin,
int  wrdatapin,
int  wrgatepin,
int  rddatapin,
bool  is_apple2 = false 
)
protected

Create a hardware interface to a floppy drive.

Parameters
indexpinA pin connected to the floppy Index Sensor output
wrdatapinA pin connected to the floppy Write Data input
wrgatepinA pin connected to the floppy Write Gate input
rddatapinA pin connected to the floppy Read Data output
is_apple2True if the flux write waveform is like Apple Disk ][

Member Function Documentation

◆ begin()

bool Adafruit_FloppyBase::begin ( void  )

Initializes the GPIO pins but do not start the motor or anything.

Returns
True if able to set up all pins and capture/waveform peripherals

◆ select()

virtual void Adafruit_FloppyBase::select ( bool  selected)
pure virtual

Whether to select this drive.

Parameters
selectedTrue to select/enable

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ spin_motor()

virtual bool Adafruit_FloppyBase::spin_motor ( bool  motor_on)
pure virtual

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

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ goto_track()

virtual bool Adafruit_FloppyBase::goto_track ( int  track_num)
pure virtual

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

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ side()

virtual bool Adafruit_FloppyBase::side ( int  head)
pure virtual

Which head/side to read from.

Parameters
headHead 0 or 1
Returns
true if the head exists, false otherwise

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ get_side()

virtual int Adafruit_FloppyBase::get_side ( )
pure virtual

Current head in use, based on internal caching.

Returns
Head 0 or 1

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ track()

virtual int Adafruit_FloppyBase::track ( void  )
pure virtual

The current track location, based on internal caching.

Returns
The cached track location
Note
Returns -1 if the track is not known.

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ get_write_protect()

virtual bool Adafruit_FloppyBase::get_write_protect ( )
pure virtual

Check whether the floppy in the drive is write protected.

Returns
False if the floppy is writable, true otherwise

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ get_track0_sense()

virtual bool Adafruit_FloppyBase::get_track0_sense ( )
pure virtual

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

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ get_ready_sense()

virtual bool Adafruit_FloppyBase::get_ready_sense ( )
pure virtual

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

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ set_density()

virtual bool Adafruit_FloppyBase::set_density ( bool  high_density)
pure virtual

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.

Implemented in Adafruit_Apple2Floppy, and Adafruit_Floppy.

◆ decode_track_mfm()

size_t Adafruit_FloppyBase::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.

Parameters
sectorsA pointer to an array of memory we can use to store into, 512*n_sectors bytes
n_sectorsThe number of sectors (e.g., 18 for a standard 3.5", 1.44MB format)
sector_validityAn array of values set to 1 if the sector was captured, 0 if not captured (no IDAM, CRC error, etc)
pulsesAn array of pulses from capture_track
n_pulsesAn array of pulses from capture_track
nominal_bit_time_usThe nominal time of one MFM bit, usually 1.0f (double density) or 2.0f (high density)
clear_validityWhether to clear the validity flag. Set to false if re-reading a track with errors.
logical_trackIf not NULL, updated with the logical track number of the last sector read. (track & side numbers are not otherwise verified)
Returns
Number of sectors we actually captured

◆ encode_track_mfm()

size_t Adafruit_FloppyBase::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.

Parameters
sectorsA pointer to an array of memory we can use to store into, 512*n_sectors bytes
n_sectorsThe number of sectors (e.g., 18 for a standard 3.5", 1.44MB format)
pulsesAn array of pulses from capture_track
max_pulsesThe maximum number of pulses that may be stored
nominal_bit_time_usThe nominal time of one MFM bit, usually 1.0f (double density) or 2.0f (high density)
logical_trackThe logical track number, or -1 to use track()
Returns
Number of pulses actually generated

◆ capture_track()

size_t Adafruit_FloppyBase::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 
)

Capture one track's worth of flux transitions, between two falling index pulses.

Parameters
pulsesA pointer to an array of memory we can use to store into
max_pulsesThe size of the allocated pulses array
falling_index_offsetPointer to a uint32_t where we will store the "flux index" where the second index pulse fell. usually we read 110-125% of one track so there is an overlap of index pulse reads
store_greaseweazlePass in true to pack long pulses with two bytes
capture_msIf not zero, we will capture at least one revolution and extra time will be determined by this variable. e.g. 250ms means one revolution plus about 50 ms post-index
index_wait_msIf not zero, wait at most this many ms for an index pulse to arrive
Returns
Number of pulses we actually captured

◆ write_track()

bool Adafruit_FloppyBase::write_track ( uint8_t *  pulses,
size_t  n_pulses,
bool  store_greaseweazle = false,
bool  use_index = true 
)

Write one track of flux pulse data, starting at the index pulse.

Parameters
pulsesAn array of timer-count pulses
n_pulsesHow many bytes are in the pulse array
store_greaseweazleIf true, long pulses are 'packed' in gw format
use_indexIf true, write starts at the index pulse.
Returns
False if the data could not be written (samd51 cannot write apple flux format)

◆ print_pulse_bins()

void Adafruit_FloppyBase::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.

Parameters
pulsesA pointer to an array of memory containing pulse counts
n_pulsesThe size of the pulses in the array
max_binsThe maximum number of histogram bins to use (default 64)
is_gw_formatSet to true if we pack long pulses with two bytes
min_bin_sizeBins with fewer samples than this are skipped, not printed

◆ print_pulses()

void Adafruit_FloppyBase::print_pulses ( uint8_t *  pulses,
size_t  n_pulses,
bool  is_gw_format = false 
)

Pretty print the counts in a list of flux transitions.

Parameters
pulsesA pointer to an array of memory containing pulse counts
n_pulsesThe size of the pulses in the array
is_gw_formatSet to true if we pack long pulses with two bytes

◆ getSampleFrequency()

uint32_t Adafruit_FloppyBase::getSampleFrequency ( void  )

Get the sample rate that we read and emit pulses at, platform and implementation-dependant.

Returns
Sample frequency in Hz, or 0 if not known

◆ read_index()

bool Adafruit_FloppyBase::read_index ( )
protected

Poll the status of the index pulse.

Returns
the status of the index pulse

Member Data Documentation

◆ watchdog_delay_ms

uint16_t Adafruit_FloppyBase::watchdog_delay_ms
Initial value:
=
1000

quiescent time until drives reset (msecs)


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