123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619 |
- #include "Marlin.h"
- #include "stepper.h"
- #include "endstops.h"
- #include "planner.h"
- #include "temperature.h"
- #include "ultralcd.h"
- #include "language.h"
- #include "cardreader.h"
- #include "speed_lookuptable.h"
- #include "delay.h"
- #if HAS_DIGIPOTSS
- #include <SPI.h>
- #endif
- Stepper stepper;
- #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- bool Stepper::homing_dual_axis = false;
- #endif
- #if HAS_MOTOR_CURRENT_PWM
- uint32_t Stepper::motor_current_setting[3];
- #endif
- block_t* Stepper::current_block = NULL;
- uint8_t Stepper::last_direction_bits = 0,
- Stepper::axis_did_move;
- bool Stepper::abort_current_block;
- #if DISABLED(MIXING_EXTRUDER)
- uint8_t Stepper::last_moved_extruder = 0xFF;
- #endif
- #if ENABLED(X_DUAL_ENDSTOPS)
- bool Stepper::locked_X_motor = false, Stepper::locked_X2_motor = false;
- #endif
- #if ENABLED(Y_DUAL_ENDSTOPS)
- bool Stepper::locked_Y_motor = false, Stepper::locked_Y2_motor = false;
- #endif
- #if ENABLED(Z_DUAL_ENDSTOPS)
- bool Stepper::locked_Z_motor = false, Stepper::locked_Z2_motor = false;
- #endif
- uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
- uint8_t Stepper::steps_per_isr;
- #if DISABLED(ADAPTIVE_STEP_SMOOTHING)
- constexpr
- #endif
- uint8_t Stepper::oversampling_factor;
- int32_t Stepper::delta_error[NUM_AXIS] = { 0 };
- uint32_t Stepper::advance_dividend[NUM_AXIS] = { 0 },
- Stepper::advance_divisor = 0,
- Stepper::step_events_completed = 0,
- Stepper::accelerate_until,
- Stepper::decelerate_after,
- Stepper::step_event_count;
- #if ENABLED(MIXING_EXTRUDER)
- int32_t Stepper::delta_error_m[MIXING_STEPPERS];
- uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
- Stepper::advance_divisor_m;
- #else
- int8_t Stepper::active_extruder;
- #endif
- #if ENABLED(S_CURVE_ACCELERATION)
- int32_t __attribute__((used)) Stepper::bezier_A __asm__("bezier_A");
- int32_t __attribute__((used)) Stepper::bezier_B __asm__("bezier_B");
- int32_t __attribute__((used)) Stepper::bezier_C __asm__("bezier_C");
- uint32_t __attribute__((used)) Stepper::bezier_F __asm__("bezier_F");
- uint32_t __attribute__((used)) Stepper::bezier_AV __asm__("bezier_AV");
- bool __attribute__((used)) Stepper::A_negative __asm__("A_negative");
- bool Stepper::bezier_2nd_half;
- #endif
- uint32_t Stepper::nextMainISR = 0;
- #if ENABLED(LIN_ADVANCE)
- constexpr uint32_t LA_ADV_NEVER = 0xFFFFFFFF;
- uint32_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
- Stepper::LA_isr_rate = LA_ADV_NEVER;
- uint16_t Stepper::LA_current_adv_steps = 0,
- Stepper::LA_final_adv_steps,
- Stepper::LA_max_adv_steps;
- int8_t Stepper::LA_steps = 0;
- bool Stepper::LA_use_advance_lead;
- #endif
- int32_t Stepper::ticks_nominal = -1;
- #if DISABLED(S_CURVE_ACCELERATION)
- uint32_t Stepper::acc_step_rate;
- #endif
- volatile int32_t Stepper::endstops_trigsteps[XYZ],
- Stepper::count_position[NUM_AXIS] = { 0 };
- int8_t Stepper::count_direction[NUM_AXIS] = {
- 1, 1, 1, 1
- #if ENABLED(HANGPRINTER)
- , 1
- #endif
- };
- #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- #define DUAL_ENDSTOP_APPLY_STEP(A,V) \
- if (homing_dual_axis) { \
- if (A##_HOME_DIR < 0) { \
- if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
- if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
- } \
- else { \
- if (!(TEST(endstops.state(), A##_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
- if (!(TEST(endstops.state(), A##2_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
- } \
- } \
- else { \
- A##_STEP_WRITE(V); \
- A##2_STEP_WRITE(V); \
- }
- #endif
- #if ENABLED(X_DUAL_STEPPER_DRIVERS)
- #define X_APPLY_DIR(v,Q) do{ X_DIR_WRITE(v); X2_DIR_WRITE((v) != INVERT_X2_VS_X_DIR); }while(0)
- #if ENABLED(X_DUAL_ENDSTOPS)
- #define X_APPLY_STEP(v,Q) DUAL_ENDSTOP_APPLY_STEP(X,v)
- #else
- #define X_APPLY_STEP(v,Q) do{ X_STEP_WRITE(v); X2_STEP_WRITE(v); }while(0)
- #endif
- #elif ENABLED(DUAL_X_CARRIAGE)
- #define X_APPLY_DIR(v,ALWAYS) \
- if (extruder_duplication_enabled || ALWAYS) { \
- X_DIR_WRITE(v); \
- X2_DIR_WRITE(v); \
- } \
- else { \
- if (movement_extruder()) X2_DIR_WRITE(v); else X_DIR_WRITE(v); \
- }
- #define X_APPLY_STEP(v,ALWAYS) \
- if (extruder_duplication_enabled || ALWAYS) { \
- X_STEP_WRITE(v); \
- X2_STEP_WRITE(v); \
- } \
- else { \
- if (movement_extruder()) X2_STEP_WRITE(v); else X_STEP_WRITE(v); \
- }
- #else
- #define X_APPLY_DIR(v,Q) X_DIR_WRITE(v)
- #define X_APPLY_STEP(v,Q) X_STEP_WRITE(v)
- #endif
- #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
- #define Y_APPLY_DIR(v,Q) do{ Y_DIR_WRITE(v); Y2_DIR_WRITE((v) != INVERT_Y2_VS_Y_DIR); }while(0)
- #if ENABLED(Y_DUAL_ENDSTOPS)
- #define Y_APPLY_STEP(v,Q) DUAL_ENDSTOP_APPLY_STEP(Y,v)
- #else
- #define Y_APPLY_STEP(v,Q) do{ Y_STEP_WRITE(v); Y2_STEP_WRITE(v); }while(0)
- #endif
- #else
- #define Y_APPLY_DIR(v,Q) Y_DIR_WRITE(v)
- #define Y_APPLY_STEP(v,Q) Y_STEP_WRITE(v)
- #endif
- #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
- #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }while(0)
- #if ENABLED(Z_DUAL_ENDSTOPS)
- #define Z_APPLY_STEP(v,Q) DUAL_ENDSTOP_APPLY_STEP(Z,v)
- #else
- #define Z_APPLY_STEP(v,Q) do{ Z_STEP_WRITE(v); Z2_STEP_WRITE(v); }while(0)
- #endif
- #else
- #define Z_APPLY_DIR(v,Q) Z_DIR_WRITE(v)
- #define Z_APPLY_STEP(v,Q) Z_STEP_WRITE(v)
- #endif
- #if ENABLED(HANGPRINTER)
- #define A_APPLY_DIR(v,Q) X_APPLY_DIR(v,Q)
- #define A_APPLY_STEP(v,Q) X_APPLY_STEP(v,Q)
- #define B_APPLY_DIR(v,Q) Y_APPLY_DIR(v,Q)
- #define B_APPLY_STEP(v,Q) Y_APPLY_STEP(v,Q)
- #define C_APPLY_DIR(v,Q) Z_APPLY_DIR(v,Q)
- #define C_APPLY_STEP(v,Q) Z_APPLY_STEP(v,Q)
- #define __D_APPLY(I,T,v) E##I##_##T##_WRITE(v)
- #define _D_APPLY(I,T,v) __D_APPLY(I,T,v)
- #define D_APPLY_DIR(v,Q) _D_APPLY(EXTRUDERS, DIR, v)
- #define D_APPLY_STEP(v,Q) _D_APPLY(EXTRUDERS, STEP, v)
- #endif
- #if DISABLED(MIXING_EXTRUDER)
- #define E_APPLY_STEP(v,Q) E_STEP_WRITE(active_extruder, v)
- #endif
- static FORCE_INLINE uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2) {
- register uint8_t tmp1;
- register uint8_t tmp2;
- register uint16_t intRes;
- __asm__ __volatile__(
- A("clr %[tmp1]")
- A("mul %A[longIn1], %B[longIn2]")
- A("mov %[tmp2], r1")
- A("mul %B[longIn1], %C[longIn2]")
- A("movw %A[intRes], r0")
- A("mul %C[longIn1], %C[longIn2]")
- A("add %B[intRes], r0")
- A("mul %C[longIn1], %B[longIn2]")
- A("add %A[intRes], r0")
- A("adc %B[intRes], r1")
- A("mul %A[longIn1], %C[longIn2]")
- A("add %[tmp2], r0")
- A("adc %A[intRes], r1")
- A("adc %B[intRes], %[tmp1]")
- A("mul %B[longIn1], %B[longIn2]")
- A("add %[tmp2], r0")
- A("adc %A[intRes], r1")
- A("adc %B[intRes], %[tmp1]")
- A("mul %C[longIn1], %A[longIn2]")
- A("add %[tmp2], r0")
- A("adc %A[intRes], r1")
- A("adc %B[intRes], %[tmp1]")
- A("mul %B[longIn1], %A[longIn2]")
- A("add %[tmp2], r1")
- A("adc %A[intRes], %[tmp1]")
- A("adc %B[intRes], %[tmp1]")
- A("lsr %[tmp2]")
- A("adc %A[intRes], %[tmp1]")
- A("adc %B[intRes], %[tmp1]")
- A("mul %D[longIn2], %A[longIn1]")
- A("add %A[intRes], r0")
- A("adc %B[intRes], r1")
- A("mul %D[longIn2], %B[longIn1]")
- A("add %B[intRes], r0")
- A("clr r1")
- : [intRes] "=&r" (intRes),
- [tmp1] "=&r" (tmp1),
- [tmp2] "=&r" (tmp2)
- : [longIn1] "d" (longIn1),
- [longIn2] "d" (longIn2)
- : "cc"
- );
- return intRes;
- }
- void Stepper::wake_up() {
-
- ENABLE_STEPPER_DRIVER_INTERRUPT();
- }
- void Stepper::set_directions() {
- #define SET_STEP_DIR(A) \
- if (motor_direction(_AXIS(A))) { \
- A##_APPLY_DIR(INVERT_## A##_DIR, false); \
- count_direction[_AXIS(A)] = -1; \
- } \
- else { \
- A##_APPLY_DIR(!INVERT_## A##_DIR, false); \
- count_direction[_AXIS(A)] = 1; \
- }
- #if HAS_X_DIR
- SET_STEP_DIR(X);
- #endif
- #if HAS_Y_DIR
- SET_STEP_DIR(Y);
- #endif
- #if HAS_Z_DIR
- SET_STEP_DIR(Z);
- #endif
- #if ENABLED(HANGPRINTER)
- SET_STEP_DIR(D);
- #endif
- #if DISABLED(LIN_ADVANCE)
- #if ENABLED(MIXING_EXTRUDER)
- if (motor_direction(E_AXIS)) {
- MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
- count_direction[E_AXIS] = -1;
- }
- else {
- MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
- count_direction[E_AXIS] = 1;
- }
- #else
- if (motor_direction(E_AXIS)) {
- REV_E_DIR(active_extruder);
- count_direction[E_AXIS] = -1;
- }
- else {
- NORM_E_DIR(active_extruder);
- count_direction[E_AXIS] = 1;
- }
- #endif
- #endif
-
- #if MINIMUM_STEPPER_DIR_DELAY > 0
- DELAY_NS(MINIMUM_STEPPER_DIR_DELAY);
- #endif
- }
- #if ENABLED(S_CURVE_ACCELERATION)
-
-
- void Stepper::_calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av) {
-
- bezier_AV = av;
-
- register uint8_t r2 = v0 & 0xFF;
- register uint8_t r3 = (v0 >> 8) & 0xFF;
- register uint8_t r12 = (v0 >> 16) & 0xFF;
- register uint8_t r5 = v1 & 0xFF;
- register uint8_t r6 = (v1 >> 8) & 0xFF;
- register uint8_t r7 = (v1 >> 16) & 0xFF;
- register uint8_t r4,r8,r9,r10,r11;
- __asm__ __volatile__(
-
-
-
-
-
-
-
- A("sts bezier_F, %0")
- A("sts bezier_F+1, %1")
- A("sts bezier_F+2, %10")
-
- A("ldi %2,-1")
- A("clr %8")
- A("sub %0,%3")
- A("sbc %1,%4")
- A("sbc %10,%5")
- A("brcc 1f")
-
- A("com %10")
- A("com %1")
- A("neg %0")
- A("sbc %1,%2")
- A("sbc %10,%2")
- A("clr %2")
-
- L("1")
- A("sts A_negative, %2")
-
- A("ldi %9,6")
- A("mul %0,%9")
- A("sts bezier_A, r0")
- A("mov %6,r1")
- A("clr %7")
- A("mul %1,%9")
- A("add %6,r0")
- A("adc %7,r1")
- A("mul %10,%9")
- A("add %7,r0")
- A("sts bezier_A+1, %6")
- A("sts bezier_A+2, %7")
- A("ldi %9,15")
- A("mul %0,%9")
- A("sts bezier_B, r0")
- A("mov %6,r1")
- A("clr %7")
- A("mul %1,%9")
- A("add %6,r0")
- A("adc %7,r1")
- A("mul %10,%9")
- A("add %7,r0")
- A("sts bezier_B+1, %6")
- A("sts bezier_B+2, %7")
- A("ldi %9,10")
- A("mul %0,%9")
- A("sts bezier_C, r0")
- A("mov %6,r1")
- A("clr %7")
- A("mul %1,%9")
- A("add %6,r0")
- A("adc %7,r1")
- A("mul %10,%9")
- A("add %7,r0")
- A("sts bezier_C+1, %6")
- " sts bezier_C+2, %7"
- : "+r" (r2),
- "+d" (r3),
- "=r" (r4),
- "+r" (r5),
- "+r" (r6),
- "+r" (r7),
- "=r" (r8),
- "=r" (r9),
- "=r" (r10),
- "=d" (r11),
- "+r" (r12)
- :
- : "r0", "r1", "cc", "memory"
- );
- }
- FORCE_INLINE int32_t Stepper::_eval_bezier_curve(const uint32_t curr_step) {
-
- if (!curr_step)
- return bezier_F;
- register uint8_t r0 = 0;
- register uint8_t r2 = (curr_step) & 0xFF;
- register uint8_t r3 = (curr_step >> 8) & 0xFF;
- register uint8_t r4 = (curr_step >> 16) & 0xFF;
- register uint8_t r1,r5,r6,r7,r8,r9,r10,r11;
- __asm__ __volatile(
-
- A("lds %9,bezier_AV")
- A("mul %9,%2")
- A("mov %7,r1")
- A("clr %8")
- A("lds %10,bezier_AV+1")
- A("mul %10,%2")
- A("add %7,r0")
- A("adc %8,r1")
- A("lds r1,bezier_AV+2")
- A("mul r1,%2")
- A("add %8,r0")
- A("mul %9,%3")
- A("add %7,r0")
- A("adc %8,r1")
- A("mul %10,%3")
- A("add %8,r0")
- A("mul %9,%4")
- A("add %8,r0")
-
-
- A("mov %5,%7")
- A("mov %6,%8")
-
-
- A("mul %5,%7")
- A("mov %9,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %9,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %9,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
- A("mul %5,%7")
- A("mov %1,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
-
-
- A("clr %9")
- A("lds %2,bezier_F")
- A("lds %3,bezier_F+1")
- A("lds %4,bezier_F+2")
-
- A("lds r0,A_negative")
- A("or r0,%0")
- A("brne 3f")
- A("rjmp 1f")
-
-
-
- L("3")
- A("lds %10, bezier_C")
- A("mul %10,%5")
- A("sub %9,r1")
- A("sbc %2,%0")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %11, bezier_C+1")
- A("mul %11,%5")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %1, bezier_C+2")
- A("mul %1,%5")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %10,%6")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("mul %11,%6")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %1,%6")
- A("sub %3,r0")
- A("sbc %4,r1")
-
- A("mul %5,%7")
- A("mov %1,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
-
- A("lds %10, bezier_B")
- A("mul %10,%5")
- A("add %9,r1")
- A("adc %2,%0")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %11, bezier_B+1")
- A("mul %11,%5")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %1, bezier_B+2")
- A("mul %1,%5")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %10,%6")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("mul %11,%6")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %1,%6")
- A("add %3,r0")
- A("adc %4,r1")
-
- A("mul %5,%7")
- A("mov %1,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
-
- A("lds %10, bezier_A")
- A("mul %10,%5")
- A("sub %9,r1")
- A("sbc %2,%0")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %11, bezier_A+1")
- A("mul %11,%5")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %1, bezier_A+2")
- A("mul %1,%5")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %10,%6")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("mul %11,%6")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %1,%6")
- A("sub %3,r0")
- A("sbc %4,r1")
- A("jmp 2f")
- L("1")
-
-
-
- A("lds %10, bezier_C")
- A("mul %10,%5")
- A("add %9,r1")
- A("adc %2,%0")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %11, bezier_C+1")
- A("mul %11,%5")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %1, bezier_C+2")
- A("mul %1,%5")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %10,%6")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("mul %11,%6")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %1,%6")
- A("add %3,r0")
- A("adc %4,r1")
-
- A("mul %5,%7")
- A("mov %1,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
-
- A("lds %10, bezier_B")
- A("mul %10,%5")
- A("sub %9,r1")
- A("sbc %2,%0")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %11, bezier_B+1")
- A("mul %11,%5")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("lds %1, bezier_B+2")
- A("mul %1,%5")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %10,%6")
- A("sub %9,r0")
- A("sbc %2,r1")
- A("sbc %3,%0")
- A("sbc %4,%0")
- A("mul %11,%6")
- A("sub %2,r0")
- A("sbc %3,r1")
- A("sbc %4,%0")
- A("mul %1,%6")
- A("sub %3,r0")
- A("sbc %4,r1")
-
- A("mul %5,%7")
- A("mov %1,r1")
- A("clr %10")
- A("clr %11")
- A("mul %5,%8")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%7")
- A("add %1,r0")
- A("adc %10,r1")
- A("adc %11,%0")
- A("mul %6,%8")
- A("add %10,r0")
- A("adc %11,r1")
- A("mov %5,%10")
- A("mov %6,%11")
-
-
- A("lds %10, bezier_A")
- A("mul %10,%5")
- A("add %9,r1")
- A("adc %2,%0")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %11, bezier_A+1")
- A("mul %11,%5")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("lds %1, bezier_A+2")
- A("mul %1,%5")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %10,%6")
- A("add %9,r0")
- A("adc %2,r1")
- A("adc %3,%0")
- A("adc %4,%0")
- A("mul %11,%6")
- A("add %2,r0")
- A("adc %3,r1")
- A("adc %4,%0")
- A("mul %1,%6")
- A("add %3,r0")
- A("adc %4,r1")
- L("2")
- " clr __zero_reg__"
- : "+r"(r0),
- "+r"(r1),
- "+r"(r2),
- "+r"(r3),
- "+r"(r4),
- "+r"(r5),
- "+r"(r6),
- "+r"(r7),
- "+r"(r8),
- "+r"(r9),
- "+r"(r10),
- "+r"(r11)
- :
- :"cc","r0","r1"
- );
- return (r2 | (uint16_t(r3) << 8)) | (uint32_t(r4) << 16);
- }
- #endif
- HAL_STEP_TIMER_ISR {
- HAL_timer_isr_prologue(STEP_TIMER_NUM);
- Stepper::isr();
- HAL_timer_isr_epilogue(STEP_TIMER_NUM);
- }
- #define STEP_MULTIPLY(A,B) MultiU24X32toH16(A, B)
- void Stepper::isr() {
- DISABLE_ISRS();
-
-
-
- HAL_timer_set_compare(STEP_TIMER_NUM, HAL_TIMER_TYPE_MAX);
-
- hal_timer_t next_isr_ticks = 0;
-
- uint8_t max_loops = 10;
-
- hal_timer_t min_ticks;
- do {
-
- ENABLE_ISRS();
-
- if (!nextMainISR) Stepper::stepper_pulse_phase_isr();
- #if ENABLED(LIN_ADVANCE)
-
- if (!nextAdvanceISR) nextAdvanceISR = Stepper::advance_isr();
- #endif
-
-
- if (!nextMainISR) nextMainISR = Stepper::stepper_block_phase_isr();
- uint32_t interval =
- #if ENABLED(LIN_ADVANCE)
- MIN(nextAdvanceISR, nextMainISR)
- #else
- nextMainISR
- #endif
- ;
-
- NOMORE(interval, HAL_TIMER_TYPE_MAX);
-
- nextMainISR -= interval;
- #if ENABLED(LIN_ADVANCE)
-
- if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
- #endif
-
-
- next_isr_ticks += interval;
-
- DISABLE_ISRS();
-
- min_ticks = HAL_timer_get_count(STEP_TIMER_NUM) + hal_timer_t((STEPPER_TIMER_TICKS_PER_US) * 8);
-
- if (!--max_loops) next_isr_ticks = min_ticks;
-
- } while (next_isr_ticks < min_ticks);
-
-
-
- HAL_timer_set_compare(STEP_TIMER_NUM, hal_timer_t(next_isr_ticks));
-
- ENABLE_ISRS();
- }
- #if ENABLED(UNREGISTERED_MOVE_SUPPORT)
- #define COUNT_IT current_block->count_it
- #else
- #define COUNT_IT true
- #endif
- void Stepper::stepper_pulse_phase_isr() {
-
- if (abort_current_block) {
- abort_current_block = false;
- if (current_block) {
- axis_did_move = 0;
- current_block = NULL;
- planner.discard_current_block();
- }
- }
-
- if (!current_block) return;
-
- const uint32_t pending_events = step_event_count - step_events_completed;
- uint8_t events_to_do = MIN(pending_events, steps_per_isr);
-
- step_events_completed += events_to_do;
-
- hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
- const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
-
- do {
- #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
- #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
-
- #define PULSE_START(AXIS) do{ \
- delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
- if (delta_error[_AXIS(AXIS)] >= 0) { \
- _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); \
- if (COUNT_IT) count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
- } \
- }while(0)
-
- #define PULSE_STOP(AXIS) do { \
- if (delta_error[_AXIS(AXIS)] >= 0) { \
- delta_error[_AXIS(AXIS)] -= advance_divisor; \
- _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0); \
- } \
- }while(0)
-
- #if ENABLED(HANGPRINTER)
- #if HAS_A_STEP
- PULSE_START(A);
- #endif
- #if HAS_B_STEP
- PULSE_START(B);
- #endif
- #if HAS_C_STEP
- PULSE_START(C);
- #endif
- #if HAS_D_STEP
- PULSE_START(D);
- #endif
- #else
- #if HAS_X_STEP
- PULSE_START(X);
- #endif
- #if HAS_Y_STEP
- PULSE_START(Y);
- #endif
- #if HAS_Z_STEP
- PULSE_START(Z);
- #endif
- #endif
-
- #if ENABLED(LIN_ADVANCE)
-
- delta_error[E_AXIS] += advance_dividend[E_AXIS];
- if (delta_error[E_AXIS] >= 0) {
- if (COUNT_IT) count_position[E_AXIS] += count_direction[E_AXIS];
- delta_error[E_AXIS] -= advance_divisor;
-
- motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
- }
- #else
- #if ENABLED(MIXING_EXTRUDER)
-
- delta_error[E_AXIS] += advance_dividend[E_AXIS];
- if (delta_error[E_AXIS] >= 0) {
- if (COUNT_IT) count_position[E_AXIS] += count_direction[E_AXIS];
- delta_error[E_AXIS] -= advance_divisor;
- }
-
- MIXING_STEPPERS_LOOP(j) {
-
- delta_error_m[j] += advance_dividend_m[j];
-
- if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
- }
- #else
- PULSE_START(E);
- #endif
- #endif
- #if MINIMUM_STEPPER_PULSE
-
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { }
- #endif
-
- if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
- #if ENABLED(HANGPRINTER)
- #if HAS_A_STEP
- PULSE_STOP(A);
- #endif
- #if HAS_B_STEP
- PULSE_STOP(B);
- #endif
- #if HAS_C_STEP
- PULSE_STOP(C);
- #endif
- #if HAS_D_STEP
- PULSE_STOP(D);
- #endif
- #else
- #if HAS_X_STEP
- PULSE_STOP(X);
- #endif
- #if HAS_Y_STEP
- PULSE_STOP(Y);
- #endif
- #if HAS_Z_STEP
- PULSE_STOP(Z);
- #endif
- #endif
- #if DISABLED(LIN_ADVANCE)
- #if ENABLED(MIXING_EXTRUDER)
- MIXING_STEPPERS_LOOP(j) {
- if (delta_error_m[j] >= 0) {
- delta_error_m[j] -= advance_divisor_m;
- E_STEP_WRITE(j, INVERT_E_STEP_PIN);
- }
- }
- #else
- PULSE_STOP(E);
- #endif
- #endif
-
- --events_to_do;
-
- if (events_to_do) {
-
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { }
- #if MINIMUM_STEPPER_PULSE
-
- pulse_end += hal_timer_t(MIN_PULSE_TICKS);
- #endif
- }
- } while (events_to_do);
- }
- uint32_t Stepper::stepper_block_phase_isr() {
-
- uint32_t interval = (STEPPER_TIMER_RATE / 1000);
-
- if (current_block) {
-
- if (step_events_completed >= step_event_count) {
- axis_did_move = 0;
- current_block = NULL;
- planner.discard_current_block();
- }
- else {
-
-
- if (step_events_completed <= accelerate_until) {
- #if ENABLED(S_CURVE_ACCELERATION)
-
- uint32_t acc_step_rate =
- acceleration_time < current_block->acceleration_time
- ? _eval_bezier_curve(acceleration_time)
- : current_block->cruise_rate;
- #else
- acc_step_rate = STEP_MULTIPLY(acceleration_time, current_block->acceleration_rate) + current_block->initial_rate;
- NOMORE(acc_step_rate, current_block->nominal_rate);
- #endif
-
-
- interval = calc_timer_interval(acc_step_rate, oversampling_factor, &steps_per_isr);
- acceleration_time += interval;
- #if ENABLED(LIN_ADVANCE)
- if (LA_use_advance_lead) {
-
- if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
- }
- else if (LA_steps) nextAdvanceISR = 0;
- #endif
- }
-
- else if (step_events_completed > decelerate_after) {
- uint32_t step_rate;
- #if ENABLED(S_CURVE_ACCELERATION)
-
- if (!bezier_2nd_half) {
-
- _calc_bezier_curve_coeffs(current_block->cruise_rate, current_block->final_rate, current_block->deceleration_time_inverse);
- bezier_2nd_half = true;
-
- step_rate = current_block->cruise_rate;
- }
- else {
-
- step_rate = deceleration_time < current_block->deceleration_time
- ? _eval_bezier_curve(deceleration_time)
- : current_block->final_rate;
- }
- #else
-
- step_rate = STEP_MULTIPLY(deceleration_time, current_block->acceleration_rate);
- if (step_rate < acc_step_rate) {
- step_rate = acc_step_rate - step_rate;
- NOLESS(step_rate, current_block->final_rate);
- }
- else
- step_rate = current_block->final_rate;
- #endif
-
-
- interval = calc_timer_interval(step_rate, oversampling_factor, &steps_per_isr);
- deceleration_time += interval;
- #if ENABLED(LIN_ADVANCE)
- if (LA_use_advance_lead) {
-
- if (step_events_completed <= decelerate_after + steps_per_isr || (LA_steps && LA_isr_rate != current_block->advance_speed)) {
- nextAdvanceISR = 0;
- LA_isr_rate = current_block->advance_speed;
- }
- }
- else if (LA_steps) nextAdvanceISR = 0;
- #endif
- }
-
- else {
- #if ENABLED(LIN_ADVANCE)
-
- if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
- #endif
-
- if (ticks_nominal < 0) {
-
- ticks_nominal = calc_timer_interval(current_block->nominal_rate, oversampling_factor, &steps_per_isr);
- }
-
- interval = ticks_nominal;
- }
- }
- }
-
-
- if (!current_block) {
-
- if ((current_block = planner.get_current_block())) {
-
- while (TEST(current_block->flag, BLOCK_BIT_SYNC_POSITION)) {
- _set_position(
- current_block->position[A_AXIS], current_block->position[B_AXIS], current_block->position[C_AXIS],
- #if ENABLED(HANGPRINTER)
- current_block->position[D_AXIS],
- #endif
- current_block->position[E_AXIS]
- );
- planner.discard_current_block();
-
- if (!(current_block = planner.get_current_block()))
- return interval;
- }
-
- #if IS_CORE
-
- #define S_(N) current_block->steps[CORE_AXIS_##N]
- #define D_(N) TEST(current_block->direction_bits, CORE_AXIS_##N)
- #endif
- #if CORE_IS_XY || CORE_IS_XZ
-
- #if ENABLED(COREXY) || ENABLED(COREXZ)
- #define X_CMP ==
- #else
- #define X_CMP !=
- #endif
- #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
- #else
- #define X_MOVE_TEST !!current_block->steps[A_AXIS]
- #endif
- #if CORE_IS_XY || CORE_IS_YZ
-
- #if ENABLED(COREYX) || ENABLED(COREYZ)
- #define Y_CMP ==
- #else
- #define Y_CMP !=
- #endif
- #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
- #else
- #define Y_MOVE_TEST !!current_block->steps[B_AXIS]
- #endif
- #if CORE_IS_XZ || CORE_IS_YZ
-
- #if ENABLED(COREZX) || ENABLED(COREZY)
- #define Z_CMP ==
- #else
- #define Z_CMP !=
- #endif
- #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
- #else
- #define Z_MOVE_TEST !!current_block->steps[C_AXIS]
- #endif
- uint8_t axis_bits = 0;
- if (X_MOVE_TEST) SBI(axis_bits, A_AXIS);
- if (Y_MOVE_TEST) SBI(axis_bits, B_AXIS);
- if (Z_MOVE_TEST) SBI(axis_bits, C_AXIS);
-
-
-
-
- axis_did_move = axis_bits;
-
- acceleration_time = deceleration_time = 0;
- uint8_t oversampling = 0;
- #if ENABLED(ADAPTIVE_STEP_SMOOTHING)
-
- uint32_t max_rate = current_block->nominal_rate;
- while (max_rate < MIN_STEP_ISR_FREQUENCY) {
- max_rate <<= 1;
- if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break;
- ++oversampling;
- }
- oversampling_factor = oversampling;
- #endif
-
- step_event_count = current_block->step_event_count << oversampling;
-
- #if ENABLED(HANGPRINTER)
- delta_error[A_AXIS] = delta_error[B_AXIS] = delta_error[C_AXIS] = delta_error[D_AXIS] = delta_error[E_AXIS] = -int32_t(step_event_count);
- #else
- delta_error[X_AXIS] = delta_error[Y_AXIS] = delta_error[Z_AXIS] = delta_error[E_AXIS] = -int32_t(step_event_count);
- #endif
-
- #if ENABLED(HANGPRINTER)
- advance_dividend[A_AXIS] = current_block->steps[A_AXIS] << 1;
- advance_dividend[B_AXIS] = current_block->steps[B_AXIS] << 1;
- advance_dividend[C_AXIS] = current_block->steps[C_AXIS] << 1;
- advance_dividend[D_AXIS] = current_block->steps[D_AXIS] << 1;
- #else
- advance_dividend[X_AXIS] = current_block->steps[X_AXIS] << 1;
- advance_dividend[Y_AXIS] = current_block->steps[Y_AXIS] << 1;
- advance_dividend[Z_AXIS] = current_block->steps[Z_AXIS] << 1;
- #endif
- advance_dividend[E_AXIS] = current_block->steps[E_AXIS] << 1;
-
- advance_divisor = step_event_count << 1;
-
- step_events_completed = 0;
-
- accelerate_until = current_block->accelerate_until << oversampling;
- decelerate_after = current_block->decelerate_after << oversampling;
- #if ENABLED(MIXING_EXTRUDER)
- const uint32_t e_steps = (
- #if ENABLED(LIN_ADVANCE)
- current_block->steps[E_AXIS]
- #else
- step_event_count
- #endif
- );
- MIXING_STEPPERS_LOOP(i) {
- delta_error_m[i] = -int32_t(e_steps);
- advance_dividend_m[i] = current_block->mix_steps[i] << 1;
- }
- advance_divisor_m = e_steps << 1;
- #else
- active_extruder = current_block->active_extruder;
- #endif
-
- #if ENABLED(LIN_ADVANCE)
- #if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
-
- if (active_extruder != last_moved_extruder) LA_current_adv_steps = 0;
- #endif
- if ((LA_use_advance_lead = current_block->use_advance_lead)) {
- LA_final_adv_steps = current_block->final_adv_steps;
- LA_max_adv_steps = current_block->max_adv_steps;
-
- nextAdvanceISR = 0;
- LA_isr_rate = current_block->advance_speed;
- }
- else LA_isr_rate = LA_ADV_NEVER;
- #endif
- if (current_block->direction_bits != last_direction_bits
- #if DISABLED(MIXING_EXTRUDER)
- || active_extruder != last_moved_extruder
- #endif
- ) {
- last_direction_bits = current_block->direction_bits;
- #if DISABLED(MIXING_EXTRUDER)
- last_moved_extruder = active_extruder;
- #endif
- set_directions();
- }
-
-
-
-
-
-
-
- endstops.update();
- #if ENABLED(Z_LATE_ENABLE)
-
-
-
- if (current_block->steps[Z_AXIS]) enable_Z();
- #endif
-
- ticks_nominal = -1;
- #if DISABLED(S_CURVE_ACCELERATION)
-
- acc_step_rate = current_block->initial_rate;
- #endif
- #if ENABLED(S_CURVE_ACCELERATION)
-
- _calc_bezier_curve_coeffs(current_block->initial_rate, current_block->cruise_rate, current_block->acceleration_time_inverse);
-
- bezier_2nd_half = false;
- #endif
-
- interval = calc_timer_interval(current_block->initial_rate, oversampling_factor, &steps_per_isr);
- }
- }
-
- return interval;
- }
- #if ENABLED(LIN_ADVANCE)
-
- uint32_t Stepper::advance_isr() {
- uint32_t interval;
- if (LA_use_advance_lead) {
- if (step_events_completed > decelerate_after && LA_current_adv_steps > LA_final_adv_steps) {
- LA_steps--;
- LA_current_adv_steps--;
- interval = LA_isr_rate;
- }
- else if (step_events_completed < decelerate_after && LA_current_adv_steps < LA_max_adv_steps) {
-
- LA_steps++;
- LA_current_adv_steps++;
- interval = LA_isr_rate;
- }
- else
- interval = LA_isr_rate = LA_ADV_NEVER;
- }
- else
- interval = LA_ADV_NEVER;
- #if ENABLED(MIXING_EXTRUDER)
- if (LA_steps >= 0)
- MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
- else
- MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
- #else
- if (LA_steps >= 0)
- NORM_E_DIR(active_extruder);
- else
- REV_E_DIR(active_extruder);
- #endif
-
- hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
- const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
-
- while (LA_steps) {
-
- #if ENABLED(MIXING_EXTRUDER)
- MIXING_STEPPERS_LOOP(j) {
-
- delta_error_m[j] += advance_dividend_m[j];
-
- if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
- }
- #else
- E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
- #endif
-
- #if MINIMUM_STEPPER_PULSE
-
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { }
- #endif
-
- if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
- LA_steps < 0 ? ++LA_steps : --LA_steps;
-
- #if ENABLED(MIXING_EXTRUDER)
- MIXING_STEPPERS_LOOP(j) {
- if (delta_error_m[j] >= 0) {
- delta_error_m[j] -= advance_divisor_m;
- E_STEP_WRITE(j, INVERT_E_STEP_PIN);
- }
- }
- #else
- E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
- #endif
-
-
- if (LA_steps) {
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { }
- #if MINIMUM_STEPPER_PULSE
-
- pulse_end += hal_timer_t(MIN_PULSE_TICKS);
- #endif
- }
- }
- return interval;
- }
- #endif
- bool Stepper::is_block_busy(const block_t* const block) {
- #define sw_barrier() asm volatile("": : :"memory");
-
-
-
-
-
- block_t* vold, *vnew = current_block;
- sw_barrier();
- do {
- vold = vnew;
- vnew = current_block;
- sw_barrier();
- } while (vold != vnew);
-
- return block == vnew;
- }
- void Stepper::init() {
-
- #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
- digipot_init();
- #endif
-
- #if HAS_MICROSTEPS
- microstep_init();
- #endif
-
- #if HAS_X_DIR
- X_DIR_INIT;
- #endif
- #if HAS_X2_DIR
- X2_DIR_INIT;
- #endif
- #if HAS_Y_DIR
- Y_DIR_INIT;
- #if ENABLED(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_DIR
- Y2_DIR_INIT;
- #endif
- #endif
- #if HAS_Z_DIR
- Z_DIR_INIT;
- #if ENABLED(Z_DUAL_STEPPER_DRIVERS) && HAS_Z2_DIR
- Z2_DIR_INIT;
- #endif
- #endif
- #if HAS_E0_DIR
- E0_DIR_INIT;
- #endif
- #if HAS_E1_DIR
- E1_DIR_INIT;
- #endif
- #if HAS_E2_DIR
- E2_DIR_INIT;
- #endif
- #if HAS_E3_DIR
- E3_DIR_INIT;
- #endif
- #if HAS_E4_DIR
- E4_DIR_INIT;
- #endif
-
- #if HAS_X_ENABLE
- X_ENABLE_INIT;
- if (!X_ENABLE_ON) X_ENABLE_WRITE(HIGH);
- #if (ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS)) && HAS_X2_ENABLE
- X2_ENABLE_INIT;
- if (!X_ENABLE_ON) X2_ENABLE_WRITE(HIGH);
- #endif
- #endif
- #if HAS_Y_ENABLE
- Y_ENABLE_INIT;
- if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
- #if ENABLED(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
- Y2_ENABLE_INIT;
- if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
- #endif
- #endif
- #if HAS_Z_ENABLE
- Z_ENABLE_INIT;
- if (!Z_ENABLE_ON) Z_ENABLE_WRITE(HIGH);
- #if ENABLED(Z_DUAL_STEPPER_DRIVERS) && HAS_Z2_ENABLE
- Z2_ENABLE_INIT;
- if (!Z_ENABLE_ON) Z2_ENABLE_WRITE(HIGH);
- #endif
- #endif
- #if HAS_E0_ENABLE
- E0_ENABLE_INIT;
- if (!E_ENABLE_ON) E0_ENABLE_WRITE(HIGH);
- #endif
- #if HAS_E1_ENABLE
- E1_ENABLE_INIT;
- if (!E_ENABLE_ON) E1_ENABLE_WRITE(HIGH);
- #endif
- #if HAS_E2_ENABLE
- E2_ENABLE_INIT;
- if (!E_ENABLE_ON) E2_ENABLE_WRITE(HIGH);
- #endif
- #if HAS_E3_ENABLE
- E3_ENABLE_INIT;
- if (!E_ENABLE_ON) E3_ENABLE_WRITE(HIGH);
- #endif
- #if HAS_E4_ENABLE
- E4_ENABLE_INIT;
- if (!E_ENABLE_ON) E4_ENABLE_WRITE(HIGH);
- #endif
- #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
- #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
- #define _DISABLE(AXIS) disable_## AXIS()
- #define AXIS_INIT(AXIS, PIN) \
- _STEP_INIT(AXIS); \
- _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
- _DISABLE(AXIS)
- #define E_AXIS_INIT(NUM) AXIS_INIT(E## NUM, E)
-
- #if HAS_X_STEP
- #if ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)
- X2_STEP_INIT;
- X2_STEP_WRITE(INVERT_X_STEP_PIN);
- #endif
- AXIS_INIT(X, X);
- #endif
- #if HAS_Y_STEP
- #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
- Y2_STEP_INIT;
- Y2_STEP_WRITE(INVERT_Y_STEP_PIN);
- #endif
- AXIS_INIT(Y, Y);
- #endif
- #if HAS_Z_STEP
- #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
- Z2_STEP_INIT;
- Z2_STEP_WRITE(INVERT_Z_STEP_PIN);
- #endif
- AXIS_INIT(Z, Z);
- #endif
- #if E_STEPPERS > 0 && HAS_E0_STEP
- E_AXIS_INIT(0);
- #endif
- #if (E_STEPPERS > 1 || (E_STEPPERS == 1 && ENABLED(HANGPRINTER))) && HAS_E1_STEP
- E_AXIS_INIT(1);
- #endif
- #if (E_STEPPERS > 2 || (E_STEPPERS == 2 && ENABLED(HANGPRINTER))) && HAS_E2_STEP
- E_AXIS_INIT(2);
- #endif
- #if (E_STEPPERS > 3 || (E_STEPPERS == 3 && ENABLED(HANGPRINTER))) && HAS_E3_STEP
- E_AXIS_INIT(3);
- #endif
- #if (E_STEPPERS > 4 || (E_STEPPERS == 4 && ENABLED(HANGPRINTER))) && HAS_E4_STEP
- E_AXIS_INIT(4);
- #endif
-
- HAL_timer_start(STEP_TIMER_NUM, 122);
- ENABLE_STEPPER_DRIVER_INTERRUPT();
- endstops.enable(true);
- sei();
- set_directions();
- }
- void Stepper::_set_position(const int32_t &a, const int32_t &b, const int32_t &c,
- #if ENABLED(HANGPRINTER)
- const int32_t &d,
- #endif
- const int32_t &e
- ) {
- #if CORE_IS_XY
-
-
- count_position[A_AXIS] = a + b;
- count_position[B_AXIS] = CORESIGN(a - b);
- count_position[Z_AXIS] = c;
- #elif CORE_IS_XZ
-
- count_position[A_AXIS] = a + c;
- count_position[Y_AXIS] = b;
- count_position[C_AXIS] = CORESIGN(a - c);
- #elif CORE_IS_YZ
-
- count_position[X_AXIS] = a;
- count_position[B_AXIS] = b + c;
- count_position[C_AXIS] = CORESIGN(b - c);
- #else
-
- count_position[X_AXIS] = a;
- count_position[Y_AXIS] = b;
- count_position[Z_AXIS] = c;
- #if ENABLED(HANGPRINTER)
- count_position[D_AXIS] = d;
- #endif
- #endif
- count_position[E_AXIS] = e;
- }
- int32_t Stepper::position(const AxisEnum axis) {
- const bool was_enabled = STEPPER_ISR_ENABLED();
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
- const int32_t v = count_position[axis];
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
- return v;
- }
- void Stepper::endstop_triggered(const AxisEnum axis) {
- const bool was_enabled = STEPPER_ISR_ENABLED();
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
- #if IS_CORE
- endstops_trigsteps[axis] = 0.5f * (
- axis == CORE_AXIS_2 ? CORESIGN(count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2])
- : count_position[CORE_AXIS_1] + count_position[CORE_AXIS_2]
- );
- #else
- endstops_trigsteps[axis] = count_position[axis];
- #endif
-
- quick_stop();
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
- }
- int32_t Stepper::triggered_position(const AxisEnum axis) {
- const bool was_enabled = STEPPER_ISR_ENABLED();
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
- const int32_t v = endstops_trigsteps[axis];
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
- return v;
- }
- void Stepper::report_positions() {
-
- const bool was_enabled = STEPPER_ISR_ENABLED();
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
- const int32_t xpos = count_position[X_AXIS],
- ypos = count_position[Y_AXIS],
- #if ENABLED(HANGPRINTER)
- dpos = count_position[D_AXIS],
- #endif
- zpos = count_position[Z_AXIS];
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
- #if CORE_IS_XY || CORE_IS_XZ || IS_DELTA || IS_SCARA || ENABLED(HANGPRINTER)
- SERIAL_PROTOCOLPGM(MSG_COUNT_A);
- #else
- SERIAL_PROTOCOLPGM(MSG_COUNT_X);
- #endif
- SERIAL_PROTOCOL(xpos);
- #if CORE_IS_XY || CORE_IS_YZ || IS_DELTA || IS_SCARA || ENABLED(HANGPRINTER)
- SERIAL_PROTOCOLPGM(" B:");
- #else
- SERIAL_PROTOCOLPGM(" Y:");
- #endif
- SERIAL_PROTOCOL(ypos);
- #if CORE_IS_XZ || CORE_IS_YZ || IS_DELTA || ENABLED(HANGPRINTER)
- SERIAL_PROTOCOLPGM(" C:");
- #else
- SERIAL_PROTOCOLPGM(" Z:");
- #endif
- SERIAL_PROTOCOL(zpos);
- #if ENABLED(HANGPRINTER)
- SERIAL_PROTOCOLPAIR(" D:", dpos);
- #endif
- SERIAL_EOL();
- }
- #if ENABLED(BABYSTEPPING)
- #if MINIMUM_STEPPER_PULSE
- #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
- #else
- #define STEP_PULSE_CYCLES 0
- #endif
- #if ENABLED(DELTA)
- #define CYCLES_EATEN_BABYSTEP (2 * 15)
- #else
- #define CYCLES_EATEN_BABYSTEP 0
- #endif
- #define EXTRA_CYCLES_BABYSTEP (STEP_PULSE_CYCLES - (CYCLES_EATEN_BABYSTEP))
- #define _ENABLE(AXIS) enable_## AXIS()
- #define _READ_DIR(AXIS) AXIS ##_DIR_READ
- #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
- #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
- #if EXTRA_CYCLES_BABYSTEP > 20
- #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM)
- #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { }
- #else
- #define _SAVE_START NOOP
- #if EXTRA_CYCLES_BABYSTEP > 0
- #define _PULSE_WAIT DELAY_NS(EXTRA_CYCLES_BABYSTEP * NANOSECONDS_PER_CYCLE)
- #elif STEP_PULSE_CYCLES > 0
- #define _PULSE_WAIT NOOP
- #elif ENABLED(DELTA)
- #define _PULSE_WAIT DELAY_US(2);
- #else
- #define _PULSE_WAIT DELAY_US(4);
- #endif
- #endif
- #define BABYSTEP_AXIS(AXIS, INVERT, DIR) { \
- const uint8_t old_dir = _READ_DIR(AXIS); \
- _ENABLE(AXIS); \
- _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^DIR^INVERT); \
- DELAY_NS(MINIMUM_STEPPER_DIR_DELAY); \
- _SAVE_START; \
- _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
- _PULSE_WAIT; \
- _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
- _APPLY_DIR(AXIS, old_dir); \
- }
-
-
- void Stepper::babystep(const AxisEnum axis, const bool direction) {
- cli();
- switch (axis) {
- #if ENABLED(BABYSTEP_XY)
- case X_AXIS:
- #if CORE_IS_XY
- BABYSTEP_AXIS(X, false, direction);
- BABYSTEP_AXIS(Y, false, direction);
- #elif CORE_IS_XZ
- BABYSTEP_AXIS(X, false, direction);
- BABYSTEP_AXIS(Z, false, direction);
- #else
- BABYSTEP_AXIS(X, false, direction);
- #endif
- break;
- case Y_AXIS:
- #if CORE_IS_XY
- BABYSTEP_AXIS(X, false, direction);
- BABYSTEP_AXIS(Y, false, direction^(CORESIGN(1)<0));
- #elif CORE_IS_YZ
- BABYSTEP_AXIS(Y, false, direction);
- BABYSTEP_AXIS(Z, false, direction^(CORESIGN(1)<0));
- #else
- BABYSTEP_AXIS(Y, false, direction);
- #endif
- break;
- #endif
- case Z_AXIS: {
- #if CORE_IS_XZ
- BABYSTEP_AXIS(X, BABYSTEP_INVERT_Z, direction);
- BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z, direction^(CORESIGN(1)<0));
- #elif CORE_IS_YZ
- BABYSTEP_AXIS(Y, BABYSTEP_INVERT_Z, direction);
- BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z, direction^(CORESIGN(1)<0));
- #elif DISABLED(DELTA)
- BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z, direction);
- #else
- const bool z_direction = direction ^ BABYSTEP_INVERT_Z;
- enable_X();
- enable_Y();
- enable_Z();
- const uint8_t old_x_dir_pin = X_DIR_READ,
- old_y_dir_pin = Y_DIR_READ,
- old_z_dir_pin = Z_DIR_READ;
- X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
- Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
- Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
- #if MINIMUM_STEPPER_DIR_DELAY > 0
- DELAY_NS(MINIMUM_STEPPER_DIR_DELAY);
- #endif
- _SAVE_START;
- X_STEP_WRITE(!INVERT_X_STEP_PIN);
- Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
- Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
- _PULSE_WAIT;
- X_STEP_WRITE(INVERT_X_STEP_PIN);
- Y_STEP_WRITE(INVERT_Y_STEP_PIN);
- Z_STEP_WRITE(INVERT_Z_STEP_PIN);
-
- X_DIR_WRITE(old_x_dir_pin);
- Y_DIR_WRITE(old_y_dir_pin);
- Z_DIR_WRITE(old_z_dir_pin);
- #endif
- } break;
- default: break;
- }
- sei();
- }
- #endif
- #if HAS_DIGIPOTSS
-
- void Stepper::digitalPotWrite(const int16_t address, const int16_t value) {
- WRITE(DIGIPOTSS_PIN, LOW);
- SPI.transfer(address);
- SPI.transfer(value);
- WRITE(DIGIPOTSS_PIN, HIGH);
-
- }
- #endif
- #if HAS_MOTOR_CURRENT_PWM
- void Stepper::refresh_motor_power() {
- for (uint8_t i = 0; i < COUNT(motor_current_setting); ++i) {
- switch (i) {
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
- case 0:
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
- case 1:
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
- case 2:
- #endif
- digipot_current(i, motor_current_setting[i]);
- default: break;
- }
- }
- }
- #endif
- #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
- void Stepper::digipot_current(const uint8_t driver, const int current) {
- #if HAS_DIGIPOTSS
- const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
- digitalPotWrite(digipot_ch[driver], current);
- #elif HAS_MOTOR_CURRENT_PWM
- if (WITHIN(driver, 0, 2))
- motor_current_setting[driver] = current;
- #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
- switch (driver) {
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
- case 0: _WRITE_CURRENT_PWM(XY); break;
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
- case 1: _WRITE_CURRENT_PWM(Z); break;
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
- case 2: _WRITE_CURRENT_PWM(E); break;
- #endif
- }
- #endif
- }
- void Stepper::digipot_init() {
- #if HAS_DIGIPOTSS
- static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
- SPI.begin();
- SET_OUTPUT(DIGIPOTSS_PIN);
- for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
-
- digipot_current(i, digipot_motor_current[i]);
- }
- #elif HAS_MOTOR_CURRENT_PWM
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
- SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
- SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
- #endif
- #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
- SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
- #endif
- refresh_motor_power();
-
- SET_CS5(PRESCALER_1);
- #endif
- }
- #endif
- #if HAS_MICROSTEPS
-
- void Stepper::microstep_init() {
- SET_OUTPUT(X_MS1_PIN);
- SET_OUTPUT(X_MS2_PIN);
- #if HAS_Y_MICROSTEPS
- SET_OUTPUT(Y_MS1_PIN);
- SET_OUTPUT(Y_MS2_PIN);
- #endif
- #if HAS_Z_MICROSTEPS
- SET_OUTPUT(Z_MS1_PIN);
- SET_OUTPUT(Z_MS2_PIN);
- #endif
- #if HAS_E0_MICROSTEPS
- SET_OUTPUT(E0_MS1_PIN);
- SET_OUTPUT(E0_MS2_PIN);
- #endif
- #if HAS_E1_MICROSTEPS
- SET_OUTPUT(E1_MS1_PIN);
- SET_OUTPUT(E1_MS2_PIN);
- #endif
- #if HAS_E2_MICROSTEPS
- SET_OUTPUT(E2_MS1_PIN);
- SET_OUTPUT(E2_MS2_PIN);
- #endif
- #if HAS_E3_MICROSTEPS
- SET_OUTPUT(E3_MS1_PIN);
- SET_OUTPUT(E3_MS2_PIN);
- #endif
- #if HAS_E4_MICROSTEPS
- SET_OUTPUT(E4_MS1_PIN);
- SET_OUTPUT(E4_MS2_PIN);
- #endif
- static const uint8_t microstep_modes[] = MICROSTEP_MODES;
- for (uint16_t i = 0; i < COUNT(microstep_modes); i++)
- microstep_mode(i, microstep_modes[i]);
- }
- void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2) {
- if (ms1 >= 0) switch (driver) {
- case 0: WRITE(X_MS1_PIN, ms1); break;
- #if HAS_Y_MICROSTEPS
- case 1: WRITE(Y_MS1_PIN, ms1); break;
- #endif
- #if HAS_Z_MICROSTEPS
- case 2: WRITE(Z_MS1_PIN, ms1); break;
- #endif
- #if HAS_E0_MICROSTEPS
- case 3: WRITE(E0_MS1_PIN, ms1); break;
- #endif
- #if HAS_E1_MICROSTEPS
- case 4: WRITE(E1_MS1_PIN, ms1); break;
- #endif
- #if HAS_E2_MICROSTEPS
- case 5: WRITE(E2_MS1_PIN, ms1); break;
- #endif
- #if HAS_E3_MICROSTEPS
- case 6: WRITE(E3_MS1_PIN, ms1); break;
- #endif
- #if HAS_E4_MICROSTEPS
- case 7: WRITE(E4_MS1_PIN, ms1); break;
- #endif
- }
- if (ms2 >= 0) switch (driver) {
- case 0: WRITE(X_MS2_PIN, ms2); break;
- #if HAS_Y_MICROSTEPS
- case 1: WRITE(Y_MS2_PIN, ms2); break;
- #endif
- #if HAS_Z_MICROSTEPS
- case 2: WRITE(Z_MS2_PIN, ms2); break;
- #endif
- #if HAS_E0_MICROSTEPS
- case 3: WRITE(E0_MS2_PIN, ms2); break;
- #endif
- #if HAS_E1_MICROSTEPS
- case 4: WRITE(E1_MS2_PIN, ms2); break;
- #endif
- #if HAS_E2_MICROSTEPS
- case 5: WRITE(E2_MS2_PIN, ms2); break;
- #endif
- #if HAS_E3_MICROSTEPS
- case 6: WRITE(E3_MS2_PIN, ms2); break;
- #endif
- #if HAS_E4_MICROSTEPS
- case 7: WRITE(E4_MS2_PIN, ms2); break;
- #endif
- }
- }
- void Stepper::microstep_mode(const uint8_t driver, const uint8_t stepping_mode) {
- switch (stepping_mode) {
- case 1: microstep_ms(driver, MICROSTEP1); break;
- #if ENABLED(HEROIC_STEPPER_DRIVERS)
- case 128: microstep_ms(driver, MICROSTEP128); break;
- #else
- case 2: microstep_ms(driver, MICROSTEP2); break;
- case 4: microstep_ms(driver, MICROSTEP4); break;
- #endif
- case 8: microstep_ms(driver, MICROSTEP8); break;
- case 16: microstep_ms(driver, MICROSTEP16); break;
- default: SERIAL_ERROR_START(); SERIAL_ERRORLNPGM("Microsteps unavailable"); break;
- }
- }
- void Stepper::microstep_readings() {
- SERIAL_PROTOCOLLNPGM("MS1,MS2 Pins");
- SERIAL_PROTOCOLPGM("X: ");
- SERIAL_PROTOCOL(READ(X_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(X_MS2_PIN));
- #if HAS_Y_MICROSTEPS
- SERIAL_PROTOCOLPGM("Y: ");
- SERIAL_PROTOCOL(READ(Y_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(Y_MS2_PIN));
- #endif
- #if HAS_Z_MICROSTEPS
- SERIAL_PROTOCOLPGM("Z: ");
- SERIAL_PROTOCOL(READ(Z_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(Z_MS2_PIN));
- #endif
- #if HAS_E0_MICROSTEPS
- SERIAL_PROTOCOLPGM("E0: ");
- SERIAL_PROTOCOL(READ(E0_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(E0_MS2_PIN));
- #endif
- #if HAS_E1_MICROSTEPS
- SERIAL_PROTOCOLPGM("E1: ");
- SERIAL_PROTOCOL(READ(E1_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(E1_MS2_PIN));
- #endif
- #if HAS_E2_MICROSTEPS
- SERIAL_PROTOCOLPGM("E2: ");
- SERIAL_PROTOCOL(READ(E2_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(E2_MS2_PIN));
- #endif
- #if HAS_E3_MICROSTEPS
- SERIAL_PROTOCOLPGM("E3: ");
- SERIAL_PROTOCOL(READ(E3_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(E3_MS2_PIN));
- #endif
- #if HAS_E4_MICROSTEPS
- SERIAL_PROTOCOLPGM("E4: ");
- SERIAL_PROTOCOL(READ(E4_MS1_PIN));
- SERIAL_PROTOCOLLN(READ(E4_MS2_PIN));
- #endif
- }
- #endif
|