Skip to content

Commit fb84d3f

Browse files
gmarullcarlescufi
authored andcommitted
drivers: sensor: s/examplesensor/example-|_sensor/
Just a rename so things look a bit nicer. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent a9e3bcb commit fb84d3f

File tree

10 files changed

+99
-99
lines changed

10 files changed

+99
-99
lines changed

app/boards/nucleo_f302r8.overlay

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111

1212
/ {
13-
examplesensor0: examplesensor_0 {
14-
compatible = "zephyr,examplesensor";
13+
example_sensor: example-sensor {
14+
compatible = "zephyr,example-sensor";
1515
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
1616
};
1717
};

app/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(void)
1717

1818
printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
1919

20-
sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0));
20+
sensor = DEVICE_DT_GET(DT_NODELABEL(example_sensor));
2121
if (!device_is_ready(sensor)) {
2222
LOG_ERR("Sensor not ready");
2323
return 0;

boards/vendor/custom_plank/custom_plank.dts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
zephyr,flash = &flash0;
1818
};
1919

20-
examplesensor0: examplesensor_0 {
21-
compatible = "zephyr,examplesensor";
20+
example_sensor: example-sensor {
21+
compatible = "zephyr,example-sensor";
2222
input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
2323
};
2424
};

drivers/sensor/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) 2021 Nordic Semiconductor ASA
22
# SPDX-License-Identifier: Apache-2.0
33

4-
add_subdirectory_ifdef(CONFIG_EXAMPLESENSOR examplesensor)
4+
add_subdirectory_ifdef(CONFIG_EXAMPLE_SENSOR example_sensor)

drivers/sensor/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if SENSOR
5-
rsource "examplesensor/Kconfig"
5+
rsource "example_sensor/Kconfig"
66
endif # SENSOR

drivers/sensor/examplesensor/CMakeLists.txt renamed to drivers/sensor/example_sensor/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
zephyr_library()
5-
zephyr_library_sources(examplesensor.c)
5+
zephyr_library_sources(example_sensor.c)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright (c) 2021 Nordic Semiconductor ASA
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config EXAMPLESENSOR
4+
config EXAMPLE_SENSOR
55
bool "Example sensor"
66
default y
7-
depends on DT_HAS_ZEPHYR_EXAMPLESENSOR_ENABLED
7+
depends on DT_HAS_ZEPHYR_EXAMPLE_SENSOR_ENABLED
88
select GPIO
99
help
1010
Enable example sensor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#define DT_DRV_COMPAT zephyr_example_sensor
7+
8+
#include <zephyr/device.h>
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/drivers/sensor.h>
11+
12+
#include <zephyr/logging/log.h>
13+
LOG_MODULE_REGISTER(example_sensor, CONFIG_SENSOR_LOG_LEVEL);
14+
15+
struct example_sensor_data {
16+
int state;
17+
};
18+
19+
struct example_sensor_config {
20+
struct gpio_dt_spec input;
21+
};
22+
23+
static int example_sensor_sample_fetch(const struct device *dev,
24+
enum sensor_channel chan)
25+
{
26+
const struct example_sensor_config *config = dev->config;
27+
struct example_sensor_data *data = dev->data;
28+
29+
data->state = gpio_pin_get_dt(&config->input);
30+
31+
return 0;
32+
}
33+
34+
static int example_sensor_channel_get(const struct device *dev,
35+
enum sensor_channel chan,
36+
struct sensor_value *val)
37+
{
38+
struct example_sensor_data *data = dev->data;
39+
40+
if (chan != SENSOR_CHAN_PROX) {
41+
return -ENOTSUP;
42+
}
43+
44+
val->val1 = data->state;
45+
46+
return 0;
47+
}
48+
49+
static const struct sensor_driver_api example_sensor_api = {
50+
.sample_fetch = &example_sensor_sample_fetch,
51+
.channel_get = &example_sensor_channel_get,
52+
};
53+
54+
static int example_sensor_init(const struct device *dev)
55+
{
56+
const struct example_sensor_config *config = dev->config;
57+
58+
int ret;
59+
60+
if (!device_is_ready(config->input.port)) {
61+
LOG_ERR("Input GPIO not ready");
62+
return -ENODEV;
63+
}
64+
65+
ret = gpio_pin_configure_dt(&config->input, GPIO_INPUT);
66+
if (ret < 0) {
67+
LOG_ERR("Could not configure input GPIO (%d)", ret);
68+
return ret;
69+
}
70+
71+
return 0;
72+
}
73+
74+
#define EXAMPLE_SENSOR_INIT(i) \
75+
static struct example_sensor_data example_sensor_data_##i; \
76+
\
77+
static const struct example_sensor_config example_sensor_config_##i = {\
78+
.input = GPIO_DT_SPEC_INST_GET(i, input_gpios), \
79+
}; \
80+
\
81+
DEVICE_DT_INST_DEFINE(i, example_sensor_init, NULL, \
82+
&example_sensor_data_##i, \
83+
&example_sensor_config_##i, POST_KERNEL, \
84+
CONFIG_SENSOR_INIT_PRIORITY, &example_sensor_api);
85+
86+
DT_INST_FOREACH_STATUS_OKAY(EXAMPLE_SENSOR_INIT)

drivers/sensor/examplesensor/examplesensor.c

-86
This file was deleted.

dts/bindings/sensor/zephyr,examplesensor.yaml renamed to dts/bindings/sensor/zephyr,example-sensor.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ description: |
77
88
Example definition in devicetree:
99
10-
examplesensor {
11-
compatible = "zephyr,examplesensor";
10+
example-sensor {
11+
compatible = "zephyr,example-sensor";
1212
input-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
1313
};
1414
15-
compatible: "zephyr,examplesensor"
15+
compatible: "zephyr,example-sensor"
1616

1717
include: base.yaml
1818

0 commit comments

Comments
 (0)