-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMCP9808_ex.h
174 lines (146 loc) · 6.4 KB
/
MCP9808_ex.h
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
/*!\file MCP9808_ex.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief MCP9808 Driver extensions
** \details MCP9808: +/-0.5C Maximum Accuracy Digital Temperature Sensor
**/
/****************************************************************/
#ifndef __MCP9808_EX_H__
#define __MCP9808_EX_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "MCP9808.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\union uMCP9808_REG_MAP
** \brief Union of MCP9808 registry map
**/
typedef union uMCP9808_REG_MAP {
uint16_t Words[9];
struct PACK__ {
uint16_t RFU; //!< RFU, Reserved for Future Use (Read-Only register)
uMCP9808_REG__CFG CONFIG; //!< Configuration register (CONFIG)
uMCP9808_REG__TEMP_LIM TUpper; //!< Alert Temperature Upper Boundary Trip register (T_upper)
uMCP9808_REG__TEMP_LIM TLower; //!< Alert Temperature Lower Boundary Trip register (T_lower)
uMCP9808_REG__TEMP_LIM TCrit; //!< Critical Temperature Trip register (T_crit)
uMCP9808_REG__TEMP_AMB TA; //!< Temperature register (T_A)
uint16_t ManufacturerID; //!< Manufacturer ID register
uint16_t DeviceID; //!< Device ID/Revision register
uint16_t Resolution; //!< Resolution register (is a 8b register in reality)
} Reg;
} uMCP9808_REG_MAP;
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/****************************************/
/*** High level methods and functions ***/
/****************************************/
/*!\brief Write MCP9808 configuration
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] cfg - Configuration value
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Write_Config(MCP9808_t * const pCpnt, const uint16_t cfg);
/*!\brief Write MCP9808 configuration
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] shutdown - 0 Normal operation, 1 Shutdown
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Shutdown(MCP9808_t * const pCpnt, const bool shutdown);
/*!\brief Set MCP9808 alert hysteresis
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] hys - Alert hysteresis
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Set_AlertHysteresis(MCP9808_t * const pCpnt, const MCP9808_hyst hys);
/*!\brief Set MCP9808 alert type
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] comparator - 0 ???, 1 Comparator
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Set_AlertType(MCP9808_t * const pCpnt, const bool comparator);
/*!\brief Set MCP9808 alert enable
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] en - 0 Disabled, 1 Enabled
** \param[in] alt - 0 Low, 1 High
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Set_AlertOutput(MCP9808_t * const pCpnt, const bool en, const bool alt);
/*!\brief Set MCP9808 alert lock
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] alt - Alert type
** \param[in] lock - 0 Unlocked, 1 Locked
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Set_AlertLock(MCP9808_t * const pCpnt, const MCP9808_alert alt, const bool lock);
/*!\brief Set MCP9808 Resolution
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] res - Resolution for MCP9808
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Set_Resolution(MCP9808_t * const pCpnt, const MCP9808_res res);
/*!\brief Get MCP9808 Configuration
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] cfg - pointer to Configuration value to read to
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ MCP9808_Read_Config(MCP9808_t * const pCpnt, uint16_t * cfg) {
return MCP9808_Read(pCpnt->cfg.slave_inst, cfg, MCP9808__CONFIGURATION, 1); }
/*!\brief Get MCP9808 Configuration
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] temp - pointer to Temperature value to read to
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ MCP9808_Get_Temperature_Raw(MCP9808_t * const pCpnt, uint16_t * temp) {
return MCP9808_Read(pCpnt->cfg.slave_inst, temp, MCP9808__TEMPERATURE, 1); }
/*!\brief Get MCP9808 Resolution
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] res - pointer to Resolution to read to
** \return FctERR - error code
**/
FctERR NONNULL__ MCP9808_Get_Resolution(MCP9808_t * const pCpnt, MCP9808_res * res);
/*!\brief Get MCP9808 Manufacturer ID
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] id - pointer to Manufacturer ID result
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ MCP9808_Get_ManufacturerID(MCP9808_t * const pCpnt, uint16_t * id) {
return MCP9808_Read(pCpnt->cfg.slave_inst, id, MCP9808__MANUFACTURER_ID, 1); }
/*!\brief Get MCP9808 chip ID
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] id - pointer to chip ID result
** \return FctERR - error code
**/
__INLINE FctERR NONNULL_INLINE__ MCP9808_Get_ChipID(MCP9808_t * const pCpnt, uint16_t * id) {
return MCP9808_Read(pCpnt->cfg.slave_inst, id, MCP9808__DEVICE_ID, 1); }
/*******************/
/*** GPIO access ***/
/*******************/
/*!\brief Alert GPIO pin init for MCP9808
** \weak MCP9808 Alert GPIO pin init may be user implemented if needed
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in] GPIOx - Alert port
** \param[in] GPIO_Pin - Alert pin
** \param[in] GPIO_Active: Alert pin active state
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ MCP9808_Alert_GPIO_Init(MCP9808_t * const pCpnt, GPIO_TypeDef * const GPIOx, const uint16_t GPIO_Pin, const GPIO_PinState GPIO_Active);
/*!\brief Change GPIO pin getter for MCP9808
** \weak MCP9808 Change GPIO pin getter may be user implemented if needed
** \param[in] pCpnt - Pointer to MCP9808 component
** \param[in,out] pState - Pointer to Alert pin state variable (0: inactive, 1: active)
** \return FctERR - ErrorCode
**/
FctERR NONNULL__ MCP9808_Alert_GPIO_Get(MCP9808_t * const pCpnt, bool * const pState);
/****************************************************************/
#endif
#ifdef __cplusplus
}
#endif
#endif /* __MCP9808_EX_H__ */
/****************************************************************/