I was wondering if it's possible to get some inline assembly to work in a callback. I'd like to toggle a GPIO line.
I read in the documentation that an instance of object creation occurs when a reference to a bound method is created. So i am trying a few of the work around methods. The "test" function below does work if i pass the reference to the ISR. But it's tricky for the assembler function since arguments must be named r0, r1 etc. Any ideas if something like this can work? Thanks!
Code: Select all
class Motor(object):
"""
Motor class
timers run at 2mHz
"""
def __init__(self, name, timer_num, pin_id, mdir=0, steps=0):
self.name = name
self.steps = steps
self.motor_step_ref=self.motor_step
self.timer_num = timer_num
self.pin_id = pin_id
self.mdir = mdir
@micropython.asm_thumb
def motor_step():
movwt(r0, stm.GPIOA)
movw(r1, 1 << 6)
strh(r1, [r0, stm.GPIO_BSRRL])
movwt(r4, 30)
label(delay_off)
sub(r4, r4, 1)
cmp(r4, 0)
bgt(delay_off)
strh(r1, [r0, stm.GPIO_BSRRH])
motortim = pyb.Timer(timer_num, prescaler = 41, period = 15000)
motortim.callback(self.cb)
def test(self, _):
self.pin_id.high()
self.pin_id.low()
@micropython.asm_thumb
def motor_step():
movwt(r0, stm.GPIOA)
movw(r1, 1 << 6)
strh(r1, [r0, stm.GPIO_BSRRL])
movwt(r4, 30)
label(delay_off)
sub(r4, r4, 1)
cmp(r4, 0)
bgt(delay_off)
strh(r1, [r0, stm.GPIO_BSRRH])
def speed_change(self, motperiod):
pyb.Timer(self.timer_num, prescaler = 41, period = motperiod)
def cb(self, tim):
if self.mdir != 0:
self.motor_step()
def dir_change(self,_dir):
self.mdir = _dir