Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: sensor: lm73c: Added TI LM73C sensor driver #31064

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/sensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_subdirectory_ifdef(CONFIG_LIS2DS12 lis2ds12)
add_subdirectory_ifdef(CONFIG_LIS2DW12 lis2dw12)
add_subdirectory_ifdef(CONFIG_LIS2MDL lis2mdl)
add_subdirectory_ifdef(CONFIG_LIS3MDL lis3mdl)
add_subdirectory_ifdef(CONFIG_LM73C lm73c)
add_subdirectory_ifdef(CONFIG_LPS22HB lps22hb)
add_subdirectory_ifdef(CONFIG_LPS22HH lps22hh)
add_subdirectory_ifdef(CONFIG_LPS25HB lps25hb)
Expand Down
2 changes: 2 additions & 0 deletions drivers/sensor/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ source "drivers/sensor/lis2mdl/Kconfig"

source "drivers/sensor/lis3mdl/Kconfig"

source "drivers/sensor/lm73c/Kconfig"

source "drivers/sensor/lps22hb/Kconfig"

source "drivers/sensor/lps22hh/Kconfig"
Expand Down
5 changes: 5 additions & 0 deletions drivers/sensor/lm73c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources_ifdef(CONFIG_LM73C lm73c.c)
27 changes: 27 additions & 0 deletions drivers/sensor/lm73c/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2020 SER Consulting LLC
# SPDX-License-Identifier: Apache-2.0

menuconfig LM73C
bool "LM73C Temperature Sensor"
depends on I2C
help
Enable I2C-based driver for LM73C Temperature Sensor.

if LM73C

choice
riedlse marked this conversation as resolved.
Show resolved Hide resolved
prompt "LM73C temperature precision"
default LM73C_TEMP_PREC_1_32
help
Select temperature precision for the LM73C sensor.
config LM73C_TEMP_PREC_1_4
bool "0.25"
config LM73C_TEMP_PREC_1_8
bool "0.125"
config LM73C_TEMP_PREC_1_16
bool "0.0625"
config LM73C_TEMP_PREC_1_32
bool "0.03125"
endchoice

endif # LM73C
138 changes: 138 additions & 0 deletions drivers/sensor/lm73c/doc/LM73CIMK-0.lbr
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License (CC BY-SA) with Design Exception 1.0-->
riedlse marked this conversation as resolved.
Show resolved Hide resolved
<eagle version="7.1.0">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
<setting verticaltext="up"/>
</settings>
<grid distance="0.1" unitdist="inch" unit="inch" style="lines" multiple="1" display="no" altdistance="0.01" altunitdist="inch" altunit="inch"/>
<layers>
<layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
<layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
<layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
<layer number="18" name="Vias" color="2" fill="1" visible="yes" active="yes"/>
<layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
<layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
<layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
<layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
<layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="27" name="tValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="28" name="bValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="29" name="tStop" color="7" fill="3" visible="yes" active="yes"/>
<layer number="30" name="bStop" color="7" fill="6" visible="no" active="yes"/>
<layer number="31" name="tCream" color="7" fill="4" visible="yes" active="yes"/>
<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
<layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
<layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
<layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
<layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
<layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="39" name="tKeepout" color="4" fill="11" visible="yes" active="yes"/>
<layer number="40" name="bKeepout" color="1" fill="11" visible="yes" active="yes"/>
<layer number="41" name="tRestrict" color="4" fill="10" visible="yes" active="yes"/>
<layer number="42" name="bRestrict" color="1" fill="10" visible="yes" active="yes"/>
<layer number="43" name="vRestrict" color="2" fill="10" visible="yes" active="yes"/>
<layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
<layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
<layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
<layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
<layer number="48" name="Document" color="7" fill="1" visible="yes" active="yes"/>
<layer number="49" name="Reference" color="7" fill="1" visible="yes" active="yes"/>
<layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="90" name="Modules" color="5" fill="1" visible="yes" active="yes"/>
<layer number="91" name="Nets" color="2" fill="1" visible="yes" active="yes"/>
<layer number="92" name="Busses" color="1" fill="1" visible="yes" active="yes"/>
<layer number="93" name="Pins" color="2" fill="1" visible="yes" active="yes"/>
<layer number="94" name="Symbols" color="4" fill="1" visible="yes" active="yes"/>
<layer number="95" name="Names" color="7" fill="1" visible="yes" active="yes"/>
<layer number="96" name="Values" color="7" fill="1" visible="yes" active="yes"/>
<layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
<layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
</layers>
<library>
<packages>
<package name="SOT95P280X110-6N">
<wire x1="-0.8" y1="-1.45" x2="0.8" y2="-1.45" width="0.127" layer="51"/>
<wire x1="0.8" y1="-1.45" x2="0.8" y2="1.45" width="0.127" layer="51"/>
<wire x1="0.8" y1="1.45" x2="-0.8" y2="1.45" width="0.127" layer="51"/>
<wire x1="-0.8" y1="1.45" x2="-0.8" y2="-1.45" width="0.127" layer="51"/>
<wire x1="-0.8" y1="1.565" x2="0.8" y2="1.565" width="0.127" layer="21"/>
<wire x1="-0.8" y1="-1.565" x2="0.8" y2="-1.565" width="0.127" layer="21"/>
<wire x1="-2.13" y1="-1.495" x2="-1.05" y2="-1.495" width="0.05" layer="39"/>
<wire x1="-1.05" y1="-1.495" x2="-1.05" y2="-1.7" width="0.05" layer="39"/>
<wire x1="-1.05" y1="-1.7" x2="1.05" y2="-1.7" width="0.05" layer="39"/>
<wire x1="1.05" y1="-1.7" x2="1.05" y2="-1.495" width="0.05" layer="39"/>
<wire x1="1.05" y1="-1.495" x2="2.13" y2="-1.495" width="0.05" layer="39"/>
<wire x1="2.13" y1="-1.495" x2="2.13" y2="1.495" width="0.05" layer="39"/>
<wire x1="2.13" y1="1.495" x2="1.05" y2="1.495" width="0.05" layer="39"/>
<wire x1="1.05" y1="1.495" x2="1.05" y2="1.7" width="0.05" layer="39"/>
<wire x1="1.05" y1="1.7" x2="-1.05" y2="1.7" width="0.05" layer="39"/>
<wire x1="-1.05" y1="1.7" x2="-1.05" y2="1.495" width="0.05" layer="39"/>
<wire x1="-1.05" y1="1.495" x2="-2.13" y2="1.495" width="0.05" layer="39"/>
<wire x1="-2.13" y1="1.495" x2="-2.13" y2="-1.495" width="0.05" layer="39"/>
<circle x="-2.4" y="1.2" radius="0.1" width="0.2" layer="21"/>
<circle x="-2.4" y="1.2" radius="0.1" width="0.2" layer="51"/>
<text x="-2.1" y="1.8" size="0.8128" layer="25">&gt;NAME</text>
<text x="-2.1" y="-1.8" size="0.8128" layer="27" align="top-left">&gt;VALUE</text>
<smd name="1" x="-1.155" y="0.95" dx="1.45" dy="0.59" layer="1" roundness="25"/>
<smd name="2" x="-1.155" y="0" dx="1.45" dy="0.59" layer="1" roundness="25"/>
<smd name="3" x="-1.155" y="-0.95" dx="1.45" dy="0.59" layer="1" roundness="25"/>
<smd name="4" x="1.155" y="-0.95" dx="1.45" dy="0.59" layer="1" roundness="25"/>
<smd name="5" x="1.155" y="0" dx="1.45" dy="0.59" layer="1" roundness="25"/>
<smd name="6" x="1.155" y="0.95" dx="1.45" dy="0.59" layer="1" roundness="25"/>
</package>
</packages>
<symbols>
<symbol name="LM73CIMK-0">
<wire x1="-12.7" y1="10.16" x2="12.7" y2="10.16" width="0.41" layer="94"/>
<wire x1="12.7" y1="10.16" x2="12.7" y2="-10.16" width="0.41" layer="94"/>
<wire x1="12.7" y1="-10.16" x2="-12.7" y2="-10.16" width="0.41" layer="94"/>
<wire x1="-12.7" y1="-10.16" x2="-12.7" y2="10.16" width="0.41" layer="94"/>
<text x="-12.7" y="11.16" size="2.0828" layer="95" ratio="10" rot="SR0">&gt;NAME</text>
<text x="-12.7" y="-14.16" size="2.0828" layer="96" ratio="10" rot="SR0">&gt;VALUE</text>
<pin name="ADDR" x="-17.78" y="2.54" length="middle" direction="in"/>
<pin name="SMBCLK" x="-17.78" y="0" length="middle" direction="in" function="clk"/>
<pin name="VDD" x="17.78" y="7.62" length="middle" direction="pwr" rot="R180"/>
<pin name="!ALERT" x="17.78" y="2.54" length="middle" direction="out" rot="R180"/>
<pin name="SMBDAT" x="17.78" y="0" length="middle" direction="out" rot="R180"/>
<pin name="GND" x="17.78" y="-5.08" length="middle" direction="pwr" rot="R180"/>
</symbol>
</symbols>
<devicesets>
<deviceset name="LM73CIMK-0" prefix="U">
<gates>
<gate name="A" symbol="LM73CIMK-0" x="0" y="0"/>
</gates>
<devices>
<device name="" package="SOT95P280X110-6N">
<connects>
<connect gate="A" pin="ADDR" pad="1"/>
<connect gate="A" pin="GND" pad="2"/>
<connect gate="A" pin="SMBCLK" pad="4"/>
<connect gate="A" pin="SMBDAT" pad="6"/>
<connect gate="A" pin="VDD" pad="3"/>
<connect gate="A" pin="!ALERT" pad="5"/>
</connects>
<technologies>
<technology name="">
<attribute name="MP" value="LM73CIMK-0"/>
<attribute name="Description" value="
Temperature Sensor Digital, Local -40°C ~ 150°C 13 b TSOT-23-6
"/>
<attribute name="Package" value="SOT-23 Texas Instruments"/>
<attribute name="Digi-Key_Part_Number" value="LM73CIMK-0/NOPBCT-ND"/>
<attribute name="MF" value="Texas Instruments"/>
</technology>
</technologies>
</device>
</devices>
</deviceset>
</devicesets>
</library>
</drawing>
</eagle>
Binary file added drivers/sensor/lm73c/doc/lm73.pdf
Binary file not shown.
156 changes: 156 additions & 0 deletions drivers/sensor/lm73c/lm73c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2020 SER Consulting LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <drivers/sensor.h>
#include <kernel.h>
#include <device.h>
#include <logging/log.h>
#include <drivers/i2c.h>
#include "lm73c.h"

#define DT_DRV_COMPAT ti_lm73c

#define LM73C_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)

LOG_MODULE_REGISTER(LM73C, CONFIG_SENSOR_LOG_LEVEL);

#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0
#warning "LM73C driver enabled without any devices"
#endif


struct lm73c_data {
const struct device *i2c_dev;
uint16_t temperature;
};

/**
* @brief fetch a sample from the sensor
*
* @return 0
*/
static int lm73c_sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
int retval;
struct lm73c_data *lm73_data = dev->data;
uint8_t temp[2];

retval = i2c_burst_read(lm73_data->i2c_dev,
DT_INST_REG_ADDR(0),
LM73_REG_TEMP,
temp, sizeof(temp));

if (retval == 0) {
lm73_data->temperature = (temp[0] << 8) | temp[1];
} else {
LOG_ERR("lm73c read register err");
}

return retval;
}

/**
* @brief sensor value get
*
* @return -ENOTSUP for unsupported channels
*/
static int lm73c_channel_get(const struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
{
struct lm73c_data *lm73_data = dev->data;

if (chan != SENSOR_CHAN_AMBIENT_TEMP) {
return -ENOTSUP;
}
int32_t temp = (int32_t)lm73_data->temperature;
riedlse marked this conversation as resolved.
Show resolved Hide resolved

if (temp > 0x7fff) {
temp -= 0x8000;
}
temp = (temp >> 2) * 31250;
val->val1 = temp / 1000000;
val->val2 = temp % 1000000;
return 0;
}

static const struct sensor_driver_api lm73c_api = {
.sample_fetch = &lm73c_sample_fetch,
.channel_get = &lm73c_channel_get,
};

/**
* @brief initialize the sensor
*
* @return 0 for success
*/

static int lm73c_init(const struct device *dev)
{
const char *name = dev->name;
struct lm73c_data *drv_data = dev->data;

LOG_DBG("%s: Initializing", name);

drv_data->i2c_dev = device_get_binding(
riedlse marked this conversation as resolved.
Show resolved Hide resolved
DT_INST_BUS_LABEL(0));

if (!drv_data->i2c_dev) {
LOG_DBG("%s: i2c master not found: 0", name);
return -EINVAL;
}

int retval;
uint8_t temp[2];
uint16_t id;

retval = i2c_burst_read(drv_data->i2c_dev,
DT_INST_REG_ADDR(0),
LM73_REG_ID,
temp, sizeof(temp));
if (retval == 0) {
id = (temp[0] << 8) | temp[1];
LOG_DBG("%s: id (0x0190) = %x", name, id);

/* set resolution to .03125 deg C */
temp[0] = LM73_TEMP_PREC;
retval = i2c_burst_write(drv_data->i2c_dev,
DT_INST_REG_ADDR(0),
LM73_REG_CTRL,
temp, 1);
if (retval == 0) {
/* kick off the first read */
retval = i2c_burst_read(drv_data->i2c_dev,
DT_INST_REG_ADDR(0),
LM73_REG_TEMP,
temp, sizeof(temp));
if (retval == 0) {
drv_data->temperature =
(temp[0] << 8) | temp[1];
} else {
LOG_ERR("%s: First temp read err",
name);
return -EINVAL;
}
} else {
LOG_ERR("%s: Set resolution err",
name);
return -EINVAL;
}
} else {
LOG_ERR("%s: Read ID register err", name);
return -EINVAL;
}
LOG_DBG("%s: Initialized", name);
return 0;
}

static struct lm73c_data lm73_data;

DEVICE_AND_API_INIT(lm73c, DT_INST_LABEL(0), lm73c_init,
riedlse marked this conversation as resolved.
Show resolved Hide resolved
&lm73_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &lm73c_api);
30 changes: 30 additions & 0 deletions drivers/sensor/lm73c/lm73c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020 SER Consulting LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef _LM73C_H
#define _LM73C_H

/* LM73 registers */
#define LM73_REG_TEMP 0x00
#define LM73_REG_CONF 0x01
#define LM73_REG_THIGH 0x02
#define LM73_REG_TLOW 0x03
#define LM73_REG_CTRL 0x04
#define LM73_REG_ID 0x07

#define LM73_ID 0x9001

#if defined CONFIG_LM73C_TEMP_PREC_1_4
#define LM73_TEMP_PREC (0x00)
#elif defined CONFIG_LM73C_TEMP_PREC_1_8
#define LM73_TEMP_PREC (0x20)
#elif defined CONFIG_LM73C_TEMP_PREC_1_16
#define LM73_TEMP_PREC (0x40)
#elif defined CONFIG_LM73C_TEMP_PREC_1_32
#define LM73_TEMP_PREC (0x60)
#endif

#endif /* _LM73C_H */
8 changes: 8 additions & 0 deletions samples/sensor/lm73c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(lm73c)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
riedlse marked this conversation as resolved.
Show resolved Hide resolved
Loading