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.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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) << ((V) ? 0 : 16))
  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 _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
  33. #define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
  34. #define _SET_OUTPUT(IO) _SET_MODE(IO, GPIO_OUTPUT_PP)
  35. #define _SET_OUTPUT_OD(IO) _SET_MODE(IO, GPIO_OUTPUT_OD)
  36. #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
  37. #define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0)
  38. #define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
  39. #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
  40. #define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, GPIO_INPUT_PD)
  41. #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
  42. #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)
  43. #define SET_PWM_OD(IO) pinMode(IO, PWM_OPEN_DRAIN)
  44. #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)
  45. #define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
  46. #define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr)
  47. // digitalRead/Write wrappers
  48. #define extDigitalRead(IO) digitalRead(IO)
  49. #define extDigitalWrite(IO,V) digitalWrite(IO,V)
  50. //
  51. // Pins Definitions
  52. //
  53. #define PA0 0x00
  54. #define PA1 0x01
  55. #define PA2 0x02
  56. #define PA3 0x03
  57. #define PA4 0x04
  58. #define PA5 0x05
  59. #define PA6 0x06
  60. #define PA7 0x07
  61. #define PA8 0x08
  62. #define PA9 0x09
  63. #define PA10 0x0A
  64. #define PA11 0x0B
  65. #define PA12 0x0C
  66. #define PA13 0x0D
  67. #define PA14 0x0E
  68. #define PA15 0x0F
  69. #define PB0 0x10
  70. #define PB1 0x11
  71. #define PB2 0x12
  72. #define PB3 0x13
  73. #define PB4 0x14
  74. #define PB5 0x15
  75. #define PB6 0x16
  76. #define PB7 0x17 // 36 pins (F103T)
  77. #define PB8 0x18
  78. #define PB9 0x19
  79. #define PB10 0x1A
  80. #define PB11 0x1B
  81. #define PB12 0x1C
  82. #define PB13 0x1D
  83. #define PB14 0x1E
  84. #define PB15 0x1F
  85. #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
  86. #define PC13 0x20
  87. #define PC14 0x21
  88. #define PC15 0x22
  89. #else
  90. #define PC0 0x20
  91. #define PC1 0x21
  92. #define PC2 0x22
  93. #define PC3 0x23
  94. #define PC4 0x24
  95. #define PC5 0x25
  96. #define PC6 0x26
  97. #define PC7 0x27
  98. #define PC8 0x28
  99. #define PC9 0x29
  100. #define PC10 0x2A
  101. #define PC11 0x2B
  102. #define PC12 0x2C
  103. #define PC13 0x2D
  104. #define PC14 0x2E
  105. #define PC15 0x2F
  106. #endif
  107. #define PD0 0x30
  108. #define PD1 0x31
  109. #define PD2 0x32 // 64 pins (F103R)
  110. #define PD3 0x33
  111. #define PD4 0x34
  112. #define PD5 0x35
  113. #define PD6 0x36
  114. #define PD7 0x37
  115. #define PD8 0x38
  116. #define PD9 0x39
  117. #define PD10 0x3A
  118. #define PD11 0x3B
  119. #define PD12 0x3C
  120. #define PD13 0x3D
  121. #define PD14 0x3E
  122. #define PD15 0x3F
  123. #define PE0 0x40
  124. #define PE1 0x41
  125. #define PE2 0x42
  126. #define PE3 0x43
  127. #define PE4 0x44
  128. #define PE5 0x45
  129. #define PE6 0x46
  130. #define PE7 0x47
  131. #define PE8 0x48
  132. #define PE9 0x49
  133. #define PE10 0x4A
  134. #define PE11 0x4B
  135. #define PE12 0x4C
  136. #define PE13 0x4D
  137. #define PE14 0x4E
  138. #define PE15 0x4F // 100 pins (F103V)
  139. #define PF0 0x50
  140. #define PF1 0x51
  141. #define PF2 0x52
  142. #define PF3 0x53
  143. #define PF4 0x54
  144. #define PF5 0x55
  145. #define PF6 0x56
  146. #define PF7 0x57
  147. #define PF8 0x58
  148. #define PF9 0x59
  149. #define PF10 0x5A
  150. #define PF11 0x5B
  151. #define PF12 0x5C
  152. #define PF13 0x5D
  153. #define PF14 0x5E
  154. #define PF15 0x5F
  155. #define PG0 0x60
  156. #define PG1 0x61
  157. #define PG2 0x62
  158. #define PG3 0x63
  159. #define PG4 0x64
  160. #define PG5 0x65
  161. #define PG6 0x66
  162. #define PG7 0x67
  163. #define PG8 0x68
  164. #define PG9 0x69
  165. #define PG10 0x6A
  166. #define PG11 0x6B
  167. #define PG12 0x6C
  168. #define PG13 0x6D
  169. #define PG14 0x6E
  170. #define PG15 0x6F // 144 pins (F103Z)