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)
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/>.
25 #include "drivers/io.h"
26 #include "drivers/io_impl.h"
28 #include "debug_pin.h"
30 typedef struct dbgPinState_s
{
36 dbgPinState_t dbgPinStates
[DEBUG_PIN_COUNT
] = { 0 };
38 extern dbgPin_t dbgPins
[DEBUG_PIN_COUNT
];
39 // Define this in the target definition as (and set DEBUG_PIN_COUNT to the correct value):
40 // dbgPin_t dbgPins[DEBUG_PIN_COUNT] = {
41 // { .tag = IO_TAG(<pin>) },
48 for (unsigned i
= 0; i
< ARRAYLEN(dbgPins
); i
++) {
49 dbgPin_t
*dbgPin
= &dbgPins
[i
];
50 dbgPinState_t
*dbgPinState
= &dbgPinStates
[i
];
51 IO_t io
= IOGetByTag(dbgPin
->tag
);
55 IOInit(io
, OWNER_SYSTEM
, 0);
56 IOConfigGPIO(io
, IOCFG_OUT_PP
);
57 dbgPinState
->gpio
= IO_GPIO(io
);
58 int pinSrc
= IO_GPIO_PinSource(io
);
59 dbgPinState
->setBSRR
= (1 << pinSrc
);
60 dbgPinState
->resetBSRR
= (1 << (pinSrc
+ 16));
65 void dbgPinHi(int index
)
68 if ((unsigned)index
>= ARRAYLEN(dbgPins
)) {
72 dbgPinState_t
*dbgPinState
= &dbgPinStates
[index
];
73 if (dbgPinState
->gpio
) {
74 #if defined(STM32F7) || defined(STM32H7)
75 dbgPinState
->gpio
->BSRR
= dbgPinState
->setBSRR
;
77 dbgPinState
->gpio
->BSRRL
= dbgPinState
->setBSRR
;
85 void dbgPinLo(int index
)
88 if ((unsigned)index
>= ARRAYLEN(dbgPins
)) {
92 dbgPinState_t
*dbgPinState
= &dbgPinStates
[index
];
94 if (dbgPinState
->gpio
) {
95 #if defined(STM32F7) || defined(STM32H7)
96 dbgPinState
->gpio
->BSRR
= dbgPinState
->resetBSRR
;
98 dbgPinState
->gpio
->BSRRL
= dbgPinState
->resetBSRR
;