Merge pull request #15705 from leandrolanzieri/pr/drivers/pn532_use_pseudomodules
drivers/pn532: use pseudomodules to select i2c or spi
This commit is contained in:
commit
3b7f1d218c
@ -106,6 +106,16 @@ ifneq (,$(filter periph_ptp_timer periph_ptp_speed_adjustment,$(FEATURES_USED)))
|
|||||||
FEATURES_REQUIRED += periph_ptp
|
FEATURES_REQUIRED += periph_ptp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter pn532_i2c,$(USEMODULE)))
|
||||||
|
FEATURES_REQUIRED += periph_i2c
|
||||||
|
USEMODULE += pn532
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter pn532_spi,$(USEMODULE)))
|
||||||
|
FEATURES_REQUIRED += periph_spi
|
||||||
|
USEMODULE += pn532
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter qmc5883l_%,$(USEMODULE)))
|
ifneq (,$(filter qmc5883l_%,$(USEMODULE)))
|
||||||
USEMODULE += qmc5883l
|
USEMODULE += qmc5883l
|
||||||
endif
|
endif
|
||||||
|
|||||||
@ -25,14 +25,15 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "periph/i2c.h"
|
#include "periph/i2c.h"
|
||||||
#include "periph/spi.h"
|
#include "periph/spi.h"
|
||||||
#include "periph/gpio.h"
|
#include "periph/gpio.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if !defined(PN532_SUPPORT_I2C) && !defined(PN532_SUPPORT_SPI)
|
#if !IS_USED(MODULE_PN532_I2C) && !IS_USED(MODULE_PN532_SPI)
|
||||||
#error Please define PN532_SUPPORT_I2C and/or PN532_SUPPORT_SPI to enable \
|
#error Please use either pn532_i2c and/or pn532_spi module to enable \
|
||||||
the functionality on this device
|
the functionality on this device
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -41,16 +42,16 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
#if defined(PN532_SUPPORT_I2C) || DOXYGEN
|
#if IS_USED(MODULE_PN532_I2C) || DOXYGEN
|
||||||
i2c_t i2c; /**< I2C device */
|
i2c_t i2c; /**< I2C device */
|
||||||
#endif
|
#endif
|
||||||
#if defined(PN532_SUPPORT_SPI) || DOXYGEN
|
#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
|
||||||
spi_t spi; /**< SPI device */
|
spi_t spi; /**< SPI device */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
gpio_t reset; /**< Reset pin */
|
gpio_t reset; /**< Reset pin */
|
||||||
gpio_t irq; /**< Interrupt pin */
|
gpio_t irq; /**< Interrupt pin */
|
||||||
#if defined(PN532_SUPPORT_SPI) || DOXYGEN
|
#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
|
||||||
gpio_t nss; /**< Chip Select pin (only SPI) */
|
gpio_t nss; /**< Chip Select pin (only SPI) */
|
||||||
#endif
|
#endif
|
||||||
} pn532_params_t;
|
} pn532_params_t;
|
||||||
@ -185,11 +186,12 @@ void pn532_reset(const pn532_t *dev);
|
|||||||
int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode);
|
int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode);
|
||||||
|
|
||||||
|
|
||||||
#if defined(PN532_SUPPORT_I2C) || DOXYGEN
|
#if IS_USED(MODULE_PN532_I2C) || DOXYGEN
|
||||||
/**
|
/**
|
||||||
* @brief Initialization of PN532 using i2c
|
* @brief Initialization of PN532 using i2c
|
||||||
*
|
*
|
||||||
* @see pn532_init for parameter and return value details
|
* @see pn532_init for parameter and return value details
|
||||||
|
* @note Use `pn532_i2c` module to use this function.
|
||||||
*/
|
*/
|
||||||
static inline int pn532_init_i2c(pn532_t *dev, const pn532_params_t *params)
|
static inline int pn532_init_i2c(pn532_t *dev, const pn532_params_t *params)
|
||||||
{
|
{
|
||||||
@ -197,11 +199,12 @@ static inline int pn532_init_i2c(pn532_t *dev, const pn532_params_t *params)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PN532_SUPPORT_SPI) || DOXYGEN
|
#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
|
||||||
/**
|
/**
|
||||||
* @brief Initialization of PN532 using spi
|
* @brief Initialization of PN532 using spi
|
||||||
*
|
*
|
||||||
* @see pn532_init for parameter and return value details
|
* @see pn532_init for parameter and return value details
|
||||||
|
* @note Use `pn532_spi` module to use this function.
|
||||||
*/
|
*/
|
||||||
static inline int pn532_init_spi(pn532_t *dev, const pn532_params_t *params)
|
static inline int pn532_init_spi(pn532_t *dev, const pn532_params_t *params)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
#include "kernel_defines.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "pn532.h"
|
#include "pn532.h"
|
||||||
@ -121,7 +122,7 @@ int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode)
|
|||||||
gpio_set(dev->conf->reset);
|
gpio_set(dev->conf->reset);
|
||||||
dev->mode = mode;
|
dev->mode = mode;
|
||||||
if (mode == PN532_SPI) {
|
if (mode == PN532_SPI) {
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
/* we handle the CS line manually... */
|
/* we handle the CS line manually... */
|
||||||
gpio_init(dev->conf->nss, GPIO_OUT);
|
gpio_init(dev->conf->nss, GPIO_OUT);
|
||||||
gpio_set(dev->conf->nss);
|
gpio_set(dev->conf->nss);
|
||||||
@ -146,8 +147,8 @@ static uint8_t chksum(uint8_t *b, unsigned len)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
static void reverse(char *buff, unsigned len)
|
static void reverse(uint8_t *buff, unsigned len)
|
||||||
{
|
{
|
||||||
while (len--) {
|
while (len--) {
|
||||||
buff[len] = (buff[len] & 0xF0) >> 4 | (buff[len] & 0x0F) << 4;
|
buff[len] = (buff[len] & 0xF0) >> 4 | (buff[len] & 0x0F) << 4;
|
||||||
@ -165,7 +166,7 @@ static int _write(const pn532_t *dev, uint8_t *buff, unsigned len)
|
|||||||
(void)len;
|
(void)len;
|
||||||
|
|
||||||
switch (dev->mode) {
|
switch (dev->mode) {
|
||||||
#ifdef PN532_SUPPORT_I2C
|
#if IS_USED(MODULE_PN532_I2C)
|
||||||
case PN532_I2C:
|
case PN532_I2C:
|
||||||
i2c_acquire(dev->conf->i2c);
|
i2c_acquire(dev->conf->i2c);
|
||||||
ret = i2c_write_bytes(dev->conf->i2c, PN532_I2C_ADDRESS, buff, len, 0);
|
ret = i2c_write_bytes(dev->conf->i2c, PN532_I2C_ADDRESS, buff, len, 0);
|
||||||
@ -175,7 +176,7 @@ static int _write(const pn532_t *dev, uint8_t *buff, unsigned len)
|
|||||||
i2c_release(dev->conf->i2c);
|
i2c_release(dev->conf->i2c);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
case PN532_SPI:
|
case PN532_SPI:
|
||||||
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
||||||
gpio_clear(dev->conf->nss);
|
gpio_clear(dev->conf->nss);
|
||||||
@ -204,7 +205,7 @@ static int _read(const pn532_t *dev, uint8_t *buff, unsigned len)
|
|||||||
(void)len;
|
(void)len;
|
||||||
|
|
||||||
switch (dev->mode) {
|
switch (dev->mode) {
|
||||||
#ifdef PN532_SUPPORT_I2C
|
#if IS_USED(MODULE_PN532_I2C)
|
||||||
case PN532_I2C:
|
case PN532_I2C:
|
||||||
i2c_acquire(dev->conf->i2c);
|
i2c_acquire(dev->conf->i2c);
|
||||||
/* len+1 for RDY after read is accepted */
|
/* len+1 for RDY after read is accepted */
|
||||||
@ -215,7 +216,7 @@ static int _read(const pn532_t *dev, uint8_t *buff, unsigned len)
|
|||||||
i2c_release(dev->conf->i2c);
|
i2c_release(dev->conf->i2c);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
case PN532_SPI:
|
case PN532_SPI:
|
||||||
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
||||||
gpio_clear(dev->conf->nss);
|
gpio_clear(dev->conf->nss);
|
||||||
|
|||||||
@ -215,6 +215,10 @@ PSEUDOMODULES += ina220
|
|||||||
# include variants of mrf24j40 drivers as pseudo modules
|
# include variants of mrf24j40 drivers as pseudo modules
|
||||||
PSEUDOMODULES += mrf24j40m%
|
PSEUDOMODULES += mrf24j40m%
|
||||||
|
|
||||||
|
# include variants of the pn532 drivers as pseudo modules
|
||||||
|
PSEUDOMODULES += pn532_i2c
|
||||||
|
PSEUDOMODULES += pn532_spi
|
||||||
|
|
||||||
# include variants of sdp3x drivers as pseudo modules
|
# include variants of sdp3x drivers as pseudo modules
|
||||||
PSEUDOMODULES += sdp3x_irq
|
PSEUDOMODULES += sdp3x_irq
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
FEATURES_REQUIRED = periph_i2c periph_gpio
|
|
||||||
|
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
USEMODULE += pn532
|
|
||||||
|
# select if you want to build the SPI or the I2C version of the driver:
|
||||||
|
USEMODULE += pn532_i2c
|
||||||
|
#USEMODULE += pn532_spi
|
||||||
|
|
||||||
# set default device parameters in case they are undefined
|
# set default device parameters in case they are undefined
|
||||||
TEST_PN532_I2C ?= I2C_DEV\(0\)
|
TEST_PN532_I2C ?= I2C_DEV\(0\)
|
||||||
@ -21,16 +22,6 @@ CFLAGS += -DTEST_PN532_IRQ=$(TEST_PN532_IRQ)
|
|||||||
CFLAGS += -DTEST_PN532_SPI=$(TEST_PN532_SPI)
|
CFLAGS += -DTEST_PN532_SPI=$(TEST_PN532_SPI)
|
||||||
CFLAGS += -DTEST_PN532_NSS=$(TEST_PN532_NSS)
|
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)
|
CFLAGS += -I$(CURDIR)
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|||||||
@ -46,13 +46,8 @@ int main(void)
|
|||||||
unsigned len;
|
unsigned len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#if defined(PN532_SUPPORT_I2C)
|
pn532_mode_t mode = IS_ACTIVE(MODULE_PN532_I2C) ? PN532_I2C : PN532_SPI;
|
||||||
ret = pn532_init_i2c(&pn532, &pn532_conf[0]);
|
ret = pn532_init(&pn532, &pn532_conf[0], mode);
|
||||||
#elif defined(PN532_SUPPORT_SPI)
|
|
||||||
ret = pn532_init_spi(&pn532, &pn532_conf[0]);
|
|
||||||
#else
|
|
||||||
#error None of PN532_SUPPORT_I2C and PN532_SUPPORT_SPI set!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOG_INFO("init error %d\n", ret);
|
LOG_INFO("init error %d\n", ret);
|
||||||
|
|||||||
@ -23,16 +23,19 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
|
|
||||||
static const pn532_params_t pn532_conf[] = {
|
static const pn532_params_t pn532_conf[] = {
|
||||||
{
|
{
|
||||||
#if defined(PN532_SUPPORT_I2C)
|
#if IS_USED(MODULE_PN532_I2C)
|
||||||
.i2c = TEST_PN532_I2C,
|
.i2c = TEST_PN532_I2C,
|
||||||
#elif defined(PN532_SUPPORT_SPI)
|
#endif
|
||||||
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
.spi = TEST_PN532_SPI,
|
.spi = TEST_PN532_SPI,
|
||||||
#endif
|
#endif
|
||||||
.reset = TEST_PN532_RESET,
|
.reset = TEST_PN532_RESET,
|
||||||
.irq = TEST_PN532_IRQ,
|
.irq = TEST_PN532_IRQ,
|
||||||
#if defined(PN532_SUPPORT_SPI)
|
#if IS_USED(MODULE_PN532_SPI)
|
||||||
.nss = TEST_PN532_NSS
|
.nss = TEST_PN532_NSS
|
||||||
#endif
|
#endif
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user