@@ -66,6 +66,56 @@ void DigitalIO_StackAllocated_Test()
6666 TEST_ASSERT_MESSAGE (0 == din," Expected value to be 0, read value was not zero" );
6767}
6868
69+ // Test of pull up and pull down mode
70+ template <PinName dout_pin, PinName din_pin>
71+ void DigitalIO_PullUpPullDown_Test ()
72+ {
73+ DigitalIn dout (dout_pin);
74+ DigitalIn din (din_pin, PullNone); // Make sure no pullup/pulldown is active on this pin as some targets have this by default.
75+
76+ // test 0
77+ dout.mode (PullDown);
78+ wait_us (GPIO_PROPAGATION_TIME);
79+ TEST_ASSERT_MESSAGE (0 == din.read ()," Expected value to be 0, read value was not zero" );
80+
81+ // test 1
82+ dout.mode (PullUp);
83+ wait_us (GPIO_PROPAGATION_TIME);
84+ TEST_ASSERT_MESSAGE (1 == din.read ()," Expected value to be 1, read value was not one" );
85+ }
86+
87+ // Test that open-drain mode works as expected
88+ template <PinName dout_pin, PinName din_pin>
89+ void DigitalIO_OpenDrain_Test ()
90+ {
91+ DigitalInOut openDrain (dout_pin, PIN_OUTPUT, OpenDrain, 1 );
92+ DigitalInOut connectedPin (din_pin, PIN_INPUT, PullUp, 0 );
93+
94+ // With the open drain pin not outputting anything, we should see both pins reading high
95+ wait_us (GPIO_PROPAGATION_TIME);
96+ TEST_ASSERT_MESSAGE (1 == openDrain.read (), " openDrain was low!" );
97+ TEST_ASSERT_MESSAGE (1 == connectedPin.read (), " connectedPin was low!" );
98+
99+ // Outputting a low on the open drain pin should bring both pins low
100+ openDrain = 0 ;
101+ wait_us (GPIO_PROPAGATION_TIME);
102+ TEST_ASSERT_MESSAGE (0 == openDrain.read (), " openDrain was high!" );
103+ TEST_ASSERT_MESSAGE (0 == connectedPin.read (), " connectedPin was high!" );
104+
105+ // Outputting a high should cause both pins to go high again
106+ openDrain = 1 ;
107+ wait_us (GPIO_PROPAGATION_TIME);
108+ TEST_ASSERT_MESSAGE (1 == openDrain.read (), " openDrain was low!" );
109+ TEST_ASSERT_MESSAGE (1 == connectedPin.read (), " connectedPin was low!" );
110+
111+ // If we output a logic low with the other pin, this should be detectable with the open drain pin
112+ connectedPin.output ();
113+ connectedPin.write (0 );
114+ wait_us (GPIO_PROPAGATION_TIME);
115+ TEST_ASSERT_MESSAGE (0 == openDrain.read (), " openDrain was high!" );
116+ TEST_ASSERT_MESSAGE (0 == connectedPin.read (), " connectedPin was high!" );
117+ }
118+
69119utest::v1::status_t test_setup (const size_t number_of_cases) {
70120 // Setup Greentea using a reasonable timeout in seconds
71121 GREENTEA_SETUP (30 , " default_auto" );
@@ -80,10 +130,12 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
80130
81131// Test cases
82132Case cases[] = {
83- Case (" Digital I/O GPOUT_0 -> GPIN_0" , DigitalIO_Global_Test<GPOUT_0, GPIN_0, 0 >),
84- Case (" Digital I/O GPOUT_1 -> GPIN_1" , DigitalIO_Global_Test<GPOUT_1, GPIN_1, 1 >),
85- Case (" Digital I/O GPIN_2 -> GPOUT_2" , DigitalIO_StackAllocated_Test<PIN_GPOUT_2, PIN_GPIN_2>),
86- Case (" Digital I/O GPOUT_2 -> GPIN_2" , DigitalIO_StackAllocated_Test<PIN_GPIN_2, PIN_GPOUT_2>),
133+ Case (" Digital I/O GPOUT_0 -> GPIN_0 (Global)" , DigitalIO_Global_Test<GPOUT_0, GPIN_0, 0 >),
134+ Case (" Digital I/O GPOUT_1 -> GPIN_1 (Global)" , DigitalIO_Global_Test<GPOUT_1, GPIN_1, 1 >),
135+ Case (" Digital I/O GPIN_2 -> GPOUT_2 (Stack Allocated)" , DigitalIO_StackAllocated_Test<PIN_GPOUT_2, PIN_GPIN_2>),
136+ Case (" Digital I/O GPOUT_2 -> GPIN_2 (Stack Allocated)" , DigitalIO_StackAllocated_Test<PIN_GPIN_2, PIN_GPOUT_2>),
137+ Case (" Digital I/O Pull-Up and Pull-Down Mode" , DigitalIO_PullUpPullDown_Test<PIN_GPIN_2, PIN_GPOUT_2>),
138+ Case (" Digital I/O Open Drain Mode" , DigitalIO_OpenDrain_Test<PIN_GPIN_2, PIN_GPOUT_2>)
87139};
88140
89141Specification specification (test_setup, cases, greentea_continue_handlers);
0 commit comments