Skip to content
Snippets Groups Projects
Select Git revision
  • 7e436cb0ebddf1f60c1f39a89182beaee08ea34b
  • master default protected
  • patch-2
  • patch-1
  • add_menu_vibration
  • close_sensor_on_keyboard_interrupt
  • schneider/standby
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
35 results

struct.py

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    flashbdev.py 1.08 KiB
    import esp
    
    class FlashBdev:
    
        SEC_SIZE = 4096
        RESERVED_SECS = 0
        START_SEC = esp.flash_user_start() // SEC_SIZE + RESERVED_SECS
        NUM_BLK = 0x6b - RESERVED_SECS
    
        def __init__(self, blocks=NUM_BLK):
            self.blocks = blocks
    
        def readblocks(self, n, buf):
            #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
            esp.flash_read((n + self.START_SEC) * self.SEC_SIZE, buf)
    
        def writeblocks(self, n, buf):
            #print("writeblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
            #assert len(buf) <= self.SEC_SIZE, len(buf)
            esp.flash_erase(n + self.START_SEC)
            esp.flash_write((n + self.START_SEC) * self.SEC_SIZE, buf)
    
        def ioctl(self, op, arg):
            #print("ioctl(%d, %r)" % (op, arg))
            if op == 4:  # BP_IOCTL_SEC_COUNT
                return self.blocks
            if op == 5:  # BP_IOCTL_SEC_SIZE
                return self.SEC_SIZE
    
    size = esp.flash_size()
    if size < 1024*1024:
        bdev = None
    else:
        # 20K at the flash end is reserved for SDK params storage
        bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)