rtc12  2.0.0.0
rtc12.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 RTC12_H
29 #define RTC12_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 
49 
70 #define RTC12_REG_SECONDS 0x00
71 #define RTC12_REG_MINUTES 0x01
72 #define RTC12_REG_HOUR 0x02
73 #define RTC12_REG_DAY 0x03
74 #define RTC12_REG_DATE 0x04
75 #define RTC12_REG_MONTH 0x05
76 #define RTC12_REG_YEAR 0x06
77 #define RTC12_REG_ALARM_0_SECONDS 0x07
78 #define RTC12_REG_ALARM_0_MINUTES 0x08
79 #define RTC12_REG_ALARM_0_HOUR 0x09
80 #define RTC12_REG_ALARM_0_DAY 0x0A
81 #define RTC12_REG_ALARM_1_SECONDS 0x0B
82 #define RTC12_REG_ALARM_1_MINUTES 0x0C
83 #define RTC12_REG_ALARM_1_HOUR 0x0D
84 #define RTC12_REG_ALARM_1_DAY 0x0E
85 #define RTC12_REG_CONTROL 0x0F
86 #define RTC12_REG_STATUS 0x10
87 #define RTC12_REG_TRICKLE_CHARGER 0x11
88  // rtc12_reg
90 
105 #define RTC12_SET_EOSC_ENABLE 0x00
106 #define RTC12_SET_EOSC_DISABLE 0x01
107 #define RTC12_SET_DOSF_ENABLE 0x00
108 #define RTC12_SET_DOSF_DISABL 0x01
109 #define RTC12_SET_EGFIL_DISABLE 0x00
110 #define RTC12_SET_EGFIL_ENABLE 0x01
111 #define RTC12_SET_SQW_DISABLE 0x00
112 #define RTC12_SET_SQW_ENABLE 0x01
113 #define RTC12_SET_INTCN_A0IE 0x00
114 #define RTC12_SET_INTCN_A0IE_A1IE 0x01
115 #define RTC12_SET_ALARM_1_DISABLE 0x00
116 #define RTC12_SET_ALARM_1_ENABLE 0x01
117 #define RTC12_SET_ALARM_0_DISABLE 0x00
118 #define RTC12_SET_ALARM_0_ENABLE 0x01
119 
120  // rtc12_set
122 
137 #define RTC12_MAP_MIKROBUS( cfg, mikrobus ) \
138  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
139  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
140  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
141  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
142  cfg.pf = MIKROBUS( mikrobus, MIKROBUS_AN ); \
143  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
144  // rtc12_map // rtc12
147 
152 typedef struct
153 {
154  // Input pins
155 
156  digital_in_t pf;
157  digital_in_t int_pin;
159  // Modules
160 
161  spi_master_t spi;
163  pin_name_t chip_select;
165 } rtc12_t;
166 
171 typedef struct
172 {
173  // Communication gpio pins
174 
175  pin_name_t miso;
176  pin_name_t mosi;
177  pin_name_t sck;
178  pin_name_t cs;
180  // Additional gpio pins
181 
182  pin_name_t pf;
183  pin_name_t int_pin;
185  // static variable
186 
187  uint32_t spi_speed;
188  spi_master_mode_t spi_mode;
189  spi_master_chip_select_polarity_t cs_polarity;
191 } rtc12_cfg_t;
192 
197 typedef struct
198 {
199  uint8_t hours;
200  uint8_t min;
201  uint8_t sec;
202 
203 } rtc12_time_t;
204 
209 typedef struct
210 {
211  uint8_t year;
212  uint8_t month;
213  uint8_t day;
214  uint8_t day_of_week;
215 
216 
217 } rtc12_date_t;
218 
223 typedef struct
224 {
225  uint8_t day;
226  uint8_t hours;
227  uint8_t min;
228  uint8_t sec;
229  uint8_t alarm_rate;
230 
231 } rtc12_alarm_t;
232 
237 typedef struct
238 {
239  uint8_t eosc;
240  uint8_t dosf;
241  uint8_t egfil;
242  uint8_t sqw;
243  uint8_t intcn;
244  uint8_t a1ie;
245  uint8_t a0ie;
246 
248 
249 
254 typedef enum
255 {
256  RTC12_OK = 0,
257  RTC12_ERROR = -1
258 
260 
277 
292 err_t rtc12_init ( rtc12_t *ctx, rtc12_cfg_t *cfg );
293 
307 err_t rtc12_default_cfg ( rtc12_t *ctx );
308 
324 err_t rtc12_generic_write ( rtc12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
325 
341 err_t rtc12_generic_read ( rtc12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
342 
357 err_t rtc12_set_ctrl_reg ( rtc12_t *ctx, rtc12_control_t rtc_ctrl );
358 
373 err_t rtc12_get_ctrl_reg ( rtc12_t *ctx, rtc12_control_t *rtc_ctrl );
374 
389 err_t rtc12_get_time ( rtc12_t *ctx, rtc12_time_t *rtc_time );
390 
405 err_t rtc12_set_time ( rtc12_t *ctx, rtc12_time_t rtc_time );
406 
421 err_t rtc12_get_date ( rtc12_t *ctx, rtc12_date_t *rtc_date );
422 
437 err_t rtc12_set_date ( rtc12_t *ctx, rtc12_date_t rtc_date );
438 
453 err_t rtc12_get_alarm_0 ( rtc12_t *ctx, rtc12_alarm_t *rtc_alarm );
454 
469 err_t rtc12_set_alarm_0 ( rtc12_t *ctx, rtc12_alarm_t rtc_alarm );
470 
485 err_t rtc12_get_alarm_1 ( rtc12_t *ctx, rtc12_alarm_t *rtc_alarm );
486 
501 err_t rtc12_set_alarm_1 ( rtc12_t *ctx, rtc12_alarm_t rtc_alarm );
502 
516 uint8_t rtc12_check_int ( rtc12_t *ctx );
517 
532 
533 #ifdef __cplusplus
534 }
535 #endif
536 #endif // RTC12_H
537  // rtc12
539 
540 // ------------------------------------------------------------------------ END
rtc12_control_t::intcn
uint8_t intcn
Definition: rtc12.h:243
rtc12_t::spi
spi_master_t spi
Definition: rtc12.h:161
rtc12_t::chip_select
pin_name_t chip_select
Definition: rtc12.h:163
RTC12_ERROR
@ RTC12_ERROR
Definition: rtc12.h:257
rtc12_set_date
err_t rtc12_set_date(rtc12_t *ctx, rtc12_date_t rtc_date)
RTC 12 get time function.
rtc12_control_t
RTC 12 Click control object.
Definition: rtc12.h:238
rtc12_generic_read
err_t rtc12_generic_read(rtc12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 12 data reading function.
rtc12_get_ctrl_reg
err_t rtc12_get_ctrl_reg(rtc12_t *ctx, rtc12_control_t *rtc_ctrl)
RTC 12 get control register function.
rtc12_set_alarm_0
err_t rtc12_set_alarm_0(rtc12_t *ctx, rtc12_alarm_t rtc_alarm)
RTC 12 get alarm 0 function.
rtc12_cfg_t::pf
pin_name_t pf
Definition: rtc12.h:182
rtc12_date_t::day
uint8_t day
Definition: rtc12.h:213
rtc12_return_value_t
rtc12_return_value_t
RTC 12 Click return value data.
Definition: rtc12.h:255
rtc12_cfg_t::mosi
pin_name_t mosi
Definition: rtc12.h:176
RTC12_OK
@ RTC12_OK
Definition: rtc12.h:256
rtc12_cfg_t::cs
pin_name_t cs
Definition: rtc12.h:178
rtc12_default_cfg
err_t rtc12_default_cfg(rtc12_t *ctx)
RTC 12 default configuration function.
rtc12_cfg_t::miso
pin_name_t miso
Definition: rtc12.h:175
rtc12_set_ctrl_reg
err_t rtc12_set_ctrl_reg(rtc12_t *ctx, rtc12_control_t rtc_ctrl)
RTC 12 set control register function.
rtc12_date_t::month
uint8_t month
Definition: rtc12.h:212
rtc12_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc12.h:183
rtc12_generic_write
err_t rtc12_generic_write(rtc12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 12 data writing function.
rtc12_init
err_t rtc12_init(rtc12_t *ctx, rtc12_cfg_t *cfg)
RTC 12 initialization function.
rtc12_time_t::min
uint8_t min
Definition: rtc12.h:200
rtc12_time_t::hours
uint8_t hours
Definition: rtc12.h:199
rtc12_cfg_t::sck
pin_name_t sck
Definition: rtc12.h:177
rtc12_control_t::a1ie
uint8_t a1ie
Definition: rtc12.h:244
rtc12_date_t::year
uint8_t year
Definition: rtc12.h:211
rtc12_t
RTC 12 Click context object.
Definition: rtc12.h:153
rtc12_control_t::eosc
uint8_t eosc
Definition: rtc12.h:239
rtc12_alarm_t::min
uint8_t min
Definition: rtc12.h:227
rtc12_set_time
err_t rtc12_set_time(rtc12_t *ctx, rtc12_time_t rtc_time)
RTC 12 set time function.
rtc12_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc12.h:189
rtc12_t::pf
digital_in_t pf
Definition: rtc12.h:156
rtc12_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtc12.h:187
rtc12_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtc12.h:188
rtc12_get_time
err_t rtc12_get_time(rtc12_t *ctx, rtc12_time_t *rtc_time)
RTC 12 get time function.
rtc12_cfg_setup
void rtc12_cfg_setup(rtc12_cfg_t *cfg)
RTC 12 configuration object setup function.
rtc12_cfg_t
RTC 12 Click configuration object.
Definition: rtc12.h:172
rtc12_alarm_t::hours
uint8_t hours
Definition: rtc12.h:226
rtc12_control_t::dosf
uint8_t dosf
Definition: rtc12.h:240
rtc12_get_date
err_t rtc12_get_date(rtc12_t *ctx, rtc12_date_t *rtc_date)
RTC 12 get date function.
rtc12_set_alarm_1
err_t rtc12_set_alarm_1(rtc12_t *ctx, rtc12_alarm_t rtc_alarm)
RTC 12 get alarm 1 function.
rtc12_alarm_t
RTC 12 Click alarm object.
Definition: rtc12.h:224
rtc12_control_t::sqw
uint8_t sqw
Definition: rtc12.h:242
rtc12_alarm_t::day
uint8_t day
Definition: rtc12.h:225
rtc12_t::int_pin
digital_in_t int_pin
Definition: rtc12.h:157
rtc12_alarm_t::alarm_rate
uint8_t alarm_rate
Definition: rtc12.h:229
rtc12_control_t::a0ie
uint8_t a0ie
Definition: rtc12.h:245
rtc12_time_t
RTC 12 Click time object.
Definition: rtc12.h:198
rtc12_alarm_t::sec
uint8_t sec
Definition: rtc12.h:228
rtc12_date_t::day_of_week
uint8_t day_of_week
Definition: rtc12.h:214
rtc12_check_power_fail
uint8_t rtc12_check_power_fail(rtc12_t *ctx)
RTC 12 check power fail state function.
rtc12_time_t::sec
uint8_t sec
Definition: rtc12.h:201
rtc12_date_t
RTC 12 Click date object.
Definition: rtc12.h:210
rtc12_get_alarm_0
err_t rtc12_get_alarm_0(rtc12_t *ctx, rtc12_alarm_t *rtc_alarm)
RTC 12 get alarm 0 function.
rtc12_get_alarm_1
err_t rtc12_get_alarm_1(rtc12_t *ctx, rtc12_alarm_t *rtc_alarm)
RTC 12 get alarm 1 function.
rtc12_check_int
uint8_t rtc12_check_int(rtc12_t *ctx)
RTC 12 check interrupt state function.
rtc12_control_t::egfil
uint8_t egfil
Definition: rtc12.h:241