rtc12 2.0.0.0
rtc12.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef RTC12_H
29#define RTC12_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52
53
74#define RTC12_REG_SECONDS 0x00
75#define RTC12_REG_MINUTES 0x01
76#define RTC12_REG_HOUR 0x02
77#define RTC12_REG_DAY 0x03
78#define RTC12_REG_DATE 0x04
79#define RTC12_REG_MONTH 0x05
80#define RTC12_REG_YEAR 0x06
81#define RTC12_REG_ALARM_0_SECONDS 0x07
82#define RTC12_REG_ALARM_0_MINUTES 0x08
83#define RTC12_REG_ALARM_0_HOUR 0x09
84#define RTC12_REG_ALARM_0_DAY 0x0A
85#define RTC12_REG_ALARM_1_SECONDS 0x0B
86#define RTC12_REG_ALARM_1_MINUTES 0x0C
87#define RTC12_REG_ALARM_1_HOUR 0x0D
88#define RTC12_REG_ALARM_1_DAY 0x0E
89#define RTC12_REG_CONTROL 0x0F
90#define RTC12_REG_STATUS 0x10
91#define RTC12_REG_TRICKLE_CHARGER 0x11
92
93 // rtc12_reg
94
109#define RTC12_SET_EOSC_ENABLE 0x00
110#define RTC12_SET_EOSC_DISABLE 0x01
111#define RTC12_SET_DOSF_ENABLE 0x00
112#define RTC12_SET_DOSF_DISABL 0x01
113#define RTC12_SET_EGFIL_DISABLE 0x00
114#define RTC12_SET_EGFIL_ENABLE 0x01
115#define RTC12_SET_SQW_DISABLE 0x00
116#define RTC12_SET_SQW_ENABLE 0x01
117#define RTC12_SET_INTCN_A0IE 0x00
118#define RTC12_SET_INTCN_A0IE_A1IE 0x01
119#define RTC12_SET_ALARM_1_DISABLE 0x00
120#define RTC12_SET_ALARM_1_ENABLE 0x01
121#define RTC12_SET_ALARM_0_DISABLE 0x00
122#define RTC12_SET_ALARM_0_ENABLE 0x01
123
124
125 // rtc12_set
126
141#define RTC12_MAP_MIKROBUS( cfg, mikrobus ) \
142 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
143 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
144 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
145 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
146 cfg.pf = MIKROBUS( mikrobus, MIKROBUS_AN ); \
147 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
148
149 // rtc12_map
150 // rtc12
151
156typedef struct
157{
158 // Input pins
159
160 digital_in_t pf;
161 digital_in_t int_pin;
163 // Modules
164
165 spi_master_t spi;
167 pin_name_t chip_select;
169} rtc12_t;
170
175typedef struct
176{
177 // Communication gpio pins
178
179 pin_name_t miso;
180 pin_name_t mosi;
181 pin_name_t sck;
182 pin_name_t cs;
184 // Additional gpio pins
185
186 pin_name_t pf;
187 pin_name_t int_pin;
189 // static variable
190
191 uint32_t spi_speed;
192 spi_master_mode_t spi_mode;
193 spi_master_chip_select_polarity_t cs_polarity;
196
201typedef struct
202{
203 uint8_t hours;
204 uint8_t min;
205 uint8_t sec;
206
208
213typedef struct
214{
215 uint8_t year;
216 uint8_t month;
217 uint8_t day;
218 uint8_t day_of_week;
219
220
222
227typedef struct
228{
229 uint8_t day;
230 uint8_t hours;
231 uint8_t min;
232 uint8_t sec;
233 uint8_t alarm_rate;
234
236
241typedef struct
242{
243 uint8_t eosc;
244 uint8_t dosf;
245 uint8_t egfil;
246 uint8_t sqw;
247 uint8_t intcn;
248 uint8_t a1ie;
249 uint8_t a0ie;
250
252
253
258typedef enum
259{
261 RTC12_ERROR = -1
262
264
281
296err_t rtc12_init ( rtc12_t *ctx, rtc12_cfg_t *cfg );
297
312
328err_t rtc12_generic_write ( rtc12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
329
345err_t rtc12_generic_read ( rtc12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
346
362
378
393err_t rtc12_get_time ( rtc12_t *ctx, rtc12_time_t *rtc_time );
394
409err_t rtc12_set_time ( rtc12_t *ctx, rtc12_time_t rtc_time );
410
425err_t rtc12_get_date ( rtc12_t *ctx, rtc12_date_t *rtc_date );
426
441err_t rtc12_set_date ( rtc12_t *ctx, rtc12_date_t rtc_date );
442
457err_t rtc12_get_alarm_0 ( rtc12_t *ctx, rtc12_alarm_t *rtc_alarm );
458
473err_t rtc12_set_alarm_0 ( rtc12_t *ctx, rtc12_alarm_t rtc_alarm );
474
489err_t rtc12_get_alarm_1 ( rtc12_t *ctx, rtc12_alarm_t *rtc_alarm );
490
505err_t rtc12_set_alarm_1 ( rtc12_t *ctx, rtc12_alarm_t rtc_alarm );
506
520uint8_t rtc12_check_int ( rtc12_t *ctx );
521
536
537#ifdef __cplusplus
538}
539#endif
540#endif // RTC12_H
541
542 // rtc12
543
544// ------------------------------------------------------------------------ END
err_t rtc12_set_alarm_0(rtc12_t *ctx, rtc12_alarm_t rtc_alarm)
RTC 12 get alarm 0 function.
uint8_t rtc12_check_int(rtc12_t *ctx)
RTC 12 check interrupt state function.
err_t rtc12_generic_write(rtc12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 12 data writing function.
err_t rtc12_set_date(rtc12_t *ctx, rtc12_date_t rtc_date)
RTC 12 get time function.
err_t rtc12_default_cfg(rtc12_t *ctx)
RTC 12 default configuration function.
err_t rtc12_get_ctrl_reg(rtc12_t *ctx, rtc12_control_t *rtc_ctrl)
RTC 12 get control register function.
err_t rtc12_init(rtc12_t *ctx, rtc12_cfg_t *cfg)
RTC 12 initialization function.
uint8_t rtc12_check_power_fail(rtc12_t *ctx)
RTC 12 check power fail state function.
void rtc12_cfg_setup(rtc12_cfg_t *cfg)
RTC 12 configuration object setup function.
err_t rtc12_get_time(rtc12_t *ctx, rtc12_time_t *rtc_time)
RTC 12 get time function.
err_t rtc12_set_time(rtc12_t *ctx, rtc12_time_t rtc_time)
RTC 12 set time function.
err_t rtc12_get_date(rtc12_t *ctx, rtc12_date_t *rtc_date)
RTC 12 get date function.
err_t rtc12_generic_read(rtc12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 12 data reading function.
err_t rtc12_get_alarm_0(rtc12_t *ctx, rtc12_alarm_t *rtc_alarm)
RTC 12 get alarm 0 function.
err_t rtc12_set_alarm_1(rtc12_t *ctx, rtc12_alarm_t rtc_alarm)
RTC 12 get alarm 1 function.
err_t rtc12_set_ctrl_reg(rtc12_t *ctx, rtc12_control_t rtc_ctrl)
RTC 12 set control register function.
err_t rtc12_get_alarm_1(rtc12_t *ctx, rtc12_alarm_t *rtc_alarm)
RTC 12 get alarm 1 function.
rtc12_return_value_t
RTC 12 Click return value data.
Definition rtc12.h:259
@ RTC12_ERROR
Definition rtc12.h:261
@ RTC12_OK
Definition rtc12.h:260
RTC 12 Click alarm object.
Definition rtc12.h:228
uint8_t hours
Definition rtc12.h:230
uint8_t alarm_rate
Definition rtc12.h:233
uint8_t day
Definition rtc12.h:229
uint8_t min
Definition rtc12.h:231
uint8_t sec
Definition rtc12.h:232
RTC 12 Click configuration object.
Definition rtc12.h:176
spi_master_chip_select_polarity_t cs_polarity
Definition rtc12.h:193
pin_name_t sck
Definition rtc12.h:181
spi_master_mode_t spi_mode
Definition rtc12.h:192
pin_name_t mosi
Definition rtc12.h:180
uint32_t spi_speed
Definition rtc12.h:191
pin_name_t pf
Definition rtc12.h:186
pin_name_t int_pin
Definition rtc12.h:187
pin_name_t miso
Definition rtc12.h:179
pin_name_t cs
Definition rtc12.h:182
RTC 12 Click control object.
Definition rtc12.h:242
uint8_t egfil
Definition rtc12.h:245
uint8_t eosc
Definition rtc12.h:243
uint8_t intcn
Definition rtc12.h:247
uint8_t a1ie
Definition rtc12.h:248
uint8_t a0ie
Definition rtc12.h:249
uint8_t sqw
Definition rtc12.h:246
uint8_t dosf
Definition rtc12.h:244
RTC 12 Click date object.
Definition rtc12.h:214
uint8_t month
Definition rtc12.h:216
uint8_t day
Definition rtc12.h:217
uint8_t year
Definition rtc12.h:215
uint8_t day_of_week
Definition rtc12.h:218
RTC 12 Click context object.
Definition rtc12.h:157
spi_master_t spi
Definition rtc12.h:165
digital_in_t pf
Definition rtc12.h:160
digital_in_t int_pin
Definition rtc12.h:161
pin_name_t chip_select
Definition rtc12.h:167
RTC 12 Click time object.
Definition rtc12.h:202
uint8_t hours
Definition rtc12.h:203
uint8_t min
Definition rtc12.h:204
uint8_t sec
Definition rtc12.h:205