@@ -40,8 +40,8 @@ extern "C" {
40
40
{
41
41
GPEC = (1 << twi_sda);
42
42
}
43
- static inline __attribute__ ((always_inline)) bool SDA_READ(const int twi_sda)
44
- {
43
+ static inline __attribute__ ((always_inline)) bool SDA_READ(const int twi_sda)
44
+ {
45
45
return (GPI & (1 << twi_sda)) != 0 ;
46
46
}
47
47
static inline __attribute__ ((always_inline)) void SCL_LOW(const int twi_scl)
@@ -52,8 +52,8 @@ extern "C" {
52
52
{
53
53
GPEC = (1 << twi_scl);
54
54
}
55
- static inline __attribute__ ((always_inline)) bool SCL_READ(const int twi_scl)
56
- {
55
+ static inline __attribute__ ((always_inline)) bool SCL_READ(const int twi_scl)
56
+ {
57
57
return (GPI & (1 << twi_scl)) != 0 ;
58
58
}
59
59
@@ -160,22 +160,22 @@ static Twi twi;
160
160
161
161
void Twi::setClock (unsigned int freq)
162
162
{
163
- if (freq < 250 ) // minimum freq 250Hz to prevent overflow @ 232Hz
164
- freq = 250 ;
165
-
166
- preferred_si2c_clock = freq;
163
+ if (freq < 250 ) // minimum freq 250Hz to prevent overflow @ 232Hz
164
+ freq = 250 ;
165
+
166
+ preferred_si2c_clock = freq;
167
167
168
168
#if F_CPU == FCPU80
169
169
170
170
if (freq > 400000 )
171
- freq = 400000 ;
171
+ freq = 400000 ;
172
172
twi_dcount = (500000000 / freq); // half-cycle period in ns
173
173
twi_dcount = (1000 *(twi_dcount - 1120 )) / 62500 ; // (half cycle - overhead) / busywait loop time
174
-
174
+
175
175
#else
176
176
177
- if (freq > 800000 )
178
- freq = 800000 ;
177
+ if (freq > 800000 )
178
+ freq = 800000 ;
179
179
twi_dcount = (500000000 / freq); // half-cycle period in ns
180
180
twi_dcount = (1000 *(twi_dcount - 560 )) / 31250 ; // (half cycle - overhead) / busywait loop time
181
181
@@ -226,7 +226,7 @@ void Twi::enableSlave()
226
226
unsigned int i;
227
227
for (i = 0 ; i < v; i++) // loop time is 5 machine cycles: 31.25ns @ 160MHz, 62.5ns @ 80MHz
228
228
{
229
- asm (" nop" ); // minimum element to keep GCC from optimizing this function out.
229
+ asm (" nop" ); // minimum element to keep GCC from optimizing this function out.
230
230
}
231
231
}
232
232
@@ -472,14 +472,14 @@ void ICACHE_RAM_ATTR Twi::reply(uint8_t ack)
472
472
if (ack)
473
473
{
474
474
// TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
475
- SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
476
- twi_ack = 1 ; // _BV(TWEA)
475
+ SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
476
+ twi_ack = 1 ; // _BV(TWEA)
477
477
}
478
478
else
479
479
{
480
480
// TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
481
- SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
482
- twi_ack = 0 ; // ~_BV(TWEA)
481
+ SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
482
+ twi_ack = 0 ; // ~_BV(TWEA)
483
483
}
484
484
}
485
485
@@ -488,8 +488,8 @@ void ICACHE_RAM_ATTR Twi::releaseBus(void)
488
488
{
489
489
// release bus
490
490
// TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);
491
- SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
492
- twi_ack = 1 ; // _BV(TWEA)
491
+ SCL_HIGH (twi.twi_scl ); // _BV(TWINT)
492
+ twi_ack = 1 ; // _BV(TWEA)
493
493
SDA_HIGH (twi.twi_sda );
494
494
495
495
// update twi state
@@ -660,11 +660,11 @@ void ICACHE_RAM_ATTR Twi::onSclChange(void)
660
660
unsigned int scl;
661
661
662
662
// Store bool return in int to reduce final code size.
663
-
663
+
664
664
sda = SDA_READ (twi.twi_sda );
665
665
scl = SCL_READ (twi.twi_scl );
666
666
667
- twi.twip_status = 0xF8 ; // reset TWI status
667
+ twi.twip_status = 0xF8 ; // reset TWI status
668
668
669
669
int twip_state_mask = S2M (twi.twip_state );
670
670
IFSTATE (S2M (TWIP_START) | S2M (TWIP_REP_START) | S2M (TWIP_SLA_W) | S2M (TWIP_READ))
@@ -739,7 +739,7 @@ void ICACHE_RAM_ATTR Twi::onSclChange(void)
739
739
}
740
740
else
741
741
{
742
- SCL_LOW (twi.twi_scl ); // clock stretching
742
+ SCL_LOW (twi.twi_scl ); // clock stretching
743
743
SDA_HIGH (twi.twi_sda );
744
744
twi.twip_mode = TWIPM_ADDRESSED;
745
745
if (!(twi.twi_data & 0x01 ))
@@ -757,7 +757,7 @@ void ICACHE_RAM_ATTR Twi::onSclChange(void)
757
757
}
758
758
else
759
759
{
760
- SCL_LOW (twi.twi_scl ); // clock stretching
760
+ SCL_LOW (twi.twi_scl ); // clock stretching
761
761
SDA_HIGH (twi.twi_sda );
762
762
if (!twi.twi_ack )
763
763
{
@@ -835,7 +835,7 @@ void ICACHE_RAM_ATTR Twi::onSclChange(void)
835
835
}
836
836
else
837
837
{
838
- SCL_LOW (twi.twi_scl ); // clock stretching
838
+ SCL_LOW (twi.twi_scl ); // clock stretching
839
839
if (twi.twi_ack && twi.twi_ack_rec )
840
840
{
841
841
twi.onTwipEvent (TW_ST_DATA_ACK);
@@ -881,7 +881,7 @@ void ICACHE_RAM_ATTR Twi::onSdaChange(void)
881
881
else IFSTATE (S2M (TWIP_START) | S2M (TWIP_REP_START) | S2M (TWIP_SEND_ACK) | S2M (TWIP_WAIT_ACK) | S2M (TWIP_SLA_R) | S2M (TWIP_REC_ACK) | S2M (TWIP_READ_ACK) | S2M (TWIP_RWAIT_ACK) | S2M (TWIP_WRITE))
882
882
{
883
883
// START or STOP
884
- SDA_HIGH (twi.twi_sda ); // Should not be necessary
884
+ SDA_HIGH (twi.twi_sda ); // Should not be necessary
885
885
twi.onTwipEvent (TW_BUS_ERROR);
886
886
twi.twip_mode = TWIPM_WAIT;
887
887
twi.twip_state = TWIP_BUS_ERR;
@@ -891,7 +891,7 @@ void ICACHE_RAM_ATTR Twi::onSdaChange(void)
891
891
if (sda)
892
892
{
893
893
// STOP
894
- SCL_LOW (twi.twi_scl ); // clock stretching
894
+ SCL_LOW (twi.twi_scl ); // generates a low SCL pulse after STOP
895
895
ets_timer_disarm (&twi.timer );
896
896
twi.twip_state = TWIP_IDLE;
897
897
twi.twip_mode = TWIPM_IDLE;
@@ -925,7 +925,7 @@ void ICAC
623B
HE_RAM_ATTR Twi::onSdaChange(void)
925
925
else
926
926
{
927
927
// during first bit in byte transfer - ok
928
- SCL_LOW (twi.twi_scl ); // clock stretching
928
+ SCL_LOW (twi.twi_scl ); // clock stretching
929
929
twi.onTwipEvent (TW_SR_STOP);
930
930
if (sda)
931
931
{
0 commit comments