# This file contains common pin mappings for MKS SKIPR
# boards. To use this config, the firmware should be compiled for the
# stm32f407. When running "make menuconfig", select the 48KiB
# bootloader, and enable "Serial for communication" and select the "on USART1 PA10/PA9"

# The "make flash" command does not work on the MKS SKIPR. Instead,
# after running "make", copy the generated "out/klipper.bin" file to a
# file named "mks_skipr.bin" on an SD card and then restart the
# MKS SKIPR with that SD card.

# See docs/Config_Reference.md for a description of parameters.
[mcu]
# The hardware use USART1 PA10/PA9 connect to RK3328
#serial: /dev/serial/by-id/usb-Klipper_stm32f407xx_4D0045001850314335393520-if00
serial: /dev/ttyS0
restart_method: command

[stepper_x]
step_pin:PC14
dir_pin:!PC13
enable_pin:!PC15
microsteps: 16
rotation_distance: 40
full_steps_per_rotation:200  #set to 400 for 0.9 degree stepper
endstop_pin:PA14
position_min: 0  
position_endstop: 230
position_max: 230
homing_speed:50
homing_retract_dist:5
homing_positive_dir:true
step_pulse_duration:0.000008
[stepper_y]
step_pin:PE5
dir_pin:!PE4
enable_pin:!PD14
microsteps:16
rotation_distance: 40
full_steps_per_rotation:200  #set to 400 for 0.9 degree stepper
endstop_pin:PA15
position_min: 0
position_endstop:230
position_max:230
homing_speed:50
homing_retract_dist:5
homing_positive_dir:true
step_pulse_duration:0.000008
[stepper_z]
step_pin:PE1
dir_pin:!PE0
enable_pin: !PE2
microsteps: 16
rotation_distance: 40
full_steps_per_rotation: 200
gear_ratio: 80:16
endstop_pin:probe:z_virtual_endstop ## PB12 for Z-max; endstop have'!' is NO

##  Z-position of nozzle (in mm) to z-endstop trigger point relative to print surface (Z0)
##  (+) value = endstop above Z0, (-) value = endstop below
##	Increasing position_endstop brings nozzle closer to the bed
##  After you run Z_ENDSTOP_CALIBRATE, position_endstop will be stored at the very end of your config
#position_endstop:-5
position_max: 255
position_min: -5 
homing_speed: 8
second_homing_speed: 3

[stepper_z1]
step_pin:PD6
dir_pin:PD5
enable_pin:!PD7
microsteps:16
rotation_distance: 40
full_steps_per_rotation: 200
gear_ratio: 80:16

[stepper_z2]
step_pin:PD2
dir_pin:PD1
enable_pin:!PD3
microsteps: 16
rotation_distance: 40
full_steps_per_rotation: 200
gear_ratio: 80:16

[stepper_z3]
step_pin:PC7
dir_pin:PC6
enable_pin:!PC8
microsteps:16
rotation_distance:40
full_steps_per_rotation: 200
gear_ratio:80:16

[extruder]
step_pin:PB5
dir_pin:!PB4
enable_pin:!PB6
microsteps:16
rotation_distance: 25.12	#Bondtech 5mm Drive Gears
gear_ratio: 50:17
full_steps_per_rotation: 200	#200 for 1.8 degree, 400 for 0.9 degree
nozzle_diameter: 0.400
filament_diameter: 1.750
min_temp: 0
max_temp: 275
heater_pin: PB1
sensor_type:  NTC 100K MGB18-104F39050L32
sensor_pin: PC1
max_power: 1.0
control : pid  
pid_kp : 26.213 
pid_ki : 1.304
pid_kd : 131.721 
pressure_advance: 0.00
pressure_advance_smooth_time: 0.150
max_extrude_cross_section:20
instantaneous_corner_velocity: 1.000
max_extrude_only_distance: 50.0
max_extrude_only_velocity:5000
max_extrude_only_accel:2000
step_pulse_duration:0.000004
#[extruder1]
#step_pin: PD6
#dir_pin: !PD5
#enable_pin: !PD7
#heater_pin: PB0
#sensor_pin: PC2

#[extruder2]
#step_pin: PD2
#dir_pin: !PD1
#enable_pin: !PD3
#heater_pin: PA3
#sensor_pin: PC3

#[extruder3]
#step_pin: PC7
#dir_pin: PC6
#enable_pin: !PC8

[heater_bed]
heater_pin: PD12
sensor_type: NTC 100K MGB18-104F39050L32
sensor_pin: PC0
max_power: 1.0
control = pid
pid_kp = 71.039
pid_ki = 2.223
pid_kd = 567.421
min_temp: 0
max_temp: 200

#fan for printed model FAN0
[fan]
pin: PA2

#fan for hotend FAN1
#[heater_fan my_nozzle_fan]
[heater_fan fan1]
pin: PA1
shutdown_speed: 1

#fan for control board FAN2
#[heater_fan my_control_fan]
[heater_fan fan2]
pin: PA0
shutdown_speed: 1



####################################################################
#	Homing and Gantry Adjustment Routines
#####################################################################
[idle_timeout]
timeout: 3600

[safe_z_home]
home_xy_position: 115,115 # Change coordinates to the center of your print bed
speed: 100
z_hop: 10                 # Move up 10mm
z_hop_speed: 5

[quad_gantry_level]
gantry_corners:
	-58,-7
    308,318
##	Probe points
points:
	10,10
	10,200
	220,200
	220,10
speed: 80
horizontal_move_z: 10
retries: 1
retry_tolerance: 0.05
max_adjust: 30


#####################################################################
# 	Probe
#####################################################################
[probe]
pin:!PB15
x_offset: 0
y_offset: 25.0
z_offset: 0.55
speed: 10.0
samples: 2
samples_result: median
sample_retract_dist: 3.0
samples_tolerance: 0.05
samples_tolerance_retries: 1

[printer]
kinematics:corexy
max_velocity: 500
max_accel: 8000
max_accel_to_decel: 4000
max_z_velocity: 15
max_z_accel: 100
square_corner_velocity: 2.0
#####################################################################
# LED Control
#####################################################################

#[output_pin caselight ](Use PA9)
##  Chamber Lighting - In 5V-RGB Position
#pin: PC5
#pwm: true
#shutdown_value: 0
#value:100
#cycle_time: 0.01

########################################
# TMC UART configuration
########################################

[tmc2209 stepper_x]
uart_pin: PE6
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 400

[tmc2209 stepper_y]
uart_pin: PE3
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 400

[tmc2209 stepper_z]
uart_pin: PB7
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 120


[tmc2209 stepper_z1]
uart_pin: PD4
interpolate: True
run_current: 0.8
hold_current: 0.5
stealthchop_threshold: 120

[tmc2209 stepper_z2]
uart_pin: PD0
interpolate: True
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 120

[tmc2209 stepper_z3]
uart_pin: PD15
interpolate: True
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 120


[tmc2209 extruder]
uart_pin: PB3
run_current: 0.8
hold_current: 0.5
interpolate: True
stealthchop_threshold: 400

#[tmc2208 extruder1]
#uart_pin: PD4
#run_current: 0.8
#hold_current: 0.5
#stealthchop_threshold: 999999

#[tmc2208 extruder2]
#uart_pin: PD0
#run_current: 0.8
#hold_current: 0.5
#stealthchop_threshold: 999999

#[tmc2208 extruder3]
#uart_pin: PD15
#run_current: 0.8
#hold_current: 0.5
#stealthchop_threshold: 999999

########################################
# TMC SPI configuration
########################################

#[tmc2130 stepper_x]
#spi_bus: spi4
#cs_pin: PE6
#diag1_pin: PA14
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 stepper_y]
#spi_bus: spi4
#cs_pin: PE3
#diag1_pin: PA15
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 stepper_z]
#spi_bus: spi4
#cs_pin: PB7
#diag1_pin: PB15
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 extruder]
#spi_bus: spi4
#cs_pin: PB3
#diag1_pin: PA13
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 extruder1]
#spi_bus: spi4
#cs_pin: PD4
#diag1_pin: PC5
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 extruder2]
#spi_bus: spi4
#cs_pin: PD0
#diag1_pin: PB14
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

#[tmc2130 extruder3]
#spi_bus: spi4
#cs_pin: PD15
#run_current: 0.800
#hold_current: 0.500
#stealthchop_threshold: 999999

########################################
# EXP1 / EXP2 (display) pins
########################################

[board_pins]
aliases:
    # EXP1 header
    EXP1_1=PB2,  EXP1_3=PE11, EXP1_5=PD9, EXP1_7=PE15, EXP1_9=<GND>,
    EXP1_2=PE10, EXP1_4=PD10, EXP1_6=PD8, EXP1_8=PE7,  EXP1_10=<5V>,
    # EXP2 header
    EXP2_1=PA6, EXP2_3=PE9, EXP2_5=PE8, EXP2_7=PD13,  EXP2_9=<GND>,
    EXP2_2=PA5, EXP2_4=PA4, EXP2_6=PA7, EXP2_8=<RST>, EXP2_10=<3.3v>
    # Pins EXP2_1, EXP2_6, EXP2_2 are also MISO, MOSI, SCK of bus "ssp1"

    # See the sample-lcd.cfg file for definitions of common LCD displays.

# Some alternate glyphs for use with 128x64 LCDs. These are used by
# adding them to your printer.cfg.

# See docs/Config_Reference.md for a description of parameters.

######################################################################
# MKS Mini 12864v3.0 (with neopixel backlight leds)
######################################################################

[display]
lcd_type: uc1701
cs_pin: EXP1_3
a0_pin: EXP1_4
rst_pin: EXP1_5
contrast: 63
encoder_pins: ^EXP2_5, ^EXP2_3
click_pin: ^!EXP1_2
## Some micro-controller boards may require an spi bus to be specified:
#spi_bus: spi
## Alternatively, some micro-controller boards may work with software spi:
spi_software_miso_pin: EXP2_1
spi_software_mosi_pin: EXP2_6
spi_software_sclk_pin: EXP2_2

[output_pin beeper]
pin: EXP1_1

[neopixel fysetc_mini12864]
pin: EXP1_6
chain_count: 3
color_order: RGB
initial_RED: 1.0
initial_GREEN: 1.0
initial_BLUE: 0.0


# See the MKS Lcd Config path file for definitions of common LCD displays.

[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345]
cs_pin: rpi:None
spi_bus: spidev0.2

[resonance_tester]
accel_chip: adxl345
probe_points:
    100, 100, 20  # an example


[input_shaper]
shaper_freq_x: 68.4
shaper_type_x: mzv
shaper_freq_y: 45.6
shaper_type_y: mzv

[virtual_sdcard]
#path:/home/mks/uploads
path: ~/gcode_files

[pause_resume]

[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
  TURN_OFF_HEATERS
  CANCEL_PRINT_BASE


[display_status]


[gcode_macro G32]
gcode:
    BED_MESH_CLEAR
    G28
    QUAD_GANTRY_LEVEL
    G28