Skip to content

drivers/tmp117: TMP117 driver#22310

Open
leocordier wants to merge 32 commits into
RIOT-OS:masterfrom
leocordier:driver_tmp117
Open

drivers/tmp117: TMP117 driver#22310
leocordier wants to merge 32 commits into
RIOT-OS:masterfrom
leocordier:driver_tmp117

Conversation

@leocordier

Copy link
Copy Markdown

Contribution description

This pull request add a basic driver for the TMP117 sensor with the following capabilities:

  • tmp117 initialization
  • tmp117 configuration : update the conversion mode, cycle and averaging parameters
  • tmp117 temperature reading : with a result in centi-degrees
  • check if tmp117 temperature measure is ready

This pull request add a driver in the drivers folder and a test in the test/drivers folder

Testing procedure

The basic test that i wrote, initialize the sensor with default paramaters and i2c address.
After the initialization, it display the measured temperature every 1.5 seconds.

If the initialization or the temperature reading fail, it displays anb error.

Issues/PRs references

issue #22308

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • none

tests/drivers/tmp117: test for the TMP117 driver

This driver add the support for the TMP117 i2c temperature sensor.
@github-actions github-actions Bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: drivers Area: Device drivers labels May 19, 2026
@crasbe crasbe added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 19, 2026
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread tests/drivers/tmp117/README.md Outdated
Comment thread tests/drivers/tmp117/README.md Outdated
Comment thread tests/drivers/tmp117/main.c Outdated
@crasbe crasbe linked an issue May 19, 2026 that may be closed by this pull request
leocordier and others added 14 commits May 19, 2026 16:15
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Comment thread drivers/include/tmp117.h
tmp117_params_t params;
uint8_t is_initialized;
} tmp117_t;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines.

Static checks will highlight a few more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still more blank than needed

Suggested change

Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
Comment thread drivers/include/tmp117.h Outdated
@basilfx

basilfx commented May 19, 2026

Copy link
Copy Markdown
Member

Thanks @leocordier.

Could you also check if SAUL support would be easy to add? See https://docs.riot-os.org/advanced_tutorials/device_drivers/#saul

@basilfx

basilfx commented May 26, 2026

Copy link
Copy Markdown
Member

I gave it another quick pass. It's getting there :-)

Comment thread drivers/include/tmp117.h Outdated
#pragma once

/**
* @defgroup driver_tmp117

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @defgroup driver_tmp117
* @defgroup drivers_tmp117

Other sensors use drivers_XXX. This needs to be adapted in multiple files.

@leocordier leocordier requested a review from basilfx May 26, 2026 12:37
Comment thread tests/drivers/tmp117/Makefile.uncrustify Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
Comment thread drivers/tmp117/tmp117.c Outdated
@leocordier leocordier requested a review from kfessel May 26, 2026 13:39

@kfessel kfessel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the temperature conversion seem right now; please test with you sensor

please use "speaking" names

conf_reg or conf_val where appropriate

please check for c++ style comments

please ensure exactly 1 NL before EOF

Comment thread drivers/tmp117/tmp117.c Outdated
int tmp117_set_averaging(tmp117_t *dev, tmp117_avg_t avg)
{
int res = TMP117_NOI2C;
uint16_t value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint16_t value;
uint16_t conf_reg;

Comment thread drivers/tmp117/Makefile.dep Outdated
@@ -0,0 +1 @@
FEATURES_REQUIRED += periph_i2c No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Comment thread drivers/tmp117/Makefile.include Outdated
@@ -0,0 +1,2 @@
USEMODULE_INCLUDES_tmp117 := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_tmp117) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Comment thread tests/drivers/tmp117/Makefile Outdated
USEMODULE += ztimer
USEMODULE += ztimer_msec

include $(RIOTBASE)/Makefile.include No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Comment thread tests/drivers/tmp117/main.c
Comment thread drivers/tmp117/tmp117.c Outdated
int tmp117_set_conversion_cycle(tmp117_t *dev, tmp117_conv_cycle_t cycle)
{
int res = TMP117_NOI2C;
uint16_t value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint16_t value;
uint16_t conf_reg;

Comment thread drivers/tmp117/tmp117.c Outdated
int tmp117_set_conversion_mode(tmp117_t *dev, tmp117_conv_mode_t mode)
{
int res = TMP117_NOI2C;
uint16_t value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint16_t value;
uint16_t conf_reg;

Comment thread drivers/tmp117/tmp117.c Outdated

status = _read_16_reg(dev, TMP117_REG_DEVICE_ID, &reg);

//checking if sensor is a tmp117

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@basilfx is right we do not like sane c++ single line comments we always want /* */

@kfessel

kfessel commented May 26, 2026

Copy link
Copy Markdown
Contributor

If you think your code is working as intended please test with your hardware and post:

  • a test setup description (mcu, connection (maybe photo)) and
  • test results (console or display photo)

Comment thread drivers/include/tmp117.h Outdated
};

typedef enum {
TMP117_CONV_CC = 0, /**< continous conversion mode */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow tabs made it into this file please use 4 space for indention only

(makefiles aside)

Comment thread drivers/tmp117/tmp117.c Outdated
Comment on lines +29 to +30
#define DEFAULT_CONFIG_VALUE (dev->params.conv_mode << 10 | dev->params.conv_cycle << \
7 | dev->params.avg << 5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use your defines

#define TMP117_DATA_READY_SHIFT     13  /**< data ready bit shift in configuration register */
#define TMP117_CONV_MODE_SHIFT      10  /**< conversion mode bits shift in configuration register */
#define TMP117_CONV_CYCLE_SHIFT     7   /**< conversion cycle bits shift in configuration register */
#define TMP117_AVG_SHIFT
Suggested change
#define DEFAULT_CONFIG_VALUE (dev->params.conv_mode << 10 | dev->params.conv_cycle << \
7 | dev->params.avg << 5)
#define DEFAULT_CONFIG_VALUE ( dev->params.conv_mode << TMP117_CONV_MODE_SHIFT \
| dev->params.conv_cycle << TMP117_CONV_CYCLE_SHIFT \
| dev->params.avg << TMP117_AVG_SHIFT)

@leocordier

Copy link
Copy Markdown
Author

If you think your code is working as intended please test with your hardware and post:

* a test setup description (mcu, connection (maybe photo)) and

* test results (console or display photo)

Here is the setup i use to test the TMP117 driver:
Hardware

2026-05-27-10-26-03-758 2026-05-27-10-26-11-372 2026-05-27-10-26-15-560

Result

################################
####### TMP117 test app ########
################################

Initializing tmp117 sensor ...
  done.

temperature : 25.78°C
temperature : 25.77°C
temperature : 25.78°C
temperature : 25.78°C
temperature : 25.78°C
temperature : 25.77°C
temperature : 25.80°C
temperature : 25.85°C
temperature : 26.02°C
temperature : 26.10°C
temperature : 26.25°C
temperature : 26.30°C
temperature : 26.39°C
temperature : 26.44°C
temperature : 26.46°C
temperature : 26.46°C
temperature : 26.46°C
temperature : 26.46°C
temperature : 26.45°C
temperature : 26.42°C
temperature : 26.42°C
temperature : 26.39°C

@leocordier leocordier requested a review from kfessel May 27, 2026 08:35
@kfessel

kfessel commented May 28, 2026

Copy link
Copy Markdown
Contributor

If you think your code is working as intended please test with your hardware and post:

Here is the setup i use to test the TMP117 driver: Hardware
...
Result

################################
####### TMP117 test app ########
################################

Initializing tmp117 sensor ...
  done.

temperature : 25.78°C
...
temperature : 26.39°C
temperature : 26.44°C
temperature : 26.46°C

I see your test PCB has multiple of these sensors is that supported by the driver

What is the i2c address translation IC?'

is that LTC4316?

@kfessel kfessel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for all the white space things but there will be a time the static test will complain again

/**
* @brief Define the number of configured sensors
*/
#define TMP117_NUM (unsigned)(sizeof((tmp117_params)) / sizeof((tmp117_params)[0]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you include container.h

I assume it is this run
https://ci.riot-os.org/details/786c4cfa69eb4a8089a198ac2141682f

/**
* @brief Define the number of saul info
*/
#define TMP117_INFO_NUM (unsigned)(sizeof((tmp117_saul_info)) / sizeof((tmp117_saul_info)[0]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Comment thread drivers/tmp117/include/tmp117_params.h Outdated
* @{
*/
#ifndef TMP117_PARAM_I2C
# define TMP117_PARAM_I2C (I2C_DEV(0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define TMP117_PARAM_I2C (I2C_DEV(0))
# define TMP117_PARAM_I2C (I2C_DEV(0))

Comment thread drivers/tmp117/include/tmp117_params.h Outdated
# define TMP117_PARAM_I2C (I2C_DEV(0))
#endif
#ifndef TMP117_PARAM_ADDR
# define TMP117_PARAM_ADDR (0x48)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define TMP117_PARAM_ADDR (0x48)
# define TMP117_PARAM_ADDR (0x48)

Comment on lines +49 to +55
#ifndef TMP117_PARAMS
# define TMP117_PARAMS { .i2c = TMP117_PARAM_I2C, \
.addr = TMP117_PARAM_ADDR, \
.conv_mode = TMP117_PARAM_CONV_MODE, \
.conv_cycle = TMP117_PARAM_CONV_CYCLE, \
.avg = TMP117_PARAM_AVG }
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifndef TMP117_PARAMS
# define TMP117_PARAMS { .i2c = TMP117_PARAM_I2C, \
.addr = TMP117_PARAM_ADDR, \
.conv_mode = TMP117_PARAM_CONV_MODE, \
.conv_cycle = TMP117_PARAM_CONV_CYCLE, \
.avg = TMP117_PARAM_AVG }
#endif
#ifndef TMP117_PARAMS
# define TMP117_PARAMS { .i2c = TMP117_PARAM_I2C, \
.addr = TMP117_PARAM_ADDR, \
.conv_mode = TMP117_PARAM_CONV_MODE, \
.conv_cycle = TMP117_PARAM_CONV_CYCLE, \
.avg = TMP117_PARAM_AVG }
#endif

Comment thread drivers/tmp117/tmp117.c

conf_reg &= ~TMP117_AVG_MASK;
conf_reg |= avg << TMP117_AVG_SHIFT;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment thread drivers/tmp117/tmp117.c
DEBUG("[tmp117] set averaging - error: unable to read conf reg \n");
goto release;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +26 to +27


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


#include "tmp117.h"
#include "tmp117_params.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


ztimer_sleep(ZTIMER_MSEC, 1500);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@leocordier

Copy link
Copy Markdown
Author

If you think your code is working as intended please test with your hardware and post:

Here is the setup i use to test the TMP117 driver: Hardware
...
Result

################################
####### TMP117 test app ########
################################

Initializing tmp117 sensor ...
  done.

temperature : 25.78°C
...
temperature : 26.39°C
temperature : 26.44°C
temperature : 26.46°C

I see your test PCB has multiple of these sensors is that supported by the driver

What is the i2c address translation IC?'

is that LTC4316?

Hello,
it's a test PCB that i am using currently at work. It has 8 TMP117 sensor but in this test i use only one.
You can initialize and use more thant one sensor with the driver, you just need to pass to the init function a new tmp117_t structure with parameters.

And yes the i2c address shifting IC is a LTCLTC4316.

@leocordier

Copy link
Copy Markdown
Author

sorry for all the white space things but there will be a time the static test will complain again

Is there a tool to automatically delete those blank lines and apply the appropriate spacing?
I use uncrustify with the riot-os spec every time i push a commit but this seems not to be enough.

@basilfx

basilfx commented Jun 23, 2026

Copy link
Copy Markdown
Member

sorry for all the white space things but there will be a time the static test will complain again

Is there a tool to automatically delete those blank lines and apply the appropriate spacing? I use uncrustify with the riot-os spec every time i push a commit but this seems not to be enough.

I usually have my editor configured to remove trailing whitespaces. For example VS Code can do this. I also have a plugin to highlight them.

@leocordier

Copy link
Copy Markdown
Author

sorry for all the white space things but there will be a time the static test will complain again

Is there a tool to automatically delete those blank lines and apply the appropriate spacing? I use uncrustify with the riot-os spec every time i push a commit but this seems not to be enough.

I usually have my editor configured to remove trailing whitespaces. For example VS Code can do this. I also have a plugin to highlight them.

I just removed them by hand, it should be good now

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a lot of other review comments are still open.

Comment thread tests/drivers/tmp117/README.md Outdated
* conversion cycle : 1s
* averaging : 8 samples

After the initialization, the temperature value is displayed every 1s5.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After the initialization, the temperature value is displayed every 1s5.
After the initialization, the temperature value is displayed every 1.5 seconds.

Comment thread tests/drivers/tmp117/README.md Outdated
Comment on lines +9 to +11
* conversion mode : continuous
* conversion cycle : 1s
* averaging : 8 samples

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* conversion mode : continuous
* conversion cycle : 1s
* averaging : 8 samples
* conversion mode: continuous
* conversion cycle: 1s
* averaging: 8 samples

puts("Initializing tmp117 sensor ...");

if (tmp117_init(&tmp117, tmp117_params) != TMP117_OK) {
return -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return -1;
puts(" failed.\n");
return -1;

Comment thread tests/drivers/tmp117/main.c Outdated

while (1) {
if (tmp117_read_temperature(&tmp117, &raw_temp) == TMP117_OK) {
printf("temperature : %02d.%02d°C\n", raw_temp / 100, raw_temp % 100);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf("temperature : %02d.%02d°C\n", raw_temp / 100, raw_temp % 100);
printf("Temperature: %02d.%02d°C\n", raw_temp / 100, raw_temp % 100);

Comment thread tests/drivers/tmp117/main.c Outdated
printf("temperature : %02d.%02d°C\n", raw_temp / 100, raw_temp % 100);
}
else {
puts("[tmp117 test] error : unable to read temperature\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
puts("[tmp117 test] error : unable to read temperature\n");
puts("ERROR: unable to read temperature\n");

I think in this case it's clear which test is running.

Comment thread drivers/include/tmp117.h Outdated
Comment on lines +105 to +109
* @param[in, out] dev device descriptor
* @param[out] value read value in centi-celsius
*
* @return TMP117_OK on success
* @return TMP117_I2C if other error occurs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param[in, out] dev device descriptor
* @param[out] value read value in centi-celsius
*
* @return TMP117_OK on success
* @return TMP117_I2C if other error occurs
* @param[in,out] dev device descriptor
* @param[out] value read value in centi-celsius
*
* @retval TMP117_OK on success
* @retval TMP117_I2C if other error occurs

Comment thread drivers/include/tmp117.h
Comment thread drivers/include/tmp117.h Outdated
tmp117_conv_mode_t conv_mode; /**< conversion mode */
tmp117_conv_cycle_t conv_cycle; /**< conversion cycle time */
tmp117_avg_t avg; /**< data averaging*/
}tmp117_params_t;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}tmp117_params_t;
} tmp117_params_t;

assert(TMP117_NUM == TMP117_INFO_NUM);

for (unsigned i = 0; i < TMP117_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing tmp117 #%u\n", i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_DEBUG("[auto_init_saul] initializing tmp117 #%u\n", i);
LOG_DEBUG("[auto_init_saul] initializing TMP117 #%u\n", i);

LOG_DEBUG("[auto_init_saul] initializing tmp117 #%u\n", i);

if (tmp117_init(&tmp117_devs[i], &tmp117_params[i]) != TMP117_OK) {
LOG_ERROR("[auto_init_saul] error initializing tmp117 #%u\n", i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_ERROR("[auto_init_saul] error initializing tmp117 #%u\n", i);
LOG_ERROR("[auto_init_saul] error initializing TMP117 #%u\n", i);

@leocordier leocordier requested a review from crasbe June 29, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: doc Area: Documentation Area: drivers Area: Device drivers Area: SAUL Area: Sensor/Actuator Uber Layer Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a driver for the TMP117 temperature sensor

5 participants