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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define RTC5_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.mfp = MIKROBUS( mikrobus, MIKROBUS_INT );
80#define RTC5_RETVAL uint8_t
81
82#define RTC5_OK 0x00
83#define RTC5_INIT_ERROR 0xFF
90#define RTC5_REG_TIME_HUN_OF_SEC 0x00
91#define RTC5_REG_TIME_SEC 0x01
92#define RTC5_REG_TIME_MIN 0x02
93#define RTC5_REG_TIME_HOUR 0x03
94#define RTC5_REG_TIME_DAY_OF_THE_WEEK 0x04
95#define RTC5_REG_TIME_DATE_DAY 0x05
96#define RTC5_REG_TIME_DATE_MONTH 0x06
97#define RTC5_REG_TIME_DATE_YEAR 0x07
98#define RTC5_REG_CONFIG 0x08
99#define RTC5_REG_CALIBRATION 0x09
100#define RTC5_REG_ALARM_0_SEC 0x0C
101#define RTC5_REG_ALARM_0_MIN 0x0D
102#define RTC5_REG_ALARM_0_HOUR 0x0E
103#define RTC5_REG_ALARM_0_DATE_DATE 0x0F
104#define RTC5_REG_ALARM_0_DATE_DAY 0x10
105#define RTC5_REG_ALARM_0_MONTH 0x11
106#define RTC5_REG_ALARM_1_HUN_OF_SEC 0x12
107#define RTC5_REG_ALARM_1_SEC 0x13
108#define RTC5_REG_ALARM_1_MIN 0x14
109#define RTC5_REG_ALARM_1_HOUR 0x15
110#define RTC5_REG_ALARM_1_DATE_DATE 0x16
111#define RTC5_REG_ALARM_1_DATE_DAY 0x17
118#define RTC5_ALARM_0_VALUE 0x00
119#define RTC5_ALARM_1_VALUE 0x01
126#define RTC5_SPI_WRITE 0x12
127#define RTC5_SPI_READ 0x13
134#define RTC5_OSC_DISABLE 0x00
135#define RTC5_OSC_ENABLE 0x01
142#define RTC5_COUNTING_DISABLE 0x7F
143#define RTC5_COUNTING_ENABLE 0x80
150#define RTC5_CLR_CMD 0x54
157#define RTC5_DAY_OF_THE_WEEK_MONDAY 1
158#define RTC5_DAY_OF_THE_WEEK_TUESDAY 2
159#define RTC5_DAY_OF_THE_WEEK_WEDNESDAY 3
160#define RTC5_DAY_OF_THE_WEEK_THURSDAY 4
161#define RTC5_DAY_OF_THE_WEEK_FRIDAY 5
162#define RTC5_DAY_OF_THE_WEEK_SATURDAY 6
163#define RTC5_DAY_OF_THE_WEEK_SUNDAY 7
166 // End group macro
167// --------------------------------------------------------------- PUBLIC TYPES
176typedef struct
177{
178 digital_out_t cs;
179
180 // Input pins
181
182 digital_in_t mfp;
183
184 // Modules
185
186 spi_master_t spi;
187 pin_name_t chip_select;
188
189} rtc5_t;
190
194typedef struct
195{
196 // Communication gpio pins
197
198 pin_name_t miso;
199 pin_name_t mosi;
200 pin_name_t sck;
201 pin_name_t cs;
202
203 // Additional gpio pins
204
205 pin_name_t mfp;
206
207 // static variable
208
209 uint32_t spi_speed;
210 spi_master_mode_t spi_mode;
211 spi_master_chip_select_polarity_t cs_polarity;
212
213} rtc5_cfg_t;
214
218typedef struct
219{
220 // Time
221
222 uint8_t hun_of_sec;
223 uint8_t sec;
224 uint8_t min;
225 uint8_t hours;
226
227 // Date
228
229 uint8_t day;
230 uint8_t month;
231 uint8_t year;
232 uint8_t w_day;
233
235
236 // End types group
237
238// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
239
244#ifdef __cplusplus
245extern "C"{
246#endif
247
257
266
287
300(
301 rtc5_t *ctx,
302 uint8_t *wr_buf,
303 uint16_t wr_len,
304 uint8_t *rd_buf,
305 uint16_t rd_len
306);
307
318void rtc5_generic_write ( rtc5_t *ctx, uint8_t reg, uint8_t tx_data );
319
332uint8_t rtc5_generic_read ( rtc5_t *ctx, uint8_t reg );
333
342void rtc5_set_counting ( rtc5_t *ctx, uint8_t en_osc );
343
352void rtc5_clear ( rtc5_t *ctx );
353
364void rtc5_set_time_hun_of_sec ( rtc5_t *ctx, uint8_t hun_sec );
365
379
390void rtc5_set_time_sec ( rtc5_t *ctx, uint8_t seconds );
391
404uint8_t rtc5_get_time_sec ( rtc5_t *ctx );
405
416void rtc5_set_time_min ( rtc5_t *ctx, uint8_t minutes );
417
430uint8_t rtc5_get_time_min ( rtc5_t *ctx );
431
442void rtc5_set_time_hours ( rtc5_t *ctx, uint8_t hours );
443
457
476void rtc5_set_day_of_the_week ( rtc5_t *ctx, uint8_t w_day );
477
491
502void rtc5_set_date_day ( rtc5_t *ctx, uint8_t date_day );
503
516uint8_t rtc5_get_date_day ( rtc5_t *ctx );
517
528void rtc5_set_date_month ( rtc5_t *ctx, uint8_t date_month );
529
543
557uint8_t rtc5_get_leap_year ( rtc5_t *ctx );
558
569void rtc5_set_date_year ( rtc5_t *ctx, uint16_t date_year );
570
583uint8_t rtc5_get_date_year ( rtc5_t *ctx );
584
597void rtc5_set_time ( rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec );
598
611void rtc5_set_date ( rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year );
612
623void rtc5_get_time_and_date ( rtc5_t *ctx, rtc5_timedate_t *timedate_data );
624
625
626
627#ifdef __cplusplus
628}
629#endif
630#endif // _RTC5_H_
631
632 // End public_function group
634
635// ------------------------------------------------------------------------- END
#define RTC5_RETVAL
Definition rtc5.h:80
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:195
pin_name_t mfp
Definition rtc5.h:205
spi_master_chip_select_polarity_t cs_polarity
Definition rtc5.h:211
pin_name_t sck
Definition rtc5.h:200
spi_master_mode_t spi_mode
Definition rtc5.h:210
pin_name_t mosi
Definition rtc5.h:199
uint32_t spi_speed
Definition rtc5.h:209
pin_name_t miso
Definition rtc5.h:198
pin_name_t cs
Definition rtc5.h:201
Click ctx object definition.
Definition rtc5.h:177
digital_out_t cs
Definition rtc5.h:178
spi_master_t spi
Definition rtc5.h:186
digital_in_t mfp
Definition rtc5.h:182
pin_name_t chip_select
Definition rtc5.h:187
Time and date structure definition.
Definition rtc5.h:219
uint8_t hours
Definition rtc5.h:225
uint8_t month
Definition rtc5.h:230
uint8_t hun_of_sec
Definition rtc5.h:222
uint8_t day
Definition rtc5.h:229
uint8_t year
Definition rtc5.h:231
uint8_t w_day
Definition rtc5.h:232
uint8_t min
Definition rtc5.h:224
uint8_t sec
Definition rtc5.h:223