-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfxps7550_analog.c
More file actions
99 lines (75 loc) · 2.54 KB
/
Copy pathfxps7550_analog.c
File metadata and controls
99 lines (75 loc) · 2.54 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
/**
******************************************************************************
* @file fxps7550_analog.c
* @author Sensors Software Solution Team
* @brief FXPS7550 driver file
******************************************************************************
* @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.
*
******************************************************************************
*/
//-----------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------
#include <fxps7550_analog.h>
#include "string.h"
//-----------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------
const char sensor_pn[] = "FXPS7550A4S";
//-----------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------
int32_t fxps7550_read_reg(stmdev_ctx_t *ctx, uint8_t reg,
uint8_t *data, uint16_t len)
{
int32_t ret = FXPS7550_SUCCESS;
if (ctx == NULL || ctx->read_reg == NULL)
{
return FXPS7550_INVALIDPARAM_ERR;
}
ret = ctx->read_reg(ctx->handle, reg, data, len);
return ret;
}
int32_t fxps7550_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
const uint8_t *data, uint16_t len)
{
int32_t ret = FXPS7550_ERROR_READ_ONLY;
return ret;
}
void fxps7550_device_id_get(stmdev_ctx_t *ctx, char *str)
{
strcpy(str, sensor_pn);
}
int32_t fxps7550_pressure_raw_get(stmdev_ctx_t *ctx, uint16_t *pPressure)
{
int32_t ret = FXPS7550_SUCCESS;
int16_t raw_pressure = 0;
uint8_t buff[2] = {0}; //FXPS7550_DATA_SIZE
if (pPressure == NULL)
{
return FXPS7550_INVALIDPARAM_ERR;
}
ret = fxps7550_read_reg(ctx, 0, buff, 2);
raw_pressure = ((int16_t)((buff[1]<< 8) & 0xFF00) | buff[0]);
*pPressure = raw_pressure;
return ret;
}
float fxps7550_pressure_raw_to_kpa(uint32_t pressure_raw)
{
float pressure;
/* The transfer function of the analog pressure sensor does not require
* compensation.
*
* Refer to DataSheet for transfer function
*/
pressure = FXPS7550_OFFSET + FXPS7550_SENS * ((float)pressure_raw / ADC_MAX_12BIT);
return pressure;
}