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.

HAL_Stm32f1.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  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. /**
  24. * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
  25. */
  26. #ifndef _HAL_STM32F1_H
  27. #define _HAL_STM32F1_H
  28. #undef DEBUG_NONE
  29. #ifndef vsnprintf_P
  30. #define vsnprintf_P vsnprintf
  31. #endif
  32. // --------------------------------------------------------------------------
  33. // Includes
  34. // --------------------------------------------------------------------------
  35. #include <stdint.h>
  36. #include "Arduino.h"
  37. #include "fastio_Stm32f1.h"
  38. #include "watchdog_Stm32f1.h"
  39. #include "HAL_timers_Stm32f1.h"
  40. // --------------------------------------------------------------------------
  41. // Defines
  42. // --------------------------------------------------------------------------
  43. #if SERIAL_PORT == -1
  44. #define MYSERIAL SerialUSB
  45. #elif SERIAL_PORT == 0
  46. #define MYSERIAL Serial
  47. #elif SERIAL_PORT == 1
  48. #define MYSERIAL Serial1
  49. #elif SERIAL_PORT == 2
  50. #define MYSERIAL Serial2
  51. #elif SERIAL_PORT == 3
  52. #define MYSERIAL Serial3
  53. #endif
  54. #define _BV(bit) (1 << (bit))
  55. /**
  56. * TODO: review this to return 1 for pins that are not analog input
  57. */
  58. #ifndef analogInputToDigitalPin
  59. #define analogInputToDigitalPin(p) (p)
  60. #endif
  61. #define CRITICAL_SECTION_START noInterrupts();
  62. #define CRITICAL_SECTION_END interrupts();
  63. // On AVR this is in math.h?
  64. #define square(x) ((x)*(x))
  65. #ifndef strncpy_P
  66. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  67. #endif
  68. // Fix bug in pgm_read_ptr
  69. #undef pgm_read_ptr
  70. #define pgm_read_ptr(addr) (*(addr))
  71. #define RST_POWER_ON 1
  72. #define RST_EXTERNAL 2
  73. #define RST_BROWN_OUT 4
  74. #define RST_WATCHDOG 8
  75. #define RST_JTAG 16
  76. #define RST_SOFTWARE 32
  77. #define RST_BACKUP 64
  78. // --------------------------------------------------------------------------
  79. // Types
  80. // --------------------------------------------------------------------------
  81. typedef int8_t pin_t;
  82. // --------------------------------------------------------------------------
  83. // Public Variables
  84. // --------------------------------------------------------------------------
  85. /** result of last ADC conversion */
  86. extern uint16_t HAL_adc_result;
  87. // --------------------------------------------------------------------------
  88. // Public functions
  89. // --------------------------------------------------------------------------
  90. // Disable interrupts
  91. #define cli() noInterrupts()
  92. // Enable interrupts
  93. #define sei() interrupts()
  94. // Memory related
  95. #define __bss_end __bss_end__
  96. /** clear reset reason */
  97. void HAL_clear_reset_source (void);
  98. /** reset reason */
  99. uint8_t HAL_get_reset_source (void);
  100. void _delay_ms(const int delay);
  101. /*
  102. extern "C" {
  103. int freeMemory(void);
  104. }
  105. */
  106. extern "C" char* _sbrk(int incr);
  107. /*
  108. static int freeMemory() {
  109. volatile int top;
  110. top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
  111. return top;
  112. }
  113. */
  114. static int freeMemory() {
  115. volatile char top;
  116. return &top - reinterpret_cast<char*>(_sbrk(0));
  117. }
  118. // SPI: Extended functions which take a channel number (hardware SPI only)
  119. /** Write single byte to specified SPI channel */
  120. void spiSend(uint32_t chan, byte b);
  121. /** Write buffer to specified SPI channel */
  122. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  123. /** Read single byte from specified SPI channel */
  124. uint8_t spiRec(uint32_t chan);
  125. // EEPROM
  126. /**
  127. * TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
  128. * Wire library should work for i2c eeproms.
  129. */
  130. void eeprom_write_byte(unsigned char *pos, unsigned char value);
  131. unsigned char eeprom_read_byte(unsigned char *pos);
  132. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  133. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  134. // ADC
  135. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT_ANALOG);
  136. inline void HAL_adc_init(void) {}
  137. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  138. #define HAL_READ_ADC HAL_adc_result
  139. void HAL_adc_start_conversion(const uint8_t adc_pin);
  140. uint16_t HAL_adc_get_result(void);
  141. /* Todo: Confirm none of this is needed.
  142. uint16_t HAL_getAdcReading(uint8_t chan);
  143. void HAL_startAdcConversion(uint8_t chan);
  144. uint8_t HAL_pinToAdcChannel(int pin);
  145. uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
  146. //uint16_t HAL_getAdcSuperSample(uint8_t chan);
  147. void HAL_enable_AdcFreerun(void);
  148. //void HAL_disable_AdcFreerun(uint8_t chan);
  149. */
  150. #define GET_PIN_MAP_PIN(index) index
  151. #define GET_PIN_MAP_INDEX(pin) pin
  152. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  153. #endif // _HAL_STM32F1_H