added 'parasitic' config field

sipo
Ondřej Hruška 7 years ago
parent eca8319820
commit c641bef80a
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      units/1wire/_ow_internal.h
  2. 15
      units/1wire/unit_1wire.c

@ -15,6 +15,7 @@
struct priv { struct priv {
char port_name; char port_name;
uint8_t pin_number; uint8_t pin_number;
bool parasitic;
GPIO_TypeDef *port; GPIO_TypeDef *port;
uint32_t ll_pin; uint32_t ll_pin;

@ -23,6 +23,9 @@ static void U1WIRE_loadBinary(Unit *unit, PayloadParser *pp)
priv->port_name = pp_char(pp); priv->port_name = pp_char(pp);
priv->pin_number = pp_u8(pp); priv->pin_number = pp_u8(pp);
if (version >= 1) {
priv->parasitic = pp_bool(pp);
}
} }
/** Write to a binary buffer for storing in Flash */ /** 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; struct priv *priv = unit->data;
pb_u8(pb, 0); // version pb_u8(pb, 1); // version
pb_char(pb, priv->port_name); pb_char(pb, priv->port_name);
pb_u8(pb, priv->pin_number); 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")) { if (streq(key, "pin")) {
suc = parse_pin(value, &priv->port_name, &priv->pin_number); suc = parse_pin(value, &priv->port_name, &priv->pin_number);
} }
else if (streq(key, "parasitic")) {
priv->parasitic = str_parse_yn(value, &suc);
}
else { else {
return E_BAD_KEY; return E_BAD_KEY;
} }
@ -62,6 +69,9 @@ static void U1WIRE_writeIni(Unit *unit, IniWriter *iw)
iw_comment(iw, "Data pin"); iw_comment(iw, "Data pin");
iw_entry(iw, "pin", "%c%d", priv->port_name, priv->pin_number); 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 // some defaults
priv->pin_number = 0; priv->pin_number = 0;
priv->port_name = 'A'; priv->port_name = 'A';
priv->parasitic = false;
return E_SUCCESS; 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); ow_write_u8(unit, OW_DS1820_CONVERT_T);
while (!ow_read_bit(unit)); 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); // osDelay(750);
// TODO this will be done with an async timer // TODO this will be done with an async timer
// If parasitive power is not used, we could poll and check the status bit // If parasitive power is not used, we could poll and check the status bit

Loading…
Cancel
Save