no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
max31343.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file max31343.h
3 * @brief Max31343 Real Time Clock header file
4 * @author Robert Budai (robert.budai@analog.com)
5 ********************************************************************************
6 * Copyright (c) 2024 Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34#ifndef __MAX31343__
35#define __MAX31343__
36
37#include <stdint.h>
38#include <string.h>
39#include "no_os_util.h"
40#include "no_os_i2c.h"
41
42#define MAX31343_I2C_ADDRESS 0x68
43#define MAX31343_R_STATUS 0x00
44#define MAX31343_R_INT_EN 0x01
45#define MAX31343_R_RTC_RESET 0x02
46#define MAX31343_R_CFG1 0x03
47#define MAX31343_R_CFG2 0x04
48#define MAX31343_R_TIMER_CONFIG 0x05
49#define MAX31343_R_SECONDS 0x06
50#define MAX31343_R_MINUTES 0x07
51#define MAX31343_R_HOURS 0x08
52#define MAX31343_R_DAY 0x09
53#define MAX31343_R_DATE 0x0A
54#define MAX31343_R_MONTH 0x0B
55#define MAX31343_R_YEAR 0x0C
56#define MAX31343_R_ALM1_SEC 0x0D
57#define MAX31343_R_ALM1_MIN 0x0E
58#define MAX31343_R_ALM1_HRS 0x0F
59#define MAX31343_R_ALM1DAY_DATE 0x10
60#define MAX31343_R_ALM1_MON 0x11
61#define MAX31343_R_ALM1_YEAR 0x12
62#define MAX31343_R_ALM2_MIN 0x13
63#define MAX31343_R_ALM2_HRS 0x14
64#define MAX31343_R_ALM2DAY_DATE 0x15
65#define MAX31343_R_TIMER_COUNT 0x16
66#define MAX31343_R_TIMER_INIT 0x17
67#define MAX31343_R_PWR_MGMT 0x18
68#define MAX31343_R_TRICKLE 0x19
69#define MAX31343_R_TEMP_MSB 0x1A
70#define MAX31343_R_TEMP_LSB 0x1B
71#define MAX31343_R_TS_CONFIG 0x1C
72#define MAX31343_R_RAM_REG_START 0x22
73#define MAX31343_R_RAM_REG_END 0x61
74
75/* Status register bits */
76#define MAX31343_F_STATUS_A1F NO_OS_BIT(0)
77#define MAX31343_F_STATUS_A2F NO_OS_BIT(1)
78#define MAX31343_F_STATUS_TIF NO_OS_BIT(2)
79#define MAX31343_F_STATUS_TSF NO_OS_BIT(3)
80#define MAX31343_F_STATUS_PFAIL NO_OS_BIT(5)
81#define MAX31343_F_STATUS_OSF NO_OS_BIT(6)
82#define MAX31343_F_STATUS_PSDECT NO_OS_BIT(7)
83
84/* Interrupt enable register bits */
85#define MAX31343_F_INT_EN_A1IE NO_OS_BIT(0)
86#define MAX31343_F_INT_EN_A2IE NO_OS_BIT(1)
87#define MAX31343_F_INT_EN_TIE NO_OS_BIT(2)
88#define MAX31343_F_INT_EN_TSIE NO_OS_BIT(3)
89#define MAX31343_F_INT_EN_PFAILE NO_OS_BIT(5)
90#define MAX31343_F_INT_EN_DOSF NO_OS_BIT(6)
91
92/* RTC reset register bits */
93#define MAX31343_F_RTC_RESET_SWRST NO_OS_BIT(0)
94
95/* Config 1 register bits */
96#define MAX31343_F_CFG1_ENOSC NO_OS_BIT(1)
97#define MAX31343_F_CFG1_I2C_TIMEOUT NO_OS_BIT(3)
98#define MAX31343_F_CFG1_DATA_RET NO_OS_BIT(4)
99
100/* Config 2 register bits */
101#define MAX31343_F_CFG2_SQW_HZ NO_OS_BIT(0)
102#define MAX31343_F_CFG2_CLKO_HZ NO_OS_BIT(3)
103#define MAX31343_F_CFG2_ENCLKO NO_OS_BIT(7)
104
105/* Timer config register bits */
106#define MAX31343_F_TIMER_CONFIG_TFS NO_OS_BIT(0)
107#define MAX31343_F_TIMER_CONFIG_TRPT NO_OS_BIT(2)
108#define MAX31343_F_TIMER_CONFIG_TPAUSE NO_OS_BIT(3)
109#define MAX31343_F_TIMER_CONFIG_TE NO_OS_BIT(4)
110
111/* Power management register bits */
112#define MAX31343_F_PWR_MGMT_DMAN_SEL NO_OS_BIT(2)
113#define MAX31343_F_PWR_MGMT_D_VBACK_SEL NO_OS_BIT(3)
114#define MAX31343_F_PWR_MGMT_PFVT NO_OS_BIT(4)
115
116/* Trickle register bits */
117#define MAX31343_F_TRICKLE_D_TRICKLE NO_OS_BIT(0)
118#define MAX31343_F_TRICKLE_TCHE NO_OS_BIT(4)
119
120/* Temperature sensor config register bits */
121#define MAX31343_F_TS_CONFIG_TTSINT NO_OS_BIT(3)
122#define MAX31343_F_TS_CONFIG_ONESHOT_MODE NO_OS_BIT(6)
123#define MAX31343_F_TS_CONFIG_AUTO_MODE NO_OS_BIT(7)
124
130 uint8_t sec; /* Seconds [0-61] */
131 uint8_t min; /* Minutes [0-59] */
132 uint8_t hr; /* Hours [0-23] */
133 uint8_t day; /* Day of month [1-31] */
134 uint8_t mon; /* Month [0-11] */
135 uint8_t year; /* Year [2000-2199] */
136};
137
147
157
158/* Read device register. */
159int max31343_reg_read(struct max31343_dev *dev, uint8_t reg_addr,
160 uint8_t *reg_data);
161
162/* Write device register. */
163int max31343_reg_write(struct max31343_dev *dev, uint8_t reg_addr,
164 uint8_t reg_data);
165
166/* Update specific register bits. */
167int max31343_update_bits(struct max31343_dev *dev, uint8_t reg_addr,
168 uint8_t mask, uint8_t reg_data);
169
170/* Set time stemp */
172 struct max31343_time_stamp ts);
173
174/* Read time stamp */
176 struct max31343_time_stamp *ts);
177
178/* Initialize the device. */
181
182/* Remove the device and release resources. */
183int max31343_remove(struct max31343_dev *dev);
184
185#endif /* __MAX31343__ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int max31343_reg_write(struct max31343_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Write device register.
Definition max31343.c:66
int max31343_reg_read_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp *ts)
Read time stamp.
Definition max31343.c:212
int max31343_remove(struct max31343_dev *dev)
Remove the device and release resources.
Definition max31343.c:264
int max31343_init(struct max31343_dev **device, struct max31343_init_param init_param)
Initialize the device.
Definition max31343.c:108
int max31343_set_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp ts)
Set time stamp.
Definition max31343.c:159
int max31343_reg_read(struct max31343_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Read device register.
Definition max31343.c:47
int max31343_update_bits(struct max31343_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t reg_data)
Update specific register bits.
Definition max31343.c:85
Header file of I2C Interface.
Header file of utility functions.
Definition ad9361_util.h:63
max31343 Device structure.
Definition max31343.h:152
uint8_t battery_en
Definition max31343.h:155
struct no_os_i2c_desc * i2c_desc
Definition max31343.h:154
max31343 Device initialization parameters.
Definition max31343.h:142
struct no_os_i2c_init_param * i2c_init
Definition max31343.h:144
uint8_t battery_en
Definition max31343.h:145
Structure holding the date parameters.
Definition max31343.h:129
uint8_t min
Definition max31343.h:131
uint8_t year
Definition max31343.h:135
uint8_t day
Definition max31343.h:133
uint8_t sec
Definition max31343.h:130
uint8_t hr
Definition max31343.h:132
uint8_t mon
Definition max31343.h:134
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52