MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / cmd

Method cmd

mpython/lib/sdcard.py:148–184  ·  view source on GitHub ↗
(self, cmd, arg, crc, final=0, release=True, skip1=False)

Source from the content-addressed store, hash-verified

146 raise OSError("timeout waiting for v2 card")
147
148 def cmd(self, cmd, arg, crc, final=0, release=True, skip1=False):
149 self.cs(0)
150
151 # create and send the command
152 buf = self.cmdbuf
153 buf[0] = 0x40 | cmd
154 buf[1] = arg >> 24
155 buf[2] = arg >> 16
156 buf[3] = arg >> 8
157 buf[4] = arg
158 buf[5] = crc
159 self.spi.write(buf)
160
161 if skip1:
162 self.spi.readinto(self.tokenbuf, 0xFF)
163
164 # wait for the response (response[7] == 0)
165 for i in range(_CMD_TIMEOUT):
166 self.spi.readinto(self.tokenbuf, 0xFF)
167 response = self.tokenbuf[0]
168 if not (response & 0x80):
169 # this could be a big-endian integer that we are getting here
170 # if final<0 then store the first byte to tokenbuf and discard the rest
171 if final < 0:
172 self.spi.readinto(self.tokenbuf, 0xFF)
173 final = -1 - final
174 for j in range(final):
175 self.spi.write(b"\xff")
176 if release:
177 self.cs(1)
178 self.spi.write(b"\xff")
179 return response
180
181 # timeout
182 self.cs(1)
183 self.spi.write(b"\xff")
184 return -1
185
186 def readinto(self, buf):
187 self.cs(0)

Callers 5

init_cardMethod · 0.95
init_card_v1Method · 0.95
init_card_v2Method · 0.95
readblocksMethod · 0.95
writeblocksMethod · 0.95

Calls 2

readintoMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected