2018-10-03 08:26:07 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 21:06:53 +00:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-03 08:26:07 +00: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-07 22:08:01 +00:00
|
|
|
* Fast I/O interfaces for STM32
|
2018-10-31 00:25:44 +00:00
|
|
|
* These use GPIO register access for fast port manipulation.
|
2018-10-03 08:26:07 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-31 00:25:44 +00: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))
|
|
|
|
|
|
|
|
#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 20:34:37 +00:00
|
|
|
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + (V ? 0 : 16)))
|
2018-10-31 00:25:44 +00:00
|
|
|
#endif
|
2018-10-03 08:26:07 +00:00
|
|
|
|
2018-10-31 00:25:44 +00: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 08:26:07 +00: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 00:25:44 +00: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 08:26:07 +00: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)
|
|
|
|
|
|
|
|
#define GET_INPUT(IO)
|
|
|
|
#define GET_OUTPUT(IO)
|
|
|
|
#define GET_TIMER(IO)
|
2018-10-06 05:14:12 +00:00
|
|
|
|
2019-03-13 01:39:55 +00:00
|
|
|
#define PWM_PIN(p) digitalPinHasPWM(p)
|
2018-10-06 05:14:12 +00:00
|
|
|
#define USEABLE_HARDWARE_PWM(p) PWM_PIN(p)
|
2019-03-05 06:41:31 +00:00
|
|
|
|
|
|
|
// digitalRead/Write wrappers
|
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|