From ed68ef5678cfbd14f1435f30d76edbfe319dc5f7 Mon Sep 17 00:00:00 2001 From: Guillaume Lager Date: Mon, 30 Aug 2021 12:05:24 +0200 Subject: [PATCH] samples: tmp116: Add access to eeprom Add read access to internal tmp116 eeprom which contains the device unique id after manufacturing Signed-off-by: Guillaume Lager --- .../tmp116/boards/nucleo_f401re.overlay | 9 ++++++++ samples/sensor/tmp116/prj.conf | 4 ++++ samples/sensor/tmp116/src/main.c | 22 ++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/samples/sensor/tmp116/boards/nucleo_f401re.overlay b/samples/sensor/tmp116/boards/nucleo_f401re.overlay index 3ba3e8d4843..1ad19f76a7b 100644 --- a/samples/sensor/tmp116/boards/nucleo_f401re.overlay +++ b/samples/sensor/tmp116/boards/nucleo_f401re.overlay @@ -10,6 +10,15 @@ compatible = "ti,tmp116"; reg = <0x4B>; label = "TMP116"; + #address-cells = <1>; + #size-cells = <0>; + + eeprom: ti_tmp116_eeprom@0 { + compatible = "ti,tmp116-eeprom"; + reg = <0x0>; + label = "TMP116_EEPROM"; + read-only; + }; }; }; diff --git a/samples/sensor/tmp116/prj.conf b/samples/sensor/tmp116/prj.conf index 0555ec27e50..667f5896540 100644 --- a/samples/sensor/tmp116/prj.conf +++ b/samples/sensor/tmp116/prj.conf @@ -1,4 +1,8 @@ CONFIG_STDOUT_CONSOLE=y CONFIG_I2C=y CONFIG_SENSOR=y +CONFIG_SENSOR_INIT_PRIORITY=90 CONFIG_TMP116=y +CONFIG_EEPROM=y +CONFIG_EEPROM_INIT_PRIORITY=91 +CONFIG_EEPROM_TMP116=y diff --git a/samples/sensor/tmp116/src/main.c b/samples/sensor/tmp116/src/main.c index 86d661fda1f..4f7a3cda355 100644 --- a/samples/sensor/tmp116/src/main.c +++ b/samples/sensor/tmp116/src/main.c @@ -7,12 +7,17 @@ #include #include #include +#include +#include #include #include +static uint8_t eeprom_content[EEPROM_TMP116_SIZE]; + void main(void) { - const struct device *dev; + const struct device *dev = DEVICE_DT_GET(DT_INST(0, ti_tmp116)); + const struct device *eeprom = DEVICE_DT_GET(DT_INST(0, ti_tmp116_eeprom)); struct sensor_value temp_value; /* offset to be added to the temperature @@ -21,11 +26,22 @@ void main(void) struct sensor_value offset_value; int ret; - dev = device_get_binding(DT_LABEL(DT_INST(0, ti_tmp116))); - __ASSERT(dev != NULL, "Failed to get TMP116 device binding"); + __ASSERT(device_is_ready(dev), "TMP116 device not ready"); + __ASSERT(device_is_ready(eeprom), "TMP116 eeprom device not ready"); printk("Device %s - %p is ready\n", dev->name, dev); + ret = eeprom_read(eeprom, 0, eeprom_content, sizeof(eeprom_content)); + if (ret == 0) { + printk("eeprom content %02x%02x%02x%02x%02x%02x%02x%02x\n", + eeprom_content[0], eeprom_content[1], + eeprom_content[2], eeprom_content[3], + eeprom_content[4], eeprom_content[5], + eeprom_content[6], eeprom_content[7]); + } else { + printk("Failed to get eeprom content\n"); + } + /* * if an offset of 2.5 oC is to be added, * set val1 = 2 and val2 = 500000.