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);
30 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
32 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
39 void set_motor(u8 slot) {
45 /* loads up the shift register with the right bits */
46 bclr_misc_output(A3800_MOTOR_COL8_ENABLE|A3800_MOTOR_COL9_ENABLE);
49 bset_misc_output(A3800_MOTOR_COL8_ENABLE);
53 bset_misc_output(A3800_MOTOR_COL9_ENABLE);
57 motor_shift_send(1 << col); /* cols from 0..7 */
58 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE);
61 motor_shift_send(1 << (row-1)); /* rows from 1..8 here */
63 bclr((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_CLOCK);
67 bclr_changer_output(A3000_MOTOR_ROW_DISABLE);
71 bset_changer_output(A3000_MOTOR_ROW_DISABLE);
75 bset_changer_output(A3000_MOTOR_ROW_DISABLE);
76 bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE);
77 bclr_misc_output(A3800_MOTOR_COL8_ENABLE | A3800_MOTOR_COL9_ENABLE);
80 bool motor_here(u8 slot) {
83 for (i=0; i < 8; i++) {
86 if ((_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERVOLTAGE) == 0) {
99 bool is_motor(u8 slot) {
100 /* FIXME - does more need to be done? */
101 return motor_here(slot);
104 bool start_motor(u8 slot) {
112 for (i = 0; i < 1000; i++) {
113 if ((home_sensors & r) != 0) return 1;
121 bool back_home(u8 slot) {
126 for (i = 0; i < 5; i++) {
127 if ((home_sensors & r) == 0) return 1;
131 /* it never arrived */
135 #define is_overcurrent() ((_io_ports[M6811_PORTE] & PORTE_MOTOR_NOT_OVERCURRENT)==0)
136 bool motor_overcurrent() {
137 u8 good_passes = 0, t;
138 for (t = 0; t < 8; t++) {
140 if (is_overcurrent()) continue;
143 if (good_passes == 5) return 0;
148 u8 dispense_motor(u8 slot) {
149 if (!is_motor(slot)) return MOTOR_NOSLOT;
150 if (!start_motor(slot)) return MOTOR_HOME_FAIL;
154 if (motor_overcurrent()) {
156 return MOTOR_CURRENT_FAIL;
158 if (back_home(slot)) {
160 return MOTOR_SUCCESS;