-static volatile uint8_t rxbuf[16];
-static volatile uint8_t rxlen;
-static volatile uint8_t portval;
-static volatile uint8_t done;
+#define NB_SERVO (sizeof(servo_table)/sizeof(*servo_table))
+
+register uint8_t bypass asm("r2");
+register uint8_t done asm("r3");
+register uint8_t portval asm("r4");
+register uint8_t rxidx asm("r5");
+
+/*
+ * SPI protocol:
+ *
+ * A command is stored on 2 bytes. The first one has its msb to 0, and the
+ * second one to 1. The first received byte contains the command number, and the
+ * msb of the servo value. The second byte contains the lsb of the servo value.
+ *
+ * Commands 0 to NB_SERVO are to set the value of servo.
+ * Command 14 is to enable bypass mode.
+ * Command 15 is to disable bypass mode.
+ */
+register union {
+ uint8_t u8;
+ struct {
+ uint16_t zero:1;
+ uint16_t cmd_num:4;
+ uint16_t val_msb:3;
+ };
+} byte0 asm("r6");
+
+register union {
+ uint8_t u8;
+ struct {
+ uint8_t one:1;
+ uint8_t val_lsb:7;
+ };
+} byte1 asm("r7");