rtc13  2.0.0.0
rtc13.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef RTC13_H
29 #define RTC13_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define RTC13_REG_CTRL1_ADDR 0x00
71 #define RTC13_REG_CTRL2_ADDR 0x01
72 #define RTC13_REG_TIME_SECONDS 0x02
73 #define RTC13_REG_TIME_MINUTES 0x03
74 #define RTC13_REG_TIME_HOUR 0x04
75 #define RTC13_REG_DATE_DAY 0x05
76 #define RTC13_REG_DATE_WEEKDAYS 0x06
77 #define RTC13_REG_DATE_MONTHS 0x07
78 #define RTC13_REG_DATE_YEARS 0x08
79 #define RTC13_REG_ALARM_MINUTE 0x09
80 #define RTC13_REG_ALARM_HOUR 0x0A
81 #define RTC13_REG_ALARM_DAY 0x0B
82 #define RTC13_REG_ALARM_WEEKDAY 0x0C
83 #define RTC13_REG_OFFSET_ADDR 0x0D
84 #define RTC13_REG_TIMER_CLKOUT_ADDR 0x0E
85 #define RTC13_REG_COUNTDOWN_TIMER_ADDR 0x0F
86  // rtc13_reg
88 
103 #define RTC13_SOFT_RESET 0x58
104 #define RTC13_BLOCK_CLKOUT_DISABLE 0x00
105 #define RTC13_BLOCK_CLKOUT_ENABLE 0x01
106 
115 #define RTC13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
116 #define RTC13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
117  // rtc13_set
119 
134 #define RTC13_MAP_MIKROBUS( cfg, mikrobus ) \
135  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
136  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
137  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
138  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
139  cfg.cle = MIKROBUS( mikrobus, MIKROBUS_RST ); \
140  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
141  // rtc13_map // rtc13
144 
149 typedef struct
150 {
151  uint8_t hours;
152  uint8_t min;
153  uint8_t sec;
154 
155 } rtc13_time_t;
156 
161 typedef struct
162 {
163  uint8_t year;
164  uint8_t month;
165  uint8_t day;
166  uint8_t weekday;
167 
168 } rtc13_date_t;
169 
174 typedef struct
175 {
176  uint8_t min;
177  uint8_t hours;
178  uint8_t day;
179  uint8_t weekday;
180 
181 } rtc13_alarm_t;
182 
187 typedef struct
188 {
189  // Output pins
190  digital_out_t cle;
192  // Input pins
193  digital_in_t int_pin;
195  // Modules
196  spi_master_t spi;
198  pin_name_t chip_select;
200 } rtc13_t;
201 
206 typedef struct
207 {
208  // Communication gpio pins
209  pin_name_t miso;
210  pin_name_t mosi;
211  pin_name_t sck;
212  pin_name_t cs;
214  // Additional gpio pins
215  pin_name_t cle;
216  pin_name_t int_pin;
218  // static variable
219  uint32_t spi_speed;
220  spi_master_mode_t spi_mode;
221  spi_master_chip_select_polarity_t cs_polarity;
223 } rtc13_cfg_t;
224 
229 typedef enum
230 {
231  RTC13_OK = 0,
232  RTC13_ERROR = -1
233 
235 
254 
271 err_t rtc13_init ( rtc13_t *ctx, rtc13_cfg_t *cfg );
272 
288 err_t rtc13_default_cfg ( rtc13_t *ctx );
289 
304 uint8_t rtc13_get_interrupt ( rtc13_t *ctx );
305 
323 err_t rtc13_block_clkout ( rtc13_t *ctx, uint8_t en_clkout );
324 
342 err_t rtc13_generic_write ( rtc13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
343 
361 err_t rtc13_generic_read ( rtc13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
362 
378 err_t rtc13_soft_reset ( rtc13_t *ctx );
379 
396 err_t rtc13_get_time ( rtc13_t *ctx, rtc13_time_t *rtc_time );
397 
414 err_t rtc13_set_time ( rtc13_t *ctx, rtc13_time_t rtc_time );
415 
432 err_t rtc13_get_date ( rtc13_t *ctx, rtc13_date_t *rtc_date );
433 
450 err_t rtc13_set_date ( rtc13_t *ctx, rtc13_date_t rtc_date );
451 
468 err_t rtc13_get_alarm ( rtc13_t *ctx, rtc13_alarm_t *rtc_alarm );
469 
486 err_t rtc13_set_alarm ( rtc13_t *ctx, rtc13_alarm_t rtc_alarm );
487 
488 #ifdef __cplusplus
489 }
490 #endif
491 #endif // RTC13_H
492  // rtc13
494 
495 // ------------------------------------------------------------------------ END
rtc13_cfg_setup
void rtc13_cfg_setup(rtc13_cfg_t *cfg)
RTC 13 configuration object setup function.
rtc13_t::int_pin
digital_in_t int_pin
Definition: rtc13.h:193
rtc13_alarm_t
RTC 13 Click alarm object.
Definition: rtc13.h:175
rtc13_t::cle
digital_out_t cle
Definition: rtc13.h:190
rtc13_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc13.h:221
RTC13_ERROR
@ RTC13_ERROR
Definition: rtc13.h:232
rtc13_get_interrupt
uint8_t rtc13_get_interrupt(rtc13_t *ctx)
RTC 13 get interrupt function.
rtc13_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtc13.h:220
rtc13_cfg_t::mosi
pin_name_t mosi
Definition: rtc13.h:210
rtc13_time_t::min
uint8_t min
Definition: rtc13.h:152
rtc13_time_t::hours
uint8_t hours
Definition: rtc13.h:151
spi_specifics.h
This file contains SPI specific macros, functions, etc.
rtc13_soft_reset
err_t rtc13_soft_reset(rtc13_t *ctx)
RTC 13 soft reset function.
rtc13_time_t
RTC 13 Click time object.
Definition: rtc13.h:150
rtc13_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc13.h:216
rtc13_get_time
err_t rtc13_get_time(rtc13_t *ctx, rtc13_time_t *rtc_time)
RTC 13 get time function.
rtc13_cfg_t::cle
pin_name_t cle
Definition: rtc13.h:215
rtc13_set_time
err_t rtc13_set_time(rtc13_t *ctx, rtc13_time_t rtc_time)
RTC 13 set time function.
rtc13_generic_write
err_t rtc13_generic_write(rtc13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 13 data writing function.
rtc13_date_t
RTC 13 Click date object.
Definition: rtc13.h:162
rtc13_t::chip_select
pin_name_t chip_select
Definition: rtc13.h:198
rtc13_cfg_t::sck
pin_name_t sck
Definition: rtc13.h:211
rtc13_alarm_t::min
uint8_t min
Definition: rtc13.h:176
rtc13_time_t::sec
uint8_t sec
Definition: rtc13.h:153
rtc13_date_t::weekday
uint8_t weekday
Definition: rtc13.h:166
rtc13_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtc13.h:219
rtc13_t::spi
spi_master_t spi
Definition: rtc13.h:196
rtc13_alarm_t::weekday
uint8_t weekday
Definition: rtc13.h:179
rtc13_block_clkout
err_t rtc13_block_clkout(rtc13_t *ctx, uint8_t en_clkout)
RTC 13 block CLKOUT function.
rtc13_cfg_t
RTC 13 Click configuration object.
Definition: rtc13.h:207
rtc13_set_date
err_t rtc13_set_date(rtc13_t *ctx, rtc13_date_t rtc_date)
RTC 13 set date function.
rtc13_cfg_t::cs
pin_name_t cs
Definition: rtc13.h:212
rtc13_alarm_t::hours
uint8_t hours
Definition: rtc13.h:177
rtc13_t
RTC 13 Click context object.
Definition: rtc13.h:188
rtc13_cfg_t::miso
pin_name_t miso
Definition: rtc13.h:209
rtc13_alarm_t::day
uint8_t day
Definition: rtc13.h:178
rtc13_return_value_t
rtc13_return_value_t
RTC 13 Click return value data.
Definition: rtc13.h:230
rtc13_set_alarm
err_t rtc13_set_alarm(rtc13_t *ctx, rtc13_alarm_t rtc_alarm)
RTC 13 set alarm function.
rtc13_date_t::year
uint8_t year
Definition: rtc13.h:163
rtc13_get_date
err_t rtc13_get_date(rtc13_t *ctx, rtc13_date_t *rtc_date)
RTC 13 get date function.
rtc13_init
err_t rtc13_init(rtc13_t *ctx, rtc13_cfg_t *cfg)
RTC 13 initialization function.
rtc13_date_t::day
uint8_t day
Definition: rtc13.h:165
rtc13_date_t::month
uint8_t month
Definition: rtc13.h:164
rtc13_get_alarm
err_t rtc13_get_alarm(rtc13_t *ctx, rtc13_alarm_t *rtc_alarm)
RTC 13 get alarm function.
RTC13_OK
@ RTC13_OK
Definition: rtc13.h:231
rtc13_default_cfg
err_t rtc13_default_cfg(rtc13_t *ctx)
RTC 13 default configuration function.
rtc13_generic_read
err_t rtc13_generic_read(rtc13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 13 data reading function.