Просмотр исходного кода

Added the ability to work DS18x2x in two-wire mode

Victor 3 лет назад
Родитель
Сommit
54d21e823f
2 измененных файлов с 22 добавлено и 0 удалено
  1. 11 0
      interfaces/OneWireSensor.c
  2. 11 0
      interfaces/OneWireSensor.h

+ 11 - 0
interfaces/OneWireSensor.c

@@ -130,6 +130,7 @@ bool unitemp_OneWire_alloc(void* s, uint16_t* anotherValues) {
     }
     sensor->instance = instance;
 
+    instance->powerMode = PWR_ACTIVE;
     instance->gpio = unitemp_GPIO_getFromInt(anotherValues[0]);
     if(instance->gpio != NULL) {
         return true;
@@ -227,8 +228,18 @@ UnitempStatus unitemp_OneWire_update(void* s) {
         if(!oneWire_start(instance)) return UT_TIMEOUT;
         oneWire_write(instance, 0xCC); // skip ROM
         oneWire_write(instance, 0x44); // convert t
+        if(instance->powerMode == PWR_PASSIVE) {
+            furi_hal_gpio_write(instance->gpio->pin, true);
+            furi_hal_gpio_init(
+                instance->gpio->pin, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh);
+        }
         return UT_POLLING;
     } else {
+        if(instance->powerMode == PWR_PASSIVE) {
+            furi_hal_gpio_write(instance->gpio->pin, true);
+            furi_hal_gpio_init(
+                instance->gpio->pin, GpioModeOutputOpenDrain, GpioPullUp, GpioSpeedVeryHigh);
+        }
         if(!oneWire_start(instance)) return UT_TIMEOUT;
         oneWire_write(instance, 0xCC); // skip ROM
         oneWire_write(instance, 0xBE); // Read Scratch-pad

+ 11 - 0
interfaces/OneWireSensor.h

@@ -3,18 +3,29 @@
 
 #include "../unitemp.h"
 
+//Коды семейства устройств
 typedef enum DallasFamilyCode {
     FC_DS18S20 = 0x10,
     FC_DS1822 = 0x22,
     FC_DS18B20 = 0x28,
 } DallasFamilyCode;
 
+//Режим питания датчка
+typedef enum PowerMode {
+    PWR_PASSIVE, //Питание от линии данных
+    PWR_ACTIVE //Питание от источника питания
+} PowerMode;
+
 typedef struct OneWireSensor {
     //Порт подключения датчика
     const GPIO* gpio;
     //Текущий адрес устройства на шине OneWire
     uint64_t addr;
+    //Код семейства устройств
     DallasFamilyCode familyCode;
+    //Режим питания датчка
+    PowerMode powerMode;
+
 } OneWireSensor;
 
 /**