API Reference

adafruit_floppy

Interface with old floppy drives.

  • Author(s): Jeff Epler

class adafruit_floppy.Floppy(*, densitypin: Pin, indexpin: Pin, selectpin: Pin, motorpin: Pin, directionpin: Pin, steppin: Pin, track0pin: Pin, protectpin: Pin, rddatapin: Pin, sidepin: Pin, readypin: Pin, wrdatapin: Pin | None = None, wrgatepin: Pin | None = None, floppydirectionpin: Pin | None = None, floppyenablepin: Pin | None = None)

Interface with floppy disk drive hardware

find_track0()

Move the head out until the ‘track0’ signal becomes False

If successful, sets the internal track number to 0.

If unsuccsessful, sets the internatl track number to None and raises an exception.

flux_readinto(buf: circuitpython_typing.WriteableBuffer) int

Read flux transition information into the buffer.

The function returns when the buffer has filled, or when the index input indicates that one full revolution of data has been recorded. Due to technical limitations, this process may not be interruptible by KeyboardInterrupt.

Parameters:

buf – Read data into this buffer. Each element represents the time between successive zero-to-one transitions.

Returns:

The actual number of bytes of read

property selected: bool

Select this drive.

Set this property to True before doing anything with the drive.

property side: int

The side (0/1) for read/write operations

property spin: bool

True spins the floppy, False stops it

property track: int | None

The current track number, or None if the track number is unknown.

class adafruit_floppy.FloppyBlockDevice(floppy, *, max_sectors=18, autodetect: bool = True, heads: int | None = None, sectors: int | None = None, tracks: int | None = None, flux_buffer: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray | None = None, t1_nom_ns: float | None = None, keep_selected: bool = False)

Wrap an MFMFloppy object into a block device suitable for storage.VfsFat

The default is to autodetect the data rate and the geometry of an inserted floppy using the floppy’s “BIOS paramter block”

In the current implementation, the floppy is read-only.

A cache is used for track 0 on cylinder 0 and for the last track accessed.

Example:

import storage
import adafruit_floppy

floppy = adafruit_floppy.Floppy(...)
block_device = adafruit_floppy.FloppyBlockDevice(floppy)
vfs = storage.VfsFat(f)
storage.mount(vfs, '/floppy')
print(os.listdir("/floppy"))
autodetect()

Detect an inserted DOS floppy

The floppy must have a standard MFM data rate & DOS 2.0 compatible Bios Parameter Block (BPB). Almost all FAT formatted floppies for DOS & Windows should autodetect in this way.

This also flushes the cached data.

count()

Return the floppy capacity in 512-byte units

deinit()

Deinitialize this object

property keep_selected: bool

Whether to keep the drive selected & spinning between operations

This can make operations faster by avoiding spin up time

on_disk_change()

This function (or autodetect or setformat) must be called after a disk is changed

Flushes the cached floppy data

readblocks(start_block, buf)

Read a number of blocks from the flopppy

setformat(heads, sectors, tracks, t1_nom_ns)

Set the floppy format details

This also calls on_disk_change to flush cached floppy data.

sync()

Write out any pending data to disk (does nothing)

writeblocks(start, buf)

Write to the floppy (always raises an exception)