Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / io_def.h
blob4171124feb076b711e2bcbab838331c9ee4653ce
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "common/utils.h"
25 // return ioTag_t for given pinid
26 // tag for NONE must be false
27 #define DEFIO_TAG(pinid) CONCAT(DEFIO_TAG__, pinid)
28 #define DEFIO_TAG__NONE 0
29 #define DEFIO_TAG_E(pinid) CONCAT(DEFIO_TAG_E__, pinid)
30 #define DEFIO_TAG_E__NONE 0
33 // return ioRec_t or NULL for given pinid
34 // tags should be preferred, possibly removing it in future
35 // io_impl.h must be included when this macro is used
36 #define DEFIO_REC(pinid) CONCAT(DEFIO_REC__, pinid)
37 #define DEFIO_REC__NONE NULL
39 #define DEFIO_IO(pinid) (IO_t)DEFIO_REC(pinid)
40 // TODO - macro to check for pinid NONE (fully in preprocessor)
42 // get ioRec by index
43 #define DEFIO_REC_INDEXED(idx) (ioRecs + (idx))
45 // ioTag_t accessor macros
46 #define DEFIO_TAG_MAKE(gpioid, pin) ((ioTag_t)((((gpioid) + 1) << 4) | (pin)))
47 #define DEFIO_TAG_ISEMPTY(tag) (!(tag))
48 #define DEFIO_TAG_GPIOID(tag) (((tag) >> 4) - 1)
49 #define DEFIO_TAG_PIN(tag) ((tag) & 0x0f)
51 // TARGET must define used pins
52 #include "target.h"
53 // include template-generated macros for IO pins
54 #include "io_def_generated.h"