rtc17  2.0.0.0
rtc17.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 RTC17_H
29 #define RTC17_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 RTC17_REG_SECOND_COUNTER 0x00
70 #define RTC17_REG_MINUTE_COUNTER 0x01
71 #define RTC17_REG_HOUR_COUNTER 0x02
72 #define RTC17_REG_DAY_OF_WEEK_COUNTER 0x03
73 #define RTC17_REG_DAY_COUNTER 0x04
74 #define RTC17_REG_MONTH_COUNTER 0x05
75 #define RTC17_REG_YEAR_COUNTER 0x06
76 #define RTC17_REG_OSC_ADJ 0x07
77 #define RTC17_REG_ALARM_W_MINUTE 0x08
78 #define RTC17_REG_ALARM_W_HOUR 0x09
79 #define RTC17_REG_ALARM_W_DAY_OF_WEEK 0x0A
80 #define RTC17_REG_ALARM_D_MINUTE 0x0B
81 #define RTC17_REG_ALARM_D_HOUR 0x0C
82 #define RTC17_REG_CONTROL1 0x0E
83 #define RTC17_REG_CONTROL2 0x0F
84  // rtc17_reg
86 
101 #define RTC17_CONTROL1_ALARM_W_DISABLE 0x00
102 #define RTC17_CONTROL1_ALARM_W_ENABLE 0x80
103 #define RTC17_CONTROL1_ALARM_D_DISABLE 0x00
104 #define RTC17_CONTROL1_ALARM_D_ENABLE 0x40
105 #define RTC17_CONTROL1_12HOUR_TIME 0x00
106 #define RTC17_CONTROL1_24HOUR_TIME 0x20
107 #define RTC17_CONTROL1_CLOCK1_ENABLE 0x00
108 #define RTC17_CONTROL1_CLOCK1_DISABLE 0x10
109 #define RTC17_CONTROL1_TEST_NORMAL 0x00
110 #define RTC17_CONTROL1_TEST_TEST 0x08
111 #define RTC17_CONTROL1_CT_OFF 0x00
112 #define RTC17_CONTROL1_CT_FIXED_L 0x01
113 #define RTC17_CONTROL1_CT_PULSE_2HZ 0x02
114 #define RTC17_CONTROL1_CT_PULSE_1HZ 0x03
115 #define RTC17_CONTROL1_CT_EVERY_SECOND 0x04
116 #define RTC17_CONTROL1_CT_EVERY_MINUTE 0x05
117 #define RTC17_CONTROL1_CT_EVERY_HOUR 0x06
118 #define RTC17_CONTROL1_CT_EVERY_MONTH 0x07
119 
124 #define RTC17_CONTROL2_VDSL_2p1V 0x00
125 #define RTC17_CONTROL2_VDSL_1p6V 0x80
126 #define RTC17_CONTROL2_VDET_ABOVE 0x00
127 #define RTC17_CONTROL2_VDET_BELOW 0x40
128 #define RTC17_CONTROL2_SCRATCH_BIT 0x20
129 #define RTC17_CONTROL2_XSTP_NORMAL 0x00
130 #define RTC17_CONTROL2_XSTP_HALT 0x10
131 #define RTC17_CONTROL2_CLOCK2_ENABLE 0x00
132 #define RTC17_CONTROL2_CLOCK2_DISABLE 0x08
133 #define RTC17_CONTROL2_CLEAR_INTERRUPT 0x04
134 #define RTC17_CONTROL2_CLEAR_ALARM_W 0x02
135 #define RTC17_CONTROL2_CLEAR_ALARM_D 0x01
136 
141 #define RTC17_MONDAY 0x00
142 #define RTC17_TUESDAY 0x01
143 #define RTC17_WEDNESDAY 0x02
144 #define RTC17_THURSDAY 0x03
145 #define RTC17_FRIDAY 0x04
146 #define RTC17_SATURDAY 0x05
147 #define RTC17_SUNDAY 0x06
148 
154 #define RTC17_SET_DEVICE_ADDRESS 0x32
155  // rtc17_set
157 
172 #define RTC17_MAP_MIKROBUS( cfg, mikrobus ) \
173  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
174  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
175  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
176  // rtc17_map // rtc17
179 
184 typedef struct
185 {
186  // Input pins
187  digital_in_t int_pin;
189  // Modules
190  i2c_master_t i2c;
192  // I2C slave address
193  uint8_t slave_address;
195 } rtc17_t;
196 
201 typedef struct
202 {
203  pin_name_t scl;
204  pin_name_t sda;
206  pin_name_t int_pin;
208  uint32_t i2c_speed;
209  uint8_t i2c_address;
211 } rtc17_cfg_t;
212 
218 typedef struct
219 {
220  uint8_t second;
221  uint8_t minute;
222  uint8_t hour;
223 
224 } rtc17_time_t;
225 
231 typedef struct
232 {
233  uint8_t day_of_week;
234  uint8_t day;
235  uint8_t month;
236  uint8_t year;
237 
238 } rtc17_date_t;
239 
244 typedef enum
245 {
246  RTC17_OK = 0,
247  RTC17_ERROR = -1
248 
250 
267 
281 err_t rtc17_init ( rtc17_t *ctx, rtc17_cfg_t *cfg );
282 
295 err_t rtc17_default_cfg ( rtc17_t *ctx );
296 
310 err_t rtc17_write_register ( rtc17_t *ctx, uint8_t reg, uint8_t data_in );
311 
326 err_t rtc17_write_multiple_registers ( rtc17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
327 
340 err_t rtc17_read_register ( rtc17_t *ctx, uint8_t reg, uint8_t *data_out );
341 
356 err_t rtc17_read_multiple_registers ( rtc17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
357 
366 uint8_t rtc17_get_int_pin ( rtc17_t *ctx );
367 
379 
392 err_t rtc17_set_time ( rtc17_t *ctx, rtc17_time_t *time );
393 
406 err_t rtc17_read_time ( rtc17_t *ctx, rtc17_time_t *time );
407 
420 err_t rtc17_set_date ( rtc17_t *ctx, rtc17_date_t *date );
421 
434 err_t rtc17_read_date ( rtc17_t *ctx, rtc17_date_t *date );
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // RTC17_H
440  // rtc17
442 
443 // ------------------------------------------------------------------------ END
rtc17_date_t::day_of_week
uint8_t day_of_week
Definition: rtc17.h:233
rtc17_date_t::day
uint8_t day
Definition: rtc17.h:234
rtc17_time_t::second
uint8_t second
Definition: rtc17.h:220
rtc17_read_time
err_t rtc17_read_time(rtc17_t *ctx, rtc17_time_t *time)
RTC 17 read time function.
rtc17_return_value_t
rtc17_return_value_t
RTC 17 Click return value data.
Definition: rtc17.h:245
rtc17_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc17.h:206
RTC17_OK
@ RTC17_OK
Definition: rtc17.h:246
rtc17_cfg_t::sda
pin_name_t sda
Definition: rtc17.h:204
rtc17_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc17.h:209
rtc17_date_t::month
uint8_t month
Definition: rtc17.h:235
rtc17_set_time
err_t rtc17_set_time(rtc17_t *ctx, rtc17_time_t *time)
RTC 17 set time function.
RTC17_ERROR
@ RTC17_ERROR
Definition: rtc17.h:247
rtc17_cfg_t::scl
pin_name_t scl
Definition: rtc17.h:203
rtc17_set_date
err_t rtc17_set_date(rtc17_t *ctx, rtc17_date_t *date)
RTC 17 set date function.
rtc17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc17.h:208
rtc17_clear_interrupts
err_t rtc17_clear_interrupts(rtc17_t *ctx)
RTC 17 clear interrupts function.
rtc17_t::i2c
i2c_master_t i2c
Definition: rtc17.h:190
rtc17_read_register
err_t rtc17_read_register(rtc17_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 17 read register function.
rtc17_t::int_pin
digital_in_t int_pin
Definition: rtc17.h:187
rtc17_get_int_pin
uint8_t rtc17_get_int_pin(rtc17_t *ctx)
RTC 17 get int pin function.
rtc17_t
RTC 17 Click context object.
Definition: rtc17.h:185
rtc17_time_t
RTC 17 Click time object.
Definition: rtc17.h:219
rtc17_date_t::year
uint8_t year
Definition: rtc17.h:236
rtc17_cfg_t
RTC 17 Click configuration object.
Definition: rtc17.h:202
rtc17_time_t::minute
uint8_t minute
Definition: rtc17.h:221
rtc17_init
err_t rtc17_init(rtc17_t *ctx, rtc17_cfg_t *cfg)
RTC 17 initialization function.
rtc17_default_cfg
err_t rtc17_default_cfg(rtc17_t *ctx)
RTC 17 default configuration function.
rtc17_time_t::hour
uint8_t hour
Definition: rtc17.h:222
rtc17_date_t
RTC 17 Click date object.
Definition: rtc17.h:232
rtc17_write_multiple_registers
err_t rtc17_write_multiple_registers(rtc17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
RTC 17 write multiple registers function.
rtc17_cfg_setup
void rtc17_cfg_setup(rtc17_cfg_t *cfg)
RTC 17 configuration object setup function.
rtc17_read_date
err_t rtc17_read_date(rtc17_t *ctx, rtc17_date_t *date)
RTC 17 read date function.
rtc17_write_register
err_t rtc17_write_register(rtc17_t *ctx, uint8_t reg, uint8_t data_in)
RTC 17 write register function.
rtc17_t::slave_address
uint8_t slave_address
Definition: rtc17.h:193
rtc17_read_multiple_registers
err_t rtc17_read_multiple_registers(rtc17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
RTC 17 read multiple registers function.