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

This commit is contained in:
teemuatlut 2017-07-11 21:59:27 +01:00 committed by Scott Lahteine
parent cfef925559
commit f3e562e46e
18 changed files with 1532 additions and 4 deletions

View File

@ -3,6 +3,8 @@ sudo: true
# #
language: c language: c
# #
dist: trusty
sudo: required
group: deprecated-2017Q2 group: deprecated-2017Q2
notifications: notifications:
email: false email: false
@ -21,12 +23,17 @@ before_install:
- sleep 3 - sleep 3
- export DISPLAY=:1.0 - export DISPLAY=:1.0
# #
# Teensy compiling
- lsb_release -a
- sudo apt-get -qq update
- sudo apt-get install -y binutils-arm-none-eabi gcc-arm-none-eabi lib32ncurses5 lib32z1
#
install: install:
# #
# Install arduino 1.6.10 # Install arduino 1.8.0
- wget http://downloads-02.arduino.cc/arduino-1.6.10-linux64.tar.xz - wget http://downloads-02.arduino.cc/arduino-1.8.0-linux64.tar.xz
- tar xf arduino-1.6.10-linux64.tar.xz - tar xf arduino-1.8.0-linux64.tar.xz
- sudo mv arduino-1.6.10 /usr/local/share/arduino - sudo mv arduino-1.8.0 /usr/local/share/arduino
- ln -s /usr/local/share/arduino/arduino ${TRAVIS_BUILD_DIR}/buildroot/bin/arduino - ln -s /usr/local/share/arduino/arduino ${TRAVIS_BUILD_DIR}/buildroot/bin/arduino
# #
# Install: LiquidCrystal_I2C library # Install: LiquidCrystal_I2C library
@ -57,6 +64,36 @@ install:
- git clone https://github.com/adafruit/Adafruit_NeoPixel.git - git clone https://github.com/adafruit/Adafruit_NeoPixel.git
- sudo mv Adafruit_NeoPixel /usr/local/share/arduino/libraries/Adafruit_NeoPixel - sudo mv Adafruit_NeoPixel /usr/local/share/arduino/libraries/Adafruit_NeoPixel
# #
# Install Teensy stuff
- wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q2/gccarmnoneeabi542016q220160622linuxtar.bz2
- tar xf gccarmnoneeabi542016q220160622linuxtar.bz2
- sudo mkdir -p /usr/local/share/arduino/hardware/tools/arm
- sudo mv gcc-arm-none-eabi-5_4-2016q2/* /usr/local/share/arduino/hardware/tools/arm/
- wget https://github.com/ARM-software/CMSIS_5/raw/develop/CMSIS/Lib/ARM/arm_cortexM4lf_math.lib
- sudo mv arm_cortexM4lf_math.lib /usr/local/share/arduino/hardware/tools/arm/arm-none-eabi/lib/libarm_cortexM4lf_math.a
- git clone https://github.com/teemuatlut/teensyfiles_for_marlin.git
- sudo mkdir -p /usr/local/share/arduino/hardware/teensy/avr
- sudo cp teensyfiles_for_marlin/*.txt /usr/local/share/arduino/hardware/teensy/avr/
- git clone https://github.com/PaulStoffregen/cores.git
- sudo mv cores /usr/local/share/arduino/hardware/teensy/avr
# Teensy libraries
- git clone https://github.com/PaulStoffregen/Wire.git
- git clone https://github.com/PaulStoffregen/SPI.git
- git clone https://github.com/PaulStoffregen/Servo.git
- sudo mkdir -p /usr/local/share/arduino/hardware/teensy/avr/libraries/
- sudo mv Wire /usr/local/share/arduino/hardware/teensy/avr/libraries/
- sudo mv SPI /usr/local/share/arduino/hardware/teensy/avr/libraries/
- sudo mv Servo /usr/local/share/arduino/hardware/teensy/avr/libraries/
- mkdir -p /usr/local/share/arduino/hardware/tools/arm
- sudo ln -s /usr/bin /usr/local/share/arduino/hardware/tools/arm/bin
- sudo ln -s /usr/lib /usr/local/share/arduino/hardware/tools/arm/lib
before_script: before_script:
# #
# Change current working directory to the build dir # Change current working directory to the build dir
@ -353,3 +390,259 @@ script:
# #
# To be added in nightly test branch # To be added in nightly test branch
# #
# Backup Configuration.h, Configuration_adv.h, and pins_RAMPS.h
#
- restore_configs
- opt_set MOTHERBOARD BOARD_TEENSY35_36
- cp Marlin/Configuration.h Marlin/Configuration.h.backup
- cp Marlin/Configuration_adv.h Marlin/Configuration_adv.h.backup
- cp Marlin/pins_RAMPS.h Marlin/pins_RAMPS.h.backup
#
# Test Teensy3.5 with default config
#
- build_marlin_teensy35
#
# Test heated bed temperature sensor
#
- opt_set TEMP_SENSOR_BED 1
- build_marlin_teensy35
#
# Test 2 extruders on basic RAMPS 1.4
#
- opt_set EXTRUDERS 2
- opt_set TEMP_SENSOR_1 1
- build_marlin_teensy35
#
# Test PIDTEMPBED
#
- restore_configs
- opt_enable PIDTEMPBED
- build_marlin_teensy35
#
# Test a "Fix Mounted" Probe along with Safe Homing
#
- restore_configs
- opt_enable FIX_MOUNTED_PROBE Z_SAFE_HOMING
- build_marlin_teensy35
#
# ...with AUTO_BED_LEVELING_LINEAR, Z_MIN_PROBE_REPEATABILITY_TEST, and DEBUG_LEVELING_FEATURE
#
- opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE
- opt_set ABL_GRID_POINTS_X 16
- opt_set ABL_GRID_POINTS_Y 16
- build_marlin_teensy35
#
# Test a Sled Z Probe
#
- restore_configs
- opt_enable Z_PROBE_SLED
- build_marlin_teensy35
#
# ...with AUTO_BED_LEVELING_LINEAR, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, and EEPROM_CHITCHAT
#
- opt_enable AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
- build_marlin_teensy35
#
# Test a Servo Probe
#
- restore_configs
- opt_enable NUM_SERVOS Z_ENDSTOP_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE
- build_marlin_teensy35
#
# ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES
#
- opt_enable AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
- opt_enable_adv EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES
- build_marlin_teensy35
#
# Test MESH_BED_LEVELING feature, with LCD
#
- restore_configs
- opt_enable MESH_BED_LEVELING MESH_G28_REST_ORIGIN MANUAL_BED_LEVELING ULTIMAKERCONTROLLER
- build_marlin_teensy35
#
# Test EEPROM_SETTINGS, EEPROM_CHITCHAT, M100_FREE_MEMORY_WATCHER,
# INCH_MODE_SUPPORT, TEMPERATURE_UNITS_SUPPORT
#
- restore_configs
# - opt_enable M100_FREE_MEMORY_WATCHER // Compiler error!
- opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT
- build_marlin_teensy35
#
# Mixing Extruder
#
- restore_configs
- opt_enable MIXING_EXTRUDER
- opt_set MIXING_STEPPERS 2
- build_marlin_teensy35
#
# Test DUAL_X_CARRIAGE
#
#- restore_configs
#- opt_set EXTRUDERS 2
#- opt_set TEMP_SENSOR_1 1
#- opt_enable USE_XMAX_PLUG
#- opt_enable_adv DUAL_X_CARRIAGE
#- build_marlin_teensy35
#
# Test SWITCHING_EXTRUDER
#
- restore_configs
- opt_set EXTRUDERS 2
- opt_enable NUM_SERVOS
- opt_set NUM_SERVOS 1
- opt_set TEMP_SENSOR_1 1
- opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER
- build_marlin_teensy35
#
# Test FILAMENT_CHANGE_FEATURE and LCD_INFO_MENU
#
- restore_configs
- opt_enable ULTIMAKERCONTROLLER
- opt_enable_adv FILAMENT_CHANGE_FEATURE LCD_INFO_MENU
- build_marlin_teensy35
#
# Enable filament sensor
#
- restore_configs
- opt_enable FILAMENT_WIDTH_SENSOR
- build_marlin_teensy35
#
# Enable filament sensor with LCD display
#
- opt_enable ULTIMAKERCONTROLLER FILAMENT_LCD_DISPLAY
- build_marlin_teensy35
#
# Enable BEZIER_CURVE_SUPPORT, EXPERIMENTAL_I2CBUS, and I2C_SLAVE_ADDRESS
#
- restore_configs
- opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS
- opt_set_adv I2C_SLAVE_ADDRESS 63
- build_marlin_teensy35
#
# Enable COREXY
#
- restore_configs
- opt_enable COREXY
- build_marlin_teensy35
#
# Enable COREXZ
#
- restore_configs
- opt_enable COREXZ
- build_marlin_teensy35
#
# Enable Z_DUAL_STEPPER_DRIVERS, Z_DUAL_ENDSTOPS
#
- restore_configs
- opt_enable_adv Z_DUAL_STEPPER_DRIVERS Z_DUAL_ENDSTOPS
- pins_set RAMPS X_MAX_PIN -1
- opt_set_adv Z2_MAX_PIN 2
- build_marlin_teensy35
#
# Test PRINTCOUNTER
#
- restore_configs
- opt_enable PRINTCOUNTER
- build_marlin_teensy35
#
# Test NOZZLE_PARK_FEATURE
#
- restore_configs
- opt_enable NOZZLE_PARK_FEATURE
- build_marlin_teensy35
#
# Test NOZZLE_CLEAN_FEATURE
#
- restore_configs
- opt_enable NOZZLE_CLEAN_FEATURE
- build_marlin_teensy35
#
#
######## STANDARD LCD/PANELS ##############
#
# ULTRA_LCD
#
- restore_configs
- opt_enable ULTRA_LCD
- build_marlin_teensy35
#
# DOGLCD
#
- restore_configs
- opt_enable DOGLCD
- build_marlin_teensy35
#
# ULTIMAKERCONTROLLER
#
- restore_configs
- opt_enable ULTIMAKERCONTROLLER
- build_marlin_teensy35
#
# MAKRPANEL
# Needs to use Melzi and Sanguino hardware
#
#- restore_configs
#- opt_enable MAKRPANEL
#- build_marlin
#
# REPRAP_DISCOUNT_SMART_CONTROLLER, SDSUPPORT, and BABYSTEPPING
#
- restore_configs
- opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT BABYSTEPPING
- build_marlin_teensy35
#
# G3D_PANEL
#
- restore_configs
- opt_enable G3D_PANEL SDSUPPORT
- build_marlin_teensy35
#
# REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
#
- restore_configs
- opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER SDSUPPORT
- build_marlin_teensy35
#
# REPRAPWORLD_KEYPAD
#
# Cant find configuration details to get it to compile
#- restore_configs
#- opt_enable ULTRA_LCD REPRAPWORLD_KEYPAD REPRAPWORLD_KEYPAD_MOVE_STEP
#- build_marlin
#
# RA_CONTROL_PANEL
#
- restore_configs
- opt_enable RA_CONTROL_PANEL
- build_marlin_teensy35
#
######## I2C LCD/PANELS ##############
#
# !!!ATTENTION!!!
# Most I2C configurations are failing at the moment because they require
# a different Liquid Crystal library "LiquidTWI2".
#
# LCD_I2C_SAINSMART_YWROBOT
#
#- restore_configs
#- opt_enable LCD_I2C_SAINSMART_YWROBOT
#- build_marlin
#
# LCD_I2C_PANELOLU2
#
#- restore_configs
#- opt_enable LCD_I2C_PANELOLU2
#- build_marlin
#
# LCD_I2C_VIKI
#
#- restore_configs
#- opt_enable LCD_I2C_VIKI
#- build_marlin
#
# LCM1602
#
- restore_configs
- opt_enable LCM1602
- build_marlin_teensy35

130
Marlin/pins_TEENSY35_36.h Normal file
View File

@ -0,0 +1,130 @@
/****************************************************************************************
* Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0) Breadboard pin assignments
* Requires the Teensyduino software with Teensy 3.5 or Teensy 3.6 selected in Arduino IDE!
* http://www.pjrc.com/teensy/teensyduino.html
*
****************************************************************************************/
#if MOTHERBOARD == 841 // BOARD_TEENSY35_36
#define KNOWN_BOARD 1
#define AT90USB 1286 // Disable MarlinSerial etc.
#if !IS_32BIT_TEENSY
#error Oops! Make sure you have 'Teensy 3.5' or 'Teensy 3.6' selected from the 'Tools -> Boards' menu.
#endif
#if IS_TEENSY35
#define BOARD_NAME "Teensy3.5"
#elif IS_TEENSY36
#define BOARD_NAME "Teensy3.6"
#endif
#define LARGE_FLASH true
#define USBCON //1286 // Disable MarlinSerial etc.
/*
teemuatlut plan for Teensy3.5 and Teensy3.6:
USB
GND |-----#####-----| VIN 5V
X_STEP_PIN MOSI1 RX1 0 | ##### | Analog GND
X_DIR_PIN MISO1 TX1 1 | | 3.3V
Y_STEP_PIN PWM 2 | *NC AREF* | 23 A9 PWM
Y_DIR_PIN SCL2 CAN0TX PWM 3 | *A26 A10* | 22 A8 PWM
Z_STEP_PIN SDA2 CAN0RX PWM 4 | *A25 A11* | 21 A7 PWM CS0 MOSI1 RX1
Z_DIR_PIN MISO1 TX1 PWM 5 | *GND * * 57 | 20 A6 PWM CS0 SCK1 FILWIDTH_PIN
X_ENABLE_PIN PWM 6 | *GND * * 56 | 19 A5 SCL0 E0_STEP_PIN
Y_ENABLE_PIN SCL0 MOSI0 RX3 PWM 7 | * * 55 | 18 A4 SDA0 E0_DIR_PIN
Z_ENABLE_PIN SDA0 MISO0 TX3 PWM 8 | * * 54 | 17 A3 SDA0 E0_ENABLE_PIN
CS0 RX2 PWM 9 | | 16 A2 SCL0 TEMP_0_PIN
CS0 TX2 PWM 10 | | 15 A1 CS0 TEMP_BED_PIN
X_STOP_PIN MOSI0 11 | | 14 A0 PWM CS0 TEMP_1_PIN
Y_STOP_PIN MISO0 12 | | 13 LED SCK0 LED_PIN
3.3V | | GND
Z_STOP_PIN 24 | 40 * * 53 | A22 DAC1
AUX2 25 | 41 * * 52 | A21 DAC0
AUX2 FAN_PIN SCL2 TX1 26 | 42 * * 51 | 39 A20 MISO0 SDSS
AUX2 Z-PROBE PWR SCK0 RX1 27 | * * * * * | 38 A19 PWM SDA1
AUX2 SOL1_PIN MOSI0 28 | 43 * * 50 | 37 A18 PWM SCL1
D10 CONTROLLERFAN_PIN CAN0TX PWM 29 | 44 * * 49 | 36 A17 PWM
D9 HEATER_0_PIN CAN0RX PWM 30 | 45 * * 48 | 35 A16 PWM E1_ENABLE_PIN
D8 HEATER_BED_PIN CS1 RX4 A12 31 | 46 * * 47 | 34 A15 PWM SDA0 RX5 E1_DIR_PIN
SCK1 TX4 A13 32 |__GND_*_*_3.3V_| 33 A14 PWM SCL0 TX5 E1_STEP_PIN
Interior pins:
LCD_PINS_RS 40 * * 53 SCK2
LCD_PINS_ENABLE 41 * * 52 MOSI2
LCD_PINS_D4 42 * * 51 MISO2
LCD_PINS_D5 CS2 43 * * 50 A24
LCD_PINS_D6 MOSI2 44 * * 49 A23
LCD_PINS_D7 MISO2 45 * * 48 TX6 SDA0 BTN_ENC
BTN_EN1 SCK2 46 * * 47 RX6 SCL0 BTN_EN2
GND * * 3.3V
*/
#define X_STEP_PIN 22
#define X_DIR_PIN 21
#define X_ENABLE_PIN 39
#define Y_STEP_PIN 19
#define Y_DIR_PIN 18
#define Y_ENABLE_PIN 20
#define Z_STEP_PIN 38
#define Z_DIR_PIN 37
#define Z_ENABLE_PIN 17
#define E0_STEP_PIN 31
#define E0_DIR_PIN 30
#define E0_ENABLE_PIN 32
#define E1_STEP_PIN 33
#define E1_DIR_PIN 34
#define E1_ENABLE_PIN 35
#define HEATER_0_PIN 30
#define HEATER_1_PIN 36
#define HEATER_2_PIN -1
#define HEATER_BED_PIN 31
#define FAN_PIN 2
#define X_STOP_PIN 24
#define Y_STOP_PIN 26
#define Z_STOP_PIN 28
#define TEMP_0_PIN 2 // Extruder / Analog pin numbering: 2 => A2
#define TEMP_BED_PIN 1 // Bed / Analog pin numbering
#define TEMP_1_PIN 0
#define TEMP_2_PIN -1
#define SDPOWER -1
#define SD_DETECT_PIN -1
#define SDSS 39 // 8
#define LED_PIN 13
#define PS_ON_PIN 1
#define KILL_PIN -1
#define ALARM_PIN -1
#define FILWIDTH_PIN 6
#define SOL1_PIN 28
#ifndef SDSUPPORT
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 13
#define MISO_PIN 12
#define MOSI_PIN 11
#endif
#ifdef ULTRA_LCD
#define LCD_PINS_RS 40
#define LCD_PINS_ENABLE 41
#define LCD_PINS_D4 42
#define LCD_PINS_D5 43
#define LCD_PINS_D6 44
#define LCD_PINS_D7 45
#define BTN_EN1 46
#define BTN_EN2 47
#define BTN_ENC 48
#endif
#endif // MOTHERBOARD == 841 (Teensy3.5 and Teensy3.6)

View File

@ -0,0 +1,28 @@
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "HAL_Servo_Teensy.h"
#include "../../../MarlinConfig.h"
int8_t libServo::attach(int pin) {
if (this->servoIndex >= MAX_SERVOS) return -1;
return Servo::attach(pin);
}
int8_t libServo::attach(int pin, int min, int max) {
return Servo::attach(pin, min, max);
}
void libServo::move(int value) {
if (this->attach(0) >= 0) {
this->write(value);
delay(SERVO_DELAY);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
this->detach();
#endif
}
}
#endif

View File

@ -0,0 +1,18 @@
#ifndef HAL_Servo_Teensy_h
#define HAL_Servo_Teensy_h
#include <Servo.h>
// Inherit and expand on the official library
class libServo : public Servo {
public:
int8_t attach(int pin);
int8_t attach(int pin, int min, int max);
void move(int value);
private:
uint16_t min_ticks;
uint16_t max_ticks;
uint8_t servoIndex; // index into the channel data for this servo
};
#endif

View File

@ -0,0 +1,119 @@
/* **************************************************************************
Marlin 3D Printer Firmware
Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
/**
* Description: HAL for Teensy35 (MK64FX512)
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../HAL.h"
#include <Wire.h>
uint16_t HAL_adc_result;
static const uint8_t pin2sc1a[] = {
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9
255, 255, 255, 255, 255, 255, 255, // 24-30 are digital only
14+128, 15+128, 17, 18, 4+128, 5+128, 6+128, 7+128, 17+128, // 31-39 are A12-A20
255, 255, 255, 255, 255, 255, 255, 255, 255, // 40-48 are digital only
10+128, 11+128, // 49-50 are A23-A24
255, 255, 255, 255, 255, 255, 255, // 51-57 are digital only
255, 255, 255, 255, 255, 255, // 58-63 (sd card pins) are digital only
3, 19+128, // 64-65 are A10-A11
23, 23+128,// 66-67 are A21-A22 (DAC pins)
1, 1+128, // 68-69 are A25-A26 (unused USB host port on Teensy 3.5)
26, // 70 is Temperature Sensor
18+128 // 71 is Vref
};
/*
// disable interrupts
void cli(void)
{
noInterrupts();
}
// enable interrupts
void sei(void)
{
interrupts();
}
*/
void HAL_adc_init() {
analog_init();
while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
NVIC_ENABLE_IRQ(IRQ_FTM1);
}
void HAL_clear_reset_source (void)
{ }
uint8_t HAL_get_reset_source (void)
{
switch ( RCM_SRS0 )
{
case 128: return RST_POWER_ON; break;
case 64: return RST_EXTERNAL; break;
case 32: return RST_WATCHDOG; break;
// case 8: return RST_LOSS_OF_LOCK; break;
// case 4: return RST_LOSS_OF_CLOCK; break;
// case 2: return RST_LOW_VOLTAGE; break;
default:
return 0;
}
}
void _delay_ms (int delay_ms)
{
delay (delay_ms);
}
extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;
int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}
void HAL_adc_start_conversion (uint8_t adc_pin)
{
ADC0_SC1A = pin2sc1a[adc_pin];
}
uint16_t HAL_adc_get_result(void)
{
return ADC0_RA;
}
#endif // __MK64FX512__ || __MK66FX1M0__

View File

@ -0,0 +1,149 @@
/* **************************************************************************
Marlin 3D Printer Firmware
Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
/**
* Description: HAL for Teensy 3.5 and Teensy 3.6
*/
#ifndef _HAL_TEENSY_H
#define _HAL_TEENSY_H
// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------
#include <stdint.h>
#include "Arduino.h"
#include "fastio_Teensy.h"
#include "watchdog_Teensy.h"
#include "HAL_timers_Teensy.h"
// --------------------------------------------------------------------------
// Defines
// --------------------------------------------------------------------------
#define MOTHERBOARD BOARD_TEENSY35_36
#define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
#define IS_TEENSY35 defined(__MK64FX512__)
#define IS_TEENSY36 defined(__MK66FX1M0__)
#if SERIAL_PORT == -1
#define MYSERIAL SerialUSB
#elif SERIAL_PORT == 0
#define MYSERIAL Serial
#elif SERIAL_PORT == 1
#define MYSERIAL Serial1
#elif SERIAL_PORT == 2
#define MYSERIAL Serial2
#elif SERIAL_PORT == 3
#define MYSERIAL Serial3
#endif
#define HAL_SERVO_LIB libServo
//#define _BV(bit) (1 << (bit))
#ifndef analogInputToDigitalPin
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg;
// On AVR this is in math.h?
#define square(x) ((x)*(x))
#ifndef strncpy_P
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
#endif
// Fix bug in pgm_read_ptr
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
#undef pgm_read_word
#define pgm_read_word(addr) (*(addr))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
/** clear reset reason */
void HAL_clear_reset_source (void);
/** reset reason */
uint8_t HAL_get_reset_source (void);
void _delay_ms(int delay);
extern "C" {
int freeMemory(void);
}
// SPI: Extended functions which take a channel number (hardware SPI only)
/** Write single byte to specified SPI channel */
void spiSend(uint32_t chan, byte b);
/** Write buffer to specified SPI channel */
void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
/** Read single byte from specified SPI channel */
uint8_t spiRec(uint32_t chan);
// ADC
void HAL_adc_init();
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC HAL_adc_get_result()
#define HAL_ANALOG_SELECT(pin) NOOP;
void HAL_adc_start_conversion (uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/*
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
#endif // _HAL_TEENSY_H

View File

@ -0,0 +1,107 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HAL_PINSDEBUG_TEENSY_H
#define FTM0_CH0_PIN 22
#define FTM0_CH1_PIN 23
#define FTM0_CH2_PIN 9
#define FTM0_CH3_PIN 10
#define FTM0_CH4_PIN 6
#define FTM0_CH5_PIN 20
#define FTM0_CH6_PIN 21
#define FTM0_CH7_PIN 5
#define FTM1_CH0_PIN 3
#define FTM1_CH1_PIN 4
#define FTM2_CH0_PIN 29
#define FTM2_CH1_PIN 30
#define FTM3_CH0_PIN 2
#define FTM3_CH1_PIN 14
#define FTM3_CH2_PIN 7
#define FTM3_CH3_PIN 8
#define FTM3_CH4_PIN 35
#define FTM3_CH5_PIN 36
#define FTM3_CH6_PIN 37
#define FTM3_CH7_PIN 38
#if defined(__MK66FX1M0__) // Teensy3.6
#define TPM1_CH0_PIN 16
#define TPM1_CH1_PIN 17
#endif
#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && (P) <= analogInputToDigitalPin(9)) || ((P) >= analogInputToDigitalPin(12) && (P) <= analogInputToDigitalPin(20))
void HAL_print_analog_pin(char buffer[], int8_t pin) {
if (pin <= 23) sprintf(buffer, "(A%2d) ", int(pin - 14));
else if (pin <= 39) sprintf(buffer, "(A%2d) ", int(pin - 19));
}
void HAL_analog_pin_state(char buffer[], int8_t pin) {
if (pin <= 23) sprintf(buffer, "Analog in =% 5d", analogRead(pin - 14));
else if (pin <= 39) sprintf(buffer, "Analog in =% 5d", analogRead(pin - 19));
}
#define PWM_PRINT(V) do{ sprintf(buffer, "PWM: %4d", 22); SERIAL_ECHO(buffer); }while(0)
#define FTM_CASE(N,Z) \
case FTM##N##_CH##Z##_PIN: \
if (FTM##N##_C##Z##V) { \
PWM_PRINT(FTM##N##_C##Z##V); \
return true; \
} else return false
/**
* Print a pin's PWM status.
* Return true if it's currently a PWM pin.
*/
bool HAL_pwm_status(int8_t pin) {
char buffer[20]; // for the sprintf statements
switch(pin) {
FTM_CASE(0,0);
FTM_CASE(0,1);
FTM_CASE(0,2);
FTM_CASE(0,3);
FTM_CASE(0,4);
FTM_CASE(0,5);
FTM_CASE(0,6);
FTM_CASE(0,7);
FTM_CASE(1,0);
FTM_CASE(1,1);
FTM_CASE(2,0);
FTM_CASE(2,1);
FTM_CASE(3,0);
FTM_CASE(3,1);
FTM_CASE(3,2);
FTM_CASE(3,3);
FTM_CASE(3,4);
FTM_CASE(3,5);
FTM_CASE(3,6);
FTM_CASE(3,7);
case NOT_ON_TIMER:
default:
return false;
}
SERIAL_PROTOCOLPGM(" ");
}
static void HAL_pwm_details(uint8_t pin) { /* TODO */ }
#endif

View File

@ -0,0 +1,104 @@
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../HAL.h"
#include <SPI.h>
#include <pins_arduino.h>
#include "spi_pins.h"
#include "../../../macros.h"
static SPISettings spiConfig;
// Standard SPI functions
/** Initialise SPI bus */
void spiBegin(void) {
#ifndef SS_PIN
#error SS_PIN not defined!
#endif
SET_OUTPUT(SS_PIN);
WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
//#if DISABLED(SOFTWARE_SPI)
#if false
// set SS high - may be chip select for another SPI device
#if SET_SPI_SS_HIGH
WRITE(SS_PIN, HIGH);
#endif // SET_SPI_SS_HIGH
// set a default rate
spiInit(SPI_HALF_SPEED); // 1
#endif // SOFTWARE_SPI
}
/** Configure SPI for specified SPI speed */
void spiInit(uint8_t spiRate) {
// Use datarates Marlin uses
uint32_t clock;
switch (spiRate) {
case SPI_FULL_SPEED: clock = 10000000; break;
case SPI_HALF_SPEED: clock = 5000000; break;
case SPI_QUARTER_SPEED: clock = 2500000; break;
case SPI_EIGHTH_SPEED: clock = 1250000; break;
case SPI_SPEED_5: clock = 625000; break;
case SPI_SPEED_6: clock = 312500; break;
default:
clock = 4000000; // Default from the SPI libarary
}
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
SPI.begin();
}
//------------------------------------------------------------------------------
/** SPI receive a byte */
uint8_t spiRec(void) {
SPI.beginTransaction(spiConfig);
uint8_t returnByte = SPI.transfer(0xFF);
SPI.endTransaction();
return returnByte;
// SPDR = 0XFF;
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
// return SPDR;
}
//------------------------------------------------------------------------------
/** SPI read data */
void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig);
SPI.transfer(buf, nbyte);
SPI.endTransaction();
//if (nbyte-- == 0) return;
// SPDR = 0XFF;
//for (uint16_t i = 0; i < nbyte; i++) {
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
// buf[i] = SPDR;
// SPDR = 0XFF;
//}
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
//buf[nbyte] = SPDR;
}
//------------------------------------------------------------------------------
/** SPI send a byte */
void spiSend(uint8_t b) {
SPI.beginTransaction(spiConfig);
SPI.transfer(b);
SPI.endTransaction();
// SPDR = b;
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
}
//------------------------------------------------------------------------------
/** SPI send block */
void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig);
SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) {
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
SPDR = buf[i];
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
SPDR = buf[i + 1];
}
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
SPI.endTransaction();
}
#endif

View File

@ -0,0 +1,95 @@
/* **************************************************************************
Marlin 3D Printer Firmware
Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
/**
* Teensy3.5 __MK64FX512__
* Teensy3.6 __MK66FX1M0__
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../HAL.h"
#include "HAL_timers_Teensy.h"
void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
switch (timer_num) {
case 0:
FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
FTM0_SC = 0x00; // Set this to zero before changing the modulus
FTM0_CNT = 0x0000; // Reset the count to zero
FTM0_MOD = 0xFFFF; // max modulus = 65535
FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
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
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
case 1:
FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
FTM1_SC = 0x00; // Set this to zero before changing the modulus
FTM1_CNT = 0x0000; // Reset the count to zero
FTM1_MOD = 0xFFFF; // max modulus = 65535
FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
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
FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
break;
default:
break;
}
}
void HAL_timer_enable_interrupt (uint8_t timer_num)
{
switch(timer_num) {
case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
default:
break;
}
}
void HAL_timer_disable_interrupt (uint8_t timer_num)
{
switch (timer_num) {
case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
default:
break;
}
}
void HAL_timer_isr_prologue(uint8_t timer_num) {
switch(timer_num) {
case 0:
FTM0_CNT = 0x0000;
FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
case 1:
FTM1_CNT = 0x0000;
FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
break;
default:
break;
}
}
#endif // Teensy3.5 or Teensy3.6

View File

@ -0,0 +1,109 @@
/* **************************************************************************
Marlin 3D Printer Firmware
Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
/**
* Description: HAL for
* Teensy3.5 (__MK64FX512__)
* Teensy3.6 (__MK66FX1M0__)
*/
#ifndef _HAL_TIMERS_TEENSY_H
#define _HAL_TIMERS_TEENSY_H
// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------
#include <stdint.h>
// --------------------------------------------------------------------------
// Defines
// --------------------------------------------------------------------------
#define FORCE_INLINE __attribute__((always_inline)) inline
#define HAL_TIMER_TYPE uint32_t
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
#define STEP_TIMER_NUM 0
#define TEMP_TIMER_NUM 1
#define FTM0_TIMER_PRESCALE 8
#define FTM1_TIMER_PRESCALE 4
#define FTM0_TIMER_PRESCALE_BITS 0b011
#define FTM1_TIMER_PRESCALE_BITS 0b010
#define FTM0_TIMER_RATE F_BUS/FTM0_TIMER_PRESCALE // 60MHz / 8 = 7500kHz
#define FTM1_TIMER_RATE F_BUS/FTM1_TIMER_PRESCALE // 60MHz / 4 = 15MHz
#define STEPPER_TIMER STEP_TIMER_NUM // Alias?
#define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
#define HAL_TICKS_PER_US (HAL_STEPPER_TIMER_RATE/1000000)
#define TEMP_TIMER_FREQUENCY 1000
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt (STEP_TIMER_NUM)
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
#define HAL_STEP_TIMER_ISR extern "C" void ftm0_isr(void) //void TC3_Handler()
#define HAL_TEMP_TIMER_ISR extern "C" void ftm1_isr(void) //void TC4_Handler()
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
switch(timer_num) {
case 0: FTM0_C0V = count; break;
case 1: FTM1_C0V = count; break;
default: break;
}
}
static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
switch(timer_num) {
case 0: return FTM0_C0V;
case 1: return FTM1_C0V;
default: return 0;
}
}
static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) {
switch(timer_num) {
case 0: return FTM0_CNT;
case 1: return FTM1_CNT;
default: return 0;
}
}
void HAL_timer_enable_interrupt (uint8_t timer_num);
void HAL_timer_disable_interrupt (uint8_t timer_num);
void HAL_timer_isr_prologue(uint8_t timer_num);
#endif // _HAL_TIMERS_TEENSY_H

View File

@ -0,0 +1,84 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Endstop Interrupts
*
* Without endstop interrupts the endstop pins must be polled continually in
* the stepper-ISR via endstops.update(), most of the time finding no change.
* With this feature endstops.update() is called only when we know that at
* least one endstop has changed state, saving valuable CPU cycles.
*
* This feature only works when all used endstop pins can generate an 'external interrupt'.
*
* Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
*/
#ifndef _ENDSTOP_INTERRUPTS_H_
#define _ENDSTOP_INTERRUPTS_H_
/**
* Endstop interrupts for Due based targets.
* On Due, all pins support external interrupt capability.
*/
void setup_endstop_interrupts( void ) {
#if HAS_X_MAX
attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
#endif
#if HAS_X_MIN
attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Y_MAX
attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Y_MIN
attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Z_MAX
attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Z_MIN
attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Z2_MAX
attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Z2_MIN
attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
#endif
#if HAS_Z_MIN_PROBE_PIN
attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
#endif
}
#endif //_ENDSTOP_INTERRUPTS_H_

View File

@ -0,0 +1,120 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
This code contributed by Triffid_Hunter and modified by Kliment
why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
*/
/**
* Description: Fast IO functions for Teensy 3.5 and Teensy 3.6
*/
#ifndef _FASTIO_TEENSY_H
#define _FASTIO_TEENSY_H
/**
utility functions
*/
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#endif
#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
#define GPIO_BITBAND(reg, bit) (*(uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
/**
magic I/O routines
now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0);
*/
/// Read a pin
#define _READ(p) ((bool)(CORE_PIN ## p ## _PINREG & CORE_PIN ## p ## _BITMASK))
/// Write to a pin
#define _WRITE(p, v) do { if (v) CORE_PIN ## p ## _PORTSET = CORE_PIN ## p ## _BITMASK; \
else CORE_PIN ## p ## _PORTCLEAR = CORE_PIN ## p ## _BITMASK; } while (0)
/// toggle a pin
#define _TOGGLE(p) (*(&(CORE_PIN ## p ## _PORTCLEAR)+1) = CORE_PIN ## p ## _BITMASK)
/// set pin as input
#define _SET_INPUT(p) do { CORE_PIN ## p ## _CONFIG = PORT_PCR_MUX(1); \
GPIO_BITBAND(CORE_PIN ## p ## _DDRREG , CORE_PIN ## p ## _BIT) = 0; \
} while (0)
/// set pin as output
#define _SET_OUTPUT(p) do { CORE_PIN ## p ## _CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE|PORT_PCR_DSE; \
GPIO_BITBAND(CORE_PIN ## p ## _DDRREG , CORE_PIN ## p ## _BIT) = 1; \
} while (0)
/// set pin as input with pullup mode
//#define _PULLUP(IO, v) { pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)); }
/// check if pin is an input
#define _GET_INPUT(p) ((CORE_PIN ## p ## _DDRREG & CORE_PIN ## p ## _BITMASK) == 0)
/// check if pin is an output
#define _GET_OUTPUT(p) ((CORE_PIN ## p ## _DDRREG & CORE_PIN ## p ## _BITMASK) == 0)
/// check if pin is an timer
//#define _GET_TIMER(IO)
// why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
/// Read a pin wrapper
#define READ(IO) _READ(IO)
/// Write to a pin wrapper
#define WRITE_VAR(IO, v) _WRITE_VAR(IO, v)
#define WRITE(IO, v) _WRITE(IO, v)
/// toggle a pin wrapper
#define TOGGLE(IO) _TOGGLE(IO)
/// set pin as input wrapper
#define SET_INPUT(IO) _SET_INPUT(IO)
/// set pin as input with pullup wrapper
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _WRITE(IO, HIGH); }while(0)
/// set pin as output wrapper
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
/// check if pin is an input wrapper
#define GET_INPUT(IO) _GET_INPUT(IO)
/// check if pin is an output wrapper
#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
// Shorthand
#define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
/**
ports and functions
added as necessary or if I feel like it- not a comprehensive list!
*/
/**
pins
*/
#define DIO0_PIN 8
#endif /* _FASTIO_TEENSY_H */

View File

@ -0,0 +1,57 @@
#include "../persistent_store_api.h"
#include "../../../types.h"
#include "../../../language.h"
#include "../../../serial.h"
#include "../../../utility.h"
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#if ENABLED(EEPROM_SETTINGS)
namespace HAL {
namespace PersistentStore {
bool access_start() {
return true;
}
bool access_finish(){
return true;
}
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
while (size--) {
uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value;
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v);
if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
return false;
}
}
crc16(crc, &v, 1);
pos++;
value++;
};
return true;
}
void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
do {
uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c;
crc16(crc, &c, 1);
pos++;
value++;
} while (--size);
}
}
}
#endif // EEPROM_SETTINGS
#endif // ARDUINO_ARCH_AVR

View File

@ -0,0 +1,28 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SPI_PINS_H_
#define SPI_PINS_H_
#define SCK_PIN 13
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN 20 //SDSS // A.28, A.29, B.21, C.26, C.29
#endif /* SPI_PINS_H_ */

View File

@ -0,0 +1,39 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../../../Marlin.h"
#if ENABLED(USE_WATCHDOG)
#include "watchdog_Teensy.h"
void watchdog_init() {
WDOG_TOVALH = 0;
WDOG_TOVALL = 4000;
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
}
#endif //USE_WATCHDOG
#endif

View File

@ -0,0 +1,38 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef WATCHDOG_TEENSY_H
#define WATCHDOG_TEENSY_H
//#include "../../../Marlin.h"
// Arduino Due core now has watchdog support
void watchdog_init();
inline void watchdog_reset() {
// Watchdog refresh sequence
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
}
#endif /* WATCHDOG_TEENSY_H */

View File

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

View File

@ -87,3 +87,10 @@ framework = arduino
board = due board = due
build_flags = -I $BUILDSRC_DIR build_flags = -I $BUILDSRC_DIR
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
[env:teensy35]
platform = teensy
framework = arduino
board = teensy35
build_flags = -I $BUILDSRC_DIR
lib_deps = ${common.lib_deps}