From 9835768ca5fecdb70c96b5576563c19754f5260a Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Thu, 16 Feb 2012 11:22:43 +0100 Subject: [PATCH] PN532 updates --- ChangeLog.txt | 3 ++ Makefile | 5 +-- .../LPC1343 Workspace.workspace.session | 14 +++++--- build/codelite/LPC1343_CodeBase.project | 12 +++++-- build/crossworks/LPC1343_CodeBase.hzp | 4 ++- build/crossworks/LPC1343_CodeBase.hzs | 14 ++++---- core/i2c/i2c.c | 16 +++++----- core/i2c/i2c.h | 4 +-- drivers/sensors/pn532/helpers/pn532_mifare.h | 4 +-- .../pn532/helpers/pn532_mifare_classic.c | 3 +- .../pn532/helpers/pn532_mifare_ultralight.c | 32 ++----------------- drivers/sensors/pn532/pn532_bus_i2c.c | 2 -- projectconfig.h | 2 ++ 13 files changed, 55 insertions(+), 60 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 52bd28a..ecf050d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,8 @@ v0.9.8 - Ongoing ================ +- Added I2C driver for PN532 +- Updated and added PN532 examples at + /tools/examples/sensors/PN532 - updated touchscreen.h to be a bit clearer during calibration, though it can still be much better organised diff --git a/Makefile b/Makefile index 12f36ce..14e1c26 100644 --- a/Makefile +++ b/Makefile @@ -100,8 +100,9 @@ VPATH += drivers/dac/mcp4725 OBJS += mcp4725.o # RFID/NFC -VPATH += drivers/sensors/pn532 -OBJS += pn532.o +VPATH += drivers/sensors/pn532 drivers/sensors/pn532/helpers +OBJS += pn532.o pn532_bus_i2c.o pn532_bus_uart.o +OBJS += pn532_mifare_classic.o pn532_mifare_ultralight.o # TAOS Light Sensors VPATH += drivers/sensors/tcs3414 drivers/sensors/tsl2561 diff --git a/build/codelite/LPC1343 Workspace.workspace.session b/build/codelite/LPC1343 Workspace.workspace.session index 89b677c..a989bd8 100644 --- a/build/codelite/LPC1343 Workspace.workspace.session +++ b/build/codelite/LPC1343 Workspace.workspace.session @@ -3,16 +3,22 @@ + + + + + + - - + + - - + + diff --git a/build/codelite/LPC1343_CodeBase.project b/build/codelite/LPC1343_CodeBase.project index 54c13ef..1b12a41 100644 --- a/build/codelite/LPC1343_CodeBase.project +++ b/build/codelite/LPC1343_CodeBase.project @@ -132,8 +132,16 @@ - - + + + + + + + + + + diff --git a/build/crossworks/LPC1343_CodeBase.hzp b/build/crossworks/LPC1343_CodeBase.hzp index b5c6b47..d7f6d5d 100644 --- a/build/crossworks/LPC1343_CodeBase.hzp +++ b/build/crossworks/LPC1343_CodeBase.hzp @@ -171,7 +171,9 @@ - + + + diff --git a/build/crossworks/LPC1343_CodeBase.hzs b/build/crossworks/LPC1343_CodeBase.hzs index f56c47e..e894c45 100644 --- a/build/crossworks/LPC1343_CodeBase.hzs +++ b/build/crossworks/LPC1343_CodeBase.hzs @@ -18,7 +18,7 @@ - + @@ -33,9 +33,11 @@ - - - + + + + + @@ -71,7 +73,7 @@ - + - + diff --git a/core/i2c/i2c.c b/core/i2c/i2c.c index 2db915e..05bd4e2 100644 --- a/core/i2c/i2c.c +++ b/core/i2c/i2c.c @@ -216,8 +216,8 @@ void I2C_IRQHandler(void) ** Function name: I2CStart ** ** Descriptions: Create I2C start condition, a timeout -** value is set if the I2C never gets started, -** and timed out. It's a fatal error. +** value is set if the I2C never gets started, +** and timed out. It's a fatal error. ** ** parameters: None ** Returned value: true or false, return false if timed out @@ -269,7 +269,7 @@ static uint32_t I2CStop( void ) ** ** parameters: I2c mode is either MASTER or SLAVE ** Returned value: true or false, return false if the I2C -** interrupt handler was not installed correctly +** interrupt handler was not installed correctly ** *****************************************************************************/ uint32_t i2cInit( uint32_t I2cMode ) @@ -320,11 +320,11 @@ uint32_t i2cInit( uint32_t I2cMode ) ** Function name: I2CEngine ** ** Descriptions: The routine to complete a I2C transaction -** from start to stop. All the intermitten -** steps are handled in the interrupt handler. -** Before this routine is called, the read -** length, write length and I2C master buffer -** need to be filled. +** from start to stop. All the intermitten +** steps are handled in the interrupt handler. +** Before this routine is called, the read +** length, write length and I2C master buffer +** need to be filled. ** ** parameters: None ** Returned value: Any of the I2CSTATE_... values. See i2c.h diff --git a/core/i2c/i2c.h b/core/i2c/i2c.h index ff1e224..63b01e8 100644 --- a/core/i2c/i2c.h +++ b/core/i2c/i2c.h @@ -75,8 +75,8 @@ Fast Mode (400KHz) = CFG_CPU_CCLK / 800000 Fast- Mode Plus (1MHz) = CFG_CPU_CCLK / 2000000 */ -#define I2SCLH_SCLH CFG_CPU_CCLK / 800000 /* Standard Mode I2C SCL Duty Cycle High (400KHz) */ -#define I2SCLL_SCLL CFG_CPU_CCLK / 800000 /* Fast Mode I2C SCL Duty Cycle Low (400KHz) */ +#define I2SCLH_SCLH CFG_CPU_CCLK / 200000 /* Standard Mode I2C SCL Duty Cycle High (400KHz) */ +#define I2SCLL_SCLL CFG_CPU_CCLK / 200000 /* Fast Mode I2C SCL Duty Cycle Low (400KHz) */ #define I2SCLH_HS_SCLH CFG_CPU_CCLK / 2000000 /* Fast Plus I2C SCL Duty Cycle High Reg */ #define I2SCLL_HS_SCLL CFG_CPU_CCLK / 2000000 /* Fast Plus I2C SCL Duty Cycle Low Reg */ diff --git a/drivers/sensors/pn532/helpers/pn532_mifare.h b/drivers/sensors/pn532/helpers/pn532_mifare.h index fedebeb..94d2c2e 100644 --- a/drivers/sensors/pn532/helpers/pn532_mifare.h +++ b/drivers/sensors/pn532/helpers/pn532_mifare.h @@ -10,8 +10,8 @@ #include "projectconfig.h" // These may need to be enlarged for multi card support -#define PN532_RESPONSELEN_INLISTPASSIVETARGET (32) -#define PN532_RESPONSELEN_INDATAEXCHANGE (32) +#define PN532_RESPONSELEN_INLISTPASSIVETARGET (64) +#define PN532_RESPONSELEN_INDATAEXCHANGE (64) typedef enum pn532_mifare_cmd_e { diff --git a/drivers/sensors/pn532/helpers/pn532_mifare_classic.c b/drivers/sensors/pn532/helpers/pn532_mifare_classic.c index ece672e..debf834 100644 --- a/drivers/sensors/pn532/helpers/pn532_mifare_classic.c +++ b/drivers/sensors/pn532/helpers/pn532_mifare_classic.c @@ -253,7 +253,8 @@ pn532_error_t pn532_mifareclassic_WaitForPassiveTarget (byte_t * pbtCUID, size_t { /* Card appears to be Mifare Classic */ *szCUIDLen = abtResponse[12]; - for (uint8_t i=0; i < *szCUIDLen; i++) + uint8_t i; + for (i=0; i < *szCUIDLen; i++) { pbtCUID[i] = abtResponse[13+i]; } diff --git a/drivers/sensors/pn532/helpers/pn532_mifare_ultralight.c b/drivers/sensors/pn532/helpers/pn532_mifare_ultralight.c index 1b4007a..0876101 100644 --- a/drivers/sensors/pn532/helpers/pn532_mifare_ultralight.c +++ b/drivers/sensors/pn532/helpers/pn532_mifare_ultralight.c @@ -153,7 +153,8 @@ pn532_error_t pn532_mifareultralight_WaitForPassiveTarget (byte_t * pbtCUID, siz { /* Card appears to be Mifare Ultralight */ *szCUIDLen = abtResponse[12]; - for (uint8_t i=0; i < *szCUIDLen; i++) + uint8_t i; + for (i=0; i < *szCUIDLen; i++) { pbtCUID[i] = abtResponse[13+i]; } @@ -283,32 +284,3 @@ pn532_error_t pn532_mifareultralight_ReadPage (uint8_t page, byte_t * pbtBuffer) return PN532_ERROR_NONE; } -//static bool -//read_card (void) -//{ -// uint32_t page; -// bool bFailure = false; -// uint32_t uiReadedPages = 0; -// -// printf ("Reading %d pages |", uiBlocks + 1); -// -// for (page = 0; page <= uiBlocks; page += 4) { -// // Try to read out the data block -// if (nfc_initiator_mifare_cmd (pnd, MC_READ, page, &mp)) { -// memcpy (mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 16); -// } else { -// bFailure = true; -// break; -// } -// -// print_success_or_failure (bFailure, &uiReadedPages); -// print_success_or_failure (bFailure, &uiReadedPages); -// print_success_or_failure (bFailure, &uiReadedPages); -// print_success_or_failure (bFailure, &uiReadedPages); -// } -// printf ("|\n"); -// printf ("Done, %d of %d pages readed.\n", uiReadedPages, uiBlocks + 1); -// fflush (stdout); -// -// return (!bFailure); -//} diff --git a/drivers/sensors/pn532/pn532_bus_i2c.c b/drivers/sensors/pn532/pn532_bus_i2c.c index 024fdfd..1f73624 100644 --- a/drivers/sensors/pn532/pn532_bus_i2c.c +++ b/drivers/sensors/pn532/pn532_bus_i2c.c @@ -197,7 +197,6 @@ pn532_error_t pn532_bus_SendCommand(const byte_t * pbtData, const size_t szData) { pn532_error_t error = PN532_ERROR_NONE; pn532_pcb_t *pn532 = pn532GetPCB(); - uint32_t ready_timeout = 0; // Check if we're busy if (pn532->state == PN532_STATE_BUSY) @@ -405,7 +404,6 @@ pn532_error_t pn532_bus_ReadResponse(byte_t * pbtResponse, size_t * pszRxLen) /**************************************************************************/ pn532_error_t pn532_bus_Wakeup(void) { - size_t szLen; pn532_error_t error = PN532_ERROR_NONE; byte_t abtWakeUp[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00 }; uint32_t i; diff --git a/projectconfig.h b/projectconfig.h index e677c80..2eb55c0 100644 --- a/projectconfig.h +++ b/projectconfig.h @@ -144,6 +144,7 @@ SSD1306 . . . . X X X . X X . . . . . . . SSD1351 . . . . X X X X X . . . . . . . . MCP121 . . . . . . . . . . . . . . X . . + PN532 [3] . . . . . . . . . . . . . . X X . TIMERS SSP ADC UART ====================== === ======= ==== @@ -166,6 +167,7 @@ can safely be used by other peripherals, but may need to be reconfigured when you wakeup from deep-sleep. [2] INTERFACE can be configured to use either USBCDC or UART + [3] 3.2 only used when with the I2C bus (for IRQ) **************************************************************************/ -- 2.20.1