From: Melissa LeBlanc-Williams Date: Tue, 4 Jun 2019 23:59:18 +0000 (-0700) Subject: Merge branch 'master' of https://github.com/adafruit/Adafruit_Blinka X-Git-Tag: 2.1.0^2~3 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/0de62bd1a61c0d22622c372bd7a44b4bdc779071?hp=9691d8101fef1e55afa3f78f6d9480256aa3b6be Merge branch 'master' of https://github.com/adafruit/Adafruit_Blinka --- diff --git a/src/adafruit_blinka/microcontroller/generic_linux/spi.py b/src/adafruit_blinka/microcontroller/generic_linux/spi.py index 9ef05fc..ef442b1 100755 --- a/src/adafruit_blinka/microcontroller/generic_linux/spi.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/spi.py @@ -35,7 +35,7 @@ class SPI: def set_no_cs(self): # Linux SPI driver for AM33XX chip in BeagleBone and PocketBeagle # does not support setting SPI_NO_CS mode bit (issue #104) - if not self.chip.AM33XX and not self.chip.IMX8MX: + if not self.chip.AM33XX and not self.chip.IMX8MX and not self.chip.SAMA5: try: self._spi.no_cs = True # this doesn't work but try anyways except AttributeError: diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py index 6266fbb..d0686f7 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py @@ -55,13 +55,13 @@ class PWMOut(object): self._open(pin, duty_cycle, frequency, variable_frequency) def __del__(self): - self.close() + self.deinit() def __enter__(self): return self def __exit__(self, t, value, traceback): - self.close() + self.deinit() def _open(self, pin, duty=0, freq=500, variable_frequency=False): self._channel = None @@ -90,12 +90,12 @@ class PWMOut(object): except IOError as e: raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) - self._set_enabled(False) - + #self._set_enabled(False) # This line causes a write error when trying to enable + # Look up the period, for fast duty cycle updates self._period = self._get_period() - self.duty_cycle = 0 + #self.duty_cycle = 0 # This line causes a write error when trying to enable # set frequency self.frequency = freq @@ -104,8 +104,8 @@ class PWMOut(object): self._set_enabled(True) - def close(self): - """Close the sysfs PWM.""" + def deinit(self): + """Deinit the sysfs PWM.""" if self._channel is not None: self.duty_cycle = 0 try: @@ -118,7 +118,15 @@ class PWMOut(object): self._channel = None self._pwmpin = None + def _is_deinited(self): + if self._pwmpin is None: + raise ValueError("Object has been deinitialize and can no longer " + "be used. Create a new object.") + def _write_pin_attr(self, attr, value): + # Make sure the pin is active + self._is_deinited() + path = os.path.join( self._sysfs_path, self._channel_path.format(self._channel), @@ -128,8 +136,11 @@ class PWMOut(object): with open(path, 'w') as f_attr: #print(value, path) f_attr.write(value + "\n") - + def _read_pin_attr(self, attr): + # Make sure the pin is active + self._is_deinited() + path = os.path.join( self._sysfs_path, self._channel_path.format(self._channel), @@ -142,8 +153,9 @@ class PWMOut(object): # Mutable properties def _get_period(self): + period_ns = self._read_pin_attr(self._pin_period_path) try: - period_ns = int(self._read_pin_attr(self._pin_period_path)) + period_ns = int(period_ns) except ValueError: raise PWMError(None, "Unknown period value: \"%s\"" % period_ns) @@ -177,8 +189,9 @@ class PWMOut(object): """ def _get_duty_cycle(self): + duty_cycle_ns = self._read_pin_attr(self._pin_duty_cycle_path) try: - duty_cycle_ns = int(self._read_pin_attr(self._pin_duty_cycle_path)) + duty_cycle_ns = int(duty_cycle_ns) except ValueError: raise PWMError(None, "Unknown duty cycle value: \"%s\"" % duty_cycle_ns)