# This file contains pin mappings for the stock Sovol SV06 Plus.
# 
# Find installation instructions at https://github.com/bassamanator/Sovol-SV06-firmware
# 
# See https://www.klipper3d.org/Config_Reference.html for configuration reference.

[include ./cfgs/misc-macros.cfg]
[include ./cfgs/PARKING.cfg]
[include ./cfgs/MECHANICAL_GANTRY_CALIBRATION.cfg]
[include ./cfgs/CALIBRATION.cfg]

# NOTE Uncomment the ONE of the following lines if you're using an adxl345
# [include ./cfgs/adxl-rp2040.cfg]
# [include ./cfgs/adxl-rpi-pico-2x.cfg]
# [include ./cfgs/adxl-direct.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: PC2
dir_pin: !PB9
enable_pin: !PC3
microsteps: 128
rotation_distance: 40
endstop_pin: tmc2209_stepper_x:virtual_endstop
position_endstop: 0
position_max: 300 # NOTE You can adjust this if you have more room
homing_speed: 40
homing_retract_dist: 0

[tmc2209 stepper_x]
uart_pin: PC1
run_current: 0.820
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 3
driver_SGTHRS: 86 # NOTE Bump sensitivity; increase to make more sensitive
diag_pin: PA5

[stepper_y]
step_pin: PB8
dir_pin: PB7
enable_pin: !PC3
microsteps: 128
rotation_distance: 40
endstop_pin: tmc2209_stepper_y:virtual_endstop
position_endstop: 0
position_max: 300 # NOTE You can adjust this if you have more room
homing_speed: 40
homing_retract_dist: 0

[tmc2209 stepper_y]
uart_pin: PC0
run_current: 0.880
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 3
driver_SGTHRS: 110 # NOTE Bump sensitivity; increase to make more sensitive
diag_pin: PA6

[stepper_z]
step_pin: PB6
dir_pin: !PB5
enable_pin: !PC3
microsteps: 128
rotation_distance: 4
endstop_pin: probe:z_virtual_endstop
position_min: -4
position_max: 340 # NOTE You can adjust this if you have more room
homing_speed: 5

[tmc2209 stepper_z]
uart_pin: PA15
run_current: 0.800
stealthchop_threshold: 0
interpolate: False
sense_resistor: 0.150
uart_address: 3
diag_pin: PA7

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

[extruder]
step_pin: PB4
dir_pin: !PB3
enable_pin: !PC3
microsteps: 128
rotation_distance: 4.65 # NOTE Calibrate e-steps and adjust https://www.klipper3d.org/Rotation_Distance.html
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PA1
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC5
control: pid
pid_kd: 41.96
pid_kp: 15.66
pid_ki: 1.49
min_temp: 0
max_temp: 300
max_extrude_only_distance: 150.0

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

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

[heater_bed]
heater_pin: PA2
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC4
control: pid
pid_kp: 186.38
pid_ki: 36.12
pid_kd: 637.30
min_temp: 0
max_temp: 110

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

[probe]
pin: PB1
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: 123, 170
speed: 100.0
z_hop: 10
z_hop_speed: 15

[bed_mesh]
speed: 175
mesh_min: 30, 30
mesh_max: 270, 270
probe_count: 5,5
algorithm: bicubic
fade_start: 1
fade_end: 10
fade_target: 0

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

[fan]
pin: PA0

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

# NOTE Apparently the screen is not Klipper friendly
# [display]
# lcd_type: st7920
# cs_pin: PB12
# sclk_pin: PB13
# sid_pin: PB15
# encoder_pins: ^PB14, ^PB10
# click_pin: ^!PB2

# NOTE The speaker will not work, since the screen doesn't
# [output_pin beeper]
# pin: PC6
# value: 0
# shutdown_value: 0
# pwm: True
# cycle_time: 0.0005 ; Default beeper tone in kHz. 1 / 0.0005 = 2000Hz (2kHz)

[filament_switch_sensor filament_sensor]
switch_pin: PA4
pause_on_runout: True
insert_gcode:
    { action_respond_info("Insert Detected") }
runout_gcode:
    { action_respond_info("Runout Detected") }
    CONDITIONAL_BEEP i=3 dur=300 freq=400
