stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
Loading...
Searching...
No Matches
onewire.h
Go to the documentation of this file.
1
12
13#ifndef ONEWIRE_H
14#define ONEWIRE_H
15
16#include "ow_config.h"
17#include "ow_version.h"
18#include <stdint.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
28
30#define ONEWIRE_ROM_BYTES 8
32#define ONEWIRE_ROM_BITS (ONEWIRE_ROM_BYTES * 8)
34#define ONEWIRE_BITS_PER_BYTE 8
36#define ONEWIRE_MAX_SLOTS 256u
38#define ONEWIRE_MAX_READ_BYTES (ONEWIRE_MAX_SLOTS / ONEWIRE_BITS_PER_BYTE)
49#define ONEWIRE_RELEASE_PULSE 0u
51#define ONEWIRE_SEARCH_ROM 0xF0
53#define ONEWIRE_ALARM_SEARCH 0xEC
55#define ONEWIRE_MATCH_ROM 0x55
57#define ONEWIRE_SKIP_ROM 0xCC
82#include "ow_board.h"
83
85
90
115void onewire_init(void);
116
126uint32_t onewire_config_token(void);
127
142uint8_t onewire_clock_ok(uint32_t sysclk_mhz);
143
145
153
158uint8_t onewire_bus_done(void);
159
168void onewire_reset(volatile uint16_t* reset_pulses);
169
185
201uint8_t onewire_present(const volatile uint16_t* pulses, uint8_t captured);
202
223uint8_t onewire_write_slots(const ow_pulse_t* pulses, uint16_t slots);
224
230uint8_t onewire_write_bit(uint8_t bit);
231
237void onewire_read_pair(volatile uint16_t* pair_pulses);
238
245void onewire_pair_bits(const volatile uint16_t* pair_pulses, uint8_t* id_bit, uint8_t* cmp_bit);
246
258void onewire_write_then_read(uint8_t bit);
259
275uint8_t onewire_read_data(volatile uint8_t* dst, uint8_t bytes);
276
283static inline uint8_t onewire_bit_from_pulse(uint16_t dur) {
284 return (dur <= ONEWIRE_SHORT_PULSE_MAX) ? 1u : 0u;
285}
286
297void onewire_decode_pulses(uint8_t* dst, const volatile uint8_t* pulse, uint8_t nbytes);
298
304void onewire_encode_byte(ow_pulse_t* out, uint8_t byte);
305
318void onewire_strong_pullup(uint8_t on);
319
320#if OW_LOW_POWER
333uint8_t onewire_long_wait_pending(void);
334
348void onewire_sleep_until_done(void);
349#endif
350
352
365
367typedef uint8_t (*onewire_search_sink_t)(const uint8_t* rom);
368
382void onewire_search_start(onewire_search_sink_t sink, uint8_t max_devices,
383 uint8_t command, uint8_t family);
384
390
396
402
404
409
416uint8_t onewire_crc8(const uint8_t* data, uint8_t len);
417
429uint16_t onewire_crc16(const uint8_t* data, uint8_t len);
430
432
433#ifdef __cplusplus
434}
435#endif
436
437#endif /* ONEWIRE_H */
void onewire_encode_byte(ow_pulse_t *out, uint8_t byte)
Encode a byte into write-pulse durations.
void onewire_read_pair(volatile uint16_t *pair_pulses)
Schedule a two-slot read of a Search ROM id/cmp bit pair.
uint8_t onewire_reset_captured(void)
Edges captured by the last capture operation armed.
void onewire_pair_bits(const volatile uint16_t *pair_pulses, uint8_t *id_bit, uint8_t *cmp_bit)
Decode the id/cmp bits of a two-slot read pair.
uint8_t onewire_bus_done(void)
Non-blocking completion check for the scheduled bus operation.
void onewire_strong_pullup(uint8_t on)
Engage or release the parasite-power strong pull-up on the bus.
void onewire_write_then_read(uint8_t bit)
Schedule a merged single-slot write followed by a two-slot read pair.
uint8_t onewire_present(const volatile uint16_t *pulses, uint8_t captured)
Decode the presence pulse captured by onewire_reset().
void onewire_reset(volatile uint16_t *reset_pulses)
Schedule a 1-Wire bus reset (presence pulse captured via DMA).
uint8_t onewire_read_data(volatile uint8_t *dst, uint8_t bytes)
Schedule a read of bytes bytes from the bus.
uint8_t onewire_write_slots(const ow_pulse_t *pulses, uint16_t slots)
Schedule a write of slots bit slots.
uint8_t onewire_write_bit(uint8_t bit)
Schedule a single-slot write of one raw bit.
void onewire_decode_pulses(uint8_t *dst, const volatile uint8_t *pulse, uint8_t nbytes)
Decode captured pulse durations into data bytes (LSB-first bits).
uint16_t onewire_crc16(const uint8_t *data, uint8_t len)
Calculate the Maxim 1-Wire CRC-16 over a byte buffer.
uint8_t onewire_crc8(const uint8_t *data, uint8_t len)
Calculate the Dallas/Maxim 1-Wire CRC-8 over a byte buffer.
uint32_t onewire_config_token(void)
Configuration token the library was compiled with.
uint8_t onewire_clock_ok(uint32_t sysclk_mhz)
Whether the runtime core clock agrees with the build.
void onewire_init(void)
Initialize the shared 1-Wire timer/DMA/GPIO resources.
uint8_t onewire_search_count(void)
Number of devices found (valid once the search finished).
uint8_t onewire_search_active(void)
Check whether a search is currently running.
uint8_t(* onewire_search_sink_t)(const uint8_t *rom)
Per-device callback invoked by the search engine.
Definition onewire.h:367
void onewire_search_start(onewire_search_sink_t sink, uint8_t max_devices, uint8_t command, uint8_t family)
Start a non-blocking search (Search ROM or Alarm Search).
uint8_t onewire_search_poll(void)
Advance the non-blocking search by one hardware operation.
Public board-level facts for the non-blocking 1-Wire layer.
uint8_t ow_pulse_t
DMA feed entry width of the active family.
Definition ow_board.h:135
Central compile-time configuration for the 1-Wire stack.
#define ONEWIRE_SHORT_PULSE_MAX
Upper bound (in µs) for the short-pulse detection window.
Definition ow_config.h:122
Library version (semantic versioning).