2018-10-03 10:26:07 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 22:06:53 +01:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-03 10:26:07 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
* Copyright (C) 2017 Victor Perez
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/**
|
2018-10-08 00:08:01 +02:00
|
|
|
* Fast I/O interfaces for STM32
|
2018-10-31 01:25:44 +01:00
|
|
|
* These use GPIO register access for fast port manipulation.
|
2018-10-03 10:26:07 +02:00
|
|
|
*/
|
|
|
|
|
2018-10-31 01:25:44 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Public Variables
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
extern GPIO_TypeDef * FastIOPortMap[];
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Public functions
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FastIO_init(); // Must be called before using fast io macros
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Defines
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define _BV32(b) (1UL << (b))
|
|
|
|
|
2019-03-16 01:14:06 +01:00
|
|
|
#if !defined(PWM)
|
|
|
|
#define PWM OUTPUT
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 01:25:44 +01:00
|
|
|
#if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
|
|
|
|
#define _WRITE(IO, V) do { \
|
|
|
|
if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
|
|
|
|
else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \
|
|
|
|
} while(0)
|
|
|
|
#else
|
2018-10-31 21:34:37 +01:00
|
|
|
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + (V ? 0 : 16)))
|
2018-10-31 01:25:44 +01:00
|
|
|
#endif
|
2018-10-03 10:26:07 +02:00
|
|
|
|
2018-10-31 01:25:44 +01:00
|
|
|
#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO]))))
|
|
|
|
#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO])))
|
2018-10-03 10:26:07 +02:00
|
|
|
|
|
|
|
#define _GET_MODE(IO)
|
|
|
|
#define _SET_MODE(IO,M) pinMode(IO, M)
|
|
|
|
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
|
|
|
|
2018-10-31 01:25:44 +01:00
|
|
|
#define WRITE_VAR(IO,V) _WRITE(IO,V)
|
|
|
|
#define WRITE(IO,V) _WRITE(IO,V)
|
|
|
|
#define READ(IO) _READ(IO)
|
|
|
|
#define TOGGLE(IO) _TOGGLE(IO)
|
|
|
|
|
2018-10-03 10:26:07 +02:00
|
|
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
|
|
|
|
|
|
|
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
|
|
|
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
|
|
|
|
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
|
|
|
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
2019-03-13 12:51:15 +01:00
|
|
|
#define SET_PWM(IO) _SET_MODE(IO, PWM)
|
2018-10-03 10:26:07 +02:00
|
|
|
|
2019-03-29 18:21:14 +01:00
|
|
|
#define IS_INPUT(IO)
|
|
|
|
#define IS_OUTPUT(IO)
|
|
|
|
#define HAS_TIMER(IO)
|
2018-10-06 07:14:12 +02:00
|
|
|
|
2019-03-29 18:21:14 +01:00
|
|
|
#define PWM_PIN(P) HAS_TIMER(P)
|
2019-03-13 12:51:15 +01:00
|
|
|
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
|
2019-03-05 07:41:31 +01:00
|
|
|
|
|
|
|
// digitalRead/Write wrappers
|
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|