1.. _module-pw_digital_io_rp2040: 2 3-------------------- 4pw_digital_io_rp2040 5-------------------- 6``pw_digital_io_rp2040`` implements the :ref:`module-pw_digital_io` interface using 7the `Raspberry Pi Pico SDK <https://github.com/raspberrypi/pico-sdk/>`_. 8 9Setup 10===== 11Use of this module requires setting up the Pico SDK for use with Pigweed. Follow 12the steps in :ref:`target-raspberry-pi-pico` to get setup. 13 14Examples 15======== 16Use ``pw::digital_io::Rp2040DigitalIn`` and 17``pw::digital_io::Rp2040DigitalInOut`` classes to control GPIO pins. 18 19Example code to use GPIO pins: 20 21.. code-block:: cpp 22 23 #include "pw_digital_io/polarity.h" 24 #include "pw_digital_io_rp2040/digital_io.h" 25 26 using pw::digital_io::Polarity; 27 using pw::digital_io::Rp2040Config; 28 using pw::digital_io::Rp2040DigitalIn; 29 using pw::digital_io::Rp2040DigitalInOut; 30 using pw::digital_io::State; 31 32 constexpr Rp2040Config output_pin_config{ 33 .pin = 15, 34 .polarity = Polarity::kActiveLow, 35 }; 36 constexpr Rp2040Config input_pin_config{ 37 .pin = 16, 38 .polarity = Polarity::kActiveHigh, 39 }; 40 41 // Config output pin: 42 Rp2040DigitalInOut out(output_pin_config); 43 out.Enable(); 44 45 // Set the output pin active. 46 // This pulls pin to ground since the polarity is kActiveLow. 47 out.SetState(State::kActive); 48 49 // Config input pin: 50 Rp2040DigitalIn in(input_pin_config); 51 in.Enable(); 52 53 // Get the pin state. Since the polarity is kActiveHigh this will return 54 // State::kActive if the pin is high or and State::kInactive if the pin is 55 // low (grounded). 56 State pin_state = in.GetState(); 57