diff --git a/src/main/drivers/io.c b/src/main/drivers/io.c
index 271854640..8b08a2088 100644
--- a/src/main/drivers/io.c
+++ b/src/main/drivers/io.c
@@ -353,9 +353,20 @@ void IOConfigGPIOAF(IO_t io, ioConfig_t cfg, uint8_t af)
}
#endif
+#if DEFIO_PORT_USED_COUNT > 0
static const uint16_t ioDefUsedMask[DEFIO_PORT_USED_COUNT] = { DEFIO_PORT_USED_LIST };
static const uint8_t ioDefUsedOffset[DEFIO_PORT_USED_COUNT] = { DEFIO_PORT_OFFSET_LIST };
+#else
+// Avoid -Wpedantic warning
+static const uint16_t ioDefUsedMask[1] = {0};
+static const uint8_t ioDefUsedOffset[1] = {0};
+#endif
+#if DEFIO_IO_USED_COUNT
ioRec_t ioRecs[DEFIO_IO_USED_COUNT];
+#else
+// Avoid -Wpedantic warning
+ioRec_t ioRecs[1];
+#endif
// initialize all ioRec_t structures from ROM
// currently only bitmask is used, this may change in future
diff --git a/src/main/drivers/io_def_generated.h b/src/main/drivers/io_def_generated.h
index 975f6721c..c99ba9265 100644
--- a/src/main/drivers/io_def_generated.h
+++ b/src/main/drivers/io_def_generated.h
@@ -15,8 +15,9 @@
* along with Cleanflight. If not, see .
*/
- #pragma once
-// this file is automatically generated by def_generated.pl script
+#pragma once
+
+// this file is automatically generated by src/utils/def_generated.pl script
// do not modify this file directly, your changes will be lost
// DEFIO_PORT__USED_MASK is bitmask of used pins on target
@@ -96,7 +97,8 @@
#define DEFIO_GPIOID__F 5
#define DEFIO_GPIOID__G 6
-// DEFIO_TAG__P will expand to TAG if defined for target
+// DEFIO_TAG__P will expand to TAG if defined for target, error is triggered otherwise
+// DEFIO_TAG_E__P will expand to TAG if defined, to NONE otherwise (usefull for tables that are CPU-specific)
// DEFIO_REC__P will expand to ioRec* (using DEFIO_REC_INDEX(idx))
#if DEFIO_PORT_A_USED_MASK & BIT(0)
@@ -1150,8 +1152,10 @@
# define DEFIO_PORT_OFFSET_LIST DEFIO_PORT_A_OFFSET
#endif
-#if !defined DEFIO_PORT_USED_LIST
-# warning "No pins are defined. Maybe you forgot to define TARGET_IO_PORTx in target_io.h"
+#if !defined(DEFIO_PORT_USED_LIST)
+# if !defined DEFIO_NO_PORTS // supress warnings if we really don't want any pins
+# warning "No pins are defined. Maybe you forgot to define TARGET_IO_PORTx in target.h"
+# endif
# define DEFIO_PORT_USED_COUNT 0
# define DEFIO_PORT_USED_LIST /* empty */
# define DEFIO_PORT_OFFSET_LIST /* empty */
diff --git a/src/main/drivers/io_impl.h b/src/main/drivers/io_impl.h
index 30f611025..6775abf5b 100644
--- a/src/main/drivers/io_impl.h
+++ b/src/main/drivers/io_impl.h
@@ -33,7 +33,7 @@ typedef struct ioRec_s {
uint8_t index;
} ioRec_t;
-extern ioRec_t ioRecs[DEFIO_IO_USED_COUNT];
+extern ioRec_t ioRecs[];
int IO_GPIOPortIdx(IO_t io);
int IO_GPIOPinIdx(IO_t io);
diff --git a/src/utils/def_generated.pl b/src/utils/def_generated.pl
index 39413037d..0bd9ef6f7 100644
--- a/src/utils/def_generated.pl
+++ b/src/utils/def_generated.pl
@@ -14,6 +14,25 @@ my $drivers_dir = "../main/drivers";
# change list separator to newline - we use @{} interpolation to merge multiline strings
$" = "\n";
+chomp(my $license = <<"END");
+/*
+ * This file is part of Cleanflight.
+ *
+ * Cleanflight is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cleanflight is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cleanflight. If not, see .
+ */
+END
+
chomp(my $disclaimer_generated = <<"END");
// this file is automatically generated by src/utils/def_generated.pl script
// do not modify this file directly, your changes will be lost
@@ -23,7 +42,10 @@ my $io_def_file="$drivers_dir/io_def_generated.h";
my $fh;
open $fh, '>', $io_def_file or die "Cannot open $io_def_file: $!";
print { $fh} <<"END" or die "Cannot write into $io_def_file: $!"; close $fh;
+${license}
+
#pragma once
+
${disclaimer_generated}
// DEFIO_PORT__USED_MASK is bitmask of used pins on target
@@ -39,7 +61,7 @@ ${disclaimer_generated}
# define DEFIO_PORT_${port}_USED_MASK 0
# define DEFIO_PORT_${port}_USED_COUNT 0
#endif
-# define DEFIO_PORT_${port}_OFFSET (@{[join('+', map { "DEFIO_PORT_${_}_USED_COUNT" } @prev_ports) || '0']})
+#define DEFIO_PORT_${port}_OFFSET (@{[join('+', map { "DEFIO_PORT_${_}_USED_COUNT" } @prev_ports) || '0']})
END2
@@ -48,18 +70,20 @@ END2
#define DEFIO_GPIOID__${port} @{[ord($port)-ord('A')]}
END2
-// DEFIO_TAG__P will expand to TAG if defined for target
+// DEFIO_TAG__P will expand to TAG if defined for target, error is triggered otherwise
+// DEFIO_TAG_E__P will expand to TAG if defined, to NONE otherwise (usefull for tables that are CPU-specific)
// DEFIO_REC__P will expand to ioRec* (using DEFIO_REC_INDEX(idx))
-// all P macros are defined to expand to self to generate warning if someone tries to redefine them
+
@{[do {
my @prev_ports = ();
map { my $port = $_; my @ret = map { my $pin = $_; chomp(my $ret = << "END2"); $ret } @pins ; push @prev_ports, $port; @ret } @ports; }]}
-#define P${port}${pin} P${port}${pin}
#if DEFIO_PORT_${port}_USED_MASK & BIT(${pin})
# define DEFIO_TAG__P${port}${pin} DEFIO_TAG_MAKE(DEFIO_GPIOID__${port}, ${pin})
+# define DEFIO_TAG_E__P${port}${pin} DEFIO_TAG_MAKE(DEFIO_GPIOID__${port}, ${pin})
# define DEFIO_REC__P${port}${pin} DEFIO_REC_INDEXED(BITCOUNT(DEFIO_PORT_${port}_USED_MASK & (BIT(${pin}) - 1)) + @{[join('+', map { "DEFIO_PORT_${_}_USED_COUNT" } @prev_ports) || '0']})
#else
# define DEFIO_TAG__P${port}${pin} defio_error_P${port}${pin}_is_not_supported_on_TARGET
+# define DEFIO_TAG_E__P${port}${pin} DEFIO_TAG_E__NONE
# define DEFIO_REC__P${port}${pin} defio_error_P${port}${pin}_is_not_supported_on_TARGET
#endif
END2
@@ -80,8 +104,10 @@ END2
#endif
END2
-#if !defined(DEFIO_PORT_USED_LIST) && !defined(UNIT_TEST)
-# warning "No pins are defined. Maybe you forgot to define TARGET_IO_PORTx in target.h"
+#if !defined(DEFIO_PORT_USED_LIST)
+# if !defined DEFIO_NO_PORTS // supress warnings if we really don't want any pins
+# warning "No pins are defined. Maybe you forgot to define TARGET_IO_PORTx in target.h"
+# endif
# define DEFIO_PORT_USED_COUNT 0
# define DEFIO_PORT_USED_LIST /* empty */
# define DEFIO_PORT_OFFSET_LIST /* empty */