From 97275659ac40a8c36f3c809ebd5103dba232ca0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Thu, 23 Jun 2022 17:30:23 +0200 Subject: [PATCH] samples: sensor: lsm303dlhc_magn: Convert sample to use DEVICE_DT_GET_ONE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- samples/sensor/lsm303dlhc/src/main.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/samples/sensor/lsm303dlhc/src/main.c b/samples/sensor/lsm303dlhc/src/main.c index bbb9eadeba8..afa8e310fd2 100644 --- a/samples/sensor/lsm303dlhc/src/main.c +++ b/samples/sensor/lsm303dlhc/src/main.c @@ -38,20 +38,16 @@ end: void main(void) { - const struct device *accelerometer = device_get_binding( - DT_LABEL(DT_INST(0, st_lis2dh))); - const struct device *magnetometer = device_get_binding( - DT_LABEL(DT_INST(0, st_lsm303dlhc_magn))); + const struct device *accelerometer = DEVICE_DT_GET_ONE(st_lis2dh); + const struct device *magnetometer = DEVICE_DT_GET_ONE(st_lsm303dlhc_magn); - if (accelerometer == NULL) { - printf("Could not get %s device\n", - DT_LABEL(DT_INST(0, st_lis2dh))); + if (!device_is_ready(accelerometer)) { + printf("Device %s is not ready\n", accelerometer->name); return; } - if (magnetometer == NULL) { - printf("Could not get %s device\n", - DT_LABEL(DT_INST(0, st_lsm303dlhc_magn))); + if (!device_is_ready(magnetometer)) { + printf("Device %s is not ready\n", magnetometer->name); return; }