Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Roadmap #1

Open
3 of 6 tasks
Gadgetoid opened this issue May 2, 2024 · 2 comments
Open
3 of 6 tasks

Roadmap #1

Gadgetoid opened this issue May 2, 2024 · 2 comments

Comments

@Gadgetoid
Copy link
Owner

Gadgetoid commented May 2, 2024

  • refactor uf2 support into a standard IOSteam? reader that works just like open() on a bin file
  • make this work on MicroPython?
  • refactor to a class/library (half way done, kinda)
  • add support for pins and such
  • add tests, CI and packaging
  • make UF2Reader lazy?
@Gadgetoid
Copy link
Owner Author

TO make this work on MicroPython, it just needs a new reader:

class FlashReader():
    def __init__(self):
        self.mem = machine.mem8
        self.offset = 0
        self.buf_len = 16
        self.buf = bytearray(self.buf_len)
        
    def seek(self, offset):
        self.offset = offset
        
    def read(self, length):
        buf = bytearray(length) if length > self.buf_len else self.buf
        for i in range(length):
            buf[i] = self.mem[FLASH_START_ADDR + self.offset]
            self.offset += 1
        return bytes(buf[:length])

@Gadgetoid
Copy link
Owner Author

Revised version now added to py_decl:

class MemoryReader():
    def __init__(self, mem, global_offset=FLASH_START_ADDR):
        self.mem = mem
        self.offset = 0
        self.buf_len = 16
        self.global_offset = global_offset
        self.buf = bytearray(self.buf_len)
        
    def seek(self, offset):
        self.offset = offset
        
    def read(self, length):
        buf = bytearray(length) if length > self.buf_len else self.buf
        for i in range(length):
            buf[i] = self.mem[self.global_offset + self.offset]
            self.offset += 1
        return bytes(buf[:length])

Note: UF2Reader does not work on MicroPython because you can't subclass BytesIO (call to BytesIO.__init__ fails).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant