From 75df0ae94a91461c5721b1378dedf9560dbfcb43 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 19 Nov 2014 12:33:33 -0800 Subject: [PATCH] coredevice/gpio: replace set() with on()/off() to make API consistent --- artiq/coredevice/gpio.py | 8 ++++++-- doc/manual/getting_started.rst | 11 +++++++---- examples/dds_test.py | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/artiq/coredevice/gpio.py b/artiq/coredevice/gpio.py index d6622b7a7..125939855 100644 --- a/artiq/coredevice/gpio.py +++ b/artiq/coredevice/gpio.py @@ -5,5 +5,9 @@ class GPIOOut(AutoContext): parameters = "channel" @kernel - def set(self, level): - syscall("gpio_set", self.channel, level) + def on(self): + syscall("gpio_set", self.channel, 1) + + @kernel + def off(self): + syscall("gpio_set", self.channel, 0) diff --git a/doc/manual/getting_started.rst b/doc/manual/getting_started.rst index 364ce1d8e..2a5a0efa3 100644 --- a/doc/manual/getting_started.rst +++ b/doc/manual/getting_started.rst @@ -14,7 +14,7 @@ As a very first step, we will turn on a LED on the core device. Create a file `` @kernel def run(self): - self.led.set(1) + self.led.on() if __name__ == "__main__": with comm_serial.Comm() as comm: @@ -46,7 +46,10 @@ Modify the code as follows: :: @kernel def run(self): - self.led.set(input_led_state()) + if input_led_state(): + self.led.on() + else: + self.led.off() You can then turn the LED off and on by entering 0 or 1 at the prompt that appears: :: @@ -113,13 +116,13 @@ Try reducing the period of the generated waveform until the CPU cannot keep up w @kernel def run(self): - self.led.set(0) + self.led.off() try: for i in range(1000000): self.o.pulse(...) delay(...) except RTIOUnderflow: - self.led.set(1) + self.led.on() print_underflow() Parallel and sequential blocks diff --git a/examples/dds_test.py b/examples/dds_test.py index e09faefe5..9c31e3891 100644 --- a/examples/dds_test.py +++ b/examples/dds_test.py @@ -9,9 +9,9 @@ class DDSTest(AutoContext): def run(self): for i in range(10000): if i & 0x200: - self.led.set(1) + self.led.on() else: - self.led.set(0) + self.led.off() with parallel: with sequential: self.a.pulse(100*MHz + 4*i*kHz, 500*us) @@ -19,7 +19,7 @@ class DDSTest(AutoContext): with sequential: self.c.pulse(200*MHz, 100*us) self.d.pulse(250*MHz, 200*us) - self.led.set(0) + self.led.off() def main():