forked from nimaltd/ds18b20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onewire.h
71 lines (59 loc) · 2.4 KB
/
onewire.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef ONEWIRE_H
#define ONEWIRE_H
/* C++ detection */
#ifdef __cplusplus
extern "C" {
#endif
#include "gpio.h"
#if (_DS18B20_USE_FREERTOS==1)
#include "cmsis_os.h"
#define OneWireDelay(x) osDelay(x)
#else
#define OneWireDelay(x) HAL_Delay(x)
#endif
typedef struct {
GPIO_TypeDef* GPIOx; /*!< GPIOx port to be used for I/O functions */
uint16_t GPIO_Pin; /*!< GPIO Pin to be used for I/O functions */
uint8_t LastDiscrepancy; /*!< Search private */
uint8_t LastFamilyDiscrepancy; /*!< Search private */
uint8_t LastDeviceFlag; /*!< Search private */
uint8_t ROM_NO[8]; /*!< 8-bytes address of last search device */
} OneWire_t;
/* OneWire delay */
void ONEWIRE_DELAY(uint16_t time_us);
/* Pin settings */
void ONEWIRE_LOW(OneWire_t *gp);
void ONEWIRE_HIGH(OneWire_t *gp);
void ONEWIRE_INPUT(OneWire_t *gp);
void ONEWIRE_OUTPUT(OneWire_t *gp);
/* OneWire commands */
#define ONEWIRE_CMD_RSCRATCHPAD 0xBE
#define ONEWIRE_CMD_WSCRATCHPAD 0x4E
#define ONEWIRE_CMD_CPYSCRATCHPAD 0x48
#define ONEWIRE_CMD_RECEEPROM 0xB8
#define ONEWIRE_CMD_RPWRSUPPLY 0xB4
#define ONEWIRE_CMD_SEARCHROM 0xF0
#define ONEWIRE_CMD_READROM 0x33
#define ONEWIRE_CMD_MATCHROM 0x55
#define ONEWIRE_CMD_SKIPROM 0xCC
//#######################################################################################################
void OneWire_Init(OneWire_t* OneWireStruct, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint8_t OneWire_Reset(OneWire_t* OneWireStruct);
uint8_t OneWire_ReadByte(OneWire_t* OneWireStruct);
void OneWire_WriteByte(OneWire_t* OneWireStruct, uint8_t byte);
void OneWire_WriteBit(OneWire_t* OneWireStruct, uint8_t bit);
uint8_t OneWire_ReadBit(OneWire_t* OneWireStruct);
uint8_t OneWire_Search(OneWire_t* OneWireStruct, uint8_t command);
void OneWire_ResetSearch(OneWire_t* OneWireStruct);
uint8_t OneWire_First(OneWire_t* OneWireStruct);
uint8_t OneWire_Next(OneWire_t* OneWireStruct);
void OneWire_GetFullROM(OneWire_t* OneWireStruct, uint8_t *firstIndex);
void OneWire_Select(OneWire_t* OneWireStruct, uint8_t* addr);
void OneWire_SelectWithPointer(OneWire_t* OneWireStruct, uint8_t* ROM);
uint8_t OneWire_CRC8(uint8_t* addr, uint8_t len);
//#######################################################################################################
/* C++ detection */
#ifdef __cplusplus
}
#endif
#endif