@@ -35,6 +35,11 @@ def __init__(self,
3535 :param software_reset: Flag to use software reset
3636 :type software_reset: bool
3737 """
38+ self ._manufacturer = 0x0
39+ self ._mem_type = 0
40+ self ._device_type = 0x0
41+ self ._capacity = 0
42+
3843 self .cs = cs
3944 self .spi = spi
4045 self .cs .init (self .cs .OUT , value = 1 )
@@ -58,12 +63,51 @@ def __init__(self,
5863 # setup address mode:
5964 if self ._ADR_LEN == 4 :
6065 if not self ._read_status_reg (nr = 16 ): # not in 4-byte mode
61- print ("entering 4-byte address mode" )
6266 self ._await ()
6367 self .cs (0 )
6468 self .spi .write (b'\xB7 ' ) # 'Enter 4-Byte Address Mode'
6569 self .cs (1 )
6670
71+ @property
72+ def capacity (self ) -> int :
73+ """
74+ Get the storage capacity of the flash
75+
76+ :returns: Capacity of the flash in bytes
77+ :rtype: int
78+ """
79+ return self ._capacity
80+
81+ @property
82+ def device (self ) -> int :
83+ """
84+ Get the flash device type
85+
86+ :returns: Flash device type
87+ :rtype: int
88+ """
89+ return self ._device_type
90+
91+ @property
92+ def manufacturer (self ) -> int :
93+ """
94+ Get the manufacturer ID of the flash
95+
96+ :returns: Manufacturer ID of the flash
97+ :rtype: int
98+ """
99+ return self ._manufacturer
100+
101+ @property
102+ def mem_type (self ) -> int :
103+ """
104+ Get the memory type of the flash
105+
106+ :returns: Memory type of the flash
107+ :rtype: int
108+ """
109+ return self ._mem_type
110+
67111 def reset (self ) -> None :
68112 """
69113 Reset the Winbond flash if the device has no hardware reset pin.
@@ -103,7 +147,6 @@ def reset(self) -> None:
103147 self .cs (1 )
104148 time .sleep_us (30 )
105149 self ._busy = False
106- # print('Reset performed')
107150
108151 def identify (self ) -> None :
109152 """
@@ -132,10 +175,11 @@ def identify(self) -> None:
132175 raise OSError ("manufacturer ({}) or memory type ({}) unsupported" .
133176 format (hex (mf ), hex (mem_type )))
134177
135- print ("manufacturer: {}" .format (hex (mf ))) # 0xef
136- print ("mem_type: {}" .format (mem_type ))
137- print ("device: {}" .format (hex (mem_type << 8 | cap ))) # 0x4016
138- print ("capacity: {} bytes" .format (self ._CAPACITY )) # 4194304 bytes
178+ self ._manufacturer = hex (mf )
179+ self ._mem_type = mem_type
180+ self ._device_type = hex (mem_type << 8 | cap )
181+ self ._capacity = self ._CAPACITY
182+
139183 # return self._CAPACITY # calculate number of bytes
140184
141185 def get_size (self ) -> int :
@@ -224,7 +268,6 @@ def _read(self, buf: list, addr: int) -> None:
224268 assert addr + len (buf ) <= self ._CAPACITY , \
225269 "memory not addressable at %s with range %d (max.: %s)" % \
226270 (hex (addr ), len (buf ), hex (self ._CAPACITY - 1 ))
227- # print("read {} bytes starting at {}".format(len(buf), hex(addr)))
228271
229272 self ._await ()
230273 self .cs (0 )
@@ -268,7 +311,6 @@ def _write(self, buf: list, addr: int) -> None:
268311 assert addr + len (buf ) <= self ._CAPACITY , \
269312 ("memory not addressable at {} with range {} (max.: {})" .
270313 format (hex (addr ), len (buf ), hex (self ._CAPACITY - 1 )))
271- # print("write buf[{}] to {} ({})".format(len(buf), hex(addr), addr))
272314
273315 for i in range (0 , len (buf ), self .PAGE_SIZE ):
274316 self ._wren ()
@@ -296,7 +338,6 @@ def _writeblock(self, blocknum: int, buf: list) -> None:
296338 """
297339 assert len (buf ) == self .BLOCK_SIZE , \
298340 "invalid block length: {}" .format (len (buf ))
299- # print("writeblock({}, buf[{}])".format(blocknum, len(buf)))
300341
301342 sector_nr = blocknum // 8
302343 sector_addr = sector_nr * self .SECTOR_SIZE
0 commit comments