Skip to content

Commit

Permalink
drivers: adc: ltc2451: Address review comments
Browse files Browse the repository at this point in the history
Address all review comments

Signed-off-by: Ethan Duckett <[email protected]>
  • Loading branch information
ethan-duckett-brill committed Nov 8, 2023
1 parent 5d87b5a commit 87ec3f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
12 changes: 3 additions & 9 deletions drivers/adc/Kconfig.ltc2451
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@

menuconfig ADC_LTC2451
bool "LTC2451 driver"
default n

if ADC_LTC2451

config ADC_LTC2451_INIT_PRIORITY
int "LTC2451 init priority"
default 70
help
LTC2451 driver device initialization priority.
default y
depends on DT_HAS_LLTC_LTC2451_ENABLED
select I2C

module = ADC_LTC2451
module-str = ADC_LTC2451
Expand Down
32 changes: 23 additions & 9 deletions drivers/adc/adc_ltc2451.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <zephyr/drivers/i2c.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(ltc2451, CONFIG_ADC_LTC2451_LOG_LEVEL);
LOG_MODULE_REGISTER(ltc2451, CONFIG_ADC_LOG_LEVEL);

#define DT_DRV_COMPAT lltc_ltc2451

Expand All @@ -27,21 +27,35 @@ static int ltc2451_channel_setup(const struct device *dev,
{
(void)dev;
(void)channel_cfg;
return -ENOSYS; /** there is only 1 channel which requires no real setup */
return 0; /* there is only 1 channel which requires no real setup */
}

static int ltc2451_set_conversion_speed(const struct device *dev, uint8_t conversion_speed)
{
const struct ltc2451_config *config = dev->config;
struct ltc2451_data *data = dev->data;
uint8_t wr_buf[1] = {conversion_speed};
uint8_t speed_bit = -1;

if (conversion_speed == 60) {
speed_bit = 0;
}
else if (conversion_speed == 30) {
speed_bit = 1;
}
else {
err = -EINVAL;
LOG_ERR("LTC write failed (err %d)", err);
return err;
}

uint8_t wr_buf[1] = {speed_bit};

int err = i2c_write(config->i2c.bus, wr_buf, sizeof(wr_buf), config->i2c.addr);
int err = i2c_write_dt(&config->i2c, wr_buf, sizeof(wr_buf));

if (err) {
LOG_ERR("LTC write failed (err %d)", err);
} else {
if (err == 0) {
data->conversion_speed = conversion_speed;
} else {
LOG_ERR("LTC write failed (err %d)", err);
}

return err;
Expand All @@ -55,7 +69,7 @@ static int ltc2451_read_latest_conversion(const struct device *dev,
const struct ltc2451_config *config = dev->config;
uint16_t *value_buf;

int err = i2c_read(config->i2c.bus, rd_buf, sizeof(rd_buf), config->i2c.addr);
int err = i2c_read_dt(&config->i2c, rd_buf, sizeof(rd_buf));

if (err) {
LOG_ERR("LTC read failed (err %d)", err);
Expand Down Expand Up @@ -96,7 +110,7 @@ static const struct adc_driver_api ltc2451_api = {
}; \
\
DEVICE_DT_INST_DEFINE(index, &ltc2451_init, NULL, &ltc2451_data_##index, \
&ltc2451_cfg_##index, POST_KERNEL, CONFIG_ADC_LTC2451_INIT_PRIORITY, \
&ltc2451_cfg_##index, POST_KERNEL, CONFIG_ADC_INIT_PRIORITY, \
&ltc2451_api);

DT_INST_FOREACH_STATUS_OKAY(INIT_LTC2451_DEVICE)
7 changes: 3 additions & 4 deletions dts/bindings/adc/lltc,ltc2451.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ properties:

conversion-speed:
type: int
default: 0
enum:
- 0 # 60 Hz
- 1 # 30 Hz
description: Set conversion speed
- 30
- 60
description: Set conversion speed in Hz

0 comments on commit 87ec3f0

Please sign in to comment.