rtc5  2.0.0.0
rtc5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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  // Input pins
165 
166  digital_in_t mfp;
167 
168  // Modules
169 
170  spi_master_t spi;
171 
172 } rtc5_t;
173 
177 typedef struct
178 {
179  // Communication gpio pins
180 
181  pin_name_t miso;
182  pin_name_t mosi;
183  pin_name_t sck;
184  pin_name_t cs;
185 
186  // Additional gpio pins
187 
188  pin_name_t mfp;
189 
190  // static variable
191 
192  hal_spi_speed_t spi_speed;
193  hal_spi_mode_t spi_mode;
194 
195 } rtc5_cfg_t;
196 
200 typedef struct
201 {
202  // Time
203 
204  uint8_t hun_of_sec;
205  uint8_t sec;
206  uint8_t min;
207  uint8_t hours;
208 
209  // Date
210 
211  uint8_t day;
212  uint8_t month;
213  uint8_t year;
214  uint8_t w_day;
215 
217  // End types group
219 // ------------------------------------------------------------------ CONSTANTS // End constants group
228 // ------------------------------------------------------------------ VARIABLES // End variable group
236 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
237 
242 #ifdef __cplusplus
243 extern "C"{
244 #endif
245 
254 void rtc5_cfg_setup ( rtc5_cfg_t *cfg );
255 
263 RTC5_RETVAL rtc5_init ( rtc5_t *ctx, rtc5_cfg_t *cfg );
264 
284 void rtc5_default_cfg ( rtc5_t *ctx );
285 
294 void rtc5_generic_transfer ( rtc5_t *ctx, spi_master_transfer_data_t *block );
295 
306 void rtc5_generic_write ( rtc5_t *ctx, uint8_t reg, uint8_t tx_data );
307 
320 uint8_t rtc5_generic_read ( rtc5_t *ctx, uint8_t reg );
321 
330 void rtc5_set_counting ( rtc5_t *ctx, uint8_t en_osc );
331 
340 void rtc5_clear ( rtc5_t *ctx );
341 
352 void rtc5_set_time_hun_of_sec ( rtc5_t *ctx, uint8_t hun_sec );
353 
366 uint8_t rtc5_get_time_hun_of_sec ( rtc5_t *ctx );
367 
378 void rtc5_set_time_sec ( rtc5_t *ctx, uint8_t seconds );
379 
392 uint8_t rtc5_get_time_sec ( rtc5_t *ctx );
393 
404 void rtc5_set_time_min ( rtc5_t *ctx, uint8_t minutes );
405 
418 uint8_t rtc5_get_time_min ( rtc5_t *ctx );
419 
430 void rtc5_set_time_hours ( rtc5_t *ctx, uint8_t hours );
431 
444 uint8_t rtc5_get_time_hours ( rtc5_t *ctx );
445 
464 void rtc5_set_day_of_the_week ( rtc5_t *ctx, uint8_t w_day );
465 
478 uint8_t rtc5_get_day_of_the_week ( rtc5_t *ctx );
479 
490 void rtc5_set_date_day ( rtc5_t *ctx, uint8_t date_day );
491 
504 uint8_t rtc5_get_date_day ( rtc5_t *ctx );
505 
516 void rtc5_set_date_month ( rtc5_t *ctx, uint8_t date_month );
517 
530 uint8_t rtc5_get_date_month ( rtc5_t *ctx );
531 
545 uint8_t rtc5_get_leap_year ( rtc5_t *ctx );
546 
557 void rtc5_set_date_year ( rtc5_t *ctx, uint16_t date_year );
558 
571 uint8_t rtc5_get_date_year ( rtc5_t *ctx );
572 
585 void rtc5_set_time ( rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec );
586 
599 void rtc5_set_date ( rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year );
600 
611 void rtc5_get_time_and_date ( rtc5_t *ctx, rtc5_timedate_t *timedate_data );
612 
613 
614 
615 #ifdef __cplusplus
616 }
617 #endif
618 #endif // _RTC5_H_
619  // End public_function group
622 
623 // ------------------------------------------------------------------------- END
void rtc5_generic_transfer(rtc5_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
hal_spi_speed_t spi_speed
Definition: rtc5.h:192
void rtc5_set_time_min(rtc5_t *ctx, uint8_t minutes)
Set minutes function.
hal_spi_mode_t spi_mode
Definition: rtc5.h:193
uint8_t hun_of_sec
Definition: rtc5.h:204
uint8_t rtc5_get_time_hours(rtc5_t *ctx)
Get hours function.
void rtc5_set_day_of_the_week(rtc5_t *ctx, uint8_t w_day)
Set day of the week function.
void rtc5_set_time_hours(rtc5_t *ctx, uint8_t hours)
Set hours function.
Click configuration structure definition.
Definition: rtc5.h:177
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_default_cfg(rtc5_t *ctx)
Click Default Configuration function.
uint8_t rtc5_get_day_of_the_week(rtc5_t *ctx)
Get day of the week function.
uint8_t rtc5_get_time_hun_of_sec(rtc5_t *ctx)
Get hundred of seconds function.
uint8_t rtc5_generic_read(rtc5_t *ctx, uint8_t reg)
Click Default Configuration function.
uint8_t sec
Definition: rtc5.h:205
pin_name_t cs
Definition: rtc5.h:184
void rtc5_set_date_month(rtc5_t *ctx, uint8_t date_month)
Set month 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 year
Definition: rtc5.h:213
pin_name_t miso
Definition: rtc5.h:181
uint8_t hours
Definition: rtc5.h:207
RTC5_RETVAL rtc5_init(rtc5_t *ctx, rtc5_cfg_t *cfg)
Initialization function.
void rtc5_set_time_sec(rtc5_t *ctx, uint8_t seconds)
Set seconds function.
Time and date structure definition.
Definition: rtc5.h:200
uint8_t month
Definition: rtc5.h:212
Click ctx object definition.
Definition: rtc5.h:162
void rtc5_set_time_hun_of_sec(rtc5_t *ctx, uint8_t hun_sec)
Set hundred of seconds function.
uint8_t day
Definition: rtc5.h:211
spi_master_t spi
Definition: rtc5.h:170
void rtc5_set_counting(rtc5_t *ctx, uint8_t en_osc)
Enable counting function.
void rtc5_set_date_day(rtc5_t *ctx, uint8_t date_day)
Set day function.
uint8_t rtc5_get_date_month(rtc5_t *ctx)
Get month function.
pin_name_t mfp
Definition: rtc5.h:188
pin_name_t sck
Definition: rtc5.h:183
void rtc5_set_date_year(rtc5_t *ctx, uint16_t date_year)
Set year function.
uint8_t w_day
Definition: rtc5.h:214
void rtc5_get_time_and_date(rtc5_t *ctx, rtc5_timedate_t *timedate_data)
Get time and date function.
uint8_t rtc5_get_time_sec(rtc5_t *ctx)
Get seconds function.
#define RTC5_RETVAL
Definition: rtc5.h:66
uint8_t rtc5_get_date_day(rtc5_t *ctx)
Get day function.
uint8_t min
Definition: rtc5.h:206
uint8_t rtc5_get_leap_year(rtc5_t *ctx)
Get leap year function.
pin_name_t mosi
Definition: rtc5.h:182
void rtc5_cfg_setup(rtc5_cfg_t *cfg)
Config Object Initialization function.
uint8_t rtc5_get_date_year(rtc5_t *ctx)
Get year function.
void rtc5_clear(rtc5_t *ctx)
Clear RTCC and SRAM memory function.
void rtc5_generic_write(rtc5_t *ctx, uint8_t reg, uint8_t tx_data)
Click Default Configuration function.
digital_in_t mfp
Definition: rtc5.h:166
uint8_t rtc5_get_time_min(rtc5_t *ctx)
Get minutes function.