"""Write data from the buffer to an address"""
if end is None:
end = len(buffer)
- self._gf.i2c.write(address, buffer[start: end])
+ self._gf.i2c.write(address, buffer[start:end])
def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
"""Read data from an address and into the buffer"""
readin = self._gf.i2c.read(address, end - start)
for i in range(end - start):
buffer[i + start] = readin[i]
+
# pylint: enable=unused-argument
def writeto_then_readfrom(
gf = GreatFET()
except:
- raise RuntimeError("Unable to create GreatFET object. Make sure library is installed and the device is connected.")
+ raise RuntimeError(
+ "Unable to create GreatFET object. Make sure library is installed and the device is connected."
+ )
+
class Pin:
"""A basic Pin class for the NXP LPC4330 that acts as a wrapper for the GreatFET api."""
"No action for mode {} with value {}".format(self._mode, val)
)
+
# create pin instances for each pin
# J1 Header Pins
J1_P3 = Pin("J1_P3")
J1_P40 = Pin("J1_P40") # MISO
-
# J2 Header Pins
J2_P3 = Pin("J2_P3")
J2_P4 = Pin("J2_P4")
-J2_P5 = Pin("J2_P5") # ADC, ADC, DAC
+J2_P5 = Pin("J2_P5") # ADC, ADC, DAC
J2_P6 = Pin("J2_P6")
J2_P7 = Pin("J2_P7")
J2_P8 = Pin("J2_P8")
-J2_P9 = Pin("J2_P9") # ADC, GPIO
+J2_P9 = Pin("J2_P9") # ADC, GPIO
J2_P10 = Pin("J2_P10")
J2_P13 = Pin("J2_P13")
J2_P14 = Pin("J2_P14")
# Bonus Row Pins
J7_P2 = Pin("J7_P2")
J7_P3 = Pin("J7_P3")
-J7_P4 = Pin("J7_P4") # ADC, ADC
-J7_P5 = Pin("J7_P5") # ADC, ADC
+J7_P4 = Pin("J7_P4") # ADC, ADC
+J7_P5 = Pin("J7_P5") # ADC, ADC
J7_P6 = Pin("J7_P6")
J7_P7 = Pin("J7_P7")
J7_P8 = Pin("J7_P8")
# pylint: disable=unnecessary-pass
class PWMError(IOError):
"""Base class for PWM errors."""
+
pass
period = property(_get_period, _set_period)
-
def _get_duty_cycle(self):
"""Get or set the PWM's output duty cycle as a ratio from 0.0 to 1.0.
if isinstance(duty_cycle, int):
duty_cycle /= 65535.0
if not 0.0 <= duty_cycle <= 1.0:
- raise ValueError("Invalid duty cycle value, should be between 0.0 and 1.0.")
-
+ raise ValueError("Invalid duty cycle value, should be between 0.0 and 1.0.")
+
# Generate a pattern for 1024 samples of the duty cycle
pattern = [(1 << self._channel)] * round(PWMOut.MAX_CYCLE_LEVEL * duty_cycle)
- pattern += [(0 << self._channel)] * round(PWMOut.MAX_CYCLE_LEVEL * (1.0 - duty_cycle))
-
+ pattern += [(0 << self._channel)] * round(
+ PWMOut.MAX_CYCLE_LEVEL * (1.0 - duty_cycle)
+ )
+
self._pattern = pattern
self._duty_cycle = duty_cycle
if self._enable:
"""SPI Class for NXP LPC4330"""
from greatfet import GreatFET
+
class SPI:
"""Custom I2C Class for NXP LPC4330"""
34000000: (2, 2),
51000000: (2, 1),
102000000: (2, 0),
- }
-
+ }
+
# pylint: disable=too-many-arguments
def init(
self,
polarity = int(polarity)
phase = int(phase)
self._mode = (polarity << 1) | phase
-
+
# Using API due to possible interface change
self._spi = self._gf.apis.spi
# Check baudrate against presets and adjust to the closest one
# Set the polarity and phase (the "SPI mode").
self._spi.set_clock_polarity_and_phase(self._mode)
+
# pylint: enable=too-many-arguments
def _find_closest_preset(self, target_frequency):
closest_preset = None
for frequency in self._presets:
preset = self._presets[frequency]
- if self._frequency is None or abs(frequency - target_frequency) < abs(self._frequency - target_frequency):
+ if self._frequency is None or abs(frequency - target_frequency) < abs(
+ self._frequency - target_frequency
+ ):
self._frequency = frequency
closest_preset = preset
# Transmit our data in chunks of the buffer size.
while data_to_transmit:
# Extract a single data chunk from the transmit buffer.
- chunk = data_to_transmit[0:self.buffer_size]
- del data_to_transmit[0:self.buffer_size]
+ chunk = data_to_transmit[0 : self.buffer_size]
+ del data_to_transmit[0 : self.buffer_size]
# Finally, exchange the data.
response = self._spi.clock_data(len(chunk), bytes(chunk))
from greatfet import GreatFET
from greatfet.interfaces.uart import UART as _UART
+
class UART:
"""Custom UART Class for NXP LPC4330"""
- PARITY_NONE = 0
- PARITY_ODD = 1
- PARITY_EVEN = 2
- PARITY_STUCK_AT_ONE = 3
+ PARITY_NONE = 0
+ PARITY_ODD = 1
+ PARITY_EVEN = 2
+ PARITY_STUCK_AT_ONE = 3
PARITY_STUCK_AT_ZERO = 4
# pylint: disable=too-many-arguments
flow=None,
):
self._gf = GreatFET()
- self._uart = _UART(self._gf, baud=baudrate, data_bits=bits, stop_bits=stop, parity=parity, uart_number=portid)
-
+ self._uart = _UART(
+ self._gf,
+ baud=baudrate,
+ data_bits=bits,
+ stop_bits=stop,
+ parity=parity,
+ uart_number=portid,
+ )
+
if flow is not None: # default None
raise NotImplementedError(
"Parameter '{}' unsupported on GreatFET One".format("flow")