Переглянути джерело

Implement HAL and apply macros across code-base

Implement AVR Platform
Christopher Pepper 7 роки тому
джерело
коміт
4b16fa3272
65 змінених файлів з 2266 додано та 763 видалено
  1. 5
    1
      .gitignore
  2. 79
    2
      Marlin/Conditionals_post.h
  3. 1
    6
      Marlin/Marlin.h
  4. 2
    3
      Marlin/MarlinConfig.h
  5. 14
    36
      Marlin/Marlin_main.cpp
  6. 5
    146
      Marlin/Sd2Card.cpp
  7. 6
    12
      Marlin/Sd2Card.h
  8. 3
    2
      Marlin/SdFile.h
  9. 23
    0
      Marlin/boards.h
  10. 0
    1
      Marlin/buzzer.h
  11. 1
    1
      Marlin/circularqueue.h
  12. 9
    39
      Marlin/configuration_store.cpp
  13. 0
    2
      Marlin/configuration_store.h
  14. 108
    0
      Marlin/dac_dac084s085.cpp
  15. 11
    0
      Marlin/dac_dac084s085.h
  16. 1
    1
      Marlin/hex_print_routines.cpp
  17. 0
    5
      Marlin/macros.h
  18. 70
    42
      Marlin/pins.h
  19. 4
    2
      Marlin/pins_RAMPS.h
  20. 1
    1
      Marlin/planner.cpp
  21. 8
    4
      Marlin/printcounter.h
  22. 3
    3
      Marlin/private_spi.h
  23. 16
    10
      Marlin/serial.h
  24. 94
    0
      Marlin/src/HAL/HAL.h
  25. 100
    0
      Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp
  26. 160
    0
      Marlin/src/HAL/HAL_AVR/HAL_AVR.h
  27. 18
    6
      Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h
  28. 213
    0
      Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
  29. 6
    3
      Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
  30. 4
    1
      Marlin/src/HAL/HAL_AVR/MarlinSerial.h
  31. 90
    0
      Marlin/src/HAL/HAL_AVR/ServoTimers.h
  32. 1
    11
      Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
  33. 1
    1
      Marlin/src/HAL/HAL_AVR/fastio_1280.h
  34. 1
    1
      Marlin/src/HAL/HAL_AVR/fastio_1281.h
  35. 1
    1
      Marlin/src/HAL/HAL_AVR/fastio_168.h
  36. 1
    1
      Marlin/src/HAL/HAL_AVR/fastio_644.h
  37. 1
    1
      Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h
  38. 3
    4
      Marlin/src/HAL/HAL_AVR/fastio_AVR.h
  39. 112
    0
      Marlin/src/HAL/HAL_AVR/math_AVR.h
  40. 57
    0
      Marlin/src/HAL/HAL_AVR/persistent_store.cpp
  41. 0
    0
      Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h
  42. 0
    0
      Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
  43. 12
    115
      Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
  44. 67
    0
      Marlin/src/HAL/HAL_AVR/spi_pins.h
  45. 5
    2
      Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
  46. 4
    3
      Marlin/src/HAL/HAL_AVR/watchdog_AVR.h
  47. 53
    0
      Marlin/src/HAL/HAL_endstop_interrupts.h
  48. 35
    0
      Marlin/src/HAL/HAL_pinsDebug.h
  49. 39
    0
      Marlin/src/HAL/HAL_spi_pins.h
  50. 162
    0
      Marlin/src/HAL/I2cEeprom.cpp
  51. 117
    0
      Marlin/src/HAL/SpiEeprom.cpp
  52. 33
    0
      Marlin/src/HAL/math_32bit.h
  53. 19
    0
      Marlin/src/HAL/persistent_store_api.h
  54. 168
    0
      Marlin/src/HAL/servo.cpp
  55. 9
    61
      Marlin/src/HAL/servo.h
  56. 103
    0
      Marlin/src/HAL/servo_private.h
  57. 83
    97
      Marlin/stepper.cpp
  58. 66
    62
      Marlin/stepper.h
  59. 52
    66
      Marlin/temperature.cpp
  60. 1
    1
      Marlin/temperature.h
  61. 1
    1
      Marlin/ubl_G29.cpp
  62. 0
    2
      Marlin/ubl_motion.cpp
  63. 2
    2
      Marlin/ultralcd.cpp
  64. 1
    1
      Marlin/ultralcd_impl_DOGM.h
  65. 1
    1
      Marlin/ultralcd_impl_HD44780.h

+ 5
- 1
.gitignore Переглянути файл

118
 
118
 
119
 # PlatformIO files/dirs
119
 # PlatformIO files/dirs
120
 .pio*
120
 .pio*
121
-lib/readme.txt
121
+.pioenvs
122
+.piolibdeps
123
+.clang_complete
124
+.gcc-flags.json
125
+lib/
122
 
126
 
123
 #Visual Studio
127
 #Visual Studio
124
 *.sln
128
 *.sln

+ 79
- 2
Marlin/Conditionals_post.h Переглянути файл

203
     #define DEFAULT_KEEPALIVE_INTERVAL 2
203
     #define DEFAULT_KEEPALIVE_INTERVAL 2
204
   #endif
204
   #endif
205
 
205
 
206
+  #ifdef CPU_32_BIT
207
+    /**
208
+     * Hidden options for developer
209
+     */
210
+    // Double stepping start from STEP_DOUBLER_FREQUENCY + 1, quad stepping start from STEP_DOUBLER_FREQUENCY * 2 + 1
211
+    #ifndef STEP_DOUBLER_FREQUENCY
212
+      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
213
+        #define STEP_DOUBLER_FREQUENCY 60000 // Hz
214
+      #else
215
+        #define STEP_DOUBLER_FREQUENCY 80000 // Hz
216
+      #endif
217
+    #endif
218
+    // Disable double / quad stepping
219
+    //#define DISABLE_MULTI_STEPPING
220
+  #endif
221
+
206
   /**
222
   /**
207
    * Provide a MAX_AUTORETRACT for older configs
223
    * Provide a MAX_AUTORETRACT for older configs
208
    */
224
    */
214
    * MAX_STEP_FREQUENCY differs for TOSHIBA
230
    * MAX_STEP_FREQUENCY differs for TOSHIBA
215
    */
231
    */
216
   #if ENABLED(CONFIG_STEPPERS_TOSHIBA)
232
   #if ENABLED(CONFIG_STEPPERS_TOSHIBA)
217
-    #define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
233
+    #ifdef CPU_32_BIT
234
+      #define MAX_STEP_FREQUENCY STEP_DOUBLER_FREQUENCY // Max step frequency for Toshiba Stepper Controllers, 96kHz is close to maximum for an Arduino Due
235
+    #else
236
+      #define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
237
+    #endif
218
   #else
238
   #else
219
-    #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
239
+    #ifdef CPU_32_BIT
240
+      #define MAX_STEP_FREQUENCY (STEP_DOUBLER_FREQUENCY * 4) // Max step frequency for the Due is approx. 330kHz
241
+    #else
242
+      #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
243
+    #endif
220
   #endif
244
   #endif
221
 
245
 
222
   // MS1 MS2 Stepper Driver Microstepping mode table
246
   // MS1 MS2 Stepper Driver Microstepping mode table
224
   #define MICROSTEP2 HIGH,LOW
248
   #define MICROSTEP2 HIGH,LOW
225
   #define MICROSTEP4 LOW,HIGH
249
   #define MICROSTEP4 LOW,HIGH
226
   #define MICROSTEP8 HIGH,HIGH
250
   #define MICROSTEP8 HIGH,HIGH
251
+  #ifdef __SAM3X8E__
252
+    #if MB(ALLIGATOR)
253
+      #define MICROSTEP16 LOW,LOW
254
+      #define MICROSTEP32 HIGH,HIGH
255
+    #else
256
+      #define MICROSTEP16 HIGH,HIGH
257
+    #endif
258
+  #else
227
   #define MICROSTEP16 HIGH,HIGH
259
   #define MICROSTEP16 HIGH,HIGH
260
+  #endif
228
 
261
 
229
   /**
262
   /**
230
    * Advance calculated values
263
    * Advance calculated values
350
     #define BED_USES_THERMISTOR
383
     #define BED_USES_THERMISTOR
351
   #endif
384
   #endif
352
 
385
 
386
+  #ifdef __SAM3X8E__
387
+    #define HEATER_USES_AD595 (ENABLED(HEATER_0_USES_AD595) || ENABLED(HEATER_1_USES_AD595) || ENABLED(HEATER_2_USES_AD595) || ENABLED(HEATER_3_USES_AD595))
388
+  #endif
389
+
353
   /**
390
   /**
354
    * Flags for PID handling
391
    * Flags for PID handling
355
    */
392
    */
873
 
910
 
874
   // Stepper pulse duration, in cycles
911
   // Stepper pulse duration, in cycles
875
   #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
912
   #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
913
+  #ifdef CPU_32_BIT
914
+    // Add additional delay for between direction signal and pulse signal of stepper
915
+    #ifndef STEPPER_DIRECTION_DELAY
916
+      #define STEPPER_DIRECTION_DELAY 0 // time in microseconds
917
+    #endif
918
+  #endif
919
+
920
+  #ifndef __SAM3X8E__ //todo: hal: broken hal encapsulation
921
+    #undef UI_VOLTAGE_LEVEL
922
+    #undef RADDS_DISPLAY
923
+    #undef MOTOR_CURRENT
924
+  #endif
876
 
925
 
877
   #if ENABLED(SDCARD_SORT_ALPHA)
926
   #if ENABLED(SDCARD_SORT_ALPHA)
878
     #define HAS_FOLDER_SORTING (FOLDER_SORTING || ENABLED(SDSORT_GCODE))
927
     #define HAS_FOLDER_SORTING (FOLDER_SORTING || ENABLED(SDSORT_GCODE))
928
     #endif
977
     #endif
929
   #endif
978
   #endif
930
 
979
 
980
+  // Use float instead of double. Needs profiling.
981
+  #if defined(ARDUINO_ARCH_SAM) && ENABLED(DELTA_FAST_SQRT)
982
+    #undef ATAN2
983
+    #undef FABS
984
+    #undef POW
985
+    #undef SQRT
986
+    #undef CEIL
987
+    #undef FLOOR
988
+    #undef LROUND
989
+    #undef FMOD
990
+    #define ATAN2(y, x) atan2f(y, x)
991
+    #define FABS(x) fabsf(x)
992
+    #define POW(x, y) powf(x, y)
993
+    #define SQRT(x) sqrtf(x)
994
+    #define CEIL(x) ceilf(x)
995
+    #define FLOOR(x) floorf(x)
996
+    #define LROUND(x) lroundf(x)
997
+    #define FMOD(x, y) fmodf(x, y)
998
+  #endif
999
+
1000
+  #ifdef TEENSYDUINO
1001
+    #undef max
1002
+    #define max(a,b) ((a)>(b)?(a):(b))
1003
+    #undef min
1004
+    #define min(a,b) ((a)<(b)?(a):(b))
1005
+
1006
+    #define NOT_A_PIN 0 // For PINS_DEBUGGING
1007
+  #endif
931
 #endif // CONDITIONALS_POST_H
1008
 #endif // CONDITIONALS_POST_H

+ 1
- 6
Marlin/Marlin.h Переглянути файл

28
 #include <string.h>
28
 #include <string.h>
29
 #include <inttypes.h>
29
 #include <inttypes.h>
30
 
30
 
31
-#include <util/delay.h>
32
-#include <avr/pgmspace.h>
33
-#include <avr/eeprom.h>
34
-#include <avr/interrupt.h>
35
-
36
 #include "MarlinConfig.h"
31
 #include "MarlinConfig.h"
37
 
32
 
38
 #ifdef DEBUG_GCODE_PARSER
33
 #ifdef DEBUG_GCODE_PARSER
39
   #include "gcode.h"
34
   #include "gcode.h"
40
 #endif
35
 #endif
36
+#include "src/HAL/HAL.h"
41
 
37
 
42
 #include "enum.h"
38
 #include "enum.h"
43
 #include "types.h"
39
 #include "types.h"
44
-#include "fastio.h"
45
 #include "utility.h"
40
 #include "utility.h"
46
 #include "serial.h"
41
 #include "serial.h"
47
 
42
 

+ 2
- 3
Marlin/MarlinConfig.h Переглянути файл

23
 #ifndef MARLIN_CONFIG_H
23
 #ifndef MARLIN_CONFIG_H
24
 #define MARLIN_CONFIG_H
24
 #define MARLIN_CONFIG_H
25
 
25
 
26
-#include "fastio.h"
27
 #include "macros.h"
26
 #include "macros.h"
27
+#include "src/HAL/HAL.h"
28
 #include "boards.h"
28
 #include "boards.h"
29
 #include "Version.h"
29
 #include "Version.h"
30
 #include "Configuration.h"
30
 #include "Configuration.h"
31
 #include "Conditionals_LCD.h"
31
 #include "Conditionals_LCD.h"
32
 #include "Configuration_adv.h"
32
 #include "Configuration_adv.h"
33
 #include "pins.h"
33
 #include "pins.h"
34
-#ifndef USBCON
34
+#if defined(ARDUINO_ARCH_AVR) && !defined(USBCON)
35
   #define HardwareSerial_h // trick to disable the standard HWserial
35
   #define HardwareSerial_h // trick to disable the standard HWserial
36
 #endif
36
 #endif
37
-#include "Arduino.h"
38
 #include "Conditionals_post.h"
37
 #include "Conditionals_post.h"
39
 #include "SanityCheck.h"
38
 #include "SanityCheck.h"
40
 
39
 

+ 14
- 36
Marlin/Marlin_main.cpp Переглянути файл

251
 #include "cardreader.h"
251
 #include "cardreader.h"
252
 #include "configuration_store.h"
252
 #include "configuration_store.h"
253
 #include "language.h"
253
 #include "language.h"
254
-#include "pins_arduino.h"
254
+#ifdef ARDUINO
255
+  #include "pins_arduino.h"
256
+#endif
255
 #include "math.h"
257
 #include "math.h"
256
 #include "nozzle.h"
258
 #include "nozzle.h"
257
 #include "duration_t.h"
259
 #include "duration_t.h"
275
   #include "buzzer.h"
277
   #include "buzzer.h"
276
 #endif
278
 #endif
277
 
279
 
278
-#if ENABLED(USE_WATCHDOG)
279
-  #include "watchdog.h"
280
-#endif
281
-
282
 #if ENABLED(MAX7219_DEBUG)
280
 #if ENABLED(MAX7219_DEBUG)
283
   #include "Max7219_Debug_LEDs.h"
281
   #include "Max7219_Debug_LEDs.h"
284
 #endif
282
 #endif
297
 #endif
295
 #endif
298
 
296
 
299
 #if HAS_SERVOS
297
 #if HAS_SERVOS
300
-  #include "servo.h"
298
+  #include "src/HAL/servo.h"
301
 #endif
299
 #endif
302
 
300
 
303
 #if HAS_DIGIPOTSS
301
 #if HAS_DIGIPOTSS
317
 #endif
315
 #endif
318
 
316
 
319
 #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
317
 #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
320
-  #include "endstop_interrupts.h"
318
+  #include "src/HAL/HAL_endstop_interrupts.h"
321
 #endif
319
 #endif
322
 
320
 
323
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
321
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
653
 static bool send_ok[BUFSIZE];
651
 static bool send_ok[BUFSIZE];
654
 
652
 
655
 #if HAS_SERVOS
653
 #if HAS_SERVOS
656
-  Servo servo[NUM_SERVOS];
654
+  HAL_SERVO_LIB servo[NUM_SERVOS];
657
   #define MOVE_SERVO(I, P) servo[I].move(P)
655
   #define MOVE_SERVO(I, P) servo[I].move(P)
658
   #if HAS_Z_SERVO_ENDSTOP
656
   #if HAS_Z_SERVO_ENDSTOP
659
     #define DEPLOY_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[0])
657
     #define DEPLOY_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[0])
789
 
787
 
790
 #endif
788
 #endif
791
 
789
 
792
-#if ENABLED(SDSUPPORT)
793
-  #include "SdFatUtil.h"
794
-  int freeMemory() { return SdFatUtil::FreeRam(); }
795
-#else
796
-extern "C" {
797
-  extern char __bss_end;
798
-  extern char __heap_start;
799
-  extern void* __brkval;
800
-
801
-  int freeMemory() {
802
-    int free_memory;
803
-    if ((int)__brkval == 0)
804
-      free_memory = ((int)&free_memory) - ((int)&__bss_end);
805
-    else
806
-      free_memory = ((int)&free_memory) - ((int)__brkval);
807
-    return free_memory;
808
-  }
809
-}
810
-#endif // !SDSUPPORT
811
-
812
 #if ENABLED(DIGIPOT_I2C)
790
 #if ENABLED(DIGIPOT_I2C)
813
   extern void digipot_i2c_set_current(uint8_t channel, float current);
791
   extern void digipot_i2c_set_current(uint8_t channel, float current);
814
   extern void digipot_i2c_init();
792
   extern void digipot_i2c_init();
11845
     delta_diagonal_rod_2_tower[C_AXIS] = sq(diagonal_rod + drt[C_AXIS]);
11823
     delta_diagonal_rod_2_tower[C_AXIS] = sq(diagonal_rod + drt[C_AXIS]);
11846
   }
11824
   }
11847
 
11825
 
11848
-  #if ENABLED(DELTA_FAST_SQRT)
11826
+  #if ENABLED(DELTA_FAST_SQRT) && defined(ARDUINO_ARCH_AVR)
11849
     /**
11827
     /**
11850
      * Fast inverse sqrt from Quake III Arena
11828
      * Fast inverse sqrt from Quake III Arena
11851
      * See: https://en.wikipedia.org/wiki/Fast_inverse_square_root
11829
      * See: https://en.wikipedia.org/wiki/Fast_inverse_square_root
13357
   #endif
13335
   #endif
13358
 
13336
 
13359
   MYSERIAL.begin(BAUDRATE);
13337
   MYSERIAL.begin(BAUDRATE);
13338
+  while(!MYSERIAL);
13360
   SERIAL_PROTOCOLLNPGM("start");
13339
   SERIAL_PROTOCOLLNPGM("start");
13361
   SERIAL_ECHO_START();
13340
   SERIAL_ECHO_START();
13362
 
13341
 
13363
   // Check startup - does nothing if bootloader sets MCUSR to 0
13342
   // Check startup - does nothing if bootloader sets MCUSR to 0
13364
-  byte mcu = MCUSR;
13343
+  byte mcu = HAL_get_reset_source();
13365
   if (mcu &  1) SERIAL_ECHOLNPGM(MSG_POWERUP);
13344
   if (mcu &  1) SERIAL_ECHOLNPGM(MSG_POWERUP);
13366
   if (mcu &  2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
13345
   if (mcu &  2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
13367
   if (mcu &  4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
13346
   if (mcu &  4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
13368
   if (mcu &  8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
13347
   if (mcu &  8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
13369
   if (mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
13348
   if (mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
13370
-  MCUSR = 0;
13349
+  HAL_clear_reset_source();
13350
+
13351
+  #if ENABLED(USE_WATCHDOG) //reinit watchdog after HAL_get_reset_source call
13352
+    watchdog_init();
13353
+  #endif
13371
 
13354
 
13372
   SERIAL_ECHOPGM(MSG_MARLIN);
13355
   SERIAL_ECHOPGM(MSG_MARLIN);
13373
   SERIAL_CHAR(' ');
13356
   SERIAL_CHAR(' ');
13406
 
13389
 
13407
   thermalManager.init();    // Initialize temperature loop
13390
   thermalManager.init();    // Initialize temperature loop
13408
 
13391
 
13409
-  #if ENABLED(USE_WATCHDOG)
13410
-    watchdog_init();
13411
-  #endif
13412
-
13413
   stepper.init();    // Initialize stepper, this enables interrupts!
13392
   stepper.init();    // Initialize stepper, this enables interrupts!
13414
   servo_init();
13393
   servo_init();
13415
 
13394
 
13619
   endstops.report_state();
13598
   endstops.report_state();
13620
   idle();
13599
   idle();
13621
 }
13600
 }
13622
-

+ 5
- 146
Marlin/Sd2Card.cpp Переглянути файл

31
 #if ENABLED(SDSUPPORT)
31
 #if ENABLED(SDSUPPORT)
32
 #include "Sd2Card.h"
32
 #include "Sd2Card.h"
33
 
33
 
34
-#if ENABLED(USE_WATCHDOG)
35
-  #include "watchdog.h"
36
-#endif
37
-
38
-//------------------------------------------------------------------------------
39
-#if DISABLED(SOFTWARE_SPI)
40
-  // functions for hardware SPI
41
-  //------------------------------------------------------------------------------
42
-  // make sure SPCR rate is in expected bits
43
-  #if (SPR0 != 0 || SPR1 != 1)
44
-    #error "unexpected SPCR bits"
45
-  #endif
46
-  /**
47
-   * Initialize hardware SPI
48
-   * Set SCK rate to F_CPU/pow(2, 1 + spiRate) for spiRate [0,6]
49
-   */
50
-  static void spiInit(uint8_t spiRate) {
51
-    // See avr processor documentation
52
-    SPCR = _BV(SPE) | _BV(MSTR) | (spiRate >> 1);
53
-    SPSR = spiRate & 1 || spiRate == 6 ? 0 : _BV(SPI2X);
54
-  }
55
-  //------------------------------------------------------------------------------
56
-  /** SPI receive a byte */
57
-  static uint8_t spiRec() {
58
-    SPDR = 0xFF;
59
-    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
60
-    return SPDR;
61
-  }
62
-  //------------------------------------------------------------------------------
63
-  /** SPI read data - only one call so force inline */
64
-  static inline __attribute__((always_inline))
65
-  void spiRead(uint8_t* buf, uint16_t nbyte) {
66
-    if (nbyte-- == 0) return;
67
-    SPDR = 0xFF;
68
-    for (uint16_t i = 0; i < nbyte; i++) {
69
-      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
70
-      buf[i] = SPDR;
71
-      SPDR = 0xFF;
72
-    }
73
-    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
74
-    buf[nbyte] = SPDR;
75
-  }
76
-  //------------------------------------------------------------------------------
77
-  /** SPI send a byte */
78
-  static void spiSend(uint8_t b) {
79
-    SPDR = b;
80
-    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
81
-  }
82
-  //------------------------------------------------------------------------------
83
-  /** SPI send block - only one call so force inline */
84
-  static inline __attribute__((always_inline))
85
-  void spiSendBlock(uint8_t token, const uint8_t* buf) {
86
-    SPDR = token;
87
-    for (uint16_t i = 0; i < 512; i += 2) {
88
-      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
89
-      SPDR = buf[i];
90
-      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
91
-      SPDR = buf[i + 1];
92
-    }
93
-    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
94
-  }
95
-       //------------------------------------------------------------------------------
96
-#else  // SOFTWARE_SPI
97
-       //------------------------------------------------------------------------------
98
-  /** nop to tune soft SPI timing */
99
-  #define nop asm volatile ("nop\n\t")
100
-  //------------------------------------------------------------------------------
101
-  /** Soft SPI receive byte */
102
-  static uint8_t spiRec() {
103
-    uint8_t data = 0;
104
-    // no interrupts during byte receive - about 8 us
105
-    cli();
106
-    // output pin high - like sending 0xFF
107
-    WRITE(SPI_MOSI_PIN, HIGH);
108
-
109
-    for (uint8_t i = 0; i < 8; i++) {
110
-      WRITE(SPI_SCK_PIN, HIGH);
111
-
112
-      // adjust so SCK is nice
113
-      nop;
114
-      nop;
115
-
116
-      data <<= 1;
117
-
118
-      if (READ(SPI_MISO_PIN)) data |= 1;
119
-
120
-      WRITE(SPI_SCK_PIN, LOW);
121
-    }
122
-    // enable interrupts
123
-    sei();
124
-    return data;
125
-  }
126
-  //------------------------------------------------------------------------------
127
-  /** Soft SPI read data */
128
-  static void spiRead(uint8_t* buf, uint16_t nbyte) {
129
-    for (uint16_t i = 0; i < nbyte; i++)
130
-      buf[i] = spiRec();
131
-  }
132
-  //------------------------------------------------------------------------------
133
-  /** Soft SPI send byte */
134
-  static void spiSend(uint8_t data) {
135
-    // no interrupts during byte send - about 8 us
136
-    cli();
137
-    for (uint8_t i = 0; i < 8; i++) {
138
-      WRITE(SPI_SCK_PIN, LOW);
139
-
140
-      WRITE(SPI_MOSI_PIN, data & 0x80);
141
-
142
-      data <<= 1;
143
-
144
-      WRITE(SPI_SCK_PIN, HIGH);
145
-    }
146
-    // hold SCK high for a few ns
147
-    nop;
148
-    nop;
149
-    nop;
150
-    nop;
151
-
152
-    WRITE(SPI_SCK_PIN, LOW);
153
-    // enable interrupts
154
-    sei();
155
-  }
156
-  //------------------------------------------------------------------------------
157
-  /** Soft SPI send block */
158
-  void spiSendBlock(uint8_t token, const uint8_t* buf) {
159
-    spiSend(token);
160
-    for (uint16_t i = 0; i < 512; i++)
161
-      spiSend(buf[i]);
162
-  }
163
-#endif  // SOFTWARE_SPI
164
 //------------------------------------------------------------------------------
34
 //------------------------------------------------------------------------------
165
 // send command and return error code.  Return zero for OK
35
 // send command and return error code.  Return zero for OK
166
 uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
36
 uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
310
   #endif
180
   #endif
311
 
181
 
312
   // set pin modes
182
   // set pin modes
313
-  pinMode(chipSelectPin_, OUTPUT);
314
-  chipSelectHigh();
315
-  SET_INPUT(SPI_MISO_PIN);
316
-  SET_OUTPUT(SPI_MOSI_PIN);
317
-  SET_OUTPUT(SPI_SCK_PIN);
183
+//todo: should use chipSelectPin ?
184
+  spiBegin();
318
 
185
 
319
-  #if DISABLED(SOFTWARE_SPI)
320
-    // SS must be in output mode even it is not chip select
321
-    SET_OUTPUT(SS_PIN);
322
-    // set SS high - may be chip select for another SPI device
323
-    #if SET_SPI_SS_HIGH
324
-      WRITE(SS_PIN, HIGH);
325
-    #endif  // SET_SPI_SS_HIGH
326
-    // set SCK rate for initialization commands
327
-    spiRate_ = SPI_SD_INIT_RATE;
328
-    spiInit(spiRate_);
329
-  #endif  // SOFTWARE_SPI
186
+  // set SCK rate for initialization commands
187
+  spiRate_ = SPI_SD_INIT_RATE;
188
+  spiInit(spiRate_);
330
 
189
 
331
   // must supply min of 74 clock cycles with CS high.
190
   // must supply min of 74 clock cycles with CS high.
332
   for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
191
   for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);

+ 6
- 12
Marlin/Sd2Card.h Переглянути файл

39
 #include "SdFatConfig.h"
39
 #include "SdFatConfig.h"
40
 #include "SdInfo.h"
40
 #include "SdInfo.h"
41
 //------------------------------------------------------------------------------
41
 //------------------------------------------------------------------------------
42
-// SPI speed is F_CPU/2^(1 + index), 0 <= index <= 6
43
-/** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */
44
-uint8_t const SPI_FULL_SPEED = 0;
45
-/** Set SCK rate to F_CPU/4. See Sd2Card::setSckRate(). */
46
-uint8_t const SPI_HALF_SPEED = 1;
47
-/** Set SCK rate to F_CPU/8. See Sd2Card::setSckRate(). */
48
-uint8_t const SPI_QUARTER_SPEED = 2;
49
-/** Set SCK rate to F_CPU/16. See Sd2Card::setSckRate(). */
50
-uint8_t const SPI_EIGHTH_SPEED = 3;
51
-/** Set SCK rate to F_CPU/32. See Sd2Card::setSckRate(). */
52
-uint8_t const SPI_SIXTEENTH_SPEED = 4;
53
-//------------------------------------------------------------------------------
54
 /** init timeout ms */
42
 /** init timeout ms */
55
 uint16_t const SD_INIT_TIMEOUT = 2000;
43
 uint16_t const SD_INIT_TIMEOUT = 2000;
56
 /** erase timeout ms */
44
 /** erase timeout ms */
133
 //------------------------------------------------------------------------------
121
 //------------------------------------------------------------------------------
134
 // SPI pin definitions - do not edit here - change in SdFatConfig.h
122
 // SPI pin definitions - do not edit here - change in SdFatConfig.h
135
 //
123
 //
124
+#define SD_CHIP_SELECT_PIN SS_PIN
125
+
126
+#if 0
136
 #if DISABLED(SOFTWARE_SPI)
127
 #if DISABLED(SOFTWARE_SPI)
137
   // hardware pin defs
128
   // hardware pin defs
138
   /** The default chip select pin for the SD card is SS. */
129
   /** The default chip select pin for the SD card is SS. */
156
   /** SPI Clock pin */
147
   /** SPI Clock pin */
157
   #define SPI_SCK_PIN SOFT_SPI_SCK_PIN
148
   #define SPI_SCK_PIN SOFT_SPI_SCK_PIN
158
 #endif  // SOFTWARE_SPI
149
 #endif  // SOFTWARE_SPI
150
+
151
+#endif
152
+
159
 //------------------------------------------------------------------------------
153
 //------------------------------------------------------------------------------
160
 /**
154
 /**
161
  * \class Sd2Card
155
  * \class Sd2Card

+ 3
- 2
Marlin/SdFile.h Переглянути файл

34
 
34
 
35
 #if ENABLED(SDSUPPORT)
35
 #if ENABLED(SDSUPPORT)
36
 #include "SdBaseFile.h"
36
 #include "SdBaseFile.h"
37
-#include <Print.h>
37
+//todo: HAL: create wrapper for Print?
38
+//#include <Print.h>
38
 #ifndef SdFile_h
39
 #ifndef SdFile_h
39
 #define SdFile_h
40
 #define SdFile_h
40
 //------------------------------------------------------------------------------
41
 //------------------------------------------------------------------------------
42
  * \class SdFile
43
  * \class SdFile
43
  * \brief SdBaseFile with Print.
44
  * \brief SdBaseFile with Print.
44
  */
45
  */
45
-class SdFile : public SdBaseFile, public Print {
46
+class SdFile : public SdBaseFile/*, public Print*/ {
46
  public:
47
  public:
47
   SdFile() {}
48
   SdFile() {}
48
   SdFile(const char* name, uint8_t oflag);
49
   SdFile(const char* name, uint8_t oflag);

+ 23
- 0
Marlin/boards.h Переглянути файл

76
 #define BOARD_BRAINWAVE         82   // Brainwave (AT90USB646)
76
 #define BOARD_BRAINWAVE         82   // Brainwave (AT90USB646)
77
 #define BOARD_SAV_MKI           83   // SAV Mk-I (AT90USB1286)
77
 #define BOARD_SAV_MKI           83   // SAV Mk-I (AT90USB1286)
78
 #define BOARD_TEENSY2           84   // Teensy++2.0 (AT90USB1286) - CLI compile: HARDWARE_MOTHERBOARD=84  make
78
 #define BOARD_TEENSY2           84   // Teensy++2.0 (AT90USB1286) - CLI compile: HARDWARE_MOTHERBOARD=84  make
79
+#define BOARD_TEENSY35_36       841  // Teensy3.5 and Teensy3.6
79
 #define BOARD_BRAINWAVE_PRO     85   // Brainwave Pro (AT90USB1286)
80
 #define BOARD_BRAINWAVE_PRO     85   // Brainwave Pro (AT90USB1286)
80
 #define BOARD_GEN3_PLUS         9    // Gen3+
81
 #define BOARD_GEN3_PLUS         9    // Gen3+
81
 #define BOARD_GEN3_MONOLITHIC   22   // Gen3 Monolithic Electronics
82
 #define BOARD_GEN3_MONOLITHIC   22   // Gen3 Monolithic Electronics
100
 #define BOARD_BAM_DICE_DUE      402  // 2PrintBeta BAM&DICE Due with STK drivers
101
 #define BOARD_BAM_DICE_DUE      402  // 2PrintBeta BAM&DICE Due with STK drivers
101
 #define BOARD_BQ_ZUM_MEGA_3D    503  // bq ZUM Mega 3D
102
 #define BOARD_BQ_ZUM_MEGA_3D    503  // bq ZUM Mega 3D
102
 #define BOARD_ZRIB_V20          504  // zrib V2.0 control board (Chinese knock off RAMPS replica)
103
 #define BOARD_ZRIB_V20          504  // zrib V2.0 control board (Chinese knock off RAMPS replica)
104
+//ARM 32
105
+#define BOARD_DUE3DOM          1411  // DUE3DOM for Arduino DUE
106
+#define BOARD_DUE3DOM_MINI     1412  // DUE3DOM MINI for Arduino DUE
107
+#define BOARD_RADDS            1502  // RADDS
108
+#define BOARD_RAMPS_FD_V1      1503  // RAMPS-FD v1
109
+#define BOARD_RAMPS_FD_V2      1504  // RAMPS-FD v2
110
+#define BOARD_RAMPS_SMART_EFB  1523  // RAMPS-SMART (Power outputs: Hotend, Fan, Bed)
111
+#define BOARD_RAMPS_SMART_EEB  1524  // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Bed)
112
+#define BOARD_RAMPS_SMART_EFF  1525  // RAMPS-SMART (Power outputs: Hotend, Fan0, Fan1)
113
+#define BOARD_RAMPS_SMART_EEF  1526  // RAMPS-SMART (Power outputs: Hotend0, Hotend1, Fan)
114
+#define BOARD_RAMPS_SMART_SF   1528  // RAMPS-SMART (Power outputs: Spindle, Controller Fan)
115
+#define BOARD_RAMPS_DUO_EFB    1533  // RAMPS Duo (Power outputs: Hotend, Fan, Bed)
116
+#define BOARD_RAMPS_DUO_EEB    1534  // RAMPS Duo (Power outputs: Hotend0, Hotend1, Bed)
117
+#define BOARD_RAMPS_DUO_EFF    1535  // RAMPS Duo (Power outputs: Hotend, Fan0, Fan1)
118
+#define BOARD_RAMPS_DUO_EEF    1536  // RAMPS Duo (Power outputs: Hotend0, Hotend1, Fan)
119
+#define BOARD_RAMPS_DUO_SF     1538  // RAMPS Duo (Power outputs: Spindle, Controller Fan)
120
+#define BOARD_RAMPS4DUE_EFB    1543  // RAMPS4DUE (Power outputs: Hotend, Fan, Bed)
121
+#define BOARD_RAMPS4DUE_EEB    1544  // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Bed)
122
+#define BOARD_RAMPS4DUE_EFF    1545  // RAMPS4DUE (Power outputs: Hotend, Fan0, Fan1)
123
+#define BOARD_RAMPS4DUE_EEF    1546  // RAMPS4DUE (Power outputs: Hotend0, Hotend1, Fan)
124
+#define BOARD_RAMPS4DUE_SF     1548  // RAMPS4DUE (Power outputs: Spindle, Controller Fan)
125
+#define BOARD_ALLIGATOR        1602  // Alligator Board R2
103
 
126
 
104
 #define MB(board) (MOTHERBOARD==BOARD_##board)
127
 #define MB(board) (MOTHERBOARD==BOARD_##board)
105
 
128
 

+ 0
- 1
Marlin/buzzer.h Переглянути файл

24
 #define __BUZZER_H__
24
 #define __BUZZER_H__
25
 
25
 
26
 #include "types.h"
26
 #include "types.h"
27
-#include "fastio.h"
28
 #include "circularqueue.h"
27
 #include "circularqueue.h"
29
 #include "temperature.h"
28
 #include "temperature.h"
30
 
29
 

+ 1
- 1
Marlin/circularqueue.h Переглянути файл

23
 #ifndef __CIRCULARQUEUE_H__
23
 #ifndef __CIRCULARQUEUE_H__
24
 #define __CIRCULARQUEUE_H__
24
 #define __CIRCULARQUEUE_H__
25
 
25
 
26
-#include <Arduino.h>
26
+#include <stdint.h>
27
 
27
 
28
 /**
28
 /**
29
  * @brief   Circular Queue class
29
  * @brief   Circular Queue class

+ 9
- 39
Marlin/configuration_store.cpp Переглянути файл

252
 }
252
 }
253
 
253
 
254
 #if ENABLED(EEPROM_SETTINGS)
254
 #if ENABLED(EEPROM_SETTINGS)
255
+  #include "src/HAL/persistent_store_api.h"
255
 
256
 
256
   #define DUMMY_PID_VALUE 3000.0f
257
   #define DUMMY_PID_VALUE 3000.0f
257
-  #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
258
+  #define EEPROM_START() int eeprom_index = EEPROM_OFFSET; HAL::PersistentStore::access_start()
259
+  #define EEPROM_FINISH() HAL::PersistentStore::access_finish()
258
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
260
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
259
-  #define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
260
-  #define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
261
+  #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
262
+  #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
261
   #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
263
   #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
262
 
264
 
263
   const char version[4] = EEPROM_VERSION;
265
   const char version[4] = EEPROM_VERSION;
268
     int MarlinSettings::meshes_begin;
270
     int MarlinSettings::meshes_begin;
269
   #endif
271
   #endif
270
 
272
 
271
-  void MarlinSettings::write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
272
-    if (eeprom_error) return;
273
-    while (size--) {
274
-      uint8_t * const p = (uint8_t * const)pos;
275
-      uint8_t v = *value;
276
-      // EEPROM has only ~100,000 write cycles,
277
-      // so only write bytes that have changed!
278
-      if (v != eeprom_read_byte(p)) {
279
-        eeprom_write_byte(p, v);
280
-        if (eeprom_read_byte(p) != v) {
281
-          SERIAL_ECHO_START();
282
-          SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
283
-          eeprom_error = true;
284
-          return;
285
-        }
286
-      }
287
-      crc16(crc, &v, 1);
288
-      pos++;
289
-      value++;
290
-    };
291
-  }
292
-
293
-  void MarlinSettings::read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
294
-    if (eeprom_error) return;
295
-    do {
296
-      uint8_t c = eeprom_read_byte((unsigned char*)pos);
297
-      *value = c;
298
-      crc16(crc, &c, 1);
299
-      pos++;
300
-      value++;
301
-    } while (--size);
302
-  }
303
-
304
   /**
273
   /**
305
    * M500 - Store Configuration
274
    * M500 - Store Configuration
306
    */
275
    */
668
       if (ubl.state.storage_slot >= 0)
637
       if (ubl.state.storage_slot >= 0)
669
         store_mesh(ubl.state.storage_slot);
638
         store_mesh(ubl.state.storage_slot);
670
     #endif
639
     #endif
671
-
640
+    EEPROM_FINISH();
672
     return !eeprom_error;
641
     return !eeprom_error;
673
   }
642
   }
674
 
643
 
1067
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1036
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1068
       report();
1037
       report();
1069
     #endif
1038
     #endif
1039
+    EEPROM_FINISH();
1070
 
1040
 
1071
     return !eeprom_error;
1041
     return !eeprom_error;
1072
   }
1042
   }
1107
         uint16_t crc = 0;
1077
         uint16_t crc = 0;
1108
         int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
1078
         int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
1109
 
1079
 
1110
-        write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
1080
+        HAL::PersistentStore::write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
1111
 
1081
 
1112
         // Write crc to MAT along with other data, or just tack on to the beginning or end
1082
         // Write crc to MAT along with other data, or just tack on to the beginning or end
1113
 
1083
 
1138
         uint16_t crc = 0;
1108
         uint16_t crc = 0;
1139
         int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
1109
         int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
1140
         uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
1110
         uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
1141
-        read_data(pos, dest, sizeof(ubl.z_values), &crc);
1111
+        HAL::PersistentStore::read_data(pos, dest, sizeof(ubl.z_values), &crc);
1142
 
1112
 
1143
         // Compare crc with crc from MAT, or read from end
1113
         // Compare crc with crc from MAT, or read from end
1144
 
1114
 

+ 0
- 2
Marlin/configuration_store.h Переглянути файл

72
 
72
 
73
       #endif
73
       #endif
74
 
74
 
75
-      static void write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
76
-      static void read_data(int &pos, uint8_t *value, uint16_t size, uint16_t *crc);
77
     #endif
75
     #endif
78
 };
76
 };
79
 
77
 

+ 108
- 0
Marlin/dac_dac084s085.cpp Переглянути файл

1
+/***************************************************************
2
+ *
3
+ * External DAC for Alligator Board
4
+ *
5
+ ****************************************************************/
6
+#include "Marlin.h"
7
+
8
+#if MB(ALLIGATOR)
9
+  #include "stepper.h"
10
+  #include "dac_dac084s085.h"
11
+
12
+  dac084s085::dac084s085() {
13
+    return ;
14
+  }
15
+
16
+  void dac084s085::begin() {
17
+    uint8_t externalDac_buf[2] = {0x20,0x00};//all off
18
+
19
+    // All SPI chip-select HIGH
20
+    pinMode (DAC0_SYNC, OUTPUT);
21
+    digitalWrite( DAC0_SYNC , HIGH );
22
+    #if EXTRUDERS > 1
23
+      pinMode (DAC1_SYNC, OUTPUT);
24
+      digitalWrite( DAC1_SYNC , HIGH );
25
+    #endif
26
+    digitalWrite( SPI_EEPROM1_CS , HIGH );
27
+    digitalWrite( SPI_EEPROM2_CS , HIGH );
28
+    digitalWrite( SPI_FLASH_CS , HIGH );
29
+    digitalWrite( SS_PIN , HIGH );
30
+    spiBegin();
31
+
32
+    //init onboard DAC
33
+    delayMicroseconds(2U);
34
+    digitalWrite( DAC0_SYNC , LOW );
35
+    delayMicroseconds(2U);
36
+    digitalWrite( DAC0_SYNC , HIGH );
37
+    delayMicroseconds(2U);
38
+    digitalWrite( DAC0_SYNC , LOW );
39
+
40
+    spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
41
+    digitalWrite( DAC0_SYNC , HIGH );
42
+
43
+    #if EXTRUDERS > 1
44
+      //init Piggy DAC
45
+      delayMicroseconds(2U);
46
+      digitalWrite( DAC1_SYNC , LOW );
47
+      delayMicroseconds(2U);
48
+      digitalWrite( DAC1_SYNC , HIGH );
49
+      delayMicroseconds(2U);
50
+      digitalWrite( DAC1_SYNC , LOW );
51
+
52
+      spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
53
+      digitalWrite( DAC1_SYNC , HIGH );
54
+    #endif
55
+
56
+    return;
57
+  }
58
+
59
+  void dac084s085::setValue(uint8_t channel, uint8_t value) {
60
+    if(channel >= 7) // max channel (X,Y,Z,E0,E1,E2,E3)
61
+      return;
62
+    if(value > 255) value = 255;
63
+
64
+    uint8_t externalDac_buf[2] = {0x10,0x00};
65
+
66
+    if(channel > 3)
67
+      externalDac_buf[0] |= (7 - channel << 6);
68
+    else
69
+      externalDac_buf[0] |= (3 - channel << 6);
70
+
71
+    externalDac_buf[0] |= (value>>4);
72
+    externalDac_buf[1] |= (value<<4);
73
+    
74
+    // All SPI chip-select HIGH
75
+    digitalWrite( DAC0_SYNC , HIGH );
76
+    #if EXTRUDERS > 1
77
+      digitalWrite( DAC1_SYNC , HIGH );
78
+    #endif
79
+    digitalWrite( SPI_EEPROM1_CS , HIGH );
80
+    digitalWrite( SPI_EEPROM2_CS , HIGH );
81
+    digitalWrite( SPI_FLASH_CS , HIGH );
82
+    digitalWrite( SS_PIN , HIGH );
83
+
84
+    if(channel > 3) { // DAC Piggy E1,E2,E3
85
+
86
+      digitalWrite(DAC1_SYNC , LOW);
87
+      delayMicroseconds(2U);
88
+      digitalWrite(DAC1_SYNC , HIGH);
89
+      delayMicroseconds(2U);
90
+      digitalWrite(DAC1_SYNC , LOW);
91
+    }
92
+
93
+    else { // DAC onboard X,Y,Z,E0
94
+
95
+      digitalWrite(DAC0_SYNC , LOW);
96
+      delayMicroseconds(2U);
97
+      digitalWrite(DAC0_SYNC , HIGH);
98
+      delayMicroseconds(2U);
99
+      digitalWrite(DAC0_SYNC , LOW);
100
+    }
101
+
102
+    delayMicroseconds(2U);
103
+    spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
104
+
105
+    return;
106
+  }
107
+
108
+#endif

+ 11
- 0
Marlin/dac_dac084s085.h Переглянути файл

1
+#ifndef dac084s085_h
2
+#define dac084s085_h
3
+
4
+class dac084s085 {
5
+  public:
6
+    dac084s085();
7
+    static void begin(void);
8
+    static void setValue(uint8_t channel, uint8_t value);
9
+};
10
+
11
+#endif //dac084s085_h

+ 1
- 1
Marlin/hex_print_routines.cpp Переглянути файл

43
 }
43
 }
44
 
44
 
45
 char* hex_address(const void * const w) {
45
 char* hex_address(const void * const w) {
46
-  (void)hex_word((uint16_t)w);
46
+  (void)hex_word((int)w);
47
   return _hex;
47
   return _hex;
48
 }
48
 }
49
 
49
 

+ 0
- 5
Marlin/macros.h Переглянути файл

36
 #define _O2          __attribute__((optimize("O2")))
36
 #define _O2          __attribute__((optimize("O2")))
37
 #define _O3          __attribute__((optimize("O3")))
37
 #define _O3          __attribute__((optimize("O3")))
38
 
38
 
39
-// Bracket code that shouldn't be interrupted
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
 
39
 
45
 // Clock speed factors
40
 // Clock speed factors
46
 #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20
41
 #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20

+ 70
- 42
Marlin/pins.h Переглянути файл

231
 #elif MB(5DPRINT)
231
 #elif MB(5DPRINT)
232
   #include "pins_5DPRINT.h"           // AT90USB1286
232
   #include "pins_5DPRINT.h"           // AT90USB1286
233
 
233
 
234
+//
235
+// 32-bit Boards
236
+//
237
+
238
+#elif MB(TEENSY35_36)
239
+  #include "pins_TEENSY35_36.h"
240
+#elif MB(DUE3DOM)
241
+  #include "pins_DUE3DOM.h"
242
+#elif MB(DUE3DOM_MINI)
243
+  #include "pins_DUE3DOM_MINI.h"
244
+#elif MB(RADDS)
245
+  #include "pins_RADDS.h"
246
+#elif MB(RAMPS_FD_V1)
247
+  #include "pins_RAMPS_FD.h"
248
+#elif MB(RAMPS_FD_V2)
249
+  #include "pins_RAMPS_FD_V2.h"
250
+#elif MB(RAMPS_SMART_EFB)
251
+  #define IS_RAMPS_EFB
252
+  #include "pins_RAMPS_SMART.h"
253
+#elif MB(RAMPS_SMART_EEB)
254
+  #define IS_RAMPS_EEB
255
+  #include "pins_RAMPS_SMART.h"
256
+#elif MB(RAMPS_SMART_EFF)
257
+  #define IS_RAMPS_EFF
258
+  #include "pins_RAMPS_SMART.h"
259
+#elif MB(RAMPS_SMART_EEF)
260
+  #define IS_RAMPS_EEF
261
+  #include "pins_RAMPS_SMART.h"
262
+#elif MB(RAMPS_SMART_SF)
263
+  #define IS_RAMPS_SF
264
+  #include "pins_RAMPS_SMART.h"
265
+#elif MB(RAMPS_DUO_EFB)
266
+  #define IS_RAMPS_EFB
267
+  #include "pins_RAMPS_DUO.h"
268
+#elif MB(RAMPS_DUO_EEB)
269
+  #define IS_RAMPS_EEB
270
+  #include "pins_RAMPS_DUO.h"
271
+#elif MB(RAMPS_DUO_EFF)
272
+  #define IS_RAMPS_EFF
273
+  #include "pins_RAMPS_DUO.h"
274
+#elif MB(RAMPS_DUO_EEF)
275
+  #define IS_RAMPS_EEF
276
+  #include "pins_RAMPS_DUO.h"
277
+#elif MB(RAMPS_DUO_SF)
278
+  #define IS_RAMPS_SF
279
+  #include "pins_RAMPS_DUO.h"
280
+#elif MB(RAMPS4DUE_EFB)
281
+  #define IS_RAMPS_EFB
282
+  #include "pins_RAMPS4DUE.h"
283
+#elif MB(RAMPS4DUE_EEB)
284
+  #define IS_RAMPS_EEB
285
+  #include "pins_RAMPS4DUE.h"
286
+#elif MB(RAMPS4DUE_EFF)
287
+  #define IS_RAMPS_EFF
288
+  #include "pins_RAMPS4DUE.h"
289
+#elif MB(RAMPS4DUE_EEF)
290
+  #define IS_RAMPS_EEF
291
+  #include "pins_RAMPS4DUE.h"
292
+#elif MB(RAMPS4DUE_SF)
293
+  #define IS_RAMPS_SF
294
+  #include "pins_RAMPS4DUE.h"
295
+#elif MB(ALLIGATOR)
296
+  #include "pins_ALLIGATOR_R2.h"
297
+#elif MB(RAMPS_FD_V1) || MB(RAMPS_FD_V2)
298
+  #include "pins_RAMPS_FD_v1.h"
299
+
234
 #else
300
 #else
235
   #error "Unknown MOTHERBOARD value set in Configuration.h"
301
   #error "Unknown MOTHERBOARD value set in Configuration.h"
236
 #endif
302
 #endif
606
 
672
 
607
 #define HAS_DIGIPOTSS (PIN_EXISTS(DIGIPOTSS))
673
 #define HAS_DIGIPOTSS (PIN_EXISTS(DIGIPOTSS))
608
 
674
 
609
-/**
610
- * Define SPI Pins: SCK, MISO, MOSI, SS
611
- */
612
-#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
613
-  #define AVR_SCK_PIN  13
614
-  #define AVR_MISO_PIN 12
615
-  #define AVR_MOSI_PIN 11
616
-  #define AVR_SS_PIN   10
617
-#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)
618
-  #define AVR_SCK_PIN  7
619
-  #define AVR_MISO_PIN 6
620
-  #define AVR_MOSI_PIN 5
621
-  #define AVR_SS_PIN   4
622
-#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
623
-  #define AVR_SCK_PIN  52
624
-  #define AVR_MISO_PIN 50
625
-  #define AVR_MOSI_PIN 51
626
-  #define AVR_SS_PIN   53
627
-#elif defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__)
628
-  #define AVR_SCK_PIN  21
629
-  #define AVR_MISO_PIN 23
630
-  #define AVR_MOSI_PIN 22
631
-  #define AVR_SS_PIN   20
632
-#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
633
-  #define AVR_SCK_PIN  10
634
-  #define AVR_MISO_PIN 12
635
-  #define AVR_MOSI_PIN 11
636
-  #define AVR_SS_PIN   16
637
-#endif
638
-
639
-#ifndef SCK_PIN
640
-  #define SCK_PIN  AVR_SCK_PIN
641
-#endif
642
-#ifndef MISO_PIN
643
-  #define MISO_PIN AVR_MISO_PIN
644
-#endif
645
-#ifndef MOSI_PIN
646
-  #define MOSI_PIN AVR_MOSI_PIN
647
-#endif
648
-#ifndef SS_PIN
649
-  #define SS_PIN   AVR_SS_PIN
650
-#endif
675
+// Note: default SPI pins are defined in the HAL
676
+
677
+#include "src/HAL/HAL_spi_pins.h"
678
+
651
 
679
 
652
 #endif // __PINS_H__
680
 #endif // __PINS_H__

+ 4
- 2
Marlin/pins_RAMPS.h Переглянути файл

44
  *         7 | 11
44
  *         7 | 11
45
  */
45
  */
46
 
46
 
47
-#if !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__)
48
-  #error "Oops!  Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu."
47
+#if !defined(IS_RAMPS_SMART) && !defined(IS_RAMPS_DUO) && !defined(IS_RAMPS4DUE)
48
+  #if !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__)
49
+    #error "Oops!  Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu."
50
+  #endif
49
 #endif
51
 #endif
50
 
52
 
51
 #ifndef BOARD_NAME
53
 #ifndef BOARD_NAME

+ 1
- 1
Marlin/planner.cpp Переглянути файл

1222
   }
1222
   }
1223
   block->acceleration_steps_per_s2 = accel;
1223
   block->acceleration_steps_per_s2 = accel;
1224
   block->acceleration = accel / steps_per_mm;
1224
   block->acceleration = accel / steps_per_mm;
1225
-  block->acceleration_rate = (long)(accel * 16777216.0 / ((F_CPU) * 0.125)); // * 8.388608
1225
+  block->acceleration_rate = (long)(accel * 16777216.0 / (HAL_STEPPER_TIMER_RATE)); // 16777216 = <<24
1226
 
1226
 
1227
   // Initial limit on the segment entry velocity
1227
   // Initial limit on the segment entry velocity
1228
   float vmax_junction;
1228
   float vmax_junction;

+ 8
- 4
Marlin/printcounter.h Переглянути файл

26
 #include "macros.h"
26
 #include "macros.h"
27
 #include "language.h"
27
 #include "language.h"
28
 #include "stopwatch.h"
28
 #include "stopwatch.h"
29
-#include <avr/eeprom.h>
30
-
31
 
29
 
32
 // Print debug messages with M111 S2
30
 // Print debug messages with M111 S2
33
 //#define DEBUG_PRINTCOUNTER
31
 //#define DEBUG_PRINTCOUNTER
51
      * @brief EEPROM address
49
      * @brief EEPROM address
52
      * @details Defines the start offset address where the data is stored.
50
      * @details Defines the start offset address where the data is stored.
53
      */
51
      */
54
-    const uint16_t address = 0x32;
55
-
52
+    #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
53
+      // round up address to next page boundary (assuming 32 byte pages)
54
+      const uint32_t address = 0x40;
55
+    #elif defined(CPU_32_BIT)
56
+      const uint32_t address = 0x32;
57
+    #else
58
+      const uint16_t address = 0x32;
59
+    #endif
56
     /**
60
     /**
57
      * @brief Interval in seconds between counter updates
61
      * @brief Interval in seconds between counter updates
58
      * @details This const value defines what will be the time between each
62
      * @details This const value defines what will be the time between each

Marlin/spi.h → Marlin/private_spi.h Переглянути файл

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#ifndef __SPI_H__
24
-#define __SPI_H__
23
+#ifndef __PRIVATE_SPI_H__
24
+#define __PRIVATE_SPI_H__
25
 
25
 
26
 #include <stdint.h>
26
 #include <stdint.h>
27
 #include "softspi.h"
27
 #include "softspi.h"
54
 
54
 
55
 };
55
 };
56
 
56
 
57
-#endif // __SPI_H__
57
+#endif // __PRIVATE_SPI_H__

+ 16
- 10
Marlin/serial.h Переглянути файл

23
 #ifndef __SERIAL_H__
23
 #ifndef __SERIAL_H__
24
 #define __SERIAL_H__
24
 #define __SERIAL_H__
25
 
25
 
26
-#include "MarlinConfig.h"
26
+#include "src/HAL/HAL.h"
27
 
27
 
28
-#ifdef USBCON
29
-  #include "HardwareSerial.h"
30
-  #if ENABLED(BLUETOOTH)
31
-    #define MYSERIAL bluetoothSerial
28
+//todo: HAL: breaks encapsulation
29
+// For AVR only, define a serial interface based on configuration
30
+#ifdef ARDUINO_ARCH_AVR
31
+  #ifdef USBCON
32
+    #include "HardwareSerial.h"
33
+    #if ENABLED(BLUETOOTH)
34
+      #define MYSERIAL bluetoothSerial
35
+    #else
36
+      #define MYSERIAL Serial
37
+    #endif // BLUETOOTH
32
   #else
38
   #else
33
-    #define MYSERIAL Serial
34
-  #endif // BLUETOOTH
35
-#else
36
-  #include "MarlinSerial.h"
37
-  #define MYSERIAL customizedSerial
39
+    #include "src/HAL/HAL_AVR/MarlinSerial.h"
40
+    #define MYSERIAL customizedSerial
41
+  #endif
38
 #endif
42
 #endif
39
 
43
 
44
+#include "MarlinConfig.h"
45
+
40
 extern const char echomagic[] PROGMEM;
46
 extern const char echomagic[] PROGMEM;
41
 extern const char errormagic[] PROGMEM;
47
 extern const char errormagic[] PROGMEM;
42
 
48
 

+ 94
- 0
Marlin/src/HAL/HAL.h Переглянути файл

1
+/* **************************************************************************
2
+
3
+ Marlin 3D Printer Firmware
4
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+****************************************************************************/
20
+
21
+/**
22
+ * Description: HAL wrapper
23
+ *
24
+ * Supports platforms :
25
+ *    ARDUINO_ARCH_SAM : For Arduino Due and other boards based on Atmel SAM3X8E
26
+ *    ARDUINO_ARCH_AVR : For all Atmel AVR boards
27
+ */
28
+
29
+#ifndef _HAL_H
30
+#define _HAL_H
31
+
32
+#include <stdint.h>
33
+
34
+/**
35
+ * SPI speed where 0 <= index <= 6
36
+ *
37
+ * Approximate rates :
38
+ *
39
+ *  0 :  8 - 10 MHz
40
+ *  1 :  4 - 5 MHz
41
+ *  2 :  2 - 2.5 MHz
42
+ *  3 :  1 - 1.25 MHz
43
+ *  4 :  500 - 625 kHz
44
+ *  5 :  250 - 312 kHz
45
+ *  6 :  125 - 156 kHz
46
+ *
47
+ *  On AVR, actual speed is F_CPU/2^(1 + index).
48
+ *  On other platforms, speed should be in range given above where possible.
49
+ */
50
+
51
+/** Set SCK to max rate */
52
+uint8_t const SPI_FULL_SPEED = 0;
53
+/** Set SCK rate to half max rate. */
54
+uint8_t const SPI_HALF_SPEED = 1;
55
+/** Set SCK rate to quarter max rate. */
56
+uint8_t const SPI_QUARTER_SPEED = 2;
57
+/** Set SCK rate to 1/8 max rate. */
58
+uint8_t const SPI_EIGHTH_SPEED = 3;
59
+/** Set SCK rate to 1/16 of max rate. */
60
+uint8_t const SPI_SIXTEENTH_SPEED = 4;
61
+/** Set SCK rate to 1/32 of max rate. */
62
+uint8_t const SPI_SPEED_5 = 5;
63
+/** Set SCK rate to 1/64 of max rate. */
64
+uint8_t const SPI_SPEED_6 = 6;
65
+
66
+// Standard SPI functions
67
+/** Initialise SPI bus */
68
+void spiBegin(void);
69
+/** Configure SPI for specified SPI speed */
70
+void spiInit(uint8_t spiRate);
71
+/** Write single byte to SPI */
72
+void spiSend(uint8_t b);
73
+/** Read single byte from SPI */
74
+uint8_t spiRec(void);
75
+/** Read from SPI into buffer */
76
+void spiRead(uint8_t* buf, uint16_t nbyte);
77
+/** Write token and then write from 512 byte buffer to SPI (for SD card) */
78
+void spiSendBlock(uint8_t token, const uint8_t* buf);
79
+
80
+#ifdef ARDUINO_ARCH_AVR
81
+  #include "HAL_AVR/HAL_AVR.h"
82
+#elif defined(ARDUINO_ARCH_SAM)
83
+  #define CPU_32_BIT
84
+  #include "HAL_DUE/HAL_Due.h"
85
+  #include "math_32bit.h"
86
+#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
87
+  #define CPU_32_BIT
88
+  #include "HAL_TEENSY35_36/HAL_Teensy.h"
89
+  #include "math_32bit.h"
90
+#else
91
+  #error Unsupported Platform!
92
+#endif
93
+
94
+#endif /* HAL_H_ */

+ 100
- 0
Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp Переглянути файл

1
+/* **************************************************************************
2
+
3
+ Marlin 3D Printer Firmware
4
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+
6
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
7
+ 
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+
21
+****************************************************************************/
22
+
23
+/**
24
+ * Description: HAL for AVR
25
+ *
26
+ * For ARDUINO_ARCH_AVR
27
+ */
28
+
29
+
30
+#ifdef ARDUINO_ARCH_AVR
31
+
32
+// --------------------------------------------------------------------------
33
+// Includes
34
+// --------------------------------------------------------------------------
35
+
36
+#include "../HAL.h"
37
+#include "../../../macros.h"
38
+
39
+// --------------------------------------------------------------------------
40
+// Externals
41
+// --------------------------------------------------------------------------
42
+
43
+// --------------------------------------------------------------------------
44
+// Local defines
45
+// --------------------------------------------------------------------------
46
+
47
+// --------------------------------------------------------------------------
48
+// Types
49
+// --------------------------------------------------------------------------
50
+
51
+// --------------------------------------------------------------------------
52
+// Variables
53
+// --------------------------------------------------------------------------
54
+
55
+// --------------------------------------------------------------------------
56
+// Public Variables
57
+// --------------------------------------------------------------------------
58
+
59
+//uint8_t MCUSR;
60
+
61
+// --------------------------------------------------------------------------
62
+// Private Variables
63
+// --------------------------------------------------------------------------
64
+
65
+// --------------------------------------------------------------------------
66
+// Function prototypes
67
+// --------------------------------------------------------------------------
68
+
69
+// --------------------------------------------------------------------------
70
+// Private functions
71
+// --------------------------------------------------------------------------
72
+
73
+// --------------------------------------------------------------------------
74
+// Public functions
75
+// --------------------------------------------------------------------------
76
+
77
+#if ENABLED(SDSUPPORT)
78
+  #include "../../../SdFatUtil.h"
79
+  int freeMemory() { return SdFatUtil::FreeRam(); }
80
+#else
81
+
82
+extern "C" {
83
+  extern char __bss_end;
84
+  extern char __heap_start;
85
+  extern void* __brkval;
86
+
87
+  int freeMemory() {
88
+    int free_memory;
89
+    if ((int)__brkval == 0)
90
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
91
+    else
92
+      free_memory = ((int)&free_memory) - ((int)__brkval);
93
+    return free_memory;
94
+  }
95
+}
96
+
97
+#endif //!SDSUPPORT
98
+
99
+#endif
100
+

+ 160
- 0
Marlin/src/HAL/HAL_AVR/HAL_AVR.h Переглянути файл

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

Marlin/pinsDebug.h → Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h Переглянути файл

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+#ifndef HAL_PINSDEBUG_AVR_H
24
+
25
+void HAL_print_analog_pin(char buffer[], int8_t pin) {
26
+  sprintf(buffer, "(A%2d)  ", int(pin - analogInputToDigitalPin(0)));
27
+}
28
+
29
+void HAL_analog_pin_state(char buffer[], int8_t pin) {
30
+  sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
31
+}
32
+
23
 bool endstop_monitor_flag = false;
33
 bool endstop_monitor_flag = false;
24
 
34
 
25
 #define NAME_FORMAT "%-35s"   // one place to specify the format of all the sources of names
35
 #define NAME_FORMAT "%-35s"   // one place to specify the format of all the sources of names
46
 #define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
56
 #define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
47
 #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
57
 #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
48
 
58
 
49
-#include "pinsDebug_list.h"
59
+#include "../../../pinsDebug_list.h"
50
 #line 51
60
 #line 51
51
 
61
 
52
 // manually add pins that have names that are macros which don't play well with these macros
62
 // manually add pins that have names that are macros which don't play well with these macros
97
     #endif
107
     #endif
98
   #endif
108
   #endif
99
 
109
 
100
-  #include "pinsDebug_list.h"
110
+  #include "../../../pinsDebug_list.h"
101
   #line 102
111
   #line 102
102
 
112
 
103
 };
113
 };
146
  * Print a pin's PWM status.
156
  * Print a pin's PWM status.
147
  * Return true if it's currently a PWM pin.
157
  * Return true if it's currently a PWM pin.
148
  */
158
  */
149
-static bool pwm_status(uint8_t pin) {
159
+static bool HAL_pwm_status(uint8_t pin) {
150
   char buffer[20];   // for the sprintf statements
160
   char buffer[20];   // for the sprintf statements
151
 
161
 
152
   switch (digitalPinToTimer_DEBUG(pin)) {
162
   switch (digitalPinToTimer_DEBUG(pin)) {
338
   if (TEST(*TMSK, TOIE)) err_prob_interrupt();
348
   if (TEST(*TMSK, TOIE)) err_prob_interrupt();
339
 }
349
 }
340
 
350
 
341
-static void pwm_details(uint8_t pin) {
351
+static void HAL_pwm_details(uint8_t pin) {
342
   switch (digitalPinToTimer_DEBUG(pin)) {
352
   switch (digitalPinToTimer_DEBUG(pin)) {
343
 
353
 
344
     #if defined(TCCR0A) && defined(COM0A1)
354
     #if defined(TCCR0A) && defined(COM0A1)
514
                 print_input_or_output(false);
524
                 print_input_or_output(false);
515
                 SERIAL_PROTOCOL(digitalRead_mod(pin));
525
                 SERIAL_PROTOCOL(digitalRead_mod(pin));
516
               }
526
               }
517
-              else if (pwm_status(pin)) {
527
+              else if (HAL_pwm_status(pin)) {
518
                 // do nothing
528
                 // do nothing
519
               }
529
               }
520
               else {
530
               else {
522
                 SERIAL_PROTOCOL(digitalRead_mod(pin));
532
                 SERIAL_PROTOCOL(digitalRead_mod(pin));
523
               }
533
               }
524
             }
534
             }
525
-            if (!multi_name_pin && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
535
+            if (!multi_name_pin && extended) HAL_pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
526
           }
536
           }
527
         }
537
         }
528
       }
538
       }
581
     SERIAL_EOL();
591
     SERIAL_EOL();
582
   }
592
   }
583
 }
593
 }
594
+
595
+#endif //HAL_PINSDEBUG_AVR_H

+ 213
- 0
Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Originally from Arduino Sd2Card Library
25
+ * Copyright (C) 2009 by William Greiman
26
+ */
27
+ 
28
+/**
29
+ * Description: HAL for AVR - SPI functions
30
+ *
31
+ * For ARDUINO_ARCH_AVR
32
+ */
33
+
34
+#ifdef ARDUINO_ARCH_AVR
35
+
36
+// --------------------------------------------------------------------------
37
+// Includes
38
+// --------------------------------------------------------------------------
39
+
40
+#include "../../../MarlinConfig.h"
41
+
42
+// --------------------------------------------------------------------------
43
+// Public Variables
44
+// --------------------------------------------------------------------------
45
+
46
+
47
+// --------------------------------------------------------------------------
48
+// Public functions
49
+// --------------------------------------------------------------------------
50
+
51
+void spiBegin (void) {
52
+  SET_OUTPUT(SS_PIN);
53
+  WRITE(SS_PIN, HIGH);
54
+  SET_OUTPUT(SCK_PIN);
55
+  SET_INPUT(MISO_PIN);
56
+  SET_OUTPUT(MOSI_PIN);
57
+
58
+  #if DISABLED(SOFTWARE_SPI)
59
+    // SS must be in output mode even it is not chip select
60
+    SET_OUTPUT(SS_PIN);
61
+    // set SS high - may be chip select for another SPI device
62
+    #if SET_SPI_SS_HIGH
63
+      WRITE(SS_PIN, HIGH);
64
+    #endif  // SET_SPI_SS_HIGH
65
+    // set a default rate
66
+    spiInit(1);
67
+  #endif  // SOFTWARE_SPI
68
+}
69
+
70
+
71
+//------------------------------------------------------------------------------
72
+#if DISABLED(SOFTWARE_SPI)
73
+  // functions for hardware SPI
74
+  //------------------------------------------------------------------------------
75
+  // make sure SPCR rate is in expected bits
76
+  #if (SPR0 != 0 || SPR1 != 1)
77
+    #error "unexpected SPCR bits"
78
+  #endif
79
+
80
+  /**
81
+   * Initialize hardware SPI
82
+   * Set SCK rate to F_CPU/pow(2, 1 + spiRate) for spiRate [0,6]
83
+   */
84
+  void spiInit(uint8_t spiRate) {
85
+    // See avr processor documentation
86
+    CBI(
87
+      #ifdef PRR
88
+        PRR
89
+      #elif defined(PRR0)
90
+        PRR0
91
+      #endif
92
+        , PRSPI);
93
+
94
+    SPCR = _BV(SPE) | _BV(MSTR) | (spiRate >> 1);
95
+    SPSR = spiRate & 1 || spiRate == 6 ? 0 : _BV(SPI2X);
96
+  }
97
+  //------------------------------------------------------------------------------
98
+  /** SPI receive a byte */
99
+  uint8_t spiRec(void) {
100
+    SPDR = 0XFF;
101
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
102
+    return SPDR;
103
+  }
104
+  //------------------------------------------------------------------------------
105
+  /** SPI read data  */
106
+  void spiRead(uint8_t* buf, uint16_t nbyte) {
107
+    if (nbyte-- == 0) return;
108
+    SPDR = 0XFF;
109
+    for (uint16_t i = 0; i < nbyte; i++) {
110
+      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
111
+      buf[i] = SPDR;
112
+      SPDR = 0XFF;
113
+    }
114
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
115
+    buf[nbyte] = SPDR;
116
+  }
117
+  //------------------------------------------------------------------------------
118
+  /** SPI send a byte */
119
+  void spiSend(uint8_t b) {
120
+    SPDR = b;
121
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
122
+  }
123
+  //------------------------------------------------------------------------------
124
+  /** SPI send block  */
125
+  void spiSendBlock(uint8_t token, const uint8_t* buf) {
126
+    SPDR = token;
127
+    for (uint16_t i = 0; i < 512; i += 2) {
128
+      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
129
+      SPDR = buf[i];
130
+      while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
131
+      SPDR = buf[i + 1];
132
+    }
133
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
134
+  }
135
+       //------------------------------------------------------------------------------
136
+#else  // SOFTWARE_SPI
137
+       //------------------------------------------------------------------------------
138
+  /** nop to tune soft SPI timing */
139
+  #define nop asm volatile ("\tnop\n")
140
+
141
+  /** Set SPI rate */
142
+  void spiInit(uint8_t spiRate) {
143
+    // nothing to do
144
+    UNUSED(spiRate);
145
+  }
146
+
147
+  //------------------------------------------------------------------------------
148
+  /** Soft SPI receive byte */
149
+  uint8_t spiRec() {
150
+    uint8_t data = 0;
151
+    // no interrupts during byte receive - about 8 us
152
+    cli();
153
+    // output pin high - like sending 0XFF
154
+    WRITE(MOSI_PIN, HIGH);
155
+
156
+    for (uint8_t i = 0; i < 8; i++) {
157
+      WRITE(SCK_PIN, HIGH);
158
+
159
+      // adjust so SCK is nice
160
+      nop;
161
+      nop;
162
+
163
+      data <<= 1;
164
+
165
+      if (READ(MISO_PIN)) data |= 1;
166
+
167
+      WRITE(SCK_PIN, LOW);
168
+    }
169
+    // enable interrupts
170
+    sei();
171
+    return data;
172
+  }
173
+  //------------------------------------------------------------------------------
174
+  /** Soft SPI read data */
175
+  void spiRead(uint8_t* buf, uint16_t nbyte) {
176
+    for (uint16_t i = 0; i < nbyte; i++)
177
+      buf[i] = spiRec();
178
+  }
179
+  //------------------------------------------------------------------------------
180
+  /** Soft SPI send byte */
181
+  void spiSend(uint8_t data) {
182
+    // no interrupts during byte send - about 8 us
183
+    cli();
184
+    for (uint8_t i = 0; i < 8; i++) {
185
+      WRITE(SCK_PIN, LOW);
186
+
187
+      WRITE(MOSI_PIN, data & 0X80);
188
+
189
+      data <<= 1;
190
+
191
+      WRITE(SCK_PIN, HIGH);
192
+    }
193
+    // hold SCK high for a few ns
194
+    nop;
195
+    nop;
196
+    nop;
197
+    nop;
198
+
199
+    WRITE(SCK_PIN, LOW);
200
+    // enable interrupts
201
+    sei();
202
+  }
203
+  //------------------------------------------------------------------------------
204
+  /** Soft SPI send block */
205
+  void spiSendBlock(uint8_t token, const uint8_t* buf) {
206
+    spiSend(token);
207
+    for (uint16_t i = 0; i < 512; i++)
208
+      spiSend(buf[i]);
209
+  }
210
+#endif  // SOFTWARE_SPI
211
+
212
+
213
+#endif // ARDUINO_ARCH_AVR

Marlin/MarlinSerial.cpp → Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp Переглянути файл

28
  * Modified 28 September 2010 by Mark Sproul
28
  * Modified 28 September 2010 by Mark Sproul
29
  * Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
29
  * Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
30
  */
30
  */
31
+#ifdef ARDUINO_ARCH_AVR
31
 
32
 
32
 #include "MarlinSerial.h"
33
 #include "MarlinSerial.h"
33
-#include "Marlin.h"
34
+#include "../../../Marlin.h"
34
 
35
 
35
 // Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
36
 // Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
36
 
37
 
46
 
47
 
47
   #if ENABLED(EMERGENCY_PARSER)
48
   #if ENABLED(EMERGENCY_PARSER)
48
 
49
 
49
-    #include "stepper.h"
50
-    #include "language.h"
50
+    #include "../../../stepper.h"
51
+    #include "../../../language.h"
51
 
52
 
52
     // Currently looking for: M108, M112, M410
53
     // Currently looking for: M108, M112, M410
53
     // If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
54
     // If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
515
 #if defined(USBCON) && ENABLED(BLUETOOTH)
516
 #if defined(USBCON) && ENABLED(BLUETOOTH)
516
   HardwareSerial bluetoothSerial;
517
   HardwareSerial bluetoothSerial;
517
 #endif
518
 #endif
519
+
520
+#endif

Marlin/MarlinSerial.h → Marlin/src/HAL/HAL_AVR/MarlinSerial.h Переглянути файл

32
 #ifndef MARLINSERIAL_H
32
 #ifndef MARLINSERIAL_H
33
 #define MARLINSERIAL_H
33
 #define MARLINSERIAL_H
34
 
34
 
35
-#include "MarlinConfig.h"
35
+#include "../../../MarlinConfig.h"
36
+
37
+#include <WString.h>
36
 
38
 
37
 #ifndef SERIAL_PORT
39
 #ifndef SERIAL_PORT
38
   #define SERIAL_PORT 0
40
   #define SERIAL_PORT 0
160
       static void println(unsigned long, int = DEC);
162
       static void println(unsigned long, int = DEC);
161
       static void println(double, int = 2);
163
       static void println(double, int = 2);
162
       static void println(void);
164
       static void println(void);
165
+      operator bool() { return true; }
163
   };
166
   };
164
 
167
 
165
   extern MarlinSerial customizedSerial;
168
   extern MarlinSerial customizedSerial;

+ 90
- 0
Marlin/src/HAL/HAL_AVR/ServoTimers.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+  Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
25
+  Copyright (c) 2009 Michael Margolis.  All right reserved.
26
+
27
+  This library is free software; you can redistribute it and/or
28
+  modify it under the terms of the GNU Lesser General Public
29
+  License as published by the Free Software Foundation; either
30
+  version 2.1 of the License, or (at your option) any later version.
31
+
32
+  This library is distributed in the hope that it will be useful,
33
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35
+  Lesser General Public License for more details.
36
+
37
+  You should have received a copy of the GNU Lesser General Public
38
+  License along with this library; if not, write to the Free Software
39
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
40
+*/
41
+
42
+/*
43
+ * Defines for 16 bit timers used with  Servo library
44
+ *
45
+ * If _useTimerX is defined then TimerX is a 16 bit timer on the current board
46
+ * timer16_Sequence_t enumerates the sequence that the timers should be allocated
47
+ * _Nbr_16timers indicates how many 16 bit timers are available.
48
+ */
49
+
50
+/**
51
+ * AVR Only definitions
52
+ * --------------------
53
+ */
54
+
55
+#define TRIM_DURATION       2    // compensation ticks to trim adjust for digitalWrite delays
56
+#define PRESCALER           8   // timer prescaler
57
+
58
+// Say which 16 bit timers can be used and in what order
59
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
60
+  //#define _useTimer1
61
+  #define _useTimer3
62
+  #define _useTimer4
63
+  #if !HAS_MOTOR_CURRENT_PWM
64
+    #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
65
+  #endif
66
+#elif defined(__AVR_ATmega32U4__)
67
+  #define _useTimer3
68
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
69
+  #define _useTimer3
70
+#elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2561__)
71
+  #define _useTimer3
72
+#else
73
+  // everything else
74
+#endif
75
+
76
+typedef enum {
77
+  #if ENABLED(_useTimer1)
78
+    _timer1,
79
+  #endif
80
+  #if ENABLED(_useTimer3)
81
+    _timer3,
82
+  #endif
83
+  #if ENABLED(_useTimer4)
84
+    _timer4,
85
+  #endif
86
+  #if ENABLED(_useTimer5)
87
+    _timer5,
88
+  #endif
89
+  _Nbr_16timers
90
+} timer16_Sequence_t;

Marlin/endstop_interrupts.h → Marlin/src/HAL/HAL_AVR/endstop_interrupts.h Переглянути файл

38
 #ifndef _ENDSTOP_INTERRUPTS_H_
38
 #ifndef _ENDSTOP_INTERRUPTS_H_
39
 #define _ENDSTOP_INTERRUPTS_H_
39
 #define _ENDSTOP_INTERRUPTS_H_
40
 
40
 
41
-#include "macros.h"
41
+#include "../../../macros.h"
42
 
42
 
43
 /**
43
 /**
44
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
44
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
72
                                     0 )
72
                                     0 )
73
 #endif
73
 #endif
74
 
74
 
75
-volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
76
-                            // Must be reset to 0 by the test function when finished.
77
 
75
 
78
 // Install Pin change interrupt for a pin. Can be called multiple times.
76
 // Install Pin change interrupt for a pin. Can be called multiple times.
79
 void pciSetup(byte pin) {
77
 void pciSetup(byte pin) {
82
   SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
80
   SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
83
 }
81
 }
84
 
82
 
85
-// This is what is really done inside the interrupts.
86
-FORCE_INLINE void endstop_ISR_worker( void ) {
87
-  e_hit = 2; // Because the detection of a e-stop hit has a 1 step debouncer it has to be called at least twice.
88
-}
89
-
90
-// Use one Routine to handle each group
91
-// One ISR for all EXT-Interrupts
92
-void endstop_ISR(void) { endstop_ISR_worker(); }
93
 
83
 
94
 // Handlers for pin change interrupts
84
 // Handlers for pin change interrupts
95
 #ifdef PCINT0_vect
85
 #ifdef PCINT0_vect

Marlin/fastio_1280.h → Marlin/src/HAL/HAL_AVR/fastio_1280.h Переглянути файл

31
 #ifndef _FASTIO_1280
31
 #ifndef _FASTIO_1280
32
 #define _FASTIO_1280
32
 #define _FASTIO_1280
33
 
33
 
34
-#include "fastio.h"
34
+#include "fastio_AVR.h"
35
 
35
 
36
 // change for your board
36
 // change for your board
37
 #define DEBUG_LED   DIO21
37
 #define DEBUG_LED   DIO21

Marlin/fastio_1281.h → Marlin/src/HAL/HAL_AVR/fastio_1281.h Переглянути файл

31
 #ifndef _FASTIO_1281
31
 #ifndef _FASTIO_1281
32
 #define _FASTIO_1281
32
 #define _FASTIO_1281
33
 
33
 
34
-#include "fastio.h"
34
+#include "fastio_AVR.h"
35
 
35
 
36
 // change for your board
36
 // change for your board
37
 #define DEBUG_LED   DIO46
37
 #define DEBUG_LED   DIO46

Marlin/fastio_168.h → Marlin/src/HAL/HAL_AVR/fastio_168.h Переглянути файл

31
 #ifndef _FASTIO_168
31
 #ifndef _FASTIO_168
32
 #define _FASTIO_168
32
 #define _FASTIO_168
33
 
33
 
34
-#include "fastio.h"
34
+#include "fastio_AVR.h"
35
 
35
 
36
 #define DEBUG_LED   AIO5
36
 #define DEBUG_LED   AIO5
37
 
37
 

Marlin/fastio_644.h → Marlin/src/HAL/HAL_AVR/fastio_644.h Переглянути файл

31
 #ifndef _FASTIO_644
31
 #ifndef _FASTIO_644
32
 #define _FASTIO_644
32
 #define _FASTIO_644
33
 
33
 
34
-#include "fastio.h"
34
+#include "fastio_AVR.h"
35
 
35
 
36
 #define DEBUG_LED   DIO0
36
 #define DEBUG_LED   DIO0
37
 
37
 

Marlin/fastio_AT90USB.h → Marlin/src/HAL/HAL_AVR/fastio_AT90USB.h Переглянути файл

32
 #ifndef _FASTIO_AT90USB
32
 #ifndef _FASTIO_AT90USB
33
 #define _FASTIO_AT90USB
33
 #define _FASTIO_AT90USB
34
 
34
 
35
-#include "fastio.h"
35
+#include "fastio_AVR.h"
36
 
36
 
37
 // change for your board
37
 // change for your board
38
 #define DEBUG_LED   DIO31 /* led D5 red */
38
 #define DEBUG_LED   DIO31 /* led D5 red */

Marlin/fastio.h → Marlin/src/HAL/HAL_AVR/fastio_AVR.h Переглянути файл

30
 #define _FASTIO_ARDUINO_H
30
 #define _FASTIO_ARDUINO_H
31
 
31
 
32
 #include <avr/io.h>
32
 #include <avr/io.h>
33
-#include "macros.h"
33
+#include "../../../macros.h"
34
 
34
 
35
 #define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__)  || defined(__AVR_AT90USB647__))
35
 #define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__)  || defined(__AVR_AT90USB647__))
36
 #define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
36
 #define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
38
 #define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
38
 #define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
39
 #define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328p__))
39
 #define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328p__))
40
 
40
 
41
-
42
 /**
41
 /**
43
  * Include Ports and Functions
42
  * Include Ports and Functions
44
  */
43
  */
57
 #endif
56
 #endif
58
 
57
 
59
 #ifndef _BV
58
 #ifndef _BV
60
-  #define _BV(PIN) (1UL << PIN)
59
+  #define _BV(bit) (1UL << (bit))
61
 #endif
60
 #endif
62
 
61
 
63
 /**
62
 /**
269
   #define PWM_CHK_MOTOR_CURRENT(p) false
268
   #define PWM_CHK_MOTOR_CURRENT(p) false
270
 #endif
269
 #endif
271
 
270
 
272
-#if defined(NUM_SERVOS)
271
+#ifdef NUM_SERVOS
273
   #if AVR_ATmega2560_FAMILY
272
   #if AVR_ATmega2560_FAMILY
274
     #define PWM_CHK_SERVO(p) ( p == 5 || NUM_SERVOS > 12 && p == 6 || NUM_SERVOS > 24 && p == 46)  //PWMS 3A, 4A & 5A
273
     #define PWM_CHK_SERVO(p) ( p == 5 || NUM_SERVOS > 12 && p == 6 || NUM_SERVOS > 24 && p == 46)  //PWMS 3A, 4A & 5A
275
   #elif AVR_ATmega2561_FAMILY
274
   #elif AVR_ATmega2561_FAMILY

+ 112
- 0
Marlin/src/HAL/HAL_AVR/math_AVR.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef MATH_AVR_H
24
+#define MATH_AVR_H
25
+
26
+/**
27
+ * Optimized math functions for AVR
28
+ */
29
+
30
+// intRes = longIn1 * longIn2 >> 24
31
+// uses:
32
+// r26 to store 0
33
+// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
34
+// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
35
+// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
36
+// B0 A0 are bits 24-39 and are the returned value
37
+// C1 B1 A1 is longIn1
38
+// D2 C2 B2 A2 is longIn2
39
+//
40
+#define MultiU24X32toH16(intRes, longIn1, longIn2) \
41
+  asm volatile ( \
42
+                 "clr r26 \n\t" \
43
+                 "mul %A1, %B2 \n\t" \
44
+                 "mov r27, r1 \n\t" \
45
+                 "mul %B1, %C2 \n\t" \
46
+                 "movw %A0, r0 \n\t" \
47
+                 "mul %C1, %C2 \n\t" \
48
+                 "add %B0, r0 \n\t" \
49
+                 "mul %C1, %B2 \n\t" \
50
+                 "add %A0, r0 \n\t" \
51
+                 "adc %B0, r1 \n\t" \
52
+                 "mul %A1, %C2 \n\t" \
53
+                 "add r27, r0 \n\t" \
54
+                 "adc %A0, r1 \n\t" \
55
+                 "adc %B0, r26 \n\t" \
56
+                 "mul %B1, %B2 \n\t" \
57
+                 "add r27, r0 \n\t" \
58
+                 "adc %A0, r1 \n\t" \
59
+                 "adc %B0, r26 \n\t" \
60
+                 "mul %C1, %A2 \n\t" \
61
+                 "add r27, r0 \n\t" \
62
+                 "adc %A0, r1 \n\t" \
63
+                 "adc %B0, r26 \n\t" \
64
+                 "mul %B1, %A2 \n\t" \
65
+                 "add r27, r1 \n\t" \
66
+                 "adc %A0, r26 \n\t" \
67
+                 "adc %B0, r26 \n\t" \
68
+                 "lsr r27 \n\t" \
69
+                 "adc %A0, r26 \n\t" \
70
+                 "adc %B0, r26 \n\t" \
71
+                 "mul %D2, %A1 \n\t" \
72
+                 "add %A0, r0 \n\t" \
73
+                 "adc %B0, r1 \n\t" \
74
+                 "mul %D2, %B1 \n\t" \
75
+                 "add %B0, r0 \n\t" \
76
+                 "clr r1 \n\t" \
77
+                 : \
78
+                 "=&r" (intRes) \
79
+                 : \
80
+                 "d" (longIn1), \
81
+                 "d" (longIn2) \
82
+                 : \
83
+                 "r26" , "r27" \
84
+               )
85
+
86
+// intRes = intIn1 * intIn2 >> 16
87
+// uses:
88
+// r26 to store 0
89
+// r27 to store the byte 1 of the 24 bit result
90
+#define MultiU16X8toH16(intRes, charIn1, intIn2) \
91
+  asm volatile ( \
92
+                 "clr r26 \n\t" \
93
+                 "mul %A1, %B2 \n\t" \
94
+                 "movw %A0, r0 \n\t" \
95
+                 "mul %A1, %A2 \n\t" \
96
+                 "add %A0, r1 \n\t" \
97
+                 "adc %B0, r26 \n\t" \
98
+                 "lsr r0 \n\t" \
99
+                 "adc %A0, r26 \n\t" \
100
+                 "adc %B0, r26 \n\t" \
101
+                 "clr r1 \n\t" \
102
+                 : \
103
+                 "=&r" (intRes) \
104
+                 : \
105
+                 "d" (charIn1), \
106
+                 "d" (intIn2) \
107
+                 : \
108
+                 "r26" \
109
+               )
110
+
111
+
112
+#endif

+ 57
- 0
Marlin/src/HAL/HAL_AVR/persistent_store.cpp Переглянути файл

1
+#include "../persistent_store_api.h"
2
+
3
+#include "../../../types.h"
4
+#include "../../../language.h"
5
+#include "../../../serial.h"
6
+#include "../../../utility.h"
7
+
8
+#ifdef ARDUINO_ARCH_AVR
9
+#if ENABLED(EEPROM_SETTINGS)
10
+
11
+namespace HAL {
12
+namespace PersistentStore {
13
+
14
+bool access_start() {
15
+  return true;
16
+}
17
+
18
+bool access_finish(){
19
+  return true;
20
+}
21
+
22
+bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
23
+  while (size--) {
24
+    uint8_t * const p = (uint8_t * const)pos;
25
+    uint8_t v = *value;
26
+    // EEPROM has only ~100,000 write cycles,
27
+    // so only write bytes that have changed!
28
+    if (v != eeprom_read_byte(p)) {
29
+      eeprom_write_byte(p, v);
30
+      if (eeprom_read_byte(p) != v) {
31
+        SERIAL_ECHO_START();
32
+        SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
33
+        return false;
34
+      }
35
+    }
36
+    crc16(crc, &v, 1);
37
+    pos++;
38
+    value++;
39
+  };
40
+  return true;
41
+}
42
+
43
+void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
44
+  do {
45
+    uint8_t c = eeprom_read_byte((unsigned char*)pos);
46
+    *value = c;
47
+    crc16(crc, &c, 1);
48
+    pos++;
49
+    value++;
50
+  } while (--size);
51
+}
52
+
53
+}
54
+}
55
+
56
+#endif // EEPROM_SETTINGS
57
+#endif // ARDUINO_ARCH_AVR

Marlin/pinsDebug_Teensyduino.h → Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h Переглянути файл


Marlin/pinsDebug_plus_70.h → Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h Переглянути файл


Marlin/servo.cpp → Marlin/src/HAL/HAL_AVR/servo_AVR.cpp Переглянути файл

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+
23
 /**
24
 /**
24
  * servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
25
  * servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
25
  * Copyright (c) 2009 Michael Margolis.  All right reserved.
26
  * Copyright (c) 2009 Michael Margolis.  All right reserved.
50
  * detach()              - Stop an attached servo from pulsing its i/o pin.
51
  * detach()              - Stop an attached servo from pulsing its i/o pin.
51
  *
52
  *
52
  */
53
  */
53
-#include "MarlinConfig.h"
54
+
55
+#ifdef ARDUINO_ARCH_AVR
56
+
57
+#include "../../../MarlinConfig.h"
54
 
58
 
55
 #if HAS_SERVOS
59
 #if HAS_SERVOS
56
 
60
 
57
 #include <avr/interrupt.h>
61
 #include <avr/interrupt.h>
58
 #include <Arduino.h>
62
 #include <Arduino.h>
59
 
63
 
60
-#include "servo.h"
61
-
62
-#define usToTicks(_us)    (( clockCyclesPerMicrosecond()* _us) / 8)     // converts microseconds to tick (assumes prescale of 8)  // 12 Aug 2009
63
-#define ticksToUs(_ticks) (( (unsigned)_ticks * 8)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds
64
-
65
-#define TRIM_DURATION       2                               // compensation ticks to trim adjust for digitalWrite delays // 12 August 2009
66
-
67
-//#define NBR_TIMERS        ((MAX_SERVOS) / (SERVOS_PER_TIMER))
64
+#include "../servo.h"
65
+#include "../servo_private.h"
68
 
66
 
69
-static ServoInfo_t servo_info[MAX_SERVOS];                  // static array of servo info structures
70
 static volatile int8_t Channel[_Nbr_16timers ];             // counter for the servo being pulsed for each timer (or -1 if refresh interval)
67
 static volatile int8_t Channel[_Nbr_16timers ];             // counter for the servo being pulsed for each timer (or -1 if refresh interval)
71
 
68
 
72
-uint8_t ServoCount = 0;                                     // the total number of attached servos
73
-
74
-
75
-// convenience macros
76
-#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
77
-#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % (SERVOS_PER_TIMER))       // returns the index of the servo on this timer
78
-#define SERVO_INDEX(_timer,_channel)  ((_timer*(SERVOS_PER_TIMER)) + _channel)     // macro to access servo index by timer and channel
79
-#define SERVO(_timer,_channel)  (servo_info[SERVO_INDEX(_timer,_channel)])       // macro to access servo class by timer and channel
80
-
81
-#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4)  // minimum value in uS for this servo
82
-#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4)  // maximum value in uS for this servo
83
 
69
 
84
 /************ static functions common to all instances ***********************/
70
 /************ static functions common to all instances ***********************/
85
 
71
 
138
 
124
 
139
 #endif // WIRING
125
 #endif // WIRING
140
 
126
 
127
+/****************** end of static functions ******************************/
141
 
128
 
142
-static void initISR(timer16_Sequence_t timer) {
129
+void initISR(timer16_Sequence_t timer) {
143
   #if ENABLED(_useTimer1)
130
   #if ENABLED(_useTimer1)
144
     if (timer == _timer1) {
131
     if (timer == _timer1) {
145
       TCCR1A = 0;             // normal counting mode
132
       TCCR1A = 0;             // normal counting mode
198
   #endif
185
   #endif
199
 }
186
 }
200
 
187
 
201
-static void finISR(timer16_Sequence_t timer) {
188
+void finISR(timer16_Sequence_t timer) {
202
   // Disable use of the given timer
189
   // Disable use of the given timer
203
   #ifdef WIRING
190
   #ifdef WIRING
204
     if (timer == _timer1) {
191
     if (timer == _timer1) {
227
   #endif
214
   #endif
228
 }
215
 }
229
 
216
 
230
-static bool isTimerActive(timer16_Sequence_t timer) {
231
-  // returns true if any servo is active on this timer
232
-  for (uint8_t channel = 0; channel < SERVOS_PER_TIMER; channel++) {
233
-    if (SERVO(timer, channel).Pin.isActive)
234
-      return true;
235
-  }
236
-  return false;
237
-}
238
-
239
-
240
-/****************** end of static functions ******************************/
241
-
242
-Servo::Servo() {
243
-  if (ServoCount < MAX_SERVOS) {
244
-    this->servoIndex = ServoCount++;                    // assign a servo index to this instance
245
-    servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH);   // store default values  - 12 Aug 2009
246
-  }
247
-  else
248
-    this->servoIndex = INVALID_SERVO;  // too many servos
249
-}
250
-
251
-int8_t Servo::attach(int pin) {
252
-  return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
253
-}
254
-
255
-int8_t Servo::attach(int pin, int min, int max) {
256
-
257
-  if (this->servoIndex >= MAX_SERVOS) return -1;
258
-
259
-  if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
260
-  pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
261
-
262
-  // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
263
-  this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
264
-  this->max = (MAX_PULSE_WIDTH - max) / 4;
265
-
266
-  // initialize the timer if it has not already been initialized
267
-  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
268
-  if (!isTimerActive(timer)) initISR(timer);
269
-  servo_info[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
270
-
271
-  return this->servoIndex;
272
-}
273
-
274
-void Servo::detach() {
275
-  servo_info[this->servoIndex].Pin.isActive = false;
276
-  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
277
-  if (!isTimerActive(timer)) finISR(timer);
278
-}
279
-
280
-void Servo::write(int value) {
281
-  if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
282
-    value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
283
-  }
284
-  this->writeMicroseconds(value);
285
-}
286
-
287
-void Servo::writeMicroseconds(int value) {
288
-  // calculate and store the values for the given channel
289
-  byte channel = this->servoIndex;
290
-  if (channel < MAX_SERVOS) {  // ensure channel is valid
291
-    // ensure pulse width is valid
292
-    value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
293
-    value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
294
-
295
-    CRITICAL_SECTION_START;
296
-    servo_info[channel].ticks = value;
297
-    CRITICAL_SECTION_END;
298
-  }
299
-}
300
-
301
-// return the value as degrees
302
-int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); }
303
-
304
-int Servo::readMicroseconds() {
305
-  return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + TRIM_DURATION;
306
-}
307
-
308
-bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
309
-
310
-void Servo::move(int value) {
311
-  constexpr uint16_t servo_delay[] = SERVO_DELAY;
312
-  static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
313
-  if (this->attach(0) >= 0) {
314
-    this->write(value);
315
-    delay(servo_delay[this->servoIndex]);
316
-    #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
317
-      this->detach();
318
-    #endif
319
-  }
320
-}
217
+#endif // HAS_SERVOS
321
 
218
 
322
-#endif
219
+#endif // ARDUINO_ARCH_AVR

+ 67
- 0
Marlin/src/HAL/HAL_AVR/spi_pins.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
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
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+#ifndef SPI_PINS_H_
21
+#define SPI_PINS_H_
22
+
23
+/**
24
+ * Define SPI Pins: SCK, MISO, MOSI, SS
25
+ */
26
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
27
+  #define AVR_SCK_PIN  13
28
+  #define AVR_MISO_PIN 12
29
+  #define AVR_MOSI_PIN 11
30
+  #define AVR_SS_PIN   10
31
+#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)
32
+  #define AVR_SCK_PIN  7
33
+  #define AVR_MISO_PIN 6
34
+  #define AVR_MOSI_PIN 5
35
+  #define AVR_SS_PIN   4
36
+#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
37
+  #define AVR_SCK_PIN  52
38
+  #define AVR_MISO_PIN 50
39
+  #define AVR_MOSI_PIN 51
40
+  #define AVR_SS_PIN   53
41
+#elif defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__)
42
+  #define AVR_SCK_PIN  21
43
+  #define AVR_MISO_PIN 23
44
+  #define AVR_MOSI_PIN 22
45
+  #define AVR_SS_PIN   20
46
+#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
47
+  #define AVR_SCK_PIN  10
48
+  #define AVR_MISO_PIN 12
49
+  #define AVR_MOSI_PIN 11
50
+  #define AVR_SS_PIN   16
51
+#endif
52
+
53
+#ifndef SCK_PIN
54
+  #define SCK_PIN  AVR_SCK_PIN
55
+#endif
56
+#ifndef MISO_PIN
57
+  #define MISO_PIN AVR_MISO_PIN
58
+#endif
59
+#ifndef MOSI_PIN
60
+  #define MOSI_PIN AVR_MOSI_PIN
61
+#endif
62
+#ifndef SS_PIN
63
+  #define SS_PIN   AVR_SS_PIN
64
+#endif
65
+
66
+
67
+#endif /* SPI_PINS_H_ */

Marlin/watchdog.cpp → Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp Переглянути файл

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#include "Marlin.h"
23
+#ifdef ARDUINO_ARCH_AVR
24
+
25
+#include "../../../Marlin.h"
24
 
26
 
25
 #if ENABLED(USE_WATCHDOG)
27
 #if ENABLED(USE_WATCHDOG)
26
 
28
 
27
-#include "watchdog.h"
29
+#include "watchdog_AVR.h"
28
 
30
 
29
 // Initialize watchdog with a 4 sec interrupt time
31
 // Initialize watchdog with a 4 sec interrupt time
30
 void watchdog_init() {
32
 void watchdog_init() {
54
 #endif // WATCHDOG_RESET_MANUAL
56
 #endif // WATCHDOG_RESET_MANUAL
55
 
57
 
56
 #endif // USE_WATCHDOG
58
 #endif // USE_WATCHDOG
59
+#endif // ARDUINO_ARCH_AVR

Marlin/watchdog.h → Marlin/src/HAL/HAL_AVR/watchdog_AVR.h Переглянути файл

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#ifndef WATCHDOG_H
24
-#define WATCHDOG_H
23
+#ifndef WATCHDOG_AVR_H
24
+#define WATCHDOG_AVR_H
25
+
26
+//#include "../../../Marlin.h"
25
 
27
 
26
-#include "Marlin.h"
27
 #include <avr/wdt.h>
28
 #include <avr/wdt.h>
28
 
29
 
29
 // Initialize watchdog with a 4 second interrupt time
30
 // Initialize watchdog with a 4 second interrupt time

+ 53
- 0
Marlin/src/HAL/HAL_endstop_interrupts.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
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
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+
21
+#ifndef HAL_ENDSTOP_INTERRUPTS_H_
22
+#define HAL_ENDSTOP_INTERRUPTS_H_
23
+
24
+volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
25
+                            // Must be reset to 0 by the test function when finished.
26
+
27
+// This is what is really done inside the interrupts.
28
+FORCE_INLINE void endstop_ISR_worker( void ) {
29
+  e_hit = 2; // Because the detection of a e-stop hit has a 1 step debouncer it has to be called at least twice.
30
+}
31
+
32
+// One ISR for all EXT-Interrupts
33
+void endstop_ISR(void) { endstop_ISR_worker(); }
34
+
35
+#ifdef ARDUINO_ARCH_AVR
36
+
37
+  #include "HAL_AVR/endstop_interrupts.h"
38
+
39
+#elif defined(ARDUINO_ARCH_SAM)
40
+
41
+  #include "HAL_DUE/endstop_interrupts.h"
42
+
43
+#elif IS_32BIT_TEENSY
44
+
45
+  #include "HAL_TEENSY35_36/endstop_interrupts.h"
46
+
47
+#else
48
+
49
+  #error Unsupported Platform!
50
+
51
+#endif
52
+
53
+#endif /* HAL_ENDSTOP_INTERRUPTS_H_ */

+ 35
- 0
Marlin/src/HAL/HAL_pinsDebug.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef HAL_PINSDEBUG_H
24
+
25
+#ifdef ARDUINO_ARCH_AVR
26
+  #include "HAL_AVR/HAL_pinsDebug_AVR.h"
27
+#elif defined(ARDUINO_ARCH_SAM)
28
+  #include "HAL_DUE/HAL_pinsDebug_Due.h"
29
+#elif IS_32BIT_TEENSY
30
+  #include "HAL_TEENSY35_36/HAL_pinsDebug_Teensy.h"
31
+#else
32
+  #error Unsupported Platform!
33
+#endif
34
+
35
+#endif

+ 39
- 0
Marlin/src/HAL/HAL_spi_pins.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
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
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+
21
+#ifndef HAL_SPI_PINS_H_
22
+#define HAL_SPI_PINS_H_
23
+
24
+#include "MarlinConfig.h"
25
+
26
+#ifdef ARDUINO_ARCH_SAM
27
+  #include "HAL_DUE/spi_pins.h"
28
+
29
+#elif defined(IS_32BIT_TEENSY)
30
+  #include "HAL_TEENSY35_36/spi_pins.h"
31
+
32
+#elif defined(ARDUINO_ARCH_AVR)
33
+  #include "HAL_AVR/spi_pins.h"
34
+
35
+#else
36
+  #error "Unsupported Platform!"
37
+#endif
38
+
39
+#endif /* HAL_SPI_PINS_H_ */

+ 162
- 0
Marlin/src/HAL/I2cEeprom.cpp Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
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
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+
21
+/**
22
+ * Description: functions for I2C connected external EEPROM.
23
+ * Not platform dependent.
24
+ */
25
+
26
+#include "../../MarlinConfig.h"
27
+
28
+#if ENABLED(I2C_EEPROM)
29
+
30
+// --------------------------------------------------------------------------
31
+// Includes
32
+// --------------------------------------------------------------------------
33
+
34
+#include "HAL.h"
35
+#include <Wire.h>
36
+
37
+// --------------------------------------------------------------------------
38
+// Externals
39
+// --------------------------------------------------------------------------
40
+
41
+// --------------------------------------------------------------------------
42
+// Local defines
43
+// --------------------------------------------------------------------------
44
+
45
+// --------------------------------------------------------------------------
46
+// Types
47
+// --------------------------------------------------------------------------
48
+
49
+// --------------------------------------------------------------------------
50
+// Variables
51
+// --------------------------------------------------------------------------
52
+
53
+// --------------------------------------------------------------------------
54
+// Public Variables
55
+// --------------------------------------------------------------------------
56
+
57
+// --------------------------------------------------------------------------
58
+// Private Variables
59
+// --------------------------------------------------------------------------
60
+
61
+// --------------------------------------------------------------------------
62
+// Function prototypes
63
+// --------------------------------------------------------------------------
64
+
65
+// --------------------------------------------------------------------------
66
+// Private functions
67
+// --------------------------------------------------------------------------
68
+
69
+// --------------------------------------------------------------------------
70
+// Public functions
71
+// --------------------------------------------------------------------------
72
+
73
+static bool eeprom_initialised = false;
74
+static uint8_t eeprom_device_address = 0x50;
75
+
76
+static void eeprom_init(void) {
77
+  if (!eeprom_initialised) {
78
+    Wire.begin();
79
+    eeprom_initialised = true;
80
+  }
81
+}
82
+
83
+void eeprom_write_byte(unsigned char *pos, unsigned char value) {
84
+  unsigned eeprom_address = (unsigned) pos;
85
+
86
+  eeprom_init();
87
+
88
+  Wire.beginTransmission(eeprom_device_address);
89
+  Wire.write((int)(eeprom_address >> 8));   // MSB
90
+  Wire.write((int)(eeprom_address & 0xFF)); // LSB
91
+  Wire.write(value);
92
+  Wire.endTransmission();
93
+
94
+  // wait for write cycle to complete
95
+  // this could be done more efficiently with "acknowledge polling"
96
+  delay(5);
97
+}
98
+
99
+// WARNING: address is a page address, 6-bit end will wrap around
100
+// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
101
+void eeprom_update_block(const void* pos, void* eeprom_address, size_t n) {
102
+  uint8_t eeprom_temp[32] = {0};
103
+  uint8_t flag = 0;
104
+
105
+  eeprom_init();
106
+
107
+  Wire.beginTransmission(eeprom_device_address);
108
+  Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
109
+  Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
110
+  Wire.endTransmission();
111
+  Wire.requestFrom(eeprom_device_address, (byte)n);
112
+  for (byte c = 0; c < n; c++) {
113
+    if (Wire.available()) eeprom_temp[c] = Wire.read();
114
+    flag |= (eeprom_temp[c] ^ *((uint8_t*)pos + c));
115
+  }
116
+
117
+  if (flag) {
118
+    Wire.beginTransmission(eeprom_device_address);
119
+    Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
120
+    Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
121
+    Wire.write((uint8_t*)(pos), n);
122
+    Wire.endTransmission();
123
+
124
+    // wait for write cycle to complete
125
+    // this could be done more efficiently with "acknowledge polling"
126
+    delay(5);
127
+  }
128
+}
129
+
130
+
131
+unsigned char eeprom_read_byte(unsigned char *pos) {
132
+  byte data = 0xFF;
133
+  unsigned eeprom_address = (unsigned) pos;
134
+
135
+  eeprom_init ();
136
+
137
+  Wire.beginTransmission(eeprom_device_address);
138
+  Wire.write((int)(eeprom_address >> 8));   // MSB
139
+  Wire.write((int)(eeprom_address & 0xFF)); // LSB
140
+  Wire.endTransmission();
141
+  Wire.requestFrom(eeprom_device_address, (byte)1);
142
+  if (Wire.available())
143
+    data = Wire.read();
144
+  return data;
145
+}
146
+
147
+// maybe let's not read more than 30 or 32 bytes at a time!
148
+void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
149
+  eeprom_init();
150
+
151
+  Wire.beginTransmission(eeprom_device_address);
152
+  Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
153
+  Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
154
+  Wire.endTransmission();
155
+  Wire.requestFrom(eeprom_device_address, (byte)n);
156
+  for (byte c = 0; c < n; c++ )
157
+    if (Wire.available()) *((uint8_t*)pos + c) = Wire.read();
158
+}
159
+
160
+
161
+#endif // ENABLED(I2C_EEPROM)
162
+

+ 117
- 0
Marlin/src/HAL/SpiEeprom.cpp Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
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
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+/**
21
+ * Description: functions for SPI connected external EEPROM.
22
+ * Not platform dependent.
23
+ */
24
+
25
+#include "../../MarlinConfig.h"
26
+
27
+#if ENABLED(SPI_EEPROM)
28
+
29
+#include "HAL.h"
30
+
31
+#define CMD_WREN  6   // WREN
32
+#define CMD_READ  2   // WRITE
33
+#define CMD_WRITE 2   // WRITE
34
+
35
+uint8_t eeprom_read_byte(uint8_t* pos) {
36
+  uint8_t v;
37
+  uint8_t eeprom_temp[3];
38
+
39
+  // set read location
40
+  // begin transmission from device
41
+  eeprom_temp[0] = CMD_READ;
42
+  eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF; // addr High
43
+  eeprom_temp[2] = (unsigned)pos& 0xFF;       // addr Low
44
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
45
+  digitalWrite(SPI_EEPROM1_CS, LOW);
46
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
47
+
48
+  v = spiRec(SPI_CHAN_EEPROM1);
49
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
50
+  return v;
51
+}
52
+
53
+
54
+void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) {
55
+  uint8_t eeprom_temp[3];
56
+
57
+  // set read location
58
+  // begin transmission from device
59
+  eeprom_temp[0] = CMD_READ;
60
+  eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; // addr High
61
+  eeprom_temp[2] = (unsigned)eeprom_address& 0xFF;       // addr Low
62
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
63
+  digitalWrite(SPI_EEPROM1_CS, LOW);
64
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
65
+
66
+  uint8_t *p_dest = (uint8_t *)dest;
67
+  while (n--)
68
+    *p_dest++ = spiRec(SPI_CHAN_EEPROM1);
69
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
70
+}
71
+
72
+void eeprom_write_byte(uint8_t* pos, uint8_t value) {
73
+  uint8_t eeprom_temp[3];
74
+
75
+  /*write enable*/
76
+  eeprom_temp[0] = CMD_WREN;
77
+  digitalWrite(SPI_EEPROM1_CS, LOW);
78
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
79
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
80
+  delay(1);
81
+
82
+  /*write addr*/
83
+  eeprom_temp[0] = CMD_WRITE;
84
+  eeprom_temp[1] = ((unsigned)pos>>8) & 0xFF;  //addr High
85
+  eeprom_temp[2] = (unsigned)pos & 0xFF;       //addr Low
86
+  digitalWrite(SPI_EEPROM1_CS, LOW);
87
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
88
+
89
+  spiSend(SPI_CHAN_EEPROM1, value);
90
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
91
+  delay(7);   // wait for page write to complete
92
+}
93
+
94
+void eeprom_update_block(const void* src, void* eeprom_address, size_t n) {
95
+  uint8_t eeprom_temp[3];
96
+
97
+  /*write enable*/
98
+  eeprom_temp[0] = CMD_WREN;
99
+  digitalWrite(SPI_EEPROM1_CS, LOW);
100
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
101
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
102
+  delay(1);
103
+
104
+  /*write addr*/
105
+  eeprom_temp[0] = CMD_WRITE;
106
+  eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF;  //addr High
107
+  eeprom_temp[2] = (unsigned)eeprom_address & 0xFF;       //addr Low
108
+  digitalWrite(SPI_EEPROM1_CS, LOW);
109
+  spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
110
+
111
+  spiSend(SPI_CHAN_EEPROM1, (const uint8_t*)src, n);
112
+  digitalWrite(SPI_EEPROM1_CS, HIGH);
113
+  delay(7);   // wait for page write to complete
114
+}
115
+
116
+
117
+#endif // ENABLED(SPI_EEPROM)

+ 33
- 0
Marlin/src/HAL/math_32bit.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef MATH_32BIT_H
24
+#define MATH_32BIT_H
25
+
26
+/**
27
+ * Math helper functions for 32 bit CPUs
28
+ */
29
+
30
+#define MultiU32X32toH32(intRes, longIn1, longIn2) intRes = ((uint64_t)longIn1 * longIn2 + 0x80000000) >> 32
31
+#define MultiU32X24toH32(intRes, longIn1, longIn2) intRes = ((uint64_t)longIn1 * longIn2 + 0x00800000) >> 24
32
+
33
+#endif

+ 19
- 0
Marlin/src/HAL/persistent_store_api.h Переглянути файл

1
+#ifndef _PERSISTENT_STORE_H_
2
+#define _PERSISTENT_STORE_H_
3
+
4
+#include <stddef.h>
5
+#include <stdint.h>
6
+
7
+namespace HAL {
8
+namespace PersistentStore {
9
+
10
+bool access_start();
11
+bool access_finish();
12
+bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
13
+void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) ;
14
+
15
+}
16
+}
17
+
18
+
19
+#endif /* _PERSISTANT_STORE_H_ */

+ 168
- 0
Marlin/src/HAL/servo.cpp Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+/**
25
+ * servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
26
+ * Copyright (c) 2009 Michael Margolis.  All right reserved.
27
+ */
28
+
29
+/**
30
+ * A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
31
+ * The servos are pulsed in the background using the value most recently written using the write() method
32
+ *
33
+ * Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.
34
+ * Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four.
35
+ *
36
+ * The methods are:
37
+ *
38
+ * Servo - Class for manipulating servo motors connected to Arduino pins.
39
+ *
40
+ * attach(pin)           - Attach a servo motor to an i/o pin.
41
+ * attach(pin, min, max) - Attach to a pin, setting min and max values in microseconds
42
+ *                         Default min is 544, max is 2400
43
+ *
44
+ * write()               - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.)
45
+ * writeMicroseconds()   - Set the servo pulse width in microseconds.
46
+ * move(pin, angle)      - Sequence of attach(pin), write(angle), delay(SERVO_DELAY).
47
+ *                         With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after SERVO_DELAY.
48
+ * read()                - Get the last-written servo pulse width as an angle between 0 and 180.
49
+ * readMicroseconds()    - Get the last-written servo pulse width in microseconds.
50
+ * attached()            - Return true if a servo is attached.
51
+ * detach()              - Stop an attached servo from pulsing its i/o pin.
52
+ *
53
+ */
54
+
55
+
56
+#include "../../MarlinConfig.h"
57
+
58
+#include "HAL.h"
59
+
60
+#if HAS_SERVOS && !IS_32BIT_TEENSY
61
+
62
+//#include <Arduino.h>
63
+
64
+#include "servo.h"
65
+#include "servo_private.h"
66
+
67
+ServoInfo_t servo_info[MAX_SERVOS];                  // static array of servo info structures
68
+uint8_t ServoCount = 0;                              // the total number of attached servos
69
+
70
+
71
+#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4)  // minimum value in uS for this servo
72
+#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4)  // maximum value in uS for this servo
73
+
74
+/************ static functions common to all instances ***********************/
75
+
76
+static boolean isTimerActive(timer16_Sequence_t timer) {
77
+  // returns true if any servo is active on this timer
78
+  for (uint8_t channel = 0; channel < SERVOS_PER_TIMER; channel++) {
79
+    if (SERVO(timer, channel).Pin.isActive)
80
+      return true;
81
+  }
82
+  return false;
83
+}
84
+
85
+/****************** end of static functions ******************************/
86
+
87
+Servo::Servo() {
88
+  if (ServoCount < MAX_SERVOS) {
89
+    this->servoIndex = ServoCount++;                    // assign a servo index to this instance
90
+    servo_info[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH);   // store default values  - 12 Aug 2009
91
+  }
92
+  else
93
+    this->servoIndex = INVALID_SERVO;  // too many servos
94
+}
95
+
96
+int8_t Servo::attach(int pin) {
97
+  return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
98
+}
99
+
100
+int8_t Servo::attach(int pin, int min, int max) {
101
+
102
+  if (this->servoIndex >= MAX_SERVOS) return -1;
103
+
104
+  if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
105
+  pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
106
+
107
+  // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
108
+  this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
109
+  this->max = (MAX_PULSE_WIDTH - max) / 4;
110
+
111
+  // initialize the timer if it has not already been initialized
112
+  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
113
+  if (!isTimerActive(timer)) initISR(timer);
114
+  servo_info[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
115
+
116
+  return this->servoIndex;
117
+}
118
+
119
+void Servo::detach() {
120
+  servo_info[this->servoIndex].Pin.isActive = false;
121
+  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
122
+  if (!isTimerActive(timer)) finISR(timer);
123
+}
124
+
125
+void Servo::write(int value) {
126
+  if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
127
+    value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
128
+  }
129
+  this->writeMicroseconds(value);
130
+}
131
+
132
+void Servo::writeMicroseconds(int value) {
133
+  // calculate and store the values for the given channel
134
+  byte channel = this->servoIndex;
135
+  if (channel < MAX_SERVOS) {  // ensure channel is valid
136
+    // ensure pulse width is valid
137
+    value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
138
+    value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
139
+
140
+    CRITICAL_SECTION_START;
141
+    servo_info[channel].ticks = value;
142
+    CRITICAL_SECTION_END;
143
+  }
144
+}
145
+
146
+// return the value as degrees
147
+int Servo::read() { return map(this->readMicroseconds() + 1, SERVO_MIN(), SERVO_MAX(), 0, 180); }
148
+
149
+int Servo::readMicroseconds() {
150
+  return (this->servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[this->servoIndex].ticks) + TRIM_DURATION;
151
+}
152
+
153
+bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
154
+
155
+void Servo::move(int value) {
156
+  constexpr uint16_t servo_delay[] = SERVO_DELAY;
157
+  static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
158
+  if (this->attach(0) >= 0) {
159
+    this->write(value);
160
+    delay(servo_delay[this->servoIndex]);
161
+    #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
162
+      this->detach();
163
+    #endif
164
+  }
165
+}
166
+
167
+#endif // HAS_SERVOS
168
+

Marlin/servo.h → Marlin/src/HAL/servo.h Переглянути файл

69
 #ifndef servo_h
69
 #ifndef servo_h
70
 #define servo_h
70
 #define servo_h
71
 
71
 
72
-#include <inttypes.h>
72
+#if IS_32BIT_TEENSY
73
+  #include "HAL_TEENSY35_36/HAL_Servo_Teensy.h" // Teensy HAL uses an inherited library
74
+#else
73
 
75
 
74
-/**
75
- * Defines for 16 bit timers used with  Servo library
76
- *
77
- * If _useTimerX is defined then TimerX is a 16 bit timer on the current board
78
- * timer16_Sequence_t enumerates the sequence that the timers should be allocated
79
- * _Nbr_16timers indicates how many 16 bit timers are available.
80
- *
81
- */
76
+#include <inttypes.h>
82
 
77
 
83
-// Say which 16 bit timers can be used and in what order
84
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
85
-  //#define _useTimer1 // Timer 1 is used by the stepper ISR
86
-  #define _useTimer3
87
-  #define _useTimer4
88
-  #if !HAS_MOTOR_CURRENT_PWM
89
-    #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
90
-  #endif
91
-#elif defined(__AVR_ATmega32U4__)
92
-  #define _useTimer3
93
-#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
94
-  #define _useTimer3
95
-#elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2561__)
96
-  #define _useTimer3
78
+#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAM)
79
+  // we're good to go
97
 #else
80
 #else
98
-  // everything else
81
+  #error "This library only supports boards with an AVR or SAM3X processor."
99
 #endif
82
 #endif
100
 
83
 
101
-typedef enum {
102
-  #if ENABLED(_useTimer1)
103
-    _timer1,
104
-  #endif
105
-  #if ENABLED(_useTimer3)
106
-    _timer3,
107
-  #endif
108
-  #if ENABLED(_useTimer4)
109
-    _timer4,
110
-  #endif
111
-  #if ENABLED(_useTimer5)
112
-    _timer5,
113
-  #endif
114
-  _Nbr_16timers
115
-} timer16_Sequence_t;
116
-
117
-
118
 #define Servo_VERSION           2     // software version of this library
84
 #define Servo_VERSION           2     // software version of this library
119
 
85
 
120
-#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo
121
-#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo
122
-#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
123
-#define REFRESH_INTERVAL    20000     // minimum time to refresh servos in microseconds
124
-
125
-#define SERVOS_PER_TIMER       12     // the maximum number of servos controlled by one timer
126
-#define MAX_SERVOS   (_Nbr_16timers  * SERVOS_PER_TIMER)
127
-
128
-#define INVALID_SERVO         255     // flag indicating an invalid servo index
129
-
130
-typedef struct {
131
-  uint8_t nbr        : 6 ;            // a pin number from 0 to 63
132
-  uint8_t isActive   : 1 ;            // true if this channel is enabled, pin not pulsed if false
133
-} ServoPin_t;
134
-
135
-typedef struct {
136
-  ServoPin_t Pin;
137
-  unsigned int ticks;
138
-} ServoInfo_t;
139
-
140
 class Servo {
86
 class Servo {
141
   public:
87
   public:
142
     Servo();
88
     Servo();
158
     int8_t max;                       // maximum is this value times 4 added to MAX_PULSE_WIDTH
104
     int8_t max;                       // maximum is this value times 4 added to MAX_PULSE_WIDTH
159
 };
105
 };
160
 
106
 
107
+#endif // !TEENSY
108
+
161
 #endif
109
 #endif

+ 103
- 0
Marlin/src/HAL/servo_private.h Переглянути файл

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+  servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
25
+  Copyright (c) 2009 Michael Margolis.  All right reserved.
26
+
27
+  This library is free software; you can redistribute it and/or
28
+  modify it under the terms of the GNU Lesser General Public
29
+  License as published by the Free Software Foundation; either
30
+  version 2.1 of the License, or (at your option) any later version.
31
+
32
+  This library is distributed in the hope that it will be useful,
33
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35
+  Lesser General Public License for more details.
36
+
37
+  You should have received a copy of the GNU Lesser General Public
38
+  License along with this library; if not, write to the Free Software
39
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
40
+*/
41
+
42
+#ifndef servo_private_h
43
+#define servo_private_h
44
+
45
+#include <inttypes.h>
46
+
47
+// Architecture specific include
48
+#ifdef ARDUINO_ARCH_AVR
49
+  #include "HAL_AVR/ServoTimers.h"
50
+#elif defined(ARDUINO_ARCH_SAM)
51
+  #include "HAL_DUE/ServoTimers.h"
52
+#else
53
+  #error "This library only supports boards with an AVR or SAM3X processor."
54
+#endif
55
+
56
+// Macros
57
+
58
+#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo
59
+#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo
60
+#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
61
+#define REFRESH_INTERVAL    20000     // minimum time to refresh servos in microseconds
62
+
63
+#define SERVOS_PER_TIMER       12     // the maximum number of servos controlled by one timer
64
+#define MAX_SERVOS   (_Nbr_16timers  * SERVOS_PER_TIMER)
65
+
66
+#define INVALID_SERVO         255     // flag indicating an invalid servo index
67
+
68
+//
69
+#define usToTicks(_us)    (( clockCyclesPerMicrosecond()* _us) / PRESCALER)     // converts microseconds to tick (PRESCALER depends on architecture)
70
+#define ticksToUs(_ticks) (( (unsigned)_ticks * PRESCALER)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds
71
+
72
+//#define NBR_TIMERS        ((MAX_SERVOS) / (SERVOS_PER_TIMER))
73
+
74
+// convenience macros
75
+#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
76
+#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % (SERVOS_PER_TIMER))       // returns the index of the servo on this timer
77
+#define SERVO_INDEX(_timer,_channel)  ((_timer*(SERVOS_PER_TIMER)) + _channel)     // macro to access servo index by timer and channel
78
+#define SERVO(_timer,_channel)  (servo_info[SERVO_INDEX(_timer,_channel)])       // macro to access servo class by timer and channel
79
+
80
+// Types
81
+
82
+typedef struct {
83
+  uint8_t nbr        : 6 ;            // a pin number from 0 to 63
84
+  uint8_t isActive   : 1 ;            // true if this channel is enabled, pin not pulsed if false
85
+} ServoPin_t;
86
+
87
+typedef struct {
88
+  ServoPin_t Pin;
89
+  unsigned int ticks;
90
+} ServoInfo_t;
91
+
92
+// Global variables
93
+
94
+extern uint8_t ServoCount;
95
+extern ServoInfo_t servo_info[MAX_SERVOS];
96
+
97
+// Public functions
98
+
99
+extern void initISR(timer16_Sequence_t timer);
100
+extern void finISR(timer16_Sequence_t timer);
101
+
102
+
103
+#endif

+ 83
- 97
Marlin/stepper.cpp Переглянути файл

48
 #include "stepper.h"
48
 #include "stepper.h"
49
 #include "endstops.h"
49
 #include "endstops.h"
50
 #include "planner.h"
50
 #include "planner.h"
51
+#if MB(ALLIGATOR)
52
+  #include "dac_dac084s085.h"
53
+#endif
51
 #include "temperature.h"
54
 #include "temperature.h"
52
 #include "ultralcd.h"
55
 #include "ultralcd.h"
53
 #include "language.h"
56
 #include "language.h"
54
 #include "cardreader.h"
57
 #include "cardreader.h"
55
-#include "speed_lookuptable.h"
58
+#ifdef ARDUINO_ARCH_AVR
59
+  #include "speed_lookuptable.h"
60
+#endif
56
 
61
 
57
 #if HAS_DIGIPOTSS
62
 #if HAS_DIGIPOTSS
58
   #include <SPI.h>
63
   #include <SPI.h>
99
 
104
 
100
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
105
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
101
 
106
 
102
-  constexpr uint16_t ADV_NEVER = 65535;
107
+  constexpr HAL_TIMER_TYPE ADV_NEVER = HAL_TIMER_TYPE_MAX;
103
 
108
 
104
-  uint16_t Stepper::nextMainISR = 0,
105
-           Stepper::nextAdvanceISR = ADV_NEVER,
106
-           Stepper::eISR_Rate = ADV_NEVER;
109
+  HAL_TIMER_TYPE Stepper::nextMainISR = 0,
110
+         Stepper::nextAdvanceISR = ADV_NEVER,
111
+         Stepper::eISR_Rate = ADV_NEVER;
107
 
112
 
108
   #if ENABLED(LIN_ADVANCE)
113
   #if ENABLED(LIN_ADVANCE)
109
     volatile int Stepper::e_steps[E_STEPPERS];
114
     volatile int Stepper::e_steps[E_STEPPERS];
144
   long Stepper::counter_m[MIXING_STEPPERS];
149
   long Stepper::counter_m[MIXING_STEPPERS];
145
 #endif
150
 #endif
146
 
151
 
147
-unsigned short Stepper::acc_step_rate; // needed for deceleration start point
152
+HAL_TIMER_TYPE Stepper::acc_step_rate; // needed for deceleration start point
148
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
153
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
149
-unsigned short Stepper::OCR1A_nominal;
154
+HAL_TIMER_TYPE Stepper::OCR1A_nominal;
150
 
155
 
151
 volatile long Stepper::endstops_trigsteps[XYZ];
156
 volatile long Stepper::endstops_trigsteps[XYZ];
152
 
157
 
213
   #define E_APPLY_STEP(v,Q) E_STEP_WRITE(v)
218
   #define E_APPLY_STEP(v,Q) E_STEP_WRITE(v)
214
 #endif
219
 #endif
215
 
220
 
216
-// intRes = longIn1 * longIn2 >> 24
217
-// uses:
218
-// r26 to store 0
219
-// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
220
-// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
221
-// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
222
-// B0 A0 are bits 24-39 and are the returned value
223
-// C1 B1 A1 is longIn1
224
-// D2 C2 B2 A2 is longIn2
225
-//
226
-#define MultiU24X32toH16(intRes, longIn1, longIn2) \
227
-  asm volatile ( \
228
-                 "clr r26 \n\t" \
229
-                 "mul %A1, %B2 \n\t" \
230
-                 "mov r27, r1 \n\t" \
231
-                 "mul %B1, %C2 \n\t" \
232
-                 "movw %A0, r0 \n\t" \
233
-                 "mul %C1, %C2 \n\t" \
234
-                 "add %B0, r0 \n\t" \
235
-                 "mul %C1, %B2 \n\t" \
236
-                 "add %A0, r0 \n\t" \
237
-                 "adc %B0, r1 \n\t" \
238
-                 "mul %A1, %C2 \n\t" \
239
-                 "add r27, r0 \n\t" \
240
-                 "adc %A0, r1 \n\t" \
241
-                 "adc %B0, r26 \n\t" \
242
-                 "mul %B1, %B2 \n\t" \
243
-                 "add r27, r0 \n\t" \
244
-                 "adc %A0, r1 \n\t" \
245
-                 "adc %B0, r26 \n\t" \
246
-                 "mul %C1, %A2 \n\t" \
247
-                 "add r27, r0 \n\t" \
248
-                 "adc %A0, r1 \n\t" \
249
-                 "adc %B0, r26 \n\t" \
250
-                 "mul %B1, %A2 \n\t" \
251
-                 "add r27, r1 \n\t" \
252
-                 "adc %A0, r26 \n\t" \
253
-                 "adc %B0, r26 \n\t" \
254
-                 "lsr r27 \n\t" \
255
-                 "adc %A0, r26 \n\t" \
256
-                 "adc %B0, r26 \n\t" \
257
-                 "mul %D2, %A1 \n\t" \
258
-                 "add %A0, r0 \n\t" \
259
-                 "adc %B0, r1 \n\t" \
260
-                 "mul %D2, %B1 \n\t" \
261
-                 "add %B0, r0 \n\t" \
262
-                 "clr r1 \n\t" \
263
-                 : \
264
-                 "=&r" (intRes) \
265
-                 : \
266
-                 "d" (longIn1), \
267
-                 "d" (longIn2) \
268
-                 : \
269
-                 "r26" , "r27" \
270
-               )
271
-
272
-// Some useful constants
273
-
274
-#define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
275
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
221
+
276
 
222
 
277
 /**
223
 /**
278
  *         __________________________
224
  *         __________________________
345
  * Stepper Driver Interrupt
291
  * Stepper Driver Interrupt
346
  *
292
  *
347
  * Directly pulses the stepper motors at high frequency.
293
  * Directly pulses the stepper motors at high frequency.
294
+ *
295
+ * AVR :
348
  * Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
296
  * Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
349
  *
297
  *
350
  * OCR1A   Frequency
298
  * OCR1A   Frequency
355
  *  2000     1 KHz - sleep rate
303
  *  2000     1 KHz - sleep rate
356
  *  4000   500  Hz - init rate
304
  *  4000   500  Hz - init rate
357
  */
305
  */
358
-ISR(TIMER1_COMPA_vect) {
306
+
307
+HAL_STEP_TIMER_ISR {
308
+  HAL_timer_isr_prologue(STEP_TIMER_NUM);
359
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
309
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
360
     Stepper::advance_isr_scheduler();
310
     Stepper::advance_isr_scheduler();
361
   #else
311
   #else
363
   #endif
313
   #endif
364
 }
314
 }
365
 
315
 
366
-#define _ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr) CBI(TIMSK0, OCIE0B); else SBI(TIMSK0, OCIE0B); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
367
-
368
 void Stepper::isr() {
316
 void Stepper::isr() {
369
 
317
 
370
-  uint16_t ocr_val;
318
+  HAL_TIMER_TYPE ocr_val;
371
 
319
 
372
   #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
320
   #define ENDSTOP_NOMINAL_OCR_VAL 3000    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
373
   #define OCR_VAL_TOLERANCE 1000          // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
321
   #define OCR_VAL_TOLERANCE 1000          // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
374
 
322
 
375
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
323
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
376
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
324
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
377
-    CBI(TIMSK0, OCIE0B); // Temperature ISR
325
+    DISABLE_TEMPERATURE_INTERRUPT(); // Temperature ISR
378
     DISABLE_STEPPER_DRIVER_INTERRUPT();
326
     DISABLE_STEPPER_DRIVER_INTERRUPT();
379
-    sei();
327
+    #if !defined(CPU_32_BIT)
328
+      sei();
329
+    #endif
380
   #endif
330
   #endif
381
 
331
 
382
-  #define _SPLIT(L) (ocr_val = (uint16_t)L)
332
+  #define _SPLIT(L) (ocr_val = (HAL_TIMER_TYPE)L)
383
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
333
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
384
     #define SPLIT(L) _SPLIT(L)
334
     #define SPLIT(L) _SPLIT(L)
385
   #else                 // sample endstops in between step pulses
335
   #else                 // sample endstops in between step pulses
405
       }
355
       }
406
 
356
 
407
       _NEXT_ISR(ocr_val);
357
       _NEXT_ISR(ocr_val);
358
+      #ifdef CPU_32_BIT
359
+        //todo: HAL?
360
+      #else
361
+        NOLESS(OCR1A, TCNT1 + 16);
362
+      #endif
408
 
363
 
409
-      NOLESS(OCR1A, TCNT1 + 16);
410
-
411
-      _ENABLE_ISRs(); // re-enable ISRs
364
+      HAL_ENABLE_ISRs(); // re-enable ISRs
412
       return;
365
       return;
413
     }
366
     }
414
   #endif
367
   #endif
420
     #ifdef SD_FINISHED_RELEASECOMMAND
373
     #ifdef SD_FINISHED_RELEASECOMMAND
421
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
374
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
422
     #endif
375
     #endif
423
-    _NEXT_ISR(200); // Run at max speed - 10 KHz
424
-    _ENABLE_ISRs(); // re-enable ISRs
376
+    _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 10000); // Run at max speed - 10 KHz
377
+    HAL_ENABLE_ISRs(); // re-enable ISRs
425
     return;
378
     return;
426
   }
379
   }
427
 
380
 
450
       #if ENABLED(Z_LATE_ENABLE)
403
       #if ENABLED(Z_LATE_ENABLE)
451
         if (current_block->steps[Z_AXIS] > 0) {
404
         if (current_block->steps[Z_AXIS] > 0) {
452
           enable_Z();
405
           enable_Z();
453
-          _NEXT_ISR(2000); // Run at slow speed - 1 KHz
454
-          _ENABLE_ISRs(); // re-enable ISRs
406
+          _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
407
+          HAL_ENABLE_ISRs(); // re-enable ISRs
455
           return;
408
           return;
456
         }
409
         }
457
       #endif
410
       #endif
461
       // #endif
414
       // #endif
462
     }
415
     }
463
     else {
416
     else {
464
-      _NEXT_ISR(2000); // Run at slow speed - 1 KHz
465
-      _ENABLE_ISRs(); // re-enable ISRs
417
+      _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
418
+      HAL_ENABLE_ISRs(); // re-enable ISRs
466
       return;
419
       return;
467
     }
420
     }
468
   }
421
   }
613
      * 10µs = 160 or 200 cycles.
566
      * 10µs = 160 or 200 cycles.
614
      */
567
      */
615
     #if EXTRA_CYCLES_XYZE > 20
568
     #if EXTRA_CYCLES_XYZE > 20
616
-      uint32_t pulse_start = TCNT0;
569
+      uint32_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
617
     #endif
570
     #endif
618
 
571
 
619
     #if HAS_X_STEP
572
     #if HAS_X_STEP
645
 
598
 
646
     // For minimum pulse time wait before stopping pulses
599
     // For minimum pulse time wait before stopping pulses
647
     #if EXTRA_CYCLES_XYZE > 20
600
     #if EXTRA_CYCLES_XYZE > 20
648
-      while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
649
-      pulse_start = TCNT0;
601
+      while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
602
+      pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
650
     #elif EXTRA_CYCLES_XYZE > 0
603
     #elif EXTRA_CYCLES_XYZE > 0
651
       DELAY_NOPS(EXTRA_CYCLES_XYZE);
604
       DELAY_NOPS(EXTRA_CYCLES_XYZE);
652
     #endif
605
     #endif
686
 
639
 
687
     // For minimum pulse time wait after stopping pulses also
640
     // For minimum pulse time wait after stopping pulses also
688
     #if EXTRA_CYCLES_XYZE > 20
641
     #if EXTRA_CYCLES_XYZE > 20
689
-      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
642
+      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
690
     #elif EXTRA_CYCLES_XYZE > 0
643
     #elif EXTRA_CYCLES_XYZE > 0
691
       if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
644
       if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
692
     #endif
645
     #endif
716
   // Calculate new timer value
669
   // Calculate new timer value
717
   if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
670
   if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
718
 
671
 
719
-    MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
672
+    #ifdef CPU_32_BIT
673
+      MultiU32X24toH32(acc_step_rate, acceleration_time, current_block->acceleration_rate);
674
+    #else
675
+      MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
676
+    #endif
720
     acc_step_rate += current_block->initial_rate;
677
     acc_step_rate += current_block->initial_rate;
721
 
678
 
722
     // upper limit
679
     // upper limit
723
     NOMORE(acc_step_rate, current_block->nominal_rate);
680
     NOMORE(acc_step_rate, current_block->nominal_rate);
724
 
681
 
725
     // step_rate to timer interval
682
     // step_rate to timer interval
726
-    const uint16_t timer = calc_timer(acc_step_rate);
683
+    const HAL_TIMER_TYPE timer = calc_timer(acc_step_rate);
727
 
684
 
728
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
685
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
729
     _NEXT_ISR(ocr_val);
686
     _NEXT_ISR(ocr_val);
764
     #endif // ADVANCE or LIN_ADVANCE
721
     #endif // ADVANCE or LIN_ADVANCE
765
 
722
 
766
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
723
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
724
+      // TODO: HAL
767
       eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
725
       eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
768
     #endif
726
     #endif
769
   }
727
   }
770
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
728
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
771
-    uint16_t step_rate;
772
-    MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
729
+    HAL_TIMER_TYPE step_rate;
730
+    #ifdef CPU_32_BIT
731
+      MultiU32X24toH32(step_rate, deceleration_time, current_block->acceleration_rate);
732
+    #else
733
+      MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
734
+    #endif
773
 
735
 
774
     if (step_rate < acc_step_rate) { // Still decelerating?
736
     if (step_rate < acc_step_rate) { // Still decelerating?
775
       step_rate = acc_step_rate - step_rate;
737
       step_rate = acc_step_rate - step_rate;
779
       step_rate = current_block->final_rate;
741
       step_rate = current_block->final_rate;
780
 
742
 
781
     // step_rate to timer interval
743
     // step_rate to timer interval
782
-    const uint16_t timer = calc_timer(step_rate);
744
+    const HAL_TIMER_TYPE timer = calc_timer(step_rate);
783
 
745
 
784
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
746
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
785
     _NEXT_ISR(ocr_val);
747
     _NEXT_ISR(ocr_val);
834
 
796
 
835
     SPLIT(OCR1A_nominal);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
797
     SPLIT(OCR1A_nominal);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
836
     _NEXT_ISR(ocr_val);
798
     _NEXT_ISR(ocr_val);
837
-
838
     // ensure we're running at the correct step rate, even if we just came off an acceleration
799
     // ensure we're running at the correct step rate, even if we just came off an acceleration
839
     step_loops = step_loops_nominal;
800
     step_loops = step_loops_nominal;
840
   }
801
   }
841
 
802
 
842
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
803
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
843
-    NOLESS(OCR1A, TCNT1 + 16);
804
+    #ifdef CPU_32_BIT
805
+      // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
806
+      uint32_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM);
807
+      uint32_t stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
808
+      HAL_timer_set_count(STEP_TIMER_NUM, stepper_timer_count < stepper_timer_current_count ? stepper_timer_current_count : stepper_timer_count);
809
+    #else
810
+      NOLESS(OCR1A, TCNT1 + 16);
811
+    #endif
844
   #endif
812
   #endif
845
 
813
 
846
   // If current block is finished, reset pointer
814
   // If current block is finished, reset pointer
849
     planner.discard_current_block();
817
     planner.discard_current_block();
850
   }
818
   }
851
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
819
   #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
852
-    _ENABLE_ISRs(); // re-enable ISRs
820
+    HAL_ENABLE_ISRs(); // re-enable ISRs
853
   #endif
821
   #endif
854
 }
822
 }
855
 
823
 
951
 
919
 
952
   void Stepper::advance_isr_scheduler() {
920
   void Stepper::advance_isr_scheduler() {
953
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
921
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
954
-    CBI(TIMSK0, OCIE0B); // Temperature ISR
922
+    DISABLE_TEMPERATURE_INTERRUPT(); // Temperature ISR
955
     DISABLE_STEPPER_DRIVER_INTERRUPT();
923
     DISABLE_STEPPER_DRIVER_INTERRUPT();
956
     sei();
924
     sei();
957
 
925
 
984
     NOLESS(OCR1A, TCNT1 + 16);
952
     NOLESS(OCR1A, TCNT1 + 16);
985
 
953
 
986
     // Restore original ISR settings
954
     // Restore original ISR settings
987
-    _ENABLE_ISRs();
955
+    HAL_ENABLE_ISRs();
988
   }
956
   }
989
 
957
 
990
 #endif // ADVANCE or LIN_ADVANCE
958
 #endif // ADVANCE or LIN_ADVANCE
996
     digipot_init();
964
     digipot_init();
997
   #endif
965
   #endif
998
 
966
 
967
+  #if MB(ALLIGATOR)
968
+    const float motor_current[] = MOTOR_CURRENT;
969
+    unsigned int digipot_motor = 0;
970
+    for (uint8_t i = 0; i < 3 + EXTRUDERS; i++) {
971
+      digipot_motor = 255 * (motor_current[i] / 2.5);
972
+      dac084s085::setValue(i, digipot_motor);
973
+    }
974
+  #endif//MB(ALLIGATOR)
975
+
999
   // Init Microstepping Pins
976
   // Init Microstepping Pins
1000
   #if HAS_MICROSTEPS
977
   #if HAS_MICROSTEPS
1001
     microstep_init();
978
     microstep_init();
1152
     E_AXIS_INIT(4);
1129
     E_AXIS_INIT(4);
1153
   #endif
1130
   #endif
1154
 
1131
 
1132
+#ifdef ARDUINO_ARCH_AVR
1155
   // waveform generation = 0100 = CTC
1133
   // waveform generation = 0100 = CTC
1156
   SET_WGM(1, CTC_OCRnA);
1134
   SET_WGM(1, CTC_OCRnA);
1157
 
1135
 
1168
   // Init Stepper ISR to 122 Hz for quick starting
1146
   // Init Stepper ISR to 122 Hz for quick starting
1169
   OCR1A = 0x4000;
1147
   OCR1A = 0x4000;
1170
   TCNT1 = 0;
1148
   TCNT1 = 0;
1149
+#else
1150
+  // Init Stepper ISR to 122 Hz for quick starting
1151
+  HAL_timer_start (STEP_TIMER_NUM, 122);
1152
+#endif
1153
+
1171
   ENABLE_STEPPER_DRIVER_INTERRUPT();
1154
   ENABLE_STEPPER_DRIVER_INTERRUPT();
1172
 
1155
 
1173
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
1156
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
1663
       case 4: microstep_ms(driver, MICROSTEP4); break;
1646
       case 4: microstep_ms(driver, MICROSTEP4); break;
1664
       case 8: microstep_ms(driver, MICROSTEP8); break;
1647
       case 8: microstep_ms(driver, MICROSTEP8); break;
1665
       case 16: microstep_ms(driver, MICROSTEP16); break;
1648
       case 16: microstep_ms(driver, MICROSTEP16); break;
1649
+      #if MB(ALLIGATOR)
1650
+        case 32: microstep_ms(driver, MICROSTEP32); break;
1651
+      #endif
1666
     }
1652
     }
1667
   }
1653
   }
1668
 
1654
 

+ 66
- 62
Marlin/stepper.h Переглянути файл

52
 class Stepper;
52
 class Stepper;
53
 extern Stepper stepper;
53
 extern Stepper stepper;
54
 
54
 
55
-// intRes = intIn1 * intIn2 >> 16
56
-// uses:
57
-// r26 to store 0
58
-// r27 to store the byte 1 of the 24 bit result
59
-#define MultiU16X8toH16(intRes, charIn1, intIn2) \
60
-  asm volatile ( \
61
-                 "clr r26 \n\t" \
62
-                 "mul %A1, %B2 \n\t" \
63
-                 "movw %A0, r0 \n\t" \
64
-                 "mul %A1, %A2 \n\t" \
65
-                 "add %A0, r1 \n\t" \
66
-                 "adc %B0, r26 \n\t" \
67
-                 "lsr r0 \n\t" \
68
-                 "adc %A0, r26 \n\t" \
69
-                 "adc %B0, r26 \n\t" \
70
-                 "clr r1 \n\t" \
71
-                 : \
72
-                 "=&r" (intRes) \
73
-                 : \
74
-                 "d" (charIn1), \
75
-                 "d" (intIn2) \
76
-                 : \
77
-                 "r26" \
78
-               )
79
-
80
 class Stepper {
55
 class Stepper {
81
 
56
 
82
   public:
57
   public:
112
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
87
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
113
 
88
 
114
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
89
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
115
-      static uint16_t nextMainISR, nextAdvanceISR, eISR_Rate;
90
+      static HAL_TIMER_TYPE nextMainISR, nextAdvanceISR, eISR_Rate;
116
       #define _NEXT_ISR(T) nextMainISR = T
91
       #define _NEXT_ISR(T) nextMainISR = T
92
+
117
       #if ENABLED(LIN_ADVANCE)
93
       #if ENABLED(LIN_ADVANCE)
118
         static volatile int e_steps[E_STEPPERS];
94
         static volatile int e_steps[E_STEPPERS];
119
         static int final_estep_rate;
95
         static int final_estep_rate;
127
         static long old_advance;
103
         static long old_advance;
128
       #endif
104
       #endif
129
     #else
105
     #else
130
-      #define _NEXT_ISR(T) OCR1A = T
106
+      #define _NEXT_ISR(T) HAL_timer_set_count(STEP_TIMER_NUM, T);
131
     #endif // ADVANCE or LIN_ADVANCE
107
     #endif // ADVANCE or LIN_ADVANCE
132
 
108
 
133
     static long acceleration_time, deceleration_time;
109
     static long acceleration_time, deceleration_time;
134
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
110
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
135
-    static unsigned short acc_step_rate; // needed for deceleration start point
111
+    static HAL_TIMER_TYPE acc_step_rate; // needed for deceleration start point
136
     static uint8_t step_loops, step_loops_nominal;
112
     static uint8_t step_loops, step_loops_nominal;
137
-    static unsigned short OCR1A_nominal;
113
+    static HAL_TIMER_TYPE OCR1A_nominal;
138
 
114
 
139
     static volatile long endstops_trigsteps[XYZ];
115
     static volatile long endstops_trigsteps[XYZ];
140
     static volatile long endstops_stepsTotal, endstops_stepsDone;
116
     static volatile long endstops_stepsTotal, endstops_stepsDone;
285
 
261
 
286
   private:
262
   private:
287
 
263
 
288
-    static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
289
-      unsigned short timer;
264
+    static FORCE_INLINE HAL_TIMER_TYPE calc_timer(HAL_TIMER_TYPE step_rate) {
265
+      HAL_TIMER_TYPE timer;
290
 
266
 
291
       NOMORE(step_rate, MAX_STEP_FREQUENCY);
267
       NOMORE(step_rate, MAX_STEP_FREQUENCY);
292
 
268
 
293
-      if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
294
-        step_rate >>= 2;
295
-        step_loops = 4;
296
-      }
297
-      else if (step_rate > 10000) { // If steprate > 10kHz >> step 2 times
298
-        step_rate >>= 1;
299
-        step_loops = 2;
300
-      }
301
-      else {
302
-        step_loops = 1;
303
-      }
269
+      // TODO: HAL: tidy this up, use condtionals_post.h
270
+      #ifdef CPU_32_BIT
271
+        #if ENABLED(DISABLE_MULTI_STEPPING)
272
+          step_loops = 1;
273
+        #else
274
+          if (step_rate > STEP_DOUBLER_FREQUENCY * 2) { // If steprate > (STEP_DOUBLER_FREQUENCY * 2) kHz >> step 4 times
275
+            step_rate >>= 2;
276
+            step_loops = 4;
277
+          }
278
+          else if (step_rate > STEP_DOUBLER_FREQUENCY) { // If steprate > STEP_DOUBLER_FREQUENCY kHz >> step 2 times
279
+            step_rate >>= 1;
280
+            step_loops = 2;
281
+          }
282
+          else {
283
+            step_loops = 1;
284
+          }
285
+        #endif
286
+      #else
287
+        if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
288
+          step_rate >>= 2;
289
+          step_loops = 4;
290
+        }
291
+        else if (step_rate > 10000) { // If steprate > 10kHz >> step 2 times
292
+          step_rate >>= 1;
293
+          step_loops = 2;
294
+        }
295
+        else {
296
+          step_loops = 1;
297
+        }
298
+      #endif
299
+
300
+      #ifdef CPU_32_BIT
301
+        // In case of high-performance processor, it is able to calculate in real-time 
302
+        timer = (uint32_t)(HAL_STEPPER_TIMER_RATE) / step_rate;
303
+        if (timer < (HAL_STEPPER_TIMER_RATE / (STEP_DOUBLER_FREQUENCY * 2))) { // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
304
+          timer = (HAL_STEPPER_TIMER_RATE / (STEP_DOUBLER_FREQUENCY * 2));
305
+        }
306
+      #else
307
+        NOLESS(step_rate, F_CPU / 500000);
308
+        step_rate -= F_CPU / 500000; // Correct for minimal speed
309
+        if (step_rate >= (8 * 256)) { // higher step rate
310
+          unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
311
+          unsigned char tmp_step_rate = (step_rate & 0x00ff);
312
+          unsigned short gain = (unsigned short)pgm_read_word_near(table_address + 2);
313
+          MultiU16X8toH16(timer, tmp_step_rate, gain);
314
+          timer = (unsigned short)pgm_read_word_near(table_address) - timer;
315
+        }
316
+        else { // lower step rates
317
+          unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
318
+          table_address += ((step_rate) >> 1) & 0xfffc;
319
+          timer = (unsigned short)pgm_read_word_near(table_address);
320
+          timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
321
+        }
322
+        if (timer < 100) { // (20kHz - this should never happen)
323
+          timer = 100;
324
+          MYSERIAL.print(MSG_STEPPER_TOO_HIGH);
325
+          MYSERIAL.println(step_rate);
326
+        }
327
+      #endif
304
 
328
 
305
-      NOLESS(step_rate, F_CPU / 500000);
306
-      step_rate -= F_CPU / 500000; // Correct for minimal speed
307
-      if (step_rate >= (8 * 256)) { // higher step rate
308
-        unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
309
-        unsigned char tmp_step_rate = (step_rate & 0x00FF);
310
-        unsigned short gain = (unsigned short)pgm_read_word_near(table_address + 2);
311
-        MultiU16X8toH16(timer, tmp_step_rate, gain);
312
-        timer = (unsigned short)pgm_read_word_near(table_address) - timer;
313
-      }
314
-      else { // lower step rates
315
-        unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
316
-        table_address += ((step_rate) >> 1) & 0xFFFC;
317
-        timer = (unsigned short)pgm_read_word_near(table_address);
318
-        timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
319
-      }
320
-      if (timer < 100) { // (20kHz - this should never happen)
321
-        timer = 100;
322
-        MYSERIAL.print(MSG_STEPPER_TOO_HIGH);
323
-        MYSERIAL.println(step_rate);
324
-      }
325
       return timer;
329
       return timer;
326
     }
330
     }
327
 
331
 

+ 52
- 66
Marlin/temperature.cpp Переглянути файл

32
 #include "language.h"
32
 #include "language.h"
33
 
33
 
34
 #if ENABLED(HEATER_0_USES_MAX6675)
34
 #if ENABLED(HEATER_0_USES_MAX6675)
35
-  #include "spi.h"
35
+  #include "private_spi.h"
36
 #endif
36
 #endif
37
 
37
 
38
 #if ENABLED(BABYSTEPPING)
38
 #if ENABLED(BABYSTEPPING)
43
   #include "endstops.h"
43
   #include "endstops.h"
44
 #endif
44
 #endif
45
 
45
 
46
-#if ENABLED(USE_WATCHDOG)
47
-  #include "watchdog.h"
48
-#endif
49
-
50
 #ifdef K1 // Defined in Configuration.h in the PID settings
46
 #ifdef K1 // Defined in Configuration.h in the PID settings
51
   #define K2 (1.0-K1)
47
   #define K2 (1.0-K1)
52
 #endif
48
 #endif
1054
 
1050
 
1055
   #endif // HEATER_0_USES_MAX6675
1051
   #endif // HEATER_0_USES_MAX6675
1056
 
1052
 
1057
-  #ifdef DIDR2
1058
-    #define ANALOG_SELECT(pin) do{ if (pin < 8) SBI(DIDR0, pin); else SBI(DIDR2, pin - 8); }while(0)
1059
-  #else
1060
-    #define ANALOG_SELECT(pin) do{ SBI(DIDR0, pin); }while(0)
1061
-  #endif
1053
+  HAL_adc_init();
1062
 
1054
 
1063
-  // Set analog inputs
1064
-  ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
1065
-  DIDR0 = 0;
1066
-  #ifdef DIDR2
1067
-    DIDR2 = 0;
1068
-  #endif
1069
   #if HAS_TEMP_0
1055
   #if HAS_TEMP_0
1070
-    ANALOG_SELECT(TEMP_0_PIN);
1056
+    HAL_ANALOG_SELECT(TEMP_0_PIN);
1071
   #endif
1057
   #endif
1072
   #if HAS_TEMP_1
1058
   #if HAS_TEMP_1
1073
-    ANALOG_SELECT(TEMP_1_PIN);
1059
+    HAL_ANALOG_SELECT(TEMP_1_PIN);
1074
   #endif
1060
   #endif
1075
   #if HAS_TEMP_2
1061
   #if HAS_TEMP_2
1076
-    ANALOG_SELECT(TEMP_2_PIN);
1062
+    HAL_ANALOG_SELECT(TEMP_2_PIN);
1077
   #endif
1063
   #endif
1078
   #if HAS_TEMP_3
1064
   #if HAS_TEMP_3
1079
-    ANALOG_SELECT(TEMP_3_PIN);
1065
+    HAL_ANALOG_SELECT(TEMP_3_PIN);
1080
   #endif
1066
   #endif
1081
   #if HAS_TEMP_4
1067
   #if HAS_TEMP_4
1082
-    ANALOG_SELECT(TEMP_4_PIN);
1068
+    HAL_ANALOG_SELECT(TEMP_4_PIN);
1083
   #endif
1069
   #endif
1084
   #if HAS_TEMP_BED
1070
   #if HAS_TEMP_BED
1085
-    ANALOG_SELECT(TEMP_BED_PIN);
1071
+    HAL_ANALOG_SELECT(TEMP_BED_PIN);
1086
   #endif
1072
   #endif
1087
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
1073
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
1088
-    ANALOG_SELECT(FILWIDTH_PIN);
1074
+    HAL_ANALOG_SELECT(FILWIDTH_PIN);
1075
+  #endif
1076
+
1077
+// todo: HAL: fix abstraction
1078
+  #ifdef ARDUINO_ARCH_AVR
1079
+    // Use timer0 for temperature measurement
1080
+    // Interleave temperature interrupt with millies interrupt
1081
+    OCR0B = 128;
1082
+    SBI(TIMSK0, OCIE0B);
1083
+  #else
1084
+    HAL_timer_start (TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
1085
+    HAL_timer_enable_interrupt (TEMP_TIMER_NUM);
1089
   #endif
1086
   #endif
1090
 
1087
 
1091
   #if HAS_AUTO_FAN_0
1088
   #if HAS_AUTO_FAN_0
1139
     #endif
1136
     #endif
1140
   #endif
1137
   #endif
1141
 
1138
 
1142
-  // Use timer0 for temperature measurement
1143
-  // Interleave temperature interrupt with millies interrupt
1144
-  OCR0B = 128;
1145
-  SBI(TIMSK0, OCIE0B);
1146
-
1147
   // Wait for temperature measurement to settle
1139
   // Wait for temperature measurement to settle
1148
   delay(250);
1140
   delay(250);
1149
 
1141
 
1415
     uint32_t max6675_temp = 2000;
1407
     uint32_t max6675_temp = 2000;
1416
     #define MAX6675_ERROR_MASK 7
1408
     #define MAX6675_ERROR_MASK 7
1417
     #define MAX6675_DISCARD_BITS 18
1409
     #define MAX6675_DISCARD_BITS 18
1418
-    #define MAX6675_SPEED_BITS (_BV(SPR1)) // clock ÷ 64
1410
+    #define MAX6675_SPEED_BITS 3  // (_BV(SPR1)) // clock ÷ 64
1419
   #else
1411
   #else
1420
     uint16_t max6675_temp = 2000;
1412
     uint16_t max6675_temp = 2000;
1421
     #define MAX6675_ERROR_MASK 4
1413
     #define MAX6675_ERROR_MASK 4
1422
     #define MAX6675_DISCARD_BITS 3
1414
     #define MAX6675_DISCARD_BITS 3
1423
-    #define MAX6675_SPEED_BITS (_BV(SPR0)) // clock ÷ 16
1415
+    #define MAX6675_SPEED_BITS 2 // (_BV(SPR0)) // clock ÷ 16
1424
   #endif
1416
   #endif
1425
 
1417
 
1426
   int Temperature::read_max6675() {
1418
   int Temperature::read_max6675() {
1433
 
1425
 
1434
     next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
1426
     next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
1435
 
1427
 
1436
-    CBI(
1437
-      #ifdef PRR
1438
-        PRR
1439
-      #elif defined(PRR0)
1440
-        PRR0
1441
-      #endif
1442
-        , PRSPI);
1443
-    SPCR = _BV(MSTR) | _BV(SPE) | MAX6675_SPEED_BITS;
1428
+    spiBegin();
1429
+    spiInit(MAX6675_SPEED_BITS);
1444
 
1430
 
1445
     WRITE(MAX6675_SS, 0); // enable TT_MAX6675
1431
     WRITE(MAX6675_SS, 0); // enable TT_MAX6675
1446
 
1432
 
1451
     // Read a big-endian temperature value
1437
     // Read a big-endian temperature value
1452
     max6675_temp = 0;
1438
     max6675_temp = 0;
1453
     for (uint8_t i = sizeof(max6675_temp); i--;) {
1439
     for (uint8_t i = sizeof(max6675_temp); i--;) {
1454
-      max6675_temp |= max6675_spi.receive();
1440
+      max6675_temp |= spiRec();
1455
       if (i > 0) max6675_temp <<= 8; // shift left if not the last byte
1441
       if (i > 0) max6675_temp <<= 8; // shift left if not the last byte
1456
     }
1442
     }
1457
 
1443
 
1607
  *  - For PINS_DEBUGGING, monitor and report endstop pins
1593
  *  - For PINS_DEBUGGING, monitor and report endstop pins
1608
  *  - For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
1594
  *  - For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
1609
  */
1595
  */
1610
-ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1596
+HAL_TEMP_TIMER_ISR {
1597
+  HAL_timer_isr_prologue (TEMP_TIMER_NUM);
1598
+  Temperature::isr();
1599
+}
1611
 
1600
 
1612
 volatile bool Temperature::in_temp_isr = false;
1601
 volatile bool Temperature::in_temp_isr = false;
1613
 
1602
 
1618
   in_temp_isr = true;
1607
   in_temp_isr = true;
1619
 
1608
 
1620
   // Allow UART and stepper ISRs
1609
   // Allow UART and stepper ISRs
1621
-  CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
1622
-  sei();
1610
+  DISABLE_TEMPERATURE_INTERRUPT(); //Disable Temperature ISR
1611
+  #if !defined(CPU_32_BIT)
1612
+    sei();
1613
+  #endif
1623
 
1614
 
1624
   static int8_t temp_count = -1;
1615
   static int8_t temp_count = -1;
1625
   static ADCSensorState adc_sensor_state = StartupDelay;
1616
   static ADCSensorState adc_sensor_state = StartupDelay;
1914
    * This gives each ADC 0.9765ms to charge up.
1905
    * This gives each ADC 0.9765ms to charge up.
1915
    */
1906
    */
1916
 
1907
 
1917
-  #define SET_ADMUX_ADCSRA(pin) ADMUX = _BV(REFS0) | (pin & 0x07); SBI(ADCSRA, ADSC)
1918
-  #ifdef MUX5
1919
-    #define START_ADC(pin) if (pin > 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1920
-  #else
1921
-    #define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
1922
-  #endif
1923
-
1924
   switch (adc_sensor_state) {
1908
   switch (adc_sensor_state) {
1925
 
1909
 
1926
     case SensorsReady: {
1910
     case SensorsReady: {
1940
 
1924
 
1941
     #if HAS_TEMP_0
1925
     #if HAS_TEMP_0
1942
       case PrepareTemp_0:
1926
       case PrepareTemp_0:
1943
-        START_ADC(TEMP_0_PIN);
1927
+        HAL_START_ADC(TEMP_0_PIN);
1944
         break;
1928
         break;
1945
       case MeasureTemp_0:
1929
       case MeasureTemp_0:
1946
-        raw_temp_value[0] += ADC;
1930
+        raw_temp_value[0] += HAL_READ_ADC;
1947
         break;
1931
         break;
1948
     #endif
1932
     #endif
1949
 
1933
 
1950
     #if HAS_TEMP_BED
1934
     #if HAS_TEMP_BED
1951
       case PrepareTemp_BED:
1935
       case PrepareTemp_BED:
1952
-        START_ADC(TEMP_BED_PIN);
1936
+        HAL_START_ADC(TEMP_BED_PIN);
1953
         break;
1937
         break;
1954
       case MeasureTemp_BED:
1938
       case MeasureTemp_BED:
1955
-        raw_temp_bed_value += ADC;
1939
+        raw_temp_bed_value += HAL_READ_ADC;
1956
         break;
1940
         break;
1957
     #endif
1941
     #endif
1958
 
1942
 
1959
     #if HAS_TEMP_1
1943
     #if HAS_TEMP_1
1960
       case PrepareTemp_1:
1944
       case PrepareTemp_1:
1961
-        START_ADC(TEMP_1_PIN);
1945
+        HAL_START_ADC(TEMP_1_PIN);
1962
         break;
1946
         break;
1963
       case MeasureTemp_1:
1947
       case MeasureTemp_1:
1964
-        raw_temp_value[1] += ADC;
1948
+        raw_temp_value[1] += HAL_READ_ADC;
1965
         break;
1949
         break;
1966
     #endif
1950
     #endif
1967
 
1951
 
1968
     #if HAS_TEMP_2
1952
     #if HAS_TEMP_2
1969
       case PrepareTemp_2:
1953
       case PrepareTemp_2:
1970
-        START_ADC(TEMP_2_PIN);
1954
+        HAL_START_ADC(TEMP_2_PIN);
1971
         break;
1955
         break;
1972
       case MeasureTemp_2:
1956
       case MeasureTemp_2:
1973
-        raw_temp_value[2] += ADC;
1957
+        raw_temp_value[2] += HAL_READ_ADC;
1974
         break;
1958
         break;
1975
     #endif
1959
     #endif
1976
 
1960
 
1977
     #if HAS_TEMP_3
1961
     #if HAS_TEMP_3
1978
       case PrepareTemp_3:
1962
       case PrepareTemp_3:
1979
-        START_ADC(TEMP_3_PIN);
1963
+        HAL_START_ADC(TEMP_3_PIN);
1980
         break;
1964
         break;
1981
       case MeasureTemp_3:
1965
       case MeasureTemp_3:
1982
-        raw_temp_value[3] += ADC;
1966
+        raw_temp_value[3] += HAL_READ_ADC;
1983
         break;
1967
         break;
1984
     #endif
1968
     #endif
1985
 
1969
 
1986
     #if HAS_TEMP_4
1970
     #if HAS_TEMP_4
1987
       case PrepareTemp_4:
1971
       case PrepareTemp_4:
1988
-        START_ADC(TEMP_4_PIN);
1972
+        HAL_START_ADC(TEMP_4_PIN);
1989
         break;
1973
         break;
1990
       case MeasureTemp_4:
1974
       case MeasureTemp_4:
1991
-        raw_temp_value[4] += ADC;
1975
+        raw_temp_value[4] += HAL_READ_ADC;
1992
         break;
1976
         break;
1993
     #endif
1977
     #endif
1994
 
1978
 
1995
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
1979
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
1996
       case Prepare_FILWIDTH:
1980
       case Prepare_FILWIDTH:
1997
-        START_ADC(FILWIDTH_PIN);
1981
+        HAL_START_ADC(FILWIDTH_PIN);
1998
       break;
1982
       break;
1999
       case Measure_FILWIDTH:
1983
       case Measure_FILWIDTH:
2000
-        if (ADC > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
1984
+        if (HAL_READ_ADC > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
2001
           raw_filwidth_value -= (raw_filwidth_value >> 7); // Subtract 1/128th of the raw_filwidth_value
1985
           raw_filwidth_value -= (raw_filwidth_value >> 7); // Subtract 1/128th of the raw_filwidth_value
2002
-          raw_filwidth_value += ((unsigned long)ADC << 7); // Add new ADC reading, scaled by 128
1986
+          raw_filwidth_value += ((unsigned long)HAL_READ_ADC << 7); // Add new ADC reading, scaled by 128
2003
         }
1987
         }
2004
       break;
1988
       break;
2005
     #endif
1989
     #endif
2130
     }
2114
     }
2131
   #endif
2115
   #endif
2132
 
2116
 
2133
-  cli();
2117
+  #if !defined(CPU_32_BIT)
2118
+    cli();
2119
+  #endif
2134
   in_temp_isr = false;
2120
   in_temp_isr = false;
2135
-  SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
2121
+  ENABLE_TEMPERATURE_INTERRUPT(); //re-enable Temperature ISR
2136
 }
2122
 }

+ 1
- 1
Marlin/temperature.h Переглянути файл

125
     #endif
125
     #endif
126
 
126
 
127
     #if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
127
     #if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
128
-      #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (F_CPU / 64.0 / 256.0))
128
+      #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
129
     #endif
129
     #endif
130
 
130
 
131
     #if ENABLED(PIDTEMP)
131
     #if ENABLED(PIDTEMP)

+ 1
- 1
Marlin/ubl_G29.cpp Переглянути файл

1371
         z_values[x][y] -= tmp_z_values[x][y];
1371
         z_values[x][y] -= tmp_z_values[x][y];
1372
   }
1372
   }
1373
 
1373
 
1374
-  mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], const bool far_flag) {
1374
+  mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, uint16_t bits[16], const bool far_flag) {
1375
     mesh_index_pair out_mesh;
1375
     mesh_index_pair out_mesh;
1376
     out_mesh.x_index = out_mesh.y_index = -1;
1376
     out_mesh.x_index = out_mesh.y_index = -1;
1377
 
1377
 

+ 0
- 2
Marlin/ubl_motion.cpp Переглянути файл

27
   #include "ubl.h"
27
   #include "ubl.h"
28
   #include "planner.h"
28
   #include "planner.h"
29
   #include "stepper.h"
29
   #include "stepper.h"
30
-  #include <avr/io.h>
31
   #include <math.h>
30
   #include <math.h>
32
 
31
 
33
   extern float destination[XYZE];
32
   extern float destination[XYZE];
737
   #endif // UBL_DELTA
736
   #endif // UBL_DELTA
738
 
737
 
739
 #endif // AUTO_BED_LEVELING_UBL
738
 #endif // AUTO_BED_LEVELING_UBL
740
-

+ 2
- 2
Marlin/ultralcd.cpp Переглянути файл

184
     void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
184
     void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
185
     typedef void _name##_void
185
     typedef void _name##_void
186
 
186
 
187
+  DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
187
   DECLARE_MENU_EDIT_TYPE(int16_t, int3);
188
   DECLARE_MENU_EDIT_TYPE(int16_t, int3);
188
   DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
189
   DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
189
   DECLARE_MENU_EDIT_TYPE(float, float3);
190
   DECLARE_MENU_EDIT_TYPE(float, float3);
193
   DECLARE_MENU_EDIT_TYPE(float, float51);
194
   DECLARE_MENU_EDIT_TYPE(float, float51);
194
   DECLARE_MENU_EDIT_TYPE(float, float52);
195
   DECLARE_MENU_EDIT_TYPE(float, float52);
195
   DECLARE_MENU_EDIT_TYPE(float, float62);
196
   DECLARE_MENU_EDIT_TYPE(float, float62);
196
-  DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
197
 
197
 
198
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
198
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
199
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
199
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
4039
     } \
4039
     } \
4040
     typedef void _name
4040
     typedef void _name
4041
 
4041
 
4042
+  DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
4042
   DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
4043
   DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
4043
   DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
4044
   DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
4044
   DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
4045
   DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
4048
   DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
4049
   DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
4049
   DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
4050
   DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
4050
   DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
4051
   DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
4051
-  DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
4052
 
4052
 
4053
   /**
4053
   /**
4054
    *
4054
    *

+ 1
- 1
Marlin/ultralcd_impl_DOGM.h Переглянути файл

869
     } \
869
     } \
870
     typedef void _name##_void
870
     typedef void _name##_void
871
 
871
 
872
+  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
872
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
873
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
873
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
874
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
874
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
875
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
878
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
879
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
879
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
880
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
880
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
881
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
881
-  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
882
 
882
 
883
   #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
883
   #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
884
   #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
884
   #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h Переглянути файл

976
     } \
976
     } \
977
     typedef void _name##_void
977
     typedef void _name##_void
978
 
978
 
979
+  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
979
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
980
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
980
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
981
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
981
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
982
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
985
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
986
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
986
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
987
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
987
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
988
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
988
-  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
989
 
989
 
990
   #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
990
   #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
991
   #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
991
   #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))

Завантаження…
Відмінити
Зберегти