From 8863418f0595c8dfd7d01081be941541539827bb Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Fri, 4 Mar 2011 20:25:26 -0500 Subject: Brought examples/ up to date; PIN_MAP bugfix for D24. (Cherry-pick from refactor with some modifications). --- examples/test-session.cpp | 137 +++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 56 deletions(-) (limited to 'examples/test-session.cpp') diff --git a/examples/test-session.cpp b/examples/test-session.cpp index 7601fab..cf1f4ec 100644 --- a/examples/test-session.cpp +++ b/examples/test-session.cpp @@ -20,27 +20,43 @@ int rate = 0; +#if defined(BOARD_maple) || defined(BOARD_maple_RET6) + +#elif defined(BOARD_maple_mini) + +#elif defined(BOARD_maple_native) +const uint8[] pins_to_skip = {LED_PIN}; + +#else +#error "Board not selected correctly." +#endif + #if defined(BOARD_maple) const uint8 pwm_pins[] = {0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12, 14, 24, 25, 27, 28}; const uint8 adc_pins[] = {0, 1, 2, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 27, 28}; +const uint8 pins_to_skip[] = {LED_PIN}; #elif defined(BOARD_maple_mini) +#define USB_DP 23 +#define USB_DM 24 const uint8 pwm_pins[] = {3, 4, 5, 8, 9, 10, 11, 15, 16, 25, 26, 27}; const uint8 adc_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 33}; // NB: 33 is LED +const uint8 pins_to_skip[] = {LED_PIN, USB_DP, USB_DM}; #elif defined(BOARD_maple_native) -const uint8 pwm_pins[] = {12, 13, 14, 15, 22, 23, 24, 25, 37, 38, 45, - 46, 47, 48, 49, 50, 53, 54}; -const uint8 adc_pins[] = {6, 7, 8, 9, 10, 11, - /* the following are on ADC3, which lacks support: - 39, 40, 41, 42, 43, 45, */ - 46, 47, 48, 49, 50, 51, 52, 53, 54}; +const uint8 pwm_pins[] = { + 12, 13, 14, 15, 22, 23, 24, 25, 37, 38, 45, 46, 47, 48, 49, 50, 53, 54}; +const uint8 adc_pins[] = { + 6, 7, 8, 9, 10, 11, + /* FIXME These are on ADC3, which lacks support: + 39, 40, 41, 42, 43, 45, */ + 46, 47, 48, 49, 50, 51, 52, 53, 54}; +const uint8 pins_to_skip[] = {LED_PIN}; #else -#error "Board type has not been selected correctly" - +#error "Board type has not been selected correctly." #endif uint8 gpio_state[NR_GPIO_PINS]; @@ -62,6 +78,7 @@ void cmd_sequential_pwm_test(void); void cmd_pwm_sweep(void); void cmd_servo_sweep(void); +bool skip_pin_p(uint8 pin); void measure_adc_noise(uint8 pin); void fast_gpio(int pin); void do_serials(HardwareSerial **serials, int n, unsigned baud); @@ -79,10 +96,10 @@ void setup() { // Send a message out over COMM interface COMM.println(" "); COMM.println(" __ __ _ _ "); - COMM.println(" | \/ | __ _ _ __ | | ___| |"); - COMM.println(" | |\/| |/ _` | '_ \| |/ _ \ |"); + COMM.println(" | \\/ | __ _ _ __ | | ___| |"); + COMM.println(" | |\\/| |/ _` | '_ \\| |/ _ \\ |"); COMM.println(" | | | | (_| | |_) | | __/_|"); - COMM.println(" |_| |_|\__,_| .__/|_|\___(_)"); + COMM.println(" |_| |_|\\__,_| .__/|_|\\___(_)"); COMM.println(" |_|"); COMM.println(" by leaflabs"); COMM.println(""); @@ -274,7 +291,7 @@ void cmd_print_help(void) { COMM.println("\tr: Monitor and print GPIO status changes"); COMM.println("\ts: output a sweeping servo PWM on all PWM channels"); COMM.println("\tm: output data on USART1 and USART3 with various rates"); - COMM.println("\t+: test shield mode (for QA, will disrupt Serial2!)"); + COMM.println("\t+: test shield mode (for QA; will disrupt USARTS)"); COMM.println("Unimplemented:"); COMM.println("\te: do everything all at once until new input"); @@ -294,11 +311,11 @@ void measure_adc_noise(uint8 pin) { // TODO // variance algorithm from knuth; see wikipedia // checked against python - for(int i = 0; i<100; i++) { + for(int i = 0; i < 100; i++) { data[i] = analogRead(pin); delta = data[i] - mean; - mean = mean + delta/(i+1); - M2 = M2 + delta*(data[i] - mean); + mean = mean + delta/(i + 1); + M2 = M2 + delta * (data[i] - mean); } //sqrt is broken? @@ -313,7 +330,7 @@ void measure_adc_noise(uint8 pin) { // TODO void cmd_adc_stats(void) { COMM.println("Taking ADC noise stats..."); digitalWrite(BOARD_LED_PIN, 0); - for(uint32 i = 0; i= j) COMM.print("#"); else COMM.print(" "); } COMM.print("| "); - for(int j = 0; j<12; j++) { - if(sample & (1 << (11-j))) COMM.print("1"); + for(int j = 0; j < 12; j++) { + if(sample & (1 << (11 - j))) COMM.print("1"); else COMM.print("0"); } COMM.println(""); @@ -466,32 +483,33 @@ void cmd_sequential_adc_reads(void) { void cmd_gpio_qa(void) { COMM.println("Doing QA testing for most GPIO pins..."); digitalWrite(BOARD_LED_PIN, 0); - for(int i = 0; i 65500) rate = 0; - for(uint32 i = 2; i 5734) rate = 4096; - for(uint32 i = 2; i