rtc13 2.0.0.0
rtc13.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 RTC13_H
29#define RTC13_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38#include "spi_specifics.h"
39
60#define RTC13_REG_CTRL1_ADDR 0x00
61#define RTC13_REG_CTRL2_ADDR 0x01
62#define RTC13_REG_TIME_SECONDS 0x02
63#define RTC13_REG_TIME_MINUTES 0x03
64#define RTC13_REG_TIME_HOUR 0x04
65#define RTC13_REG_DATE_DAY 0x05
66#define RTC13_REG_DATE_WEEKDAYS 0x06
67#define RTC13_REG_DATE_MONTHS 0x07
68#define RTC13_REG_DATE_YEARS 0x08
69#define RTC13_REG_ALARM_MINUTE 0x09
70#define RTC13_REG_ALARM_HOUR 0x0A
71#define RTC13_REG_ALARM_DAY 0x0B
72#define RTC13_REG_ALARM_WEEKDAY 0x0C
73#define RTC13_REG_OFFSET_ADDR 0x0D
74#define RTC13_REG_TIMER_CLKOUT_ADDR 0x0E
75#define RTC13_REG_COUNTDOWN_TIMER_ADDR 0x0F
76 // rtc13_reg
78
93#define RTC13_SOFT_RESET 0x58
94#define RTC13_BLOCK_CLKOUT_DISABLE 0x00
95#define RTC13_BLOCK_CLKOUT_ENABLE 0x01
96
105#define RTC13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
106#define RTC13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
107 // rtc13_set
109
124#define RTC13_MAP_MIKROBUS( cfg, mikrobus ) \
125 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
126 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
127 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
128 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
129 cfg.cle = MIKROBUS( mikrobus, MIKROBUS_RST ); \
130 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
131 // rtc13_map // rtc13
134
139typedef struct
140{
141 uint8_t hours;
142 uint8_t min;
143 uint8_t sec;
144
146
151typedef struct
152{
153 uint8_t year;
154 uint8_t month;
155 uint8_t day;
156 uint8_t weekday;
157
159
164typedef struct
165{
166 uint8_t min;
167 uint8_t hours;
168 uint8_t day;
169 uint8_t weekday;
170
172
177typedef struct
178{
179 // Output pins
180 digital_out_t cle;
182 // Input pins
183 digital_in_t int_pin;
185 // Modules
186 spi_master_t spi;
188 pin_name_t chip_select;
190} rtc13_t;
191
196typedef struct
197{
198 // Communication gpio pins
199 pin_name_t miso;
200 pin_name_t mosi;
201 pin_name_t sck;
202 pin_name_t cs;
204 // Additional gpio pins
205 pin_name_t cle;
206 pin_name_t int_pin;
208 // static variable
209 uint32_t spi_speed;
210 spi_master_mode_t spi_mode;
211 spi_master_chip_select_polarity_t cs_polarity;
214
219typedef enum
220{
222 RTC13_ERROR = -1
223
225
244
261err_t rtc13_init ( rtc13_t *ctx, rtc13_cfg_t *cfg );
262
279
295
313err_t rtc13_block_clkout ( rtc13_t *ctx, uint8_t en_clkout );
314
332err_t rtc13_generic_write ( rtc13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
333
351err_t rtc13_generic_read ( rtc13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
352
369
386err_t rtc13_get_time ( rtc13_t *ctx, rtc13_time_t *rtc_time );
387
404err_t rtc13_set_time ( rtc13_t *ctx, rtc13_time_t rtc_time );
405
422err_t rtc13_get_date ( rtc13_t *ctx, rtc13_date_t *rtc_date );
423
440err_t rtc13_set_date ( rtc13_t *ctx, rtc13_date_t rtc_date );
441
458err_t rtc13_get_alarm ( rtc13_t *ctx, rtc13_alarm_t *rtc_alarm );
459
476err_t rtc13_set_alarm ( rtc13_t *ctx, rtc13_alarm_t rtc_alarm );
477
478#ifdef __cplusplus
479}
480#endif
481#endif // RTC13_H
482 // rtc13
484
485// ------------------------------------------------------------------------ END
uint8_t rtc13_get_interrupt(rtc13_t *ctx)
RTC 13 get interrupt function.
err_t rtc13_init(rtc13_t *ctx, rtc13_cfg_t *cfg)
RTC 13 initialization function.
err_t rtc13_default_cfg(rtc13_t *ctx)
RTC 13 default configuration function.
err_t rtc13_block_clkout(rtc13_t *ctx, uint8_t en_clkout)
RTC 13 block CLKOUT function.
void rtc13_cfg_setup(rtc13_cfg_t *cfg)
RTC 13 configuration object setup function.
err_t rtc13_soft_reset(rtc13_t *ctx)
RTC 13 soft reset function.
err_t rtc13_get_time(rtc13_t *ctx, rtc13_time_t *rtc_time)
RTC 13 get time function.
err_t rtc13_generic_read(rtc13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 13 data reading function.
err_t rtc13_set_date(rtc13_t *ctx, rtc13_date_t rtc_date)
RTC 13 set date function.
err_t rtc13_set_time(rtc13_t *ctx, rtc13_time_t rtc_time)
RTC 13 set time function.
err_t rtc13_get_date(rtc13_t *ctx, rtc13_date_t *rtc_date)
RTC 13 get date function.
err_t rtc13_get_alarm(rtc13_t *ctx, rtc13_alarm_t *rtc_alarm)
RTC 13 get alarm function.
err_t rtc13_set_alarm(rtc13_t *ctx, rtc13_alarm_t rtc_alarm)
RTC 13 set alarm function.
err_t rtc13_generic_write(rtc13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 13 data writing function.
rtc13_return_value_t
RTC 13 Click return value data.
Definition: rtc13.h:220
@ RTC13_ERROR
Definition: rtc13.h:222
@ RTC13_OK
Definition: rtc13.h:221
This file contains SPI specific macros, functions, etc.
RTC 13 Click alarm object.
Definition: rtc13.h:165
uint8_t hours
Definition: rtc13.h:167
uint8_t weekday
Definition: rtc13.h:169
uint8_t day
Definition: rtc13.h:168
uint8_t min
Definition: rtc13.h:166
RTC 13 Click configuration object.
Definition: rtc13.h:197
pin_name_t cle
Definition: rtc13.h:205
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc13.h:211
pin_name_t sck
Definition: rtc13.h:201
spi_master_mode_t spi_mode
Definition: rtc13.h:210
pin_name_t mosi
Definition: rtc13.h:200
uint32_t spi_speed
Definition: rtc13.h:209
pin_name_t int_pin
Definition: rtc13.h:206
pin_name_t miso
Definition: rtc13.h:199
pin_name_t cs
Definition: rtc13.h:202
RTC 13 Click date object.
Definition: rtc13.h:152
uint8_t month
Definition: rtc13.h:154
uint8_t weekday
Definition: rtc13.h:156
uint8_t day
Definition: rtc13.h:155
uint8_t year
Definition: rtc13.h:153
RTC 13 Click context object.
Definition: rtc13.h:178
digital_out_t cle
Definition: rtc13.h:180
spi_master_t spi
Definition: rtc13.h:186
digital_in_t int_pin
Definition: rtc13.h:183
pin_name_t chip_select
Definition: rtc13.h:188
RTC 13 Click time object.
Definition: rtc13.h:140
uint8_t hours
Definition: rtc13.h:141
uint8_t min
Definition: rtc13.h:142
uint8_t sec
Definition: rtc13.h:143