LibDriver RX8025T
Loading...
Searching...
No Matches
driver_rx8025t_basic.c
Go to the documentation of this file.
1
36
38
39static rx8025t_handle_t gs_handle;
40static int8_t gs_time_zone = 0;
41
49uint8_t rx8025t_basic_init(void)
50{
51 uint8_t res;
52
53 /* link functions */
62
63 /* init rx8025t */
64 res = rx8025t_init(&gs_handle);
65 if (res != 0)
66 {
67 rx8025t_interface_debug_print("rx8025t: init failed.\n");
68
69 return 1;
70 }
71
72 /* start the clock */
73 res = rx8025t_start(&gs_handle);
74 if (res != 0)
75 {
76 rx8025t_interface_debug_print("rx8025t: start failed.\n");
77 (void)rx8025t_deinit(&gs_handle);
78
79 return 1;
80 }
81
82 /* set default temperature compensation interval */
84 if (res != 0)
85 {
86 rx8025t_interface_debug_print("rx8025t: set temperature compensation interval failed.\n");
87 (void)rx8025t_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* disable update interrupt */
94 if (res != 0)
95 {
96 rx8025t_interface_debug_print("rx8025t: set update interrupt failed.\n");
97 (void)rx8025t_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* disable timer interrupt */
104 if (res != 0)
105 {
106 rx8025t_interface_debug_print("rx8025t: set timer interrupt failed.\n");
107 (void)rx8025t_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* disable alarm interrupt */
114 if (res != 0)
115 {
116 rx8025t_interface_debug_print("rx8025t: set alarm interrupt failed.\n");
117 (void)rx8025t_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* clear flag */
123 res = rx8025t_clear_flag(&gs_handle);
124 if (res != 0)
125 {
126 rx8025t_interface_debug_print("rx8025t: clear flag failed.\n");
127 (void)rx8025t_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* disable test */
133 res = rx8025t_set_test(&gs_handle, RX8025T_BOOL_FALSE);
134 if (res != 0)
135 {
136 rx8025t_interface_debug_print("rx8025t: set test failed.\n");
137 (void)rx8025t_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* disable timer */
143 res = rx8025t_set_timer(&gs_handle, RX8025T_BOOL_FALSE);
144 if (res != 0)
145 {
146 rx8025t_interface_debug_print("rx8025t: set timer failed.\n");
147 (void)rx8025t_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 return 0;
153}
154
163{
164 if (rx8025t_deinit(&gs_handle) != 0)
165 {
166 return 1;
167 }
168
169 return 0;
170}
171
181{
182 /* set time */
183 if (rx8025t_set_time(&gs_handle, t) != 0)
184 {
185 return 1;
186 }
187
188 return 0;
189}
190
199uint8_t rx8025t_basic_set_timestamp(time_t timestamp)
200{
202 struct tm *timeptr;
203
204 /* convert times */
205 timestamp += (time_t)(gs_time_zone * 3600);
206 timeptr = localtime(&timestamp);
207 t.date = (uint8_t)timeptr->tm_mday;
208 t.hour = (uint8_t)timeptr->tm_hour;
209 t.minute = (uint8_t)timeptr->tm_min;
210 t.month = (uint8_t)timeptr->tm_mon + 1;
211 t.second = (uint8_t)timeptr->tm_sec;
212 if (timeptr->tm_wday == 0)
213 {
214 t.week = 7;
215 }
216 else
217 {
218 t.week = (uint8_t)timeptr->tm_wday;
219 }
220 t.year = (uint16_t)(timeptr->tm_year + 1900);
221
222 /* set time */
223 if (rx8025t_set_time(&gs_handle, &t) != 0)
224 {
225 return 1;
226 }
227
228 return 0;
229}
230
239{
240 gs_time_zone = zone;
241
242 return 0;
243}
244
254{
255 /* get time */
256 if (rx8025t_get_time(&gs_handle, t) != 0)
257 {
258 return 1;
259 }
260
261 return 0;
262}
263
272uint8_t rx8025t_basic_get_timestamp(time_t *timestamp)
273{
275 struct tm timeptr;
276
277 /* get time */
278 if (rx8025t_get_time(&gs_handle, &t) != 0)
279 {
280 return 1;
281 }
282 timeptr.tm_year = t.year - 1900;
283 timeptr.tm_mon = t.month - 1;
284 timeptr.tm_wday = t.week;
285 timeptr.tm_mday = t.date;
286 timeptr.tm_hour = t.hour;
287 timeptr.tm_min = t.minute;
288 timeptr.tm_sec = t.second;
289
290 /* make time */
291 *timestamp = mktime(&timeptr) - gs_time_zone * 3600;
292
293 return 0;
294}
295
304{
305 *zone = gs_time_zone;
306
307 return 0;
308}
309
319uint8_t rx8025t_basic_get_ascii_time(char *buf, uint8_t len)
320{
322
323 /* get time */
324 if (rx8025t_get_time(&gs_handle, &t) != 0)
325 {
326 return 1;
327 }
328
329 (void)snprintf(buf, len, "%04d-%02d-%02d %02d:%02d:%02d %d.\n", t.year, t.month, t.date, t.hour, t.minute, t.second, t.week);
330
331 return 0;
332}
333
342uint8_t rx8025t_basic_read_ram(uint8_t *data)
343{
344 if (rx8025t_get_ram(&gs_handle, data) != 0)
345 {
346 return 1;
347 }
348
349 return 0;
350}
351
360uint8_t rx8025t_basic_write_ram(uint8_t data)
361{
362 if (rx8025t_set_ram(&gs_handle, data) != 0)
363 {
364 return 1;
365 }
366
367 return 0;
368}
driver rx8025t basic header file
uint8_t rx8025t_set_time(rx8025t_handle_t *handle, rx8025t_time_t *t)
set the current time
uint8_t rx8025t_set_update_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable update interrupt
uint8_t rx8025t_set_ram(rx8025t_handle_t *handle, uint8_t data)
set ram
uint8_t rx8025t_set_timer_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable timer interrupt
uint8_t rx8025t_set_alarm_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable alarm interrupt
uint8_t rx8025t_start(rx8025t_handle_t *handle)
start
uint8_t rx8025t_init(rx8025t_handle_t *handle)
initialize the chip
uint8_t rx8025t_clear_flag(rx8025t_handle_t *handle)
clear flag
uint8_t rx8025t_get_ram(rx8025t_handle_t *handle, uint8_t *data)
get ram
struct rx8025t_time_s rx8025t_time_t
rx8025t time structure definition
uint8_t rx8025t_set_test(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable test
uint8_t rx8025t_get_time(rx8025t_handle_t *handle, rx8025t_time_t *t)
get the current time
uint8_t rx8025t_set_temperature_compensation_interval(rx8025t_handle_t *handle, rx8025t_temperature_compensation_interval_t interval)
set the temperature compensation interval
uint8_t rx8025t_set_timer(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable timer
struct rx8025t_handle_s rx8025t_handle_t
rx8025t handle structure definition
uint8_t rx8025t_deinit(rx8025t_handle_t *handle)
close the chip
@ RX8025T_BOOL_FALSE
uint8_t rx8025t_basic_write_ram(uint8_t data)
basic example write ram
#define RX8025T_BASIC_DEFAULT_TEMPERATURE_COMPENSATION_INTERVAL
rx8025t basic example default definition
uint8_t rx8025t_basic_get_ascii_time(char *buf, uint8_t len)
basic example get the ascii time
uint8_t rx8025t_basic_set_time(rx8025t_time_t *t)
basic example set the time
uint8_t rx8025t_basic_set_timestamp_time_zone(int8_t zone)
basic example set the local time zone
uint8_t rx8025t_basic_get_timestamp(time_t *timestamp)
basic example get the time in a unix timestamp
uint8_t rx8025t_basic_get_time(rx8025t_time_t *t)
basic example get the time
uint8_t rx8025t_basic_init(void)
basic example init
uint8_t rx8025t_basic_get_timestamp_time_zone(int8_t *zone)
basic example get the local time zone
uint8_t rx8025t_basic_read_ram(uint8_t *data)
basic example read ram
uint8_t rx8025t_basic_set_timestamp(time_t timestamp)
basic example set the time by a unix timestamp
uint8_t rx8025t_basic_deinit(void)
basic example deinit
uint8_t rx8025t_interface_iic_init(void)
interface iic bus init
uint8_t rx8025t_interface_iic_deinit(void)
interface iic bus deinit
uint8_t rx8025t_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void rx8025t_interface_debug_print(const char *const fmt,...)
interface print format data
void rx8025t_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t rx8025t_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void rx8025t_interface_delay_ms(uint32_t ms)
interface delay ms