rtc14 2.0.0.0
rtc14.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 RTC14_H
29#define RTC14_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_i2c_master.h"
52
73#define RTC14_REG_SC 0x00
74#define RTC14_REG_MN 0x01
75#define RTC14_REG_HR 0x02
76#define RTC14_REG_DT 0x03
77#define RTC14_REG_MO 0x04
78#define RTC14_REG_YR 0x05
79#define RTC14_REG_DW 0x06
80#define RTC14_REG_SR 0x07
81#define RTC14_REG_INT 0x08
82#define RTC14_REG_ATR 0x0A
83#define RTC14_REG_DTR 0x0B
84#define RTC14_REG_SCA 0x0C
85#define RTC14_REG_MNA 0x0D
86#define RTC14_REG_HRA 0x0E
87#define RTC14_REG_DTA 0x0F
88#define RTC14_REG_MOA 0x10
89#define RTC14_REG_DWA 0x11
90#define RTC14_REG_USR1 0x12
91#define RTC14_REG_USR2 0x13
92#define RTC14_REG_SCT 0x14
93#define RTC14_REG_MNT 0x15
94#define RTC14_REG_HRT 0x16
95#define RTC14_REG_DTT 0x17
96#define RTC14_REG_MOT 0x18
97#define RTC14_REG_YRT 0x19
98
99 // rtc14_reg
100
115#define RTC14_SET_HOURS_FORMAT_12 0x00
116#define RTC14_SET_HOURS_FORMAT_24 0x80
117#define RTC14_SET_HOURS_FORMAT_12_AM 0x00
118#define RTC14_SET_HOURS_FORMAT_12_PM 0x20
119#define RTC14_SET_ALARM_ENABLE 0x80
120#define RTC14_SET_INT_ENABLE 0x40
121#define RTC14_SET_SOFT_RESET 0x80
122#define RTC14_SET_ENABLE_WRTC 0x10
123
128#define RTC14_DW_SUNDAY 0x00
129#define RTC14_DW_MONDAY 0x01
130#define RTC14_DW_TUESDAY 0x02
131#define RTC14_DW_WEDNESDAY 0x03
132#define RTC14_DW_THURSDAY 0x04
133#define RTC14_DW_FRIDAY 0x05
134#define RTC14_DW_SATURDAY 0x06
135
141#define RTC14_SET_DEV_ADDR 0x6F
142
143 // rtc14_set
144
159#define RTC14_MAP_MIKROBUS( cfg, mikrobus ) \
160 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
162 cfg.fo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
163 cfg.ein = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
164 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
165
166 // rtc14_map
167 // rtc14
168
173typedef struct
174{
175 // Output pins
176 digital_out_t ein;
178 // Input pins
179 digital_in_t fo;
180 digital_in_t int_pin;
182 // Modules
183 i2c_master_t i2c;
185 // I2C slave address
188} rtc14_t;
189
194typedef struct
195{
196 pin_name_t scl;
197 pin_name_t sda;
199 pin_name_t fo;
200 pin_name_t ein;
201 pin_name_t int_pin;
203 uint32_t i2c_speed;
204 uint8_t i2c_address;
207
212typedef struct
213{
215 uint8_t am_pm;
216 uint8_t hours;
217 uint8_t min;
218 uint8_t sec;
219
221
226typedef struct
227{
228 uint8_t year;
229 uint8_t month;
230 uint8_t day;
231 uint8_t day_of_week;
232
233
235
240typedef struct
241{
242 uint8_t sec;
243 uint8_t min;
244 uint8_t hours;
245 uint8_t day;
246 uint8_t month;
247 uint8_t day_of_week;
248
250
255typedef struct
256{
257 uint8_t sec;
258 uint8_t min;
259 uint8_t hours;
260 uint8_t day;
261 uint8_t month;
262 uint8_t year;
263
265
270typedef enum
271{
273 RTC14_ERROR = -1
274
276
295
312err_t rtc14_init ( rtc14_t *ctx, rtc14_cfg_t *cfg );
313
330
348err_t rtc14_generic_write ( rtc14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
349
367err_t rtc14_generic_read ( rtc14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
368
385err_t rtc14_write_sram ( rtc14_t *ctx, uint16_t sram_data_in );
386
403err_t rtc14_read_sram ( rtc14_t *ctx, uint16_t *sram_data_out );
404
420
435uint8_t rtc14_get_fout ( rtc14_t *ctx );
436
453
470
487err_t rtc14_get_time ( rtc14_t *ctx, rtc14_time_t *rtc_time );
488
505err_t rtc14_set_time ( rtc14_t *ctx, rtc14_time_t rtc_time );
506
523err_t rtc14_get_date ( rtc14_t *ctx, rtc14_date_t *rtc_date );
524
541err_t rtc14_set_date ( rtc14_t *ctx, rtc14_date_t rtc_date );
542
559err_t rtc14_get_alarm ( rtc14_t *ctx, rtc14_alarm_t *rtc_alarm );
560
577err_t rtc14_set_alarm ( rtc14_t *ctx, rtc14_alarm_t rtc_alarm );
578
592
609err_t rtc14_get_time_stamp ( rtc14_t *ctx, rtc14_time_stamp_t *rtc_time_stamp );
610
611#ifdef __cplusplus
612}
613#endif
614#endif // RTC14_H
615
616 // rtc14
617
618// ------------------------------------------------------------------------ END
err_t rtc14_generic_write(rtc14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
RTC 14 I2C writing function.
err_t rtc14_init(rtc14_t *ctx, rtc14_cfg_t *cfg)
RTC 14 initialization function.
err_t rtc14_set_date(rtc14_t *ctx, rtc14_date_t rtc_date)
RTC 14 set date function.
void rtc14_cfg_setup(rtc14_cfg_t *cfg)
RTC 14 configuration object setup function.
err_t rtc14_get_time(rtc14_t *ctx, rtc14_time_t *rtc_time)
RTC 14 get time function.
err_t rtc14_set_time(rtc14_t *ctx, rtc14_time_t rtc_time)
RTC 14 set time function.
void rtc14_trigger_time_stamp(rtc14_t *ctx)
RTC 14 trigger time stamp function.
err_t rtc14_write_sram(rtc14_t *ctx, uint16_t sram_data_in)
RTC 14 write SRAM function.
uint8_t rtc14_get_fout(rtc14_t *ctx)
RTC 14 get fout function.
err_t rtc14_get_time_stamp(rtc14_t *ctx, rtc14_time_stamp_t *rtc_time_stamp)
RTC 14 get time stamp function.
uint8_t rtc14_get_interrupt(rtc14_t *ctx)
RTC 14 get interrupt function.
err_t rtc14_soft_reset(rtc14_t *ctx)
RTC 14 soft reset function.
err_t rtc14_generic_read(rtc14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
RTC 14 I2C reading function.
err_t rtc14_get_alarm(rtc14_t *ctx, rtc14_alarm_t *rtc_alarm)
RTC 14 get alarm function.
err_t rtc14_enable_rtc(rtc14_t *ctx)
RTC 14 enable RTC function.
err_t rtc14_get_date(rtc14_t *ctx, rtc14_date_t *rtc_date)
RTC 14 get date function.
err_t rtc14_default_cfg(rtc14_t *ctx)
RTC 14 default configuration function.
err_t rtc14_set_alarm(rtc14_t *ctx, rtc14_alarm_t rtc_alarm)
RTC 14 set alarm function.
err_t rtc14_read_sram(rtc14_t *ctx, uint16_t *sram_data_out)
RTC 14 I2C reading SRAM function.
rtc14_return_value_t
RTC 14 Click return value data.
Definition rtc14.h:271
@ RTC14_ERROR
Definition rtc14.h:273
@ RTC14_OK
Definition rtc14.h:272
RTC 14 Click alarm object.
Definition rtc14.h:241
uint8_t hours
Definition rtc14.h:244
uint8_t month
Definition rtc14.h:246
uint8_t day
Definition rtc14.h:245
uint8_t day_of_week
Definition rtc14.h:247
uint8_t min
Definition rtc14.h:243
uint8_t sec
Definition rtc14.h:242
RTC 14 Click configuration object.
Definition rtc14.h:195
pin_name_t ein
Definition rtc14.h:200
pin_name_t fo
Definition rtc14.h:199
uint32_t i2c_speed
Definition rtc14.h:203
pin_name_t scl
Definition rtc14.h:196
pin_name_t int_pin
Definition rtc14.h:201
pin_name_t sda
Definition rtc14.h:197
uint8_t i2c_address
Definition rtc14.h:204
RTC 14 Click date object.
Definition rtc14.h:227
uint8_t month
Definition rtc14.h:229
uint8_t day
Definition rtc14.h:230
uint8_t year
Definition rtc14.h:228
uint8_t day_of_week
Definition rtc14.h:231
RTC 14 Click context object.
Definition rtc14.h:174
digital_in_t fo
Definition rtc14.h:179
digital_in_t int_pin
Definition rtc14.h:180
i2c_master_t i2c
Definition rtc14.h:183
digital_out_t ein
Definition rtc14.h:176
uint8_t slave_address
Definition rtc14.h:186
RTC 14 Click time stamp object.
Definition rtc14.h:256
uint8_t hours
Definition rtc14.h:259
uint8_t month
Definition rtc14.h:261
uint8_t day
Definition rtc14.h:260
uint8_t year
Definition rtc14.h:262
uint8_t min
Definition rtc14.h:258
uint8_t sec
Definition rtc14.h:257
RTC 14 Click time object.
Definition rtc14.h:213
uint8_t hours
Definition rtc14.h:216
uint8_t hours_format
Definition rtc14.h:214
uint8_t min
Definition rtc14.h:217
uint8_t sec
Definition rtc14.h:218
uint8_t am_pm
Definition rtc14.h:215