mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
in prep for new firmware, no old v3xxx supported anymore
This commit is contained in:
parent
d8817f2cb2
commit
bf7ac0b8ce
1 changed files with 34 additions and 34 deletions
42
armsrc/i2c.c
42
armsrc/i2c.c
|
@ -502,13 +502,13 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uint8_t *pd = data;
|
||||||
|
|
||||||
// extra wait 500us (514us measured)
|
// extra wait 500us (514us measured)
|
||||||
// 200us (xx measured)
|
// 200us (xx measured)
|
||||||
WaitUS(600);
|
WaitUS(600);
|
||||||
|
|
||||||
bool _break = true;
|
bool _break = true;
|
||||||
uint16_t readcount = 0;
|
|
||||||
uint16_t recv_len = 0;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (I2C_Start() == false) {
|
if (I2C_Start() == false) {
|
||||||
|
@ -529,7 +529,6 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||||
// 0xB1 / 0xC1 == i2c read
|
// 0xB1 / 0xC1 == i2c read
|
||||||
I2C_Start();
|
I2C_Start();
|
||||||
I2C_SendByte(device_address | 1);
|
I2C_SendByte(device_address | 1);
|
||||||
|
|
||||||
if (I2C_WaitAck() == false) {
|
if (I2C_WaitAck() == false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -543,6 +542,9 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t readcount = 0;
|
||||||
|
uint16_t recv_len = 0;
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
|
|
||||||
int16_t tmp = I2C_ReadByte();
|
int16_t tmp = I2C_ReadByte();
|
||||||
|
@ -555,14 +557,13 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
// Starting firmware v4 the length is encoded on the first two bytes.
|
// Starting firmware v4 the length is encoded on the first two bytes.
|
||||||
// This only applies if command is I2C_DEVICE_CMD_READ.
|
|
||||||
if (device_cmd == I2C_DEVICE_CMD_READ) {
|
|
||||||
switch (readcount) {
|
switch (readcount) {
|
||||||
case 0:
|
case 0: {
|
||||||
// Length (MSB)
|
// Length (MSB)
|
||||||
recv_len = (*data) << 8;
|
recv_len = (*data) << 8;
|
||||||
break;
|
break;
|
||||||
case 1:
|
}
|
||||||
|
case 1: {
|
||||||
// Length (LSB)
|
// Length (LSB)
|
||||||
recv_len += *data;
|
recv_len += *data;
|
||||||
// Adjust len if needed
|
// Adjust len if needed
|
||||||
|
@ -570,36 +571,35 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||||
len = recv_len;
|
len = recv_len;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
// Data byte received
|
// Data byte received
|
||||||
data++;
|
data++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Length is encoded on 1 byte
|
|
||||||
if ((readcount == 0) && (len > *data)) {
|
|
||||||
len = *data;
|
|
||||||
} else {
|
|
||||||
data++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readcount++;
|
readcount++;
|
||||||
|
|
||||||
// acknowledgements. After last byte send NACK.
|
// acknowledgements. After last byte send NACK.
|
||||||
if (len == 0)
|
if (len == 0) {
|
||||||
I2C_NoAck();
|
I2C_NoAck();
|
||||||
else
|
} else {
|
||||||
I2C_Ack();
|
I2C_Ack();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
|
|
||||||
// return bytecount - bytes encoding length
|
// Dbprintf("rec len... %u readcount... %u", recv_len, readcount);
|
||||||
if (device_cmd == I2C_DEVICE_CMD_READ) {
|
// Dbhexdump(readcount, pd, false);
|
||||||
return readcount - 2;
|
|
||||||
|
if (readcount < 2 ) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return readcount - 1;
|
// return bytecount - bytes encoding length
|
||||||
|
return readcount - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
|
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue