1 #ifndef RX8130CE_H
2 #define RX8130CE_H
3 
4 /**@defgroup rx8310ce_api
5  * @{
6  */
7 
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /* ===== System include ===== */
14 #include "aos/hal/i2c.h"
15 #include "aos/hal/rtc.h"
16 // #include "rtc.h"
17 
18 /* I2C settings for I2C library */
19 #ifndef RX8130CE_I2C
20 #define RX8130CE_I2C 1
21 #endif
22 
23 /* RX8130CE I2C clock */
24 #ifndef RX8130CE_I2C_CLOCK
25 #define RX8130CE_I2C_CLOCK 100000
26 #endif
27 
28 /* I2C slave address for RX8130CE */
29 #define RX8130CE_I2C_ADDR 0x32
30 
31 /* Registers location */
32 #define RX8130CE_SECONDS 0x10
33 #define RX8130CE_MINUTES 0x11
34 #define RX8130CE_HOURS 0x12
35 #define RX8130CE_WEEK 0x13
36 #define RX8130CE_DAY 0x14
37 #define RX8130CE_MONTH 0x15
38 #define RX8130CE_YEAR 0x16
39 #define RX8130CE_MIN_ALARM 0x17
40 #define RX8130CE_HOUR_ALARM 0x18
41 #define RX8130CE_WEEK_DAY_ALARM 0x19
42 #define RX8130CE_TCNT0 0x1A
43 #define RX8130CE_TCNT1 0x1B
44 #define RX8130CE_EXT 0x1C
45 #define RX8130CE_FLAG 0x1D
46 #define RX8130CE_CR0 0x1E
47 #define RX8130CE_CR1 0x1F
48 #define RX8130CE_DOFFSET 0x30
49 
50 /* Extension Register (1Ch) bit positions */
51 #define RX8130CE_EXT_BIT_TSEL (7 << 0)
52 #define RX8130CE_EXT_BIT_WADA (1 << 3)
53 #define RX8130CE_EXT_BIT_TE (1 << 4)
54 #define RX8130CE_EXT_BIT_USEL (1 << 5)
55 #define RX8130CE_EXT_BIT_FSEL (3 << 6)
56 
57 /* Flag Register (1Dh) bit positions */
58 #define RX8130CE_FLAG_BIT_VLF (1 << 1)
59 #define RX8130CE_FLAG_BIT_AF (1 << 3)
60 #define RX8130CE_FLAG_BIT_TF (1 << 4)
61 #define RX8130CE_FLAG_BIT_UF (1 << 5)
62 
63 /* Control 0 Register (1Еh) bit positions */
64 #define RX8130CE_CR0_BIT_TSTP (1 << 2)
65 #define RX8130CE_CR0_BIT_AIE (1 << 3)
66 #define RX8130CE_CR0_BIT_TIE (1 << 4)
67 #define RX8130CE_CR0_BIT_UIE (1 << 5)
68 #define RX8130CE_CR0_BIT_STOP (1 << 6)
69 #define RX8130CE_CR0_BIT_TEST (1 << 7)
70 
71 /* Digital offset Register (1Еh) bit positions */
72 #define RX8130CE_DOFFSET_BIT_DTE (1 << 7)
73 
74 /* ===== Dev Type Definition ===== */
75 /* RX8130CE Result enumeration */
76 typedef enum {
77   RX8130CE_RESULT_OK = 0x00,         /*!< Everything OK */
78   RX8130CE_RESULT_ERROR,             /*!< An error occurred */
79   RX8130CE_RESULT_DEVICENOTCONNECTED /*!< Device is not connected */
80 } RX8130CE_RESULT_E;
81 
82 /* RX8130CE Structure for date/time */
83 typedef struct {
84   uint8_t seconds; /*!< Seconds parameter, from 00 to 59 */
85   uint8_t minutes; /*!< Minutes parameter, from 00 to 59 */
86   uint8_t hours;   /*!< Hours parameter, 24Hour mode, 00 to 23 */
87   uint8_t week;    /*!< Day in a week, from 1 to 7 */
88   uint8_t day;     /*!< Day in a month, 1 to 31 */
89   uint8_t month;   /*!< Month in a year, 1 to 12 */
90   uint8_t year;    /*!< Year parameter, 00 to 99, 00 is 2000 and 99 is 2099 */
91 } RX8130CE_TIME_T;
92 
93 /**
94  * @brief  Enumeration for SQW/OUT pin
95  */
96 typedef enum {
97   RX8130CE_OutputFrequency_1Hz =
98       0x00, /*!< Set SQW/OUT pin to 1Hz output frequency */
99   RX8130CE_OutputFrequency_4096Hz,  /*!< Set SQW/OUT pin to 4096Hz output
100                                       frequency */
101   RX8130CE_OutputFrequency_8192Hz,  /*!< Set SQW/OUT pin to 8192Hz output
102                                       frequency */
103   RX8130CE_OutputFrequency_32768Hz, /*!< Set SQW/OUT pin to 32768Hz output
104                                       frequency */
105   RX8130CE_OutputFrequency_High, /*!< Set SQW/OUT pin high. Because this pin is
106                                    open-drain, you will need external pull up
107                                    resistor */
108   RX8130CE_OutputFrequency_Low   /*!< Set SQW/OUT pin low */
109 } RX8130CE_OutputFrequency_t;
110 
111 
112 /* ===== API Lists ===== */
113 /*********************************************************
114  * @fun    rx8130ce_init
115  * @breif  rx8130ce initialization
116  * @param  none
117  * @rtn    0 : on success, EIO : error
118  *********************************************************/
119 int rx8130ce_init(void);
120 
121 /*********************************************************
122  * @fun    rx8130ce_set_time
123  * @param[in]  buf      the pointer for rx8130ce time
124  * @param[in]  len      the length of time
125  * @rtn    0 : on success, EIO : error
126  *********************************************************/
127 int rx8130ce_set_time(const void *buf, uint8_t len);
128 
129 /*********************************************************
130  * @fun    rx8130ce_get_time
131  * @param[in]  buf      the pointer for rx8130ce time
132  * @param[in]  len      the length of time
133  * @rtn    0 : on success, EIO : error
134  *********************************************************/
135 int rx8130ce_get_time(void *buf, uint8_t len);
136 
137 #ifdef __cplusplus
138 }
139 #endif /* __cplusplus */
140 
141 /**
142  * @}
143  */
144 #endif /* RX8130CE_H */
145