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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define RTC5_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.mfp = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define RTC5_RETVAL uint8_t
77 
78 #define RTC5_OK 0x00
79 #define RTC5_INIT_ERROR 0xFF
80 
86 #define RTC5_REG_TIME_HUN_OF_SEC 0x00
87 #define RTC5_REG_TIME_SEC 0x01
88 #define RTC5_REG_TIME_MIN 0x02
89 #define RTC5_REG_TIME_HOUR 0x03
90 #define RTC5_REG_TIME_DAY_OF_THE_WEEK 0x04
91 #define RTC5_REG_TIME_DATE_DAY 0x05
92 #define RTC5_REG_TIME_DATE_MONTH 0x06
93 #define RTC5_REG_TIME_DATE_YEAR 0x07
94 #define RTC5_REG_CONFIG 0x08
95 #define RTC5_REG_CALIBRATION 0x09
96 #define RTC5_REG_ALARM_0_SEC 0x0C
97 #define RTC5_REG_ALARM_0_MIN 0x0D
98 #define RTC5_REG_ALARM_0_HOUR 0x0E
99 #define RTC5_REG_ALARM_0_DATE_DATE 0x0F
100 #define RTC5_REG_ALARM_0_DATE_DAY 0x10
101 #define RTC5_REG_ALARM_0_MONTH 0x11
102 #define RTC5_REG_ALARM_1_HUN_OF_SEC 0x12
103 #define RTC5_REG_ALARM_1_SEC 0x13
104 #define RTC5_REG_ALARM_1_MIN 0x14
105 #define RTC5_REG_ALARM_1_HOUR 0x15
106 #define RTC5_REG_ALARM_1_DATE_DATE 0x16
107 #define RTC5_REG_ALARM_1_DATE_DAY 0x17
108 
114 #define RTC5_ALARM_0_VALUE 0x00
115 #define RTC5_ALARM_1_VALUE 0x01
116 
122 #define RTC5_SPI_WRITE 0x12
123 #define RTC5_SPI_READ 0x13
124 
130 #define RTC5_OSC_DISABLE 0x00
131 #define RTC5_OSC_ENABLE 0x01
132 
138 #define RTC5_COUNTING_DISABLE 0x7F
139 #define RTC5_COUNTING_ENABLE 0x80
140 
146 #define RTC5_CLR_CMD 0x54
147 
153 #define RTC5_DAY_OF_THE_WEEK_MONDAY 1
154 #define RTC5_DAY_OF_THE_WEEK_TUESDAY 2
155 #define RTC5_DAY_OF_THE_WEEK_WEDNESDAY 3
156 #define RTC5_DAY_OF_THE_WEEK_THURSDAY 4
157 #define RTC5_DAY_OF_THE_WEEK_FRIDAY 5
158 #define RTC5_DAY_OF_THE_WEEK_SATURDAY 6
159 #define RTC5_DAY_OF_THE_WEEK_SUNDAY 7
160  // End group macro
163 // --------------------------------------------------------------- PUBLIC TYPES
172 typedef struct
173 {
174  digital_out_t cs;
175 
176  // Input pins
177 
178  digital_in_t mfp;
179 
180  // Modules
181 
182  spi_master_t spi;
183  pin_name_t chip_select;
184 
185 } rtc5_t;
186 
190 typedef struct
191 {
192  // Communication gpio pins
193 
194  pin_name_t miso;
195  pin_name_t mosi;
196  pin_name_t sck;
197  pin_name_t cs;
198 
199  // Additional gpio pins
200 
201  pin_name_t mfp;
202 
203  // static variable
204 
205  uint32_t spi_speed;
206  spi_master_mode_t spi_mode;
207  spi_master_chip_select_polarity_t cs_polarity;
208 
209 } rtc5_cfg_t;
210 
214 typedef struct
215 {
216  // Time
217 
218  uint8_t hun_of_sec;
219  uint8_t sec;
220  uint8_t min;
221  uint8_t hours;
222 
223  // Date
224 
225  uint8_t day;
226  uint8_t month;
227  uint8_t year;
228  uint8_t w_day;
229 
231  // End types group
233 
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
240 #ifdef __cplusplus
241 extern "C"{
242 #endif
243 
253 
262 
282 void rtc5_default_cfg ( rtc5_t *ctx );
283 
296 (
297  rtc5_t *ctx,
298  uint8_t *wr_buf,
299  uint16_t wr_len,
300  uint8_t *rd_buf,
301  uint16_t rd_len
302 );
303 
314 void rtc5_generic_write ( rtc5_t *ctx, uint8_t reg, uint8_t tx_data );
315 
328 uint8_t rtc5_generic_read ( rtc5_t *ctx, uint8_t reg );
329 
338 void rtc5_set_counting ( rtc5_t *ctx, uint8_t en_osc );
339 
348 void rtc5_clear ( rtc5_t *ctx );
349 
360 void rtc5_set_time_hun_of_sec ( rtc5_t *ctx, uint8_t hun_sec );
361 
375 
386 void rtc5_set_time_sec ( rtc5_t *ctx, uint8_t seconds );
387 
400 uint8_t rtc5_get_time_sec ( rtc5_t *ctx );
401 
412 void rtc5_set_time_min ( rtc5_t *ctx, uint8_t minutes );
413 
426 uint8_t rtc5_get_time_min ( rtc5_t *ctx );
427 
438 void rtc5_set_time_hours ( rtc5_t *ctx, uint8_t hours );
439 
452 uint8_t rtc5_get_time_hours ( rtc5_t *ctx );
453 
472 void rtc5_set_day_of_the_week ( rtc5_t *ctx, uint8_t w_day );
473 
487 
498 void rtc5_set_date_day ( rtc5_t *ctx, uint8_t date_day );
499 
512 uint8_t rtc5_get_date_day ( rtc5_t *ctx );
513 
524 void rtc5_set_date_month ( rtc5_t *ctx, uint8_t date_month );
525 
538 uint8_t rtc5_get_date_month ( rtc5_t *ctx );
539 
553 uint8_t rtc5_get_leap_year ( rtc5_t *ctx );
554 
565 void rtc5_set_date_year ( rtc5_t *ctx, uint16_t date_year );
566 
579 uint8_t rtc5_get_date_year ( rtc5_t *ctx );
580 
593 void rtc5_set_time ( rtc5_t *ctx, uint8_t time_hours, uint8_t time_min, uint8_t time_sec );
594 
607 void rtc5_set_date ( rtc5_t *ctx, uint8_t date_day, uint8_t date_month, uint16_t date_year );
608 
619 void rtc5_get_time_and_date ( rtc5_t *ctx, rtc5_timedate_t *timedate_data );
620 
621 
622 
623 #ifdef __cplusplus
624 }
625 #endif
626 #endif // _RTC5_H_
627  // End public_function group
630 
631 // ------------------------------------------------------------------------- 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:195
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:76
rtc5_timedate_t::year
uint8_t year
Definition: rtc5.h:227
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:221
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:194
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:182
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:220
rtc5_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtc5.h:205
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:206
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:191
rtc5_t::mfp
digital_in_t mfp
Definition: rtc5.h:178
rtc5_timedate_t
Time and date structure definition.
Definition: rtc5.h:215
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:183
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:219
rtc5_t::cs
digital_out_t cs
Definition: rtc5.h:174
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:226
rtc5_timedate_t::hun_of_sec
uint8_t hun_of_sec
Definition: rtc5.h:218
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:207
rtc5_cfg_t::sck
pin_name_t sck
Definition: rtc5.h:196
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:201
rtc5_t
Click ctx object definition.
Definition: rtc5.h:173
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:225
rtc5_timedate_t::w_day
uint8_t w_day
Definition: rtc5.h:228
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:197