Skip to content

Commit

Permalink
[GPIO] Fix build warnings on ESP8266 for GPIO direction
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Sep 29, 2024
1 parent 8afead7 commit 25f7358
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/_P004_Dallas.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].OutputDataType = Output_Data_type_t::Simple;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P013_HCSR04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P018_Dust.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ boolean Plugin_018(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P021_Level.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P029_Output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ boolean Plugin_029(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P031_SHT1X.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ boolean Plugin_031(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P035_IRTX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String& string)
Device[++deviceCount].Number = PLUGIN_ID_035;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].SendDataOption = false;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P038_NeoPixel.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string)
Device[++deviceCount].Number = PLUGIN_ID_038;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].TimerOption = false;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P041_NeoClock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE;
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P042_Candle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ boolean Plugin_042(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].ValueCount = 3;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P043_ClkOutput.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ boolean Plugin_043(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].ValueCount = 2;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].OutputDataType = Output_Data_type_t::Simple;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P054_DMX512.ino
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ boolean Plugin_054(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].Ports = 0;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/_P055_Chiming.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].InverseLogicOption = true;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin3Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin3Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P063_TTP229_KeyPad.ino
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ boolean Plugin_063(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P067_HX711_Load_Cell.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ boolean Plugin_067(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P070_NeoPixel_Clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ boolean Plugin_070(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 3;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);

// FIXME TD-er: Not sure if access to any existing task data is needed when saving
Device[deviceCount].ExitTaskBeforeSave = false;
Expand Down
6 changes: 3 additions & 3 deletions src/_P073_7DGT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE;
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin3Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin3Direction(gpio_direction::gpio_output);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P076_HLW8012.ino
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ boolean Plugin_076(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].PluginStats = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_P088_HeatpumpIR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ boolean Plugin_088(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE;
Device[deviceCount].Ports = 0;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);

break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/_P126_74HC595.ino
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ boolean Plugin_126(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].HasFormatUserVar = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin3Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin3Direction(gpio_direction::gpio_output);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P128_NeoPixelBusFX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ boolean Plugin_128(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/_P129_74HC165.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ boolean Plugin_129(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].TimerOption = true; // Used to update the Devices page
Device[deviceCount].TimerOptional = true;
Device[deviceCount].HasFormatUserVar = true;
Device[deviceCount].Pin2Direction = gpio_direction::gpio_output;
Device[deviceCount].Pin3Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin2Direction(gpio_direction::gpio_output);
Device[deviceCount].setPin3Direction(gpio_direction::gpio_output);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P131_NeoPixelMatrix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].ValueCount = 0;
Device[deviceCount].TimerOption = true;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P165_7SegNeopixel.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ boolean Plugin_165(uint8_t function, struct EventStruct *event, String& string)
Device[++deviceCount].Number = PLUGIN_ID_165;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE;
Device[deviceCount].Pin1Direction = gpio_direction::gpio_output;
Device[deviceCount].setPin1Direction(gpio_direction::gpio_output);
break;
}

Expand Down
23 changes: 18 additions & 5 deletions src/src/DataStructs/DeviceStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
DeviceStruct::DeviceStruct() :
Number(0), Type(0), VType(Sensor_VType::SENSOR_TYPE_NONE), Ports(0), ValueCount(0),
OutputDataType(Output_Data_type_t::Default),
Pin1Direction(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX)),
Pin2Direction(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX)),
Pin3Direction(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX)),
PullUpOption(false), InverseLogicOption(false), FormulaOption(false),
Custom(false), SendDataOption(false), GlobalSyncOption(false),
TimerOption(false), TimerOptional(false), DecimalsOnly(false),
DuplicateDetection(false), ExitTaskBeforeSave(true), ErrorStateValues(false),
PluginStats(false), PluginLogsPeaks(false), PowerManager(false),
TaskLogsOwnPeaks(false), I2CNoDeviceCheck(false),
I2CMax100kHz(false), HasFormatUserVar(false), Pin1Direction(gpio_direction::gpio_direction_MAX),
Pin2Direction(gpio_direction::gpio_direction_MAX), Pin3Direction(gpio_direction::gpio_direction_MAX) {}
I2CMax100kHz(false), HasFormatUserVar(false)
{}

bool DeviceStruct::connectedToGPIOpins() const {
switch(Type) {
Expand Down Expand Up @@ -69,14 +72,24 @@ bool DeviceStruct::isCustom() const {
(Type == DEVICE_TYPE_CUSTOM3);
}

void DeviceStruct::setPinDirection(int pin, gpio_direction direction)
{
const uint8_t val = static_cast<uint8_t>(direction) & ((1 << GPIO_DIRECTION_NR_BITS) - 1);
switch (pin) {
case 1: Pin1Direction = val; break;
case 2: Pin2Direction = val; break;
case 3: Pin3Direction = val; break;
}
}

gpio_direction DeviceStruct::getPinDirection(int pin) const {
switch (pin) {
case 1:
return Pin1Direction;
return static_cast<gpio_direction>(Pin1Direction);
case 2:
return Pin2Direction;
return static_cast<gpio_direction>(Pin2Direction);
case 3:
return Pin3Direction;
return static_cast<gpio_direction>(Pin3Direction);
}
return gpio_direction::gpio_direction_MAX;
}
Expand Down
12 changes: 8 additions & 4 deletions src/src/DataStructs/DeviceStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ struct __attribute__((__packed__)) DeviceStruct
return pluginID_t::toPluginID(Number);
}

void setPinDirection(int pin, gpio_direction direction);
void setPin1Direction(gpio_direction direction) { setPinDirection(1, direction); }
void setPin2Direction(gpio_direction direction) { setPinDirection(2, direction); }
void setPin3Direction(gpio_direction direction) { setPinDirection(3, direction); }

gpio_direction getPinDirection(int pin) const;
PinSelectPurpose pinDirectionToPurpose(gpio_direction direction) const;
PinSelectPurpose getPinSelectPurpose(int pin) const;
Expand All @@ -80,10 +85,9 @@ struct __attribute__((__packed__)) DeviceStruct
uint8_t Ports; // Port to use when device has multiple I/O pins (N.B. not used much)
uint8_t ValueCount; // The number of output values of a plugin. The value should match the number of keys PLUGIN_VALUENAME1_xxx
Output_Data_type_t OutputDataType; // Subset of selectable output data types (Default = no selection)

gpio_direction Pin1Direction : NR_BITS(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX));
gpio_direction Pin2Direction : NR_BITS(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX));
gpio_direction Pin3Direction : NR_BITS(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX));
uint8_t Pin1Direction : GPIO_DIRECTION_NR_BITS;
uint8_t Pin2Direction : GPIO_DIRECTION_NR_BITS;
uint8_t Pin3Direction : GPIO_DIRECTION_NR_BITS;

bool PullUpOption : 1; // Allow to set internal pull-up resistors.
bool InverseLogicOption : 1; // Allow to invert the boolean state (e.g. a switch)
Expand Down
6 changes: 6 additions & 0 deletions src/src/Helpers/ESPEasy_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ void run_compiletime_checks() {
//const size_t offset = offsetof(SettingsStruct, ControllerEnabled);
//check_size<SettingsStruct, offset>();


// ESP8266 toolchain does not support constexpr macros in struct defines
// to determine nr of bits in a struct.
static_assert(GPIO_DIRECTION_NR_BITS== NR_BITS(static_cast<uint8_t>(gpio_direction::gpio_direction_MAX)), "Correct GPIO_DIRECTION_NR_BITS");


#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/src/Helpers/StringGenerator_GPIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define HTML_SYMBOL_OUTPUT "&#8658;"
#define HTML_SYMBOL_I_O "&#8660;"


#define GPIO_DIRECTION_NR_BITS 2
enum class gpio_direction : uint8_t {
gpio_input,
gpio_output,
Expand Down

0 comments on commit 25f7358

Please sign in to comment.