Browse Source

drivers/cc110x: adapted to SPI API changes

pr/spi.typo
Hauke Petersen 6 years ago
parent
commit
8799b3ab9e
  1. 65
      drivers/cc110x/cc110x-spi.c
  2. 8
      drivers/cc110x/cc110x.c

65
drivers/cc110x/cc110x-spi.c

@ -35,10 +35,18 @@
#include "xtimer.h"
#include "irq.h"
#define SPI_CLK SPI_CLK_5MHZ
#define SPI_MODE SPI_MODE_0
/**********************************************************************
* CC110x spi access
**********************************************************************/
static inline void lock(cc110x_t *dev)
{
spi_acquire(dev->params.spi, dev->params.cs, SPI_MODE, SPI_CLK);
}
void cc110x_cs(cc110x_t *dev)
{
volatile int retry_count = 0;
@ -68,17 +76,18 @@ void cc110x_cs(cc110x_t *dev)
}
/* Switch MISO/GDO1 to spi mode */
#ifndef GPIO_READS_SPI_PINS
spi_conf_pins(dev->params.spi);
spi_init_pins(dev->params.spi);
#endif
}
void cc110x_writeburst_reg(cc110x_t *dev, uint8_t addr, const char *src, uint8_t count)
{
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_regs(dev->params.spi, addr | CC110X_WRITE_BURST, (char *)src, 0, count);
spi_transfer_regs(dev->params.spi, SPI_CS_UNDEF,
(addr | CC110X_WRITE_BURST), src, NULL, count);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
@ -88,12 +97,14 @@ void cc110x_readburst_reg(cc110x_t *dev, uint8_t addr, char *buffer, uint8_t cou
{
int i = 0;
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_byte(dev->params.spi, addr | CC110X_READ_BURST, 0);
spi_transfer_byte(dev->params.spi, SPI_CS_UNDEF, false,
(addr | CC110X_READ_BURST));
while (i < count) {
spi_transfer_byte(dev->params.spi, CC110X_NOBYTE, &buffer[i]);
buffer[i] = (char)spi_transfer_byte(dev->params.spi, SPI_CS_UNDEF,
false, CC110X_NOBYTE);
i++;
}
gpio_set(dev->params.cs);
@ -104,10 +115,10 @@ void cc110x_readburst_reg(cc110x_t *dev, uint8_t addr, char *buffer, uint8_t cou
void cc110x_write_reg(cc110x_t *dev, uint8_t addr, uint8_t value)
{
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_reg(dev->params.spi, addr, value, 0);
spi_transfer_reg(dev->params.spi, SPI_CS_UNDEF, addr, value);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
@ -115,26 +126,28 @@ void cc110x_write_reg(cc110x_t *dev, uint8_t addr, uint8_t value)
uint8_t cc110x_read_reg(cc110x_t *dev, uint8_t addr)
{
char result;
uint8_t result;
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_reg(dev->params.spi, addr | CC110X_READ_SINGLE, CC110X_NOBYTE, &result);
result = spi_transfer_reg(dev->params.spi, SPI_CS_UNDEF,
(addr | CC110X_READ_SINGLE), CC110X_NOBYTE);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
return (uint8_t) result;
return result;
}
uint8_t cc110x_read_status(cc110x_t *dev, uint8_t addr)
{
char result;
uint8_t result;
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_reg(dev->params.spi, addr | CC110X_READ_BURST, CC110X_NOBYTE, &result);
result = spi_transfer_reg(dev->params.spi, SPI_CS_UNDEF,
(addr | CC110X_READ_BURST), CC110X_NOBYTE);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
@ -143,19 +156,21 @@ uint8_t cc110x_read_status(cc110x_t *dev, uint8_t addr)
uint8_t cc110x_get_reg_robust(cc110x_t *dev, uint8_t addr)
{
char result, result2;
uint8_t res1, res2;
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
do {
spi_transfer_reg(dev->params.spi, addr | CC110X_READ_BURST, CC110X_NOBYTE, &result);
spi_transfer_reg(dev->params.spi, addr | CC110X_READ_BURST, CC110X_NOBYTE, &result2);
} while (result != result2);
res1 = spi_transfer_reg(dev->params.spi, SPI_CS_UNDEF,
(addr | CC110X_READ_BURST), CC110X_NOBYTE);
res2 = spi_transfer_reg(dev->params.spi, SPI_CS_UNDEF,
(addr | CC110X_READ_BURST), CC110X_NOBYTE);
} while (res1 != res2);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
return (uint8_t) result;
return res1;
}
uint8_t cc110x_strobe(cc110x_t *dev, uint8_t c)
@ -166,14 +181,14 @@ uint8_t cc110x_strobe(cc110x_t *dev, uint8_t c)
}
#endif
char result;
uint8_t result;
unsigned int cpsr;
spi_acquire(dev->params.spi);
lock(dev);
cpsr = irq_disable();
cc110x_cs(dev);
spi_transfer_byte(dev->params.spi, c, &result);
result = spi_transfer_byte(dev->params.spi, SPI_CS_UNDEF, false, c);
gpio_set(dev->params.cs);
irq_restore(cpsr);
spi_release(dev->params.spi);
return (uint8_t) result;
return result;
}

8
drivers/cc110x/cc110x.c

@ -55,17 +55,11 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params)
dev->params = *params;
/* Configure chip-select */
gpio_init(dev->params.cs, GPIO_OUT);
gpio_set(dev->params.cs);
spi_init_cs(dev->params.spi, dev->params.cs);
/* Configure GDO1 */
gpio_init(dev->params.gdo1, GPIO_IN);
/* Configure SPI */
spi_acquire(dev->params.spi);
spi_init_master(dev->params.spi, SPI_CONF_FIRST_RISING, SPI_SPEED_5MHZ);
spi_release(dev->params.spi);
#ifndef CC110X_DONT_RESET
/* reset device*/
_power_up_reset(dev);

Loading…
Cancel
Save