samples: sensor: hmc5883l: Convert sample to use DEVICE_DT_GET_ONE
Move to use DEVICE_DT_GET_ONE instead of device_get_binding as
we work on phasing out use of DTS 'label' property.
Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
diff --git a/samples/sensor/hmc5883l/src/main.c b/samples/sensor/hmc5883l/src/main.c
index 84d286f..9bcced0 100644
--- a/samples/sensor/hmc5883l/src/main.c
+++ b/samples/sensor/hmc5883l/src/main.c
@@ -38,14 +38,10 @@
void main(void)
{
- const struct device *dev;
+ const struct device *dev = DEVICE_DT_GET_ONE(honeywell_hmc5883l);
- dev = device_get_binding(DT_LABEL(DT_INST(0, honeywell_hmc5883l)));
-
- if (dev == NULL) {
- printk("Could not get %s device at I2C addr 0x%02X\n",
- DT_LABEL(DT_INST(0, honeywell_hmc5883l)),
- DT_REG_ADDR(DT_INST(0, honeywell_hmc5883l)));
+ if (!device_is_ready(dev)) {
+ printk("Device %s is not ready\n", dev->name);
return;
}