4 void motor_shift_send(u8 data) {
6 /* load it in, MSB first */
7 for (i = 0; i < 8; i++) {
9 bset_misc_output(A3800_MOTOR_DATA);
11 bclr_misc_output(A3800_MOTOR_DATA);
14 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
15 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
21 void motor_on(u8 slot) {
27 /* loads up the shift register with the right bits */
28 bclr_misc_output(A3800_MOTOR_COL8_ENABLE|A3800_MOTOR_COL9_ENABLE);
31 bset_misc_output(A3800_MOTOR_COL8_ENABLE);
35 bset_misc_output(A3800_MOTOR_COL9_ENABLE);
39 motor_shift_send(1 << col); /* cols from 0..7 */
42 motor_shift_send(1 << (row-1)); /* rows from 1..8 here */
44 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
45 bclr_changer_output(A3000_MOTOR_ROW_DISABLE);
49 bset_changer_output(A3000_MOTOR_ROW_DISABLE);
50 delay(10); /* XXX cf motors_off */
51 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE);
52 bclr_misc_output(A3800_MOTOR_COL8_ENABLE | A3800_MOTOR_COL9_ENABLE);
55 bool motor_here(u8 slot) {
58 for (i=0; i < 8; i++) {
60 if (_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERVOLTAGE) {
73 bool is_motor(u8 slot) {
74 /* FIXME - does more need to be done? */
75 return motor_here(slot);
78 bool left_home(u8 slot) {
83 for (i = 0; i < 5; i++)
84 if ((home_sensors & r) == 0) return 1;
90 bool back_home(u8 slot) {
95 for (i = 0; i < 5; i++) {
96 if (home_sensors & r) return 1;
97 if ((_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERCURRENT) == 0) return 1;
104 bool motor_overcurrent() {
108 if (7 == t) return 1;
109 if (_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERCURRENT) continue;
112 if (5 == i) return 0;
116 u8 dispense_motor(u8 slot) {
117 if (!is_motor(slot)) return MOTOR_NOSLOT;
121 if (!left_home(slot)) {
123 return MOTOR_HOME_FAIL;
127 if (motor_overcurrent()) {
129 return MOTOR_CURRENT_FAIL;
131 /* something should call motor_here? */
132 if (back_home(slot)) {
134 return MOTOR_SUCCESS;