rtc20  2.1.0.0
rtc20.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 RTC20_H
29 #define RTC20_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 RTC20_REG_HUNDREDTHS 0x00
70 #define RTC20_REG_SECONDS 0x01
71 #define RTC20_REG_MINUTES 0x02
72 #define RTC20_REG_HOURS 0x03
73 #define RTC20_REG_DATE 0x04
74 #define RTC20_REG_MONTH 0x05
75 #define RTC20_REG_YEAR 0x06
76 #define RTC20_REG_DAY 0x07
77 #define RTC20_REG_HUNDREDTHS_ALARM 0x08
78 #define RTC20_REG_SECONDS_ALARM 0x09
79 #define RTC20_REG_MINUTES_ALARM 0x0A
80 #define RTC20_REG_HOURS_ALARM 0x0B
81 #define RTC20_REG_DATE_ALARM 0x0C
82 #define RTC20_REG_MONTH_ALARM 0x0D
83 #define RTC20_REG_WEEKDAYS_ALARM 0x0E
84 #define RTC20_REG_STATUS 0x0F
85 #define RTC20_REG_CONTROL1 0x10
86 #define RTC20_REG_CONTROL2 0x11
87 #define RTC20_REG_OSC_CONTROL 0x1C
88 #define RTC20_REG_OSC_STATUS 0x1D
89  // rtc20_reg
91 
106 #define RTC20_SET_CTRL_STOP_DISABLE 0x00
107 #define RTC20_SET_CTRL_STOP_ENABLE 0x01
108 #define RTC20_SET_CTRL_HOURS_OP_MODE_24h 0x00
109 #define RTC20_SET_CTRL_HOURS_OP_MODE_12h 0x01
110 #define RTC20_SET_CTRL_OUTB_nIRQ2 0x00
111 #define RTC20_SET_CTRL_OUTB_LKO2 0x01
112 #define RTC20_SET_CTRL_OUT_nIRQ 0x00
113 #define RTC20_SET_CTRL_OUT_SQWE 0x01
114 #define RTC20_SET_CTRL_ARST_NO_CLR 0x00
115 #define RTC20_SET_CTRL_ARST_CLR 0x01
116 #define RTC20_SET_CTRL_WRTC_DISABLE 0x00
117 #define RTC20_SET_CTRL_WRTC_ENABLE 0x01
118 #define RTC20_SET_CTRL_OUT2S_nIRQ_ENABLE 0x00
119 #define RTC20_SET_CTRL_OUT2S_SQW_ENABLE 0x01
120 #define RTC20_SET_CTRL_OUT2S_nAIRQ_ENABLE 0x03
121 #define RTC20_SET_CTRL_OUT2S_TIRQ_ENABLE 0x04
122 #define RTC20_SET_CTRL_OUT2S_nTIRQ_ENABLE 0x05
123 #define RTC20_SET_CTRL_OUT2S_OUTB_ENABLE 0x07
124 #define RTC20_SET_CTRL_OUT1S_nIRQ_ENABLE 0x00
125 #define RTC20_SET_CTRL_OUT1S_SQW_ENABLE 0x01
126 #define RTC20_SET_CTRL_OUT1S_SQW_nIRQ_ENABLE 0x02
127 #define RTC20_SET_CTRL_OUT1S_nAIRQ_ENABLE 0x03
128 
133 #define RTC20_DW_SUNDAY 0
134 #define RTC20_DW_MONDAY 1
135 #define RTC20_DW_TUESDAY 2
136 #define RTC20_DW_WEDNESDAY 3
137 #define RTC20_DW_THURSDAY 4
138 #define RTC20_DW_FRIDAY 5
139 #define RTC20_DW_SATURDAY 6
140 
141 
142 
148 #define RTC20_DEVICE_ADDRESS 0x69
149  // rtc20_set
151 
166 #define RTC20_MAP_MIKROBUS( cfg, mikrobus ) \
167  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
168  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
169  cfg.ir2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
170  cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_RST ); \
171  cfg.ext = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
172  cfg.ir1 = MIKROBUS( mikrobus, MIKROBUS_INT )
173  // rtc20_map // rtc20
176 
181 typedef struct
182 {
183  // Output pins
184  digital_out_t wdi;
185  digital_out_t ext;
187  // Input pins
188  digital_in_t ir2;
189  digital_in_t ir1;
191  // Modules
192  i2c_master_t i2c;
194  // I2C slave address
195  uint8_t slave_address;
197 } rtc20_t;
198 
203 typedef struct
204 {
205  pin_name_t scl;
206  pin_name_t sda;
208  pin_name_t ir2;
209  pin_name_t wdi;
210  pin_name_t ext;
211  pin_name_t ir1;
213  uint32_t i2c_speed;
214  uint8_t i2c_address;
216 } rtc20_cfg_t;
217 
223 typedef struct
224 {
225  uint8_t hundredths;
226  uint8_t second;
227  uint8_t minute;
228  uint8_t hour;
229 
230 } rtc20_time_t;
231 
237 typedef struct
238 {
239  uint8_t day_of_week;
240  uint8_t day;
241  uint8_t month;
242  uint8_t year;
243 
244 } rtc20_date_t;
245 
250 typedef struct
251 {
252  uint8_t stop;
253  uint8_t hours_op_mode;
254  uint8_t outb;
255  uint8_t out;
256  uint8_t arst;
257  uint8_t wrtc;
258  uint8_t out2s;
259  uint8_t out1s;
260 
262 
267 typedef enum
268 {
269  RTC20_OK = 0,
270  RTC20_ERROR = -1
271 
273 
290 
304 err_t rtc20_init ( rtc20_t *ctx, rtc20_cfg_t *cfg );
305 
320 err_t rtc20_generic_write ( rtc20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
321 
336 err_t rtc20_generic_read ( rtc20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
337 
354 void rtc20_wdi_pin_state ( rtc20_t *ctx, uint8_t pin_state );
355 
372 void rtc20_ext_pin_state ( rtc20_t *ctx, uint8_t pin_state );
373 
386 err_t rtc20_set_time ( rtc20_t *ctx, rtc20_time_t rtc_time );
387 
400 err_t rtc20_get_time ( rtc20_t *ctx, rtc20_time_t *rtc_time );
401 
414 err_t rtc20_set_date ( rtc20_t *ctx, rtc20_date_t rtc_date );
415 
428 err_t rtc20_get_date ( rtc20_t *ctx, rtc20_date_t *rtc_date );
429 
443 err_t rtc20_set_alarm ( rtc20_t *ctx, rtc20_time_t rtc_alarm_time, rtc20_date_t rtc_alarm_date );
444 
458 err_t rtc20_get_alarm ( rtc20_t *ctx, rtc20_time_t *rtc_alarm_time, rtc20_date_t *rtc_alarm_date );
459 
472 err_t rtc20_get_status ( rtc20_t *ctx, uint8_t *status );
473 
487 
501 
515 uint8_t rtc20_get_ir1_pin ( rtc20_t *ctx );
516 
532 uint8_t rtc20_get_ir2_pin ( rtc20_t *ctx );
533 
534 #ifdef __cplusplus
535 }
536 #endif
537 #endif // RTC20_H
538  // rtc20
540 
541 // ------------------------------------------------------------------------ END
rtc20_ctrl_signals_t::arst
uint8_t arst
Definition: rtc20.h:256
rtc20_time_t::second
uint8_t second
Definition: rtc20.h:226
rtc20_cfg_t::wdi
pin_name_t wdi
Definition: rtc20.h:209
rtc20_cfg_t::ir1
pin_name_t ir1
Definition: rtc20.h:211
rtc20_get_ir2_pin
uint8_t rtc20_get_ir2_pin(rtc20_t *ctx)
RTC 20 get IR2 pin function.
rtc20_get_time
err_t rtc20_get_time(rtc20_t *ctx, rtc20_time_t *rtc_time)
RTC 20 get time function.
rtc20_date_t::month
uint8_t month
Definition: rtc20.h:241
rtc20_cfg_t::scl
pin_name_t scl
Definition: rtc20.h:205
rtc20_get_alarm
err_t rtc20_get_alarm(rtc20_t *ctx, rtc20_time_t *rtc_alarm_time, rtc20_date_t *rtc_alarm_date)
RTC 20 get alarm function.
rtc20_get_date
err_t rtc20_get_date(rtc20_t *ctx, rtc20_date_t *rtc_date)
RTC 20 get date function.
rtc20_set_time
err_t rtc20_set_time(rtc20_t *ctx, rtc20_time_t rtc_time)
RTC 20 set time function.
rtc20_date_t::day
uint8_t day
Definition: rtc20.h:240
rtc20_set_date
err_t rtc20_set_date(rtc20_t *ctx, rtc20_date_t rtc_date)
RTC 20 set date function.
rtc20_set_ctrl_signals
err_t rtc20_set_ctrl_signals(rtc20_t *ctx, rtc20_ctrl_signals_t ctrl_signals)
RTC 20 set ctrl signals function.
rtc20_ctrl_signals_t::wrtc
uint8_t wrtc
Definition: rtc20.h:257
rtc20_date_t
RTC 20 Click date object.
Definition: rtc20.h:238
rtc20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc20.h:213
rtc20_ctrl_signals_t::outb
uint8_t outb
Definition: rtc20.h:254
rtc20_set_alarm
err_t rtc20_set_alarm(rtc20_t *ctx, rtc20_time_t rtc_alarm_time, rtc20_date_t rtc_alarm_date)
RTC 20 set alarm function.
rtc20_time_t
RTC 20 Click time object.
Definition: rtc20.h:224
rtc20_generic_read
err_t rtc20_generic_read(rtc20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 20 I2C reading function.
rtc20_get_ir1_pin
uint8_t rtc20_get_ir1_pin(rtc20_t *ctx)
RTC 20 get IR1 pin function.
rtc20_return_value_t
rtc20_return_value_t
RTC 20 Click return value data.
Definition: rtc20.h:268
rtc20_get_ctrl_signals
err_t rtc20_get_ctrl_signals(rtc20_t *ctx, rtc20_ctrl_signals_t *ctrl_signals)
RTC 20 get ctrl signals function.
rtc20_t::i2c
i2c_master_t i2c
Definition: rtc20.h:192
rtc20_generic_write
err_t rtc20_generic_write(rtc20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 20 I2C writing function.
rtc20_ctrl_signals_t::hours_op_mode
uint8_t hours_op_mode
Definition: rtc20.h:253
rtc20_time_t::hundredths
uint8_t hundredths
Definition: rtc20.h:225
rtc20_ctrl_signals_t
RTC 20 Click control signals object.
Definition: rtc20.h:251
rtc20_init
err_t rtc20_init(rtc20_t *ctx, rtc20_cfg_t *cfg)
RTC 20 initialization function.
rtc20_cfg_t
RTC 20 Click configuration object.
Definition: rtc20.h:204
rtc20_time_t::hour
uint8_t hour
Definition: rtc20.h:228
rtc20_date_t::year
uint8_t year
Definition: rtc20.h:242
rtc20_cfg_t::ext
pin_name_t ext
Definition: rtc20.h:210
rtc20_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc20.h:214
RTC20_OK
@ RTC20_OK
Definition: rtc20.h:269
rtc20_cfg_t::sda
pin_name_t sda
Definition: rtc20.h:206
rtc20_wdi_pin_state
void rtc20_wdi_pin_state(rtc20_t *ctx, uint8_t pin_state)
RTC 20 I2C reading function.
rtc20_ctrl_signals_t::out
uint8_t out
Definition: rtc20.h:255
rtc20_ext_pin_state
void rtc20_ext_pin_state(rtc20_t *ctx, uint8_t pin_state)
RTC 20 I2C reading function.
rtc20_ctrl_signals_t::out1s
uint8_t out1s
Definition: rtc20.h:259
rtc20_t::ext
digital_out_t ext
Definition: rtc20.h:185
rtc20_ctrl_signals_t::out2s
uint8_t out2s
Definition: rtc20.h:258
rtc20_time_t::minute
uint8_t minute
Definition: rtc20.h:227
rtc20_t
RTC 20 Click context object.
Definition: rtc20.h:182
rtc20_cfg_t::ir2
pin_name_t ir2
Definition: rtc20.h:208
rtc20_date_t::day_of_week
uint8_t day_of_week
Definition: rtc20.h:239
rtc20_t::wdi
digital_out_t wdi
Definition: rtc20.h:184
rtc20_ctrl_signals_t::stop
uint8_t stop
Definition: rtc20.h:252
rtc20_t::ir1
digital_in_t ir1
Definition: rtc20.h:189
rtc20_cfg_setup
void rtc20_cfg_setup(rtc20_cfg_t *cfg)
RTC 20 configuration object setup function.
RTC20_ERROR
@ RTC20_ERROR
Definition: rtc20.h:270
rtc20_t::ir2
digital_in_t ir2
Definition: rtc20.h:188
rtc20_get_status
err_t rtc20_get_status(rtc20_t *ctx, uint8_t *status)
RTC 20 get status function.
rtc20_t::slave_address
uint8_t slave_address
Definition: rtc20.h:195