Fix stepper half half step mode (#1397)

* Fixed half half step mode

Half step mode originally had second and third steps mixed up for output A.
https://github.com/esphome/issues/issues/1655

* Updated half step mode to have no branching

Code based off comments in PR: https://github.com/esphome/esphome/pull/1397#issuecomment-739413973

* removed variable declarations in the switch/case

Oops. No explicit declarations.
Rearranged to be tidier, same output sequence.

* Fixed typo bracket

Minor typo fixed - logic complete to do branchless half stepping.

* Format the brackets to satisfy clang
This commit is contained in:
Fractal147 2021-01-08 03:17:41 +00:00 committed by GitHub
parent 34df25da39
commit 3c64c9b0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,14 +70,8 @@ void ULN2003::write_step_(int32_t step) {
}
case ULN2003_STEP_MODE_HALF_STEP: {
// A, AB, B, BC, C, CD, D, DA
if (i == 0 || i == 2 || i == 7)
res |= 1 << 0;
if (i == 1 || i == 2 || i == 3)
res |= 1 << 1;
if (i == 3 || i == 4 || i == 5)
res |= 1 << 2;
if (i == 5 || i == 6 || i == 7)
res |= 1 << 3;
res |= 1 << (i >> 1);
res |= 1 << (((i + 1) >> 1) & 0x3);
break;
}
case ULN2003_STEP_MODE_WAVE_DRIVE: {