spi support
[protos/xbee-avr.git] / commands.c
index 986ca92..6eb034c 100644 (file)
 #include <aversive/pgmspace.h>
 #include <aversive/queue.h>
 #include <aversive/endian.h>
+#include <aversive/error.h>
+#include <aversive/wait.h>
 #include <parse.h>
 #include <rdline.h>
 #include <parse_string.h>
 #include <parse_num.h>
+#include <uart.h>
 
 #include "xbee_atcmd.h"
 #include "xbee_neighbor.h"
 #include "parse_neighbor.h"
 #include "parse_monitor.h"
 
+#include "spi_servo.h"
 #include "rc_proto.h"
 #include "main.h"
+#include "cmdline.h"
 
 /* commands_gen.c */
 extern parse_pgm_inst_t cmd_reset;
@@ -1214,7 +1219,88 @@ parse_pgm_inst_t cmd_debug = {
        },
 };
 
+#ifndef USE_USB
+/**********************************************************/
 
+/* this structure is filled when cmd_baudrate is parsed successfully */
+struct cmd_baudrate_result {
+       fixed_string_t arg0;
+       uint32_t arg1;
+};
+
+/* function called when cmd_baudrate is parsed successfully */
+static void cmd_baudrate_parsed(void * parsed_result, __attribute__((unused)) void *data)
+{
+       struct cmd_baudrate_result *res = parsed_result;
+       struct uart_config c;
+
+       uart_getconf(XBEE_UART, &c);
+       c.baudrate = res->arg1;
+       uart_setconf(XBEE_UART, &c);
+}
+
+prog_char str_baudrate_arg0[] = "baudrate";
+parse_pgm_token_string_t cmd_baudrate_arg0 =
+       TOKEN_STRING_INITIALIZER(struct cmd_baudrate_result, arg0,
+                                str_baudrate_arg0);
+parse_pgm_token_num_t cmd_baudrate_arg1 =
+       TOKEN_NUM_INITIALIZER(struct cmd_baudrate_result, arg1,
+                             UINT32);
+
+prog_char help_baudrate[] = "Change xbee baudrate";
+parse_pgm_inst_t cmd_baudrate = {
+       .f = cmd_baudrate_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = help_baudrate,
+       .tokens = {        /* token list, NULL terminated */
+               (prog_void *)&cmd_baudrate_arg0,
+               (prog_void *)&cmd_baudrate_arg1,
+               NULL,
+       },
+};
+#endif
+
+/* this structure is filled when cmd_test_spi is parsed successfully */
+struct cmd_test_spi_result {
+       fixed_string_t arg0;
+};
+
+static void cmd_test_spi_parsed(void * parsed_result,
+                               __attribute__((unused)) void *data)
+{
+       int i;
+
+
+       while (1) {
+               for (i = 0; i < 50; i++) {
+                       spi_servo_set(0, 0);
+                       wait_ms(100);
+                       spi_servo_set(0, 500);
+                       wait_ms(100);
+               }
+
+               spi_servo_bypass(1);
+               wait_ms(10000);
+               spi_servo_bypass(0);
+               wait_ms(1);
+       }
+}
+
+prog_char str_test_spi_arg0[] = "test_spi";
+parse_pgm_token_string_t cmd_test_spi_arg0 =
+       TOKEN_STRING_INITIALIZER(struct cmd_test_spi_result, arg0,
+                                str_test_spi_arg0);
+
+prog_char help_test_spi[] = "Test the spi";
+parse_pgm_inst_t cmd_test_spi = {
+       .f = cmd_test_spi_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = help_test_spi,
+       .tokens = {        /* token list, NULL terminated */
+               (prog_void *)&cmd_test_spi_arg0,
+               NULL,
+       },
+};
 
 /* in progmem */
 parse_pgm_ctx_t main_ctx[] = {
@@ -1251,5 +1337,9 @@ parse_pgm_ctx_t main_ctx[] = {
        (parse_pgm_inst_t *)&cmd_raw,
        (parse_pgm_inst_t *)&cmd_dump,
        (parse_pgm_inst_t *)&cmd_debug,
+#ifndef USE_USB
+       (parse_pgm_inst_t *)&cmd_baudrate,
+#endif
+       (parse_pgm_inst_t *)&cmd_test_spi,
        NULL,
 };