From 872c3988bd585e27378ae9c233727b637888d300 Mon Sep 17 00:00:00 2001 From: haskal Date: Sun, 25 Jul 2021 18:45:28 -0400 Subject: [PATCH] WIP 1wire --- bsp/rp2040/m_default/1wire.c | 3 ++ src/m_default/1wire.h | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 bsp/rp2040/m_default/1wire.c create mode 100644 src/m_default/1wire.h diff --git a/bsp/rp2040/m_default/1wire.c b/bsp/rp2040/m_default/1wire.c new file mode 100644 index 0000000..97faead --- /dev/null +++ b/bsp/rp2040/m_default/1wire.c @@ -0,0 +1,3 @@ +#include + +#include "m_default/1wire.h" diff --git a/src/m_default/1wire.h b/src/m_default/1wire.h new file mode 100644 index 0000000..1bcf0ee --- /dev/null +++ b/src/m_default/1wire.h @@ -0,0 +1,54 @@ +#ifndef _1WIRE_H +#define _1WIRE_H // we're too cool for #pragma once over here? + +#include +#include +#include + +enum onewire_cmd { + // select controller or peripheral, and enable or disable overdrive mode + OW_SET_MODE = 0x00, + + // controller + OW_WRITE_READ = 0x01, + OW_READ_ROM = 0x02, + OW_MATCH_ROM = 0x03, + OW_SEARCH_ROM = 0x04, + + // peripheral + OW_SET_EMULATION_TYPE = 0x81, + OW_SET_EMULATION_DATA = 0x82, + OW_REPORT_TIMING = 0x83, // 🕵️📈 +}; + +enum onewire_mode { + OWM_CONTROLLER = 0x00, + OWM_CONTROLLER_OD = 0x10, + OWM_PERIPHERAL = 0x01, + OWM_PERIPHERAL_OD = 0x11 +}; + +enum ow_emulation_type { + DS2401 = 0x2401 + // TODO: more +}; + +// low level init (eg, load and configure PIO program on rp2040) +bool ow_bsp_init(); +// low level deinit (eg, unload PIO program on rp2040) +bool ow_bsp_deinit(); + +// write some bytes then read some bytes +bool ow_write_read(bool od, uint8_t* out, size_t out_len, uint8_t* in, size_t in_len); +// read rom (eg for 1w serial numbers / eeproms) +bool ow_read_rom(bool od, uint8_t* in, size_t in_len); +// TODO: match rom +// bool ow_match_rom(...); +// identify all connected devices +bool ow_search_rom(bool od, uint64_t* discovered_devices, size_t max_devices); + +// execute an emulation of a 1w peripheral +void ow_run_peripheral_emulation( + bool od, enum ow_emulation_type typ, uint8_t* data, size_t data_len); + +#endif