Browse Source

HAL for 32-bit Teensy (3.5, 3.6) architecture

teemuatlut 7 years ago
parent
commit
f3e562e46e

+ 297
- 4
.travis.yml View File

@@ -3,6 +3,8 @@ sudo: true
3 3
   #
4 4
 language: c
5 5
   #
6
+dist: trusty
7
+sudo: required
6 8
 group: deprecated-2017Q2
7 9
 notifications:
8 10
   email: false
@@ -21,12 +23,17 @@ before_install:
21 23
   - sleep 3
22 24
   - export DISPLAY=:1.0
23 25
   #
26
+  # Teensy compiling
27
+  - lsb_release -a
28
+  - sudo apt-get -qq update
29
+  - sudo apt-get install -y binutils-arm-none-eabi gcc-arm-none-eabi lib32ncurses5 lib32z1
30
+  #
24 31
 install:
25 32
   #
26
-  # Install arduino 1.6.10
27
-  - wget http://downloads-02.arduino.cc/arduino-1.6.10-linux64.tar.xz
28
-  - tar xf arduino-1.6.10-linux64.tar.xz
29
-  - sudo mv arduino-1.6.10 /usr/local/share/arduino
33
+  # Install arduino 1.8.0
34
+  - wget http://downloads-02.arduino.cc/arduino-1.8.0-linux64.tar.xz
35
+  - tar xf arduino-1.8.0-linux64.tar.xz
36
+  - sudo mv arduino-1.8.0 /usr/local/share/arduino
30 37
   - ln -s /usr/local/share/arduino/arduino ${TRAVIS_BUILD_DIR}/buildroot/bin/arduino
31 38
   #
32 39
   # Install: LiquidCrystal_I2C library
@@ -57,6 +64,36 @@ install:
57 64
   - git clone https://github.com/adafruit/Adafruit_NeoPixel.git
58 65
   - sudo mv Adafruit_NeoPixel /usr/local/share/arduino/libraries/Adafruit_NeoPixel
59 66
   #
67
+  # Install Teensy stuff
68
+
69
+  - wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q2/gccarmnoneeabi542016q220160622linuxtar.bz2
70
+  - tar xf gccarmnoneeabi542016q220160622linuxtar.bz2
71
+  - sudo mkdir -p /usr/local/share/arduino/hardware/tools/arm
72
+  - sudo mv gcc-arm-none-eabi-5_4-2016q2/* /usr/local/share/arduino/hardware/tools/arm/
73
+
74
+  - wget https://github.com/ARM-software/CMSIS_5/raw/develop/CMSIS/Lib/ARM/arm_cortexM4lf_math.lib
75
+  - sudo mv arm_cortexM4lf_math.lib /usr/local/share/arduino/hardware/tools/arm/arm-none-eabi/lib/libarm_cortexM4lf_math.a
76
+
77
+  - git clone https://github.com/teemuatlut/teensyfiles_for_marlin.git
78
+  - sudo mkdir -p /usr/local/share/arduino/hardware/teensy/avr
79
+  - sudo cp teensyfiles_for_marlin/*.txt /usr/local/share/arduino/hardware/teensy/avr/
80
+
81
+  - git clone https://github.com/PaulStoffregen/cores.git
82
+  - sudo mv cores /usr/local/share/arduino/hardware/teensy/avr
83
+
84
+  # Teensy libraries
85
+
86
+  - git clone https://github.com/PaulStoffregen/Wire.git
87
+  - git clone https://github.com/PaulStoffregen/SPI.git
88
+  - git clone https://github.com/PaulStoffregen/Servo.git
89
+  - sudo mkdir -p /usr/local/share/arduino/hardware/teensy/avr/libraries/
90
+  - sudo mv Wire /usr/local/share/arduino/hardware/teensy/avr/libraries/
91
+  - sudo mv SPI /usr/local/share/arduino/hardware/teensy/avr/libraries/
92
+  - sudo mv Servo /usr/local/share/arduino/hardware/teensy/avr/libraries/
93
+
94
+  - mkdir -p /usr/local/share/arduino/hardware/tools/arm
95
+  - sudo ln -s /usr/bin /usr/local/share/arduino/hardware/tools/arm/bin
96
+  - sudo ln -s /usr/lib /usr/local/share/arduino/hardware/tools/arm/lib
60 97
 before_script:
61 98
   #
62 99
   # Change current working directory to the build dir
@@ -353,3 +390,259 @@ script:
353 390
   #
354 391
   # To be added in nightly test branch
355 392
   #
393
+  # Backup Configuration.h, Configuration_adv.h, and pins_RAMPS.h
394
+  #
395
+  - restore_configs
396
+  - opt_set MOTHERBOARD BOARD_TEENSY35_36
397
+  - cp Marlin/Configuration.h Marlin/Configuration.h.backup
398
+  - cp Marlin/Configuration_adv.h Marlin/Configuration_adv.h.backup
399
+  - cp Marlin/pins_RAMPS.h Marlin/pins_RAMPS.h.backup
400
+  #
401
+  # Test Teensy3.5 with default config
402
+  #
403
+  - build_marlin_teensy35
404
+  #
405
+  # Test heated bed temperature sensor
406
+  #
407
+  - opt_set TEMP_SENSOR_BED 1
408
+  - build_marlin_teensy35
409
+  #
410
+  # Test 2 extruders on basic RAMPS 1.4
411
+  #
412
+  - opt_set EXTRUDERS 2
413
+  - opt_set TEMP_SENSOR_1 1
414
+  - build_marlin_teensy35
415
+  #
416
+  # Test PIDTEMPBED
417
+  #
418
+  - restore_configs
419
+  - opt_enable PIDTEMPBED
420
+  - build_marlin_teensy35
421
+  #
422
+  # Test a "Fix Mounted" Probe along with Safe Homing
423
+  #
424
+  - restore_configs
425
+  - opt_enable FIX_MOUNTED_PROBE Z_SAFE_HOMING
426
+  - build_marlin_teensy35
427
+  #
428
+  # ...with AUTO_BED_LEVELING_LINEAR, Z_MIN_PROBE_REPEATABILITY_TEST, and DEBUG_LEVELING_FEATURE
429
+  #
430
+  - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE
431
+  - opt_set ABL_GRID_POINTS_X 16
432
+  - opt_set ABL_GRID_POINTS_Y 16
433
+  - build_marlin_teensy35
434
+  #
435
+  # Test a Sled Z Probe
436
+  #
437
+  - restore_configs
438
+  - opt_enable Z_PROBE_SLED
439
+  - build_marlin_teensy35
440
+  #
441
+  # ...with AUTO_BED_LEVELING_LINEAR, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, and EEPROM_CHITCHAT
442
+  #
443
+  - opt_enable AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
444
+  - build_marlin_teensy35
445
+  #
446
+  # Test a Servo Probe
447
+  #
448
+  - restore_configs
449
+  - opt_enable NUM_SERVOS Z_ENDSTOP_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE
450
+  - build_marlin_teensy35
451
+  #
452
+  # ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES
453
+  #
454
+  - opt_enable AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
455
+  - opt_enable_adv EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES
456
+  - build_marlin_teensy35
457
+  #
458
+  # Test MESH_BED_LEVELING feature, with LCD
459
+  #
460
+  - restore_configs
461
+  - opt_enable MESH_BED_LEVELING MESH_G28_REST_ORIGIN MANUAL_BED_LEVELING ULTIMAKERCONTROLLER
462
+  - build_marlin_teensy35
463
+  #
464
+  # Test EEPROM_SETTINGS, EEPROM_CHITCHAT, M100_FREE_MEMORY_WATCHER,
465
+  #   INCH_MODE_SUPPORT, TEMPERATURE_UNITS_SUPPORT
466
+  #
467
+  - restore_configs
468
+  # - opt_enable M100_FREE_MEMORY_WATCHER // Compiler error!
469
+  - opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT
470
+  - build_marlin_teensy35
471
+  #
472
+  # Mixing Extruder
473
+  #
474
+  - restore_configs
475
+  - opt_enable MIXING_EXTRUDER
476
+  - opt_set MIXING_STEPPERS 2
477
+  - build_marlin_teensy35
478
+  #
479
+  # Test DUAL_X_CARRIAGE
480
+  #
481
+  #- restore_configs
482
+  #- opt_set EXTRUDERS 2
483
+  #- opt_set TEMP_SENSOR_1 1
484
+  #- opt_enable USE_XMAX_PLUG
485
+  #- opt_enable_adv DUAL_X_CARRIAGE
486
+  #- build_marlin_teensy35
487
+  #
488
+  # Test SWITCHING_EXTRUDER
489
+  #
490
+  - restore_configs
491
+  - opt_set EXTRUDERS 2
492
+  - opt_enable NUM_SERVOS
493
+  - opt_set NUM_SERVOS 1
494
+  - opt_set TEMP_SENSOR_1 1
495
+  - opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER
496
+  - build_marlin_teensy35
497
+  #
498
+  # Test FILAMENT_CHANGE_FEATURE and LCD_INFO_MENU
499
+  #
500
+  - restore_configs
501
+  - opt_enable ULTIMAKERCONTROLLER
502
+  - opt_enable_adv FILAMENT_CHANGE_FEATURE LCD_INFO_MENU
503
+  - build_marlin_teensy35
504
+  #
505
+  # Enable filament sensor
506
+  #
507
+  - restore_configs
508
+  - opt_enable FILAMENT_WIDTH_SENSOR
509
+  - build_marlin_teensy35
510
+  #
511
+  # Enable filament sensor with LCD display
512
+  #
513
+  - opt_enable ULTIMAKERCONTROLLER FILAMENT_LCD_DISPLAY
514
+  - build_marlin_teensy35
515
+  #
516
+  # Enable BEZIER_CURVE_SUPPORT, EXPERIMENTAL_I2CBUS, and I2C_SLAVE_ADDRESS
517
+  #
518
+  - restore_configs
519
+  - opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS
520
+  - opt_set_adv I2C_SLAVE_ADDRESS 63
521
+  - build_marlin_teensy35
522
+  #
523
+  # Enable COREXY
524
+  #
525
+  - restore_configs
526
+  - opt_enable COREXY
527
+  - build_marlin_teensy35
528
+  #
529
+  # Enable COREXZ
530
+  #
531
+  - restore_configs
532
+  - opt_enable COREXZ
533
+  - build_marlin_teensy35
534
+  #
535
+  # Enable Z_DUAL_STEPPER_DRIVERS, Z_DUAL_ENDSTOPS
536
+  #
537
+  - restore_configs
538
+  - opt_enable_adv Z_DUAL_STEPPER_DRIVERS Z_DUAL_ENDSTOPS
539
+  - pins_set RAMPS X_MAX_PIN -1
540
+  - opt_set_adv Z2_MAX_PIN 2
541
+  - build_marlin_teensy35
542
+  #
543
+  # Test PRINTCOUNTER
544
+  #
545
+  - restore_configs
546
+  - opt_enable PRINTCOUNTER
547
+  - build_marlin_teensy35
548
+  #
549
+  # Test NOZZLE_PARK_FEATURE
550
+  #
551
+  - restore_configs
552
+  - opt_enable NOZZLE_PARK_FEATURE
553
+  - build_marlin_teensy35
554
+  #
555
+  # Test NOZZLE_CLEAN_FEATURE
556
+  #
557
+  - restore_configs
558
+  - opt_enable NOZZLE_CLEAN_FEATURE
559
+  - build_marlin_teensy35
560
+  #
561
+  #
562
+  ######## STANDARD LCD/PANELS ##############
563
+  #
564
+  # ULTRA_LCD
565
+  #
566
+  - restore_configs
567
+  - opt_enable ULTRA_LCD
568
+  - build_marlin_teensy35
569
+  #
570
+  # DOGLCD
571
+  #
572
+  - restore_configs
573
+  - opt_enable DOGLCD
574
+  - build_marlin_teensy35
575
+  #
576
+  # ULTIMAKERCONTROLLER
577
+  #
578
+  - restore_configs
579
+  - opt_enable ULTIMAKERCONTROLLER
580
+  - build_marlin_teensy35
581
+  #
582
+  # MAKRPANEL
583
+  # Needs to use Melzi and Sanguino hardware
584
+  #
585
+  #- restore_configs
586
+  #- opt_enable MAKRPANEL
587
+  #- build_marlin
588
+  #
589
+  # REPRAP_DISCOUNT_SMART_CONTROLLER, SDSUPPORT, and BABYSTEPPING
590
+  #
591
+  - restore_configs
592
+  - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT BABYSTEPPING
593
+  - build_marlin_teensy35
594
+  #
595
+  # G3D_PANEL
596
+  #
597
+  - restore_configs
598
+  - opt_enable G3D_PANEL SDSUPPORT
599
+  - build_marlin_teensy35
600
+  #
601
+  # REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
602
+  #
603
+  - restore_configs
604
+  - opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER SDSUPPORT
605
+  - build_marlin_teensy35
606
+  #
607
+  # REPRAPWORLD_KEYPAD
608
+  #
609
+  # Cant find configuration details to get it to compile
610
+  #- restore_configs
611
+  #- opt_enable ULTRA_LCD REPRAPWORLD_KEYPAD REPRAPWORLD_KEYPAD_MOVE_STEP
612
+  #- build_marlin
613
+  #
614
+  # RA_CONTROL_PANEL
615
+  #
616
+  - restore_configs
617
+  - opt_enable RA_CONTROL_PANEL
618
+  - build_marlin_teensy35
619
+  #
620
+  ######## I2C LCD/PANELS ##############
621
+  #
622
+  # !!!ATTENTION!!!
623
+  # Most I2C configurations are failing at the moment because they require
624
+  # a different Liquid Crystal library "LiquidTWI2".
625
+  #
626
+  # LCD_I2C_SAINSMART_YWROBOT
627
+  #
628
+  #- restore_configs
629
+  #- opt_enable LCD_I2C_SAINSMART_YWROBOT
630
+  #- build_marlin
631
+  #
632
+  # LCD_I2C_PANELOLU2
633
+  #
634
+  #- restore_configs
635
+  #- opt_enable LCD_I2C_PANELOLU2
636
+  #- build_marlin
637
+  #
638
+  # LCD_I2C_VIKI
639
+  #
640
+  #- restore_configs
641
+  #- opt_enable LCD_I2C_VIKI
642
+  #- build_marlin
643
+  #
644
+  # LCM1602
645
+  #
646
+  - restore_configs
647
+  - opt_enable LCM1602
648
+  - build_marlin_teensy35

+ 130
- 0
Marlin/pins_TEENSY35_36.h View File

@@ -0,0 +1,130 @@
1
+/****************************************************************************************
2
+* Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0) Breadboard pin assignments
3
+* Requires the Teensyduino software with Teensy 3.5 or Teensy 3.6 selected in Arduino IDE!
4
+* http://www.pjrc.com/teensy/teensyduino.html
5
+* 
6
+****************************************************************************************/
7
+#if MOTHERBOARD == 841 // BOARD_TEENSY35_36
8
+#define KNOWN_BOARD 1
9
+#define AT90USB 1286  // Disable MarlinSerial etc.
10
+
11
+#if !IS_32BIT_TEENSY
12
+  #error Oops!  Make sure you have 'Teensy 3.5' or 'Teensy 3.6' selected from the 'Tools -> Boards' menu.
13
+#endif
14
+
15
+#if IS_TEENSY35
16
+  #define BOARD_NAME "Teensy3.5"
17
+#elif IS_TEENSY36
18
+  #define BOARD_NAME "Teensy3.6"
19
+#endif
20
+
21
+#define LARGE_FLASH        true
22
+#define USBCON //1286  // Disable MarlinSerial etc.
23
+
24
+/* 
25
+teemuatlut plan for Teensy3.5 and Teensy3.6:
26
+
27
+                                                     USB
28
+                                          GND |-----#####-----| VIN 5V
29
+      X_STEP_PIN          MOSI1   RX1       0 |     #####     | Analog GND
30
+      X_DIR_PIN           MISO1   TX1       1 |               | 3.3V
31
+      Y_STEP_PIN                       PWM  2 | *NC     AREF* | 23  A9 PWM
32
+      Y_DIR_PIN           SCL2 CAN0TX  PWM  3 | *A26     A10* | 22  A8 PWM
33
+      Z_STEP_PIN          SDA2 CAN0RX  PWM  4 | *A25     A11* | 21  A7 PWM  CS0   MOSI1  RX1
34
+      Z_DIR_PIN           MISO1   TX1  PWM  5 | *GND * * 57   | 20  A6 PWM  CS0   SCK1        FILWIDTH_PIN
35
+      X_ENABLE_PIN                     PWM  6 | *GND * * 56   | 19  A5            SCL0        E0_STEP_PIN
36
+      Y_ENABLE_PIN  SCL0  MOSI0   RX3  PWM  7 |      * * 55   | 18  A4            SDA0        E0_DIR_PIN
37
+      Z_ENABLE_PIN  SDA0  MISO0   TX3  PWM  8 |      * * 54   | 17  A3            SDA0        E0_ENABLE_PIN
38
+                          CS0     RX2  PWM  9 |               | 16  A2            SCL0        TEMP_0_PIN
39
+                          CS0     TX2  PWM 10 |               | 15  A1      CS0               TEMP_BED_PIN
40
+      X_STOP_PIN          MOSI0            11 |               | 14  A0 PWM  CS0               TEMP_1_PIN
41
+      Y_STOP_PIN          MISO0            12 |               | 13 LED            SCK0        LED_PIN
42
+                                         3.3V |               | GND
43
+      Z_STOP_PIN                           24 |   40 * * 53   |    A22 DAC1
44
+AUX2                                       25 |   41 * * 52   |    A21 DAC0
45
+AUX2  FAN_PIN             SCL2    TX1      26 |   42 * * 51   | 39 A20      MISO0             SDSS
46
+AUX2  Z-PROBE PWR         SCK0    RX1      27 | *  *  *  *  * | 38 A19 PWM        SDA1
47
+AUX2  SOL1_PIN            MOSI0            28 |   43 * * 50   | 37 A18 PWM        SCL1
48
+D10   CONTROLLERFAN_PIN   CAN0TX       PWM 29 |   44 * * 49   | 36 A17 PWM
49
+D9    HEATER_0_PIN        CAN0RX       PWM 30 |   45 * * 48   | 35 A16 PWM                    E1_ENABLE_PIN
50
+D8    HEATER_BED_PIN      CS1     RX4  A12 31 |   46 * * 47   | 34 A15 PWM        SDA0  RX5   E1_DIR_PIN
51
+                          SCK1    TX4  A13 32 |__GND_*_*_3.3V_| 33 A14 PWM        SCL0  TX5   E1_STEP_PIN
52
+
53
+          Interior pins:
54
+                          LCD_PINS_RS             40 * * 53   SCK2
55
+                          LCD_PINS_ENABLE         41 * * 52   MOSI2
56
+                          LCD_PINS_D4             42 * * 51   MISO2
57
+                          LCD_PINS_D5     CS2     43 * * 50   A24
58
+                          LCD_PINS_D6     MOSI2   44 * * 49   A23
59
+                          LCD_PINS_D7     MISO2   45 * * 48   TX6   SDA0  BTN_ENC
60
+                          BTN_EN1         SCK2    46 * * 47   RX6   SCL0  BTN_EN2
61
+                                                 GND * * 3.3V
62
+
63
+*/
64
+
65
+#define X_STEP_PIN          22
66
+#define X_DIR_PIN           21
67
+#define X_ENABLE_PIN        39
68
+
69
+#define Y_STEP_PIN          19
70
+#define Y_DIR_PIN           18
71
+#define Y_ENABLE_PIN        20
72
+
73
+#define Z_STEP_PIN          38
74
+#define Z_DIR_PIN           37
75
+#define Z_ENABLE_PIN        17
76
+
77
+#define E0_STEP_PIN        31
78
+#define E0_DIR_PIN         30
79
+#define E0_ENABLE_PIN      32
80
+
81
+#define E1_STEP_PIN        33
82
+#define E1_DIR_PIN         34
83
+#define E1_ENABLE_PIN      35
84
+
85
+#define HEATER_0_PIN       30
86
+#define HEATER_1_PIN       36
87
+#define HEATER_2_PIN       -1
88
+#define HEATER_BED_PIN     31
89
+#define FAN_PIN             2
90
+
91
+#define X_STOP_PIN         24
92
+#define Y_STOP_PIN         26
93
+#define Z_STOP_PIN         28
94
+
95
+#define TEMP_0_PIN          2 // Extruder / Analog pin numbering: 2 => A2
96
+#define TEMP_BED_PIN        1 // Bed / Analog pin numbering
97
+#define TEMP_1_PIN          0
98
+#define TEMP_2_PIN         -1
99
+
100
+#define SDPOWER            -1
101
+#define SD_DETECT_PIN      -1
102
+#define SDSS               39 // 8
103
+#define LED_PIN            13
104
+#define PS_ON_PIN           1
105
+#define KILL_PIN           -1
106
+#define ALARM_PIN          -1
107
+
108
+#define FILWIDTH_PIN        6
109
+#define SOL1_PIN           28
110
+
111
+#ifndef SDSUPPORT
112
+// these pins are defined in the SD library if building with SD support
113
+  #define SCK_PIN          13
114
+  #define MISO_PIN         12
115
+  #define MOSI_PIN         11
116
+#endif
117
+
118
+#ifdef ULTRA_LCD
119
+  #define LCD_PINS_RS        40
120
+  #define LCD_PINS_ENABLE    41
121
+  #define LCD_PINS_D4        42
122
+  #define LCD_PINS_D5        43
123
+  #define LCD_PINS_D6        44
124
+  #define LCD_PINS_D7        45
125
+  #define BTN_EN1            46
126
+  #define BTN_EN2            47
127
+  #define BTN_ENC            48
128
+#endif
129
+
130
+#endif  // MOTHERBOARD == 841 (Teensy3.5 and Teensy3.6)

+ 28
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp View File

@@ -0,0 +1,28 @@
1
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2
+
3
+
4
+#include "HAL_Servo_Teensy.h"
5
+#include "../../../MarlinConfig.h"
6
+
7
+
8
+int8_t libServo::attach(int pin) {
9
+	if (this->servoIndex >= MAX_SERVOS) return -1;
10
+	return Servo::attach(pin);
11
+}
12
+
13
+int8_t libServo::attach(int pin, int min, int max) {
14
+	return Servo::attach(pin, min, max);
15
+}
16
+
17
+void libServo::move(int value) {
18
+  if (this->attach(0) >= 0) {
19
+    this->write(value);
20
+    delay(SERVO_DELAY);
21
+    #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
22
+      this->detach();
23
+    #endif
24
+  }
25
+}
26
+
27
+
28
+#endif

+ 18
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h View File

@@ -0,0 +1,18 @@
1
+#ifndef HAL_Servo_Teensy_h
2
+#define HAL_Servo_Teensy_h
3
+
4
+#include <Servo.h>
5
+
6
+// Inherit and expand on the official library
7
+class libServo : public Servo {
8
+	public:
9
+		int8_t attach(int pin);
10
+		int8_t attach(int pin, int min, int max);
11
+		void move(int value);
12
+	private:
13
+	   uint16_t min_ticks;
14
+	   uint16_t max_ticks;
15
+	   uint8_t servoIndex;               // index into the channel data for this servo
16
+};
17
+
18
+#endif

+ 119
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.cpp View File

@@ -0,0 +1,119 @@
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
+/**
23
+ * Description: HAL for Teensy35 (MK64FX512)
24
+ */
25
+
26
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
27
+
28
+#include "../HAL.h"
29
+
30
+#include <Wire.h>
31
+
32
+uint16_t HAL_adc_result;
33
+
34
+
35
+static const uint8_t pin2sc1a[] = {
36
+  5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
37
+  5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9
38
+  255, 255, 255, 255, 255, 255, 255, // 24-30 are digital only
39
+  14+128, 15+128, 17, 18, 4+128, 5+128, 6+128, 7+128, 17+128,  // 31-39 are A12-A20
40
+  255, 255, 255, 255, 255, 255, 255, 255, 255,  // 40-48 are digital only
41
+  10+128, 11+128, // 49-50 are A23-A24
42
+  255, 255, 255, 255, 255, 255, 255, // 51-57 are digital only
43
+  255, 255, 255, 255, 255, 255, // 58-63 (sd card pins) are digital only
44
+  3, 19+128, // 64-65 are A10-A11
45
+  23, 23+128,// 66-67 are A21-A22 (DAC pins)
46
+  1, 1+128,  // 68-69 are A25-A26 (unused USB host port on Teensy 3.5)
47
+  26,        // 70 is Temperature Sensor
48
+  18+128     // 71 is Vref
49
+};
50
+
51
+/*
52
+// disable interrupts
53
+void cli(void)
54
+{
55
+	noInterrupts();
56
+}
57
+
58
+// enable interrupts
59
+void sei(void)
60
+{
61
+	interrupts();
62
+}
63
+*/
64
+void HAL_adc_init() {
65
+  analog_init();
66
+  while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
67
+  NVIC_ENABLE_IRQ(IRQ_FTM1);
68
+}
69
+
70
+void HAL_clear_reset_source (void)
71
+{ }
72
+
73
+uint8_t HAL_get_reset_source (void)
74
+{
75
+  switch ( RCM_SRS0 )
76
+  {
77
+    case 128: return RST_POWER_ON; break;
78
+    case 64: return RST_EXTERNAL; break;
79
+    case 32: return RST_WATCHDOG; break;
80
+//  case 8: return RST_LOSS_OF_LOCK; break;
81
+//  case 4: return RST_LOSS_OF_CLOCK; break;
82
+//  case 2: return RST_LOW_VOLTAGE; break;
83
+    default:
84
+      return 0;
85
+  }
86
+}
87
+
88
+void _delay_ms (int delay_ms)
89
+{
90
+	delay (delay_ms);
91
+}
92
+
93
+extern "C" {
94
+  extern char __bss_end;
95
+  extern char __heap_start;
96
+  extern void* __brkval;
97
+
98
+  int freeMemory() {
99
+    int free_memory;
100
+    if ((int)__brkval == 0)
101
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
102
+    else
103
+      free_memory = ((int)&free_memory) - ((int)__brkval);
104
+    return free_memory;
105
+  }
106
+}
107
+
108
+void HAL_adc_start_conversion (uint8_t adc_pin)
109
+{
110
+	ADC0_SC1A = pin2sc1a[adc_pin];
111
+}
112
+
113
+uint16_t HAL_adc_get_result(void)
114
+{
115
+	return ADC0_RA;
116
+}
117
+
118
+#endif // __MK64FX512__ || __MK66FX1M0__
119
+

+ 149
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h View File

@@ -0,0 +1,149 @@
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
+ Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.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 Teensy 3.5 and Teensy 3.6
24
+ */
25
+
26
+
27
+#ifndef _HAL_TEENSY_H
28
+#define _HAL_TEENSY_H
29
+
30
+// --------------------------------------------------------------------------
31
+// Includes
32
+// --------------------------------------------------------------------------
33
+
34
+#include <stdint.h>
35
+
36
+#include "Arduino.h"
37
+
38
+#include "fastio_Teensy.h"
39
+#include "watchdog_Teensy.h"
40
+
41
+#include "HAL_timers_Teensy.h"
42
+
43
+// --------------------------------------------------------------------------
44
+// Defines
45
+// --------------------------------------------------------------------------
46
+
47
+#define MOTHERBOARD BOARD_TEENSY35_36
48
+
49
+#define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
50
+#define IS_TEENSY35 defined(__MK64FX512__)
51
+#define IS_TEENSY36 defined(__MK66FX1M0__)
52
+
53
+#if SERIAL_PORT == -1
54
+  #define MYSERIAL SerialUSB
55
+#elif SERIAL_PORT == 0
56
+  #define MYSERIAL Serial
57
+#elif SERIAL_PORT == 1
58
+  #define MYSERIAL Serial1
59
+#elif SERIAL_PORT == 2
60
+  #define MYSERIAL Serial2
61
+#elif SERIAL_PORT == 3
62
+  #define MYSERIAL Serial3
63
+#endif
64
+
65
+#define HAL_SERVO_LIB libServo
66
+
67
+//#define _BV(bit) 	(1 << (bit))
68
+
69
+#ifndef analogInputToDigitalPin
70
+  #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
71
+#endif
72
+
73
+#define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli();
74
+#define CRITICAL_SECTION_END    SREG = _sreg;
75
+
76
+
77
+// On AVR this is in math.h?
78
+#define square(x) ((x)*(x))
79
+
80
+#ifndef strncpy_P
81
+  #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
82
+#endif
83
+
84
+// Fix bug in pgm_read_ptr
85
+#undef pgm_read_ptr
86
+#define pgm_read_ptr(addr) (*(addr))
87
+#undef pgm_read_word
88
+#define pgm_read_word(addr) (*(addr))
89
+
90
+#define RST_POWER_ON   1
91
+#define RST_EXTERNAL   2
92
+#define RST_BROWN_OUT  4
93
+#define RST_WATCHDOG   8
94
+#define RST_JTAG       16
95
+#define RST_SOFTWARE   32
96
+#define RST_BACKUP     64
97
+
98
+/** clear reset reason */
99
+void HAL_clear_reset_source (void);
100
+
101
+/** reset reason */
102
+uint8_t HAL_get_reset_source (void);
103
+
104
+void _delay_ms(int delay);
105
+
106
+extern "C" {
107
+  int freeMemory(void);
108
+}
109
+
110
+// SPI: Extended functions which take a channel number (hardware SPI only)
111
+/** Write single byte to specified SPI channel */
112
+void spiSend(uint32_t chan, byte b);
113
+/** Write buffer to specified SPI channel */
114
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
115
+/** Read single byte from specified SPI channel */
116
+uint8_t spiRec(uint32_t chan);
117
+
118
+// ADC
119
+
120
+void HAL_adc_init();
121
+
122
+#define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
123
+#define HAL_READ_ADC        HAL_adc_get_result()
124
+
125
+#define HAL_ANALOG_SELECT(pin) NOOP;
126
+
127
+void HAL_adc_start_conversion (uint8_t adc_pin);
128
+
129
+uint16_t HAL_adc_get_result(void);
130
+
131
+/*
132
+uint16_t HAL_getAdcReading(uint8_t chan);
133
+
134
+void HAL_startAdcConversion(uint8_t chan);
135
+uint8_t HAL_pinToAdcChannel(int pin);
136
+
137
+uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
138
+//uint16_t HAL_getAdcSuperSample(uint8_t chan);
139
+
140
+void HAL_enable_AdcFreerun(void);
141
+//void HAL_disable_AdcFreerun(uint8_t chan);
142
+*/
143
+
144
+// --------------------------------------------------------------------------
145
+//
146
+// --------------------------------------------------------------------------
147
+
148
+#endif // _HAL_TEENSY_H
149
+

+ 107
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_pinsDebug_Teensy.h View File

@@ -0,0 +1,107 @@
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_TEENSY_H
24
+
25
+#define FTM0_CH0_PIN 22
26
+#define FTM0_CH1_PIN 23
27
+#define FTM0_CH2_PIN  9
28
+#define FTM0_CH3_PIN 10
29
+#define FTM0_CH4_PIN  6
30
+#define FTM0_CH5_PIN 20
31
+#define FTM0_CH6_PIN 21
32
+#define FTM0_CH7_PIN  5
33
+#define FTM1_CH0_PIN  3
34
+#define FTM1_CH1_PIN  4
35
+#define FTM2_CH0_PIN 29
36
+#define FTM2_CH1_PIN 30
37
+#define FTM3_CH0_PIN  2
38
+#define FTM3_CH1_PIN 14
39
+#define FTM3_CH2_PIN  7
40
+#define FTM3_CH3_PIN  8
41
+#define FTM3_CH4_PIN 35
42
+#define FTM3_CH5_PIN 36
43
+#define FTM3_CH6_PIN 37
44
+#define FTM3_CH7_PIN 38
45
+#if defined(__MK66FX1M0__) // Teensy3.6
46
+  #define TPM1_CH0_PIN 16
47
+  #define TPM1_CH1_PIN 17
48
+#endif
49
+
50
+#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && (P) <= analogInputToDigitalPin(9)) || ((P) >= analogInputToDigitalPin(12) && (P) <= analogInputToDigitalPin(20))
51
+
52
+void HAL_print_analog_pin(char buffer[], int8_t pin) {
53
+	if (pin <= 23)      sprintf(buffer, "(A%2d)  ", int(pin - 14));
54
+	else if (pin <= 39) sprintf(buffer, "(A%2d)  ", int(pin - 19));
55
+}
56
+
57
+void HAL_analog_pin_state(char buffer[], int8_t pin) {
58
+  if (pin <= 23)      sprintf(buffer, "Analog in =% 5d", analogRead(pin - 14));
59
+  else if (pin <= 39) sprintf(buffer, "Analog in =% 5d", analogRead(pin - 19));
60
+}
61
+
62
+#define PWM_PRINT(V) do{ sprintf(buffer, "PWM:  %4d", 22); SERIAL_ECHO(buffer); }while(0)
63
+#define FTM_CASE(N,Z) \
64
+  case FTM##N##_CH##Z##_PIN: \
65
+    if (FTM##N##_C##Z##V) { \
66
+      PWM_PRINT(FTM##N##_C##Z##V); \
67
+      return true; \
68
+    } else return false
69
+
70
+/**
71
+ * Print a pin's PWM status.
72
+ * Return true if it's currently a PWM pin.
73
+ */
74
+bool HAL_pwm_status(int8_t pin) {
75
+  char buffer[20];   // for the sprintf statements
76
+  switch(pin) {
77
+    FTM_CASE(0,0);
78
+    FTM_CASE(0,1);
79
+    FTM_CASE(0,2);
80
+    FTM_CASE(0,3);
81
+    FTM_CASE(0,4);
82
+    FTM_CASE(0,5);
83
+    FTM_CASE(0,6);
84
+    FTM_CASE(0,7);
85
+    FTM_CASE(1,0);
86
+    FTM_CASE(1,1);
87
+    FTM_CASE(2,0);
88
+    FTM_CASE(2,1);
89
+    FTM_CASE(3,0);
90
+    FTM_CASE(3,1);
91
+    FTM_CASE(3,2);
92
+    FTM_CASE(3,3);
93
+    FTM_CASE(3,4);
94
+    FTM_CASE(3,5);
95
+    FTM_CASE(3,6);
96
+    FTM_CASE(3,7);
97
+
98
+    case NOT_ON_TIMER:
99
+    default:
100
+      return false;
101
+  }
102
+  SERIAL_PROTOCOLPGM("  ");
103
+}
104
+
105
+static void HAL_pwm_details(uint8_t pin) { /* TODO */ }
106
+
107
+#endif

+ 104
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp View File

@@ -0,0 +1,104 @@
1
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2
+
3
+#include "../HAL.h"
4
+#include <SPI.h>
5
+#include <pins_arduino.h>
6
+#include "spi_pins.h"
7
+#include "../../../macros.h"
8
+
9
+static SPISettings spiConfig;
10
+
11
+// Standard SPI functions
12
+/** Initialise SPI bus */
13
+void spiBegin(void) {
14
+  #ifndef SS_PIN
15
+    #error SS_PIN not defined!
16
+  #endif
17
+  SET_OUTPUT(SS_PIN);
18
+  WRITE(SS_PIN, HIGH);
19
+  SET_OUTPUT(SCK_PIN);
20
+  SET_INPUT(MISO_PIN);
21
+  SET_OUTPUT(MOSI_PIN);
22
+
23
+  //#if DISABLED(SOFTWARE_SPI)
24
+  #if false
25
+    // set SS high - may be chip select for another SPI device
26
+    #if SET_SPI_SS_HIGH
27
+      WRITE(SS_PIN, HIGH);
28
+    #endif  // SET_SPI_SS_HIGH
29
+    // set a default rate
30
+    spiInit(SPI_HALF_SPEED); // 1
31
+  #endif  // SOFTWARE_SPI
32
+}
33
+
34
+/** Configure SPI for specified SPI speed */
35
+void spiInit(uint8_t spiRate) {
36
+	// Use datarates Marlin uses
37
+	uint32_t clock;
38
+	switch (spiRate) {
39
+  case SPI_FULL_SPEED:		clock = 10000000;	break;
40
+  case SPI_HALF_SPEED:		clock =  5000000;	break;
41
+  case SPI_QUARTER_SPEED:	clock =  2500000;	break;
42
+  case SPI_EIGHTH_SPEED:	clock =  1250000;	break;
43
+  case SPI_SPEED_5:				clock =   625000;	break;
44
+  case SPI_SPEED_6:				clock =   312500;	break;
45
+  default:
46
+		clock = 4000000; // Default from the SPI libarary
47
+	}
48
+	spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
49
+	SPI.begin();
50
+}
51
+
52
+//------------------------------------------------------------------------------
53
+/** SPI receive a byte */
54
+uint8_t spiRec(void) {
55
+  SPI.beginTransaction(spiConfig);
56
+  uint8_t returnByte = SPI.transfer(0xFF);
57
+  SPI.endTransaction();
58
+  return returnByte;
59
+//  SPDR = 0XFF;
60
+//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
61
+//  return SPDR;
62
+}
63
+//------------------------------------------------------------------------------
64
+/** SPI read data  */
65
+void spiRead(uint8_t* buf, uint16_t nbyte) {
66
+  SPI.beginTransaction(spiConfig);
67
+  SPI.transfer(buf, nbyte);
68
+  SPI.endTransaction();
69
+//if (nbyte-- == 0) return;
70
+//  SPDR = 0XFF;
71
+//for (uint16_t i = 0; i < nbyte; i++) {
72
+//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
73
+//  buf[i] = SPDR;
74
+//  SPDR = 0XFF;
75
+//}
76
+//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
77
+//buf[nbyte] = SPDR;
78
+}
79
+//------------------------------------------------------------------------------
80
+/** SPI send a byte */
81
+void spiSend(uint8_t b) {
82
+  SPI.beginTransaction(spiConfig);
83
+  SPI.transfer(b);
84
+  SPI.endTransaction();
85
+//  SPDR = b;
86
+//  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
87
+}
88
+//------------------------------------------------------------------------------
89
+/** SPI send block  */
90
+void spiSendBlock(uint8_t token, const uint8_t* buf) {
91
+  SPI.beginTransaction(spiConfig);
92
+  SPDR = token;
93
+  for (uint16_t i = 0; i < 512; i += 2) {
94
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
95
+    SPDR = buf[i];
96
+    while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
97
+    SPDR = buf[i + 1];
98
+  }
99
+  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
100
+  SPI.endTransaction();
101
+}
102
+
103
+
104
+#endif

+ 95
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp View File

@@ -0,0 +1,95 @@
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
+/**
23
+ * Teensy3.5 __MK64FX512__
24
+ * Teensy3.6 __MK66FX1M0__
25
+ */
26
+
27
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
28
+
29
+#include "../HAL.h"
30
+#include "HAL_timers_Teensy.h"
31
+
32
+
33
+void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
34
+  switch (timer_num) {
35
+  case 0:
36
+    FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
37
+    FTM0_SC = 0x00; // Set this to zero before changing the modulus
38
+    FTM0_CNT = 0x0000; // Reset the count to zero
39
+    FTM0_MOD = 0xFFFF; // max modulus = 65535
40
+    FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
41
+    FTM0_SC = (FTM_SC_CLKS(0b1)&FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS)&FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
42
+    FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
43
+    break;
44
+  case 1:
45
+    FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
46
+    FTM1_SC = 0x00; // Set this to zero before changing the modulus
47
+    FTM1_CNT = 0x0000; // Reset the count to zero
48
+    FTM1_MOD = 0xFFFF; // max modulus = 65535
49
+    FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
50
+    FTM1_SC = (FTM_SC_CLKS(0b1)&FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS)&FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
51
+    FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
52
+    break;
53
+  default:
54
+    break;
55
+  }
56
+}
57
+
58
+void HAL_timer_enable_interrupt (uint8_t timer_num)
59
+{
60
+  switch(timer_num) {
61
+  case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
62
+  case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
63
+  default:
64
+    break;
65
+  }
66
+}
67
+
68
+void HAL_timer_disable_interrupt (uint8_t timer_num)
69
+{
70
+  switch (timer_num) {
71
+  case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
72
+  case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
73
+  default:
74
+    break;
75
+  }
76
+}
77
+
78
+void HAL_timer_isr_prologue(uint8_t timer_num) {
79
+  switch(timer_num) {
80
+  case 0:
81
+    FTM0_CNT = 0x0000;
82
+    FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
83
+    FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
84
+    break;
85
+  case 1:
86
+    FTM1_CNT = 0x0000;
87
+    FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
88
+    FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
89
+    break;
90
+  default:
91
+    break;
92
+  }
93
+}
94
+
95
+#endif // Teensy3.5 or Teensy3.6

+ 109
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

@@ -0,0 +1,109 @@
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
+ Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.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
24
+ * Teensy3.5 (__MK64FX512__)
25
+ * Teensy3.6 (__MK66FX1M0__)
26
+ */
27
+
28
+
29
+#ifndef _HAL_TIMERS_TEENSY_H
30
+#define _HAL_TIMERS_TEENSY_H
31
+
32
+// --------------------------------------------------------------------------
33
+// Includes
34
+// --------------------------------------------------------------------------
35
+
36
+#include <stdint.h>
37
+
38
+// --------------------------------------------------------------------------
39
+// Defines
40
+// --------------------------------------------------------------------------
41
+
42
+#define FORCE_INLINE __attribute__((always_inline)) inline
43
+
44
+#define HAL_TIMER_TYPE uint32_t
45
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
46
+
47
+#define STEP_TIMER_NUM 0
48
+#define TEMP_TIMER_NUM 1
49
+
50
+#define FTM0_TIMER_PRESCALE 8
51
+#define FTM1_TIMER_PRESCALE 4
52
+#define FTM0_TIMER_PRESCALE_BITS 0b011
53
+#define FTM1_TIMER_PRESCALE_BITS 0b010
54
+
55
+#define FTM0_TIMER_RATE F_BUS/FTM0_TIMER_PRESCALE // 60MHz / 8 = 7500kHz
56
+#define FTM1_TIMER_RATE F_BUS/FTM1_TIMER_PRESCALE // 60MHz / 4 = 15MHz
57
+
58
+#define STEPPER_TIMER STEP_TIMER_NUM // Alias?
59
+#define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
60
+
61
+#define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
62
+#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
63
+#define HAL_TICKS_PER_US       (HAL_STEPPER_TIMER_RATE/1000000)
64
+
65
+#define TEMP_TIMER_FREQUENCY   1000
66
+
67
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
68
+#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt (STEP_TIMER_NUM)
69
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
70
+#define DISABLE_TEMPERATURE_INTERRUPT()  HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
71
+
72
+#define HAL_STEP_TIMER_ISR  extern "C" void ftm0_isr(void) //void TC3_Handler()
73
+#define HAL_TEMP_TIMER_ISR  extern "C" void ftm1_isr(void) //void TC4_Handler()
74
+
75
+#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
76
+
77
+void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
78
+
79
+static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
80
+  switch(timer_num) {
81
+  case 0: FTM0_C0V = count; break;
82
+  case 1: FTM1_C0V = count; break;
83
+  default: break;
84
+  }
85
+}
86
+
87
+static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
88
+  switch(timer_num) {
89
+  case 0: return FTM0_C0V;
90
+  case 1: return FTM1_C0V;
91
+  default: return 0;
92
+  }
93
+}
94
+
95
+static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) {
96
+  switch(timer_num) {
97
+  case 0: return FTM0_CNT;
98
+  case 1: return FTM1_CNT;
99
+  default: return 0;
100
+  }
101
+}
102
+
103
+void HAL_timer_enable_interrupt (uint8_t timer_num);
104
+void HAL_timer_disable_interrupt (uint8_t timer_num);
105
+
106
+void HAL_timer_isr_prologue(uint8_t timer_num);
107
+
108
+#endif // _HAL_TIMERS_TEENSY_H
109
+

+ 84
- 0
Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h View File

@@ -0,0 +1,84 @@
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
+ * Endstop Interrupts
25
+ *
26
+ * Without endstop interrupts the endstop pins must be polled continually in
27
+ * the stepper-ISR via endstops.update(), most of the time finding no change.
28
+ * With this feature endstops.update() is called only when we know that at
29
+ * least one endstop has changed state, saving valuable CPU cycles.
30
+ *
31
+ * This feature only works when all used endstop pins can generate an 'external interrupt'.
32
+ *
33
+ * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
34
+ * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
35
+ */
36
+
37
+ #ifndef _ENDSTOP_INTERRUPTS_H_
38
+ #define _ENDSTOP_INTERRUPTS_H_
39
+
40
+/**
41
+ *  Endstop interrupts for Due based targets.
42
+ *  On Due, all pins support external interrupt capability.
43
+ */
44
+
45
+void setup_endstop_interrupts( void ) {
46
+
47
+  #if HAS_X_MAX
48
+    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
49
+  #endif
50
+
51
+  #if HAS_X_MIN
52
+    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
53
+  #endif
54
+
55
+  #if HAS_Y_MAX
56
+    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
57
+  #endif
58
+
59
+  #if HAS_Y_MIN
60
+    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
61
+  #endif
62
+
63
+  #if HAS_Z_MAX
64
+    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
65
+  #endif
66
+
67
+  #if HAS_Z_MIN
68
+     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
69
+  #endif
70
+
71
+  #if HAS_Z2_MAX
72
+    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
73
+  #endif
74
+
75
+  #if HAS_Z2_MIN
76
+    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
77
+  #endif
78
+
79
+  #if HAS_Z_MIN_PROBE_PIN
80
+    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
81
+  #endif
82
+}
83
+
84
+#endif //_ENDSTOP_INTERRUPTS_H_

+ 120
- 0
Marlin/src/HAL/HAL_TEENSY35_36/fastio_Teensy.h View File

@@ -0,0 +1,120 @@
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
+  This code contributed by Triffid_Hunter and modified by Kliment
25
+  why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
26
+*/
27
+
28
+/**
29
+ * Description: Fast IO functions for Teensy 3.5 and Teensy 3.6
30
+ */
31
+
32
+#ifndef	_FASTIO_TEENSY_H
33
+#define	_FASTIO_TEENSY_H
34
+
35
+/**
36
+  utility functions
37
+*/
38
+
39
+#ifndef MASK
40
+  #define MASK(PIN)  (1 << PIN)
41
+#endif
42
+
43
+#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
44
+#define GPIO_BITBAND(reg, bit) (*(uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
45
+
46
+/**
47
+  magic I/O routines
48
+  now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0);
49
+*/
50
+
51
+/// Read a pin
52
+#define _READ(p) ((bool)(CORE_PIN ## p ## _PINREG & CORE_PIN ## p ## _BITMASK))
53
+
54
+/// Write to a pin
55
+#define _WRITE(p, v) do { if (v) CORE_PIN ## p ## _PORTSET = CORE_PIN ## p ## _BITMASK; \
56
+                            else CORE_PIN ## p ## _PORTCLEAR = CORE_PIN ## p ## _BITMASK; } while (0)
57
+
58
+/// toggle a pin
59
+#define _TOGGLE(p)  (*(&(CORE_PIN ## p ## _PORTCLEAR)+1) = CORE_PIN ## p ## _BITMASK)
60
+
61
+/// set pin as input
62
+  #define _SET_INPUT(p)   do { CORE_PIN ## p ## _CONFIG = PORT_PCR_MUX(1); \
63
+                            GPIO_BITBAND(CORE_PIN ## p ## _DDRREG , CORE_PIN ## p ## _BIT) = 0; \
64
+                            } while (0)
65
+/// set pin as output
66
+  #define _SET_OUTPUT(p)  do { CORE_PIN ## p ## _CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE|PORT_PCR_DSE; \
67
+                            GPIO_BITBAND(CORE_PIN ## p ## _DDRREG , CORE_PIN ## p ## _BIT) = 1; \
68
+                            } while (0)
69
+
70
+/// set pin as input with pullup mode
71
+//#define _PULLUP(IO, v)  { pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)); }
72
+
73
+/// check if pin is an input
74
+#define _GET_INPUT(p)   ((CORE_PIN ## p ## _DDRREG & CORE_PIN ## p ## _BITMASK) == 0)
75
+/// check if pin is an output
76
+#define _GET_OUTPUT(p)  ((CORE_PIN ## p ## _DDRREG & CORE_PIN ## p ## _BITMASK) == 0)
77
+
78
+/// check if pin is an timer
79
+//#define _GET_TIMER(IO)
80
+
81
+//  why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
82
+
83
+/// Read a pin wrapper
84
+#define READ(IO)  _READ(IO)
85
+
86
+/// Write to a pin wrapper
87
+#define WRITE_VAR(IO, v)  _WRITE_VAR(IO, v)
88
+#define WRITE(IO, v)  _WRITE(IO, v)
89
+
90
+/// toggle a pin wrapper
91
+#define TOGGLE(IO)  _TOGGLE(IO)
92
+
93
+/// set pin as input wrapper
94
+#define SET_INPUT(IO)  _SET_INPUT(IO)
95
+/// set pin as input with pullup wrapper
96
+#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _WRITE(IO, HIGH); }while(0)
97
+/// set pin as output wrapper
98
+#define SET_OUTPUT(IO)  _SET_OUTPUT(IO)
99
+
100
+/// check if pin is an input wrapper
101
+#define GET_INPUT(IO)  _GET_INPUT(IO)
102
+/// check if pin is an output wrapper
103
+#define GET_OUTPUT(IO)  _GET_OUTPUT(IO)
104
+
105
+// Shorthand
106
+#define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
107
+
108
+/**
109
+  ports and functions
110
+
111
+  added as necessary or if I feel like it- not a comprehensive list!
112
+*/
113
+
114
+/**
115
+pins
116
+*/
117
+
118
+#define DIO0_PIN 8
119
+
120
+#endif	/* _FASTIO_TEENSY_H */

+ 57
- 0
Marlin/src/HAL/HAL_TEENSY35_36/persistent_store.cpp View File

@@ -0,0 +1,57 @@
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
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
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

+ 28
- 0
Marlin/src/HAL/HAL_TEENSY35_36/spi_pins.h View File

@@ -0,0 +1,28 @@
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
+#define SCK_PIN		13
24
+#define MISO_PIN	12
25
+#define MOSI_PIN	11
26
+#define SS_PIN		20 //SDSS // A.28, A.29, B.21, C.26, C.29
27
+
28
+#endif /* SPI_PINS_H_ */

+ 39
- 0
Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp View File

@@ -0,0 +1,39 @@
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
+#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
24
+ 
25
+  #include "../../../Marlin.h"
26
+
27
+  #if ENABLED(USE_WATCHDOG)
28
+
29
+    #include "watchdog_Teensy.h"
30
+
31
+    void watchdog_init() {
32
+      WDOG_TOVALH = 0;
33
+      WDOG_TOVALL = 4000;
34
+      WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
35
+    }
36
+
37
+  #endif //USE_WATCHDOG
38
+
39
+#endif

+ 38
- 0
Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h View File

@@ -0,0 +1,38 @@
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 WATCHDOG_TEENSY_H
24
+#define WATCHDOG_TEENSY_H
25
+
26
+//#include "../../../Marlin.h"
27
+
28
+// Arduino Due core now has watchdog support
29
+
30
+void watchdog_init();
31
+
32
+inline void watchdog_reset() {
33
+	// Watchdog refresh sequence
34
+	WDOG_REFRESH = 0xA602;
35
+	WDOG_REFRESH = 0xB480;
36
+}
37
+
38
+#endif /* WATCHDOG_TEENSY_H */

+ 3
- 0
buildroot/bin/build_marlin_teensy35 View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env bash
2
+
3
+arduino --verify --board teensy:avr:teensy35:usb=serial,speed=120,opt=o1std,keys=en-us Marlin/Marlin.ino

+ 7
- 0
platformio.ini View File

@@ -87,3 +87,10 @@ framework = arduino
87 87
 board = due
88 88
 build_flags = -I $BUILDSRC_DIR
89 89
 lib_deps = ${common.lib_deps}
90
+
91
+[env:teensy35]
92
+platform = teensy
93
+framework = arduino
94
+board = teensy35
95
+build_flags = -I $BUILDSRC_DIR
96
+lib_deps = ${common.lib_deps}

Loading…
Cancel
Save