Implementation of PN532 NFC reader#5573
Conversation
|
Assigned myself for now, support is pretty much welcome. We have these modules available in the HAW, so if anyone from here volunteers to do some testing, go ahead ;-). @thomaseichinger you've been involved in #2692. Do you find time to take care of this PR? |
| #define LOG_LEVEL LOG_INFO | ||
| #include "log.h" | ||
|
|
||
| #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
There was a problem hiding this comment.
This macro is never really used.
Sorry, wrong line.
|
@lebrush There seem to be a couple of functions that are never used. Are those meant to improve functionality at some later point? |
|
@thomaseichinger @PeterKietzmann we have only this [1] PN532 module at the HAW. |
|
@lebrush please provide a |
|
@BytesGalore thx! true story: I forgot the Makefile 👍 |
|
@thomaseichinger @BytesGalore, I just addressed your comments |
|
@thomaseichinger, do you think you could find some time during the next days for testing? |
|
@OlegHahm I'm planning to, will have to borrow a board to connect the
pn532 to though.
|
| * @param[in] dev target device | ||
| * @param[in] params configuration parameters | ||
| * | ||
| * @return 0 on success |
There was a problem hiding this comment.
I would vote to give a word on the possible non-success values, e.g.:
@return -1 on undefined device given (I2C)
@return -2 on unsupported speed value (I2C)
There was a problem hiding this comment.
👍
edit: see line below
|
Let's hope Murdock is now happy |
|
Murdock is happy. @PeterKietzmann should this a candidate for 2017.01 ? |
If it's merged it's merged ;-) |
|
Tested I2C and SPI mode successfully. Code is also in good shape. @lebrush can you squash your commits? |
|
@cgundogan thanks for testing it! 🎉 I just squashed and left the meaningful ones :-) |
|
@lebrush thanks! (: let's wait for Murdock now and merge as soon as it turns green. |
|
cppcheck found some issues and some of the Cortex-M0 ports fail. |
|
@OlegHahm why tries to compile it if the Compiling it manually returns: "There are unsatisfied feature requirements: periph_i2c. Expect Errors" |
|
The error of cppcheck: Running './dist/tools/cppcheck/check.sh master --diff-filter=AC' x
Command output:
drivers/pn532/pn532.c:135: style (knownConditionTrueFalse): Condition 'ret==0' is always falseRefers to the code: int ret = -1;
(...)
if (mode == PN532_I2C) {
#ifdef PN532_SUPPORT_I2C
ret = i2c_init_master(dev->conf->i2c, I2C_SPEED_FAST);
#endif
}
else {
#ifdef PN532_SUPPORT_SPI
ret = spi_init_master(dev->conf->spi, SPI_CONF_FIRST_RISING,
SPI_SPEED_1MHZ);
gpio_init(dev->conf->nss, GPIO_OUT);
gpio_set(dev->conf->nss);
#endif
}
--> if (ret == 0) {
pn532_reset(dev);
}Which does only apply when #if !defined(PN532_SUPPORT_I2C) && !defined(PN532_SUPPORT_SPI)
#error Please define PN532_SUPPORT_I2C and/or PN532_SUPPORT_SPI to enable \
the functionality on this device
#endifI would ignore this one otherwise please suggest how to fix it |
If so, please suppress the cppcheck warning with a corresponding reasoning (take #6024 as a reference about how to do this). |
|
@miri64 thanks! /* cppcheck-suppress knownConditionTrueFalse
* (reason: variable set when PN532_SUPPORT_{I2C,SPI} defined) */
if (ret == 0) {
pn532_reset(dev);
}Should do the trick right? What about the compilation on platforms which don't have |
|
This you should do in the build system AFAIK, using the FEATURE_REQUIRED macro. But better ask someone more knowledgable about drivers like @haukepetersen or @PeterKietzmann. |
tests/driver_pn532/Makefile
Outdated
| USEMODULE += pn532 | ||
|
|
||
| # set default device parameters in case they are undefined | ||
| TEST_PN532_I2C ?= I2C_0 |
There was a problem hiding this comment.
Use I2C_DEV\(0\) here! Should also fix build tests
There was a problem hiding this comment.
Thanks for the hint! done :-)
|
Oh and please squash all commits to one. |
This is a driver for the PN532 based on i2c we have been using for a while. The SPI protocol is very similar, making the driver work with both should not be difficult (mostly replacing the
_writeand_readmethods).The driver has been adapted to the "new" gpio API and to be able to handle multiple PN532 devices. I can't test these because I don't have the PN532 anymore... but they are small changes and should simply work...right? :-)
Related: #2692