Skip to content

Commit 3ba6047

Browse files
nmaggioniacassis
authored andcommitted
drivers/sensors/tmp112: Add support for TMP112 temperature sensor
Add support for the Texas Instruments TMP112 I2C/SMBus digital temperature sensor. Also add a new defconfig that includes support for a TMP112 sensor and extend the existing documentation to include its description. Signed-off-by: Niccolò Maggioni <[email protected]>
1 parent 2b3741d commit 3ba6047

File tree

11 files changed

+764
-19
lines changed

11 files changed

+764
-19
lines changed

Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,42 +48,42 @@ Pad Signal Notes
4848
===== ========== ==========
4949
1 GPIO0 Default TX for UART0 serial console
5050
2 GPIO1 Default RX for UART0 serial console
51-
3 Ground
52-
4 GPIO2
53-
5 GPIO3
51+
3 Ground
52+
4 GPIO2
53+
5 GPIO3
5454
6 GPIO4 Default SDA for I2C0
5555
7 GPIO5 Default SCL for I2C0
56-
8 Ground
56+
8 Ground
5757
9 GPIO6 Default SDA for I2C1
5858
10 GPIO7 Default SCL for I2C1
5959
11 GPIO8 Default RX for SPI1
6060
12 GPIO9 Default CSn for SPI1
61-
13 Ground
61+
13 Ground
6262
14 GPIO10 Default SCK for SPI1
6363
15 GPIO11 Default TX for SPI1
64-
16 GPIO12
65-
17 GPIO13
66-
18 Ground
67-
19 GPIO14
68-
20 GPIO15
64+
16 GPIO12
65+
17 GPIO13
66+
18 Ground
67+
19 GPIO14
68+
20 GPIO15
6969
21 GPIO16 Default RX for SPI0
7070
22 GPIO17 Default CSn for SPI0
71-
23 Ground
71+
23 Ground
7272
24 GPIO18 Default SCK for SPI0
7373
25 GPIO19 Default TX for SPI0
7474
26 GPIO20 Default TX for UART1 serial console
7575
27 GPIO21 Default RX for UART1 serial console
76-
28 Ground
77-
29 GPIO22
78-
30 Run
76+
28 Ground
77+
29 GPIO22
78+
30 Run
7979
31 GPIO26 ADC0
8080
32 GPIO27 ADC1
8181
33 AGND Analog Ground
8282
34 GPIO28 ADC2
8383
35 ADC_VREF Analog reference voltage
8484
36 3V3 Power output to peripherals
8585
37 3V3_EN Pull to ground to turn off.
86-
38 Ground
86+
38 Ground
8787
39 VSYS +5V Supply to board
8888
40 VBUS Connected to USB +5V
8989
===== ========== ==========
@@ -217,7 +217,7 @@ LCD1602 Segment LCD Display (I2C).
217217
:widths: auto
218218
:header-rows: 1
219219

220-
* - PCF8574 BackPack
220+
* - PCF8574 BackPack
221221
- Raspberry Pi Pico
222222
* - GND
223223
- GND (Pin 3 or 38 or ...)
@@ -263,7 +263,7 @@ card support enabled.
263263

264264
* - SD card slot
265265
- Raspberry Pi Pico
266-
* - DAT2
266+
* - DAT2
267267
- Not connected
268268
* - DAT3/CS
269269
- GP17 (SPI0 CSn) (Pin 22)
@@ -277,7 +277,7 @@ card support enabled.
277277
- GND (Pin 3 or 38 or ...)
278278
* - DAT0/DO
279279
- GP16 (SPI0 RX) (Pin 21)
280-
* - DAT1
280+
* - DAT1
281281
- Not connected
282282

283283
Card hot swapping is not supported.
@@ -300,7 +300,7 @@ for SSD1306 OLED display (I2C) test configuration.
300300
- 3V3 OUT (Pin 36)
301301
* - SDA
302302
- GP4 (I2C0 SDA) (Pin 6)
303-
* - SCL
303+
* - SCL
304304
- GP5 (I2C0 SCL) (Pin 7)
305305

306306
st7735
@@ -332,6 +332,34 @@ ST7735 SPI LCD.
332332
* - RESET
333333
- GP10 (Pin 14)
334334

335+
tmp112
336+
------
337+
338+
NuttShell configuration (console enabled in USB Port, at 115200 bps) with support for Texas Instruments TMP112 sensor:
339+
340+
.. list-table:: TMP112 connections
341+
:widths: auto
342+
:header-rows: 1
343+
344+
* - TMP112
345+
- Raspberry Pi Pico
346+
* - GND
347+
- GND (Pin 3 or 38 or ...)
348+
* - VCC
349+
- 3V3 OUT (Pin 36)
350+
* - SDA
351+
- GP4 (I2C0 SDA) (Pin 6)
352+
* - SCL
353+
- GP5 (I2C0 SCL) (Pin 7)
354+
* - ADD0
355+
- GND (Pin 3 or 38 or ...)
356+
357+
.. code-block:: console
358+
359+
nsh> tmp112
360+
Sensor #1 = 27.688 degrees Celsius
361+
nsh>
362+
335363
usbmsc
336364
------
337365

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/****************************************************************************
2+
* boards/arm/rp2040/common/include/rp2040_tmp112.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_TMP112_H
24+
#define __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_TMP112_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
#include <nuttx/i2c/i2c_master.h>
32+
33+
/****************************************************************************
34+
* Pre-processor Definitions
35+
****************************************************************************/
36+
37+
/****************************************************************************
38+
* Type Definitions
39+
****************************************************************************/
40+
41+
/****************************************************************************
42+
* Public Types
43+
****************************************************************************/
44+
45+
/****************************************************************************
46+
* Public Data
47+
****************************************************************************/
48+
49+
#ifdef __cplusplus
50+
#define EXTERN extern "C"
51+
extern "C"
52+
{
53+
#else
54+
#define EXTERN extern
55+
#endif
56+
57+
/****************************************************************************
58+
* Inline Functions
59+
****************************************************************************/
60+
61+
/****************************************************************************
62+
* Public Function Prototypes
63+
****************************************************************************/
64+
65+
/****************************************************************************
66+
* Name: board_tmp112_initialize
67+
*
68+
* Description:
69+
* Initialize and register the TMP112 temperature sensor driver.
70+
*
71+
* Input Parameters:
72+
* i2c - An instance of the I2C interface to use.
73+
* devno - The device number, used to build the device path as /dev/tempN.
74+
* addr - The I2C address to use.
75+
*
76+
* Returned Value:
77+
* Zero (OK) on success; a negated errno value on failure.
78+
*
79+
****************************************************************************/
80+
81+
int board_tmp112_initialize(FAR struct i2c_master_s *i2c, int devno,
82+
uint8_t addr);
83+
84+
#undef EXTERN
85+
#ifdef __cplusplus
86+
}
87+
#endif
88+
89+
#endif /* __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_TMP112_H */

boards/arm/rp2040/common/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ ifeq ($(CONFIG_SENSORS_MAX6675),y)
109109
CSRCS += rp2040_max6675.c
110110
endif
111111

112+
ifeq ($(CONFIG_SENSORS_TMP112),y)
113+
CSRCS += rp2040_tmp112.c
114+
endif
115+
112116
DEPPATH += --dep-path src
113117
VPATH += :src
114118
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

boards/arm/rp2040/common/src/rp2040_common_bringup.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
#include "rp2040_max6675.h"
9191
#endif
9292

93+
#ifdef CONFIG_SENSORS_TMP112
94+
#include <nuttx/sensors/tmp112.h>
95+
#include "rp2040_tmp112.h"
96+
#include "rp2040_i2c.h"
97+
#endif
98+
9399
#ifdef CONFIG_RP2040_PWM
94100
#include "rp2040_pwm.h"
95101
#include "rp2040_pwmdev.h"
@@ -569,6 +575,17 @@ int rp2040_common_bringup(void)
569575
}
570576
#endif
571577

578+
#ifdef CONFIG_SENSORS_TMP112
579+
/* Try to register TMP112 device at I2C0 with a common address */
580+
581+
ret = board_tmp112_initialize(rp2040_i2cbus_initialize(0), 0,
582+
TMP112_ADDR_1);
583+
if (ret < 0)
584+
{
585+
syslog(LOG_ERR, "Failed to initialize TMP112 driver: %d\n", ret);
586+
}
587+
#endif
588+
572589
#ifdef CONFIG_VIDEO_FB
573590
ret = fb_register(0, 0);
574591
if (ret < 0)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/****************************************************************************
2+
* boards/arm/rp2040/common/src/rp2040_tmp112.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdio.h>
30+
#include <debug.h>
31+
32+
#include <nuttx/arch.h>
33+
#include <nuttx/sensors/tmp112.h>
34+
35+
#include "rp2040_i2c.h"
36+
#include "rp2040_tmp112.h"
37+
38+
/****************************************************************************
39+
* Pre-processor Definitions
40+
****************************************************************************/
41+
42+
/****************************************************************************
43+
* Private Types
44+
****************************************************************************/
45+
46+
/****************************************************************************
47+
* Private Function Prototypes
48+
****************************************************************************/
49+
50+
/****************************************************************************
51+
* Private Data
52+
****************************************************************************/
53+
54+
/****************************************************************************
55+
* Public Data
56+
****************************************************************************/
57+
58+
/****************************************************************************
59+
* Private Functions
60+
****************************************************************************/
61+
62+
/****************************************************************************
63+
* Public Functions
64+
****************************************************************************/
65+
66+
/****************************************************************************
67+
* Name: board_tmp112_initialize
68+
*
69+
* Description:
70+
* Initialize and register the TMP112 temperature sensor driver.
71+
*
72+
* Input Parameters:
73+
* i2c - An instance of the I2C interface to use.
74+
* devno - The device number, used to build the device path as /dev/tempN.
75+
* addr - The I2C address to use.
76+
*
77+
* Returned Value:
78+
* Zero (OK) on success; a negated errno value on failure.
79+
*
80+
****************************************************************************/
81+
82+
int board_tmp112_initialize(FAR struct i2c_master_s *i2c, int devno,
83+
uint8_t addr)
84+
{
85+
char devpath[11];
86+
int ret;
87+
88+
sninfo("Initializing TMP112 with address %#4x\n", addr);
89+
90+
if (i2c)
91+
{
92+
snprintf(devpath, sizeof(devpath), "/dev/temp%d", devno);
93+
ret = tmp112_register(devpath, i2c, addr);
94+
if (ret < 0)
95+
{
96+
snerr("ERROR: Error registering TMP112 at /dev/temp%d\n", devno);
97+
}
98+
}
99+
else
100+
{
101+
ret = -ENODEV;
102+
}
103+
104+
return ret;
105+
}

0 commit comments

Comments
 (0)