# uPy - RPi Pico testing Fram MB85RS64 through SPI and FS
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-01-28  initial release

from	machine		import	Pin, SPI
from	mve_fram	import	MB85RS64	as	Fram
from	ve_fram_fs	import	FramFs

# ============ Hardware definitions (Pico) ==============

pin_led         = 25				# on-board green led
pin_spi_sck		= 18
pin_spi_mosi	= 19
pin_spi_miso	= 16
pin_spi_cs		= 17

# ================== Hardware setup  ===================

led		= Pin(pin_led, Pin.OUT, value=1)
spi	    = SPI(0, 10_000_000, sck=pin_spi_sck, mosi=pin_spi_mosi,
              miso=pin_spi_miso)
spi_cs  = Pin(pin_spi_cs, Pin.OUT, value=1)

# ======================= main =========================
    
def main():
    fram = Fram(spi=spi, cs=spi_cs)
    fs   = FramFs(fram)
    fs.erase()
#     fs.write('A1', 'hello')
#     fs.write('A2', '12345')
#     fs.write('A3', 'Hello world')
#     fs.write('A4', '0123456789')
#     print(fs.read('A1'))
#     print(fs.read('A2'))
#     print(fs.read('A3'))
#     print(fs.read('A4'))
#     fs.dump(0x0000, 0x0040);	print()
#     fs.dump(0x0400, 0x0440);	print()
#     fs.printLs();    			print()
#     print(fs.ls())
#     fs.delete('A2')
#     print(fs.ls())
#     fs.defragment()
#     print(fs.ls())
    # fs.dump()
    fs.dump(0x0000, 0x0040);	print()
    fs.dump(0x0400, 0x0440);	print()
#     fs.printLs();				print()
#     print(fs.ls());				print()
    
#     print(fs.read('A1'))
#     print(fs.read('A3'))
#     print(fs.read('A4'))

#     file1 = 'line1\nline2\nline3'
#     fs.write('file1.txt', file1)
#     print(fs.read('file1.txt'))

#     file2 = '''
# line 10
# line 20
# line 33'''
#     fs.write('file2.txt', file2)
#     print(fs.read('file2.txt'))

    # d = dict(key1=123, key2='hello', key3=3.14, key4=[1,2,3,4,5])
    # fs.write('A5', d)
    # print(fs.read('A5'))

main()

# ======================== End ==========================
