mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/adt7310: adapted to SPI API changes
This commit is contained in:
parent
f42ae58d27
commit
610e671aac
@ -95,15 +95,9 @@ static int adt7310_read_reg(const adt7310_t *dev, const uint8_t addr, const uint
|
||||
int status = 0;
|
||||
uint8_t command = ADT7310_CMD_READ | (addr << ADT7310_CMD_ADDR_SHIFT);
|
||||
/* Acquire exclusive access to the bus. */
|
||||
spi_acquire(dev->spi);
|
||||
spi_acquire(dev->spi, dev->cs, SPI_MODE_0, dev->clk);
|
||||
/* Perform the transaction */
|
||||
gpio_clear(dev->cs);
|
||||
|
||||
if (spi_transfer_regs(dev->spi, command, NULL, (char *)buf, len) < len) {
|
||||
status = -1;
|
||||
}
|
||||
|
||||
gpio_set(dev->cs);
|
||||
spi_transfer_regs(dev->spi, dev->cs, command, NULL, buf, (size_t)len);
|
||||
/* Release the bus for other threads. */
|
||||
spi_release(dev->spi);
|
||||
|
||||
@ -127,34 +121,28 @@ static int adt7310_write_reg(const adt7310_t *dev, const uint8_t addr,
|
||||
int status = 0;
|
||||
uint8_t command = ADT7310_CMD_WRITE | (addr << ADT7310_CMD_ADDR_SHIFT);
|
||||
/* Acquire exclusive access to the bus. */
|
||||
spi_acquire(dev->spi);
|
||||
spi_acquire(dev->spi, dev->cs, SPI_MODE_0, dev->clk);
|
||||
/* Perform the transaction */
|
||||
gpio_clear(dev->cs);
|
||||
|
||||
if (spi_transfer_regs(dev->spi, command, (char *)buf, NULL, len) < len) {
|
||||
status = -1;
|
||||
}
|
||||
|
||||
gpio_set(dev->cs);
|
||||
spi_transfer_regs(dev->spi, dev->cs, command, buf, NULL, (size_t)len);
|
||||
/* Release the bus for other threads. */
|
||||
spi_release(dev->spi);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int adt7310_init(adt7310_t *dev, spi_t spi, gpio_t cs)
|
||||
int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs)
|
||||
{
|
||||
int status;
|
||||
uint8_t reg = 0;
|
||||
/* write device descriptor */
|
||||
dev->spi = spi;
|
||||
dev->clk = clk;
|
||||
dev->cs = cs;
|
||||
dev->initialized = false;
|
||||
dev->high_res = false;
|
||||
|
||||
/* CS */
|
||||
gpio_init(dev->cs, GPIO_OUT);
|
||||
gpio_set(dev->cs);
|
||||
spi_init_cs(dev->spi, dev->cs);
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
|
@ -65,6 +65,7 @@ extern "C"
|
||||
*/
|
||||
typedef struct {
|
||||
spi_t spi; /**< SPI bus the sensor is connected to */
|
||||
spi_clk_t clk; /**< SPI bus clock speed */
|
||||
gpio_t cs; /**< CS pin GPIO handle */
|
||||
bool initialized; /**< sensor status, true if sensor is initialized */
|
||||
bool high_res; /**< Sensor resolution, true if configured to 16 bit resolution */
|
||||
@ -124,7 +125,7 @@ int adt7310_set_config(adt7310_t *dev, uint8_t config);
|
||||
* @return 0 on success
|
||||
* @return <0 on error
|
||||
*/
|
||||
int adt7310_init(adt7310_t *dev, spi_t spi, gpio_t cs);
|
||||
int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs);
|
||||
|
||||
/**
|
||||
* @brief Read raw temperature register value
|
||||
|
@ -9,7 +9,7 @@ USEMODULE += adt7310
|
||||
USEMODULE += xtimer
|
||||
|
||||
# set default device parameters in case they are undefined
|
||||
TEST_ADT7310_SPI ?= SPI_0
|
||||
TEST_ADT7310_SPI ?= SPI_DEV\(0\)
|
||||
TEST_ADT7310_CS ?= GPIO_PIN\(0,0\)
|
||||
|
||||
# export parameters
|
||||
|
@ -36,7 +36,7 @@
|
||||
#endif
|
||||
|
||||
#define SPI_CONF (SPI_CONF_SECOND_FALLING)
|
||||
#define SPI_SPEED (SPI_SPEED_10MHZ)
|
||||
#define SPI_CLK (SPI_CLK_10MHZ)
|
||||
|
||||
#define SLEEP_CONT (100 * 1000U)
|
||||
#define SLEEP_1SPS (1000 * 1000U)
|
||||
@ -89,17 +89,9 @@ int main(void)
|
||||
adt7310_t dev;
|
||||
|
||||
puts("ADT7310 temperature driver test application\n");
|
||||
printf("Initializing SPI_%i... ", TEST_ADT7310_SPI);
|
||||
if (spi_init_master(TEST_ADT7310_SPI, SPI_CONF, SPI_SPEED) == 0) {
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
puts("[Failed]\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
puts("Initializing ADT7310 sensor... ");
|
||||
if (adt7310_init(&dev, TEST_ADT7310_SPI, TEST_ADT7310_CS) == 0) {
|
||||
if (adt7310_init(&dev, TEST_ADT7310_SPI, SPI_CLK, TEST_ADT7310_CS) == 0) {
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user