# This file contains pin mappings for the Sovol SV06 using the BTT SKR Mini E3 V3.0.
# 
# Find installation instructions at https://github.com/bassamanator/Sovol-SV06-firmware
# 
# See https://www.klipper3d.org/Config_Reference.html for configuration reference.

[include ./osskc.cfg]

[mcu]
# NOTE Obtain definition by "ls -l /dev/serial/by-path/" or "ls -l /dev/serial/by-id/"
serial: /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-port0
restart_method: command

[printer]
kinematics: cartesian
max_velocity: 200
max_accel: 3000
max_z_velocity: 15
max_z_accel: 45
square_corner_velocity: 8.0

#####################################################################
#      X/Y/Z Stepper Settings
#####################################################################

[stepper_x]
step_pin: PB13
dir_pin: PB12
enable_pin: !PB14
microsteps: 64
rotation_distance: 40
endstop_pin: tmc2209_stepper_x:virtual_endstop
position_endstop: 0
position_max: 223 # NOTE You can adjust this if you have more room
homing_speed: 40
homing_retract_dist: 0

[tmc2209 stepper_x]
uart_pin: PC11
tx_pin: PC10
run_current: 0.600
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 0
driver_SGTHRS: 81
diag_pin: PC0

[stepper_y]
step_pin: PB10
dir_pin: !PB2
enable_pin: !PB11
microsteps: 64
rotation_distance: 40
endstop_pin: tmc2209_stepper_y:virtual_endstop
position_endstop: 0
position_max: 223 # NOTE You can adjust this if you have more room
homing_speed: 40
homing_retract_dist: 0

[tmc2209 stepper_y]
uart_pin: PC11
tx_pin: PC10
run_current: 0.600
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 2
driver_SGTHRS: 81
diag_pin: PC1

[stepper_z]
step_pin: PB0
dir_pin: PC5
enable_pin: !PB1
microsteps: 64
rotation_distance: 4
endstop_pin: probe:z_virtual_endstop
position_min: -4
position_max: 258 # NOTE You can adjust this if you have more room
homing_speed: 5

[tmc2209 stepper_z]
uart_pin: PC11
tx_pin: PC10
run_current: 0.600
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 1
# diag_pin: PC2 # Should not be needed

#####################################################################
#   Extruder
#####################################################################

[extruder]
step_pin: PB3
dir_pin: PB4
enable_pin: !PD1
microsteps: 64
rotation_distance: 4.65
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PC8
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA0
control: pid
pid_kd: 86.991
pid_kp: 21.479
pid_ki: 1.326
min_temp: 0
max_temp: 300
max_extrude_only_distance: 150.0

[tmc2209 extruder]
uart_pin: PC11
tx_pin: PC10
run_current: 0.550
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 3

#####################################################################
#   Bed Heater
#####################################################################

[heater_bed]
heater_pin: PC9
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC4
control: pid
pid_kp: 64.440
pid_ki: 0.773
pid_kd: 1343.571
min_temp: 0
max_temp: 110

#####################################################################
#   Probe Related
#####################################################################

[probe]
pin: PC14
x_offset: 27
y_offset: -20
z_offset: 0
samples: 3
samples_result: median
samples_tolerance: 0.01
samples_tolerance_retries: 5

[safe_z_home]
home_xy_position: 84.50, 135 # NOTE The probe is at the center of the bed.
speed: 100.0
z_hop: 10
z_hop_speed: 15

[bed_mesh]
speed: 175
mesh_min: 27, 6
mesh_max: 222, 203
probe_count: 5,5
algorithm: bicubic
fade_start: 1
fade_end: 10
fade_target: 0

#####################################################################
#   Fans
#####################################################################

# FAN1
[fan]
pin: PC6

# FAN2
[controller_fan electronic_enclosure_fan]
pin: PB15
idle_timeout: 60
idle_speed: 0
stepper: stepper_x, stepper_y, stepper_z

# FAN0
[heater_fan hotend_fan]
pin: PC7
heater: extruder
heater_temp: 50.0

#####################################################################
#   Misc
#####################################################################

[display]
lcd_type: st7920
cs_pin: PB8
sclk_pin: PB9
sid_pin: PD6
encoder_pins: ^PA10, ^PA9
click_pin: ^!PA15

[bed_screws]
screw1_name: front left
screw1: 26.5, 31
screw2_name: front right
screw2: 196.75, 31
screw3_name: back right
screw3: 196.75, 201
screw4_name: back left
screw4: 26.5, 201

[screws_tilt_adjust]
screw1_name: center
screw1: 84.50, 135
screw2_name: front left
screw2: 0, 51
screw3_name: front right
screw3: 169.75, 51
screw4_name: back right
screw4: 169.75, 221
screw5_name: back left
screw5: 0, 221
horizontal_move_z: 10
screw_thread: CCW-M4

[output_pin beeper]
pin: PB5
value: 0
shutdown_value: 0
pwm: True
cycle_time: 0.0005 # Default beeper tone in kHz. 1 / 0.0005 = 2000Hz (2kHz)

# Not figured at this point
# [filament_switch_sensor filament_sensor]
# switch_pin: !PA4 # "Pulled-high"
# pause_on_runout: True
# insert_gcode:
#     M117 Insert Detected
# runout_gcode:
#     M117 Runout Detected
#     CONDITIONAL_BEEP i=3 dur=300 freq=400

[board_pins]
aliases:
    # EXP1 header
    EXP1_1=PB5, EXP1_3=PA9, EXP1_5=PA10, EXP1_7=PB8, EXP1_9=<GND>,
    EXP1_2=PA15, EXP1_4=<RST>, EXP1_6=PB9, EXP1_8=PD6, EXP1_10=<5V>
