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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define RTC20_REG_HUNDREDTHS 0x00
60 #define RTC20_REG_SECONDS 0x01
61 #define RTC20_REG_MINUTES 0x02
62 #define RTC20_REG_HOURS 0x03
63 #define RTC20_REG_DATE 0x04
64 #define RTC20_REG_MONTH 0x05
65 #define RTC20_REG_YEAR 0x06
66 #define RTC20_REG_DAY 0x07
67 #define RTC20_REG_HUNDREDTHS_ALARM 0x08
68 #define RTC20_REG_SECONDS_ALARM 0x09
69 #define RTC20_REG_MINUTES_ALARM 0x0A
70 #define RTC20_REG_HOURS_ALARM 0x0B
71 #define RTC20_REG_DATE_ALARM 0x0C
72 #define RTC20_REG_MONTH_ALARM 0x0D
73 #define RTC20_REG_WEEKDAYS_ALARM 0x0E
74 #define RTC20_REG_STATUS 0x0F
75 #define RTC20_REG_CONTROL1 0x10
76 #define RTC20_REG_CONTROL2 0x11
77 #define RTC20_REG_OSC_CONTROL 0x1C
78 #define RTC20_REG_OSC_STATUS 0x1D
79  // rtc20_reg
81 
96 #define RTC20_SET_CTRL_STOP_DISABLE 0x00
97 #define RTC20_SET_CTRL_STOP_ENABLE 0x01
98 #define RTC20_SET_CTRL_HOURS_OP_MODE_24h 0x00
99 #define RTC20_SET_CTRL_HOURS_OP_MODE_12h 0x01
100 #define RTC20_SET_CTRL_OUTB_nIRQ2 0x00
101 #define RTC20_SET_CTRL_OUTB_LKO2 0x01
102 #define RTC20_SET_CTRL_OUT_nIRQ 0x00
103 #define RTC20_SET_CTRL_OUT_SQWE 0x01
104 #define RTC20_SET_CTRL_ARST_NO_CLR 0x00
105 #define RTC20_SET_CTRL_ARST_CLR 0x01
106 #define RTC20_SET_CTRL_WRTC_DISABLE 0x00
107 #define RTC20_SET_CTRL_WRTC_ENABLE 0x01
108 #define RTC20_SET_CTRL_OUT2S_nIRQ_ENABLE 0x00
109 #define RTC20_SET_CTRL_OUT2S_SQW_ENABLE 0x01
110 #define RTC20_SET_CTRL_OUT2S_nAIRQ_ENABLE 0x03
111 #define RTC20_SET_CTRL_OUT2S_TIRQ_ENABLE 0x04
112 #define RTC20_SET_CTRL_OUT2S_nTIRQ_ENABLE 0x05
113 #define RTC20_SET_CTRL_OUT2S_OUTB_ENABLE 0x07
114 #define RTC20_SET_CTRL_OUT1S_nIRQ_ENABLE 0x00
115 #define RTC20_SET_CTRL_OUT1S_SQW_ENABLE 0x01
116 #define RTC20_SET_CTRL_OUT1S_SQW_nIRQ_ENABLE 0x02
117 #define RTC20_SET_CTRL_OUT1S_nAIRQ_ENABLE 0x03
118 
123 #define RTC20_DW_SUNDAY 0
124 #define RTC20_DW_MONDAY 1
125 #define RTC20_DW_TUESDAY 2
126 #define RTC20_DW_WEDNESDAY 3
127 #define RTC20_DW_THURSDAY 4
128 #define RTC20_DW_FRIDAY 5
129 #define RTC20_DW_SATURDAY 6
130 
131 
132 
138 #define RTC20_DEVICE_ADDRESS 0x69
139  // rtc20_set
141 
156 #define RTC20_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159  cfg.ir2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
160  cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161  cfg.ext = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
162  cfg.ir1 = MIKROBUS( mikrobus, MIKROBUS_INT )
163  // rtc20_map // rtc20
166 
171 typedef struct
172 {
173  // Output pins
174  digital_out_t wdi;
175  digital_out_t ext;
177  // Input pins
178  digital_in_t ir2;
179  digital_in_t ir1;
181  // Modules
182  i2c_master_t i2c;
184  // I2C slave address
185  uint8_t slave_address;
187 } rtc20_t;
188 
193 typedef struct
194 {
195  pin_name_t scl;
196  pin_name_t sda;
198  pin_name_t ir2;
199  pin_name_t wdi;
200  pin_name_t ext;
201  pin_name_t ir1;
203  uint32_t i2c_speed;
204  uint8_t i2c_address;
206 } rtc20_cfg_t;
207 
213 typedef struct
214 {
215  uint8_t hundredths;
216  uint8_t second;
217  uint8_t minute;
218  uint8_t hour;
219 
220 } rtc20_time_t;
221 
227 typedef struct
228 {
229  uint8_t day_of_week;
230  uint8_t day;
231  uint8_t month;
232  uint8_t year;
233 
234 } rtc20_date_t;
235 
240 typedef struct
241 {
242  uint8_t stop;
243  uint8_t hours_op_mode;
244  uint8_t outb;
245  uint8_t out;
246  uint8_t arst;
247  uint8_t wrtc;
248  uint8_t out2s;
249  uint8_t out1s;
250 
252 
257 typedef enum
258 {
259  RTC20_OK = 0,
260  RTC20_ERROR = -1
261 
263 
280 
294 err_t rtc20_init ( rtc20_t *ctx, rtc20_cfg_t *cfg );
295 
310 err_t rtc20_generic_write ( rtc20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
311 
326 err_t rtc20_generic_read ( rtc20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
327 
344 void rtc20_wdi_pin_state ( rtc20_t *ctx, uint8_t pin_state );
345 
362 void rtc20_ext_pin_state ( rtc20_t *ctx, uint8_t pin_state );
363 
376 err_t rtc20_set_time ( rtc20_t *ctx, rtc20_time_t rtc_time );
377 
390 err_t rtc20_get_time ( rtc20_t *ctx, rtc20_time_t *rtc_time );
391 
404 err_t rtc20_set_date ( rtc20_t *ctx, rtc20_date_t rtc_date );
405 
418 err_t rtc20_get_date ( rtc20_t *ctx, rtc20_date_t *rtc_date );
419 
433 err_t rtc20_set_alarm ( rtc20_t *ctx, rtc20_time_t rtc_alarm_time, rtc20_date_t rtc_alarm_date );
434 
448 err_t rtc20_get_alarm ( rtc20_t *ctx, rtc20_time_t *rtc_alarm_time, rtc20_date_t *rtc_alarm_date );
449 
462 err_t rtc20_get_status ( rtc20_t *ctx, uint8_t *status );
463 
477 
491 
505 uint8_t rtc20_get_ir1_pin ( rtc20_t *ctx );
506 
522 uint8_t rtc20_get_ir2_pin ( rtc20_t *ctx );
523 
524 #ifdef __cplusplus
525 }
526 #endif
527 #endif // RTC20_H
528  // rtc20
530 
531 // ------------------------------------------------------------------------ END
rtc20_ctrl_signals_t::arst
uint8_t arst
Definition: rtc20.h:246
rtc20_time_t::second
uint8_t second
Definition: rtc20.h:216
rtc20_cfg_t::wdi
pin_name_t wdi
Definition: rtc20.h:199
rtc20_cfg_t::ir1
pin_name_t ir1
Definition: rtc20.h:201
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:231
rtc20_cfg_t::scl
pin_name_t scl
Definition: rtc20.h:195
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:230
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:247
rtc20_date_t
RTC 20 Click date object.
Definition: rtc20.h:228
rtc20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc20.h:203
rtc20_ctrl_signals_t::outb
uint8_t outb
Definition: rtc20.h:244
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:214
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:258
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:182
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:243
rtc20_time_t::hundredths
uint8_t hundredths
Definition: rtc20.h:215
rtc20_ctrl_signals_t
RTC 20 Click control signals object.
Definition: rtc20.h:241
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:194
rtc20_time_t::hour
uint8_t hour
Definition: rtc20.h:218
rtc20_date_t::year
uint8_t year
Definition: rtc20.h:232
rtc20_cfg_t::ext
pin_name_t ext
Definition: rtc20.h:200
rtc20_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc20.h:204
RTC20_OK
@ RTC20_OK
Definition: rtc20.h:259
rtc20_cfg_t::sda
pin_name_t sda
Definition: rtc20.h:196
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:245
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:249
rtc20_t::ext
digital_out_t ext
Definition: rtc20.h:175
rtc20_ctrl_signals_t::out2s
uint8_t out2s
Definition: rtc20.h:248
rtc20_time_t::minute
uint8_t minute
Definition: rtc20.h:217
rtc20_t
RTC 20 Click context object.
Definition: rtc20.h:172
rtc20_cfg_t::ir2
pin_name_t ir2
Definition: rtc20.h:198
rtc20_date_t::day_of_week
uint8_t day_of_week
Definition: rtc20.h:229
rtc20_t::wdi
digital_out_t wdi
Definition: rtc20.h:174
rtc20_ctrl_signals_t::stop
uint8_t stop
Definition: rtc20.h:242
rtc20_t::ir1
digital_in_t ir1
Definition: rtc20.h:179
rtc20_cfg_setup
void rtc20_cfg_setup(rtc20_cfg_t *cfg)
RTC 20 configuration object setup function.
RTC20_ERROR
@ RTC20_ERROR
Definition: rtc20.h:260
rtc20_t::ir2
digital_in_t ir2
Definition: rtc20.h:178
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:185