2828"""
2929
3030class PWMOut ():
31- ESP32_PWM_PINS = set ([0 , 1 , 2 , 4 , 5 ,
32- 12 , 13 , 14 , 15 ,
33- 16 , 17 , 18 , 19 ,
34- 21 , 22 , 23 , 25 ,
35- 26 , 27 , 32 , 33 ])
3631 """
3732 Implementation of CircuitPython PWMOut for ESP32SPI.
3833
@@ -42,19 +37,24 @@ class PWMOut():
4237 :param int frequency: The target frequency in Hertz (32-bit).
4338 :param bool variable_frequency: True if the frequency will change over time.
4439 """
40+ ESP32_PWM_PINS = set ([0 , 1 , 2 , 4 , 5 ,
41+ 12 , 13 , 14 , 15 ,
42+ 16 , 17 , 18 , 19 ,
43+ 21 , 22 , 23 , 25 ,
44+ 26 , 27 , 32 , 33 ])
4545 def __init__ (self , esp , pwm_pin , * , frequency = 500 , duty_cycle = 0 , variable_frequency = False ):
4646 if pwm_pin in self .ESP32_PWM_PINS :
4747 self ._pwm_pin = pwm_pin
4848 else :
49- raise AttributeError ("Pin %d is not a valid ESP32 GPIO Pin." % esp_pin )
49+ raise AttributeError ("Pin %d is not a valid ESP32 GPIO Pin." % pwm_pin )
5050 self ._esp = esp
5151 self ._duty_cycle = duty_cycle
5252 self ._freq = frequency
5353 self ._var_freq = variable_frequency
5454
5555 def __enter__ (self ):
5656 return self
57-
57+
5858 def __exit__ (self , exc_type , exc_value , exc_traceback ):
5959 self .deinit ()
6060
@@ -63,7 +63,7 @@ def deinit(self):
6363 self ._duty_cycle = 0
6464 self ._freq = 0
6565 self ._pwm_pin = None
66-
66+
6767 def _is_deinited (self ):
6868 if self ._pwm_pin is None :
6969 raise ValueError ("PWMOut Object has been deinitialized and can no longer "
@@ -75,7 +75,7 @@ def duty_cycle(self):
7575 ratio from 0.0 to 1.0."""
7676 self ._is_deinited ()
7777 return self ._duty_cycle
78-
78+
7979 @duty_cycle .setter
8080 def duty_cycle (self , duty_cycle ):
8181 """Sets the PWMOut duty cycle.
@@ -85,7 +85,7 @@ def duty_cycle(self, duty_cycle):
8585 self ._is_deinited ()
8686 if not isinstance (duty_cycle , (int , float )):
8787 raise TypeError ("Invalid duty_cycle, should be int or float." )
88-
88+
8989 duty_cycle /= 65535.0
9090 if not 0.0 <= duty_cycle <= 1.0 :
9191 raise ValueError ("Invalid duty_cycle, should be between 0.0 and 1.0" )
@@ -96,7 +96,7 @@ def frequency(self):
9696 """Returns the PWMOut object's frequency value."""
9797 self ._is_deinited ()
9898 raise NotImplementedError ("PWMOut Frequency not implemented in ESP32SPI" )
99-
99+
100100 @frequency .setter
101101 def frequency (self , freq ):
102102 """Sets the PWMOut object's frequency value.
@@ -105,5 +105,3 @@ def frequency(self, freq):
105105 """
106106 self ._is_deinited ()
107107 raise NotImplementedError ("PWMOut Frequency not implemented in ESP32SPI" )
108-
109-
0 commit comments