2009-10-12 14:52:26 +00:00
|
|
|
/**
|
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Roel Verdult
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*
|
2009-11-10 09:47:59 +00:00
|
|
|
* @file pn531_usb.c
|
|
|
|
* @brief Driver for PN531 chip using USB
|
2009-10-12 14:52:26 +00:00
|
|
|
*/
|
2009-04-29 12:51:13 +00:00
|
|
|
|
2009-06-26 09:05:25 +00:00
|
|
|
/*
|
|
|
|
Thanks to d18c7db and Okko for example code
|
2009-04-29 12:51:13 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-10 09:47:59 +00:00
|
|
|
#include "../drivers.h"
|
2009-12-07 21:13:36 +00:00
|
|
|
#include <nfc/nfc-messages.h>
|
2009-04-29 12:51:13 +00:00
|
|
|
|
2009-12-07 21:13:36 +00:00
|
|
|
nfc_device_desc_t * pn531_usb_pick_device (void)
|
|
|
|
{
|
|
|
|
nfc_device_desc_t *pndd;
|
|
|
|
|
|
|
|
if ((pndd = malloc (sizeof (*pndd)))) {
|
|
|
|
size_t szN;
|
|
|
|
|
|
|
|
if (!pn531_usb_list_devices (pndd, 1, &szN)) {
|
|
|
|
DBG("%s", "pn531_usb_list_devices failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (szN == 0) {
|
|
|
|
DBG("%s", "No device found");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pndd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pn531_usb_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound)
|
2009-09-04 13:24:34 +00:00
|
|
|
{
|
2009-04-29 12:51:13 +00:00
|
|
|
int idvendor = 0x04CC;
|
|
|
|
int idproduct = 0x0531;
|
2009-06-11 09:12:00 +00:00
|
|
|
int idvendor_alt = 0x054c;
|
|
|
|
int idproduct_alt = 0x0193;
|
2009-04-29 12:51:13 +00:00
|
|
|
|
2009-12-07 21:13:36 +00:00
|
|
|
size_t firstpass = 0;
|
|
|
|
|
|
|
|
pn53x_usb_list_devices(&pnddDevices[0], szDevices, pszDeviceFound, idvendor, idproduct, PN531_USB_DRIVER_NAME);
|
|
|
|
if(*pszDeviceFound == szDevices)
|
2009-12-07 22:18:32 +00:00
|
|
|
{
|
|
|
|
DBG("Found %d devices",*pszDeviceFound);
|
2009-12-07 21:13:36 +00:00
|
|
|
return true;
|
2009-12-07 22:18:32 +00:00
|
|
|
}
|
2009-12-07 21:13:36 +00:00
|
|
|
firstpass= *pszDeviceFound;
|
2009-12-07 22:18:32 +00:00
|
|
|
pn53x_usb_list_devices(&pnddDevices[firstpass], szDevices - firstpass, pszDeviceFound, idvendor_alt, idproduct_alt, PN531_USB_DRIVER_NAME);
|
2009-12-07 21:13:36 +00:00
|
|
|
(*pszDeviceFound) += firstpass;
|
|
|
|
|
|
|
|
DBG("Found %d devices",*pszDeviceFound);
|
|
|
|
if(*pszDeviceFound)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-29 12:51:13 +00:00
|
|
|
|
2009-12-07 21:13:36 +00:00
|
|
|
nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
|
|
|
|
{
|
|
|
|
return(pn53x_usb_connect(pndd, PN531_USB_DRIVER_NAME, NC_PN531));
|
2009-09-04 13:24:34 +00:00
|
|
|
}
|