mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/pn532: adapted to SPI interface changes
This commit is contained in:
parent
db048f22ad
commit
1ae0ad2509
@ -71,6 +71,10 @@
|
|||||||
#define SPI_DATA_READ (0xC0)
|
#define SPI_DATA_READ (0xC0)
|
||||||
#define SPI_WRITE_DELAY_US (2000)
|
#define SPI_WRITE_DELAY_US (2000)
|
||||||
|
|
||||||
|
/* SPI bus parameters */
|
||||||
|
#define SPI_MODE (SPI_MODE_0)
|
||||||
|
#define SPI_CLK (SPI_CLK_1MHZ)
|
||||||
|
|
||||||
/* Length for passive listings */
|
/* Length for passive listings */
|
||||||
#define LIST_PASSIVE_LEN_14443(num) (num * 20)
|
#define LIST_PASSIVE_LEN_14443(num) (num * 20)
|
||||||
|
|
||||||
@ -108,8 +112,6 @@ int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode)
|
|||||||
{
|
{
|
||||||
assert(dev != NULL);
|
assert(dev != NULL);
|
||||||
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
dev->conf = params;
|
dev->conf = params;
|
||||||
|
|
||||||
gpio_init_int(dev->conf->irq, GPIO_IN_PU, GPIO_FALLING,
|
gpio_init_int(dev->conf->irq, GPIO_IN_PU, GPIO_FALLING,
|
||||||
@ -120,28 +122,26 @@ int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode)
|
|||||||
dev->mode = mode;
|
dev->mode = mode;
|
||||||
if (mode == PN532_I2C) {
|
if (mode == PN532_I2C) {
|
||||||
#ifdef PN532_SUPPORT_I2C
|
#ifdef PN532_SUPPORT_I2C
|
||||||
ret = i2c_init_master(dev->conf->i2c, I2C_SPEED_FAST);
|
if (i2c_init_master(dev->conf->i2c, I2C_SPEED_FAST) != 0) {
|
||||||
|
DEBUG("pn532: initialization of I2C bus failed\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#ifdef PN532_SUPPORT_SPI
|
||||||
ret = spi_init_master(dev->conf->spi, SPI_CONF_FIRST_RISING,
|
/* we handle the CS line manually... */
|
||||||
SPI_SPEED_1MHZ);
|
|
||||||
gpio_init(dev->conf->nss, GPIO_OUT);
|
gpio_init(dev->conf->nss, GPIO_OUT);
|
||||||
gpio_set(dev->conf->nss);
|
gpio_set(dev->conf->nss);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cppcheck-suppress knownConditionTrueFalse
|
|
||||||
* (reason: variable set when PN532_SUPPORT_{I2C,SPI} defined) */
|
|
||||||
if (ret == 0) {
|
|
||||||
pn532_reset(dev);
|
pn532_reset(dev);
|
||||||
}
|
|
||||||
|
|
||||||
mutex_init(&dev->trap);
|
mutex_init(&dev->trap);
|
||||||
mutex_lock(&dev->trap);
|
mutex_lock(&dev->trap);
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char chksum(char *b, unsigned len)
|
static unsigned char chksum(char *b, unsigned len)
|
||||||
@ -181,14 +181,15 @@ static int _write(pn532_t *dev, char *buff, unsigned len)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#ifdef PN532_SUPPORT_SPI
|
||||||
spi_acquire(dev->conf->spi);
|
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
||||||
gpio_clear(dev->conf->nss);
|
gpio_clear(dev->conf->nss);
|
||||||
xtimer_usleep(SPI_WRITE_DELAY_US);
|
xtimer_usleep(SPI_WRITE_DELAY_US);
|
||||||
reverse(buff, len);
|
reverse(buff, len);
|
||||||
spi_transfer_byte(dev->conf->spi, SPI_DATA_WRITE, NULL);
|
spi_transfer_byte(dev->conf->spi, SPI_CS_UNDEF, true, SPI_DATA_WRITE);
|
||||||
ret = spi_transfer_bytes(dev->conf->spi, buff, NULL, len);
|
spi_transfer_bytes(dev->conf->spi, SPI_CS_UNDEF, true, buff, NULL, len);
|
||||||
gpio_set(dev->conf->nss);
|
gpio_set(dev->conf->nss);
|
||||||
spi_release(dev->conf->spi);
|
spi_release(dev->conf->spi);
|
||||||
|
ret = (int)len;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
DEBUG("pn532: -> ");
|
DEBUG("pn532: -> ");
|
||||||
@ -213,17 +214,16 @@ static int _read(pn532_t *dev, char *buff, unsigned len)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef PN532_SUPPORT_SPI
|
#ifdef PN532_SUPPORT_SPI
|
||||||
spi_acquire(dev->conf->spi);
|
spi_acquire(dev->conf->spi, SPI_CS_UNDEF, SPI_MODE, SPI_CLK);
|
||||||
gpio_clear(dev->conf->nss);
|
gpio_clear(dev->conf->nss);
|
||||||
spi_transfer_byte(dev->conf->spi, SPI_DATA_READ, NULL);
|
spi_transfer_byte(dev->conf->spi, SPI_CS_UNDEF, true, SPI_DATA_READ);
|
||||||
ret = spi_transfer_bytes(dev->conf->spi, 0x00, &buff[1], len);
|
spi_transfer_bytes(dev->conf->spi, SPI_CS_UNDEF, true, NULL, &buff[1], len);
|
||||||
gpio_set(dev->conf->nss);
|
gpio_set(dev->conf->nss);
|
||||||
spi_release(dev->conf->spi);
|
spi_release(dev->conf->spi);
|
||||||
if (ret >= 0) {
|
|
||||||
buff[0] = 0x80;
|
buff[0] = 0x80;
|
||||||
reverse(buff, ret);
|
reverse(buff, len);
|
||||||
ret += 1;
|
ret = (int)len + 1;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
DEBUG("pn532: <- ");
|
DEBUG("pn532: <- ");
|
||||||
|
Loading…
Reference in New Issue
Block a user