1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

Allow target without IO pins

Mostly workaround for `-Wpedantic`
This commit is contained in:
Petr Ledvina 2017-05-12 16:05:53 +02:00
parent 58212464c5
commit f9bd5c2218
4 changed files with 53 additions and 12 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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_<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<port><pin> will expand to TAG if defined for target
// DEFIO_TAG__P<port><pin> will expand to TAG if defined for target, error is triggered otherwise
// DEFIO_TAG_E__P<port><pin> will expand to TAG if defined, to NONE otherwise (usefull for tables that are CPU-specific)
// DEFIO_REC__P<port><pin> will expand to ioRec* (using DEFIO_REC_INDEX(idx))
// all P<port><pin> 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 */