Skip to content

Commit 651192b

Browse files
authored
Add files via upload
lgpio native changes
1 parent 491b424 commit 651192b

File tree

1 file changed

+16
-16
lines changed
  • src/adafruit_blinka/microcontroller/bcm283x/pwmio

1 file changed

+16
-16
lines changed

src/adafruit_blinka/microcontroller/bcm283x/pwmio/PWMOut.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
""" PWMOut Class for lgpio lg library tx_pwm library """
77

88
import lgpio
9-
import board # need board to get access to the CHIP object in the pin module
9+
import board # need board to get access to the CHIP object in the pin module
10+
1011

1112
# pylint: disable=unnecessary-pass
1213
class PWMError(IOError):
@@ -18,16 +19,16 @@ class PWMError(IOError):
1819
# pylint: enable=unnecessary-pass
1920

2021

21-
class PWMOut: # pylint: disable=invalid-name
22+
class PWMOut: # pylint: disable=invalid-name
2223
"""Pulse Width Modulation Output Class"""
2324

24-
def __init__(self, pin, *, frequency=500, duty_cycle=0,
25-
variable_frequency=False):
25+
def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
2626
if variable_frequency:
2727
print("Variable Frequency is not supported, ignoring...")
2828
self._pin = pin
29-
result = lgpio.gpio_claim_output(board.pin.CHIP, self._pin.id,
30-
lFlags=lgpio.SET_PULL_NONE)
29+
result = lgpio.gpio_claim_output(
30+
board.pin.CHIP, self._pin.id, lFlags=lgpio.SET_PULL_NONE
31+
)
3132
if result < 0:
3233
raise RuntimeError(lgpio.error_text(result))
3334
self._enabled = False
@@ -52,12 +53,11 @@ def deinit(self):
5253
"""Deinit the PWM."""
5354
if not self._deinited:
5455
if self.enabled:
55-
self._enabled = False # turn off the pwm
56+
self._enabled = False # turn off the pwm
5657
self._deinited = True
5758

58-
5959
def _is_deinited(self):
60-
""" raise Value error if the object has been de-inited """
60+
"""raise Value error if the object has been de-inited"""
6161
if self._deinited:
6262
raise ValueError(
6363
"Object has been deinitialize and can no longer "
@@ -103,15 +103,14 @@ def duty_cycle(self, duty_cycle):
103103
raise TypeError("Invalid duty cycle type, should be int or float.")
104104

105105
if not 0 <= duty_cycle <= 65535:
106-
raise ValueError(
107-
"Invalid duty cycle value, should be between 0 and 65535")
106+
raise ValueError("Invalid duty cycle value, should be between 0 and 65535")
108107

109108
# convert from 16-bit
110109
duty_cycle /= 65535.0
111110

112111
self._duty_cycle = duty_cycle
113112
if self._enabled:
114-
self.enabled = True # turn on with new values
113+
self.enabled = True # turn on with new values
115114

116115
@property
117116
def frequency(self):
@@ -133,7 +132,7 @@ def frequency(self, frequency):
133132

134133
self._frequency = frequency
135134
if self.enabled:
136-
self.enabled = True # turn on with new values
135+
self.enabled = True # turn on with new values
137136

138137
@property
139138
def enabled(self):
@@ -160,8 +159,9 @@ def enabled(self, value):
160159
raise RuntimeError(lgpio.error_text(result))
161160
return result
162161

163-
164162
# String representation
165163
def __str__(self):
166-
return (f"pin {self._pin} (freq={self.frequency:f} Hz, duty_cycle="
167-
f"{self.duty_cycle}({round(self.duty_cycle / 655.35)}%)")
164+
return (
165+
f"pin {self._pin} (freq={self.frequency:f} Hz, duty_cycle="
166+
f"{self.duty_cycle}({round(self.duty_cycle / 655.35)}%)"
167+
)

0 commit comments

Comments
 (0)