summaryrefslogtreecommitdiffstatshomepage
path: root/docs/zephyr/tutorial/pins.rst
diff options
context:
space:
mode:
authorJulia Hathaway <julia.hathaway@nxp.com>2021-08-02 17:01:57 -0500
committerDamien George <damien@micropython.org>2021-08-13 20:20:57 +1000
commit333e16521bc8af8a55f362c1bad2f21c4704d20b (patch)
tree280617f7b9c28b6e2c46c20b0812441455311f26 /docs/zephyr/tutorial/pins.rst
parent42d1a1635cc35fd3a9ae28b19685184fc3c23f1e (diff)
downloadmicropython-333e16521bc8af8a55f362c1bad2f21c4704d20b.tar.gz
micropython-333e16521bc8af8a55f362c1bad2f21c4704d20b.zip
docs/zephyr: Add quick reference for the Zephyr port.
Includes an introduction to using the Zephyr port on MicroPython. The quickref details examples of how to use each module the port currently supports. The tutorial provides additional details for Zephyr specific modules. Signed-off-by: Julia Hathaway <julia.hathaway@nxp.com>
Diffstat (limited to 'docs/zephyr/tutorial/pins.rst')
-rw-r--r--docs/zephyr/tutorial/pins.rst46
1 files changed, 46 insertions, 0 deletions
diff --git a/docs/zephyr/tutorial/pins.rst b/docs/zephyr/tutorial/pins.rst
new file mode 100644
index 0000000000..8e1d6602af
--- /dev/null
+++ b/docs/zephyr/tutorial/pins.rst
@@ -0,0 +1,46 @@
+.. _pins_zephyr:
+
+GPIO Pins
+=========
+
+Use :ref:`machine.Pin <machine.Pin>` to control I/O pins.
+
+For Zephyr, pins are initialized using a tuple of port and pin number ``(\"GPIO_x\", pin#)``
+for the ``id`` value. For example to initialize a pin for the red LED on a FRDM-k64 board::
+
+ LED = Pin(("GPIO_1", 22), Pin.OUT)
+
+Reference your board's datasheet or Zephyr documentation for pin numbers, see below for more examples.
+
+.. list-table:: Pin Formatting
+ :header-rows: 1
+
+ * - Board
+ - Pin
+ - Format
+ * - frdm_k64f
+ - Red LED = PTB22
+ - ("GPIO_1", 22)
+ * - 96b_carbon
+ - LED1 = PD2
+ - ("GPIOD", 2)
+ * - mimxrt685_evk_cm33
+ - Green LED = PIO0_14
+ - ("GPIO0", 14)
+
+Interrupts
+----------
+
+The Zephyr port also supports interrupt handling for Pins using `machine.Pin.irq() <machine.Pin.irq>`.
+To respond to Pin change IRQs run::
+
+ from machine import Pin
+
+ SW2 = Pin(("GPIO_2", 6), Pin.IN) # create Pin object for switch 2
+ SW3 = Pin(("GPIO_0", 4), Pin.IN) # create Pin object for switch 3
+
+ SW2.irq(lambda t: print("SW2 changed")) # print message when SW2 state is changed (triggers change IRQ)
+ SW3.irq(lambda t: print("SW3 changed")) # print message when SW3 state is changed (triggers change IRQ)
+
+ while True: # wait
+ pass