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

#include <Adafruit_Floppy.h>

Inheritance diagram for Adafruit_MFM_Floppy:

Public Member Functions

 Adafruit_MFM_Floppy (Adafruit_Floppy *floppy, adafruit_floppy_disk_t format=AUTODETECT)
 Instantiate an MFM-formatted floppy. More...
 
bool begin (void)
 Initialize and spin up the floppy drive. More...
 
void end (void)
 Spin down and deselect the motor and drive. More...
 
uint32_t size (void) const
 Quick calculator for expected max capacity. More...
 
int32_t readTrack (uint8_t track, bool head)
 Read one track's worth of data and MFM decode it. More...
 
uint8_t sectors_per_track (void) const
 The expected number of sectors per track in this format. More...
 
uint8_t tracks_per_side (void) const
 The expected number of tracks per side in this format. More...
 
bool dirty () const
 Check if there is data to be written to the current track. More...
 
void removed ()
 Call when the media has been removed. More...
 
bool inserted (adafruit_floppy_disk_t format)
 Call when media has been inserted. More...
 
virtual bool isBusy ()
 Check if device busy. More...
 
virtual uint32_t sectorCount ()
 Max capacity in sector block. More...
 
virtual bool syncDevice ()
 Sync written blocks NOT IMPLEMENTED YET. More...
 
virtual bool readSector (uint32_t block, uint8_t *dst)
 Read a 512 byte block of data, may used cached data. More...
 
virtual bool readSectors (uint32_t block, uint8_t *dst, size_t ns)
 Read multiple 512 byte block of data, may used cached data. More...
 
virtual bool writeSector (uint32_t block, const uint8_t *src)
 Write a 512 byte block of data NOT IMPLEMENTED YET. More...
 
virtual bool writeSectors (uint32_t block, const uint8_t *src, size_t ns)
 Write multiple 512 byte blocks of data NOT IMPLEMENTED YET. More...
 

Public Attributes

uint8_t track_data [MFM_IBMPC1440K_SECTORS_PER_TRACK *MFM_BYTES_PER_SECTOR]
 
uint8_t track_validity [MFM_IBMPC1440K_SECTORS_PER_TRACK]
 

Detailed Description

This class adds support for the BaseBlockDriver interface to an MFM encoded floppy disk. This allows it to be used with SdFat's FatFileSystem class. or for a mass storage device

Constructor & Destructor Documentation

◆ Adafruit_MFM_Floppy()

Adafruit_MFM_Floppy::Adafruit_MFM_Floppy ( Adafruit_Floppy floppy,
adafruit_floppy_disk_t  format = AUTODETECT 
)

Instantiate an MFM-formatted floppy.

Parameters
floppyAn Adafruit_Floppy object that has the pins defined
formatWhat kind of format we will be parsing out - we DO NOT autodetect!

Member Function Documentation

◆ begin()

bool Adafruit_MFM_Floppy::begin ( void  )

Initialize and spin up the floppy drive.

Returns
True if we were able to spin up and detect an index track

◆ end()

void Adafruit_MFM_Floppy::end ( void  )

Spin down and deselect the motor and drive.

Returns
True always

◆ size()

uint32_t Adafruit_MFM_Floppy::size ( void  ) const

Quick calculator for expected max capacity.

Returns
Size of the drive in bytes

◆ readTrack()

int32_t Adafruit_MFM_Floppy::readTrack ( uint8_t  logical_track,
bool  head 
)

Read one track's worth of data and MFM decode it.

Parameters
logical_trackthe logical track number, 0 to whatever is the max tracks for the given format during instantiation (e.g. 40 for DD, 80 for HD)
headwhich side to read, false for side 1, true for side 2
Returns
Number of sectors captured, or -1 if we couldn't seek

◆ sectors_per_track()

uint8_t Adafruit_MFM_Floppy::sectors_per_track ( void  ) const
inline

The expected number of sectors per track in this format.

!

Returns
The number of sectors per track

◆ tracks_per_side()

uint8_t Adafruit_MFM_Floppy::tracks_per_side ( void  ) const
inline

The expected number of tracks per side in this format.

!

Returns
The number of tracks per side

◆ dirty()

bool Adafruit_MFM_Floppy::dirty ( ) const
inline

Check if there is data to be written to the current track.

!

Returns
True if data needs to be written out

◆ removed()

void Adafruit_MFM_Floppy::removed ( )

Call when the media has been removed.

!

◆ inserted()

bool Adafruit_MFM_Floppy::inserted ( adafruit_floppy_disk_t  format)

Call when media has been inserted.

!

Parameters
formatThe hard coded format or AUTODETECT to try several common formats
Returns
True if media is hard coded or if the media was detected by autodetect

◆ isBusy()

bool Adafruit_MFM_Floppy::isBusy ( )
virtual

Check if device busy.

Returns
true if busy

◆ sectorCount()

uint32_t Adafruit_MFM_Floppy::sectorCount ( )
virtual

Max capacity in sector block.

Returns
Size of the drive in sector (512 bytes)

◆ syncDevice()

bool Adafruit_MFM_Floppy::syncDevice ( )
virtual

Sync written blocks NOT IMPLEMENTED YET.

Returns
True on success, false if failed or unimplemented

◆ readSector()

bool Adafruit_MFM_Floppy::readSector ( uint32_t  block,
uint8_t *  dst 
)
virtual

Read a 512 byte block of data, may used cached data.

Parameters
blockBlock number, will be split into head and track based on expected formatting
dstDestination buffer
Returns
True on success

◆ readSectors()

bool Adafruit_MFM_Floppy::readSectors ( uint32_t  block,
uint8_t *  dst,
size_t  nb 
)
virtual

Read multiple 512 byte block of data, may used cached data.

Parameters
blockStarting block number, will be split into head and track based on expected formatting
dstDestination buffer
nbNumber of blocks to read
Returns
True on success

◆ writeSector()

bool Adafruit_MFM_Floppy::writeSector ( uint32_t  block,
const uint8_t *  src 
)
virtual

Write a 512 byte block of data NOT IMPLEMENTED YET.

Parameters
blockBlock number, will be split into head and track based on expected formatting
srcSource buffer
Returns
True on success, false if failed or unimplemented

◆ writeSectors()

bool Adafruit_MFM_Floppy::writeSectors ( uint32_t  block,
const uint8_t *  src,
size_t  nb 
)
virtual

Write multiple 512 byte blocks of data NOT IMPLEMENTED YET.

Parameters
blockStarting lock number, will be split into head and track based on expected formatting
srcSource buffer
nbNumber of consecutive blocks to write
Returns
True on success, false if failed or unimplemented

Member Data Documentation

◆ track_data

uint8_t Adafruit_MFM_Floppy::track_data[MFM_IBMPC1440K_SECTORS_PER_TRACK *MFM_BYTES_PER_SECTOR]

! The raw byte decoded data from the last track read

◆ track_validity

uint8_t Adafruit_MFM_Floppy::track_validity[MFM_IBMPC1440K_SECTORS_PER_TRACK]

! Which tracks from the last track-read were valid MFM/CRC!


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