From dd998c8afc6d9556c4f6a230a9f922092a59f1b8 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 25 Sep 2021 14:17:11 +0800 Subject: [PATCH] nac3embedded: RTIO LED blinking demo --- nac3embedded/demo.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/nac3embedded/demo.py b/nac3embedded/demo.py index a55817839..4d784f1f8 100644 --- a/nac3embedded/demo.py +++ b/nac3embedded/demo.py @@ -54,15 +54,50 @@ class Core: if now_mu() < min_now: at_mu(min_now) +@kernel +class TTLOut: + channel: int32 + target_o: int32 + + @kernel + def __init__(self, channel: int32): + self.channel = channel + self.target_o = channel << 8 + + @kernel + def output(self): + pass + + @kernel + def set_o(self, o: bool): + rtio_output(self.target_o, 1 if o else 0) + + @kernel + def on(self): + self.set_o(True) + + @kernel + def off(self): + self.set_o(False) + + @kernel + def pulse_mu(self, duration: int64): + self.on() + delay_mu(duration) + self.off() + @kernel class Demo: @kernel def run(self): core = Core() + led = TTLOut(0) core.reset() - rtio_init() + while True: + led.pulse_mu(int64(100000000)) + delay_mu(int64(100000000)) if __name__ == "__main__":