From c641bef80a99aa40a791372528830a7c3481f6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 29 Jan 2018 22:49:18 +0100 Subject: [PATCH] added 'parasitic' config field --- units/1wire/_ow_internal.h | 1 + units/1wire/unit_1wire.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/units/1wire/_ow_internal.h b/units/1wire/_ow_internal.h index 7545d00..8a5983c 100644 --- a/units/1wire/_ow_internal.h +++ b/units/1wire/_ow_internal.h @@ -15,6 +15,7 @@ struct priv { char port_name; uint8_t pin_number; + bool parasitic; GPIO_TypeDef *port; uint32_t ll_pin; diff --git a/units/1wire/unit_1wire.c b/units/1wire/unit_1wire.c index 05b7d38..4e67960 100644 --- a/units/1wire/unit_1wire.c +++ b/units/1wire/unit_1wire.c @@ -23,6 +23,9 @@ static void U1WIRE_loadBinary(Unit *unit, PayloadParser *pp) priv->port_name = pp_char(pp); priv->pin_number = pp_u8(pp); + if (version >= 1) { + priv->parasitic = pp_bool(pp); + } } /** Write to a binary buffer for storing in Flash */ @@ -30,10 +33,11 @@ static void U1WIRE_writeBinary(Unit *unit, PayloadBuilder *pb) { struct priv *priv = unit->data; - pb_u8(pb, 0); // version + pb_u8(pb, 1); // version pb_char(pb, priv->port_name); pb_u8(pb, priv->pin_number); + pb_bool(pb, priv->parasitic); } // ------------------------------------------------------------------------ @@ -47,6 +51,9 @@ static error_t U1WIRE_loadIni(Unit *unit, const char *key, const char *value) if (streq(key, "pin")) { suc = parse_pin(value, &priv->port_name, &priv->pin_number); } + else if (streq(key, "parasitic")) { + priv->parasitic = str_parse_yn(value, &suc); + } else { return E_BAD_KEY; } @@ -62,6 +69,9 @@ static void U1WIRE_writeIni(Unit *unit, IniWriter *iw) iw_comment(iw, "Data pin"); iw_entry(iw, "pin", "%c%d", priv->port_name, priv->pin_number); + + iw_comment(iw, "Parasitic (power over DQ) mode"); + iw_entry(iw, "parasitic", str_yn(priv->parasitic)); } // ------------------------------------------------------------------------ @@ -75,6 +85,7 @@ static error_t U1WIRE_preInit(Unit *unit) // some defaults priv->pin_number = 0; priv->port_name = 'A'; + priv->parasitic = false; return E_SUCCESS; } @@ -135,6 +146,8 @@ static error_t U1WIRE_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, ow_write_u8(unit, OW_DS1820_CONVERT_T); while (!ow_read_bit(unit)); + // TODO use knowledge of the use/non-use of parasitic mode to pick the optimal strategy (non-parasitic allows polling) + // osDelay(750); // TODO this will be done with an async timer // If parasitive power is not used, we could poll and check the status bit