forked from M-Labs/artiq
1
0
Fork 0

coredevice/gpio: replace set() with on()/off() to make API consistent

This commit is contained in:
Sebastien Bourdeauducq 2014-11-19 12:33:33 -08:00
parent 9098d10766
commit 75df0ae94a
3 changed files with 16 additions and 9 deletions

View File

@ -5,5 +5,9 @@ class GPIOOut(AutoContext):
parameters = "channel" parameters = "channel"
@kernel @kernel
def set(self, level): def on(self):
syscall("gpio_set", self.channel, level) syscall("gpio_set", self.channel, 1)
@kernel
def off(self):
syscall("gpio_set", self.channel, 0)

View File

@ -14,7 +14,7 @@ As a very first step, we will turn on a LED on the core device. Create a file ``
@kernel @kernel
def run(self): def run(self):
self.led.set(1) self.led.on()
if __name__ == "__main__": if __name__ == "__main__":
with comm_serial.Comm() as comm: with comm_serial.Comm() as comm:
@ -46,7 +46,10 @@ Modify the code as follows: ::
@kernel @kernel
def run(self): 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: :: 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 @kernel
def run(self): def run(self):
self.led.set(0) self.led.off()
try: try:
for i in range(1000000): for i in range(1000000):
self.o.pulse(...) self.o.pulse(...)
delay(...) delay(...)
except RTIOUnderflow: except RTIOUnderflow:
self.led.set(1) self.led.on()
print_underflow() print_underflow()
Parallel and sequential blocks Parallel and sequential blocks

View File

@ -9,9 +9,9 @@ class DDSTest(AutoContext):
def run(self): def run(self):
for i in range(10000): for i in range(10000):
if i & 0x200: if i & 0x200:
self.led.set(1) self.led.on()
else: else:
self.led.set(0) self.led.off()
with parallel: with parallel:
with sequential: with sequential:
self.a.pulse(100*MHz + 4*i*kHz, 500*us) self.a.pulse(100*MHz + 4*i*kHz, 500*us)
@ -19,7 +19,7 @@ class DDSTest(AutoContext):
with sequential: with sequential:
self.c.pulse(200*MHz, 100*us) self.c.pulse(200*MHz, 100*us)
self.d.pulse(250*MHz, 200*us) self.d.pulse(250*MHz, 200*us)
self.led.set(0) self.led.off()
def main(): def main():