Skip to content

Commit 1d7b1fb

Browse files
authored
Merge pull request #71 from per1234/spi-macro-namespace
Use distinctive names for SPI pin macros to avoid collisions
2 parents fdbfc5b + 9806d58 commit 1d7b1fb

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed

.github/workflows/compile-examples.yml

+30
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,48 @@ jobs:
120120
starter-kit: false
121121
tone: true
122122
a5: true
123+
- fqbn: arduino:esp32:nano_nora
124+
usb: false
125+
serial1: true
126+
starter-kit: false
127+
tone: true
128+
a5: true
123129
- fqbn: arduino:megaavr:uno2018:mode=off
124130
usb: false
125131
serial1: true
126132
starter-kit: false
127133
tone: true
128134
a5: true
135+
- fqbn: arduino:renesas_uno:minima
136+
usb: true
137+
serial1: true
138+
starter-kit: false
139+
tone: true
140+
a5: true
141+
- fqbn: arduino:renesas_uno:unor4wifi
142+
usb: true
143+
serial1: true
144+
starter-kit: false
145+
tone: true
146+
a5: true
147+
- fqbn: arduino:renesas_portenta:portenta_c33
148+
usb: true
149+
serial1: true
150+
starter-kit: false
151+
tone: true
152+
a5: true
129153
- fqbn: arduino:samd:mkrzero
130154
usb: true
131155
serial1: true
132156
starter-kit: false
133157
tone: true
134158
a5: true
159+
- fqbn: arduino:mbed_giga:giga
160+
usb: false
161+
serial1: true
162+
starter-kit: false
163+
tone: true
164+
a5: true
135165
- fqbn: arduino:mbed_nano:nano33ble
136166
usb: false
137167
serial1: true

examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

+27-27
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// using an Uno. (On an Uno this is not needed).
2323
//
2424
// Alternatively you can use any other digital pin by configuring
25-
// software ('BitBanged') SPI and having appropriate defines for PIN_MOSI,
26-
// PIN_MISO and PIN_SCK.
25+
// software ('BitBanged') SPI and having appropriate defines for ARDUINOISP_PIN_MOSI,
26+
// ARDUINOISP_PIN_MISO and ARDUINOISP_PIN_SCK.
2727
//
2828
// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) as
2929
// the programmer, make sure to not expose any of the programmer's pins to 5V.
@@ -82,9 +82,9 @@
8282

8383
#ifdef USE_OLD_STYLE_WIRING
8484

85-
#define PIN_MOSI 11
86-
#define PIN_MISO 12
87-
#define PIN_SCK 13
85+
#define ARDUINOISP_PIN_MOSI 11
86+
#define ARDUINOISP_PIN_MISO 12
87+
#define ARDUINOISP_PIN_SCK 13
8888

8989
#endif
9090

@@ -100,20 +100,20 @@
100100
#endif
101101

102102
// By default, use hardware SPI pins:
103-
#ifndef PIN_MOSI
104-
#define PIN_MOSI MOSI
103+
#ifndef ARDUINOISP_PIN_MOSI
104+
#define ARDUINOISP_PIN_MOSI MOSI
105105
#endif
106106

107-
#ifndef PIN_MISO
108-
#define PIN_MISO MISO
107+
#ifndef ARDUINOISP_PIN_MISO
108+
#define ARDUINOISP_PIN_MISO MISO
109109
#endif
110110

111-
#ifndef PIN_SCK
112-
#define PIN_SCK SCK
111+
#ifndef ARDUINOISP_PIN_SCK
112+
#define ARDUINOISP_PIN_SCK SCK
113113
#endif
114114

115115
// Force bitbanged SPI if not using the hardware SPI pins:
116-
#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK)
116+
#if (ARDUINOISP_PIN_MISO != MISO) || (ARDUINOISP_PIN_MOSI != MOSI) || (ARDUINOISP_PIN_SCK != SCK)
117117
#undef USE_HARDWARE_SPI
118118
#endif
119119

@@ -186,11 +186,11 @@ private:
186186
class BitBangedSPI {
187187
public:
188188
void begin() {
189-
digitalWrite(PIN_SCK, LOW);
190-
digitalWrite(PIN_MOSI, LOW);
191-
pinMode(PIN_SCK, OUTPUT);
192-
pinMode(PIN_MOSI, OUTPUT);
193-
pinMode(PIN_MISO, INPUT);
189+
digitalWrite(ARDUINOISP_PIN_SCK, LOW);
190+
digitalWrite(ARDUINOISP_PIN_MOSI, LOW);
191+
pinMode(ARDUINOISP_PIN_SCK, OUTPUT);
192+
pinMode(ARDUINOISP_PIN_MOSI, OUTPUT);
193+
pinMode(ARDUINOISP_PIN_MISO, INPUT);
194194
}
195195

196196
void beginTransaction(SPISettings settings) {
@@ -204,11 +204,11 @@ public:
204204

205205
uint8_t transfer(uint8_t b) {
206206
for (unsigned int i = 0; i < 8; ++i) {
207-
digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW);
208-
digitalWrite(PIN_SCK, HIGH);
207+
digitalWrite(ARDUINOISP_PIN_MOSI, (b & 0x80) ? HIGH : LOW);
208+
digitalWrite(ARDUINOISP_PIN_SCK, HIGH);
209209
delayMicroseconds(pulseWidth);
210-
b = (b << 1) | digitalRead(PIN_MISO);
211-
digitalWrite(PIN_SCK, LOW); // slow pulse
210+
b = (b << 1) | digitalRead(ARDUINOISP_PIN_MISO);
211+
digitalWrite(ARDUINOISP_PIN_SCK, LOW); // slow pulse
212212
delayMicroseconds(pulseWidth);
213213
}
214214
return b;
@@ -408,7 +408,7 @@ void set_parameters() {
408408

409409
void start_pmode() {
410410

411-
// Reset target before driving PIN_SCK or PIN_MOSI
411+
// Reset target before driving ARDUINOISP_PIN_SCK or ARDUINOISP_PIN_MOSI
412412

413413
// SPI.begin() will configure SS as output, so SPI master mode is selected.
414414
// We have defined RESET as pin 10, which for many Arduinos is not the SS pin.
@@ -421,9 +421,9 @@ void start_pmode() {
421421

422422
// See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm":
423423

424-
// Pulse RESET after PIN_SCK is low:
425-
digitalWrite(PIN_SCK, LOW);
426-
delay(20); // discharge PIN_SCK, value arbitrarily chosen
424+
// Pulse RESET after ARDUINOISP_PIN_SCK is low:
425+
digitalWrite(ARDUINOISP_PIN_SCK, LOW);
426+
delay(20); // discharge ARDUINOISP_PIN_SCK, value arbitrarily chosen
427427
reset_target(false);
428428
// Pulse must be minimum 2 target CPU clock cycles so 100 usec is ok for CPU
429429
// speeds above 20 KHz
@@ -439,8 +439,8 @@ void start_pmode() {
439439
void end_pmode() {
440440
SPI.end();
441441
// We're about to take the target out of reset so configure SPI pins as input
442-
pinMode(PIN_MOSI, INPUT);
443-
pinMode(PIN_SCK, INPUT);
442+
pinMode(ARDUINOISP_PIN_MOSI, INPUT);
443+
pinMode(ARDUINOISP_PIN_SCK, INPUT);
444444
reset_target(false);
445445
pinMode(RESET, INPUT);
446446
pmode = 0;

0 commit comments

Comments
 (0)