@@ -39,6 +39,7 @@ static int ti_hdc_sample_fetch(const struct device *dev,
3939 enum sensor_channel chan )
4040{
4141 struct ti_hdc_data * drv_data = dev -> data ;
42+ const struct ti_hdc_config * cfg = dev -> config ;
4243 uint8_t buf [4 ];
4344
4445 __ASSERT_NO_MSG (chan == SENSOR_CHAN_ALL );
@@ -50,8 +51,7 @@ static int ti_hdc_sample_fetch(const struct device *dev,
5051#endif
5152
5253 buf [0 ] = TI_HDC_REG_TEMP ;
53- if (i2c_write (drv_data -> i2c , buf , 1 ,
54- DT_INST_REG_ADDR (0 )) < 0 ) {
54+ if (i2c_write_dt (& cfg -> i2c , buf , 1 ) < 0 ) {
5555 LOG_DBG ("Failed to write address pointer" );
5656 return - EIO ;
5757 }
@@ -63,7 +63,7 @@ static int ti_hdc_sample_fetch(const struct device *dev,
6363 k_msleep (HDC_CONVERSION_TIME );
6464#endif
6565
66- if (i2c_read ( drv_data -> i2c , buf , 4 , DT_INST_REG_ADDR ( 0 ) ) < 0 ) {
66+ if (i2c_read_dt ( & cfg -> i2c , buf , 4 ) < 0 ) {
6767 LOG_DBG ("Failed to read sample data" );
6868 return - EIO ;
6969 }
@@ -110,41 +110,38 @@ static const struct sensor_driver_api ti_hdc_driver_api = {
110110 .channel_get = ti_hdc_channel_get ,
111111};
112112
113- static uint16_t read16 (const struct device * dev , uint8_t a , uint8_t d )
113+ static uint16_t read16 (const struct i2c_dt_spec * i2c , uint8_t d )
114114{
115115 uint8_t buf [2 ];
116- if (i2c_burst_read ( dev , a , d , (uint8_t * )buf , 2 ) < 0 ) {
116+ if (i2c_burst_read_dt ( i2c , d , (uint8_t * )buf , 2 ) < 0 ) {
117117 LOG_ERR ("Error reading register." );
118118 }
119119 return (buf [0 ] << 8 | buf [1 ]);
120120}
121121
122122static int ti_hdc_init (const struct device * dev )
123123{
124- struct ti_hdc_data * drv_data = dev -> data ;
124+ const struct ti_hdc_config * cfg = dev -> config ;
125125 uint16_t tmp ;
126126
127- drv_data -> i2c = device_get_binding (DT_INST_BUS_LABEL (0 ));
128-
129- if (drv_data -> i2c == NULL ) {
130- LOG_DBG ("Failed to get pointer to %s device!" ,
131- DT_INST_BUS_LABEL (0 ));
132- return - EINVAL ;
127+ if (!device_is_ready (cfg -> i2c .bus )) {
128+ LOG_ERR ("Bus device is not ready" );
129+ return - ENODEV ;
133130 }
134131
135- if (read16 (drv_data -> i2c , DT_INST_REG_ADDR (0 ),
136- TI_HDC_REG_MANUFID ) != TI_HDC_MANUFID ) {
132+ if (read16 (& cfg -> i2c , TI_HDC_REG_MANUFID ) != TI_HDC_MANUFID ) {
137133 LOG_ERR ("Failed to get correct manufacturer ID" );
138134 return - EINVAL ;
139135 }
140- tmp = read16 (drv_data -> i2c , DT_INST_REG_ADDR (0 ),
141- TI_HDC_REG_DEVICEID );
136+ tmp = read16 (& cfg -> i2c , TI_HDC_REG_DEVICEID );
142137 if (tmp != TI_HDC1000_DEVID && tmp != TI_HDC1050_DEVID ) {
143138 LOG_ERR ("Unsupported device ID" );
144139 return - EINVAL ;
145140 }
146141
147142#if DT_INST_NODE_HAS_PROP (0 , drdy_gpios )
143+ struct ti_hdc_data * drv_data = dev -> data ;
144+
148145 k_sem_init (& drv_data -> data_sem , 0 , K_SEM_MAX_LIMIT );
149146
150147 /* setup data ready gpio interrupt */
@@ -178,8 +175,12 @@ static int ti_hdc_init(const struct device *dev)
178175 return 0 ;
179176}
180177
178+ static const struct ti_hdc_config ti_hdc_config = {
179+ .i2c = I2C_DT_SPEC_INST_GET (0 ),
180+ };
181+
181182static struct ti_hdc_data ti_hdc_data ;
182183
183184DEVICE_DT_INST_DEFINE (0 , ti_hdc_init , NULL , & ti_hdc_data ,
184- NULL , POST_KERNEL , CONFIG_SENSOR_INIT_PRIORITY ,
185+ & ti_hdc_config , POST_KERNEL , CONFIG_SENSOR_INIT_PRIORITY ,
185186 & ti_hdc_driver_api );
0 commit comments