4 #include "drivers/bus.h"
8 #define OW_STATUS_1WB_POS 0 // 1-Wire busy
9 #define OW_STATUS_PPD_POS 1 // Presense-pulse detect
10 #define OW_STATUS_SD_POS 2 // Short detected
11 #define OW_STATUS_LL_POS 3 // Logic level
12 #define OW_STATUS_RST_POS 4 // Device reset
13 #define OW_STATUS_SBR_POS 5 // Single bit result
14 #define OW_STATUS_TSB_POS 6 // Triplet second bit
15 #define OW_STATUS_DIR_POS 7 // Branch direction taken
17 #define OW_BUS_BUSY(status) (status & (1 << OW_STATUS_1WB_POS))
18 #define OW_DEVICE_PRESENT(status) (status & (1 << OW_STATUS_PPD_POS)) // True if a device have been detected on the bus after a bus reset
19 #define OW_RESET(status) (status & (1 << OW_STATUS_RST_POS))
20 #define OW_LOGIC_LEVEL(status) (status & (1 << OW_STATUS_LL_POS))
21 #define OW_SHORT_DETECTED(status) (status & (1 << OW_STATUS_SD_POS))
22 #define OW_SBR_VALUE(status) ((status >> OW_STATUS_SBR_POS) & 1) // Extract single bit read value or triplet first bit from status register value
23 #define OW_TSB_VALUE(status) ((status >> OW_STATUS_TSB_POS) & 1) // Extract triplet second bit value from status register value
24 #define OW_DIR_VALUE(status) ((status >> OW_STATUS_DIR_POS) & 1) // Extract triplet chosen direction bit value from status register value
26 #define OW_TRIPLET_FIRST_BIT(tripletResult) (tripletResult & (1 << 0))
27 #define OW_TRIPLET_SECOND_BIT(tripletResult) (tripletResult & (1 << 1))
28 #define OW_TRIPLET_DIRECTION_BIT(tripletResult) (tripletResult & (1 << 2))
30 #define OW_SINGLE_BIT_WRITE0 0
31 #define OW_SINGLE_BIT_WRITE1_READ (1<<7)
33 typedef struct owDev_s
{
38 bool (*reset
)(struct owDev_s
*owDev
);
39 bool (*owResetCommand
)(struct owDev_s
*owDev
);
40 bool (*owReset
)(struct owDev_s
*owDev
);
41 bool (*waitForBus
)(struct owDev_s
*owDev
);
42 bool (*readConfig
)(struct owDev_s
*owDev
, uint8_t *config
);
43 bool (*writeConfig
)(struct owDev_s
*owDev
, uint8_t config
);
44 bool (*readStatus
)(struct owDev_s
*owDev
, uint8_t *status
);
45 uint8_t (*getStatus
)(struct owDev_s
*owDev
);
46 bool (*poll
)(struct owDev_s
*owDev
, bool waitForBus
, uint8_t *status
);
47 bool (*owBusReady
)(struct owDev_s
*owDev
);
50 bool (*owSearchRom
)(struct owDev_s
*owDev
, uint8_t familyCode
, uint64_t *romTable
, uint8_t *romTableLen
);
51 bool (*owMatchRomCommand
)(struct owDev_s
*owDev
);
52 bool (*owMatchRom
)(struct owDev_s
*owDev
, uint64_t rom
);
53 bool (*owSkipRomCommand
)(struct owDev_s
*owDev
);
54 bool (*owSkipRom
)(struct owDev_s
*owDev
);
57 bool (*owWriteByteCommand
)(struct owDev_s
*owDev
, uint8_t byte
);
58 bool (*owWriteByte
)(struct owDev_s
*owDev
, uint8_t byte
);
59 bool (*owWriteBuf
)(struct owDev_s
*owDev
, const uint8_t *buf
, uint8_t len
);
60 bool (*owReadByteCommand
)(struct owDev_s
*owDev
);
61 bool (*owReadByteResult
)(struct owDev_s
*owDev
, uint8_t *result
);
62 bool (*owReadByte
)(struct owDev_s
*owDev
, uint8_t *result
);
63 bool (*owReadBuf
)(struct owDev_s
*owDev
, uint8_t *buf
, uint8_t len
);
64 bool (*owSingleBitCommand
)(struct owDev_s
*owDev
, uint8_t type
);
65 bool (*owSingleBitResult
)(struct owDev_s
*owDev
);
66 bool (*owSingleBit
)(struct owDev_s
*owDev
, uint8_t type
, bool *result
);
67 bool (*owTripletCommand
)(struct owDev_s
*owDev
, uint8_t direction
);
68 uint8_t (*owTripletResult
)(struct owDev_s
*owDev
);
69 bool (*owTriplet
)(struct owDev_s
*owDev
, uint8_t direction
, uint8_t *result
);
73 owDev_t
*getOwDev(void);
75 #endif /* defined(USE_1WIRE) && defined(USE_1WIRE_DS2482) */