diff --git a/Makefile b/Makefile index 7b5cae0..0b8588c 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ PRODUCT_ID := 0003 SRCS= main.cpp \ utils.cpp \ esc-control.cpp \ - # ppm-decode.cpp + ppm-decode.cpp INCLUDES=${SRCS:.cpp=.h} OBJS=$(addprefix $(APP_OBJ_PATH)/, $(SRCS:.cpp=.o)) diff --git a/esc-control.cpp b/esc-control.cpp index 928ae83..8d08a31 100644 --- a/esc-control.cpp +++ b/esc-control.cpp @@ -1,11 +1,7 @@ #include "wirish.h" +#include "utils.h" #include "esc-control.h" -// ASCII escape character -#define ESC ((uint8)27) - -// Default USART baud rate -#define BAUD 9600 // Servo constants #define SERVO_MIN 3430 @@ -45,7 +41,7 @@ void ppm_decode(void){ time_start = micros(); }else{ -#ifdef VERBOSE +#ifdef USB_VERBOSE SerialUSB.print(i); SerialUSB.print(":"); SerialUSB.print(time_elapsed); @@ -65,12 +61,12 @@ void ppm_decode(void){ } channels[i++] = time_elapsed; }else{ -#ifdef VERBOSE +#ifdef USB_VERBOSE SerialUSB.println(""); #endif i=0; } -#ifdef VERBOSE +#ifdef USB_VERBOSE SerialUSB.print("\t"); #endif @@ -140,32 +136,3 @@ void cmd_servo_sweep(void) { enable_usarts(); } -void cmd_board_info(void) { // TODO print more information - SerialUSB.println("Board information"); - SerialUSB.println("================="); - - SerialUSB.print("* Clock speed (MHz): "); - SerialUSB.println(CYCLES_PER_MICROSECOND); - - SerialUSB.print("* BOARD_LED_PIN: "); - SerialUSB.println(BOARD_LED_PIN); - - SerialUSB.print("* BOARD_BUTTON_PIN: "); - SerialUSB.println(BOARD_BUTTON_PIN); - - SerialUSB.print("* GPIO information (BOARD_NR_GPIO_PINS = "); - SerialUSB.print(BOARD_NR_GPIO_PINS); - SerialUSB.println("):"); - print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS); - print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS); - print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS); -} - -// -- Helper functions -------------------------------------------------------- - -static uint16 init_all_timers_prescale = 0; - -static void set_prescale(timer_dev *dev) { - timer_set_prescaler(dev, init_all_timers_prescale); -} - diff --git a/esc-control.h b/esc-control.h index f7c485c..1c9c6c4 100644 --- a/esc-control.h +++ b/esc-control.h @@ -1,15 +1,8 @@ #include "wirish.h" // Commands -void cmd_print_help(void); void cmd_servo_sweep(void); -void cmd_board_info(void); void ppm_decode(void); void set_servo_angle(float angle); -// Helper functions -void init_all_timers(uint16 prescale); -void enable_usarts(void); -void disable_usarts(void); -void print_board_array(const char* msg, const uint8 arr[], int len); diff --git a/main.cpp b/main.cpp index bd28b99..60599d7 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,4 @@ -// Comment out to disable USB printouts -#define USB_VERBOSE + // Include files #include "wirish.h" @@ -87,6 +86,7 @@ int main(void) { SerialUSB.print("Unexpected byte: 0x"); SerialUSB.print((int)input, HEX); SerialUSB.println(", press h for help."); + break; } SerialUSB.print("> "); diff --git a/ppm-decode.cpp b/ppm-decode.cpp index 6da36ce..55be8ff 100644 --- a/ppm-decode.cpp +++ b/ppm-decode.cpp @@ -1,3 +1,6 @@ +// Original code from http://pastebin.com/NQtbVCFh +// Posted on the leaflabs.com forum by Dweller: +// http://forums.leaflabs.com/topic.php?id=1170 ///********************************************************************** // Various Maple tests.. including timer capture to memory via dma =) // */ diff --git a/utils.cpp b/utils.cpp index 93283d8..afe6355 100644 --- a/utils.cpp +++ b/utils.cpp @@ -62,3 +62,26 @@ boolean isConnected(){ return (SerialUSB.isConnected() && (SerialUSB.getDTR() || SerialUSB.getRTS())); } +void cmd_board_info(void) { // TODO print more information + SerialUSB.println("Board information"); + SerialUSB.println("================="); + + SerialUSB.print("* Clock speed (MHz): "); + SerialUSB.println(CYCLES_PER_MICROSECOND); + + SerialUSB.print("* BOARD_LED_PIN: "); + SerialUSB.println(BOARD_LED_PIN); + + SerialUSB.print("* BOARD_BUTTON_PIN: "); + SerialUSB.println(BOARD_BUTTON_PIN); + + SerialUSB.print("* GPIO information (BOARD_NR_GPIO_PINS = "); + SerialUSB.print(BOARD_NR_GPIO_PINS); + SerialUSB.println("):"); + print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS); + print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS); + print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS); +} + + + diff --git a/utils.h b/utils.h index 1722a98..e96a28f 100644 --- a/utils.h +++ b/utils.h @@ -1,11 +1,17 @@ #include "wirish.h" +// Comment out to disable USB printouts +#define USB_VERBOSE + +// ASCII escape character +#define ESC ((uint8)27) // Default USART baud rate #define BAUD 9600 void cmd_print_help(void); +void cmd_board_info(void); void set_prescale(timer_dev *dev); void init_all_timers(uint16 prescale); void enable_usarts(void);