Skip to content

Commit

Permalink
Fix acq427 to work on Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Jan 31, 2020
1 parent 8144168 commit 8781464
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/fmc_acq427/extensions/fmc_acq427.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Extension module to support FMC ADC427
from .fmc_acq427 import Extension
from i2c import smbus2

# The mapping of GPIO bits is as follows:
Expand Down Expand Up @@ -54,31 +53,33 @@ def write_config_bits(self, bits):
def write_output_bits(self, bits):
self.bus.write_i2c_block_data(0x22, 0x84, bits)

def read_bit(self, (byte_ix, offset)):
def read_bit(self, byte_ix, offset):
bits = self.read_input_bits()
return bool(bits[byte_ix] & (1 << offset))

def write_bits(self, (byte_ix, offset, width), value):
def write_bits(self, value, byte_ix, offset, width):
mask = ((1 << width) - 1) << offset
value = (value << offset) & mask
self.outputs[byte_ix] = (self.outputs[byte_ix] & ~mask) | value
self.write_output_bits(self.outputs)


class BitReader:
def __init__(self, gpio, offset):
self.gpio = gpio
self.offset = offset

def read(self, number):
return self.gpio.read_bit(self.offset)
return self.gpio.read_bit(*self.offset)


class BitsWriter:
def __init__(self, gpio, offset):
self.gpio = gpio
self.offset = offset

def write(self, number, value):
self.gpio.write_bits(self.offset, value)
self.gpio.write_bits(value, *self.offset)


# We need a single GPIO controller shared between the ADC and DAC extensions.
Expand Down

0 comments on commit 8781464

Please sign in to comment.