From 36cc6884798da6e154efbf136212304d8574c3e2 Mon Sep 17 00:00:00 2001 From: uvos Date: Tue, 15 Mar 2022 22:41:06 +0100 Subject: [PATCH] softspim: allow phase mode 2 (safe phase) --- softspim.cpp | 8 ++++---- softspim.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/softspim.cpp b/softspim.cpp index a81fa4a..783e9d0 100644 --- a/softspim.cpp +++ b/softspim.cpp @@ -17,19 +17,19 @@ uint8_t SpiMaster::readWrite(uint8_t in) writePin(_port, _pinOut, in & (1 << i)); else writePin(_port, _pinOut, in & (1 << (7-i))); - if constexpr (CLOCK_PHASE == 0) + if constexpr (CLOCK_PHASE == 0 || CLOCK_PHASE == 2) _delay_us(DELAY_TIME_US); writePin(_port, _pinClock, !CLOCK_POLARITY); - if constexpr (CLOCK_PHASE == 1) + if constexpr (CLOCK_PHASE == 1 || CLOCK_PHASE == 2) _delay_us(DELAY_TIME_US); if constexpr (BIT_ORDER == 0) recByte |= readPin(_pinReg, _pinIn) << i; else recByte |= readPin(_pinReg, _pinIn) << (7-i); - if constexpr (CLOCK_PHASE == 0) + if constexpr (CLOCK_PHASE == 0 || CLOCK_PHASE == 2) _delay_us(DELAY_TIME_US); writePin(_port, _pinClock, CLOCK_POLARITY); - if constexpr (CLOCK_PHASE == 1) + if constexpr (CLOCK_PHASE == 1 || CLOCK_PHASE == 2) _delay_us(DELAY_TIME_US); } return recByte; diff --git a/softspim.h b/softspim.h index c937bc3..5fc732e 100644 --- a/softspim.h +++ b/softspim.h @@ -7,7 +7,7 @@ class SpiMaster private: static constexpr uint8_t CLOCK_POLARITY = 0; - static constexpr uint8_t CLOCK_PHASE = 0; + static constexpr uint8_t CLOCK_PHASE = 2; static constexpr uint8_t BIT_ORDER = 1; volatile uint8_t * const _port = &PORTB;