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"
@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)

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
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

View File

@ -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():