drivers: sensor: adxl362: Driver update and CS support

Updated to add support for CS. DT config names updated
to adhere to the DTS naming convention. Init and SPI
configuration now follows the device datasheet.

Signed-off-by: Henrik Malvik Halvorsen <henrik.halvorsen@nordicsemi.no>
This commit is contained in:
Henrik Malvik Halvorsen 2019-03-04 08:21:51 +01:00 committed by Kumar Gala
parent 5cd92276e7
commit 64fd822652
3 changed files with 49 additions and 12 deletions

View file

@ -574,6 +574,7 @@ static int adxl362_init(struct device *dev)
const struct adxl362_config *config = dev->config->config_info;
struct adxl362_data *data = dev->driver_data;
u8_t value;
int err;
data->spi = device_get_binding(config->spi_name);
if (!data->spi) {
@ -581,15 +582,36 @@ static int adxl362_init(struct device *dev)
return -EINVAL;
}
data->spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
SPI_MODE_CPOL | SPI_MODE_CPHA;
data->spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB;
data->spi_cfg.frequency = config->spi_max_frequency;
data->spi_cfg.slave = config->spi_slave;
adxl362_software_reset(dev);
#if defined(DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER)
data->adxl362_cs_ctrl.gpio_dev =
device_get_binding(config->gpio_cs_port);
if (!data->adxl362_cs_ctrl.gpio_dev) {
LOG_ERR("Unable to get GPIO SPI CS device");
return -ENODEV;
}
data->adxl362_cs_ctrl.gpio_pin = config->cs_gpio;
data->adxl362_cs_ctrl.delay = 0;
data->spi_cfg.cs = &data->adxl362_cs_ctrl;
#endif
err = adxl362_software_reset(dev);
if (err) {
LOG_ERR("adxl362_software_reset failed, error %d\n", err);
return -ENODEV;
}
k_sleep(5);
adxl362_get_reg(dev, &value, ADXL362_REG_PARTID, 1);
if (value != ADXL362_PART_ID) {
LOG_ERR("Failed: %d\n", value);
return -ENODEV;
}
@ -601,11 +623,15 @@ static int adxl362_init(struct device *dev)
}
static const struct adxl362_config adxl362_config = {
.spi_name = DT_ADXL362_SPI_DEV_NAME,
.spi_slave = DT_ADXL362_SPI_DEV_SLAVE,
.spi_max_frequency = DT_ADXL362_SPI_MAX_FREQUENCY,
.spi_name = DT_ADI_ADXL362_0_BUS_NAME,
.spi_slave = DT_ADI_ADXL362_0_BASE_ADDRESS,
.spi_max_frequency = DT_ADI_ADXL362_0_SPI_MAX_FREQUENCY,
#if defined(DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER)
.gpio_cs_port = DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER,
.cs_gpio = DT_ADI_ADXL362_0_CS_GPIO_PIN,
#endif
};
DEVICE_AND_API_INIT(adxl362, DT_ADXL362_DEV_NAME, adxl362_init,
DEVICE_AND_API_INIT(adxl362, DT_ADI_ADXL362_0_LABEL, adxl362_init,
&adxl362_data, &adxl362_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &adxl362_api_funcs);

View file

@ -158,11 +158,18 @@ struct adxl362_config {
char *spi_name;
u32_t spi_max_frequency;
u16_t spi_slave;
#if defined(DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER)
const char *gpio_cs_port;
u8_t cs_gpio;
#endif
};
struct adxl362_data {
struct device *spi;
struct spi_config spi_cfg;
#if defined(DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER)
struct spi_cs_control adxl362_cs_ctrl;
#endif
s32_t acc_x;
s32_t acc_y;
s32_t acc_z;

View file

@ -8,11 +8,15 @@
#define DT_ADI_ADT7420_0_INT_GPIOS_PIN 0
#endif
#ifndef DT_ADXL362_DEV_NAME
#define DT_ADXL362_DEV_NAME ""
#define DT_ADXL362_SPI_DEV_NAME ""
#define DT_ADXL362_SPI_DEV_SLAVE 0
#define DT_ADXL362_SPI_MAX_FREQUENCY 0
#ifndef DT_ADI_ADXL362_0_LABEL
#define DT_ADI_ADXL362_0_LABEL ""
#define DT_ADI_ADXL362_0_BUS_NAME ""
#define DT_ADI_ADXL362_0_BASE_ADDRESS 0
#define DT_ADI_ADXL362_0_INT1_GPIOS_CONTROLLER ""
#define DT_ADI_ADXL362_0_INT1_GPIOS_PIN 0
#define DT_ADI_ADXL362_0_CS_GPIO_CONTROLLER 0
#define DT_ADI_ADXL362_0_CS_GPIO_PIN 0
#define DT_ADI_ADXL362_0_SPI_MAX_FREQUENCY 0
#endif
#ifndef DT_ADI_ADXL372_0_LABEL