Lazy homing for manual stepper

Hello. I have a manual stepper:
[manual_stepper my_stepper]
step_pin: PC15
dir_pin: PA8
enable_pin: !PC13
microsteps: 16
rotation_distance: 360
velocity: 100
acceleration: 1000
endstop_pin: ^PB11
position_endstop: 0 ; These are not documented
homing_speed: 50 ;

[tmc2209 manual_stepper my_stepper]
uart_pin: PC14
running_current: 0.580
stealthchop_threshold: 999999

For this I use 2 macros:
[gcode_macro A0]
gcode:.
MANUAL_STEPPER STEPPER=my_stepper ENABLE=1 SPEED=100 SET_POSITION=330 MOVE=0 STOP_ON_ENDSTOP=1 # HomingSET_POSITION=330 MOVE=0 STOP_ON_ENDSTOP=1 # Homing
MANUAL_STEPPER STEPPER=my_stepper SET_POSITION=0 SPEED=100 MOVE=20
{% if (‘D’ in params) and (params.D|float <= 320) and (params.D|float >= 0) %}
MANUAL_STEPPER STEPPER=my_stepper SPEED=200 MOVE={params.D}
{% endif %}

[gcode_macro A1]
gcode: .
{% if (‘D’ in params) and (params.D|float <= 320) and (params.D|float >= 0) %}
MANUAL_STEPPER STEPPER=my_stepper SPEED=200 MOVE={params.D}
{% endif %}

I’m trying to get it to use only 1 macro. If the stepper is active, it can move to a new position. But if it is not active, it must perform homing first. On this page it might be what I need, but I lack examples. (It is easier to ‘borrow’ what others have done before). Is there a solution? I hope I have explained this well enough, my English could be better.

I managed to figure it out myself, eventually.

And what was the solution?

Yes:

[gcode_macro A0]
gcode:
  {% if ('D' in params) and (params.D|float > 320) and (params.D|float >= 0) %}
    MANUAL_STEPPER STEPPER=my_stepper ENABLE=0                                                          ; Disables
    {% else %}
    {% if printer['tmc2209 manual_stepper my_stepper'].drv_status == None %}
      MANUAL_STEPPER STEPPER=my_stepper ENABLE=1 SPEED=100 SET_POSITION=330 MOVE=0 STOP_ON_ENDSTOP=1	; Homing with bump
      MANUAL_STEPPER STEPPER=my_stepper SPEED=100 MOVE=20
    {% endif %}
    {% if ('D' in params) and (params.D|float <= 320) and (params.D|float >= 0) %}
      MANUAL_STEPPER STEPPER=my_stepper SPEED=200 MOVE={params.D}                                       ; Moves
    {% endif %}
  {% endif %}