]> sigrok.org Git - libsigrokdecode.git/blame - decoders/spiflash/pd.py
all decoders: introduce a reset() method
[libsigrokdecode.git] / decoders / spiflash / pd.py
CommitLineData
1b1c914f 1##
50bd5d25 2## This file is part of the libsigrokdecode project.
1b1c914f 3##
1be94d3d 4## Copyright (C) 2011-2016 Uwe Hermann <uwe@hermann-uwe.de>
1b1c914f
UH
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 2 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
4539e9ca 17## along with this program; if not, see <http://www.gnu.org/licenses/>.
1b1c914f
UH
18##
19
677d597b 20import sigrokdecode as srd
c2446117 21from .lists import *
1b1c914f 22
1be94d3d
UH
23L = len(cmds)
24
25# Don't forget to keep this in sync with 'cmds' is lists.py.
26class Ann:
27 WRSR, PP, READ, WRDI, RDSR, WREN, FAST_READ, SE, RDSCUR, WRSCUR, \
28 RDSR2, CE, ESRY, DSRY, REMS, RDID, RDP_RES, CP, ENSO, DP, READ2X, \
29 EXSO, CE2, BE, REMS2, \
30 BIT, FIELD, WARN = range(L + 3)
31
9389f2c1 32def cmd_annotation_classes():
da9bcbd9 33 return tuple([tuple([cmd[0].lower(), cmd[1]]) for cmd in cmds.values()])
9389f2c1 34
10d3c8dc
AG
35def decode_dual_bytes(sio0, sio1):
36 # Given a byte in SIO0 (MOSI) of even bits and a byte in
37 # SIO1 (MISO) of odd bits, return a tuple of two bytes.
38 def combine_byte(even, odd):
39 result = 0
40 for bit in range(4):
41 if even & (1 << bit):
42 result |= 1 << (bit*2)
43 if odd & (1 << bit):
44 result |= 1 << ((bit*2) + 1)
45 return result
46 return (combine_byte(sio0 >> 4, sio1 >> 4), combine_byte(sio0, sio1))
47
7cfbf663
UH
48def decode_status_reg(data):
49 # TODO: Additional per-bit(s) self.put() calls with correct start/end.
50
51 # Bits[0:0]: WIP (write in progress)
52 s = 'W' if (data & (1 << 0)) else 'No w'
53 ret = '%srite operation in progress.\n' % s
54
55 # Bits[1:1]: WEL (write enable latch)
56 s = '' if (data & (1 << 1)) else 'not '
57 ret += 'Internal write enable latch is %sset.\n' % s
58
59 # Bits[5:2]: Block protect bits
60 # TODO: More detailed decoding (chip-dependent).
61 ret += 'Block protection bits (BP3-BP0): 0x%x.\n' % ((data & 0x3c) >> 2)
62
63 # Bits[6:6]: Continuously program mode (CP mode)
64 s = '' if (data & (1 << 6)) else 'not '
65 ret += 'Device is %sin continuously program mode (CP mode).\n' % s
66
67 # Bits[7:7]: SRWD (status register write disable)
cd287c56 68 s = 'not ' if (data & (1 << 7)) else ''
7cfbf663
UH
69 ret += 'Status register writes are %sallowed.\n' % s
70
71 return ret
72
677d597b 73class Decoder(srd.Decoder):
b197383c 74 api_version = 3
3ca1f1b3
UH
75 id = 'spiflash'
76 name = 'SPI flash'
77 longname = 'SPI flash chips'
78 desc = 'xx25 series SPI (NOR) flash chip protocol.'
1b1c914f 79 license = 'gplv2+'
a1497fa3 80 inputs = ['spi']
3ca1f1b3 81 outputs = ['spiflash']
da9bcbd9 82 annotations = cmd_annotation_classes() + (
1be94d3d
UH
83 ('bit', 'Bit'),
84 ('field', 'Field'),
85 ('warning', 'Warning'),
da9bcbd9 86 )
9ed42038 87 annotation_rows = (
1be94d3d
UH
88 ('bits', 'Bits', (L + 0,)),
89 ('fields', 'Fields', (L + 1,)),
90 ('commands', 'Commands', tuple(range(len(cmds)))),
91 ('warnings', 'Warnings', (L + 2,)),
9ed42038 92 )
c2446117
UH
93 options = (
94 {'id': 'chip', 'desc': 'Chip', 'default': tuple(chips.keys())[0],
95 'values': tuple(chips.keys())},
b33a73bc
UH
96 {'id': 'format', 'desc': 'Data format', 'default': 'hex',
97 'values': ('hex', 'ascii')},
c2446117 98 )
1b1c914f 99
92b7b49f 100 def __init__(self):
10aeb8ea
GS
101 self.reset()
102
103 def reset(self):
db188228 104 self.device_id = -1
2c920167
AG
105 self.on_end_transaction = None
106 self.end_current_transaction()
107
1ec9c5e2
AG
108 # Build dict mapping command keys to handler functions. Each
109 # command in 'cmds' (defined in lists.py) has a matching
110 # handler self.handle_<shortname>.
111 def get_handler(cmd):
112 s = 'handle_%s' % cmds[cmd][0].lower().replace('/', '_')
113 return getattr(self, s)
114 self.cmd_handlers = dict((cmd, get_handler(cmd)) for cmd in cmds.keys())
115
2c920167
AG
116 def end_current_transaction(self):
117 if self.on_end_transaction is not None: # Callback for CS# transition.
118 self.on_end_transaction()
119 self.on_end_transaction = None
4772a846 120 self.state = None
781ef945 121 self.cmdstate = 1
e4022299
UH
122 self.addr = 0
123 self.data = []
1b1c914f 124
8915b346 125 def start(self):
be465111 126 self.out_ann = self.register(srd.OUTPUT_ANN)
c2446117 127 self.chip = chips[self.options['chip']]
db188228 128 self.vendor = self.options['chip'].split('_')[0]
1b1c914f 129
385508e9 130 def putx(self, data):
ee3e279c 131 # Simplification, most annotations span exactly one SPI byte/packet.
9b4d8a57
UH
132 self.put(self.ss, self.es, self.out_ann, data)
133
de22de7f
UH
134 def putf(self, data):
135 self.put(self.ss_field, self.es_field, self.out_ann, data)
136
137 def putc(self, data):
138 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
139
140 def device(self):
141 return device_name[self.vendor].get(self.device_id, 'Unknown')
7c139a54 142
db188228 143 def vendor_device(self):
de22de7f
UH
144 return '%s %s' % (self.chip['vendor'], self.device())
145
146 def cmd_ann_list(self):
147 x, s = cmds[self.state][0], cmds[self.state][1]
148 return ['Command: %s (%s)' % (s, x), 'Command: %s' % s,
149 'Cmd: %s' % s, 'Cmd: %s' % x, x]
150
151 def cmd_vendor_dev_list(self):
152 c, d = cmds[self.state], 'Device = %s' % self.vendor_device()
153 return ['%s (%s): %s' % (c[1], c[0], d), '%s: %s' % (c[1], d),
154 '%s: %s' % (c[0], d), d, self.vendor_device()]
155
156 def emit_cmd_byte(self):
157 self.ss_cmd = self.ss
158 self.putx([Ann.FIELD, self.cmd_ann_list()])
159 self.addr = 0
160
161 def emit_addr_bytes(self, mosi):
162 self.addr |= (mosi << ((4 - self.cmdstate) * 8))
163 b = ((3 - (self.cmdstate - 2)) * 8) - 1
164 self.putx([Ann.BIT,
165 ['Address bits %d..%d: 0x%02x' % (b, b - 7, mosi),
166 'Addr bits %d..%d: 0x%02x' % (b, b - 7, mosi),
167 'Addr bits %d..%d' % (b, b - 7), 'A%d..A%d' % (b, b - 7)]])
168 if self.cmdstate == 2:
169 self.ss_field = self.ss
170 if self.cmdstate == 4:
171 self.es_field = self.es
172 self.putf([Ann.FIELD, ['Address: 0x%06x' % self.addr,
173 'Addr: 0x%06x' % self.addr, '0x%06x' % self.addr]])
db188228 174
9b4d8a57 175 def handle_wren(self, mosi, miso):
de22de7f 176 self.putx([Ann.WREN, self.cmd_ann_list()])
4772a846 177 self.state = None
1b1c914f 178
b54936a9
UH
179 def handle_wrdi(self, mosi, miso):
180 pass # TODO
181
9b4d8a57 182 def handle_rdid(self, mosi, miso):
1b1c914f
UH
183 if self.cmdstate == 1:
184 # Byte 1: Master sends command ID.
de22de7f 185 self.emit_cmd_byte()
1b1c914f
UH
186 elif self.cmdstate == 2:
187 # Byte 2: Slave sends the JEDEC manufacturer ID.
de22de7f 188 self.putx([Ann.FIELD, ['Manufacturer ID: 0x%02x' % miso]])
1b1c914f 189 elif self.cmdstate == 3:
de22de7f
UH
190 # Byte 3: Slave sends the memory type.
191 self.putx([Ann.FIELD, ['Memory type: 0x%02x' % miso]])
1b1c914f
UH
192 elif self.cmdstate == 4:
193 # Byte 4: Slave sends the device ID.
9b4d8a57 194 self.device_id = miso
de22de7f 195 self.putx([Ann.FIELD, ['Device ID: 0x%02x' % miso]])
1b1c914f
UH
196
197 if self.cmdstate == 4:
de22de7f
UH
198 self.es_cmd = self.es
199 self.putc([Ann.RDID, self.cmd_vendor_dev_list()])
4772a846 200 self.state = None
1b1c914f
UH
201 else:
202 self.cmdstate += 1
203
b54936a9
UH
204 def handle_rdsr(self, mosi, miso):
205 # Read status register: Master asserts CS#, sends RDSR command,
206 # reads status register byte. If CS# is kept asserted, the status
207 # register can be read continuously / multiple times in a row.
208 # When done, the master de-asserts CS# again.
209 if self.cmdstate == 1:
210 # Byte 1: Master sends command ID.
de22de7f 211 self.emit_cmd_byte()
b54936a9
UH
212 elif self.cmdstate >= 2:
213 # Bytes 2-x: Slave sends status register as long as master clocks.
de22de7f
UH
214 self.es_cmd = self.es
215 self.putx([Ann.BIT, [decode_status_reg(miso)]])
216 self.putx([Ann.FIELD, ['Status register']])
217 self.putc([Ann.RDSR, self.cmd_ann_list()])
b54936a9
UH
218 self.cmdstate += 1
219
6ccb64fe
UH
220 def handle_rdsr2(self, mosi, miso):
221 # Read status register 2: Master asserts CS#, sends RDSR2 command,
222 # reads status register 2 byte. If CS# is kept asserted, the status
223 # register 2 can be read continuously / multiple times in a row.
224 # When done, the master de-asserts CS# again.
225 if self.cmdstate == 1:
226 # Byte 1: Master sends command ID.
de22de7f 227 self.emit_cmd_byte()
6ccb64fe
UH
228 elif self.cmdstate >= 2:
229 # Bytes 2-x: Slave sends status register 2 as long as master clocks.
de22de7f
UH
230 self.es_cmd = self.es
231 # TODO: Decode status register 2 correctly.
232 self.putx([Ann.BIT, [decode_status_reg(miso)]])
233 self.putx([Ann.FIELD, ['Status register 2']])
234 self.putc([Ann.RDSR2, self.cmd_ann_list()])
6ccb64fe
UH
235 self.cmdstate += 1
236
b54936a9 237 def handle_wrsr(self, mosi, miso):
0a89f2ae
UH
238 # Write status register: Master asserts CS#, sends WRSR command,
239 # writes 1 or 2 status register byte(s).
240 # When done, the master de-asserts CS# again. If this doesn't happen
241 # the WRSR command will not be executed.
242 if self.cmdstate == 1:
243 # Byte 1: Master sends command ID.
de22de7f
UH
244 self.emit_cmd_byte()
245 elif self.cmdstate == 2:
246 # Byte 2: Master sends status register 1.
247 self.putx([Ann.BIT, [decode_status_reg(miso)]])
248 self.putx([Ann.FIELD, ['Status register 1']])
249 elif self.cmdstate == 3:
250 # Byte 3: Master sends status register 2.
251 # TODO: Decode status register 2 correctly.
252 self.putx([Ann.BIT, [decode_status_reg(miso)]])
253 self.putx([Ann.FIELD, ['Status register 2']])
254 self.es_cmd = self.es
255 self.putc([Ann.WRSR, self.cmd_ann_list()])
0a89f2ae 256 self.cmdstate += 1
b54936a9
UH
257
258 def handle_read(self, mosi, miso):
259 # Read data bytes: Master asserts CS#, sends READ command, sends
260 # 3-byte address, reads >= 1 data bytes, de-asserts CS#.
261 if self.cmdstate == 1:
262 # Byte 1: Master sends command ID.
de22de7f 263 self.emit_cmd_byte()
b54936a9
UH
264 elif self.cmdstate in (2, 3, 4):
265 # Bytes 2/3/4: Master sends read address (24bits, MSB-first).
de22de7f 266 self.emit_addr_bytes(mosi)
b54936a9
UH
267 elif self.cmdstate >= 5:
268 # Bytes 5-x: Master reads data bytes (until CS# de-asserted).
de22de7f 269 self.es_field = self.es # Will be overwritten for each byte.
2c920167 270 if self.cmdstate == 5:
de22de7f
UH
271 self.ss_field = self.ss
272 self.on_end_transaction = lambda: self.output_data_block('Data', Ann.READ)
2c920167 273 self.data.append(miso)
b54936a9
UH
274 self.cmdstate += 1
275
276 def handle_fast_read(self, mosi, miso):
7c139a54
UH
277 # Fast read: Master asserts CS#, sends FAST READ command, sends
278 # 3-byte address + 1 dummy byte, reads >= 1 data bytes, de-asserts CS#.
279 if self.cmdstate == 1:
280 # Byte 1: Master sends command ID.
de22de7f 281 self.emit_cmd_byte()
7c139a54 282 elif self.cmdstate in (2, 3, 4):
de22de7f
UH
283 # Bytes 2/3/4: Master sends read address (24bits, MSB-first).
284 self.emit_addr_bytes(mosi)
7c139a54 285 elif self.cmdstate == 5:
1be94d3d 286 self.putx([Ann.BIT, ['Dummy byte: 0x%02x' % mosi]])
7c139a54
UH
287 elif self.cmdstate >= 6:
288 # Bytes 6-x: Master reads data bytes (until CS# de-asserted).
de22de7f 289 self.es_field = self.es # Will be overwritten for each byte.
7c139a54 290 if self.cmdstate == 6:
de22de7f
UH
291 self.ss_field = self.ss
292 self.on_end_transaction = lambda: self.output_data_block('Data', Ann.FAST_READ)
2c920167 293 self.data.append(miso)
7c139a54 294 self.cmdstate += 1
b54936a9
UH
295
296 def handle_2read(self, mosi, miso):
de22de7f
UH
297 # 2x I/O read (fast read dual I/O): Master asserts CS#, sends 2READ
298 # command, sends 3-byte address + 1 dummy byte, reads >= 1 data bytes,
299 # de-asserts CS#. All data after the command is sent via two I/O pins.
10d3c8dc 300 # MOSI = SIO0 = even bits, MISO = SIO1 = odd bits.
de22de7f
UH
301 if self.cmdstate != 1:
302 b1, b2 = decode_dual_bytes(mosi, miso)
10d3c8dc
AG
303 if self.cmdstate == 1:
304 # Byte 1: Master sends command ID.
de22de7f
UH
305 self.emit_cmd_byte()
306 elif self.cmdstate == 2:
307 # Bytes 2/3(/4): Master sends read address (24bits, MSB-first).
308 # Handle bytes 2 and 3 here.
309 self.emit_addr_bytes(b1)
310 self.cmdstate = 3
311 self.emit_addr_bytes(b2)
312 elif self.cmdstate == 4:
313 # Byte 5: Dummy byte. Also handle byte 4 (address LSB) here.
314 self.emit_addr_bytes(b1)
315 self.cmdstate = 5
316 self.putx([Ann.BIT, ['Dummy byte: 0x%02x' % b2]])
317 elif self.cmdstate >= 6:
318 # Bytes 6-x: Master reads data bytes (until CS# de-asserted).
319 self.es_field = self.es # Will be overwritten for each byte.
320 if self.cmdstate == 6:
321 self.ss_field = self.ss
322 self.on_end_transaction = lambda: self.output_data_block('Data', Ann.READ2X)
323 self.data.append(b1)
324 self.data.append(b2)
325 self.cmdstate += 1
b54936a9 326
1b1c914f
UH
327 # TODO: Warn/abort if we don't see the necessary amount of bytes.
328 # TODO: Warn if WREN was not seen before.
9b4d8a57 329 def handle_se(self, mosi, miso):
1b1c914f
UH
330 if self.cmdstate == 1:
331 # Byte 1: Master sends command ID.
de22de7f 332 self.emit_cmd_byte()
1b1c914f 333 elif self.cmdstate in (2, 3, 4):
868fd207 334 # Bytes 2/3/4: Master sends sector address (24bits, MSB-first).
de22de7f 335 self.emit_addr_bytes(mosi)
1b1c914f
UH
336
337 if self.cmdstate == 4:
de22de7f 338 self.es_cmd = self.es
87e574b7 339 d = 'Erase sector %d (0x%06x)' % (self.addr, self.addr)
de22de7f 340 self.putc([Ann.SE, [d]])
1b1c914f
UH
341 # TODO: Max. size depends on chip, check that too if possible.
342 if self.addr % 4096 != 0:
343 # Sector addresses must be 4K-aligned (same for all 3 chips).
de22de7f 344 self.putc([Ann.WARN, ['Warning: Invalid sector address!']])
4772a846 345 self.state = None
1b1c914f
UH
346 else:
347 self.cmdstate += 1
348
b54936a9
UH
349 def handle_be(self, mosi, miso):
350 pass # TODO
351
352 def handle_ce(self, mosi, miso):
353 pass # TODO
354
355 def handle_ce2(self, mosi, miso):
356 pass # TODO
357
358 def handle_pp(self, mosi, miso):
359 # Page program: Master asserts CS#, sends PP command, sends 3-byte
360 # page address, sends >= 1 data bytes, de-asserts CS#.
361 if self.cmdstate == 1:
362 # Byte 1: Master sends command ID.
de22de7f 363 self.emit_cmd_byte()
b54936a9
UH
364 elif self.cmdstate in (2, 3, 4):
365 # Bytes 2/3/4: Master sends page address (24bits, MSB-first).
de22de7f 366 self.emit_addr_bytes(mosi)
b54936a9
UH
367 elif self.cmdstate >= 5:
368 # Bytes 5-x: Master sends data bytes (until CS# de-asserted).
de22de7f 369 self.es_field = self.es # Will be overwritten for each byte.
2c920167 370 if self.cmdstate == 5:
de22de7f
UH
371 self.ss_field = self.ss
372 self.on_end_transaction = lambda: self.output_data_block('Data', Ann.PP)
2c920167 373 self.data.append(mosi)
b54936a9
UH
374 self.cmdstate += 1
375
376 def handle_cp(self, mosi, miso):
377 pass # TODO
378
379 def handle_dp(self, mosi, miso):
380 pass # TODO
381
382 def handle_rdp_res(self, mosi, miso):
e33410d3
UH
383 if self.cmdstate == 1:
384 # Byte 1: Master sends command ID.
de22de7f 385 self.emit_cmd_byte()
e33410d3
UH
386 elif self.cmdstate in (2, 3, 4):
387 # Bytes 2/3/4: Master sends three dummy bytes.
de22de7f 388 self.putx([Ann.FIELD, ['Dummy byte: %02x' % mosi]])
e33410d3
UH
389 elif self.cmdstate == 5:
390 # Byte 5: Slave sends device ID.
de22de7f 391 self.es_cmd = self.es
db188228 392 self.device_id = miso
de22de7f
UH
393 self.putx([Ann.FIELD, ['Device ID: %s' % self.device()]])
394 d = 'Device = %s' % self.vendor_device()
395 self.putc([Ann.RDP_RES, self.cmd_vendor_dev_list()])
e33410d3 396 self.state = None
e33410d3 397 self.cmdstate += 1
b54936a9 398
9b4d8a57 399 def handle_rems(self, mosi, miso):
1b1c914f
UH
400 if self.cmdstate == 1:
401 # Byte 1: Master sends command ID.
de22de7f 402 self.emit_cmd_byte()
1b1c914f
UH
403 elif self.cmdstate in (2, 3):
404 # Bytes 2/3: Master sends two dummy bytes.
de22de7f 405 self.putx([Ann.FIELD, ['Dummy byte: 0x%02x' % mosi]])
1b1c914f
UH
406 elif self.cmdstate == 4:
407 # Byte 4: Master sends 0x00 or 0x01.
408 # 0x00: Master wants manufacturer ID as first reply byte.
409 # 0x01: Master wants device ID as first reply byte.
9b4d8a57
UH
410 self.manufacturer_id_first = True if (mosi == 0x00) else False
411 d = 'manufacturer' if (mosi == 0x00) else 'device'
de22de7f 412 self.putx([Ann.FIELD, ['Master wants %s ID first' % d]])
1b1c914f
UH
413 elif self.cmdstate == 5:
414 # Byte 5: Slave sends manufacturer ID (or device ID).
9b4d8a57
UH
415 self.ids = [miso]
416 d = 'Manufacturer' if self.manufacturer_id_first else 'Device'
de22de7f 417 self.putx([Ann.FIELD, ['%s ID: 0x%02x' % (d, miso)]])
9b4d8a57 418 elif self.cmdstate == 6:
1b1c914f 419 # Byte 6: Slave sends device ID (or manufacturer ID).
7f7ea759 420 self.ids.append(miso)
de22de7f
UH
421 d = 'Device' if self.manufacturer_id_first else 'Manufacturer'
422 self.putx([Ann.FIELD, ['%s ID: 0x%02x' % (d, miso)]])
1b1c914f
UH
423
424 if self.cmdstate == 6:
1b1c914f 425 id = self.ids[1] if self.manufacturer_id_first else self.ids[0]
db188228 426 self.device_id = id
de22de7f
UH
427 self.es_cmd = self.es
428 self.putc([Ann.REMS, self.cmd_vendor_dev_list()])
4772a846 429 self.state = None
1b1c914f
UH
430 else:
431 self.cmdstate += 1
432
b54936a9
UH
433 def handle_rems2(self, mosi, miso):
434 pass # TODO
e4022299 435
b54936a9
UH
436 def handle_enso(self, mosi, miso):
437 pass # TODO
e4022299 438
b54936a9
UH
439 def handle_exso(self, mosi, miso):
440 pass # TODO
e4022299 441
b54936a9
UH
442 def handle_rdscur(self, mosi, miso):
443 pass # TODO
e4022299 444
b54936a9
UH
445 def handle_wrscur(self, mosi, miso):
446 pass # TODO
e4022299 447
b54936a9
UH
448 def handle_esry(self, mosi, miso):
449 pass # TODO
1b1c914f 450
b54936a9
UH
451 def handle_dsry(self, mosi, miso):
452 pass # TODO
5ebb76fe 453
de22de7f 454 def output_data_block(self, label, idx):
2c920167
AG
455 # Print accumulated block of data
456 # (called on CS# de-assert via self.on_end_transaction callback).
de22de7f 457 self.es_cmd = self.es # End on the CS# de-assert sample.
b33a73bc
UH
458 if self.options['format'] == 'hex':
459 s = ' '.join([('%02x' % b) for b in self.data])
460 else:
461 s = ''.join(map(chr, self.data))
de22de7f
UH
462 self.putf([Ann.FIELD, ['%s (%d bytes)' % (label, len(self.data))]])
463 self.putc([idx, ['%s (addr 0x%06x, %d bytes): %s' % \
464 (cmds[self.state][1], self.addr, len(self.data), s)]])
1b1c914f 465
2c920167 466 def decode(self, ss, es, data):
9b4d8a57 467 ptype, mosi, miso = data
1b1c914f 468
2c920167 469 self.ss, self.es = ss, es
e4022299 470
2c920167
AG
471 if ptype == 'CS-CHANGE':
472 self.end_current_transaction()
e4022299 473
3e3c0330 474 if ptype != 'DATA':
9b4d8a57 475 return
1b1c914f 476
9b4d8a57 477 # If we encountered a known chip command, enter the resp. state.
35b380b1 478 if self.state is None:
781ef945
UH
479 self.state = mosi
480 self.cmdstate = 1
1b1c914f 481
9b4d8a57 482 # Handle commands.
1ec9c5e2
AG
483 try:
484 self.cmd_handlers[self.state](mosi, miso)
485 except KeyError:
1be94d3d 486 self.putx([Ann.BIT, ['Unknown command: 0x%02x' % mosi]])
4772a846 487 self.state = None