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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define RTC20_REG_HUNDREDTHS 0x00
74#define RTC20_REG_SECONDS 0x01
75#define RTC20_REG_MINUTES 0x02
76#define RTC20_REG_HOURS 0x03
77#define RTC20_REG_DATE 0x04
78#define RTC20_REG_MONTH 0x05
79#define RTC20_REG_YEAR 0x06
80#define RTC20_REG_DAY 0x07
81#define RTC20_REG_HUNDREDTHS_ALARM 0x08
82#define RTC20_REG_SECONDS_ALARM 0x09
83#define RTC20_REG_MINUTES_ALARM 0x0A
84#define RTC20_REG_HOURS_ALARM 0x0B
85#define RTC20_REG_DATE_ALARM 0x0C
86#define RTC20_REG_MONTH_ALARM 0x0D
87#define RTC20_REG_WEEKDAYS_ALARM 0x0E
88#define RTC20_REG_STATUS 0x0F
89#define RTC20_REG_CONTROL1 0x10
90#define RTC20_REG_CONTROL2 0x11
91#define RTC20_REG_OSC_CONTROL 0x1C
92#define RTC20_REG_OSC_STATUS 0x1D
93
94 // rtc20_reg
95
110#define RTC20_SET_CTRL_STOP_DISABLE 0x00
111#define RTC20_SET_CTRL_STOP_ENABLE 0x01
112#define RTC20_SET_CTRL_HOURS_OP_MODE_24h 0x00
113#define RTC20_SET_CTRL_HOURS_OP_MODE_12h 0x01
114#define RTC20_SET_CTRL_OUTB_nIRQ2 0x00
115#define RTC20_SET_CTRL_OUTB_LKO2 0x01
116#define RTC20_SET_CTRL_OUT_nIRQ 0x00
117#define RTC20_SET_CTRL_OUT_SQWE 0x01
118#define RTC20_SET_CTRL_ARST_NO_CLR 0x00
119#define RTC20_SET_CTRL_ARST_CLR 0x01
120#define RTC20_SET_CTRL_WRTC_DISABLE 0x00
121#define RTC20_SET_CTRL_WRTC_ENABLE 0x01
122#define RTC20_SET_CTRL_OUT2S_nIRQ_ENABLE 0x00
123#define RTC20_SET_CTRL_OUT2S_SQW_ENABLE 0x01
124#define RTC20_SET_CTRL_OUT2S_nAIRQ_ENABLE 0x03
125#define RTC20_SET_CTRL_OUT2S_TIRQ_ENABLE 0x04
126#define RTC20_SET_CTRL_OUT2S_nTIRQ_ENABLE 0x05
127#define RTC20_SET_CTRL_OUT2S_OUTB_ENABLE 0x07
128#define RTC20_SET_CTRL_OUT1S_nIRQ_ENABLE 0x00
129#define RTC20_SET_CTRL_OUT1S_SQW_ENABLE 0x01
130#define RTC20_SET_CTRL_OUT1S_SQW_nIRQ_ENABLE 0x02
131#define RTC20_SET_CTRL_OUT1S_nAIRQ_ENABLE 0x03
132
137#define RTC20_DW_SUNDAY 0
138#define RTC20_DW_MONDAY 1
139#define RTC20_DW_TUESDAY 2
140#define RTC20_DW_WEDNESDAY 3
141#define RTC20_DW_THURSDAY 4
142#define RTC20_DW_FRIDAY 5
143#define RTC20_DW_SATURDAY 6
144
145
146
152#define RTC20_DEVICE_ADDRESS 0x69
153
154 // rtc20_set
155
170#define RTC20_MAP_MIKROBUS( cfg, mikrobus ) \
171 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
172 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
173 cfg.ir2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
174 cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_RST ); \
175 cfg.ext = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
176 cfg.ir1 = MIKROBUS( mikrobus, MIKROBUS_INT )
177
178 // rtc20_map
179 // rtc20
180
185typedef struct
186{
187 // Output pins
188 digital_out_t wdi;
189 digital_out_t ext;
191 // Input pins
192 digital_in_t ir2;
193 digital_in_t ir1;
195 // Modules
196 i2c_master_t i2c;
198 // I2C slave address
201} rtc20_t;
202
207typedef struct
208{
209 pin_name_t scl;
210 pin_name_t sda;
212 pin_name_t ir2;
213 pin_name_t wdi;
214 pin_name_t ext;
215 pin_name_t ir1;
217 uint32_t i2c_speed;
218 uint8_t i2c_address;
221
227typedef struct
228{
229 uint8_t hundredths;
230 uint8_t second;
231 uint8_t minute;
232 uint8_t hour;
233
235
241typedef struct
242{
243 uint8_t day_of_week;
244 uint8_t day;
245 uint8_t month;
246 uint8_t year;
247
249
254typedef struct
255{
256 uint8_t stop;
258 uint8_t outb;
259 uint8_t out;
260 uint8_t arst;
261 uint8_t wrtc;
262 uint8_t out2s;
263 uint8_t out1s;
264
266
271typedef enum
272{
274 RTC20_ERROR = -1
275
277
294
308err_t rtc20_init ( rtc20_t *ctx, rtc20_cfg_t *cfg );
309
324err_t rtc20_generic_write ( rtc20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
325
340err_t rtc20_generic_read ( rtc20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
341
358void rtc20_wdi_pin_state ( rtc20_t *ctx, uint8_t pin_state );
359
376void rtc20_ext_pin_state ( rtc20_t *ctx, uint8_t pin_state );
377
390err_t rtc20_set_time ( rtc20_t *ctx, rtc20_time_t rtc_time );
391
404err_t rtc20_get_time ( rtc20_t *ctx, rtc20_time_t *rtc_time );
405
418err_t rtc20_set_date ( rtc20_t *ctx, rtc20_date_t rtc_date );
419
432err_t rtc20_get_date ( rtc20_t *ctx, rtc20_date_t *rtc_date );
433
447err_t rtc20_set_alarm ( rtc20_t *ctx, rtc20_time_t rtc_alarm_time, rtc20_date_t rtc_alarm_date );
448
462err_t rtc20_get_alarm ( rtc20_t *ctx, rtc20_time_t *rtc_alarm_time, rtc20_date_t *rtc_alarm_date );
463
476err_t rtc20_get_status ( rtc20_t *ctx, uint8_t *status );
477
491
505
519uint8_t rtc20_get_ir1_pin ( rtc20_t *ctx );
520
536uint8_t rtc20_get_ir2_pin ( rtc20_t *ctx );
537
538#ifdef __cplusplus
539}
540#endif
541#endif // RTC20_H
542
543 // rtc20
544
545// ------------------------------------------------------------------------ END
err_t rtc20_get_ctrl_signals(rtc20_t *ctx, rtc20_ctrl_signals_t *ctrl_signals)
RTC 20 get ctrl signals function.
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.
void rtc20_wdi_pin_state(rtc20_t *ctx, uint8_t pin_state)
RTC 20 I2C reading function.
err_t rtc20_set_time(rtc20_t *ctx, rtc20_time_t rtc_time)
RTC 20 set time function.
err_t rtc20_get_date(rtc20_t *ctx, rtc20_date_t *rtc_date)
RTC 20 get date function.
err_t rtc20_set_ctrl_signals(rtc20_t *ctx, rtc20_ctrl_signals_t ctrl_signals)
RTC 20 set ctrl signals function.
err_t rtc20_generic_read(rtc20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 20 I2C reading function.
err_t rtc20_generic_write(rtc20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 20 I2C writing function.
uint8_t rtc20_get_ir2_pin(rtc20_t *ctx)
RTC 20 get IR2 pin function.
err_t rtc20_init(rtc20_t *ctx, rtc20_cfg_t *cfg)
RTC 20 initialization function.
void rtc20_ext_pin_state(rtc20_t *ctx, uint8_t pin_state)
RTC 20 I2C reading function.
void rtc20_cfg_setup(rtc20_cfg_t *cfg)
RTC 20 configuration object setup function.
uint8_t rtc20_get_ir1_pin(rtc20_t *ctx)
RTC 20 get IR1 pin function.
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.
err_t rtc20_set_date(rtc20_t *ctx, rtc20_date_t rtc_date)
RTC 20 set date function.
err_t rtc20_get_status(rtc20_t *ctx, uint8_t *status)
RTC 20 get status function.
err_t rtc20_get_time(rtc20_t *ctx, rtc20_time_t *rtc_time)
RTC 20 get time function.
rtc20_return_value_t
RTC 20 Click return value data.
Definition rtc20.h:272
@ RTC20_OK
Definition rtc20.h:273
@ RTC20_ERROR
Definition rtc20.h:274
RTC 20 Click configuration object.
Definition rtc20.h:208
pin_name_t ir2
Definition rtc20.h:212
pin_name_t wdi
Definition rtc20.h:213
uint32_t i2c_speed
Definition rtc20.h:217
pin_name_t scl
Definition rtc20.h:209
pin_name_t ext
Definition rtc20.h:214
pin_name_t ir1
Definition rtc20.h:215
pin_name_t sda
Definition rtc20.h:210
uint8_t i2c_address
Definition rtc20.h:218
RTC 20 Click control signals object.
Definition rtc20.h:255
uint8_t out2s
Definition rtc20.h:262
uint8_t stop
Definition rtc20.h:256
uint8_t out
Definition rtc20.h:259
uint8_t wrtc
Definition rtc20.h:261
uint8_t out1s
Definition rtc20.h:263
uint8_t arst
Definition rtc20.h:260
uint8_t outb
Definition rtc20.h:258
uint8_t hours_op_mode
Definition rtc20.h:257
RTC 20 Click date object.
Definition rtc20.h:242
uint8_t month
Definition rtc20.h:245
uint8_t day
Definition rtc20.h:244
uint8_t year
Definition rtc20.h:246
uint8_t day_of_week
Definition rtc20.h:243
RTC 20 Click context object.
Definition rtc20.h:186
digital_in_t ir2
Definition rtc20.h:192
digital_in_t ir1
Definition rtc20.h:193
i2c_master_t i2c
Definition rtc20.h:196
digital_out_t ext
Definition rtc20.h:189
uint8_t slave_address
Definition rtc20.h:199
digital_out_t wdi
Definition rtc20.h:188
RTC 20 Click time object.
Definition rtc20.h:228
uint8_t second
Definition rtc20.h:230
uint8_t minute
Definition rtc20.h:231
uint8_t hundredths
Definition rtc20.h:229
uint8_t hour
Definition rtc20.h:232