diff --git a/firmware/axl-stepper/src/axl b/firmware/axl-stepper/src/axl index bda32c5b94c68a6f674d8ccac94a9abf4524e9d5..3d62ffa48024d7c43844653dac7199f1bbacc254 160000 --- a/firmware/axl-stepper/src/axl +++ b/firmware/axl-stepper/src/axl @@ -1 +1 @@ -Subproject commit bda32c5b94c68a6f674d8ccac94a9abf4524e9d5 +Subproject commit 3d62ffa48024d7c43844653dac7199f1bbacc254 diff --git a/firmware/axl-stepper/src/main.cpp b/firmware/axl-stepper/src/main.cpp index 6882870d09073fbf01ebd9ab2d86eb1786e47c83..ca8e66d52be6b65080829c07dd9fe3a8a464fd25 100644 --- a/firmware/axl-stepper/src/main.cpp +++ b/firmware/axl-stepper/src/main.cpp @@ -20,8 +20,8 @@ //OSAP osap("axl-stepper_y-right"); //OSAP osap("axl-stepper_x"); //OSAP osap("axl-stepper_e"); -// OSAP osap("axl-stepper_z"); -OSAP osap("axl-stepper_rl"); +OSAP osap("axl-stepper_z"); +// OSAP osap("axl-stepper_rl"); // OSAP osap("axl-stepper_rr"); // -------------------------------------------------------- 0: USB Serial @@ -136,7 +136,7 @@ Endpoint precalculatedSegmentEP(&osap, "segmentsIn", onSegmentData); // -------------------------------------------------------- 5: Halt Input EP_ONDATA_RESPONSES onHaltInData(uint8_t* data, uint16_t len){ - axl_halt(AXL_HALT_REQUEST); + axl_halt(data[0]); return EP_ONDATA_REJECT; } @@ -172,9 +172,41 @@ EP_ONDATA_RESPONSES onMotorSettingsData(uint8_t* data, uint16_t len){ Endpoint motorSettingsEP(&osap, "motorSettings", onMotorSettingsData); -// -------------------------------------------------------- 9: Limit Halt-Output: +// -------------------------------------------------------- 10: Limit Halt-Output: -// Endpoint limitHaltEP(&osap, "limitOutput"); +Endpoint limitHaltEP(&osap, "limitSwitchState"); + +#define LIMIT_PIN 23 +#define LIMIT_PORT 0 + +void limitSetup(void){ + PORT->Group[LIMIT_PORT].DIRCLR.reg = (1 << LIMIT_PIN); + PORT->Group[LIMIT_PORT].PINCFG[LIMIT_PIN].bit.INEN = 1; + // pullup + PORT->Group[LIMIT_PORT].OUTSET.reg = (1 << LIMIT_PIN); +} + +boolean checkLimit(void){ + return (PORT->Group[LIMIT_PORT].IN.reg & (1 << LIMIT_PIN)); +} + +// -------------------------------------------------------- 11: Motion State + +boolean beforeMotionStateQuery(void); + +Endpoint motionStateEP(&osap, "motionState", beforeMotionStateQuery); + +uint8_t dummyMotionStateData[1]; + +boolean beforeMotionStateQuery(void){ + if(axl_isMoving()){ + dummyMotionStateData[0] = 1; + } else { + dummyMotionStateData[0] = 0; + } + motionStateEP.write(dummyMotionStateData, 1); + return true; +} // -------------------------------------------------------- Arduino Setup @@ -191,6 +223,8 @@ void setup() { stepper_hw->setMicrostep(4); // setup controller axl_setup(); + // setup limit swootch + limitSetup(); // ticker begin: // d51ClockUtils->start_ticker_a(AXL_TICKER_INTERVAL_US); } @@ -199,9 +233,16 @@ void setup() { uint32_t lastBlink = 0; uint32_t blinkInterval = 50; // ms + uint8_t axlData[256]; uint16_t axlDataLen = 0; +uint32_t lastLimitCheck = 0; +uint32_t limitCheckInterval = 1; // ms, helps to debounce, bummer to be running this often +uint8_t limitTrace = 0; // 8-wide 1-bit state trace... for edge-masking, +boolean limitState = false; +uint8_t dummy[2] = { 0, 0 }; // lol, typed endpoints wanted ! + void loop() { osap.loop(); // check for halt info... @@ -227,21 +268,25 @@ void loop() { // updateStatesEP(); //axl_printHomeState(); } - // // this, i.e, could be on the endpoint's loop code, non? - // if(lastLimitCheck + limitCheckInterval < millis()){ - // lastLimitCheck = millis(); - // // shift left one & tack bit on the end, - // limitStates = limitStates << 1; - // limitStates |= axl_checkLimit() ? 1 : 0; - // // this is the positive-edge mask, - // if(limitStates == 0b00001111){ - // ERRLIGHT_ON; - // errLightOnTime = millis(); - // errLightOn = true; - // dummy[0] = 1; - // limitHaltEP.write(dummy, 1); - // } - // } + // this, i.e, could be on an endpoint's loop code, non? + if(lastLimitCheck + limitCheckInterval < millis()){ + lastLimitCheck = millis(); + // shift left one & tack bit on the end, + limitTrace = limitTrace << 1; + limitTrace |= checkLimit() ? 1 : 0; + // swap on positive or -ve edges, + if(limitTrace == 0b11111111 && limitState == false){ + ERRLIGHT_ON; + limitState = true; + dummy[0] = 1; + limitHaltEP.write(dummy, 1); + } else if (limitTrace == 0b00000000 && limitState == true){ + ERRLIGHT_OFF; + limitState = false; + dummy[0] = 0; + limitHaltEP.write(dummy, 1); + } + } // if(errLightOn && errLightOnTime + 250 < millis()){ // ERRLIGHT_OFF; // errLightOn = false; diff --git a/firmware/axl-stepper/src/osape b/firmware/axl-stepper/src/osape index 02d0a15f90372e1f15f37ca4e0882b956d2eec70..e656c969af1ca5785108d0007294441ffafbb732 160000 --- a/firmware/axl-stepper/src/osape +++ b/firmware/axl-stepper/src/osape @@ -1 +1 @@ -Subproject commit 02d0a15f90372e1f15f37ca4e0882b956d2eec70 +Subproject commit e656c969af1ca5785108d0007294441ffafbb732