no-OS
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 
145  uint8_t battery_en;
146 };
147 
152 struct max31343_dev {
155  uint8_t battery_en;
156 };
157 
158 /* Read device register. */
159 int max31343_reg_read(struct max31343_dev *dev, uint8_t reg_addr,
160  uint8_t *reg_data);
161 
162 /* Write device register. */
163 int max31343_reg_write(struct max31343_dev *dev, uint8_t reg_addr,
164  uint8_t reg_data);
165 
166 /* Update specific register bits. */
167 int max31343_update_bits(struct max31343_dev *dev, uint8_t reg_addr,
168  uint8_t mask, uint8_t reg_data);
169 
170 /* Set time stemp */
171 int max31343_set_time_stamp(struct max31343_dev *dev,
172  struct max31343_time_stamp ts);
173 
174 /* Read time stamp */
176  struct max31343_time_stamp *ts);
177 
178 /* Initialize the device. */
179 int max31343_init(struct max31343_dev **device,
181 
182 /* Remove the device and release resources. */
183 int max31343_remove(struct max31343_dev *dev);
184 
185 #endif /* __MAX31343__ */
MAX31343_R_DATE
#define MAX31343_R_DATE
Definition: max31343.h:53
no_os_alloc.h
max31343_time_stamp::hr
uint8_t hr
Definition: max31343.h:132
MAX31343_R_CFG1
#define MAX31343_R_CFG1
Definition: max31343.h:46
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
max31343_init_param
max31343 Device initialization parameters.
Definition: max31343.h:142
max31343_init
int max31343_init(struct max31343_dev **device, struct max31343_init_param init_param)
Initialize the device.
Definition: max31343.c:108
MAX31343_R_YEAR
#define MAX31343_R_YEAR
Definition: max31343.h:55
MAX31343_R_MINUTES
#define MAX31343_R_MINUTES
Definition: max31343.h:50
max31343_reg_read_time_stamp
int max31343_reg_read_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp *ts)
Read time stamp.
Definition: max31343.c:212
MAX31343_F_RTC_RESET_SWRST
#define MAX31343_F_RTC_RESET_SWRST
Definition: max31343.h:93
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
max31343_update_bits
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
max31343_time_stamp::mon
uint8_t mon
Definition: max31343.h:134
no_os_delay.h
Header file of Delay functions.
hmc630x_init_param::data
struct no_os_gpio_init_param data
Definition: hmc630x.h:299
max31343_reg_read
int max31343_reg_read(struct max31343_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Read device register.
Definition: max31343.c:47
device
Definition: ad9361_util.h:69
max31343_remove
int max31343_remove(struct max31343_dev *dev)
Remove the device and release resources.
Definition: max31343.c:264
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
max31343_time_stamp::min
uint8_t min
Definition: max31343.h:131
max31343_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: max31343.h:154
max31343_dev::battery_en
uint8_t battery_en
Definition: max31343.h:155
max31343_init_param::i2c_init
struct no_os_i2c_init_param * i2c_init
Definition: max31343.h:144
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
max31343_reg_read_time_stamp
int max31343_reg_read_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp *ts)
Read time stamp.
Definition: max31343.c:212
MAX31343_R_SECONDS
#define MAX31343_R_SECONDS
Definition: max31343.h:49
max31343_init
int max31343_init(struct max31343_dev **device, struct max31343_init_param init_param)
Initialize the device.
Definition: max31343.c:108
max31343_set_time_stamp
int max31343_set_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp ts)
Set time stamp.
Definition: max31343.c:159
max31343_reg_write
int max31343_reg_write(struct max31343_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Write device register.
Definition: max31343.c:66
max31343_time_stamp::day
uint8_t day
Definition: max31343.h:133
MAX31343_R_RTC_RESET
#define MAX31343_R_RTC_RESET
Definition: max31343.h:45
MAX31343_F_CFG1_ENOSC
#define MAX31343_F_CFG1_ENOSC
Definition: max31343.h:96
max31343_init_param::battery_en
uint8_t battery_en
Definition: max31343.h:145
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
max31343_time_stamp::year
uint8_t year
Definition: max31343.h:135
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
no_os_i2c.h
Header file of I2C Interface.
max31343_set_time_stamp
int max31343_set_time_stamp(struct max31343_dev *dev, struct max31343_time_stamp ts)
Set time stamp.
Definition: max31343.c:159
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
max31343_reg_write
int max31343_reg_write(struct max31343_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Write device register.
Definition: max31343.c:66
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
max31343_remove
int max31343_remove(struct max31343_dev *dev)
Remove the device and release resources.
Definition: max31343.c:264
max31343_update_bits
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
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
no_os_bcd2bin
#define no_os_bcd2bin(x)
Definition: no_os_util.h:123
max31343_time_stamp
Structure holding the date parameters.
Definition: max31343.h:129
max31343.h
MAX31343_R_MONTH
#define MAX31343_R_MONTH
Definition: max31343.h:54
max31343_time_stamp::sec
uint8_t sec
Definition: max31343.h:130
MAX31343_R_INT_EN
#define MAX31343_R_INT_EN
Definition: max31343.h:44
no_os_util.h
Header file of utility functions.
max31343_reg_read
int max31343_reg_read(struct max31343_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Read device register.
Definition: max31343.c:47
max31343_dev
max31343 Device structure.
Definition: max31343.h:152
errno.h
Error macro definition for ARM Compiler.
no_os_bin2bcd
#define no_os_bin2bcd(x)
Definition: no_os_util.h:124
MAX31343_R_HOURS
#define MAX31343_R_HOURS
Definition: max31343.h:51