1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   4 """PWMOut Class for RP2040s with u2if"""
 
   5 from .rp2040_u2if import rp2040_u2if
 
   9     """Base Pulse Width Modulation Output Class"""
 
  11     def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
 
  12         rp2040_u2if.pwm_configure(
 
  15             duty_cycle=duty_cycle,
 
  16             variable_frequency=variable_frequency,
 
  27     def __exit__(self, t, value, traceback):
 
  32         rp2040_u2if.pwm_deinit(self._pin)
 
  36         """The PWM's output duty cycle, 16-bit."""
 
  37         return rp2040_u2if.pwm_get_duty_cycle(self._pin)
 
  40     def duty_cycle(self, duty_cycle):
 
  41         rp2040_u2if.pwm_set_duty_cycle(self._pin, duty_cycle)
 
  45         """The PWM's output frequency in Hertz."""
 
  46         return rp2040_u2if.pwm_get_frequency(self._pin)
 
  49     def frequency(self, frequency):
 
  50         rp2040_u2if.pwm_set_frequency(self._pin, frequency)