-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfxps7550_analog.h
More file actions
229 lines (191 loc) · 6.61 KB
/
Copy pathfxps7550_analog.h
File metadata and controls
229 lines (191 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
******************************************************************************
* @file fxps7550_analog.h
* @author Sensors Software Solution Team
* @brief This file contains all the functions prototypes for the
* fxps7550_analog.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef FXPS7550_ANALOG_H
#define FXPS7550_ANALOG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stddef.h>
#include <math.h>
#include <stdbool.h>
typedef int32_t (*stmdev_write_ptr)(void *, uint8_t, const uint8_t *, uint16_t);
typedef int32_t (*stmdev_read_ptr)(void *, uint8_t, uint8_t *, uint16_t);
typedef void (*stmdev_mdelay_ptr)(uint32_t millisec);
/* STdC-style context */
typedef struct
{
/** Component mandatory fields **/
stmdev_write_ptr write_reg;
stmdev_read_ptr read_reg;
/** Component optional fields **/
stmdev_mdelay_ptr mdelay;
/** Customizable optional pointer **/
void *handle;
/** private data **/
void *priv_data;
} stmdev_ctx_t;
typedef struct
{
/* per driver instance private data */
} fxps7550_priv_t;
#define FXPS7550_SETB 1 /* Set Bit */
#define FXPS7550_RSTB 0 /* Reset Bit */
//ADC values
#define VALUE_8BIT (1 << 8)
#define VALUE_10BIT (1 << 10)
#define VALUE_12BIT (1 << 12)
#define VALUE_16BIT (1 << 16)
#define ADC_MAX_8BIT (VALUE_8BIT - 1)
#define ADC_MAX_10BIT (VALUE_10BIT - 1)
#define ADC_MAX_12BIT (VALUE_12BIT - 1)
#define ADC_MAX_16BIT (VALUE_16BIT - 1)
/* Voltage divider factor is the computation between the
* Sensor supply voltage and the desire output.
* In this case:
* 3.3VDC / 5VDC = 0.66
*/
#define ADC_REF_VOLTAGE 3.3f
#define FXPS7550_SUPPLY_VOLTAGE 5.0f
#define VDIV_FACTOR ADC_REF_VOLTAGE / FXPS7550A4S_SUPPLY_VOLTAGE
//FXPS7550A4S Sensor
#define FXPS7550_OFFSET 10.0f
#define FXPS7550_SENS 250.0f
//-----------------------------------------------------------------------
// Typedefs and macros
//-----------------------------------------------------------------------
/*!
* @brief fxps7550 error_code
*/
typedef enum fxps7550_error_code
{
FXPS7550_SUCCESS = 0, /*!< Success value returned by sensor APIs. */
FXPS7550_ERROR = 1, /*!< Device error, Wrong data.*/
FXPS7550_INVALIDPARAM_ERR = 2, /*!< Invalid Param Error value by SENSOR APIs. */
FXPS7550_INIT_ERR = 3, /*!< SENSOR Init Error value returned by Init API. */
FXPS7550_READ_ERR = 4, /*!< SENSOR Read Error value returned by Read API. */
FXPS7550_ERROR_READ_ONLY = 5, /*!< SENSOR error, device is analog output (read only). */
} fxps7550_error_code_t;
extern float CZPO; /* Sample Current Zero Offset */
/*
* These are the basic platform dependent I/O routines to read
* and write device registers connected on a standard bus.
* The driver keeps offering a default implementation based on function
* pointers to read/write routines for backward compatibility.
*/
/**
* @defgroup FXPS7550X_Interfaces_Functions
* @brief This section provide a set of functions used to read and
* write a generic register of the device.
* MANDATORY: return 0 -> no Error.
* @{
*
*/
/**
* @brief Read generic device register
*
* @param ctx communication interface handler.(ptr)
* @param reg first register address to read.
* @param data buffer for data read.(ptr)
* @param len number of consecutive register to read.
* @retval interface status (MANDATORY: return 0 -> no Error)
*
*/
int32_t fxps7550_read_reg(stmdev_ctx_t *ctx, uint8_t reg,
uint8_t *data, uint16_t len);
/**
* @brief Write generic device register
*
* @param ctx communication interface handler.(ptr)
* @param reg first register address to write.
* @param data the buffer contains data to be written.(ptr)
* @param len number of consecutive register to write.
* @retval interface status (MANDATORY: return 0 -> no Error)
*
*/
int32_t fxps7550_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
const uint8_t *data, uint16_t len);
/**
* @}
*
*/
/**
* @defgroup FXPS7550X_Common
* @brief This section groups common useful functions.
* @{
*
*/
/**
* @brief Get device identification string (part number).
* The sensor part number is defined as a constant string:
* const char sensor_pn[] = "MPxx5004";
* @param ctx Pointer to device context (unused).
* @param str Pointer to the destination buffer where the string
* will be copied.
* @retval None
*/
void fxps7550_device_id_get(stmdev_ctx_t *ctx, char *str);
/**
* @}
*
*/
/**
* @defgroup FXPS7550A_Output_Data
* @brief This section groups all the data output functions
* @{
*
*/
/**
* @brief Get raw pressure data from ADC conversion.
* The FXPS7550A4S sensor provides an analog output only.
* This function returns the raw ADC conversion value,
* which corresponds to the sensor output voltage.
* No scaling or pressure conversion is applied.
* @param ctx Pointer to device context (ADC/IO interface handler).
* @param pPressure Pointer to variable where the raw ADC value will be stored.
* @retval Status of the operation.
*/
int32_t fxps7550_pressure_raw_get(stmdev_ctx_t *ctx, uint16_t *pPressure);
/**
* @}
*
*/
/**
* @defgroup FXPS7550A_Sensitivity
* @brief These functions convert raw-data into engineering units.
* @{
*
*/
/**
* @brief Convert FXPS7550A4S raw pressure reading to kPa
* This function converts a raw pressure value into kPa units.
* The raw pressure is derived from ADC conversion (in LSB / voltage).
* Optionally applies auto-zero compensation when enabled.
* @param pressure_raw Raw pressure value from ADC (LSB)
*
* @retval Returns compensated pressure value in kPa
*/
float fxps7550_pressure_raw_to_kpa(uint32_t pressure_raw);
/**
* @}
*
*/
#endif /* FXPS7550_ANALOG_H */