Skip to content

Commit cbff863

Browse files
fpistmABOSTM
authored andcommitted
Add CheckVariant sketch
Initial draft version Signed-off-by: Frederic Pillon <[email protected]>
1 parent 36537fa commit cbff863

File tree

3 files changed

+692
-0
lines changed

3 files changed

+692
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "utils.h"
2+
3+
#define PORTx(pn) (char)('A' + STM_PORT(pn))
4+
#define PINx(pn) STM_PIN(pn)
5+
6+
/*
7+
pname: Pin of type PinName (PY_n)
8+
asPN: true display as a PinName, false as a pin number (PYn)
9+
val: display value or not
10+
ln: carriage return or not
11+
*/
12+
void printPinName(PinName pname, bool asPN, bool val, bool ln) {
13+
Serial.print("P");
14+
Serial.print(PORTx(pname));
15+
if (asPN) {
16+
Serial.print("_");
17+
}
18+
Serial.print(PINx(pname));
19+
if (val) {
20+
Serial.print(" (");
21+
Serial.print(asPN ? (uint32_t)pname : pinNametoDigitalPin(pname));
22+
Serial.print(")");
23+
}
24+
if (ln) {
25+
Serial.println();
26+
}
27+
}
28+
29+
void setup() {
30+
// Serial.setTx(PA9_R);
31+
// Serial.setRx(PA10_R);
32+
Serial.begin(115200);
33+
while (!Serial) {
34+
; // wait for serial port to connect. Needed for native USB port only
35+
}
36+
pinMode(LED_BUILTIN, OUTPUT);
37+
}
38+
39+
void loop() {
40+
Serial.printf("NUM_DIGITAL_PINS = %i\n", NUM_DIGITAL_PINS);
41+
Serial.printf("NUM_ANALOG_INPUTS = %i\n", NUM_ANALOG_INPUTS);
42+
43+
checkDigitalPins();
44+
checkAnalogPins();
45+
46+
while (1) {
47+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
48+
delay(1000); // wait for a second
49+
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
50+
delay(1000); // wait for a second
51+
}
52+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
void checkAnalogPins(void) {
3+
Serial.println("Checking analog pins definition...");
4+
5+
for ( uint32_t i = 0; i < (NUM_ANALOG_INPUTS); i++) {
6+
uint8_t res = 0;
7+
// i is the index in the analogInputPin array
8+
uint32_t pinnum_array = analogInputPin[i];
9+
uint32_t pinnum_aTD_i = analogInputToDigitalPin(i);
10+
uint32_t pinnum_aTD_Ax = analogInputToDigitalPin(A0 + i);
11+
12+
PinName pn_dTpn_Ax = digitalPinToPinName(A0 + i);
13+
PinName pn_aTpn_Ax = analogInputToPinName(A0 + i);
14+
15+
16+
if ((pinnum_array != pinnum_aTD_i) || (pinnum_array != pinnum_aTD_Ax) || (pinnum_aTD_i == NC)) {
17+
res = 1;
18+
}
19+
if (!digitalpinIsAnalogInput(pinnum_array) || !digitalpinIsAnalogInput(pinnum_aTD_i) || !digitalpinIsAnalogInput(pinnum_aTD_Ax)) {
20+
res |= 2;
21+
}
22+
if ((pn_dTpn_Ax != pn_aTpn_Ax) || (pinnum_aTD_i == NC)) {
23+
res |= 4;
24+
}
25+
if (digitalPinToAnalogInput(pinnum_aTD_i) != i) {
26+
27+
res |= 8;
28+
}
29+
/*
30+
pname: Pin of type PinName (PY_n)
31+
asPN: true display as a PinName, false as a pin number (PYn)
32+
val: display value or not
33+
ln: carriage return or not
34+
*/
35+
if (res) {
36+
Serial.printf("A%i defined as %i with pin name: ", i, A0 + i);
37+
printPinName(pn_aTpn_Ax, true, true, false);
38+
Serial.print(" and pin number: ");
39+
printPinName(pn_aTpn_Ax, false, true, false);
40+
Serial.printf(" --> %i\n", res);
41+
Serial.printf(" --> digitalPinToAnalogInput(%i) = %i\n", pinnum_aTD_i, digitalPinToAnalogInput(pinnum_aTD_i));
42+
43+
44+
// Serial.print("\tPin name ");
45+
// printPinName(pn_Ax, true, true, false);
46+
// Serial.print(" have to be indexed higher than NUM_ANALOG_INPUTS (");
47+
// Serial.print(NUM_ANALOG_INPUTS);
48+
// Serial.println(") to be able to use:");
49+
// PinName pn_Ax_analog = analogInputToPinName(pinNametoDigitalPin(pn_Ax));
50+
// Serial.print("\tAnalogRead(");
51+
// printPinName(pn_Ax, false, false, false);
52+
// Serial.print(") --> which currently use pin name: ");
53+
// printPinName(pn_Ax_analog, true, true, false);
54+
// Serial.print(" and pin number: ");
55+
// printPinName(pn_Ax_analog, false, true, true);
56+
}
57+
}
58+
Serial.println("End check analog pins");
59+
Serial.println("#####");
60+
}

0 commit comments

Comments
 (0)