4 const u8 motor_lookup[80] =
5 { 1,12,23,34,46,57,68,79,
6 11,22,33,44,56,67,78,89,
7 21,32,43,54,66,77,88,99,
18 void motor_shift_send(u8 data) {
20 /* load it in, MSB first */
21 for (i = 0; i < 8; i++) {
23 bset_misc_output(A3800_MOTOR_DATA);
25 bclr_misc_output(A3800_MOTOR_DATA);
28 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
29 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
35 void motor_on(u8 slot) {
41 /* loads up the shift register with the right bits */
42 bclr_misc_output(A3800_MOTOR_COL8_ENABLE|A3800_MOTOR_COL9_ENABLE);
45 bset_misc_output(A3800_MOTOR_COL8_ENABLE);
49 bset_misc_output(A3800_MOTOR_COL9_ENABLE);
53 motor_shift_send(1 << col); /* cols from 0..7 */
56 motor_shift_send(1 << (row-1)); /* rows from 1..8 here */
58 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
59 bclr_changer_output(A3000_MOTOR_ROW_DISABLE);
63 bset_changer_output(A3000_MOTOR_ROW_DISABLE);
64 delay(10); /* XXX cf motors_off */
65 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE);
66 bclr_misc_output(A3800_MOTOR_COL8_ENABLE | A3800_MOTOR_COL9_ENABLE);
69 bool motor_here(u8 slot) {
72 for (i=0; i < 8; i++) {
74 if (_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERVOLTAGE) {
87 bool is_motor(u8 slot) {
88 /* FIXME - does more need to be done? */
89 return motor_here(slot);
92 bool left_home(u8 slot) {
97 for (i = 0; i < 5; i++)
98 if ((home_sensors & r) == 0) return 1;
104 bool back_home(u8 slot) {
109 for (i = 0; i < 5; i++) {
110 if (home_sensors & r) return 1;
111 if ((_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERCURRENT) == 0) return 1;
118 bool motor_overcurrent() {
122 if (7 == t) return 1;
123 if (_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERCURRENT) continue;
126 if (5 == i) return 0;
130 u8 dispense_motor(u8 slot) {
131 if (!is_motor(slot)) return MOTOR_NOSLOT;
135 if (!left_home(slot)) {
137 return MOTOR_HOME_FAIL;
141 if (motor_overcurrent()) {
143 return MOTOR_CURRENT_FAIL;
145 /* something should call motor_here? */
146 if (back_home(slot)) {
148 return MOTOR_SUCCESS;