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_AVR.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* **************************************************************************
  2. Marlin 3D Printer Firmware
  3. Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ****************************************************************************/
  16. /**
  17. * Description: HAL for AVR
  18. *
  19. * For ARDUINO_ARCH_AVR
  20. */
  21. #ifndef _HAL_AVR_H
  22. #define _HAL_AVR_H
  23. // --------------------------------------------------------------------------
  24. // Includes
  25. // --------------------------------------------------------------------------
  26. #include <stdint.h>
  27. #include "Arduino.h"
  28. #include <util/delay.h>
  29. #include <avr/eeprom.h>
  30. #include <avr/pgmspace.h>
  31. #include <avr/interrupt.h>
  32. #include <avr/io.h>
  33. #include "fastio_AVR.h"
  34. #include "watchdog_AVR.h"
  35. #include "math_AVR.h"
  36. // --------------------------------------------------------------------------
  37. // Defines
  38. // --------------------------------------------------------------------------
  39. //#define analogInputToDigitalPin(IO) IO
  40. #ifndef CRITICAL_SECTION_START
  41. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  42. #define CRITICAL_SECTION_END SREG = _sreg;
  43. #endif
  44. // On AVR this is in math.h?
  45. //#define square(x) ((x)*(x))
  46. // --------------------------------------------------------------------------
  47. // Types
  48. // --------------------------------------------------------------------------
  49. #define HAL_TIMER_TYPE uint16_t
  50. #define HAL_TIMER_TYPE_MAX 0xFFFF
  51. #define HAL_SERVO_LIB Servo
  52. // --------------------------------------------------------------------------
  53. // Public Variables
  54. // --------------------------------------------------------------------------
  55. //extern uint8_t MCUSR;
  56. // --------------------------------------------------------------------------
  57. // Public functions
  58. // --------------------------------------------------------------------------
  59. //void cli(void);
  60. //void _delay_ms(int delay);
  61. inline void HAL_clear_reset_source(void) { MCUSR = 0; }
  62. inline uint8_t HAL_get_reset_source(void) { return MCUSR; }
  63. extern "C" {
  64. int freeMemory(void);
  65. }
  66. // eeprom
  67. //void eeprom_write_byte(unsigned char *pos, unsigned char value);
  68. //unsigned char eeprom_read_byte(unsigned char *pos);
  69. // timers
  70. #define STEP_TIMER_NUM OCR1A
  71. #define TEMP_TIMER_NUM 0
  72. #define TEMP_TIMER_FREQUENCY (F_CPU / 64.0 / 256.0)
  73. #define HAL_TIMER_RATE ((F_CPU) / 8.0)
  74. #define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
  75. #define STEPPER_TIMER_PRESCALE INT0_PRESCALER
  76. #define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
  77. #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
  78. #define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
  79. #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
  80. //void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
  81. #define HAL_timer_start (timer_num,frequency)
  82. //void HAL_timer_set_count (uint8_t timer_num, uint16_t count);
  83. #define HAL_timer_set_count(timer,count) timer = (count)
  84. #define HAL_timer_get_current_count(timer) timer
  85. //void HAL_timer_isr_prologue (uint8_t timer_num);
  86. #define HAL_timer_isr_prologue(timer_num)
  87. #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)
  88. #define HAL_TEMP_TIMER_ISR ISR(TIMER0_COMPB_vect)
  89. #define HAL_ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
  90. // ADC
  91. #ifdef DIDR2
  92. #define HAL_ANALOG_SELECT(pin) do{ if (pin < 8) SBI(DIDR0, pin); else SBI(DIDR2, pin - 8); }while(0)
  93. #else
  94. #define HAL_ANALOG_SELECT(pin) do{ SBI(DIDR0, pin); }while(0)
  95. #endif
  96. inline void HAL_adc_init(void) {
  97. ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
  98. DIDR0 = 0;
  99. #ifdef DIDR2
  100. DIDR2 = 0;
  101. #endif
  102. }
  103. #define SET_ADMUX_ADCSRA(pin) ADMUX = _BV(REFS0) | (pin & 0x07); SBI(ADCSRA, ADSC)
  104. #ifdef MUX5
  105. #define HAL_START_ADC(pin) if (pin > 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
  106. #else
  107. #define HAL_START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
  108. #endif
  109. #define HAL_READ_ADC ADC
  110. // --------------------------------------------------------------------------
  111. //
  112. // --------------------------------------------------------------------------
  113. #endif // _HAL_AVR_H