LibDriver BPC
Loading...
Searching...
No Matches
driver_bpc_basic.c
Go to the documentation of this file.
1
36
37#include "driver_bpc_basic.h"
38
39static bpc_handle_t gs_handle;
40static int8_t gs_time_zone = 0;
41
50{
51 if (bpc_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55
56 return 0;
57}
58
67uint8_t bpc_basic_init(void (*callback)(bpc_t *data))
68{
69 uint8_t res;
70
71 /* link interface function */
76 DRIVER_BPC_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
77
78 /* init */
79 res = bpc_init(&gs_handle);
80 if (res != 0)
81 {
82 bpc_interface_debug_print("bpc: init failed.\n");
83
84 return 1;
85 }
86
87 return 0;
88}
89
97uint8_t bpc_basic_deinit(void)
98{
99 if (bpc_deinit(&gs_handle) != 0)
100 {
101 return 1;
102 }
103
104 return 0;
105}
106
115{
116 gs_time_zone = zone;
117
118 return 0;
119}
120
129{
130 *zone = gs_time_zone;
131
132 return 0;
133}
134
144uint8_t bpc_basic_convert_timestamp(bpc_t *t, time_t *timestamp)
145{
146 struct tm timeptr;
147
148 timeptr.tm_year = t->year - 1900;
149 timeptr.tm_mon = t->month - 1;
150 timeptr.tm_wday = t->week;
151 timeptr.tm_mday = t->day;
152 timeptr.tm_hour = t->hour;
153 timeptr.tm_min = t->minute;
154 timeptr.tm_sec = t->second;
155
156 /* make time */
157 *timestamp = mktime(&timeptr) - gs_time_zone * 3600;
158
159 return 0;
160}
driver bpc basic header file
uint8_t bpc_irq_handler(bpc_handle_t *handle)
irq handler
uint8_t bpc_init(bpc_handle_t *handle)
initialize the chip
struct bpc_handle_s bpc_handle_t
bpc handle structure definition
struct bpc_s bpc_t
bpc structure definition
uint8_t bpc_deinit(bpc_handle_t *handle)
close the chip
uint8_t bpc_basic_deinit(void)
basic example deinit
uint8_t bpc_basic_convert_timestamp(bpc_t *t, time_t *timestamp)
basic example convert the time to a unix timestamp
uint8_t bpc_basic_irq_handler(void)
basic irq
uint8_t bpc_basic_get_timestamp_time_zone(int8_t *zone)
basic example get the local time zone
uint8_t bpc_basic_set_timestamp_time_zone(int8_t zone)
basic example set the local time zone
uint8_t bpc_basic_init(void(*callback)(bpc_t *data))
basic example init
uint8_t bpc_interface_timestamp_read(bpc_time_t *t)
interface timestamp read
void bpc_interface_delay_ms(uint32_t ms)
interface delay ms
void bpc_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t month
Definition driver_bpc.h:90
uint8_t week
Definition driver_bpc.h:92
uint16_t year
Definition driver_bpc.h:89
uint8_t day
Definition driver_bpc.h:91
uint8_t second
Definition driver_bpc.h:95
uint8_t minute
Definition driver_bpc.h:94
uint8_t hour
Definition driver_bpc.h:93