8 static struct servo servo_table[] = {
22 #define NB_SERVO (sizeof(servo_table)/sizeof(*servo_table))
24 static volatile uint8_t bypass;
25 static volatile uint8_t done;
26 static volatile uint8_t portval;
27 static volatile uint8_t rxidx;
29 #define BYPASS_ENABLE 14
30 #define BYPASS_DISABLE 15
35 * A command is stored on 2 bytes. The first one has its msb to 0, and the
36 * second one to 1. The first received byte contains the command number, and the
37 * msb of the servo value. The second byte contains the lsb of the servo value.
39 * Commands 0 to NB_SERVO are to set the value of servo.
40 * Command 14 is to enable bypass mode.
41 * Command 15 is to disable bypass mode.
43 static volatile union {
52 static volatile union {
60 SIGNAL(TIMER1_COMPA_vect)
63 TIMSK1 &= ~_BV(OCIE1A);
67 static void poll_spi(void)
71 /* reception complete ? */
72 if (!(SPSR & (1<<SPIF)))
76 if ((rxidx == 0) && (c & 0x80)) {
80 if ((rxidx == 1) && ((c & 0x80) == 0)) {
95 if (byte0.cmd_num < NB_SERVO) {
96 val = (uint16_t)byte0.val_msb << 7;
98 servo_table[byte0.cmd_num].command = val;
100 else if (byte0.cmd_num == BYPASS_ENABLE) {
103 else if (byte0.cmd_num == BYPASS_DISABLE) {
111 static void load_timer_at(uint16_t t)
114 TIMSK1 |= _BV(OCIE1A);
117 static void do_one_servo(struct servo *s)
123 //portval = PORTC | (1 << s->bit);
124 portval = (1 << s->bit);
126 load_timer_at(t + 150);
133 //portval = PORTC & (~(1 << s->bit));
134 load_timer_at(t + 150 + 8000 + s->command * 8);
150 /* start timer1 at clk/1 (8Mhz) */
154 /* start timer0 at clk/1024 (~8Khz) */
156 TCCR0B = _BV(CS02) | _BV(CS00);
158 /* enable spi (don't set unused MISO as output) */
166 for (i = 0; i < NB_SERVO; i++) {
167 do_one_servo(&servo_table[i]);
177 while (bypass == 1) {