|
2 | 2 |
|
3 | 3 | // #define DEBUG_SERIAL Serial |
4 | 4 |
|
5 | | - |
6 | 5 | #ifdef BUSIO_USE_FAST_PINIO |
7 | 6 | #define BUSIO_SET_CLOCK_LOW() (*clkPort = *clkPort & ~clkPinMask) |
8 | 7 | #define BUSIO_SET_CLOCK_HIGH() (*clkPort = *clkPort | clkPinMask) |
9 | 8 | #define BUSIO_READ_MISO() (*misoPort & misoPinMask) |
10 | | -#define BUSIO_WRITE_MOSI(value) do { \ |
11 | | - if (value) \ |
12 | | - *mosiPort = *mosiPort | mosiPinMask; \ |
13 | | - else \ |
14 | | - *mosiPort = *mosiPort & ~mosiPinMask; \ |
15 | | -} while(0) |
| 9 | +#define BUSIO_WRITE_MOSI(value) \ |
| 10 | + do { \ |
| 11 | + if (value) \ |
| 12 | + *mosiPort = *mosiPort | mosiPinMask; \ |
| 13 | + else \ |
| 14 | + *mosiPort = *mosiPort & ~mosiPinMask; \ |
| 15 | + } while (0) |
16 | 16 | #else |
17 | 17 | #define BUSIO_SET_CLOCK_LOW() digitalWrite(_sck, LOW) |
18 | 18 | #define BUSIO_SET_CLOCK_HIGH() digitalWrite(_sck, HIGH) |
@@ -195,65 +195,65 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) { |
195 | 195 | if (bitdelay_us) { |
196 | 196 | delayMicroseconds(bitdelay_us); |
197 | 197 | } |
198 | | - |
| 198 | + |
199 | 199 | if (_dataMode == SPI_MODE0 || _dataMode == SPI_MODE2) { |
200 | 200 | towrite = send & b; |
201 | 201 | if ((_mosi != -1) && (lastmosi != towrite)) { |
202 | 202 | BUSIO_WRITE_MOSI(towrite); |
203 | 203 | lastmosi = towrite; |
204 | 204 | } |
205 | | - |
| 205 | + |
206 | 206 | BUSIO_SET_CLOCK_HIGH(); |
207 | | - |
| 207 | + |
208 | 208 | if (bitdelay_us) { |
209 | 209 | delayMicroseconds(bitdelay_us); |
210 | 210 | } |
211 | | - |
| 211 | + |
212 | 212 | if (_miso != -1) { |
213 | 213 | if (BUSIO_READ_MISO()) |
214 | 214 | reply |= b; |
215 | 215 | } |
216 | | - |
| 216 | + |
217 | 217 | BUSIO_SET_CLOCK_LOW(); |
218 | | - |
| 218 | + |
219 | 219 | } else if (_dataMode == SPI_MODE3) { |
220 | | - |
221 | | - if (_mosi != -1) { // transmit on falling edge |
| 220 | + |
| 221 | + if (_mosi != -1) { // transmit on falling edge |
222 | 222 | BUSIO_WRITE_MOSI(send & b); |
223 | 223 | } |
224 | | - |
| 224 | + |
225 | 225 | BUSIO_SET_CLOCK_LOW(); |
226 | | - |
| 226 | + |
227 | 227 | if (bitdelay_us) { |
228 | 228 | delayMicroseconds(bitdelay_us); |
229 | 229 | } |
230 | | - |
| 230 | + |
231 | 231 | BUSIO_SET_CLOCK_HIGH(); |
232 | | - |
| 232 | + |
233 | 233 | if (bitdelay_us) { |
234 | 234 | delayMicroseconds(bitdelay_us); |
235 | 235 | } |
236 | | - |
237 | | - if (_miso != -1) { // read on rising edge |
| 236 | + |
| 237 | + if (_miso != -1) { // read on rising edge |
238 | 238 | if (BUSIO_READ_MISO()) { |
239 | 239 | reply |= b; |
240 | 240 | } |
241 | 241 | } |
242 | | - |
243 | | - } else { // || _dataMode == SPI_MODE1) |
244 | | - |
| 242 | + |
| 243 | + } else { // || _dataMode == SPI_MODE1) |
| 244 | + |
245 | 245 | BUSIO_SET_CLOCK_HIGH(); |
246 | | - |
| 246 | + |
247 | 247 | if (bitdelay_us) { |
248 | 248 | delayMicroseconds(bitdelay_us); |
249 | 249 | } |
250 | | - |
| 250 | + |
251 | 251 | if (_mosi != -1) { |
252 | 252 | BUSIO_WRITE_MOSI(send & b); |
253 | 253 | } |
254 | | - |
| 254 | + |
255 | 255 | BUSIO_SET_CLOCK_LOW(); |
256 | | - |
| 256 | + |
257 | 257 | if (_miso != -1) { |
258 | 258 | if (BUSIO_READ_MISO()) { |
259 | 259 | reply |= b; |
|
0 commit comments