8 static struct servo servo_table[] = {
22 #define NB_SERVO (sizeof(servo_table)/sizeof(*servo_table))
24 register uint8_t bypass asm("r2");
25 register uint8_t done asm("r3");
26 register uint8_t portval asm("r4");
27 register uint8_t rxidx asm("r5");
32 * A command is stored on 2 bytes. The first one has its msb to 0, and the
33 * second one to 1. The first received byte contains the command number, and the
34 * msb of the servo value. The second byte contains the lsb of the servo value.
36 * Commands 0 to NB_SERVO are to set the value of servo.
37 * Command 14 is to enable bypass mode.
38 * Command 15 is to disable bypass mode.
57 SIGNAL(TIMER1_COMPA_vect)
60 TIMSK1 &= ~_BV(OCIE1A);
64 static void poll_spi(void)
68 /* reception complete ? */
69 if (!(SPSR & (1<<SPIF)))
73 if ((rxidx == 0) && (c & 0x80)) {
77 if ((rxidx == 1) && ((c & 0x80) == 0)) {
92 if (byte0.cmd_num < NB_SERVO) {
93 val = (uint16_t)byte0.val_msb << 7;
95 servo_table[byte0.cmd_num].command = val;
97 else if (byte0.cmd_num == 14) {
100 else if (byte0.cmd_num == 15) {
108 static void load_timer_at(uint16_t t)
111 TIMSK1 |= _BV(OCIE1A);
114 static void do_one_servo(struct servo *s)
120 //portval = PORTC | (1 << s->bit);
121 portval = (1 << s->bit);
123 load_timer_at(t + 150);
130 //portval = PORTC & (~(1 << s->bit));
131 load_timer_at(t + 150 + 8000 + s->command * 8);
147 /* start timer1 at clk/1 (8Mhz) */
151 /* start timer0 at clk/1024 (~8Khz) */
153 TCCR0B = _BV(CS02) | _BV(CS00);
155 /* enable spi (don't set unused MISO as output) */
162 for (i = 0; i < NB_SERVO; i++) {
163 do_one_servo(&servo_table[i]);
173 while (bypass == 1) {