Skip to content

Commit f382e15

Browse files
committed
Added Toggle() member funciton to GpioBasic.
Test passed.
1 parent e6716b4 commit f382e15

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

src/gpio/gpiobasic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ void rpp_driver::GpioBasic::Put(bool value) { sdk_.gpio_put(pin_, value); }
1717

1818
bool rpp_driver::GpioBasic::Get() { return sdk_.gpio_get(pin_); }
1919

20+
void rpp_driver::GpioBasic::Toggle() { Put(!Get()); }
21+
2022
void rpp_driver::GpioBasic::PullUp() { sdk_.gpio_pull_up(pin_); }
2123

2224
void rpp_driver::GpioBasic::PullDown() { sdk_.gpio_pull_down(pin_); }

src/gpio/gpiobasic.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GpioBasic {
4949

5050
/**
5151
* @brief Enable GPIO input.
52-
* @param enabled true to enable input on This GPIO.
52+
* @param enabled true to enable input on this GPIO.
5353
*/
5454
virtual void SetInputEnabled(bool enabled);
5555

@@ -60,22 +60,33 @@ class GpioBasic {
6060
virtual void Put(bool value);
6161

6262
/**
63-
* @brief Get state of a single This GPIO.
64-
* @returns Current state of the GPIO. 0 for low, non-zero for high
63+
* @brief Get state of a single GPIO.
64+
* @returns Current state of this GPIO. 0 for low, non-zero for high
6565
*/
6666
virtual bool Get();
67+
68+
/**
69+
* @brief Toggle the output level of this GPIO.
70+
* @details
71+
* If the current level is "H", set it to "L".
72+
* If the current level is "L", set it to "H".
73+
*/
74+
virtual void Toggle();
75+
6776
/**
68-
* @brief Set This GPIO to be pulled up.
77+
* @brief Set this GPIO to be pulled up.
78+
* @
6979
*/
7080
virtual void PullUp();
7181

7282
/**
73-
* @brief Set This GPIO to be pulled down.
83+
* @brief Set this GPIO to be pulled down.
7484
*/
7585
virtual void PullDown();
7686

7787
/**
78-
* @brief Disable pulls on This GPIO.
88+
* @brief Unset pulls on this GPIO.
89+
*
7990
*/
8091
virtual void DisablePulls();
8192

@@ -91,6 +102,7 @@ class MockGpioBasic : public SdkWrapper {
91102
MOCK_METHOD1(SetInputEnabled, void(bool));
92103
MOCK_METHOD1(Put, void(bool));
93104
MOCK_METHOD0(Get, bool(void));
105+
MOCK_METHOD0(Toggle, void(void));
94106
MOCK_METHOD0(PullUp, void(void));
95107
MOCK_METHOD0(PullDown, void(void));
96108
MOCK_METHOD0(DisablePulls, void(void));

test/test_gpiobasic.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST(GpioBasic, ConstructorDeconstructor) {
5050

5151
// -----------------------------------------------------------------
5252
//
53-
// Constructor and Deconstructor ()
53+
// Member functions.
5454
//
5555
// -----------------------------------------------------------------
5656

@@ -87,6 +87,20 @@ TEST_F(GpioBasicTest, Put) {
8787
gpio_under_test_->Put(false);
8888
} // TEST_F(GpioBasicTest, Put)
8989

90+
TEST_F(GpioBasicTest, Toggle) {
91+
using ::testing::InSequence;
92+
using ::testing::Return;
93+
{
94+
InSequence dummy;
95+
EXPECT_CALL(sdk_, gpio_get(gpio_pin_)).WillOnce(Return(true));
96+
EXPECT_CALL(sdk_, gpio_put(gpio_pin_, false));
97+
EXPECT_CALL(sdk_, gpio_get(gpio_pin_)).WillOnce(Return(false));
98+
EXPECT_CALL(sdk_, gpio_put(gpio_pin_, true));
99+
}
100+
gpio_under_test_->Toggle();
101+
gpio_under_test_->Toggle();
102+
} // TEST_F(GpioBasicTest, Toggle)
103+
90104
TEST_F(GpioBasicTest, Get) {
91105
using ::testing::InSequence;
92106
using ::testing::Return;

test/todo/test_gpiobasic.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
- [x] Make it success.
77
- [x] Remove the duplication.
88

9+
## GpioBasic::DisablePulls
10+
- [x] Implement member function .
11+
- [x] Create test case to fail.
12+
- [x] Make it success.
13+
- [x] Remove the duplication.
14+
915
## GpioBasic::PullDown
1016
- [x] Implement member function .
1117
- [x] Create test case to fail.

0 commit comments

Comments
 (0)