Skip to content

Commit

Permalink
phaser/LEDs: add global getter and individual getter/setter helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
airwoodix committed Mar 7, 2022
1 parent 17ecd35 commit 3b6880a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Highlights:
- Expose the DAC coarse mixer and ``sif_sync``
- Exposes upconverter calibration and enabling/disabling of upconverter LO & RF outputs.
- Add helpers to align Phaser updates to the RTIO timeline (``get_next_frame_mu()``)
- Add helpers to manipulate front panel LEDs
* ``get()``, ``get_mu()``, ``get_att()``, and ``get_att_mu()`` functions added for AD9910 and AD9912
* On Kasli, the number of FIFO lanes in the scalable events dispatcher (SED) can now be configured in
the JSON hardware description file.
Expand Down
43 changes: 42 additions & 1 deletion artiq/coredevice/phaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from artiq.language.core import kernel, delay_mu, delay
from artiq.coredevice.rtio import rtio_output, rtio_input_data, rtio_input_timestamp
from artiq.language.units import us, ns, ms, MHz
from artiq.language.types import TInt32
from artiq.language.types import TInt32, TBool
from artiq.coredevice.dac34h84 import DAC34H84
from artiq.coredevice.trf372017 import TRF372017

Expand Down Expand Up @@ -408,6 +408,47 @@ def set_leds(self, leds):
"""
self.write8(PHASER_ADDR_LED, leds)

@kernel
def get_leds(self) -> TInt32:
"""Get the state of the front panel LEDs.
This method advances the timeline by 20 µs.
:return: LED settings (6 bit)
"""
state = self.read8(PHASER_ADDR_LED)
delay(20*us) # slack
return state

@kernel
def set_led(self, led: TInt32, on: TBool = True):
"""Set the state of one front panel LED.
:param led: index of the LED to set (0-5)
:param on: whether to turn the LED on or off
"""
if led < 0 or led > 6:
raise ValueError("LED index out of bounds")

state = self.get_leds()
state &= ~(1 << led)
if on:
state |= (1 << led)
self.set_leds(state)

@kernel
def get_led(self, led: TInt32) -> TBool:
"""Get the state of one front panel LED.
:param led: index of the LED to query (0-5)
:return: whether the LED is on
"""
if led < 0 or led > 6:
raise ValueError("LED index out of bounds")

state = self.get_leds()
return bool((state >> led) & 1)

@kernel
def set_fan_mu(self, pwm):
"""Set the fan duty cycle.
Expand Down

0 comments on commit 3b6880a

Please sign in to comment.