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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define RTC14_REG_SC 0x00
70 #define RTC14_REG_MN 0x01
71 #define RTC14_REG_HR 0x02
72 #define RTC14_REG_DT 0x03
73 #define RTC14_REG_MO 0x04
74 #define RTC14_REG_YR 0x05
75 #define RTC14_REG_DW 0x06
76 #define RTC14_REG_SR 0x07
77 #define RTC14_REG_INT 0x08
78 #define RTC14_REG_ATR 0x0A
79 #define RTC14_REG_DTR 0x0B
80 #define RTC14_REG_SCA 0x0C
81 #define RTC14_REG_MNA 0x0D
82 #define RTC14_REG_HRA 0x0E
83 #define RTC14_REG_DTA 0x0F
84 #define RTC14_REG_MOA 0x10
85 #define RTC14_REG_DWA 0x11
86 #define RTC14_REG_USR1 0x12
87 #define RTC14_REG_USR2 0x13
88 #define RTC14_REG_SCT 0x14
89 #define RTC14_REG_MNT 0x15
90 #define RTC14_REG_HRT 0x16
91 #define RTC14_REG_DTT 0x17
92 #define RTC14_REG_MOT 0x18
93 #define RTC14_REG_YRT 0x19
94  // rtc14_reg
96 
111 #define RTC14_SET_HOURS_FORMAT_12 0x00
112 #define RTC14_SET_HOURS_FORMAT_24 0x80
113 #define RTC14_SET_HOURS_FORMAT_12_AM 0x00
114 #define RTC14_SET_HOURS_FORMAT_12_PM 0x20
115 #define RTC14_SET_ALARM_ENABLE 0x80
116 #define RTC14_SET_INT_ENABLE 0x40
117 #define RTC14_SET_SOFT_RESET 0x80
118 #define RTC14_SET_ENABLE_WRTC 0x10
119 
124 #define RTC14_DW_SUNDAY 0x00
125 #define RTC14_DW_MONDAY 0x01
126 #define RTC14_DW_TUESDAY 0x02
127 #define RTC14_DW_WEDNESDAY 0x03
128 #define RTC14_DW_THURSDAY 0x04
129 #define RTC14_DW_FRIDAY 0x05
130 #define RTC14_DW_SATURDAY 0x06
131 
137 #define RTC14_SET_DEV_ADDR 0x6F
138  // rtc14_set
140 
155 #define RTC14_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158  cfg.fo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
159  cfg.ein = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
160  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
161  // rtc14_map // rtc14
164 
169 typedef struct
170 {
171  // Output pins
172  digital_out_t ein;
174  // Input pins
175  digital_in_t fo;
176  digital_in_t int_pin;
178  // Modules
179  i2c_master_t i2c;
181  // I2C slave address
182  uint8_t slave_address;
184 } rtc14_t;
185 
190 typedef struct
191 {
192  pin_name_t scl;
193  pin_name_t sda;
195  pin_name_t fo;
196  pin_name_t ein;
197  pin_name_t int_pin;
199  uint32_t i2c_speed;
200  uint8_t i2c_address;
202 } rtc14_cfg_t;
203 
208 typedef struct
209 {
210  uint8_t hours_format;
211  uint8_t am_pm;
212  uint8_t hours;
213  uint8_t min;
214  uint8_t sec;
215 
216 } rtc14_time_t;
217 
222 typedef struct
223 {
224  uint8_t year;
225  uint8_t month;
226  uint8_t day;
227  uint8_t day_of_week;
228 
229 
230 } rtc14_date_t;
231 
236 typedef struct
237 {
238  uint8_t sec;
239  uint8_t min;
240  uint8_t hours;
241  uint8_t day;
242  uint8_t month;
243  uint8_t day_of_week;
244 
245 } rtc14_alarm_t;
246 
251 typedef struct
252 {
253  uint8_t sec;
254  uint8_t min;
255  uint8_t hours;
256  uint8_t day;
257  uint8_t month;
258  uint8_t year;
259 
261 
266 typedef enum
267 {
268  RTC14_OK = 0,
269  RTC14_ERROR = -1
270 
272 
291 
308 err_t rtc14_init ( rtc14_t *ctx, rtc14_cfg_t *cfg );
309 
325 err_t rtc14_default_cfg ( rtc14_t *ctx );
326 
344 err_t rtc14_generic_write ( rtc14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
345 
363 err_t rtc14_generic_read ( rtc14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
364 
381 err_t rtc14_write_sram ( rtc14_t *ctx, uint16_t sram_data_in );
382 
399 err_t rtc14_read_sram ( rtc14_t *ctx, uint16_t *sram_data_out );
400 
415 uint8_t rtc14_get_interrupt ( rtc14_t *ctx );
416 
431 uint8_t rtc14_get_fout ( rtc14_t *ctx );
432 
448 err_t rtc14_enable_rtc ( rtc14_t *ctx );
449 
465 err_t rtc14_soft_reset ( rtc14_t *ctx );
466 
483 err_t rtc14_get_time ( rtc14_t *ctx, rtc14_time_t *rtc_time );
484 
501 err_t rtc14_set_time ( rtc14_t *ctx, rtc14_time_t rtc_time );
502 
519 err_t rtc14_get_date ( rtc14_t *ctx, rtc14_date_t *rtc_date );
520 
537 err_t rtc14_set_date ( rtc14_t *ctx, rtc14_date_t rtc_date );
538 
555 err_t rtc14_get_alarm ( rtc14_t *ctx, rtc14_alarm_t *rtc_alarm );
556 
573 err_t rtc14_set_alarm ( rtc14_t *ctx, rtc14_alarm_t rtc_alarm );
574 
588 
605 err_t rtc14_get_time_stamp ( rtc14_t *ctx, rtc14_time_stamp_t *rtc_time_stamp );
606 
607 #ifdef __cplusplus
608 }
609 #endif
610 #endif // RTC14_H
611  // rtc14
613 
614 // ------------------------------------------------------------------------ END
rtc14_time_stamp_t::min
uint8_t min
Definition: rtc14.h:254
rtc14_write_sram
err_t rtc14_write_sram(rtc14_t *ctx, uint16_t sram_data_in)
RTC 14 write SRAM function.
rtc14_generic_write
err_t rtc14_generic_write(rtc14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
RTC 14 I2C writing function.
rtc14_generic_read
err_t rtc14_generic_read(rtc14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
RTC 14 I2C reading function.
rtc14_t::int_pin
digital_in_t int_pin
Definition: rtc14.h:176
rtc14_get_interrupt
uint8_t rtc14_get_interrupt(rtc14_t *ctx)
RTC 14 get interrupt function.
rtc14_time_stamp_t::day
uint8_t day
Definition: rtc14.h:256
rtc14_alarm_t::day_of_week
uint8_t day_of_week
Definition: rtc14.h:243
rtc14_get_time
err_t rtc14_get_time(rtc14_t *ctx, rtc14_time_t *rtc_time)
RTC 14 get time function.
rtc14_time_t::am_pm
uint8_t am_pm
Definition: rtc14.h:211
rtc14_time_stamp_t::sec
uint8_t sec
Definition: rtc14.h:253
rtc14_return_value_t
rtc14_return_value_t
RTC 14 Click return value data.
Definition: rtc14.h:267
rtc14_get_time_stamp
err_t rtc14_get_time_stamp(rtc14_t *ctx, rtc14_time_stamp_t *rtc_time_stamp)
RTC 14 get time stamp function.
rtc14_cfg_t::ein
pin_name_t ein
Definition: rtc14.h:196
RTC14_ERROR
@ RTC14_ERROR
Definition: rtc14.h:269
rtc14_get_alarm
err_t rtc14_get_alarm(rtc14_t *ctx, rtc14_alarm_t *rtc_alarm)
RTC 14 get alarm function.
rtc14_date_t::month
uint8_t month
Definition: rtc14.h:225
rtc14_init
err_t rtc14_init(rtc14_t *ctx, rtc14_cfg_t *cfg)
RTC 14 initialization function.
rtc14_date_t::year
uint8_t year
Definition: rtc14.h:224
rtc14_get_date
err_t rtc14_get_date(rtc14_t *ctx, rtc14_date_t *rtc_date)
RTC 14 get date function.
rtc14_t::slave_address
uint8_t slave_address
Definition: rtc14.h:182
rtc14_get_fout
uint8_t rtc14_get_fout(rtc14_t *ctx)
RTC 14 get fout function.
rtc14_cfg_t::sda
pin_name_t sda
Definition: rtc14.h:193
rtc14_date_t::day
uint8_t day
Definition: rtc14.h:226
rtc14_time_stamp_t::hours
uint8_t hours
Definition: rtc14.h:255
RTC14_OK
@ RTC14_OK
Definition: rtc14.h:268
rtc14_time_stamp_t::month
uint8_t month
Definition: rtc14.h:257
rtc14_time_t::min
uint8_t min
Definition: rtc14.h:213
rtc14_alarm_t::min
uint8_t min
Definition: rtc14.h:239
rtc14_set_alarm
err_t rtc14_set_alarm(rtc14_t *ctx, rtc14_alarm_t rtc_alarm)
RTC 14 set alarm function.
rtc14_set_time
err_t rtc14_set_time(rtc14_t *ctx, rtc14_time_t rtc_time)
RTC 14 set time function.
rtc14_alarm_t
RTC 14 Click alarm object.
Definition: rtc14.h:237
rtc14_alarm_t::month
uint8_t month
Definition: rtc14.h:242
rtc14_t
RTC 14 Click context object.
Definition: rtc14.h:170
rtc14_time_t
RTC 14 Click time object.
Definition: rtc14.h:209
rtc14_cfg_t
RTC 14 Click configuration object.
Definition: rtc14.h:191
rtc14_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc14.h:197
rtc14_alarm_t::hours
uint8_t hours
Definition: rtc14.h:240
rtc14_trigger_time_stamp
void rtc14_trigger_time_stamp(rtc14_t *ctx)
RTC 14 trigger time stamp function.
rtc14_default_cfg
err_t rtc14_default_cfg(rtc14_t *ctx)
RTC 14 default configuration function.
rtc14_time_stamp_t
RTC 14 Click time stamp object.
Definition: rtc14.h:252
rtc14_time_t::hours
uint8_t hours
Definition: rtc14.h:212
rtc14_set_date
err_t rtc14_set_date(rtc14_t *ctx, rtc14_date_t rtc_date)
RTC 14 set date function.
rtc14_alarm_t::day
uint8_t day
Definition: rtc14.h:241
rtc14_soft_reset
err_t rtc14_soft_reset(rtc14_t *ctx)
RTC 14 soft reset function.
rtc14_date_t
RTC 14 Click date object.
Definition: rtc14.h:223
rtc14_enable_rtc
err_t rtc14_enable_rtc(rtc14_t *ctx)
RTC 14 enable RTC function.
rtc14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc14.h:199
rtc14_time_t::hours_format
uint8_t hours_format
Definition: rtc14.h:210
rtc14_alarm_t::sec
uint8_t sec
Definition: rtc14.h:238
rtc14_read_sram
err_t rtc14_read_sram(rtc14_t *ctx, uint16_t *sram_data_out)
RTC 14 I2C reading SRAM function.
rtc14_t::ein
digital_out_t ein
Definition: rtc14.h:172
rtc14_cfg_setup
void rtc14_cfg_setup(rtc14_cfg_t *cfg)
RTC 14 configuration object setup function.
rtc14_time_stamp_t::year
uint8_t year
Definition: rtc14.h:258
rtc14_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc14.h:200
rtc14_cfg_t::scl
pin_name_t scl
Definition: rtc14.h:192
rtc14_date_t::day_of_week
uint8_t day_of_week
Definition: rtc14.h:227
rtc14_t::i2c
i2c_master_t i2c
Definition: rtc14.h:179
rtc14_time_t::sec
uint8_t sec
Definition: rtc14.h:214
rtc14_t::fo
digital_in_t fo
Definition: rtc14.h:175
rtc14_cfg_t::fo
pin_name_t fo
Definition: rtc14.h:195