-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper.c
75 lines (69 loc) · 845 Bytes
/
stepper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "stepper.h"
const uint8_t step_list[8] =
{
0x0A, /* 1010 */
0x08, /* 1000 */
0x09, /* 1001 */
0x01, /* 0001 */
0x05, /* 0101 */
0x04, /* 0100 */
0x06, /* 0110 */
0x02 /* 0010 */
};
uint8_t next_step(uint8_t *state, uint8_t param)
{
uint8_t step, ret;
step = *state;
ret = step_list[step - 0x80];
if(param & 1)
{
/* full step */
if((param >> 1) & 1)
{
if(step % 2 == 0)
{
++step;
}
else
{
step += 2;
}
if(step == 0x88)
{
step = 0x80;
}
}
else
{
if(step % 2 == 0)
{
--step;
}
else
{
step -= 2;
}
if(step == 0x7E)
{
step = 0x86;
}
}
}
else
{
/* half step */
if((param >> 1) & 1)
{
if(++step == 0x88)
{
step = 0x80;
}
}
else if(--step == 0x7F)
{
step = 0x86;
}
}
*state = step;
return ret;
}