1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <zephyr/device.h>
7 #include <zephyr/drivers/sensor.h>
8 #include <zephyr/kernel.h>
9 
10 /* Mock of internal temperature sensor. */
11 #ifdef CONFIG_TEMP_NRF5
12 #error "Cannot be enabled because it is being mocked"
13 #endif
14 
15 static struct sensor_value value;
16 
mock_temp_nrf5_value_set(struct sensor_value * val)17 void mock_temp_nrf5_value_set(struct sensor_value *val)
18 {
19 	value = *val;
20 }
21 
mock_temp_nrf5_sample_fetch(const struct device * dev,enum sensor_channel chan)22 static int mock_temp_nrf5_sample_fetch(const struct device *dev,
23 					enum sensor_channel chan)
24 {
25 	k_sleep(K_MSEC(1));
26 	return 0;
27 }
28 
mock_temp_nrf5_channel_get(const struct device * dev,enum sensor_channel chan,struct sensor_value * val)29 static int mock_temp_nrf5_channel_get(const struct device *dev,
30 				      enum sensor_channel chan,
31 				      struct sensor_value *val)
32 {
33 	*val = value;
34 	return 0;
35 }
36 
37 static DEVICE_API(sensor, mock_temp_nrf5_driver_api) = {
38 	.sample_fetch = mock_temp_nrf5_sample_fetch,
39 	.channel_get = mock_temp_nrf5_channel_get,
40 };
41 
42 DEVICE_DT_DEFINE(DT_INST(0, nordic_nrf_temp),
43 		    NULL,
44 		    NULL,
45 		    NULL,
46 		    NULL,
47 		    POST_KERNEL,
48 		    CONFIG_SENSOR_INIT_PRIORITY,
49 		    &mock_temp_nrf5_driver_api);
50