Selaa lähdekoodia

add gpio docs

Oliver Fabel 1 vuosi sitten
vanhempi
commit
e7b3dd6675
2 muutettua tiedostoa jossa 166 lisäystä ja 1 poistoa
  1. 23 1
      docs/pages/reference.rst
  2. 143 0
      flipperzero/_gpio.py

+ 23 - 1
docs/pages/reference.rst

@@ -205,6 +205,29 @@ Display message dialogs on the display for user infos and confirm actions.
 .. autofunction:: flipperzero.dialog_message_set_button
 .. autofunction:: flipperzero.dialog_message_show
 
+GPIO
+----
+
+Access to the GPIO pins of your Flipper.
+
+.. autodata:: flipperzero.GPIO_PIN_PC0
+.. autodata:: flipperzero.GPIO_PIN_PC1
+.. autodata:: flipperzero.GPIO_PIN_PC3
+.. autodata:: flipperzero.GPIO_PIN_PB2
+.. autodata:: flipperzero.GPIO_PIN_PB3
+.. autodata:: flipperzero.GPIO_PIN_PA4
+.. autodata:: flipperzero.GPIO_PIN_PA6
+.. autodata:: flipperzero.GPIO_PIN_PA7
+.. autodata:: flipperzero.GPIO_MODE_INPUT
+.. autodata:: flipperzero.GPIO_MODE_OUTPUT_PUSH_PULL
+.. autodata:: flipperzero.GPIO_MODE_OUTPUT_OPEN_DRAIN
+.. autodata:: flipperzero.GPIO_MODE_ANALOG
+.. autodata:: flipperzero.GPIO_MODE_INTERRUPT_RISE
+.. autodata:: flipperzero.GPIO_MODE_INTERRUPT_FALL
+.. autofunction:: flipperzero.gpio_init_pin
+.. autofunction:: flipperzero.gpio_set_pin
+.. autofunction:: flipperzero.gpio_get_pin
+
 Built-In
 --------
 
@@ -225,4 +248,3 @@ They're members of the global namespace instead.
       
       This function prints to the internal log buffer.
       Check out the `Flipper Zero docs <https://docs.flipper.net/development/cli#_yZ2E>`_ on how to reveal them in the CLI interface.
-

+ 143 - 0
flipperzero/_gpio.py

@@ -0,0 +1,143 @@
+GPIO_PIN_PC0: int
+'''
+Constant identifier for GPIO pin PC0.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PC1: int
+'''
+Constant identifier for GPIO pin PC1.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PC3: int
+'''
+Constant identifier for GPIO pin PC3.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PB2: int
+'''
+Constant identifier for GPIO pin PB2.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PB3: int
+'''
+Constant identifier for GPIO pin PB3.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PA4: int
+'''
+Constant identifier for GPIO pin PA4.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PA6: int
+'''
+Constant identifier for GPIO pin PA6.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_PIN_PA7: int
+'''
+Constant identifier for GPIO pin PA7.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_INPUT: int
+'''
+Constant configuration value for the GPIO input mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_OUTPUT_PUSH_PULL: int
+'''
+Constant configuration value for the GPIO output as push-pull mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_OUTPUT_OPEN_DRAIN: int
+'''
+Constant configuration value for the GPIO output as open-drain mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_ANALOG: int
+'''
+Constant configuration value for the GPIO analog mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_INTERRUPT_RISE: int
+'''
+Constant configuration value for the GPIO interrupt on rising edges mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+GPIO_MODE_INTERRUPT_FALL: int
+'''
+Constant configuration value for the GPIO interrupt on falling edges mode.
+    
+.. versionadded:: 1.2.0
+'''
+
+def gpio_init_pin(pin: int, mode: int) -> None:
+    '''
+    Initialize a GPIO pin.
+
+    :param pin: The pin to initialize (e.g. :const:`GPIO_PIN_PA4`).
+    :param mode: The mode to use (e.g. :const:`GPIO_MODE_OUTPUT_PUSH_PULL`).
+    
+    .. versionadded:: 1.2.0
+
+    .. hint::
+
+        The interrupt modes :const:`GPIO_MODE_INTERRUPT_RISE` and :const:`GPIO_MODE_INTERRUPT_FALL` can be combined using bitwise OR.
+        This allows you to handle rising `and` falling edges.
+    '''
+    pass
+
+def gpio_set_pin(pin: int, state: bool) -> None:
+    '''
+    Set the state of an output pin.
+
+    :param pin: The pin to set (e.g. :const:`GPIO_PIN_PA4`).
+    :param state: The state to set.
+    
+    .. versionadded:: 1.2.0
+
+    .. hint::
+
+        Don't forget to initialize the pin first.
+    '''
+    pass
+
+def gpio_get_pin(pin: int) -> bool:
+    '''
+    Read the state of an input pin.
+
+    :param pin: The pin to read (e.g. :const:`GPIO_PIN_PA4`).
+    :returns: :const:`True` if the pin is high, :const:`False` on a low signal.
+    
+    .. versionadded:: 1.2.0
+
+    .. hint::
+
+        Don't forget to initialize the pin first.
+    '''
+    pass