rtc21  2.1.0.0
rtc21.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 RTC21_H
29 #define RTC21_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 RTC21_REG_SECOND 0x00
60 #define RTC21_REG_MINUTE 0x01
61 #define RTC21_REG_HOUR 0x02
62 #define RTC21_REG_DAY_OF_WEEK 0x03
63 #define RTC21_REG_DATE 0x04
64 #define RTC21_REG_MONTH 0x05
65 #define RTC21_REG_YEAR 0x06
66 #define RTC21_REG_CONTROL 0x07
67 #define RTC21_REG_RAM_BOTTOM 0x08
68 #define RTC21_REG_RAM_TOP 0x3F
69  // rtc21_reg
71 
86 #define RTC21_MONDAY 0x01
87 #define RTC21_TUESDAY 0x02
88 #define RTC21_WEDNESDAY 0x03
89 #define RTC21_THURSDAY 0x04
90 #define RTC21_FRIDAY 0x05
91 #define RTC21_SATURDAY 0x06
92 #define RTC21_SUNDAY 0x07
93 
99 #define RTC21_DEVICE_ADDRESS 0x68
100  // rtc21_set
102 
117 #define RTC21_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
119  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
120  cfg.ft = MIKROBUS( mikrobus, MIKROBUS_INT )
121  // rtc21_map // rtc21
124 
129 typedef struct
130 {
131  // Input pins
132  digital_in_t ft;
134  // Modules
135  i2c_master_t i2c;
137  // I2C slave address
138  uint8_t slave_address;
140 } rtc21_t;
141 
146 typedef struct
147 {
148  pin_name_t scl;
149  pin_name_t sda;
151  pin_name_t ft;
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
156 } rtc21_cfg_t;
157 
163 typedef struct
164 {
165  uint8_t second;
166  uint8_t minute;
167  uint8_t hour;
168 
169 } rtc21_time_t;
170 
176 typedef struct
177 {
178  uint8_t day_of_week;
179  uint8_t day;
180  uint8_t month;
181  uint8_t year;
182 
183 } rtc21_date_t;
184 
189 typedef enum
190 {
191  RTC21_OK = 0,
192  RTC21_ERROR = -1
193 
195 
212 
226 err_t rtc21_init ( rtc21_t *ctx, rtc21_cfg_t *cfg );
227 
242 err_t rtc21_generic_write ( rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
243 
258 err_t rtc21_generic_read ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
259 
272 err_t rtc21_write_register ( rtc21_t *ctx, uint8_t reg, uint8_t data_in );
273 
286 err_t rtc21_read_register ( rtc21_t *ctx, uint8_t reg, uint8_t *data_out );
287 
296 uint8_t rtc21_get_ft_pin ( rtc21_t *ctx );
297 
310 err_t rtc21_set_time ( rtc21_t *ctx, rtc21_time_t *time );
311 
324 err_t rtc21_read_time ( rtc21_t *ctx, rtc21_time_t *time );
325 
338 err_t rtc21_set_date ( rtc21_t *ctx, rtc21_date_t *date );
339 
352 err_t rtc21_read_date ( rtc21_t *ctx, rtc21_date_t *date );
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // RTC21_H
358  // rtc21
360 
361 // ------------------------------------------------------------------------ END
rtc21_set_date
err_t rtc21_set_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 set date function.
rtc21_read_register
err_t rtc21_read_register(rtc21_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 21 read register function.
rtc21_cfg_setup
void rtc21_cfg_setup(rtc21_cfg_t *cfg)
RTC 21 configuration object setup function.
rtc21_date_t
RTC 21 Click date object.
Definition: rtc21.h:177
rtc21_time_t::hour
uint8_t hour
Definition: rtc21.h:167
rtc21_set_time
err_t rtc21_set_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 set time function.
rtc21_time_t
RTC 21 Click time object.
Definition: rtc21.h:164
rtc21_cfg_t::ft
pin_name_t ft
Definition: rtc21.h:151
RTC21_ERROR
@ RTC21_ERROR
Definition: rtc21.h:192
rtc21_time_t::minute
uint8_t minute
Definition: rtc21.h:166
rtc21_t::slave_address
uint8_t slave_address
Definition: rtc21.h:138
rtc21_time_t::second
uint8_t second
Definition: rtc21.h:165
rtc21_return_value_t
rtc21_return_value_t
RTC 21 Click return value data.
Definition: rtc21.h:190
RTC21_OK
@ RTC21_OK
Definition: rtc21.h:191
rtc21_date_t::day_of_week
uint8_t day_of_week
Definition: rtc21.h:178
rtc21_get_ft_pin
uint8_t rtc21_get_ft_pin(rtc21_t *ctx)
RTC 21 get ft pin function.
rtc21_read_date
err_t rtc21_read_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 read date function.
rtc21_cfg_t
RTC 21 Click configuration object.
Definition: rtc21.h:147
rtc21_t
RTC 21 Click context object.
Definition: rtc21.h:130
rtc21_cfg_t::sda
pin_name_t sda
Definition: rtc21.h:149
rtc21_date_t::month
uint8_t month
Definition: rtc21.h:180
rtc21_t::ft
digital_in_t ft
Definition: rtc21.h:132
rtc21_generic_write
err_t rtc21_generic_write(rtc21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 21 I2C writing function.
rtc21_init
err_t rtc21_init(rtc21_t *ctx, rtc21_cfg_t *cfg)
RTC 21 initialization function.
rtc21_t::i2c
i2c_master_t i2c
Definition: rtc21.h:135
rtc21_write_register
err_t rtc21_write_register(rtc21_t *ctx, uint8_t reg, uint8_t data_in)
RTC 21 write register function.
rtc21_read_time
err_t rtc21_read_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 read time function.
rtc21_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc21.h:154
rtc21_generic_read
err_t rtc21_generic_read(rtc21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 21 I2C reading function.
rtc21_cfg_t::scl
pin_name_t scl
Definition: rtc21.h:148
rtc21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc21.h:153
rtc21_date_t::year
uint8_t year
Definition: rtc21.h:181
rtc21_date_t::day
uint8_t day
Definition: rtc21.h:179