]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/rockchip/PWMOut.py
Merge pull request #835 from hajimef/develop
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / rockchip / PWMOut.py
index 09c4a8e2bb3ed62c7a607de28b51f8e8bdad1114..1e5d6e479c28ff21bc42f8d02cc4945a048e3685 100644 (file)
@@ -1,3 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """
 Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/pwm.py
 Copyright (c) 2015-2016 vsergeev / Ivan (Vanya) A. Sergeev
 """
 Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/pwm.py
 Copyright (c) 2015-2016 vsergeev / Ivan (Vanya) A. Sergeev
@@ -91,7 +94,9 @@ class PWMOut:
         if not os.path.isdir(self._channel_path):
             # Exporting the PWM.
             try:
         if not os.path.isdir(self._channel_path):
             # Exporting the PWM.
             try:
-                with open(os.path.join(self._chip_path, "export"), "w") as f_export:
+                with open(
+                    os.path.join(self._chip_path, "export"), "w", encoding="utf-8"
+                ) as f_export:
                     f_export.write("{:d}\n".format(self._channel))
             except IOError as e:
                 raise PWMError(
                     f_export.write("{:d}\n".format(self._channel))
             except IOError as e:
                 raise PWMError(
@@ -122,6 +127,7 @@ class PWMOut:
                     with open(
                         os.path.join(self._channel_path, "period"),
                         "w",
                     with open(
                         os.path.join(self._channel_path, "period"),
                         "w",
+                        encoding="utf-8",
                     ):
                         break
                 except IOError as e:
                     ):
                         break
                 except IOError as e:
@@ -136,6 +142,8 @@ class PWMOut:
 
             self.frequency = frequency
             self.duty_cycle = duty_cycle
 
             self.frequency = frequency
             self.duty_cycle = duty_cycle
+            self.polarity = "normal"
+            self.enable()
 
             # Cache the period for fast duty cycle updates
             self._period_ns = self._get_period_ns()
 
             # Cache the period for fast duty cycle updates
             self._period_ns = self._get_period_ns()
@@ -157,11 +165,15 @@ class PWMOut:
         self._channel = None
 
     def _write_channel_attr(self, attr, value):
         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", encoding="utf-8"
+        ) as f_attr:
             f_attr.write(value + "\n")
 
     def _read_channel_attr(self, 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", encoding="utf-8"
+        ) as f_attr:
             return f_attr.read().strip()
 
     # Methods
             return f_attr.read().strip()
 
     # Methods