2018-10-03 10:26:07 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-03 10:26:07 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
* Copyright (c) 2017 Victor Perez
|
2018-10-03 10:26:07 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
// Public Variables
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
|
|
|
|
extern GPIO_TypeDef * FastIOPortMap[];
|
|
|
|
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
// Public functions
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
|
|
|
|
void FastIO_init(); // Must be called before using fast io macros
|
|
|
|
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
// Defines
|
2019-07-10 05:30:06 +02:00
|
|
|
// ------------------------
|
2018-10-31 01:25:44 +01:00
|
|
|
|
|
|
|
#define _BV32(b) (1UL << (b))
|
|
|
|
|
2019-06-13 10:45:46 +02:00
|
|
|
#ifndef PWM
|
2019-03-16 01:14:06 +01:00
|
|
|
#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(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)
|
2018-10-06 07:14:12 +02:00
|
|
|
|
2019-05-22 01:28:12 +02:00
|
|
|
#define PWM_PIN(P) digitalPinHasPWM(P)
|
2019-03-05 07:41:31 +01:00
|
|
|
|
|
|
|
// digitalRead/Write wrappers
|
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|