Skip to content

Commit 750e324

Browse files
author
clawpi
committed
Update GPIO test with hardware feedback verification
- Use Arduino pin 3 to verify actual GPIO state - Tests output mode, inversion, and input mode - Note: AS7343 GPIO is open-drain (needs pull-up)
1 parent 25461de commit 750e324

2 files changed

Lines changed: 143 additions & 84 deletions

File tree

hw_tests/16_gpio_test/16_gpio_test.ino

Lines changed: 128 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,163 @@
22
* @file 16_gpio_test.ino
33
* @brief Hardware test for AS7343 GPIO functionality
44
*
5-
* Tests GPIO pin control:
6-
* - Output mode with value setting
7-
* - GPIO inversion setting
8-
* - Input mode reading
5+
* Tests GPIO pin control with hardware verification:
6+
* - Output mode: verify actual pin state via Arduino feedback pin
7+
* - Inversion: verify inverted output
8+
* - Input mode: drive pin from Arduino and read via AS7343
99
*
10-
* Note: getGPIOValue() reads the actual pin state (GPIO_IN bit), not the
11-
* output register value. Without external circuitry, read-back won't match
12-
* what was written - this is expected behavior.
13-
*
14-
* GPIO register is in bank 1, so this also tests bank switching.
10+
* Hardware: AS7343 GPIO pin connected to Metro Mini pin 3
11+
* Note: AS7343 GPIO is open-drain - requires pull-up for HIGH output
12+
* Board: Metro Mini (arduino:avr:uno)
1513
*/
1614

1715
#include <Adafruit_AS7343.h>
1816

17+
#define FEEDBACK_PIN 3 // Arduino pin connected to AS7343 GPIO
18+
1919
Adafruit_AS7343 as7343;
2020
bool allPassed = true;
2121

2222
void setup() {
2323
Serial.begin(115200);
24-
while (!Serial) delay(10);
25-
delay(500);
24+
while (!Serial)
25+
delay(10);
2626

2727
Serial.println(F("AS7343 GPIO Test"));
2828
Serial.println(F("================"));
29+
Serial.println(F("Feedback pin: D3 connected to AS7343 GPIO"));
2930
Serial.println();
3031

3132
if (!as7343.begin()) {
3233
Serial.println(F("ERROR: AS7343 not found!"));
3334
Serial.println(F("RESULT: FAIL"));
34-
while (1) delay(10);
35+
while (1)
36+
delay(10);
3537
}
3638

37-
// Output Mode Test
38-
Serial.println(F("Output Mode Test:"));
39-
40-
// Set to output mode
41-
bool ok = as7343.setGPIOOutput(true);
42-
Serial.print(F(" setGPIOOutput(true): "));
43-
Serial.println(ok ? F("OK") : F("FAIL"));
44-
if (!ok) allPassed = false;
45-
46-
// Set high
47-
ok = as7343.setGPIOValue(true);
48-
Serial.print(F(" setGPIOValue(true): "));
49-
Serial.println(ok ? F("OK") : F("FAIL"));
50-
if (!ok) allPassed = false;
51-
52-
// Read - note: reads GPIO_IN (actual pin state), not GPIO_OUT
53-
bool val = as7343.getGPIOValue();
54-
Serial.print(F(" getGPIOValue(): "));
55-
Serial.println(val ? F("true") : F("false"));
56-
57-
// Set low
58-
ok = as7343.setGPIOValue(false);
59-
Serial.print(F(" setGPIOValue(false): "));
60-
Serial.println(ok ? F("OK") : F("FAIL"));
61-
if (!ok) allPassed = false;
62-
63-
val = as7343.getGPIOValue();
64-
Serial.print(F(" getGPIOValue(): "));
65-
Serial.println(val ? F("true") : F("false"));
66-
67-
Serial.println();
68-
69-
// Inversion Test
70-
Serial.println(F("Inversion Test:"));
71-
ok = as7343.setGPIOInverted(true);
72-
Serial.print(F(" setGPIOInverted(true): "));
73-
Serial.println(ok ? F("OK") : F("FAIL"));
74-
if (!ok) allPassed = false;
75-
76-
ok = as7343.setGPIOInverted(false);
77-
Serial.print(F(" setGPIOInverted(false): "));
78-
Serial.println(ok ? F("OK") : F("FAIL"));
79-
if (!ok) allPassed = false;
39+
// ==========================================
40+
// Part 1: Output Mode with Hardware Feedback
41+
// ==========================================
42+
Serial.println(F("Part 1: Output Mode Test"));
43+
44+
// Set feedback pin as input with pull-up (AS7343 GPIO may be open-drain)
45+
pinMode(FEEDBACK_PIN, INPUT_PULLUP);
46+
47+
// Configure AS7343 GPIO as output, not inverted
48+
as7343.setGPIOOutput(true);
49+
as7343.setGPIOInverted(false);
50+
51+
// Test HIGH output
52+
as7343.setGPIOValue(true);
53+
delay(5);
54+
bool pinState = digitalRead(FEEDBACK_PIN);
55+
Serial.print(F(" Output HIGH -> Pin reads: "));
56+
Serial.print(pinState ? F("HIGH") : F("LOW"));
57+
bool passHigh = (pinState == HIGH);
58+
Serial.println(passHigh ? F(" PASS") : F(" FAIL"));
59+
if (!passHigh)
60+
allPassed = false;
61+
62+
// Test LOW output
63+
as7343.setGPIOValue(false);
64+
delay(5);
65+
pinState = digitalRead(FEEDBACK_PIN);
66+
Serial.print(F(" Output LOW -> Pin reads: "));
67+
Serial.print(pinState ? F("HIGH") : F("LOW"));
68+
bool passLow = (pinState == LOW);
69+
Serial.println(passLow ? F(" PASS") : F(" FAIL"));
70+
if (!passLow)
71+
allPassed = false;
8072

8173
Serial.println();
8274

83-
// Input Mode Test
84-
Serial.println(F("Input Mode Test:"));
85-
ok = as7343.setGPIOOutput(false);
86-
Serial.print(F(" setGPIOOutput(false): "));
87-
Serial.println(ok ? F("OK") : F("FAIL"));
88-
if (!ok) allPassed = false;
89-
90-
val = as7343.getGPIOValue();
91-
Serial.print(F(" getGPIOValue(): "));
92-
Serial.print(val ? F("true") : F("false"));
93-
Serial.println(F(" (depends on pin state)"));
75+
// ==========================================
76+
// Part 2: Inversion Test
77+
// ==========================================
78+
Serial.println(F("Part 2: Inversion Test"));
79+
80+
// Enable inversion
81+
as7343.setGPIOInverted(true);
82+
83+
// With inversion, setting HIGH should output LOW
84+
as7343.setGPIOValue(true);
85+
delay(5);
86+
pinState = digitalRead(FEEDBACK_PIN);
87+
Serial.print(F(" Inverted + Value HIGH -> Pin: "));
88+
Serial.print(pinState ? F("HIGH") : F("LOW"));
89+
bool passInvHigh = (pinState == LOW); // Inverted!
90+
Serial.println(passInvHigh ? F(" PASS") : F(" FAIL"));
91+
if (!passInvHigh)
92+
allPassed = false;
93+
94+
// With inversion, setting LOW should output HIGH
95+
as7343.setGPIOValue(false);
96+
delay(5);
97+
pinState = digitalRead(FEEDBACK_PIN);
98+
Serial.print(F(" Inverted + Value LOW -> Pin: "));
99+
Serial.print(pinState ? F("HIGH") : F("LOW"));
100+
bool passInvLow = (pinState == HIGH); // Inverted!
101+
Serial.println(passInvLow ? F(" PASS") : F(" FAIL"));
102+
if (!passInvLow)
103+
allPassed = false;
104+
105+
// Disable inversion for remaining tests
106+
as7343.setGPIOInverted(false);
94107

95108
Serial.println();
96109

110+
// ==========================================
111+
// Part 3: Input Mode Test
112+
// ==========================================
113+
Serial.println(F("Part 3: Input Mode Test"));
114+
115+
// Configure AS7343 GPIO as input
116+
as7343.setGPIOOutput(false);
117+
delay(5);
118+
119+
// Drive pin from Arduino and read via AS7343
120+
pinMode(FEEDBACK_PIN, OUTPUT);
121+
122+
// Drive HIGH
123+
digitalWrite(FEEDBACK_PIN, HIGH);
124+
delay(5);
125+
bool readVal = as7343.getGPIOValue();
126+
Serial.print(F(" Arduino drives HIGH -> AS7343 reads: "));
127+
Serial.print(readVal ? F("HIGH") : F("LOW"));
128+
bool passInHigh = (readVal == true);
129+
Serial.println(passInHigh ? F(" PASS") : F(" FAIL"));
130+
if (!passInHigh)
131+
allPassed = false;
132+
133+
// Drive LOW
134+
digitalWrite(FEEDBACK_PIN, LOW);
135+
delay(5);
136+
readVal = as7343.getGPIOValue();
137+
Serial.print(F(" Arduino drives LOW -> AS7343 reads: "));
138+
Serial.print(readVal ? F("HIGH") : F("LOW"));
139+
bool passInLow = (readVal == false);
140+
Serial.println(passInLow ? F(" PASS") : F(" FAIL"));
141+
if (!passInLow)
142+
allPassed = false;
143+
144+
// Clean up - set pin back to input
145+
pinMode(FEEDBACK_PIN, INPUT);
146+
147+
// ==========================================
97148
// Summary
98-
Serial.print(F("GPIO API: "));
99-
Serial.println(allPassed ? F("PASS") : F("FAIL"));
149+
// ==========================================
150+
Serial.println();
151+
Serial.println(F("Summary:"));
152+
Serial.print(F(" Output mode: "));
153+
Serial.println((passHigh && passLow) ? F("PASS") : F("FAIL"));
154+
Serial.print(F(" Inversion: "));
155+
Serial.println((passInvHigh && passInvLow) ? F("PASS") : F("FAIL"));
156+
Serial.print(F(" Input mode: "));
157+
Serial.println((passInHigh && passInLow) ? F("PASS") : F("FAIL"));
100158

159+
Serial.println();
101160
Serial.print(F("RESULT: "));
102161
Serial.println(allPassed ? F("PASS") : F("FAIL"));
103162
}
104163

105-
void loop() {
106-
delay(1000);
107-
}
164+
void loop() { delay(1000); }

hw_tests/16_gpio_test/output.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
AS7343 GPIO Test
22
================
3+
Feedback pin: D3 connected to AS7343 GPIO
34

4-
Output Mode Test:
5-
setGPIOOutput(true): OK
6-
setGPIOValue(true): OK
7-
getGPIOValue(): false
8-
setGPIOValue(false): OK
9-
getGPIOValue(): false
5+
Part 1: Output Mode Test
6+
Output HIGH -> Pin reads: HIGH PASS
7+
Output LOW -> Pin reads: LOW PASS
108

11-
Inversion Test:
12-
setGPIOInverted(true): OK
13-
setGPIOInverted(false): OK
9+
Part 2: Inversion Test
10+
Inverted + Value HIGH -> Pin: LOW PASS
11+
Inverted + Value LOW -> Pin: HIGH PASS
1412

15-
Input Mode Test:
16-
setGPIOOutput(false): OK
17-
getGPIOValue(): false (depends on pin state)
13+
Part 3: Input Mode Test
14+
Arduino drives HIGH -> AS7343 reads: HIGH PASS
15+
Arduino drives LOW -> AS7343 reads: LOW PASS
16+
17+
Summary:
18+
Output mode: PASS
19+
Inversion: PASS
20+
Input mode: PASS
1821

19-
GPIO API: PASS
2022
RESULT: PASS

0 commit comments

Comments
 (0)