Skip to content

Commit 0970aa2

Browse files
Jeppe Odgaardkartben
authored andcommitted
drivers: sensor: ti: tmp11x: clang-format files and change DEFINE_TMP11X
Run clang-format on tmp11x.c and tmp11x.h and change `DEFINE_TMP11X` to prevent too long lines when clang-format is run. Signed-off-by: Jeppe Odgaard <[email protected]>
1 parent 0d01361 commit 0970aa2

File tree

2 files changed

+63
-71
lines changed

2 files changed

+63
-71
lines changed

drivers/sensor/ti/tmp11x/tmp11x.c

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@
2020

2121
#include "tmp11x.h"
2222

23-
#define EEPROM_SIZE_REG sizeof(uint16_t)
24-
#define EEPROM_TMP117_RESERVED (2 * sizeof(uint16_t))
25-
#define EEPROM_MIN_BUSY_MS 7
26-
#define RESET_MIN_BUSY_MS 2
23+
#define EEPROM_SIZE_REG sizeof(uint16_t)
24+
#define EEPROM_TMP117_RESERVED (2 * sizeof(uint16_t))
25+
#define EEPROM_MIN_BUSY_MS 7
26+
#define RESET_MIN_BUSY_MS 2
2727

2828
LOG_MODULE_REGISTER(TMP11X, CONFIG_SENSOR_LOG_LEVEL);
2929

3030
int tmp11x_reg_read(const struct device *dev, uint8_t reg, uint16_t *val)
3131
{
3232
const struct tmp11x_dev_config *cfg = dev->config;
3333

34-
if (i2c_burst_read_dt(&cfg->bus, reg, (uint8_t *)val, 2)
35-
< 0) {
34+
if (i2c_burst_read_dt(&cfg->bus, reg, (uint8_t *)val, 2) < 0) {
3635
return -EIO;
3736
}
3837

@@ -96,13 +95,11 @@ static inline int16_t tmp11x_sensor_value_to_reg_format(const struct sensor_valu
9695
}
9796
}
9897

99-
static bool check_eeprom_bounds(const struct device *dev, off_t offset,
100-
size_t len)
98+
static bool check_eeprom_bounds(const struct device *dev, off_t offset, size_t len)
10199
{
102100
struct tmp11x_data *drv_data = dev->data;
103101

104-
if ((offset + len) > EEPROM_TMP11X_SIZE ||
105-
offset % EEPROM_SIZE_REG != 0 ||
102+
if ((offset + len) > EEPROM_TMP11X_SIZE || offset % EEPROM_SIZE_REG != 0 ||
106103
len % EEPROM_SIZE_REG != 0) {
107104
return false;
108105
}
@@ -130,8 +127,7 @@ int tmp11x_eeprom_await(const struct device *dev)
130127
return res;
131128
}
132129

133-
int tmp11x_eeprom_write(const struct device *dev, off_t offset,
134-
const void *data, size_t len)
130+
int tmp11x_eeprom_write(const struct device *dev, off_t offset, const void *data, size_t len)
135131
{
136132
uint8_t reg;
137133
const uint16_t *src = data;
@@ -167,8 +163,7 @@ int tmp11x_eeprom_write(const struct device *dev, off_t offset,
167163
return res;
168164
}
169165

170-
int tmp11x_eeprom_read(const struct device *dev, off_t offset, void *data,
171-
size_t len)
166+
int tmp11x_eeprom_read(const struct device *dev, off_t offset, void *data, size_t len)
172167
{
173168
uint8_t reg;
174169
uint16_t *dst = data;
@@ -189,7 +184,6 @@ int tmp11x_eeprom_read(const struct device *dev, off_t offset, void *data,
189184
return res;
190185
}
191186

192-
193187
/**
194188
* @brief Check the Device ID
195189
*
@@ -202,39 +196,34 @@ int tmp11x_eeprom_read(const struct device *dev, off_t offset, void *data,
202196
static inline int tmp11x_device_id_check(const struct device *dev, uint16_t *id)
203197
{
204198
if (tmp11x_reg_read(dev, TMP11X_REG_DEVICE_ID, id) != 0) {
205-
LOG_ERR("%s: Failed to get Device ID register!",
206-
dev->name);
199+
LOG_ERR("%s: Failed to get Device ID register!", dev->name);
207200
return -EIO;
208201
}
209202

210203
if ((*id != TMP116_DEVICE_ID) && (*id != TMP117_DEVICE_ID) && (*id != TMP119_DEVICE_ID)) {
211-
LOG_ERR("%s: Failed to match the device IDs!",
212-
dev->name);
204+
LOG_ERR("%s: Failed to match the device IDs!", dev->name);
213205
return -EINVAL;
214206
}
215207

216208
return 0;
217209
}
218210

219-
static int tmp11x_sample_fetch(const struct device *dev,
220-
enum sensor_channel chan)
211+
static int tmp11x_sample_fetch(const struct device *dev, enum sensor_channel chan)
221212
{
222213
struct tmp11x_data *drv_data = dev->data;
223214
uint16_t value;
224215
uint16_t cfg_reg = 0;
225216
int rc;
226217

227-
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL ||
228-
chan == SENSOR_CHAN_AMBIENT_TEMP);
218+
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP);
229219

230220
/* clear sensor values */
231221
drv_data->sample = 0U;
232222

233223
/* Make sure that a data is available */
234224
rc = tmp11x_reg_read(dev, TMP11X_REG_CFGR, &cfg_reg);
235225
if (rc < 0) {
236-
LOG_ERR("%s, Failed to read from CFGR register",
237-
dev->name);
226+
LOG_ERR("%s, Failed to read from CFGR register", dev->name);
238227
return rc;
239228
}
240229

@@ -246,8 +235,7 @@ static int tmp11x_sample_fetch(const struct device *dev,
246235
/* Get the most recent temperature measurement */
247236
rc = tmp11x_reg_read(dev, TMP11X_REG_TEMP, &value);
248237
if (rc < 0) {
249-
LOG_ERR("%s: Failed to read from TEMP register!",
250-
dev->name);
238+
LOG_ERR("%s: Failed to read from TEMP register!", dev->name);
251239
return rc;
252240
}
253241

@@ -270,8 +258,7 @@ static void tmp11x_temperature_to_sensor_value(int16_t temperature, struct senso
270258
val->val2 = tmp % 1000000;
271259
}
272260

273-
static int tmp11x_channel_get(const struct device *dev,
274-
enum sensor_channel chan,
261+
static int tmp11x_channel_get(const struct device *dev, enum sensor_channel chan,
275262
struct sensor_value *val)
276263
{
277264
struct tmp11x_data *drv_data = dev->data;
@@ -314,7 +301,7 @@ static int16_t tmp11x_conv_value(const struct sensor_value *val)
314301

315302
static bool tmp11x_is_attr_store_supported(enum sensor_attribute attr)
316303
{
317-
switch ((int) attr) {
304+
switch ((int)attr) {
318305
case SENSOR_ATTR_SAMPLING_FREQUENCY:
319306
case SENSOR_ATTR_LOWER_THRESH:
320307
case SENSOR_ATTR_UPPER_THRESH:
@@ -342,10 +329,8 @@ static int tmp11x_attr_store_reload(const struct device *dev)
342329
return await_res != 0 ? await_res : reset_res;
343330
}
344331

345-
static int tmp11x_attr_set(const struct device *dev,
346-
enum sensor_channel chan,
347-
enum sensor_attribute attr,
348-
const struct sensor_value *val)
332+
static int tmp11x_attr_set(const struct device *dev, enum sensor_channel chan,
333+
enum sensor_attribute attr, const struct sensor_value *val)
349334
{
350335
const struct tmp11x_dev_config *cfg = dev->config;
351336
struct tmp11x_data *drv_data = dev->data;
@@ -435,7 +420,7 @@ static int tmp11x_attr_set(const struct device *dev,
435420
case SENSOR_ATTR_TMP11X_ALERT_PIN_POLARITY:
436421
if (val->val1 == TMP11X_ALERT_PIN_ACTIVE_HIGH) {
437422
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_PIN_POL,
438-
TMP11X_CFGR_ALERT_PIN_POL);
423+
TMP11X_CFGR_ALERT_PIN_POL);
439424
} else {
440425
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_PIN_POL, 0);
441426
}
@@ -444,7 +429,7 @@ static int tmp11x_attr_set(const struct device *dev,
444429
case SENSOR_ATTR_TMP11X_ALERT_MODE:
445430
if (val->val1 == TMP11X_ALERT_THERM_MODE) {
446431
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_MODE,
447-
TMP11X_CFGR_ALERT_MODE);
432+
TMP11X_CFGR_ALERT_MODE);
448433
} else {
449434
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_MODE, 0);
450435
}
@@ -467,7 +452,7 @@ static int tmp11x_attr_set(const struct device *dev,
467452
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_DR_SEL, 0);
468453
} else {
469454
res = tmp11x_write_config(dev, TMP11X_CFGR_ALERT_DR_SEL,
470-
TMP11X_CFGR_ALERT_DR_SEL);
455+
TMP11X_CFGR_ALERT_DR_SEL);
471456
}
472457
break;
473458
#endif /* CONFIG_TMP11X_TRIGGER */
@@ -643,20 +628,27 @@ static int tmp11x_pm_control(const struct device *dev, enum pm_device_action act
643628
}
644629
#endif /* CONFIG_PM_DEVICE */
645630

646-
#define DEFINE_TMP11X(_num) \
647-
static struct tmp11x_data tmp11x_data_##_num; \
648-
static const struct tmp11x_dev_config tmp11x_config_##_num = { \
631+
#ifdef CONFIG_TMP11X_TRIGGER
632+
#define DEFINE_TMP11X_TRIGGER(_num) .alert_gpio = GPIO_DT_SPEC_INST_GET_OR(_num, alert_gpios, {}),
633+
#else
634+
#define DEFINE_TMP11X_TRIGGER(_num)
635+
#endif
636+
637+
#define DEFINE_TMP11X(_num) \
638+
static struct tmp11x_data tmp11x_data_##_num; \
639+
static const struct tmp11x_dev_config tmp11x_config_##_num = { \
649640
.bus = I2C_DT_SPEC_INST_GET(_num), \
650641
.odr = DT_INST_PROP(_num, odr), \
651642
.oversampling = DT_INST_PROP(_num, oversampling), \
652643
.alert_pin_polarity = DT_INST_PROP(_num, alert_polarity), \
653644
.alert_mode = DT_INST_PROP(_num, alert_mode), \
654645
.alert_dr_sel = DT_INST_PROP(_num, alert_dr_sel), \
655646
.store_attr_values = DT_INST_PROP(_num, store_attr_values), \
656-
IF_ENABLED(CONFIG_TMP11X_TRIGGER, \
657-
(.alert_gpio = GPIO_DT_SPEC_INST_GET_OR(_num, alert_gpios, {}),)) }; \
658-
PM_DEVICE_DT_INST_DEFINE(_num, tmp11x_pm_control); \
659-
SENSOR_DEVICE_DT_INST_DEFINE(_num, tmp11x_init, PM_DEVICE_DT_INST_GET(_num), \
647+
DEFINE_TMP11X_TRIGGER(_num)}; \
648+
\
649+
PM_DEVICE_DT_INST_DEFINE(_num, tmp11x_pm_control); \
650+
\
651+
SENSOR_DEVICE_DT_INST_DEFINE(_num, tmp11x_init, PM_DEVICE_DT_INST_GET(_num), \
660652
&tmp11x_data_##_num, &tmp11x_config_##_num, POST_KERNEL, \
661653
CONFIG_SENSOR_INIT_PRIORITY, &tmp11x_driver_api);
662654

drivers/sensor/ti/tmp11x/tmp11x.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111
#include <zephyr/drivers/gpio.h>
1212
#include <zephyr/drivers/i2c.h>
1313

14-
#define TMP11X_REG_TEMP 0x0
15-
#define TMP11X_REG_CFGR 0x1
16-
#define TMP11X_REG_HIGH_LIM 0x2
17-
#define TMP11X_REG_LOW_LIM 0x3
18-
#define TMP11X_REG_EEPROM_UL 0x4
19-
#define TMP11X_REG_EEPROM1 0x5
20-
#define TMP11X_REG_EEPROM2 0x6
21-
#define TMP11X_REG_EEPROM3 0x7
22-
#define TMP117_REG_TEMP_OFFSET 0x7
23-
#define TMP11X_REG_EEPROM4 0x8
24-
#define TMP11X_REG_DEVICE_ID 0xF
14+
#define TMP11X_REG_TEMP 0x0
15+
#define TMP11X_REG_CFGR 0x1
16+
#define TMP11X_REG_HIGH_LIM 0x2
17+
#define TMP11X_REG_LOW_LIM 0x3
18+
#define TMP11X_REG_EEPROM_UL 0x4
19+
#define TMP11X_REG_EEPROM1 0x5
20+
#define TMP11X_REG_EEPROM2 0x6
21+
#define TMP11X_REG_EEPROM3 0x7
22+
#define TMP117_REG_TEMP_OFFSET 0x7
23+
#define TMP11X_REG_EEPROM4 0x8
24+
#define TMP11X_REG_DEVICE_ID 0xF
2525

26-
#define TMP11X_RESOLUTION 78125 /* in tens of uCelsius*/
27-
#define TMP11X_RESOLUTION_DIV 10000000
26+
#define TMP11X_RESOLUTION 78125 /* in tens of uCelsius*/
27+
#define TMP11X_RESOLUTION_DIV 10000000
2828

29-
#define TMP116_DEVICE_ID 0x1116
30-
#define TMP117_DEVICE_ID 0x0117
31-
#define TMP119_DEVICE_ID 0x2117
29+
#define TMP116_DEVICE_ID 0x1116
30+
#define TMP117_DEVICE_ID 0x0117
31+
#define TMP119_DEVICE_ID 0x2117
3232

33-
#define TMP11X_CFGR_RESET BIT(1)
34-
#define TMP11X_CFGR_AVG (BIT(5) | BIT(6))
35-
#define TMP11X_CFGR_CONV (BIT(7) | BIT(8) | BIT(9))
36-
#define TMP11X_CFGR_MODE (BIT(10) | BIT(11))
33+
#define TMP11X_CFGR_RESET BIT(1)
34+
#define TMP11X_CFGR_AVG (BIT(5) | BIT(6))
35+
#define TMP11X_CFGR_CONV (BIT(7) | BIT(8) | BIT(9))
36+
#define TMP11X_CFGR_MODE (BIT(10) | BIT(11))
3737
#define TMP11X_CFGR_DATA_READY BIT(13)
3838
#define TMP11X_EEPROM_UL_UNLOCK BIT(15)
3939
#define TMP11X_EEPROM_UL_BUSY BIT(14)
@@ -43,13 +43,13 @@
4343
#define TMP11X_CFGR_ALERT_PIN_POL BIT(3) /* Alert pin polarity */
4444
#define TMP11X_CFGR_ALERT_MODE BIT(4) /* Alert pin mode (1=therm, 0=alert) */
4545

46-
#define TMP11X_AVG_1_SAMPLE 0
47-
#define TMP11X_AVG_8_SAMPLES BIT(5)
48-
#define TMP11X_AVG_32_SAMPLES BIT(6)
49-
#define TMP11X_AVG_64_SAMPLES (BIT(5) | BIT(6))
50-
#define TMP11X_MODE_CONTINUOUS 0
51-
#define TMP11X_MODE_SHUTDOWN BIT(10)
52-
#define TMP11X_MODE_ONE_SHOT (BIT(10) | BIT(11))
46+
#define TMP11X_AVG_1_SAMPLE 0
47+
#define TMP11X_AVG_8_SAMPLES BIT(5)
48+
#define TMP11X_AVG_32_SAMPLES BIT(6)
49+
#define TMP11X_AVG_64_SAMPLES (BIT(5) | BIT(6))
50+
#define TMP11X_MODE_CONTINUOUS 0
51+
#define TMP11X_MODE_SHUTDOWN BIT(10)
52+
#define TMP11X_MODE_ONE_SHOT (BIT(10) | BIT(11))
5353

5454
struct tmp11x_data {
5555
uint16_t sample;

0 commit comments

Comments
 (0)