]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Code reformat
authorRay Thomson <thomoray@gmail.com>
Sat, 6 Mar 2021 10:50:54 +0000 (21:50 +1100)
committerRay Thomson <thomoray@gmail.com>
Sat, 6 Mar 2021 10:50:54 +0000 (21:50 +1100)
src/adafruit_blinka/board/radxa/rockpi4.py
src/adafruit_blinka/microcontroller/rockchip/PWMOut.py
src/adafruit_blinka/microcontroller/rockchip/rk3399/pin.py
src/analogio.py
src/digitalio.py
src/microcontroller/__init__.py
src/microcontroller/pin.py

index 9afda3098e3c781532d979a7cb66d1570a647f48..e327ff3a176630b7a72868215ad99d69738951dc 100644 (file)
@@ -2,32 +2,32 @@
 
 from adafruit_blinka.microcontroller.rockchip.rk3399 import pin
 
-D3 = pin.GPIO2_A7   #/I2C7_SDA/PIN 71/
-D5 = pin.GPIO2_B0   #/I2C7_SCL/PIN 72/
-D7 = pin.GPIO2_B3   #/SPI2_CLK/PIN 75/
-D8 = pin.GPIO4_C4   #/UART2_TXD/PIN 148/
-D10 = pin.GPIO4_C3  #/UART2_RXD/PIN 147/
-D11 = pin.GPIO4_C2  #/PWM0/PIN 146/
-D13 = pin.GPIO4_C6  #/PWM1/PIN 150/
-D15 = pin.GPIO4_C5  #/SPDIF_TX/PIN 149/
-D16 = pin.GPIO4_D2  #/PIN 154/
-D17 = pin.GPIO4_D4  #/PIN 156/
-D19 = pin.GPIO1_B0  #/UART4_TXD/SPI1_TXD/PIN 40/
-D21 = pin.GPIO1_A7  #/UART4_RXD/SPI1_RXD/PIN 39/
-D22 = pin.GPIO4_D5  #/PIN 157/
-D23 = pin.GPIO1_B1  #/SPI1_CLK/PIN 41/
-D24 = pin.GPIO1_B2  #/SPI1_CS/PIN 42/
-D27 = pin.GPIO2_A0  #/I2C2_SDA/PIN 64/
-D28 = pin.GPIO2_A1  #/I2C2_SCL/PIN 65/
-D29 = pin.GPIO2_B2  #/I2C6_SCL/SPI2_TXD/PIN 74/
-D31 = pin.GPIO2_B1  #/I2C6_SDA/SPI2_RXD/PIN 73/
-D32 = pin.GPIO3_C0  #/SPDIF_TX/UART3_CTS/PIN 112/
-D33 = pin.GPIO2_B4  #/SPI2_CS/PIN 76/
-D35 = pin.GPIO4_A5  #/I2S1_LRCK_TX/PIN 133/
-D36 = pin.GPIO4_A4  #/I2S1_LRCK_RX/PIN 132/
-D37 = pin.GPIO4_D6  #/PIN 158/
-D38 = pin.GPIO4_A6  #/I2S1_SDI/PIN 134/
-D40 = pin.GPIO4_A7  #/I2S1_SDO/PIN 135/
+D3 = pin.GPIO2_A7  /I2C7_SDA/PIN 71/
+D5 = pin.GPIO2_B0  /I2C7_SCL/PIN 72/
+D7 = pin.GPIO2_B3  /SPI2_CLK/PIN 75/
+D8 = pin.GPIO4_C4  /UART2_TXD/PIN 148/
+D10 = pin.GPIO4_C3  # /UART2_RXD/PIN 147/
+D11 = pin.GPIO4_C2  # /PWM0/PIN 146/
+D13 = pin.GPIO4_C6  # /PWM1/PIN 150/
+D15 = pin.GPIO4_C5  # /SPDIF_TX/PIN 149/
+D16 = pin.GPIO4_D2  # /PIN 154/
+D17 = pin.GPIO4_D4  # /PIN 156/
+D19 = pin.GPIO1_B0  # /UART4_TXD/SPI1_TXD/PIN 40/
+D21 = pin.GPIO1_A7  # /UART4_RXD/SPI1_RXD/PIN 39/
+D22 = pin.GPIO4_D5  # /PIN 157/
+D23 = pin.GPIO1_B1  # /SPI1_CLK/PIN 41/
+D24 = pin.GPIO1_B2  # /SPI1_CS/PIN 42/
+D27 = pin.GPIO2_A0  # /I2C2_SDA/PIN 64/
+D28 = pin.GPIO2_A1  # /I2C2_SCL/PIN 65/
+D29 = pin.GPIO2_B2  # /I2C6_SCL/SPI2_TXD/PIN 74/
+D31 = pin.GPIO2_B1  # /I2C6_SDA/SPI2_RXD/PIN 73/
+D32 = pin.GPIO3_C0  # /SPDIF_TX/UART3_CTS/PIN 112/
+D33 = pin.GPIO2_B4  # /SPI2_CS/PIN 76/
+D35 = pin.GPIO4_A5  # /I2S1_LRCK_TX/PIN 133/
+D36 = pin.GPIO4_A4  # /I2S1_LRCK_RX/PIN 132/
+D37 = pin.GPIO4_D6  # /PIN 158/
+D38 = pin.GPIO4_A6  # /I2S1_SDI/PIN 134/
+D40 = pin.GPIO4_A7  # /I2S1_SDO/PIN 135/
 
 SDA2 = D27
 SCL2 = D28
index abff5d1ba5393a6bb65776975fbd746fe068e865..ae0f0aea702977b10d9a4a8726f961b320905e56 100644 (file)
@@ -76,8 +76,12 @@ class PWMOut:
 
         self._pwm = pwm
 
-        self._chip_path = os.path.join(self._sysfs_path, self._chip_path.format(self._chip))
-        self._channel_path = os.path.join(self._chip_path, self._channel_path.format(self._channel))
+        self._chip_path = os.path.join(
+            self._sysfs_path, self._chip_path.format(self._chip)
+        )
+        self._channel_path = os.path.join(
+            self._chip_path, self._channel_path.format(self._channel)
+        )
 
         if not os.path.isdir(self._chip_path):
             raise LookupError("Opening PWM: PWM chip {} not found.".format(self._chip))
@@ -100,18 +104,29 @@ class PWMOut:
                 sleep(PWMOut.PWM_STAT_DELAY)
 
             if not exported:
-                raise TimeoutError("Exporting PWM: waiting for \"{:s}\" timed out.".format(self._channel_path))
+                raise TimeoutError(
+                    'Exporting PWM: waiting for "{:s}" timed out.'.format(
+                        self._channel_path
+                    )
+                )
 
             # Loop until 'period' is writable, This could take some time after
             # export as application of the udev rules after export is asynchronous.
             # Without this loop, the following properties may not be writable yet.
             for i in range(PWMOut.PWM_STAT_RETRIES):
                 try:
-                    with open(os.path.join(self._channel_path, "period"), "w",):
+                    with open(
+                        os.path.join(self._channel_path, "period"),
+                        "w",
+                    ):
                         break
                 except IOError as e:
-                    if e.errno != EACCES or (e.errno == EACCES and i == PWMOut.PWM_STAT_RETRIES - 1):
-                        raise PWMError(e.errno, "Opening PWM period: " + e.strerror) from IOError
+                    if e.errno != EACCES or (
+                        e.errno == EACCES and i == PWMOut.PWM_STAT_RETRIES - 1
+                    ):
+                        raise PWMError(
+                            e.errno, "Opening PWM period: " + e.strerror
+                        ) from IOError
 
                 sleep(PWMOut.PWM_STAT_DELAY)
 
@@ -126,7 +141,9 @@ class PWMOut:
         if self._channel is not None:
             # Unexporting the PWM channel
             try:
-                unexport_fd = os.open(os.path.join(self._chip_path, self._unexport), os.O_WRONLY)
+                unexport_fd = os.open(
+                    os.path.join(self._chip_path, self._unexport), os.O_WRONLY
+                )
                 os.write(unexport_fd, "{:d}\n".format(self._channel).encode())
                 os.close(unexport_fd)
             except OSError as e:
@@ -136,11 +153,11 @@ class PWMOut:
         self._channel = None
 
     def _write_channel_attr(self, attr, value):
-        with open(os.path.join(self._channel_path, attr), 'w') as f_attr:
+        with open(os.path.join(self._channel_path, attr), "w") as f_attr:
             f_attr.write(value + "\n")
 
     def _read_channel_attr(self, attr):
-        with open(os.path.join(self._channel_path, attr), 'r') as f_attr:
+        with open(os.path.join(self._channel_path, attr), "r") as f_attr:
             return f_attr.read().strip()
 
     # Methods
@@ -216,7 +233,9 @@ class PWMOut:
         try:
             period_ns = int(period_ns)
         except ValueError:
-            raise PWMError(None, "Unknown period value: \"%s\"." % period_ns) from ValueError
+            raise PWMError(
+                None, 'Unknown period value: "%s".' % period_ns
+            ) from ValueError
 
         self._period_ns = period_ns
 
@@ -247,7 +266,9 @@ class PWMOut:
         try:
             duty_cycle_ns = int(duty_cycle_ns_str)
         except ValueError:
-            raise PWMError(None, "Unknown duty cycle value: \"{:s}\"".format(duty_cycle_ns_str))
+            raise PWMError(
+                None, 'Unknown duty cycle value: "{:s}"'.format(duty_cycle_ns_str)
+            )
 
         return duty_cycle_ns
 
@@ -312,7 +333,7 @@ class PWMOut:
         if not isinstance(polarity, str):
             raise TypeError("Invalid polarity type, should be str.")
         elif polarity.lower() not in ["normal", "inversed"]:
-            raise ValueError("Invalid polarity, can be: \"normal\" or \"inversed\".")
+            raise ValueError('Invalid polarity, can be: "normal" or "inversed".')
 
         self._write_channel_attr("polarity", polarity.lower())
 
@@ -333,7 +354,7 @@ class PWMOut:
         elif enabled == "0":
             return False
 
-        raise PWMError(None, "Unknown enabled value: \"{:s}\"".format(enabled))
+        raise PWMError(None, 'Unknown enabled value: "{:s}"'.format(enabled))
 
     def _set_enabled(self, value):
         if not isinstance(value, bool):
@@ -352,5 +373,11 @@ class PWMOut:
     # String representation
 
     def __str__(self):
-        return "PWM {:d}, chip {:d} (period={:f} sec, duty_cycle={:f}%, polarity={:s}, enabled={:s})" \
-            .format(self._channel, self._chip, self.period, self.duty_cycle * 100, self.polarity, str(self.enabled))
\ No newline at end of file
+        return "PWM {:d}, chip {:d} (period={:f} sec, duty_cycle={:f}%, polarity={:s}, enabled={:s})".format(
+            self._channel,
+            self._chip,
+            self.period,
+            self.duty_cycle * 100,
+            self.polarity,
+            str(self.enabled),
+        )
index 0663c759e34dd2b8ce96219c78a7537a41211f8e..44198610675b09a20bfef1922266c76407e3ac0f 100644 (file)
@@ -74,4 +74,4 @@ pwmOuts = (
 )
 
 # SysFS analog inputs, Ordered as analog analogInId, device, and channel
-analogIns = ((ADC_IN0, 0, 0),)
\ No newline at end of file
+analogIns = ((ADC_IN0, 0, 0),)
index 45e2a18d4b6c94ecd5a9acf2a44990c72e2daae1..1db939a3fd93465d4f88cb75bf5ae1c4bc190ef2 100644 (file)
@@ -22,7 +22,7 @@ elif detector.board.greatfet_one:
 elif detector.chip.RK3308:
     from adafruit_blinka.microcontroller.generic_linux.sysfs_analogin import AnalogIn
 elif detector.chip.RK3399:
-    from adafruit_blinka.microcontroller.generic_linux.sysfs_analogin import AnalogIn    
+    from adafruit_blinka.microcontroller.generic_linux.sysfs_analogin import AnalogIn
 elif detector.chip.IMX6ULL:
     from adafruit_blinka.microcontroller.generic_linux.sysfs_analogin import AnalogIn
 elif "sphinx" in sys.modules:
index 328600030bdd6f60933de6d2076a526eca5777fb..a59866b9a74eb10270f775983156f22da5ae9a73 100755 (executable)
@@ -52,7 +52,7 @@ elif detector.chip.MIPS24KEC:
 elif detector.chip.RK3308:
     from adafruit_blinka.microcontroller.rockchip.rk3308.pin import Pin
 elif detector.chip.RK3399:
-    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import Pin    
+    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import Pin
 elif detector.board.ftdi_ft232h:
     from adafruit_blinka.microcontroller.ft232h.pin import Pin
 elif detector.board.binho_nova:
index ec909316e1dbe67ce50de69f4b3595930cf25646..ba99896951e736ff12b98ae38f3bedadaba053ea 100755 (executable)
@@ -69,7 +69,7 @@ elif chip_id == ap_chip.A33:
 elif chip_id == ap_chip.RK3308:
     from adafruit_blinka.microcontroller.rockchip.rk3308.pin import *
 elif chip_id == ap_chip.RK3399:
-    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import *    
+    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import *
 elif chip_id == ap_chip.H5:
     from adafruit_blinka.microcontroller.allwinner.h5.pin import *
 elif chip_id == ap_chip.IMX8MX:
index faeaeb702999ac44f0938b9f58c17a097da91bf1..f83162f8ac05f8913c22fad6aadbee2f5ea187a6 100755 (executable)
@@ -57,7 +57,7 @@ elif chip_id == ap_chip.A33:
 elif chip_id == ap_chip.RK3308:
     from adafruit_blinka.microcontroller.rockchip.rk3308.pin import *
 elif chip_id == ap_chip.RK3399:
-    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import *    
+    from adafruit_blinka.microcontroller.rockchip.rk3399.pin import *
 elif chip_id == ap_chip.MIPS24KC:
     from adafruit_blinka.microcontroller.atheros.ar9331.pin import *
 elif chip_id == ap_chip.MIPS24KEC: