chips/pn53x: add pn53x_data_new() function to alloc and init pn53x_data structure.

This commit is contained in:
Romuald Conty 2011-05-09 18:47:48 +00:00
parent ebb352f1f3
commit 95914345e1
7 changed files with 40 additions and 33 deletions

View file

@ -25,8 +25,6 @@
#ifndef __PN53X_INTERNAL_H__
#define __PN53X_INTERNAL_H__
#include "pn53x.h"
// Miscellaneous
#define Diagnose 0x00
#define GetFirmwareVersion 0x02
@ -118,11 +116,11 @@ typedef struct {
#endif
} pn53x_command;
/*
#define PN531 0x01
#define PN532 0x02
#define PN533 0X04
*/
typedef enum {
PN531 = 0x01,
PN532 = 0x02,
PN533 = 0x04
} pn53x_type;
#ifndef DEBUG
# define PNCMD( X, Y ) { X , Y }

View file

@ -67,12 +67,6 @@ pn53x_init(nfc_device_t * pnd)
return false;
}
// PN53x starts in initiator mode
CHIP_DATA (pnd)->operating_mode = INITIATOR;
// Set current target to NULL
CHIP_DATA (pnd)->current_target = NULL;
// CRC handling is enabled by default
pnd->bCrc = true;
// Parity handling is enabled by default
@ -500,8 +494,6 @@ pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18])
byte_t abtFw[4];
size_t szFwLen = sizeof (abtFw);
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen)) {
// Failed to get firmware revision??, whatever...let's disconnect and clean up and return err
// FIXME: Wtf?
return false;
}
// Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC
@ -2237,3 +2229,22 @@ pn53x_nm_to_ptt(const nfc_modulation_t nm)
}
return PTT_UNDEFINED;
}
void
pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io)
{
pnd->chip_data = malloc(sizeof(struct pn53x_data));
// Keep I/O functions
CHIP_DATA (pnd)->io = io;
// Set power mode to normal, if your device starts in LowVBat (ie. PN532
// UART) the driver layer have to correctly set it.
CHIP_DATA (pnd)->power_mode = NORMAL;
// PN53x starts in initiator mode
CHIP_DATA (pnd)->operating_mode = INITIATOR;
// Set current target to NULL
CHIP_DATA (pnd)->current_target = NULL;
}

View file

@ -28,6 +28,7 @@
# define __NFC_CHIPS_PN53X_H__
# include <nfc/nfc-types.h>
# include "pn53x-internal.h"
// TODO Remove double register address defines
// Registers and symbols masks used to covers parts within a register
@ -133,12 +134,6 @@
# define DEACKMISMATCH 0x0200/* Unexpected data */
# define DEISERRFRAME 0x0300/* Error frame */
typedef enum {
PN531 = 0x01,
PN532 = 0x02,
PN533 = 0x04
} pn53x_type;
typedef enum {
NORMAL, // In that case, there is no power saved but the PN53x reacts as fast as possible on the host controller interface.
POWERDOWN, // Only on PN532, need to be wake up to process commands with a long preamble
@ -312,6 +307,7 @@ bool pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t *
bool pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar);
bool pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx);
// Error handling functions
const char *pn53x_strerror (const nfc_device_t * pnd);
@ -345,4 +341,6 @@ bool pn53x_check_ack_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, co
bool pn53x_check_error_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen);
bool pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData);
void pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io);
#endif // __NFC_CHIPS_PN53X_H__