Skip to content

Commit 95b2f8f

Browse files
Add TI temp sensor HDC302x
1 parent 243fce9 commit 95b2f8f

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

drivers/sensor/ti/ti_hdc302x/ti_hdc302x.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ static const uint8_t REG_HEATER_ON[] = {0x30, 0x6D};
2929
static const uint8_t REG_HEATER_OFF[] = {0x30, 0x66};
3030
static const uint8_t REG_HEATER_LEVEL[] = {0x30, 0x6E};
3131

32+
struct ti_hdc302x_config {
33+
struct i2c_dt_spec bus;
34+
struct gpio_dt_spec gpio_int;
35+
};
36+
37+
struct ti_hdc302x_data {
38+
struct gpio_callback cb_int;
39+
sensor_trigger_handler_t th_handler;
40+
struct sensor_trigger th_trigger;
41+
uint16_t t_sample;
42+
uint16_t rh_sample;
43+
uint16_t t_alert;
44+
uint16_t rh_alert;
45+
uint8_t t_offset;
46+
uint8_t rh_offset;
47+
enum sensor_power_mode_hdc302x power_mode;
48+
enum sensor_measurement_interval_hdc302x interval;
49+
uint8_t selected_mode[2];
50+
};
51+
3252
/* Alert status registers */
3353
static const uint8_t alert_set_commands[][2] = {
3454
{0x61, 0x00},
@@ -266,7 +286,10 @@ static void interrupt_callback(const struct device *dev, struct gpio_callback *c
266286
struct ti_hdc302x_data *data = CONTAINER_OF(cb, struct ti_hdc302x_data, cb_int);
267287
ARG_UNUSED(pins);
268288
LOG_DBG("Interrupt received");
269-
k_sem_give(&data->sem_int);
289+
290+
if (data->th_handler != NULL) {
291+
data->th_handler(dev, &data->th_trigger);
292+
}
270293
}
271294

272295
/**
@@ -298,7 +321,8 @@ static int ti_hdc302x_sample_fetch(const struct device *dev, enum sensor_channel
298321
}
299322
}
300323

301-
/* Read temperature and humidity data (6 bytes: T_MSB, T_LSB, T_CRC, RH_MSB, RH_LSB, RH_CRC)
324+
/* Read temperature and humidity data (6 bytes: T_MSB, T_LSB, T_CRC, RH_MSB, RH_LSB,
325+
* RH_CRC)
302326
*/
303327
rc = read_sensor_data(dev, buf, sizeof(buf));
304328
if (rc < 0) {
@@ -862,11 +886,24 @@ static int ti_hdc302x_attr_set(const struct device *dev, enum sensor_channel cha
862886
return 0;
863887
}
864888

889+
static int ti_hdc302x_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
890+
sensor_trigger_handler_t handler)
891+
{
892+
struct ti_hdc302x_data *data = dev->data;
893+
894+
if (trig->type == SENSOR_TRIG_DELTA) {
895+
data->th_handler = handler;
896+
data->th_trigger = *trig;
897+
}
898+
return 0;
899+
}
900+
865901
static DEVICE_API(sensor, ti_hdc302x_api_funcs) = {
866902
.sample_fetch = ti_hdc302x_sample_fetch,
867903
.channel_get = ti_hdc302x_channel_get,
868904
.attr_set = ti_hdc302x_attr_set,
869905
.attr_get = ti_hdc302x_attr_get,
906+
.trigger_set = ti_hdc302x_trigger_set,
870907
};
871908

872909
static int ti_hdc302x_reset(const struct device *dev)
@@ -947,8 +984,6 @@ static int ti_hdc302x_init(const struct device *dev)
947984
LOG_ERR("Failed to add interrupt callback: %d", rc);
948985
return rc;
949986
}
950-
951-
k_sem_init(&data->sem_int, 0, K_SEM_MAX_LIMIT);
952987
}
953988

954989
LOG_DBG("HDC302x sensor initialized successfully");

include/zephyr/drivers/sensor/ti_hdc302x.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,6 @@ enum sensor_measurement_interval_hdc302x {
8484
HDC302X_SENSOR_MEAS_INTERVAL_MAX
8585
};
8686

87-
struct ti_hdc302x_config {
88-
struct i2c_dt_spec bus;
89-
struct gpio_dt_spec gpio_int;
90-
};
91-
92-
struct ti_hdc302x_data {
93-
struct gpio_callback cb_int;
94-
95-
/* Semaphore will be used to signal when an interrupt occurs */
96-
struct k_sem sem_int;
97-
98-
uint16_t t_sample;
99-
uint16_t rh_sample;
100-
uint16_t t_alert;
101-
uint16_t rh_alert;
102-
uint8_t t_offset;
103-
uint8_t rh_offset;
104-
enum sensor_power_mode_hdc302x power_mode;
105-
enum sensor_measurement_interval_hdc302x interval;
106-
uint8_t selected_mode[2];
107-
};
108-
10987
#ifdef __cplusplus
11088
}
11189
#endif

0 commit comments

Comments
 (0)