rtc16  2.0.0.0
rtc16.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 RTC16_H
29 #define RTC16_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 RTC16_REG_SECOND_COUNTER 0x00
70 #define RTC16_REG_MINUTE_COUNTER 0x01
71 #define RTC16_REG_HOUR_COUNTER 0x02
72 #define RTC16_REG_DAY_OF_WEEK_COUNTER 0x03
73 #define RTC16_REG_DAY_COUNTER 0x04
74 #define RTC16_REG_MONTH_COUNTER 0x05
75 #define RTC16_REG_YEAR_COUNTER 0x06
76 #define RTC16_REG_TIME_TRIMMING 0x07
77 #define RTC16_REG_ALARM_A_MINUTE 0x08
78 #define RTC16_REG_ALARM_A_HOUR 0x09
79 #define RTC16_REG_ALARM_A_DAY_OF_WEEK 0x0A
80 #define RTC16_REG_ALARM_B_MINUTE 0x0B
81 #define RTC16_REG_ALARM_B_HOUR 0x0C
82 #define RTC16_REG_ALARM_B_DAY_OF_WEEK 0x0D
83 #define RTC16_REG_CONTROL1 0x0E
84 #define RTC16_REG_CONTROL2 0x0F
85  // rtc16_reg
87 
102 #define RTC16_CONTROL1_ALARM_A_DISABLE 0x00
103 #define RTC16_CONTROL1_ALARM_A_ENABLE 0x80
104 #define RTC16_CONTROL1_ALARM_B_DISABLE 0x00
105 #define RTC16_CONTROL1_ALARM_B_ENABLE 0x40
106 #define RTC16_CONTROL1_TEST_NORMAL 0x00
107 #define RTC16_CONTROL1_TEST_TEST 0x10
108 #define RTC16_CONTROL1_CT_OFF 0x00
109 #define RTC16_CONTROL1_CT_FIXED_L 0x01
110 #define RTC16_CONTROL1_CT_PULSE_2HZ 0x02
111 #define RTC16_CONTROL1_CT_PULSE_1HZ 0x03
112 #define RTC16_CONTROL1_CT_EVERY_SECOND 0x04
113 #define RTC16_CONTROL1_CT_EVERY_MINUTE 0x05
114 #define RTC16_CONTROL1_CT_EVERY_HOUR 0x06
115 #define RTC16_CONTROL1_CT_EVERY_MONTH 0x07
116 
121 #define RTC16_CONTROL2_12HOUR_TIME 0x00
122 #define RTC16_CONTROL2_24HOUR_TIME 0x20
123 #define RTC16_CONTROL2_ADJ_BIT 0x10
124 #define RTC16_CONTROL2_CLOCK_ENABLE 0x00
125 #define RTC16_CONTROL2_CLOCK_DISABLE 0x08
126 #define RTC16_CONTROL2_CLEAR_INTERRUPT 0x04
127 #define RTC16_CONTROL2_CLEAR_ALARM_A 0x02
128 #define RTC16_CONTROL2_CLEAR_ALARM_B 0x01
129 
134 #define RTC16_MONDAY 0x00
135 #define RTC16_TUESDAY 0x01
136 #define RTC16_WEDNESDAY 0x02
137 #define RTC16_THURSDAY 0x03
138 #define RTC16_FRIDAY 0x04
139 #define RTC16_SATURDAY 0x05
140 #define RTC16_SUNDAY 0x06
141 
146 #define RTC16_FAST_READ_BIT 0x04
147 
153 #define RTC16_DEVICE_ADDRESS 0x32
154  // rtc16_set
156 
171 #define RTC16_MAP_MIKROBUS( cfg, mikrobus ) \
172  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
174  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
175  // rtc16_map // rtc16
178 
183 typedef struct
184 {
185  // Input pins
186  digital_in_t int_pin;
188  // Modules
189  i2c_master_t i2c;
191  // I2C slave address
192  uint8_t slave_address;
194 } rtc16_t;
195 
200 typedef struct
201 {
202  pin_name_t scl;
203  pin_name_t sda;
205  pin_name_t int_pin;
207  uint32_t i2c_speed;
208  uint8_t i2c_address;
210 } rtc16_cfg_t;
211 
217 typedef struct
218 {
219  uint8_t second;
220  uint8_t minute;
221  uint8_t hour;
222 
223 } rtc16_time_t;
224 
230 typedef struct
231 {
232  uint8_t day_of_week;
233  uint8_t day;
234  uint8_t month;
235  uint8_t year;
236 
237 } rtc16_date_t;
238 
243 typedef enum
244 {
245  RTC16_OK = 0,
246  RTC16_ERROR = -1
247 
249 
266 
280 err_t rtc16_init ( rtc16_t *ctx, rtc16_cfg_t *cfg );
281 
294 err_t rtc16_default_cfg ( rtc16_t *ctx );
295 
309 err_t rtc16_write_register ( rtc16_t *ctx, uint8_t reg, uint8_t data_in );
310 
325 err_t rtc16_write_multiple_registers ( rtc16_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
326 
339 err_t rtc16_read_register ( rtc16_t *ctx, uint8_t reg, uint8_t *data_out );
340 
354 err_t rtc16_read_register_fast ( rtc16_t *ctx, uint8_t reg, uint8_t *data_out );
355 
370 err_t rtc16_read_multiple_registers ( rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
371 
386 err_t rtc16_read_multiple_registers_fast ( rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
387 
396 uint8_t rtc16_get_int_pin ( rtc16_t *ctx );
397 
409 
422 err_t rtc16_set_time ( rtc16_t *ctx, rtc16_time_t *time );
423 
436 err_t rtc16_read_time ( rtc16_t *ctx, rtc16_time_t *time );
437 
450 err_t rtc16_set_date ( rtc16_t *ctx, rtc16_date_t *date );
451 
464 err_t rtc16_read_date ( rtc16_t *ctx, rtc16_date_t *date );
465 
466 #ifdef __cplusplus
467 }
468 #endif
469 #endif // RTC16_H
470  // rtc16
472 
473 // ------------------------------------------------------------------------ END
rtc16_time_t::minute
uint8_t minute
Definition: rtc16.h:220
rtc16_read_register
err_t rtc16_read_register(rtc16_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 16 read register function.
rtc16_date_t::day_of_week
uint8_t day_of_week
Definition: rtc16.h:232
rtc16_return_value_t
rtc16_return_value_t
RTC 16 Click return value data.
Definition: rtc16.h:244
rtc16_read_time
err_t rtc16_read_time(rtc16_t *ctx, rtc16_time_t *time)
RTC 16 read time function.
rtc16_clear_interrupts
err_t rtc16_clear_interrupts(rtc16_t *ctx)
RTC 16 clear interrupts function.
rtc16_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc16.h:205
RTC16_OK
@ RTC16_OK
Definition: rtc16.h:245
rtc16_init
err_t rtc16_init(rtc16_t *ctx, rtc16_cfg_t *cfg)
RTC 16 initialization function.
rtc16_set_time
err_t rtc16_set_time(rtc16_t *ctx, rtc16_time_t *time)
RTC 16 set time function.
rtc16_read_multiple_registers
err_t rtc16_read_multiple_registers(rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
RTC 16 read multiple registers function.
rtc16_write_register
err_t rtc16_write_register(rtc16_t *ctx, uint8_t reg, uint8_t data_in)
RTC 16 write register function.
rtc16_date_t::year
uint8_t year
Definition: rtc16.h:235
rtc16_t::i2c
i2c_master_t i2c
Definition: rtc16.h:189
rtc16_set_date
err_t rtc16_set_date(rtc16_t *ctx, rtc16_date_t *date)
RTC 16 set date function.
rtc16_read_date
err_t rtc16_read_date(rtc16_t *ctx, rtc16_date_t *date)
RTC 16 read date function.
rtc16_date_t::day
uint8_t day
Definition: rtc16.h:233
rtc16_t
RTC 16 Click context object.
Definition: rtc16.h:184
rtc16_cfg_t::scl
pin_name_t scl
Definition: rtc16.h:202
rtc16_date_t::month
uint8_t month
Definition: rtc16.h:234
rtc16_read_multiple_registers_fast
err_t rtc16_read_multiple_registers_fast(rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
RTC 16 read multiple registers fast function.
RTC16_ERROR
@ RTC16_ERROR
Definition: rtc16.h:246
rtc16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc16.h:207
rtc16_t::int_pin
digital_in_t int_pin
Definition: rtc16.h:186
rtc16_get_int_pin
uint8_t rtc16_get_int_pin(rtc16_t *ctx)
RTC 16 get int pin function.
rtc16_cfg_t
RTC 16 Click configuration object.
Definition: rtc16.h:201
rtc16_time_t
RTC 16 Click time object.
Definition: rtc16.h:218
rtc16_cfg_t::sda
pin_name_t sda
Definition: rtc16.h:203
rtc16_read_register_fast
err_t rtc16_read_register_fast(rtc16_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 16 read register fast function.
rtc16_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc16.h:208
rtc16_time_t::second
uint8_t second
Definition: rtc16.h:219
rtc16_date_t
RTC 16 Click date object.
Definition: rtc16.h:231
rtc16_time_t::hour
uint8_t hour
Definition: rtc16.h:221
rtc16_t::slave_address
uint8_t slave_address
Definition: rtc16.h:192
rtc16_default_cfg
err_t rtc16_default_cfg(rtc16_t *ctx)
RTC 16 default configuration function.
rtc16_write_multiple_registers
err_t rtc16_write_multiple_registers(rtc16_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
RTC 16 write multiple registers function.
rtc16_cfg_setup
void rtc16_cfg_setup(rtc16_cfg_t *cfg)
RTC 16 configuration object setup function.