X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/ad60894608702cae48932dce189445f976aef126..c2bc4a90827f28abb6b51eae659a1f80a65c0497:/src/adafruit_blinka/microcontroller/starfive/JH7110/pwmio/PWMOut.py diff --git a/src/adafruit_blinka/microcontroller/starfive/JH7110/pwmio/PWMOut.py b/src/adafruit_blinka/microcontroller/starfive/JH7110/pwmio/PWMOut.py index 34e494a..efd1d40 100644 --- a/src/adafruit_blinka/microcontroller/starfive/JH7110/pwmio/PWMOut.py +++ b/src/adafruit_blinka/microcontroller/starfive/JH7110/pwmio/PWMOut.py @@ -1,11 +1,12 @@ -# SPDX-FileCopyrightText: 2024 Vladimir Shtarev +# SPDX-FileCopyrightText: 2024 Vladimir Shtarev, Jetbrains Research # # SPDX-License-Identifier: MIT """Custom PWMOut Wrapper for VisionFive.GPIO PWM Class""" import VisionFive.gpio as GPIO -GPIO.setmode(GPIO.Board) +GPIO.setmode(GPIO.BOARD) +GPIO.setwarnings(False) # pylint: disable=unnecessary-pass @@ -86,27 +87,26 @@ class PWMOut: @property def duty_cycle(self): """Get or set the PWM's output duty cycle which is the fraction of - each pulse which is high. + each pulse which is high. 16-bit Raises: PWMError: if an I/O or OS error occurs. TypeError: if value type is not int or float. - ValueError: if value is out of bounds of 0.0 to 100.0. + ValueError: if value is out of bounds of 0.0 to 1.0. :type: int, float """ - return int(self._duty_cycle) + return int(self._duty_cycle * 65535) @duty_cycle.setter def duty_cycle(self, duty_cycle): if not isinstance(duty_cycle, (int, float)): raise TypeError("Invalid duty cycle type, should be int or float.") - if not 0 <= duty_cycle <= 100: - raise ValueError( - "Invalid duty cycle value, should be between 0.0 and 100.0" - ) + if not 0 <= duty_cycle <= 65535: + raise ValueError("Invalid duty cycle value, should be between 0 and 65535") + duty_cycle = duty_cycle / 655.35 self._duty_cycle = duty_cycle self._pwmpin.ChangeDutyCycle(round(self._duty_cycle))