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 );
60 
66 #define RTC5_RETVAL uint8_t
67 
68 #define RTC5_OK 0x00
69 #define RTC5_INIT_ERROR 0xFF
70 
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
98 
104 #define RTC5_ALARM_0_VALUE 0x00
105 #define RTC5_ALARM_1_VALUE 0x01
106 
112 #define RTC5_SPI_WRITE 0x12
113 #define RTC5_SPI_READ 0x13
114 
120 #define RTC5_OSC_DISABLE 0x00
121 #define RTC5_OSC_ENABLE 0x01
122 
128 #define RTC5_COUNTING_DISABLE 0x7F
129 #define RTC5_COUNTING_ENABLE 0x80
130 
136 #define RTC5_CLR_CMD 0x54
137 
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
150  // End group macro
153 // --------------------------------------------------------------- PUBLIC TYPES
162 typedef 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 
180 typedef 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 
204 typedef 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
231 extern "C"{
232 #endif
233 
242 void rtc5_cfg_setup ( rtc5_cfg_t *cfg );
243 
251 RTC5_RETVAL rtc5_init ( rtc5_t *ctx, rtc5_cfg_t *cfg );
252 
272 void rtc5_default_cfg ( rtc5_t *ctx );
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 
304 void rtc5_generic_write ( rtc5_t *ctx, uint8_t reg, uint8_t tx_data );
305 
318 uint8_t rtc5_generic_read ( rtc5_t *ctx, uint8_t reg );
319 
328 void rtc5_set_counting ( rtc5_t *ctx, uint8_t en_osc );
329 
338 void rtc5_clear ( rtc5_t *ctx );
339 
350 void rtc5_set_time_hun_of_sec ( rtc5_t *ctx, uint8_t hun_sec );
351 
364 uint8_t rtc5_get_time_hun_of_sec ( rtc5_t *ctx );
365 
376 void rtc5_set_time_sec ( rtc5_t *ctx, uint8_t seconds );
377 
390 uint8_t rtc5_get_time_sec ( rtc5_t *ctx );
391 
402 void rtc5_set_time_min ( rtc5_t *ctx, uint8_t minutes );
403 
416 uint8_t rtc5_get_time_min ( rtc5_t *ctx );
417 
428 void rtc5_set_time_hours ( rtc5_t *ctx, uint8_t hours );
429 
442 uint8_t rtc5_get_time_hours ( rtc5_t *ctx );
443 
462 void rtc5_set_day_of_the_week ( rtc5_t *ctx, uint8_t w_day );
463 
476 uint8_t rtc5_get_day_of_the_week ( rtc5_t *ctx );
477 
488 void rtc5_set_date_day ( rtc5_t *ctx, uint8_t date_day );
489 
502 uint8_t rtc5_get_date_day ( rtc5_t *ctx );
503 
514 void rtc5_set_date_month ( rtc5_t *ctx, uint8_t date_month );
515 
528 uint8_t rtc5_get_date_month ( rtc5_t *ctx );
529 
543 uint8_t rtc5_get_leap_year ( rtc5_t *ctx );
544 
555 void rtc5_set_date_year ( rtc5_t *ctx, uint16_t date_year );
556 
569 uint8_t rtc5_get_date_year ( rtc5_t *ctx );
570 
583 void rtc5_set_time ( rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec );
584 
597 void rtc5_set_date ( rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year );
598 
609 void 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
rtc5_set_time_hours
void rtc5_set_time_hours(rtc5_t *ctx, uint8_t hours)
Set hours function.
rtc5_get_time_min
uint8_t rtc5_get_time_min(rtc5_t *ctx)
Get minutes function.
rtc5_cfg_t::mosi
pin_name_t mosi
Definition: rtc5.h:185
rtc5_set_time
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.
RTC5_RETVAL
#define RTC5_RETVAL
Definition: rtc5.h:66
rtc5_timedate_t::year
uint8_t year
Definition: rtc5.h:217
rtc5_set_date_year
void rtc5_set_date_year(rtc5_t *ctx, uint16_t date_year)
Set year function.
rtc5_timedate_t::hours
uint8_t hours
Definition: rtc5.h:211
rtc5_init
RTC5_RETVAL rtc5_init(rtc5_t *ctx, rtc5_cfg_t *cfg)
Initialization function.
rtc5_cfg_t::miso
pin_name_t miso
Definition: rtc5.h:184
rtc5_clear
void rtc5_clear(rtc5_t *ctx)
Clear RTCC and SRAM memory function.
rtc5_get_day_of_the_week
uint8_t rtc5_get_day_of_the_week(rtc5_t *ctx)
Get day of the week function.
rtc5_t::spi
spi_master_t spi
Definition: rtc5.h:172
rtc5_get_date_year
uint8_t rtc5_get_date_year(rtc5_t *ctx)
Get year function.
rtc5_timedate_t::min
uint8_t min
Definition: rtc5.h:210
rtc5_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtc5.h:195
rtc5_get_time_and_date
void rtc5_get_time_and_date(rtc5_t *ctx, rtc5_timedate_t *timedate_data)
Get time and date function.
rtc5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtc5.h:196
rtc5_set_date
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.
rtc5_cfg_t
Click configuration structure definition.
Definition: rtc5.h:180
rtc5_t::mfp
digital_in_t mfp
Definition: rtc5.h:168
rtc5_timedate_t
Time and date structure definition.
Definition: rtc5.h:204
rtc5_get_time_sec
uint8_t rtc5_get_time_sec(rtc5_t *ctx)
Get seconds function.
rtc5_t::chip_select
pin_name_t chip_select
Definition: rtc5.h:173
rtc5_get_leap_year
uint8_t rtc5_get_leap_year(rtc5_t *ctx)
Get leap year function.
rtc5_timedate_t::sec
uint8_t sec
Definition: rtc5.h:209
rtc5_t::cs
digital_out_t cs
Definition: rtc5.h:164
rtc5_generic_read
uint8_t rtc5_generic_read(rtc5_t *ctx, uint8_t reg)
Click Default Configuration function.
rtc5_set_date_month
void rtc5_set_date_month(rtc5_t *ctx, uint8_t date_month)
Set month function.
rtc5_timedate_t::month
uint8_t month
Definition: rtc5.h:216
rtc5_timedate_t::hun_of_sec
uint8_t hun_of_sec
Definition: rtc5.h:208
rtc5_set_counting
void rtc5_set_counting(rtc5_t *ctx, uint8_t en_osc)
Enable counting function.
rtc5_cfg_setup
void rtc5_cfg_setup(rtc5_cfg_t *cfg)
Config Object Initialization function.
rtc5_set_time_sec
void rtc5_set_time_sec(rtc5_t *ctx, uint8_t seconds)
Set seconds function.
rtc5_set_day_of_the_week
void rtc5_set_day_of_the_week(rtc5_t *ctx, uint8_t w_day)
Set day of the week function.
rtc5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc5.h:197
rtc5_cfg_t::sck
pin_name_t sck
Definition: rtc5.h:186
rtc5_set_date_day
void rtc5_set_date_day(rtc5_t *ctx, uint8_t date_day)
Set day function.
rtc5_default_cfg
void rtc5_default_cfg(rtc5_t *ctx)
Click Default Configuration function.
rtc5_get_time_hun_of_sec
uint8_t rtc5_get_time_hun_of_sec(rtc5_t *ctx)
Get hundred of seconds function.
rtc5_set_time_min
void rtc5_set_time_min(rtc5_t *ctx, uint8_t minutes)
Set minutes function.
rtc5_cfg_t::mfp
pin_name_t mfp
Definition: rtc5.h:191
rtc5_t
Click ctx object definition.
Definition: rtc5.h:162
rtc5_get_date_month
uint8_t rtc5_get_date_month(rtc5_t *ctx)
Get month function.
rtc5_timedate_t::day
uint8_t day
Definition: rtc5.h:215
rtc5_timedate_t::w_day
uint8_t w_day
Definition: rtc5.h:218
rtc5_generic_transfer
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.
rtc5_set_time_hun_of_sec
void rtc5_set_time_hun_of_sec(rtc5_t *ctx, uint8_t hun_sec)
Set hundred of seconds function.
rtc5_get_date_day
uint8_t rtc5_get_date_day(rtc5_t *ctx)
Get day function.
rtc5_generic_write
void rtc5_generic_write(rtc5_t *ctx, uint8_t reg, uint8_t tx_data)
Click Default Configuration function.
rtc5_get_time_hours
uint8_t rtc5_get_time_hours(rtc5_t *ctx)
Get hours function.
rtc5_cfg_t::cs
pin_name_t cs
Definition: rtc5.h:187