My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fastio_STM32F1.h 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. * Copyright (C) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #pragma once
  24. /**
  25. * Fast I/O interfaces for STM32F1
  26. * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
  27. */
  28. #include <libmaple/gpio.h>
  29. #define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
  30. #define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !((bool)V)))
  31. #define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
  32. #define WRITE_VAR(IO,V) WRITE(IO,V)
  33. #define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
  34. #define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
  35. #define _SET_OUTPUT(IO) _SET_MODE(IO, GPIO_OUTPUT_PP)
  36. #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
  37. #define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
  38. #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
  39. #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
  40. #define SET_PWM(IO) pinMode(IO, PWM) // do{ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP); timer_set_mode(PIN_MAP[pin].timer_device, PIN_MAP[pin].timer_channel, TIMER_PWM); }while(0)
  41. #define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
  42. #define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP)
  43. #define HAS_TIMER(IO) (PIN_MAP[IO].timer_device != nullptr)
  44. #define PWM_PIN(P) HAS_TIMER(P)
  45. #define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
  46. // digitalRead/Write wrappers
  47. #define extDigitalRead(IO) digitalRead(IO)
  48. #define extDigitalWrite(IO,V) digitalWrite(IO,V)