Skip to content

Implementation of PN532 NFC reader#5573

Merged
PeterKietzmann merged 1 commit intoRIOT-OS:masterfrom
lebrush:pn532
Jan 14, 2017
Merged

Implementation of PN532 NFC reader#5573
PeterKietzmann merged 1 commit intoRIOT-OS:masterfrom
lebrush:pn532

Conversation

@lebrush
Copy link
Copy Markdown
Member

@lebrush lebrush commented Jun 27, 2016

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 _write and _read methods).

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

@PeterKietzmann PeterKietzmann added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers labels Jun 27, 2016
@PeterKietzmann PeterKietzmann self-assigned this Jun 27, 2016
@PeterKietzmann
Copy link
Copy Markdown
Member

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))
Copy link
Copy Markdown
Member

@thomaseichinger thomaseichinger Jun 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro is never really used.
Sorry, wrong line.

@thomaseichinger
Copy link
Copy Markdown
Member

thomaseichinger commented Jun 28, 2016

@lebrush There seem to be a couple of functions that are never used. Are those meant to improve functionality at some later point?
Otherwise I think this is a great clean and slim driver! Congratulations.
@PeterKietzmann I won't find extensive time to test this driver, if any, can you take on that part?

@BytesGalore
Copy link
Copy Markdown
Member

@thomaseichinger @PeterKietzmann we have only this [1] PN532 module at the HAW.
Unfortunately it only provides UART communication and does not support for switching the communication modes to I2C or SPI :(

[1] http://www.dfrobot.com/index.php?route=product/product&product_id=892&search=nfc&description=true

@BytesGalore
Copy link
Copy Markdown
Member

@lebrush please provide a Makefile in RIOT/drivers/pn532

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jun 29, 2016

@BytesGalore thx! true story: I forgot the Makefile 👍

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jul 1, 2016

@thomaseichinger @BytesGalore, I just addressed your comments

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jul 14, 2016

@thomaseichinger @BytesGalore ping

@OlegHahm
Copy link
Copy Markdown
Member

@thomaseichinger, do you think you could find some time during the next days for testing?

@thomaseichinger
Copy link
Copy Markdown
Member

thomaseichinger commented Jul 18, 2016 via email

* @param[in] dev target device
* @param[in] params configuration parameters
*
* @return 0 on success
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

@lebrush lebrush Jul 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
edit: see line below

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Dec 13, 2016

Let's hope Murdock is now happy

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Dec 19, 2016

Murdock is happy. @PeterKietzmann should this a candidate for 2017.01 ?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 26, 2016

Murdock is happy. @PeterKietzmann should this a candidate for 2017.01 ?

If it's merged it's merged ;-)

@miri64 miri64 added this to the Release 2017.01 milestone Dec 26, 2016
@cgundogan cgundogan self-assigned this Jan 10, 2017
@cgundogan
Copy link
Copy Markdown
Member

Tested I2C and SPI mode successfully. Code is also in good shape. @lebrush can you squash your commits?

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jan 10, 2017

@cgundogan thanks for testing it! 🎉 I just squashed and left the meaningful ones :-)

@cgundogan
Copy link
Copy Markdown
Member

@lebrush thanks! (: let's wait for Murdock now and merge as soon as it turns green.

@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 10, 2017
@OlegHahm
Copy link
Copy Markdown
Member

cppcheck found some issues and some of the Cortex-M0 ports fail.

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jan 11, 2017

@OlegHahm why tries to compile it if the periph_i2c requirement is not satisfied?

Compiling it manually returns: "There are unsatisfied feature requirements: periph_i2c. Expect Errors"

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jan 11, 2017

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 false

Refers 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 PN532_SUPPORT_I2C or PN532_SUPPORT_SPI are set. At least one of them must be set, otherwise the compilation fails and an informative error is displayed (pn532.h:31):

#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
#endif

I would ignore this one otherwise please suggest how to fix it

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jan 11, 2017

I 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).

@lebrush
Copy link
Copy Markdown
Member Author

lebrush commented Jan 11, 2017

@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 periph_i2c?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jan 11, 2017

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.

USEMODULE += pn532

# set default device parameters in case they are undefined
TEST_PN532_I2C ?= I2C_0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use I2C_DEV\(0\) here! Should also fix build tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint! done :-)

@PeterKietzmann
Copy link
Copy Markdown
Member

Oh and please squash all commits to one.

@PeterKietzmann PeterKietzmann merged commit 9d44d6b into RIOT-OS:master Jan 14, 2017
@lebrush lebrush deleted the pn532 branch January 16, 2017 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants