1 /*
2  * Copyright (c) 2020 Sven Herrmann
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_
8 #define ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_
9 
10 /*
11  * Pressure Range
12  *
13  * MIN is always 0
14  */
15 #define MPR_P_MIN (0)
16 
17 #if defined(CONFIG_MPR_PRESSURE_RANGE_0001)
18 #define MPR_P_MAX (1)
19 
20 #elif defined(CONFIG_MPR_PRESSURE_RANGE_01_6)
21 #define MPR_P_MAX (1.6)
22 
23 #elif defined(CONFIG_MPR_PRESSURE_RANGE_02_5)
24 #define MPR_P_MAX (2.5)
25 
26 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0015)
27 #define MPR_P_MAX (15)
28 
29 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0025)
30 #define MPR_P_MAX (25)
31 
32 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0030)
33 #define MPR_P_MAX (30)
34 
35 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0060)
36 #define MPR_P_MAX (60)
37 
38 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0100)
39 #define MPR_P_MAX (100)
40 
41 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0160)
42 #define MPR_P_MAX (160)
43 
44 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0250)
45 #define MPR_P_MAX (250)
46 
47 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0400)
48 #define MPR_P_MAX (400)
49 
50 #elif defined(CONFIG_MPR_PRESSURE_RANGE_0600)
51 #define MPR_P_MAX (600)
52 
53 #else
54 #error "MPR: Unknown pressure range."
55 #endif
56 
57 /*
58  * Pressure Unit
59  */
60 #if defined(CONFIG_MPR_PRESSURE_UNIT_P)
61 /* psi to kPa conversion factor: 6.894757 * 10^6 */
62 #define MPR_CONVERSION_FACTOR (6894757)
63 
64 #elif defined(CONFIG_MPR_PRESSURE_UNIT_K)
65 /* kPa to kPa conversion factor: 1 * 10^6 */
66 #define MPR_CONVERSION_FACTOR (1000000)
67 
68 #elif defined(CONFIG_MPR_PRESSURE_UNIT_B)
69 /* bar to kPa conversion factor: 100 * 10^6 */
70 #define MPR_CONVERSION_FACTOR (100000000)
71 
72 #elif defined(CONFIG_MPR_PRESSURE_UNIT_M)
73 /* mbar to kPa conversion factor: 0.1 * 10^6 */
74 #define MPR_CONVERSION_FACTOR (100000)
75 
76 #else
77 #error "MPR: Unknown pressure unit."
78 #endif
79 
80 /*
81  * Transfer function
82  */
83 #if defined(CONFIG_MPR_TRANSFER_FUNCTION_A)
84 #define MPR_OUTPUT_MIN (0x19999A) /* 10% of 2^24 */
85 #define MPR_OUTPUT_MAX (0xE66666) /* 90% of 2^24 */
86 #elif defined(CONFIG_MPR_TRANSFER_FUNCTION_B)
87 #define MPR_OUTPUT_MIN (0x66666) /* 2.5% of 2^24 */
88 #define MPR_OUTPUT_MAX (0x399999) /* 22.5% of 2^24 */
89 #elif defined(CONFIG_MPR_TRANSFER_FUNCTION_C)
90 #define MPR_OUTPUT_MIN (0x333333) /* 20% of 2^24 */
91 #define MPR_OUTPUT_MAX (0xCCCCCC) /* 80% of 2^24 */
92 #else
93 #error "MPR: Unknown pressure reference."
94 #endif
95 
96 #define MPR_OUTPUT_RANGE (MPR_OUTPUT_MAX - MPR_OUTPUT_MIN)
97 
98 #endif /* ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_ */
99