@@ -29,6 +29,26 @@ static const uint8_t REG_HEATER_ON[] = {0x30, 0x6D};
29
29
static const uint8_t REG_HEATER_OFF [] = {0x30 , 0x66 };
30
30
static const uint8_t REG_HEATER_LEVEL [] = {0x30 , 0x6E };
31
31
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
+
32
52
/* Alert status registers */
33
53
static const uint8_t alert_set_commands [][2 ] = {
34
54
{0x61 , 0x00 },
@@ -266,7 +286,10 @@ static void interrupt_callback(const struct device *dev, struct gpio_callback *c
266
286
struct ti_hdc302x_data * data = CONTAINER_OF (cb , struct ti_hdc302x_data , cb_int );
267
287
ARG_UNUSED (pins );
268
288
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
+ }
270
293
}
271
294
272
295
/**
@@ -298,7 +321,8 @@ static int ti_hdc302x_sample_fetch(const struct device *dev, enum sensor_channel
298
321
}
299
322
}
300
323
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)
302
326
*/
303
327
rc = read_sensor_data (dev , buf , sizeof (buf ));
304
328
if (rc < 0 ) {
@@ -862,11 +886,24 @@ static int ti_hdc302x_attr_set(const struct device *dev, enum sensor_channel cha
862
886
return 0 ;
863
887
}
864
888
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
+
865
901
static DEVICE_API (sensor , ti_hdc302x_api_funcs ) = {
866
902
.sample_fetch = ti_hdc302x_sample_fetch ,
867
903
.channel_get = ti_hdc302x_channel_get ,
868
904
.attr_set = ti_hdc302x_attr_set ,
869
905
.attr_get = ti_hdc302x_attr_get ,
906
+ .trigger_set = ti_hdc302x_trigger_set ,
870
907
};
871
908
872
909
static int ti_hdc302x_reset (const struct device * dev )
@@ -947,8 +984,6 @@ static int ti_hdc302x_init(const struct device *dev)
947
984
LOG_ERR ("Failed to add interrupt callback: %d" , rc );
948
985
return rc ;
949
986
}
950
-
951
- k_sem_init (& data -> sem_int , 0 , K_SEM_MAX_LIMIT );
952
987
}
953
988
954
989
LOG_DBG ("HDC302x sensor initialized successfully" );
0 commit comments