From 80903cead78f29a91826ba568d4bb7a452434b7f Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 21 Mar 2018 08:22:48 +0000 Subject: [PATCH] novogorny: streamline gain setting method, style [nfc] --- artiq/coredevice/novogorny.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/artiq/coredevice/novogorny.py b/artiq/coredevice/novogorny.py index ae8b59d21..6fa879eb1 100644 --- a/artiq/coredevice/novogorny.py +++ b/artiq/coredevice/novogorny.py @@ -1,4 +1,3 @@ - from artiq.language.core import kernel, delay, portable from artiq.language.units import ns @@ -6,9 +5,9 @@ from artiq.coredevice import spi2 as spi SPI_CONFIG = (0*spi.SPI_OFFLINE | 0*spi.SPI_END | - 0*spi.SPI_INPUT | 0*spi.SPI_CS_POLARITY | - 0*spi.SPI_CLK_POLARITY | 0*spi.SPI_CLK_PHASE | - 0*spi.SPI_LSB_FIRST | 0*spi.SPI_HALF_DUPLEX) + 0*spi.SPI_INPUT | 0*spi.SPI_CS_POLARITY | + 0*spi.SPI_CLK_POLARITY | 0*spi.SPI_CLK_PHASE | + 0*spi.SPI_LSB_FIRST | 0*spi.SPI_HALF_DUPLEX) SPI_CS_ADC = 1 @@ -75,7 +74,7 @@ class Novogorny: kernel_invariants = {"bus", "core", "conv", "div", "v_ref"} def __init__(self, dmgr, spi_device, conv_device, div=8, - core_device="core"): + core_device="core"): self.bus = dmgr.get(spi_device) self.core = dmgr.get(core_device) self.conv = dmgr.get(conv_device) @@ -93,11 +92,13 @@ class Novogorny: :param channel: Channel index :param gain: Gain setting """ - self.gains &= ~(0b11 << (channel*2)) - self.gains |= gain << (channel*2) + gains = self.gains + gains &= ~(0b11 << (channel*2)) + gains |= gain << (channel*2) self.bus.set_config_mu(SPI_CONFIG | spi.SPI_END, 16, self.div, SPI_CS_SR) - self.bus.write(self.gains << 16) + self.bus.write(gains << 16) + self.gains = gains @kernel def configure(self, data):