LibDriver DS1307
Loading...
Searching...
No Matches
driver_ds1307.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_DS1307_H
38#define DRIVER_DS1307_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
67
71typedef enum
72{
73 DS1307_AM = 0x00,
74 DS1307_PM = 0x01,
76
80typedef enum
81{
85
94
103
114
118typedef struct ds1307_time_s
119{
120 uint16_t year;
121 uint8_t month;
122 uint8_t week;
123 uint8_t date;
124 uint8_t hour;
125 uint8_t minute;
126 uint8_t second;
130
134typedef struct ds1307_handle_s
135{
136 uint8_t (*iic_init)(void);
137 uint8_t (*iic_deinit)(void);
138 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
139 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
140 void (*debug_print)(const char *const fmt, ...);
141 void (*delay_ms)(uint32_t ms);
142 uint8_t inited;
144
160
164
171
178#define DRIVER_DS1307_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
179
186#define DRIVER_DS1307_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
187
194#define DRIVER_DS1307_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
195
202#define DRIVER_DS1307_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
203
210#define DRIVER_DS1307_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
211
218#define DRIVER_DS1307_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
219
226#define DRIVER_DS1307_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
227
231
238
247uint8_t ds1307_info(ds1307_info_t *info);
248
259uint8_t ds1307_init(ds1307_handle_t *handle);
260
271uint8_t ds1307_deinit(ds1307_handle_t *handle);
272
286
299
315uint8_t ds1307_read_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len);
316
332uint8_t ds1307_write_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len);
333
346
358uint8_t ds1307_get_oscillator(ds1307_handle_t *handle, ds1307_bool_t *enable);
359
372
385
398
411
424
437
441
448
462uint8_t ds1307_set_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
463
477uint8_t ds1307_get_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
478
482
486
487#ifdef __cplusplus
488}
489#endif
490
491#endif
uint8_t ds1307_info(ds1307_info_t *info)
get chip's information
ds1307_am_pm_t
ds1307 am pm enumeration definition
struct ds1307_info_s ds1307_info_t
ds1307 information structure definition
uint8_t ds1307_get_output_level(ds1307_handle_t *handle, ds1307_output_level_t *level)
get the output level
struct ds1307_handle_s ds1307_handle_t
ds1307 handle structure definition
ds1307_square_wave_frequency_t
ds1307 square wave frequency enumeration definition
uint8_t ds1307_get_square_wave_frequency(ds1307_handle_t *handle, ds1307_square_wave_frequency_t *freq)
get the square wave frequency
ds1307_format_t
ds1307 format enumeration definition
uint8_t ds1307_read_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
read ram
uint8_t ds1307_get_oscillator(ds1307_handle_t *handle, ds1307_bool_t *enable)
get the chip oscillator status
uint8_t ds1307_set_output_mode(ds1307_handle_t *handle, ds1307_output_mode_t mode)
set the output mode
struct ds1307_time_s ds1307_time_t
ds1307 time structure definition
uint8_t ds1307_get_output_mode(ds1307_handle_t *handle, ds1307_output_mode_t *mode)
get the output mode
uint8_t ds1307_set_oscillator(ds1307_handle_t *handle, ds1307_bool_t enable)
enable or disable the oscillator
uint8_t ds1307_init(ds1307_handle_t *handle)
initialize the chip
uint8_t ds1307_set_time(ds1307_handle_t *handle, ds1307_time_t *t)
set the current time
ds1307_output_level_t
ds1307 output level enumeration definition
uint8_t ds1307_write_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
write ram
uint8_t ds1307_set_output_level(ds1307_handle_t *handle, ds1307_output_level_t level)
set the output level
uint8_t ds1307_set_square_wave_frequency(ds1307_handle_t *handle, ds1307_square_wave_frequency_t freq)
set the square wave frequency
ds1307_bool_t
ds1307 bool enumeration definition
uint8_t ds1307_deinit(ds1307_handle_t *handle)
close the chip
uint8_t ds1307_get_time(ds1307_handle_t *handle, ds1307_time_t *t)
get the current time
ds1307_output_mode_t
ds1307 output mode enumeration definition
@ DS1307_PM
@ DS1307_AM
@ DS1307_SQUARE_WAVE_FREQUENCY_4096_HZ
@ DS1307_SQUARE_WAVE_FREQUENCY_8192_HZ
@ DS1307_SQUARE_WAVE_FREQUENCY_32768_HZ
@ DS1307_SQUARE_WAVE_FREQUENCY_1_HZ
@ DS1307_FORMAT_12H
@ DS1307_FORMAT_24H
@ DS1307_OUTPUT_LEVEL_HIGH
@ DS1307_OUTPUT_LEVEL_LOW
@ DS1307_BOOL_TRUE
@ DS1307_BOOL_FALSE
@ DS1307_OUTPUT_MODE_SQUARE_WAVE
@ DS1307_OUTPUT_MODE_LEVEL
uint8_t ds1307_get_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t ds1307_set_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
ds1307 handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
ds1307 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]
ds1307 time structure definition
ds1307_am_pm_t am_pm
ds1307_format_t format