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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define RTC16_REG_SECOND_COUNTER 0x00
60 #define RTC16_REG_MINUTE_COUNTER 0x01
61 #define RTC16_REG_HOUR_COUNTER 0x02
62 #define RTC16_REG_DAY_OF_WEEK_COUNTER 0x03
63 #define RTC16_REG_DAY_COUNTER 0x04
64 #define RTC16_REG_MONTH_COUNTER 0x05
65 #define RTC16_REG_YEAR_COUNTER 0x06
66 #define RTC16_REG_TIME_TRIMMING 0x07
67 #define RTC16_REG_ALARM_A_MINUTE 0x08
68 #define RTC16_REG_ALARM_A_HOUR 0x09
69 #define RTC16_REG_ALARM_A_DAY_OF_WEEK 0x0A
70 #define RTC16_REG_ALARM_B_MINUTE 0x0B
71 #define RTC16_REG_ALARM_B_HOUR 0x0C
72 #define RTC16_REG_ALARM_B_DAY_OF_WEEK 0x0D
73 #define RTC16_REG_CONTROL1 0x0E
74 #define RTC16_REG_CONTROL2 0x0F
75  // rtc16_reg
77 
92 #define RTC16_CONTROL1_ALARM_A_DISABLE 0x00
93 #define RTC16_CONTROL1_ALARM_A_ENABLE 0x80
94 #define RTC16_CONTROL1_ALARM_B_DISABLE 0x00
95 #define RTC16_CONTROL1_ALARM_B_ENABLE 0x40
96 #define RTC16_CONTROL1_TEST_NORMAL 0x00
97 #define RTC16_CONTROL1_TEST_TEST 0x10
98 #define RTC16_CONTROL1_CT_OFF 0x00
99 #define RTC16_CONTROL1_CT_FIXED_L 0x01
100 #define RTC16_CONTROL1_CT_PULSE_2HZ 0x02
101 #define RTC16_CONTROL1_CT_PULSE_1HZ 0x03
102 #define RTC16_CONTROL1_CT_EVERY_SECOND 0x04
103 #define RTC16_CONTROL1_CT_EVERY_MINUTE 0x05
104 #define RTC16_CONTROL1_CT_EVERY_HOUR 0x06
105 #define RTC16_CONTROL1_CT_EVERY_MONTH 0x07
106 
111 #define RTC16_CONTROL2_12HOUR_TIME 0x00
112 #define RTC16_CONTROL2_24HOUR_TIME 0x20
113 #define RTC16_CONTROL2_ADJ_BIT 0x10
114 #define RTC16_CONTROL2_CLOCK_ENABLE 0x00
115 #define RTC16_CONTROL2_CLOCK_DISABLE 0x08
116 #define RTC16_CONTROL2_CLEAR_INTERRUPT 0x04
117 #define RTC16_CONTROL2_CLEAR_ALARM_A 0x02
118 #define RTC16_CONTROL2_CLEAR_ALARM_B 0x01
119 
124 #define RTC16_MONDAY 0x00
125 #define RTC16_TUESDAY 0x01
126 #define RTC16_WEDNESDAY 0x02
127 #define RTC16_THURSDAY 0x03
128 #define RTC16_FRIDAY 0x04
129 #define RTC16_SATURDAY 0x05
130 #define RTC16_SUNDAY 0x06
131 
136 #define RTC16_FAST_READ_BIT 0x04
137 
143 #define RTC16_DEVICE_ADDRESS 0x32
144  // rtc16_set
146 
161 #define RTC16_MAP_MIKROBUS( cfg, mikrobus ) \
162  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
163  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
164  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
165  // rtc16_map // rtc16
168 
173 typedef struct
174 {
175  // Input pins
176  digital_in_t int_pin;
178  // Modules
179  i2c_master_t i2c;
181  // I2C slave address
182  uint8_t slave_address;
184 } rtc16_t;
185 
190 typedef struct
191 {
192  pin_name_t scl;
193  pin_name_t sda;
195  pin_name_t int_pin;
197  uint32_t i2c_speed;
198  uint8_t i2c_address;
200 } rtc16_cfg_t;
201 
207 typedef struct
208 {
209  uint8_t second;
210  uint8_t minute;
211  uint8_t hour;
212 
213 } rtc16_time_t;
214 
220 typedef struct
221 {
222  uint8_t day_of_week;
223  uint8_t day;
224  uint8_t month;
225  uint8_t year;
226 
227 } rtc16_date_t;
228 
233 typedef enum
234 {
235  RTC16_OK = 0,
236  RTC16_ERROR = -1
237 
239 
256 
270 err_t rtc16_init ( rtc16_t *ctx, rtc16_cfg_t *cfg );
271 
284 err_t rtc16_default_cfg ( rtc16_t *ctx );
285 
299 err_t rtc16_write_register ( rtc16_t *ctx, uint8_t reg, uint8_t data_in );
300 
315 err_t rtc16_write_multiple_registers ( rtc16_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
316 
329 err_t rtc16_read_register ( rtc16_t *ctx, uint8_t reg, uint8_t *data_out );
330 
344 err_t rtc16_read_register_fast ( rtc16_t *ctx, uint8_t reg, uint8_t *data_out );
345 
360 err_t rtc16_read_multiple_registers ( rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
361 
376 err_t rtc16_read_multiple_registers_fast ( rtc16_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
377 
386 uint8_t rtc16_get_int_pin ( rtc16_t *ctx );
387 
399 
412 err_t rtc16_set_time ( rtc16_t *ctx, rtc16_time_t *time );
413 
426 err_t rtc16_read_time ( rtc16_t *ctx, rtc16_time_t *time );
427 
440 err_t rtc16_set_date ( rtc16_t *ctx, rtc16_date_t *date );
441 
454 err_t rtc16_read_date ( rtc16_t *ctx, rtc16_date_t *date );
455 
456 #ifdef __cplusplus
457 }
458 #endif
459 #endif // RTC16_H
460  // rtc16
462 
463 // ------------------------------------------------------------------------ END
rtc16_time_t::minute
uint8_t minute
Definition: rtc16.h:210
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:222
rtc16_return_value_t
rtc16_return_value_t
RTC 16 Click return value data.
Definition: rtc16.h:234
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:195
RTC16_OK
@ RTC16_OK
Definition: rtc16.h:235
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:225
rtc16_t::i2c
i2c_master_t i2c
Definition: rtc16.h:179
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:223
rtc16_t
RTC 16 Click context object.
Definition: rtc16.h:174
rtc16_cfg_t::scl
pin_name_t scl
Definition: rtc16.h:192
rtc16_date_t::month
uint8_t month
Definition: rtc16.h:224
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:236
rtc16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc16.h:197
rtc16_t::int_pin
digital_in_t int_pin
Definition: rtc16.h:176
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:191
rtc16_time_t
RTC 16 Click time object.
Definition: rtc16.h:208
rtc16_cfg_t::sda
pin_name_t sda
Definition: rtc16.h:193
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:198
rtc16_time_t::second
uint8_t second
Definition: rtc16.h:209
rtc16_date_t
RTC 16 Click date object.
Definition: rtc16.h:221
rtc16_time_t::hour
uint8_t hour
Definition: rtc16.h:211
rtc16_t::slave_address
uint8_t slave_address
Definition: rtc16.h:182
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.