Raspberry Pio Pico Drivers project
Loading...
Searching...
No Matches
gpiobasic.hpp
Go to the documentation of this file.
1
11#ifndef PICO_DRIVER_SRC_GPIO_GPIOBASIC_HPP_
12#define PICO_DRIVER_SRC_GPIO_GPIOBASIC_HPP_
13
14#include <stdint.h>
15
16#if __has_include(<hardware/gpio.h>)
17#include "hardware/gpio.h"
18#else
19// Alternate definition for unit test.
20#endif // __has_include(<hardware/i2c.h>)
21
22#include "sdk/sdkwrapper.hpp"
23
24namespace rpp_driver {
68class GpioBasic {
69 public:
78 GpioBasic(SdkWrapper &sdk, uint pin);
79 GpioBasic() = delete;
83 virtual ~GpioBasic();
88 virtual void SetDir(bool out);
89
94 virtual void SetInputEnabled(bool enabled);
95
100 virtual void Put(bool value);
101
106 virtual bool Get();
107
114 virtual void Toggle();
115
120 virtual void PullUp();
121
125 virtual void PullDown();
126
131 virtual void DisablePulls();
132
133 private:
134 SdkWrapper &sdk_;
135 const uint pin_;
136};
137#if __has_include(<gmock/gmock.h>)
138// GCOVR_EXCL_START
139class MockGpioBasic : public GpioBasic {
140 public:
141 MockGpioBasic(SdkWrapper &sdk)
142 : GpioBasic(sdk, 0) {}; // 0 is dummy. We don't care.
143 MOCK_METHOD1(SetDir, void(bool));
144 MOCK_METHOD1(SetInputEnabled, void(bool));
145 MOCK_METHOD1(Put, void(bool));
146 MOCK_METHOD0(Get, bool(void));
147 MOCK_METHOD0(Toggle, void(void));
148 MOCK_METHOD0(PullUp, void(void));
149 MOCK_METHOD0(PullDown, void(void));
150 MOCK_METHOD0(DisablePulls, void(void));
151}; // MockGpioBasic
152// GCOVR_EXCL_STOP
153#endif // __has_include(<gmock/gmock.h>)
154}; // namespace rpp_driver
155
156#endif /* PICO_DRIVER_SRC_GPIO_GPIOBASIC_HPP_ */
Basic GPIO driver class.
Definition: gpiobasic.hpp:68
GpioBasic(SdkWrapper &sdk, uint pin)
Initialize the given GPIO pin and setup the pins.
virtual void PullDown()
Set this GPIO to be pulled down.
virtual void SetDir(bool out)
Set a single GPIO direction.
virtual bool Get()
Get state of a single GPIO.
virtual void Toggle()
Toggle the output level of this GPIO.
virtual ~GpioBasic()
deinit the GPIO by SdkWrapper::gpio_deinit();
virtual void Put(bool value)
Drive a single GPIO high/low.
virtual void SetInputEnabled(bool enabled)
Enable GPIO input.
virtual void PullUp()
Set this GPIO to be pulled up. .
virtual void DisablePulls()
Unset pulls on this GPIO.
Wrapper class for the RasPi Pico SDK functions.
Definition: sdkwrapper.hpp:74
Collection of the RP2040/RP2350 control.
Definition: adau1361.hpp:17
Wrapper for RasPi Pico SDK API.