Skip to content

Commit

Permalink
Fix pre-commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Apr 2, 2024
1 parent 96b2068 commit 90a33c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
31 changes: 24 additions & 7 deletions adafruit_floppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def _check_inpos(self) -> None:
drive_says_track0 = not self._track0.value
we_think_track0 = track == 0
if drive_says_track0 != we_think_track0:
raise RuntimeError(f"Drive lost position (target={track}, track0 sensor {drive_says_track0})")
raise RuntimeError(
f"Drive lost position (target={track}, track0 sensor {drive_says_track0})"
)

@property
def track(self) -> typing.Optional[int]:
Expand Down Expand Up @@ -217,7 +219,7 @@ def flux_readinto(self, buf: "circuitpython_typing.WritableBuffer") -> int:
return floppyio.flux_readinto(buf, self._rddata, self._index)


class FloppyBlockDevice:
class FloppyBlockDevice: # pylint: disable=too-many-instance-attributes
"""Wrap an MFMFloppy object into a block device suitable for `storage.VfsFat`
The default heads/sectors/tracks setting are for 3.5", 1.44MB floppies.
Expand All @@ -238,12 +240,20 @@ class FloppyBlockDevice:
print(os.listdir("/floppy"))
"""

def __init__(self, floppy, heads=2, sectors=18, tracks=80, flux_buffer=None, t1_nom_ns: float=1000):
def __init__( # pylint: disable=too-many-arguments
self,
floppy,
heads=2,
sectors=18,
tracks=80,
flux_buffer=None,
t1_nom_ns: float = 1000,
):
self.floppy = floppy
self.heads = heads
self.sectors = sectors
self.tracks = tracks
self.flux_buffer = flux_buffer or buffer(sectors * 12 * 512)
self.flux_buffer = flux_buffer or bytearray(sectors * 12 * 512)
self.track0side0_cache = memoryview(bytearray(sectors * 512))
self.track0side0_validity = bytearray(sectors)
self.track_cache = memoryview(bytearray(sectors * 512))
Expand All @@ -257,7 +267,6 @@ def __init__(self, floppy, heads=2, sectors=18, tracks=80, flux_buffer=None, t1_
self.cached_track = -1
self.cached_side = -1


def deinit(self):
"""Deinitialize this object"""
self.floppy.deinit()
Expand Down Expand Up @@ -316,5 +325,13 @@ def _mfm_readinto(self, track_data, validity):
for i in range(5):
self.floppy.flux_readinto(self.flux_buffer)
print("timing bins", self._t2_5_max, self._t3_5_max)
n = floppyio.mfm_readinto(track_data, self.flux_buffer, self._t2_5_max, self._t3_5_max, validity, i==0)
if n == self.sectors: break
n = floppyio.mfm_readinto(
track_data,
self.flux_buffer,
self._t2_5_max,
self._t3_5_max,
validity,
i == 0,
)
if n == self.sectors:
break
15 changes: 7 additions & 8 deletions examples/floppy_vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# memory fragmentation
flux_buffer = bytearray(110000)

# pylint: disable=wrong-import-position
import os
import storage
import board
Expand All @@ -22,7 +23,7 @@
ST_TIME = 7
SV_BFREE = 3

if hasattr(board, 'DENSITY'): # floppsy
if hasattr(board, "DENSITY"): # floppsy
floppy = adafruit_floppy.Floppy(
densitypin=board.DENSITY,
indexpin=board.INDEX,
Expand All @@ -39,6 +40,9 @@
)

else:
D24 = getattr(board, "D24") or getattr(board, "A4")
D25 = getattr(board, "D25") or getattr(board, "A5")

floppy = adafruit_floppy.Floppy(
densitypin=board.A1,
indexpin=D25,
Expand All @@ -51,17 +55,12 @@
rddatapin=board.D9,
sidepin=board.D6,
readypin=board.D5,
flux_buffer=flux_buffer
flux_buffer=flux_buffer,
)

floppy.find_track0()
print(sum(floppy._index.value for _ in range(100_000)))
print(floppy.flux_readinto(flux_buffer))
print(sum(flux_buffer))

f = adafruit_floppy.FloppyBlockDevice(floppy, sectors=18,
flux_buffer=flux_buffer
)
f = adafruit_floppy.FloppyBlockDevice(floppy, sectors=18, flux_buffer=flux_buffer)

vfs = storage.VfsFat(f)
storage.mount(vfs, "/floppy")
Expand Down

0 comments on commit 90a33c1

Please sign in to comment.