@@ -336,13 +336,14 @@ def write(self, dadr, madr, data, addr_bytes=1):
336
336
int madr : Memory address within device ('addr_bytes' long)
337
337
[int] data : Data to write (List of byte-sized ints)
338
338
int addr_bytes : Size in bytes of memory address (1 or 2)
339
- Returns: None
339
+ Returns: program instructions
340
340
"""
341
341
if madr is None :
342
342
addr_bytes = 0
343
- self ._program += super ().write (dadr , madr , data , addr_bytes = addr_bytes )
343
+ pval = super ().write (dadr , madr , data , addr_bytes = addr_bytes )
344
+ self ._program += pval
344
345
self ._check_pc ()
345
- return None
346
+ return pval
346
347
347
348
def read (self , dadr , madr , dlen , addr_bytes = 1 , reg_name = None ):
348
349
"""Add an I2C read transaction to the program.
@@ -353,24 +354,27 @@ def read(self, dadr, madr, dlen, addr_bytes=1, reg_name=None):
353
354
int addr_bytes : Size in bytes of memory address (1 or 2)
354
355
str reg_name : A name to associate with result memory address
355
356
Returns: Starting memory offset of result
357
+ NOPE! Returns: program instructions
356
358
"""
357
359
if madr is None :
358
360
addr_bytes = 0
359
- self ._program += super ().read (dadr , madr , dlen , addr_bytes = addr_bytes )
361
+ pval = super ().read (dadr , madr , dlen , addr_bytes = addr_bytes )
362
+ self ._program += pval
360
363
self ._check_pc ()
361
364
if reg_name is None :
362
365
reg_name = self ._mkRegName (dadr , madr , self ._rc )
363
366
self ._memdict [reg_name ] = (self ._rc , dlen )
364
367
self ._rc += dlen
365
368
self ._check_rc ()
366
- return self . _rc
369
+ return pval
367
370
368
371
def pause (self , n ):
369
372
"""Add a pause of 'n' ticks to the program
370
373
See README.md for discussion of tick length."""
371
- self ._program += super ().pause (n )
374
+ pval = super ().pause (n )
375
+ self ._program += pval
372
376
self ._check_pc ()
373
- return
377
+ return pval
374
378
375
379
def jump (self , n ):
376
380
"""Add a jump instruction to program counter n*32
@@ -387,9 +391,10 @@ def jump(self, n):
387
391
"Jump would result in 'jump here' instruction"
388
392
+ "(a jump to the program counter value of the jump instruction)."
389
393
)
390
- self ._program += super ().jump (n )
394
+ pval = super ().jump (n )
395
+ self ._program += pval
391
396
self ._check_pc ()
392
- return
397
+ return pval
393
398
394
399
def jump_address (self , address ):
395
400
"""Add a jump instruction to program counter 'address'
@@ -475,11 +480,12 @@ def set_resx(self, n=None):
475
480
if n is None :
476
481
n = (self ._rc // 32 ) + 1 # ceil(rc/32)
477
482
n = int (n )
478
- self ._program += super ().set_resx (n )
483
+ pval = super ().set_resx (n )
484
+ self ._program += pval
479
485
self ._check_pc ()
480
486
self ._rc = 32 * n
481
487
self ._check_rc () # This should be redundant but certainly can't hurt
482
- return
488
+ return pval
483
489
484
490
def set_resx_address (self , address = None ):
485
491
"""Add a set result address pointer instruction to program.
@@ -505,33 +511,48 @@ def set_resx_address(self, address=None):
505
511
506
512
def buffer_flip (self ):
507
513
"""Add a buffer flip instruction to the program."""
508
- self ._program += super ().buffer_flip ()
514
+ pval = super ().buffer_flip ()
515
+ self ._program += pval
509
516
self ._check_pc ()
510
- return
517
+ return pval
511
518
512
519
def trig_analyz (self ):
513
520
"""Add an analyzer trigger instruction to the program."""
514
- self ._program += super ().trig_analyz ()
521
+ pval = super ().trig_analyz ()
522
+ self ._program += pval
515
523
self ._check_pc ()
516
- return
524
+ return pval
517
525
518
526
def hw_config (self , n ):
519
527
"""Add a hw_config set instruction to the program.
520
528
Params:
521
529
int n : 4-bit mask of hw_config outputs of module i2c_chunk"""
522
- self ._program += super ().hw_config (n )
530
+ pval = super ().hw_config (n )
531
+ self ._program += pval
523
532
self ._check_pc ()
524
- return
533
+ return pval
525
534
526
- def pad (self , n = None ):
535
+ def pad (self , * args , ** kwargs ):
527
536
"""Pad program memory up to location 32*n. Typically used to pad program
528
537
to a location you can jump to. Consider using jump_pad() for this purpose.
529
538
Params:
530
539
int n : Integer multiple of 32 to pad to.
531
540
Gotchas:
532
541
32*n must be > current program counter. Use with no arg (n=None) to avoid
533
542
this pitfall (pads up to next nearest multiple of 32).
534
- Returns: program counter index (pc/32) after pad"""
543
+ Returns: program counter index (pc/32) after pad
544
+ NOTE! To allow drop-in compatibility, this function also operates using the
545
+ same interface as i2c_assem.pad(n, length). When used in this way, it returns
546
+ a list of program instructions - the same as the old-style usage."""
547
+ if len (args ) == 2 :
548
+ # Hack to preserve API of parent class
549
+ n = args [0 ]
550
+ current_pc = args [1 ]
551
+ return super ().pad (n , current_pc )
552
+ elif len (args ) == 1 :
553
+ n = args [0 ]
554
+ if 'n' in kwargs .keys ():
555
+ n = kwargs .get ('n' )
535
556
if n is None :
536
557
n = (self ._pc () // 32 ) + 1 # ceil(pc/32)
537
558
n = int (n )
@@ -544,7 +565,8 @@ def pad(self, n=None):
544
565
raise I2C_Assembler_Exception (
545
566
f"Program counter index { n } exceeds maximum { self ._INDEX_MAX } "
546
567
)
547
- self ._program += super ().pad (n , self ._pc ())
568
+ pval = super ().pad (n , self ._pc ())
569
+ self ._program += pval
548
570
self ._check_pc ()
549
571
return self ._pc () // 32
550
572
0 commit comments