Clean up and add some debug msg on ReadRegister/WriteRegister
This commit is contained in:
parent
25e2dbec95
commit
ebb352f1f3
1 changed files with 32 additions and 26 deletions
|
@ -443,46 +443,52 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value)
|
pn53x_ReadRegister (nfc_device_t * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value)
|
||||||
{
|
{
|
||||||
byte_t abtCmd[] = { ReadRegister, ui16Reg >> 8, ui16Reg & 0xff };
|
byte_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff };
|
||||||
byte_t abtRegValue[2];
|
byte_t abtRegValue[2];
|
||||||
size_t szRegValue = sizeof (abtRegValue);
|
size_t szRegValue = sizeof (abtRegValue);
|
||||||
|
|
||||||
PNREG_DBG (ui16Reg);
|
DBG ("ReadRegister (%04x)", ui16RegisterAddress);
|
||||||
|
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, &szRegValue)) {
|
||||||
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, &szRegValue)) {
|
|
||||||
if (CHIP_DATA(pnd)->type == PN533) {
|
|
||||||
// PN533 prepends its answer by a status byte
|
|
||||||
if (abtRegValue[0] == 0x00) {
|
|
||||||
*ui8Value = abtRegValue[1];
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (CHIP_DATA(pnd)->type == PN533) {
|
||||||
|
// PN533 prepends its answer by a status byte
|
||||||
|
*ui8Value = abtRegValue[1];
|
||||||
} else {
|
} else {
|
||||||
*ui8Value = abtRegValue[0];
|
*ui8Value = abtRegValue[0];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value)
|
||||||
|
{
|
||||||
|
return pn53x_ReadRegister (pnd, ui16RegisterAddress, ui8Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_write_register (nfc_device_t * pnd, const uint16_t ui16Reg, const uint8_t ui8SymbolMask, const uint8_t ui8Value)
|
pn53x_WriteRegister (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8Value)
|
||||||
{
|
{
|
||||||
byte_t abtCmd[] = { WriteRegister, ui16Reg >> 8, ui16Reg & 0xff, 0x00 };
|
byte_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value };
|
||||||
|
PNREG_DBG (ui16RegisterAddress);
|
||||||
if (ui8SymbolMask != 0xff) {
|
DBG ("WriteRegister (%04x, %02x)", ui16RegisterAddress, ui8Value);
|
||||||
uint8_t ui8Current;
|
|
||||||
if (!pn53x_read_register (pnd, ui16Reg, &ui8Current))
|
|
||||||
return false;
|
|
||||||
abtCmd[3] = ((ui8Value & ui8SymbolMask) | (ui8Current & (~ui8SymbolMask)));
|
|
||||||
if (abtCmd[3] != ui8Current) {
|
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pn53x_write_register (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8SymbolMask, const uint8_t ui8Value)
|
||||||
|
{
|
||||||
|
if (ui8SymbolMask != 0xff) {
|
||||||
|
uint8_t ui8CurrentValue;
|
||||||
|
if (!pn53x_read_register (pnd, ui16RegisterAddress, &ui8CurrentValue))
|
||||||
|
return false;
|
||||||
|
uint8_t ui8NewValue = ((ui8Value & ui8SymbolMask) | (ui8CurrentValue & (~ui8SymbolMask)));
|
||||||
|
if (ui8NewValue != ui8CurrentValue) {
|
||||||
|
return pn53x_WriteRegister (pnd, ui16RegisterAddress, ui8NewValue);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
abtCmd[3] = ui8Value;
|
return pn53x_WriteRegister (pnd, ui16RegisterAddress, ui8Value);
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue