rtc5 2.0.0.0
rtc5.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef RTC5_H
36#define RTC5_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
54#define RTC5_MAP_MIKROBUS( cfg, mikrobus ) \
55 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59 cfg.mfp = MIKROBUS( mikrobus, MIKROBUS_INT );
66#define RTC5_RETVAL uint8_t
67
68#define RTC5_OK 0x00
69#define RTC5_INIT_ERROR 0xFF
76#define RTC5_REG_TIME_HUN_OF_SEC 0x00
77#define RTC5_REG_TIME_SEC 0x01
78#define RTC5_REG_TIME_MIN 0x02
79#define RTC5_REG_TIME_HOUR 0x03
80#define RTC5_REG_TIME_DAY_OF_THE_WEEK 0x04
81#define RTC5_REG_TIME_DATE_DAY 0x05
82#define RTC5_REG_TIME_DATE_MONTH 0x06
83#define RTC5_REG_TIME_DATE_YEAR 0x07
84#define RTC5_REG_CONFIG 0x08
85#define RTC5_REG_CALIBRATION 0x09
86#define RTC5_REG_ALARM_0_SEC 0x0C
87#define RTC5_REG_ALARM_0_MIN 0x0D
88#define RTC5_REG_ALARM_0_HOUR 0x0E
89#define RTC5_REG_ALARM_0_DATE_DATE 0x0F
90#define RTC5_REG_ALARM_0_DATE_DAY 0x10
91#define RTC5_REG_ALARM_0_MONTH 0x11
92#define RTC5_REG_ALARM_1_HUN_OF_SEC 0x12
93#define RTC5_REG_ALARM_1_SEC 0x13
94#define RTC5_REG_ALARM_1_MIN 0x14
95#define RTC5_REG_ALARM_1_HOUR 0x15
96#define RTC5_REG_ALARM_1_DATE_DATE 0x16
97#define RTC5_REG_ALARM_1_DATE_DAY 0x17
104#define RTC5_ALARM_0_VALUE 0x00
105#define RTC5_ALARM_1_VALUE 0x01
112#define RTC5_SPI_WRITE 0x12
113#define RTC5_SPI_READ 0x13
120#define RTC5_OSC_DISABLE 0x00
121#define RTC5_OSC_ENABLE 0x01
128#define RTC5_COUNTING_DISABLE 0x7F
129#define RTC5_COUNTING_ENABLE 0x80
136#define RTC5_CLR_CMD 0x54
143#define RTC5_DAY_OF_THE_WEEK_MONDAY 1
144#define RTC5_DAY_OF_THE_WEEK_TUESDAY 2
145#define RTC5_DAY_OF_THE_WEEK_WEDNESDAY 3
146#define RTC5_DAY_OF_THE_WEEK_THURSDAY 4
147#define RTC5_DAY_OF_THE_WEEK_FRIDAY 5
148#define RTC5_DAY_OF_THE_WEEK_SATURDAY 6
149#define RTC5_DAY_OF_THE_WEEK_SUNDAY 7 // End group macro
153// --------------------------------------------------------------- PUBLIC TYPES
162typedef struct
163{
164 digital_out_t cs;
165
166 // Input pins
167
168 digital_in_t mfp;
169
170 // Modules
171
172 spi_master_t spi;
173 pin_name_t chip_select;
174
175} rtc5_t;
176
180typedef struct
181{
182 // Communication gpio pins
183
184 pin_name_t miso;
185 pin_name_t mosi;
186 pin_name_t sck;
187 pin_name_t cs;
188
189 // Additional gpio pins
190
191 pin_name_t mfp;
192
193 // static variable
194
195 uint32_t spi_speed;
196 spi_master_mode_t spi_mode;
197 spi_master_chip_select_polarity_t cs_polarity;
198
199} rtc5_cfg_t;
200
204typedef struct
205{
206 // Time
207
208 uint8_t hun_of_sec;
209 uint8_t sec;
210 uint8_t min;
211 uint8_t hours;
212
213 // Date
214
215 uint8_t day;
216 uint8_t month;
217 uint8_t year;
218 uint8_t w_day;
219
221 // End types group
223
224// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
225
230#ifdef __cplusplus
231extern "C"{
232#endif
233
243
252
273
286(
287 rtc5_t *ctx,
288 uint8_t *wr_buf,
289 uint16_t wr_len,
290 uint8_t *rd_buf,
291 uint16_t rd_len
292);
293
304void rtc5_generic_write ( rtc5_t *ctx, uint8_t reg, uint8_t tx_data );
305
318uint8_t rtc5_generic_read ( rtc5_t *ctx, uint8_t reg );
319
328void rtc5_set_counting ( rtc5_t *ctx, uint8_t en_osc );
329
338void rtc5_clear ( rtc5_t *ctx );
339
350void rtc5_set_time_hun_of_sec ( rtc5_t *ctx, uint8_t hun_sec );
351
365
376void rtc5_set_time_sec ( rtc5_t *ctx, uint8_t seconds );
377
390uint8_t rtc5_get_time_sec ( rtc5_t *ctx );
391
402void rtc5_set_time_min ( rtc5_t *ctx, uint8_t minutes );
403
416uint8_t rtc5_get_time_min ( rtc5_t *ctx );
417
428void rtc5_set_time_hours ( rtc5_t *ctx, uint8_t hours );
429
443
462void rtc5_set_day_of_the_week ( rtc5_t *ctx, uint8_t w_day );
463
477
488void rtc5_set_date_day ( rtc5_t *ctx, uint8_t date_day );
489
502uint8_t rtc5_get_date_day ( rtc5_t *ctx );
503
514void rtc5_set_date_month ( rtc5_t *ctx, uint8_t date_month );
515
529
543uint8_t rtc5_get_leap_year ( rtc5_t *ctx );
544
555void rtc5_set_date_year ( rtc5_t *ctx, uint16_t date_year );
556
569uint8_t rtc5_get_date_year ( rtc5_t *ctx );
570
583void rtc5_set_time ( rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec );
584
597void rtc5_set_date ( rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year );
598
609void rtc5_get_time_and_date ( rtc5_t *ctx, rtc5_timedate_t *timedate_data );
610
611
612
613#ifdef __cplusplus
614}
615#endif
616#endif // _RTC5_H_
617 // End public_function group
620
621// ------------------------------------------------------------------------- END
#define RTC5_RETVAL
Definition: rtc5.h:66
void rtc5_set_time_sec(rtc5_t *ctx, uint8_t seconds)
Set seconds function.
void rtc5_set_day_of_the_week(rtc5_t *ctx, uint8_t w_day)
Set day of the week function.
void rtc5_set_counting(rtc5_t *ctx, uint8_t en_osc)
Enable counting function.
void rtc5_set_time_hours(rtc5_t *ctx, uint8_t hours)
Set hours function.
uint8_t rtc5_get_time_sec(rtc5_t *ctx)
Get seconds function.
void rtc5_generic_transfer(rtc5_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t rtc5_get_date_day(rtc5_t *ctx)
Get day function.
void rtc5_get_time_and_date(rtc5_t *ctx, rtc5_timedate_t *timedate_data)
Get time and date function.
void rtc5_default_cfg(rtc5_t *ctx)
Click Default Configuration function.
void rtc5_set_time_min(rtc5_t *ctx, uint8_t minutes)
Set minutes function.
uint8_t rtc5_generic_read(rtc5_t *ctx, uint8_t reg)
Click Default Configuration function.
uint8_t rtc5_get_date_year(rtc5_t *ctx)
Get year function.
uint8_t rtc5_get_time_hun_of_sec(rtc5_t *ctx)
Get hundred of seconds function.
uint8_t rtc5_get_day_of_the_week(rtc5_t *ctx)
Get day of the week function.
uint8_t rtc5_get_leap_year(rtc5_t *ctx)
Get leap year function.
RTC5_RETVAL rtc5_init(rtc5_t *ctx, rtc5_cfg_t *cfg)
Initialization function.
void rtc5_set_date_day(rtc5_t *ctx, uint8_t date_day)
Set day function.
void rtc5_cfg_setup(rtc5_cfg_t *cfg)
Config Object Initialization function.
void rtc5_clear(rtc5_t *ctx)
Clear RTCC and SRAM memory function.
void rtc5_set_date(rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year)
Set date hours, minutes and seconds function.
uint8_t rtc5_get_time_min(rtc5_t *ctx)
Get minutes function.
void rtc5_set_date_year(rtc5_t *ctx, uint16_t date_year)
Set year function.
void rtc5_generic_write(rtc5_t *ctx, uint8_t reg, uint8_t tx_data)
Click Default Configuration function.
void rtc5_set_time_hun_of_sec(rtc5_t *ctx, uint8_t hun_sec)
Set hundred of seconds function.
uint8_t rtc5_get_time_hours(rtc5_t *ctx)
Get hours function.
void rtc5_set_time(rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec)
Set time hours, minutes and seconds function.
void rtc5_set_date_month(rtc5_t *ctx, uint8_t date_month)
Set month function.
uint8_t rtc5_get_date_month(rtc5_t *ctx)
Get month function.
Click configuration structure definition.
Definition: rtc5.h:181
pin_name_t mfp
Definition: rtc5.h:191
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc5.h:197
pin_name_t sck
Definition: rtc5.h:186
spi_master_mode_t spi_mode
Definition: rtc5.h:196
pin_name_t mosi
Definition: rtc5.h:185
uint32_t spi_speed
Definition: rtc5.h:195
pin_name_t miso
Definition: rtc5.h:184
pin_name_t cs
Definition: rtc5.h:187
Click ctx object definition.
Definition: rtc5.h:163
digital_out_t cs
Definition: rtc5.h:164
spi_master_t spi
Definition: rtc5.h:172
digital_in_t mfp
Definition: rtc5.h:168
pin_name_t chip_select
Definition: rtc5.h:173
Time and date structure definition.
Definition: rtc5.h:205
uint8_t hours
Definition: rtc5.h:211
uint8_t month
Definition: rtc5.h:216
uint8_t hun_of_sec
Definition: rtc5.h:208
uint8_t day
Definition: rtc5.h:215
uint8_t year
Definition: rtc5.h:217
uint8_t w_day
Definition: rtc5.h:218
uint8_t min
Definition: rtc5.h:210
uint8_t sec
Definition: rtc5.h:209