Hardware abstraction layer for libnfc:

Suppress any PN53x references in nfc.c
Improve nfc_driver_t struct to embedded HAL API
Merge macros from nfc-messages.h into nfc-internal.h
Remove useless files: nfc-messages.h, buses.h and chips.h
Implement HAL for ARYGON driver
Move send/receive callbacks from nfc_driver_t to internal chip io callbacks (since there are dedicated to pn53x framing)
This commit is contained in:
Romuald Conty 2011-03-05 10:06:52 +00:00
parent 9b202d1dbf
commit 0efa47880b
17 changed files with 153 additions and 178 deletions

View file

@ -20,10 +20,12 @@
*/
/**
* @file pn53x.h
* @file pn53x.c
* @brief PN531, PN532 and PN533 common functions
*/
/* vim:set ts=2 sw=2 et: */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H
@ -34,7 +36,6 @@
#include <stdlib.h>
#include <nfc/nfc.h>
#include <nfc/nfc-messages.h>
#include "pn53x.h"
#include "pn53x-internal.h"
@ -47,6 +48,8 @@
#include <sys/param.h>
// TODO: reorder functions according to header
// TODO: Count max bytes for InJumpForDEP reply
const byte_t pncmd_initiator_jump_for_dep[68] = { 0xD4, 0x56 };
@ -134,9 +137,9 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b
}
// Call the send/receice callback functions of the current driver
if (!pnd->driver->send (pnd, pbtTx, szTx))
if (!((struct pn53x_data*)(pnd->chip_data))->io->send (pnd, pbtTx, szTx))
return false;
int res = pnd->driver->receive (pnd, pbtRx, *pszRx);
int res = ((struct pn53x_data*)(pnd->chip_data))->io->receive (pnd, pbtRx, *pszRx);
if (res < 0) {
return false;
}
@ -490,6 +493,19 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ
return true;
}
bool
pn53x_initiator_init (nfc_device_t * pnd)
{
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
if (!pn53x_write_register (pnd, REG_CIU_TX_AUTO, SYMBOL_FORCE_100_ASK, 0x40))
return false;
// Configure the PN53X to be an Initiator or Reader/Writer
if (!pn53x_write_register (pnd, REG_CIU_CONTROL, SYMBOL_INITIATOR, 0x10))
return false;
return true;
}
bool
pn53x_initiator_select_passive_target (nfc_device_t * pnd,
const nfc_modulation_t nm,
@ -548,6 +564,11 @@ pn53x_initiator_poll_targets (nfc_device_t * pnd,
return pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, btPollNr, btPeriod, pntTargets, pszTargetFound);
}
bool
pn53x_initiator_deselect_target (nfc_device_t * pnd)
{
return (pn53x_InDeselect (pnd, 0)); // 0 mean deselect all selected targets
}
/**
* @brief C wrapper to InListPassiveTarget command

View file

@ -93,7 +93,6 @@
# define DENACK 0x0100/* NACK */
# define DEACKMISMATCH 0x0200/* Unexpected data */
# define DEISERRFRAME 0x0300/* Error frame */
# define DENOTSUP 0x0400/* Not supported */
typedef enum {
PN531 = 0x01,
@ -107,12 +106,17 @@ typedef enum {
EXECUTE = 0x02, // Need to cancel the running command to process new one
} pn53x_state;
struct pn53x_io {
bool (*send)(nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
int (*receive)(nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen);
};
struct pn53x_data {
pn53x_type type;
pn53x_state state;
const struct pn53x_io * io;
};
/* PN53x specific types */
/**
* @enum pn53x_modulation_t
@ -197,8 +201,7 @@ typedef enum {
bool pn53x_init(nfc_device_t * pnd);
bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx);
bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value);
bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
bool pn53x_set_parameters (nfc_device_t * pnd, const uint8_t ui8Value, const bool bEnable);
bool pn53x_set_tx_bits (nfc_device_t * pnd, const uint8_t ui8Bits);
bool pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtFrame,
@ -208,11 +211,14 @@ bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, b
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData,
pn53x_type chip_type, nfc_modulation_type_t nmt,
nfc_target_info_t * pnti);
bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value);
bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
bool pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18]);
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
bool pn53x_check_communication (nfc_device_t *pnd);
// NFC device as Initiator functions
bool pn53x_initiator_init (nfc_device_t * pnd);
bool pn53x_initiator_select_passive_target (nfc_device_t * pnd,
const nfc_modulation_t nm,
const byte_t * pbtInitData, const size_t szInitData,
@ -230,6 +236,8 @@ bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtT
byte_t * pbtRxPar);
bool pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx,
byte_t * pbtRx, size_t * pszRx);
bool pn53x_initiator_deselect_target (nfc_device_t * pnd);
// NFC device as Target functions
bool pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx);
bool pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);