mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-18 03:00:58 +08:00
chg: i2c - don't mix different communications layers when reporting data back
This commit is contained in:
parent
ba1ccf1994
commit
ef318b56ec
1 changed files with 22 additions and 27 deletions
47
common/i2c.c
47
common/i2c.c
|
@ -170,18 +170,6 @@ bool I2C_WaitForSim() {
|
|||
}
|
||||
|
||||
// send i2c STOP
|
||||
/*
|
||||
void I2C_Stop(void) {
|
||||
SCL_L; I2C_DELAY_2CLK;
|
||||
SDA_L; I2C_DELAY_2CLK;
|
||||
SCL_H; I2C_DELAY_2CLK;
|
||||
SDA_H;
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
}
|
||||
*/
|
||||
void I2C_Stop(void) {
|
||||
SCL_L; I2C_DELAY_2CLK;
|
||||
SDA_L; I2C_DELAY_2CLK;
|
||||
|
@ -371,9 +359,9 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
|||
// extra wait 500us (514us measured)
|
||||
// 200us (xx measured)
|
||||
SpinDelayUs(200);
|
||||
|
||||
bool bBreak = true;
|
||||
uint8_t readcount = 0;
|
||||
|
||||
do {
|
||||
if (!I2C_Start())
|
||||
return 0;
|
||||
|
@ -404,20 +392,26 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
|||
|
||||
// reading
|
||||
while (len) {
|
||||
len--;
|
||||
*data = I2C_ReadByte();
|
||||
// 读取的第一个字节为后续长度
|
||||
// The first byte read is the message length
|
||||
if (!readcount && (len > *data))
|
||||
len = *data;
|
||||
|
||||
*data = I2C_ReadByte();
|
||||
|
||||
len--;
|
||||
|
||||
// 读取的第一个字节为后续长度
|
||||
// The first byte in response is the message length
|
||||
if (!readcount && (len > *data)) {
|
||||
if ( MF_DBGLEVEL > 3 ) Dbprintf("Old len %d , Repsonse message len %d", len, *data);
|
||||
len = *data;
|
||||
} else {
|
||||
data++;
|
||||
}
|
||||
readcount++;
|
||||
|
||||
// acknowledgements. After last byte send NACK.
|
||||
if (len == 0)
|
||||
I2C_NoAck();
|
||||
else
|
||||
I2C_Ack();
|
||||
|
||||
data++;
|
||||
readcount++;
|
||||
}
|
||||
|
||||
I2C_Stop();
|
||||
|
@ -466,16 +460,17 @@ uint8_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t
|
|||
|
||||
// reading
|
||||
while (len) {
|
||||
len--;
|
||||
*data = I2C_ReadByte();
|
||||
|
||||
data++;
|
||||
readcount++;
|
||||
len--;
|
||||
|
||||
// acknowledgements. After last byte send NACK.
|
||||
if (len == 0)
|
||||
I2C_NoAck();
|
||||
else
|
||||
I2C_Ack();
|
||||
|
||||
data++;
|
||||
readcount++;
|
||||
}
|
||||
|
||||
I2C_Stop();
|
||||
|
|
Loading…
Reference in a new issue