LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20.h
Go to the documentation of this file.
1
37
38#ifndef DRIVER_DS18B20_H
39#define DRIVER_DS18B20_H
40
41#include <stdint.h>
42#include <stdio.h>
43#include <string.h>
44
45#ifdef __cplusplus
46extern "C"{
47#endif
48
54
59
63#ifndef DS18B20_MAX_SEARCH_SIZE
64 #define DS18B20_MAX_SEARCH_SIZE 64
65#endif
66
70
75
84
93
104
108typedef struct ds18b20_handle_s
109{
110 uint8_t (*bus_init)(void);
111 uint8_t (*bus_deinit)(void);
112 uint8_t (*bus_read)(uint8_t *value);
113 uint8_t (*bus_write)(uint8_t value);
114 void (*delay_ms)(uint32_t ms);
115 void (*delay_us)(uint32_t us);
116 void (*enable_irq)(void);
117 void (*disable_irq)(void);
118 void (*debug_print)(const char *const fmt, ...);
119 uint8_t inited;
120 uint8_t mode;
121 uint8_t rom[8];
123
139
143
150
157#define DRIVER_DS18B20_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
158
165#define DRIVER_DS18B20_LINK_BUS_INIT(HANDLE, FUC) (HANDLE)->bus_init = FUC
166
173#define DRIVER_DS18B20_LINK_BUS_DEINIT(HANDLE, FUC) (HANDLE)->bus_deinit = FUC
174
181#define DRIVER_DS18B20_LINK_BUS_READ(HANDLE, FUC) (HANDLE)->bus_read = FUC
182
189#define DRIVER_DS18B20_LINK_BUS_WRITE(HANDLE, FUC) (HANDLE)->bus_write = FUC
190
197#define DRIVER_DS18B20_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
198
205#define DRIVER_DS18B20_LINK_DELAY_US(HANDLE, FUC) (HANDLE)->delay_us = FUC
206
213#define DRIVER_DS18B20_LINK_ENABLE_IRQ(HANDLE, FUC) (HANDLE)->enable_irq = FUC
214
221#define DRIVER_DS18B20_LINK_DISABLE_IRQ(HANDLE, FUC) (HANDLE)->disable_irq = FUC
222
229#define DRIVER_DS18B20_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
230
234
241
250uint8_t ds18b20_info(ds18b20_info_t *info);
251
263uint8_t ds18b20_init(ds18b20_handle_t *handle);
264
275uint8_t ds18b20_deinit(ds18b20_handle_t *handle);
276
289uint8_t ds18b20_read(ds18b20_handle_t *handle, int16_t *raw, float *temp);
290
302
313uint8_t ds18b20_get_mode(ds18b20_handle_t *handle, ds18b20_mode_t *mode);
314
325uint8_t ds18b20_set_rom(ds18b20_handle_t *handle, uint8_t rom[8]);
326
337uint8_t ds18b20_get_rom(ds18b20_handle_t *handle, uint8_t rom[8]);
338
351
364
376
388
392
399
412uint8_t ds18b20_scratchpad_set_alarm_threshold(ds18b20_handle_t *handle, int8_t threshold_high, int8_t threshold_low);
413
426uint8_t ds18b20_scrachpad_get_alarm_threshold(ds18b20_handle_t *handle, int8_t *threshold_high, int8_t *threshold_low);
427
439uint8_t ds18b20_alarm_convert_to_register(ds18b20_handle_t *handle, float temp, int8_t *reg);
440
452uint8_t ds18b20_alarm_convert_to_data(ds18b20_handle_t *handle, int8_t reg, float *temp);
453
464uint8_t ds18b20_search_rom(ds18b20_handle_t *handle, uint8_t (*rom)[8], uint8_t *num);
465
476uint8_t ds18b20_search_alarm(ds18b20_handle_t *handle, uint8_t (*rom)[8], uint8_t *num);
477
488
492
496
497#ifdef __cplusplus
498}
499#endif
500
501#endif
uint8_t ds18b20_alarm_convert_to_data(ds18b20_handle_t *handle, int8_t reg, float *temp)
convert the register data to the alarm temperature
uint8_t ds18b20_search_alarm(ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
search the ds18b20 alarm rom
uint8_t ds18b20_get_power_mode(ds18b20_handle_t *handle, ds18b20_power_mode_t *power_mode)
get the power mode
uint8_t ds18b20_search_rom(ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
search the ds18b20 rom
uint8_t ds18b20_scrachpad_get_alarm_threshold(ds18b20_handle_t *handle, int8_t *threshold_high, int8_t *threshold_low)
get the alarm threshold in the scratchpad
uint8_t ds18b20_scratchpad_set_alarm_threshold(ds18b20_handle_t *handle, int8_t threshold_high, int8_t threshold_low)
set the alarm threshold in the scratchpad
uint8_t ds18b20_alarm_convert_to_register(ds18b20_handle_t *handle, float temp, int8_t *reg)
convert the alarm temperature to the register data
uint8_t ds18b20_scratchpad_get_resolution(ds18b20_handle_t *handle, ds18b20_resolution_t *resolution)
get the resolution in the scratchpad
ds18b20_power_mode_t
ds18b20 power mode enumeration definition
uint8_t ds18b20_init(ds18b20_handle_t *handle)
initialize the chip
uint8_t ds18b20_set_rom(ds18b20_handle_t *handle, uint8_t rom[8])
set the handle rom
uint8_t ds18b20_copy_eeprom_to_scratchpad(ds18b20_handle_t *handle)
copy the eeprom content to the scratchpad
uint8_t ds18b20_copy_scratchpad_to_eeprom(ds18b20_handle_t *handle)
copy the scratchpad content to the eeprom
ds18b20_resolution_t
ds18b20 resolution enumeration definition
uint8_t ds18b20_info(ds18b20_info_t *info)
get chip's information
uint8_t ds18b20_read(ds18b20_handle_t *handle, int16_t *raw, float *temp)
read data from the chip
uint8_t ds18b20_scratchpad_set_resolution(ds18b20_handle_t *handle, ds18b20_resolution_t resolution)
set the resolution in the scratchpad
struct ds18b20_handle_s ds18b20_handle_t
ds18b20 handle structure definition
ds18b20_mode_t
ds18b20 mode enumeration definition
uint8_t ds18b20_deinit(ds18b20_handle_t *handle)
close the chip
uint8_t ds18b20_get_mode(ds18b20_handle_t *handle, ds18b20_mode_t *mode)
get the chip mode
uint8_t ds18b20_set_mode(ds18b20_handle_t *handle, ds18b20_mode_t mode)
set the chip mode
struct ds18b20_info_s ds18b20_info_t
ds18b20 info structure definition
uint8_t ds18b20_get_rom(ds18b20_handle_t *handle, uint8_t rom[8])
get the chip rom
@ DS18B20_POWER_MODE_PARASITE
@ DS18B20_POWER_MODE_EXTERNALLY
@ DS18B20_RESOLUTION_11BIT
@ DS18B20_RESOLUTION_9BIT
@ DS18B20_RESOLUTION_10BIT
@ DS18B20_RESOLUTION_12BIT
@ DS18B20_MODE_SKIP_ROM
@ DS18B20_MODE_MATCH_ROM
ds18b20 handle structure definition
void(* enable_irq)(void)
uint8_t(* bus_deinit)(void)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
void(* delay_us)(uint32_t us)
void(* disable_irq)(void)
uint8_t(* bus_read)(uint8_t *value)
uint8_t(* bus_write)(uint8_t value)
uint8_t(* bus_init)(void)
ds18b20 info structure definition
uint32_t driver_version
char manufacturer_name[32]