Skip to content

Commit 5618f23

Browse files
author
Daniel Garcia
committed
Better fix to ensure no adjacent register write opcodes to optimize out on esp32
1 parent db26028 commit 5618f23

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fastspi_bitbang.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,23 @@ class AVRSoftwareSPIOutput {
124124
if(b & (1 << BIT)) {
125125
FastPin<DATA_PIN>::hi();
126126
#ifdef ESP32
127-
FastPin<CLOCK_PIN>::lo(); // kick a different register, block premature optimizations?
128-
#endif
127+
// try to ensure we never have adjacent write opcodes to the same register
128+
FastPin<CLOCK_PIN>::lo();
129+
FastPin<CLOCK_PIN>::hi(); CLOCK_HI_DELAY;
130+
FastPin<CLOCK_PIN>::toggle(); CLOCK_LO_DELAY;
131+
#else
129132
FastPin<CLOCK_PIN>::hi(); CLOCK_HI_DELAY;
130133
FastPin<CLOCK_PIN>::lo(); CLOCK_LO_DELAY;
134+
#endif
131135
} else {
132136
FastPin<DATA_PIN>::lo();
133137
FastPin<CLOCK_PIN>::hi(); CLOCK_HI_DELAY;
138+
#ifdef ESP32
139+
// try to ensure we never have adjacent write opcodes to the same register
140+
FastPin<CLOCK_PIN>::toggle(); CLOCK_HI_DELAY;
141+
#else
134142
FastPin<CLOCK_PIN>::lo(); CLOCK_LO_DELAY;
143+
#endif
135144
}
136145
//sei();
137146
}

0 commit comments

Comments
 (0)