Browse Source

drivers/pn532: enabled test app to select SPI mode

pr/spi.typo
Hauke Petersen 6 years ago
parent
commit
db048f22ad
  1. 17
      tests/driver_pn532/Makefile
  2. 7
      tests/driver_pn532/main.c
  3. 7
      tests/driver_pn532/pn532_params.h

17
tests/driver_pn532/Makefile

@ -11,11 +11,26 @@ TEST_PN532_I2C ?= I2C_DEV\(0\)
TEST_PN532_RESET ?= GPIO_PIN\(0,0\)
TEST_PN532_IRQ ?= GPIO_PIN\(0,1\)
# alternative SPI configuration
TEST_PN532_SPI ?= SPI_DEV\(0\)
TEST_PN532_NSS ?= GPIO_PIN\(0,2\)
# export parameters
CFLAGS += -DTEST_PN532_I2C=$(TEST_PN532_I2C)
CFLAGS += -DTEST_PN532_RESET=$(TEST_PN532_RESET)
CFLAGS += -DTEST_PN532_IRQ=$(TEST_PN532_IRQ)
CFLAGS += -DPN532_SUPPORT_I2C
CFLAGS += -DTEST_PN532_SPI=$(TEST_PN532_SPI)
CFLAGS += -DTEST_PN532_NSS=$(TEST_PN532_NSS)
# select if you want to build the SPI or the I2C version of the driver:
# set PN532_MODE to `i2c` or to `spi`
PN532_MODE ?= i2c
ifeq ($(PN532_MODE),i2c)
CFLAGS += -DPN532_SUPPORT_I2C
endif
ifeq ($(PN532_MODE),spi)
CFLAGS += -DPN532_SUPPORT_SPI
endif
CFLAGS += -I$(CURDIR)

7
tests/driver_pn532/main.c

@ -44,8 +44,13 @@ int main(void)
static nfc_iso14443a_t card;
static pn532_t pn532;
unsigned len;
int ret;
int ret = pn532_init_i2c(&pn532, &pn532_conf[0]);
#if defined(PN532_SUPPORT_I2C)
ret = pn532_init_i2c(&pn532, &pn532_conf[0]);
#elif defined(PN532_SUPPORT_SPI)
ret = pn532_init_spi(&pn532, &pn532_conf[0]);
#endif
if (ret != 0) {
LOG_INFO("init error %d\n", ret);

7
tests/driver_pn532/pn532_params.h

@ -25,9 +25,16 @@ extern "C" {
static const pn532_params_t pn532_conf[] = {
{
#if defined(PN532_SUPPORT_I2C)
.i2c = TEST_PN532_I2C,
#elif defined(PN532_SUPPORT_SPI)
.spi = TEST_PN532_SPI,
#endif
.reset = TEST_PN532_RESET,
.irq = TEST_PN532_IRQ,
#if defined(PN532_SUPPORT_SPI)
.nss = TEST_PN532_NSS
#endif
},
};

Loading…
Cancel
Save