Oliver Fabel 1 год назад
Родитель
Сommit
d9c5f4d8f2
6 измененных файлов с 73 добавлено и 1 удалено
  1. 9 0
      CHANGELOG.md
  2. 3 0
      docs/CHANGELOG.md
  3. 15 0
      docs/pages/reference.rst
  4. 3 0
      docs/pages/roadmap.md
  5. 6 1
      flipperzero/_gpio.py
  6. 37 0
      flipperzero/_pwm.py

+ 9 - 0
CHANGELOG.md

@@ -12,7 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 * Simple ADC support for the `flipperzero` module:
   * Read raw value.
   * Read voltage.
+* Simple PWM support for the `flipperzero` module:
+  * Start a signal.
+  * Stop a signal.
+  * Check the status.
 * Reset used GPIO pins upon script termination.
+* Improved GPIO related functions to prevent user errors.
+
+### Changed
+
+* The GPIO init function `flipperzero.gpio_init_pin` returns a boolean value.
 
 ## [1.2.0] - 2024-09-05
 

+ 3 - 0
docs/CHANGELOG.md

@@ -1,7 +1,10 @@
 ## 1.3
 
 * Added simple ADC support: read value and voltage.
+* Added simple PWM support: start, stop, check status.
+* Added success indicator to GPIO init function.
 * Reset used GPIO pins upon script termination.
+* Improved GPIO related functions to prevent user errors.
 
 ## 1.2
 

+ 15 - 0
docs/pages/reference.rst

@@ -336,6 +336,21 @@ Functions
 .. autofunction:: flipperzero.adc_read_pin_value
 .. autofunction:: flipperzero.adc_read_pin_voltage
 
+PWM
+---
+
+Output a PWM signal on selected GPIO pins:
+
+* :const:`flipperzero.GPIO_PIN_PA4`
+* :const:`flipperzero.GPIO_PIN_PA7`
+
+Functions
+~~~~~~~~~
+
+.. autofunction:: flipperzero.pwm_start
+.. autofunction:: flipperzero.pwm_stop
+.. autofunction:: flipperzero.pwm_is_running
+
 Built-In
 --------
 

+ 3 - 0
docs/pages/roadmap.md

@@ -11,6 +11,9 @@ Here you can see what to expect from future releases.
 ## Planned
 
 * Infrared
+* I2C
+* UART
+* USB HID
 * Subghz
 * Bluetooth
 * ...

+ 6 - 1
flipperzero/_gpio.py

@@ -42,6 +42,7 @@ GPIO_PIN_PA4: int
 '''
 Constant identifier for GPIO pin PA4.
 This pin can be used as ADC input.
+This pin can be used as PWM output.
     
 .. versionadded:: 1.2.0
 '''
@@ -58,6 +59,7 @@ GPIO_PIN_PA7: int
 '''
 Constant identifier for GPIO pin PA7.
 This pin can be used as ADC input.
+This pin can be used as PWM output.
     
 .. versionadded:: 1.2.0
 '''
@@ -153,7 +155,7 @@ Constant configuration value for the GPIO in very high speed.
 .. versionadded:: 1.2.0
 '''
 
-def gpio_init_pin(pin: int, mode: int, pull: int = None, speed: int = None) -> None:
+def gpio_init_pin(pin: int, mode: int, pull: int = None, speed: int = None) -> bool:
     '''
     Initialize a GPIO pin.
 
@@ -161,8 +163,11 @@ def gpio_init_pin(pin: int, mode: int, pull: int = None, speed: int = None) -> N
     :param mode: The mode to use (e.g. :const:`GPIO_MODE_INPUT`).
     :param pull: The pull resistor to use. Default is :const:`GPIO_PULL_NO`.
     :param speed: The speed to use. Default is :const:`GPIO_SPEED_LOW`.
+    :returns: :const:`True` on success, :const:`False` otherwise.
     
     .. versionadded:: 1.2.0
+    .. versionchanged:: 1.3.0
+       The return value changed from ``None`` to ``bool``.
 
     .. hint::
 

+ 37 - 0
flipperzero/_pwm.py

@@ -0,0 +1,37 @@
+def pwm_start(pin: int, frequency: int, duty: int) -> bool:
+    '''
+    Start or change the PWM signal on the corresponding GPIO pin.
+
+    :param pin: The pin to read (e.g. :const:`GPIO_PIN_PA7`).
+    :param frequency: The frequency to set in Hz.
+    :param duty: The duty cycle per period in percent.
+    :returns: :const:`True` on success, :const:`False` otherwise.
+    
+    .. versionadded:: 1.3.0
+
+    .. warning::
+
+        You don't have to initialize the pin first.
+    '''
+    pass
+
+def pwm_stop(pin: int) -> None:
+    '''
+    Stop the PWM signal on the corresponding GPIO pin.
+
+    :param pin: The pin to use (e.g. :const:`GPIO_PIN_PA7`).
+    
+    .. versionadded:: 1.3.0
+    '''
+    pass
+
+def pwm_is_running(pin: int) -> bool:
+    '''
+    Check if the corresponding GPIO pin has a PWM signal output.
+
+    :param pin: The pin to check (e.g. :const:`GPIO_PIN_PA7`).
+    :returns: :const:`True` on success, :const:`False` otherwise.
+    
+    .. versionadded:: 1.3.0
+    '''
+    pass