From 02e76ec27b5737bce836a5460427b538076f01ef 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. --- examples/vga-scope.cpp | 212 +++++++++++++++++++++++++++++++------------------ 1 file changed, 134 insertions(+), 78 deletions(-) (limited to 'examples/vga-scope.cpp') diff --git a/examples/vga-scope.cpp b/examples/vga-scope.cpp index 0265f9c..9c6dca5 100644 --- a/examples/vga-scope.cpp +++ b/examples/vga-scope.cpp @@ -1,34 +1,90 @@ -// Low-level, non-wirish demonstration of VGA -// -// Connect a microphone or something less to ANALOG_PIN +/* + VGA Oscilloscope demo. + + Connect a microphone or something like it to ANALOG_PIN (0V -- 3.3V + only; 0.2V -- 3.1V will probably look nicer); an attached VGA + monitor will display the signal roughly in real-time. + + The thick blue line corresponds roughly to 0V. + + This is a fairy crude hack, but it's fun to watch/toy around with. + + SerialUSB and SysTick are disabled to get rid of the most frequently + occurring interrupts (which mess with timing). This means that you + have to use perpetual bootloader mode or the reset button to flash + new programs. + + How to wire this to a VGA port: + D6 via ~200ohms to VGA Red (1) + D7 via ~200ohms to VGA Green (2) + D8 via ~200ohms to VGA Blue (3) + D11 to VGA VSync (14) (swapped?) + D12 to VGA HSync (13) (swapped?) + GND to VGA Ground (5) + GND to VGA Sync Ground (10) + + See also: + - http://pinouts.ru/Video/VGA15_pinout.shtml + - http://www.epanorama.net/documents/pc/vga_timing.html + + This code is released into the public domain. + */ #include "wirish.h" +#include "systick.h" + +// FIXME generalize for Native and Mini -#define LED_PIN 13 +#define LED_PIN BOARD_LED_PIN #define ANALOG_PIN 18 -#define VGA_R 5 // B6 -#define VGA_G 6 // A8 -#define VGA_B 7 // A9 -#define VGA_V 11 // A6 -#define VGA_H 12 // A7 -#define VGA_R_HIGH (GPIOB_BASE)->BSRR = BIT(6) -#define VGA_R_LOW (GPIOB_BASE)->BRR = BIT(6) -#define VGA_G_HIGH (GPIOA_BASE)->BSRR = BIT(8) -#define VGA_G_LOW (GPIOA_BASE)->BRR = BIT(8) -#define VGA_B_HIGH (GPIOA_BASE)->BSRR = BIT(9) -#define VGA_B_LOW (GPIOA_BASE)->BRR = BIT(9) -#define VGA_V_HIGH (GPIOA_BASE)->BSRR = BIT(6) -#define VGA_V_LOW (GPIOA_BASE)->BRR = BIT(6) -#define VGA_H_HIGH (GPIOA_BASE)->BSRR = BIT(7) -#define VGA_H_LOW (GPIOA_BASE)->BRR = BIT(7) + +// Pinouts -- you also must change the GPIO macros below if you change +// these +#define VGA_R 6 // STM32: A8 +#define VGA_G 7 // STM32: A9 +#define VGA_B 8 // STM32: A10 +#define VGA_V 11 // STM32: A6 +#define VGA_H 12 // STM32: A7 + +// These low level (and STM32 specific) macros make GPIO writes much +// faster +#define ABSRR ((volatile uint32*)0x40010810) +#define ABRR ((volatile uint32*)0x40010814) + +#define RBIT 8 // (see pinouts) +#define GBIT 9 +#define BBIT 10 + +#define VGA_R_HIGH *ABSRR = BIT(RBIT) +#define VGA_R_LOW *ABRR = BIT(RBIT) +#define VGA_G_HIGH *ABSRR = BIT(GBIT) +#define VGA_G_LOW *ABRR = BIT(GBIT) +#define VGA_B_HIGH *ABSRR = BIT(BBIT) +#define VGA_B_LOW *ABRR = BIT(BBIT) + +#define COLOR_WHITE (BIT(RBIT) | BIT(GBIT) | BIT(BBIT)) +#define COLOR_BLACK 0 +#define COLOR_RED BIT(RBIT) +#define COLOR_GREEN BIT(GBIT) +#define COLOR_BLUE BIT(BBIT) + +#define BORDER_COLOR COLOR_BLUE + +// set has priority, so clear every bit and set some given bits: +#define VGA_COLOR(c) (*ABSRR = c | \ + BIT(RBIT+16) | BIT(GBIT+16) | BIT(BBIT+16)) + +#define VGA_V_HIGH *ABSRR = BIT(6) +#define VGA_V_LOW *ABRR = BIT(6) +#define VGA_H_HIGH *ABSRR = BIT(7) +#define VGA_H_LOW *ABRR = BIT(7) void isr_porch(void); void isr_start(void); void isr_stop(void); void isr_update(void); -void setup() -{ +void setup() { pinMode(LED_PIN, OUTPUT); pinMode(ANALOG_PIN, INPUT_ANALOG); digitalWrite(LED_PIN, 1); @@ -38,104 +94,104 @@ void setup() pinMode(VGA_V, OUTPUT); pinMode(VGA_H, OUTPUT); - /* Send a message out USART2 */ + // Send a message out USART2 Serial2.begin(9600); - Serial2.println("Video time..."); + Serial2.println("Time to kill the radio star..."); // This gets rid of the majority of the interrupt artifacts; - // a SysTick.end() is required as well + // there's still a glitch for low values of y, but let's not worry + // about that. (Probably due to the hackish way vsync is done). SerialUSB.end(); - + systick_disable(); + digitalWrite(VGA_R, 0); digitalWrite(VGA_G, 0); digitalWrite(VGA_B, 0); - digitalWrite(VGA_H,1); - digitalWrite(VGA_V,1); - - timer_set_prescaler(4,0); - timer_set_mode(4, 1, TIMER_OUTPUTCOMPARE); - timer_set_mode(4, 2, TIMER_OUTPUTCOMPARE); - timer_set_mode(4, 3, TIMER_OUTPUTCOMPARE); - timer_set_mode(4, 4, TIMER_OUTPUTCOMPARE); - timer_set_reload(4, 2287); - timer_set_compare_value(4,1,200); - timer_set_compare_value(4,2,300); - timer_set_compare_value(4,3,2170); // 2219 max... - timer_set_compare_value(4,4,1); - timer_attach_interrupt(4,1,isr_porch); - timer_attach_interrupt(4,2,isr_start); - timer_attach_interrupt(4,3,isr_stop); - timer_attach_interrupt(4,4,isr_update); - - timer_set_count(4,0); + digitalWrite(VGA_H, 1); + digitalWrite(VGA_V, 1); + + timer_pause(TIMER4); + timer_set_prescaler(TIMER4, 0); + timer_set_mode(TIMER4, 1, TIMER_OUTPUTCOMPARE); + timer_set_mode(TIMER4, 2, TIMER_OUTPUTCOMPARE); + timer_set_mode(TIMER4, 3, TIMER_OUTPUTCOMPARE); + timer_set_mode(TIMER4, 4, TIMER_OUTPUTCOMPARE); + timer_set_reload(TIMER4, 2287); + timer_set_compare_value(TIMER4, 1, 200); + timer_set_compare_value(TIMER4, 2, 250); + timer_set_compare_value(TIMER4, 3, 2170); // 2219 max... + timer_set_compare_value(TIMER4, 4, 1); + timer_attach_interrupt(TIMER4, 1, isr_porch); + timer_attach_interrupt(TIMER4, 2, isr_start); + timer_attach_interrupt(TIMER4, 3, isr_stop); + timer_attach_interrupt(TIMER4, 4, isr_update); + + timer_set_count(TIMER4, 0); + timer_resume(TIMER4); } -int toggle = 0; -uint16 x = 0; uint16 y = 0; uint16 val = 0; -uint8 v_active = 1; -GPIO_Port *portb = GPIOB_BASE; +bool v_active = true; +const uint16 x_max = 60; // empirically (and lazily) determined void isr_porch(void) { VGA_H_HIGH; y++; - if(y>=523) { - y=1; - v_active = 1; + val = map(analogRead(ANALOG_PIN), 0, 4095, 0, x_max); + if(y >= 523) { + y = 1; + v_active = true; return; } - if(y>=492) { + if(y >= 492) { VGA_V_HIGH; return; } - if(y>=490) { + if(y >= 490) { VGA_V_LOW; return; } - if(y>=479) { // 479 - v_active = 0; + if(y >= 479) { + v_active = false; return; } } void isr_start(void) { - if(!v_active) { return; } - VGA_R_HIGH; - VGA_R_HIGH; - VGA_R_HIGH; - VGA_R_LOW; - //delayMicroseconds(2); - //gpio_write_bit(GPIOA_BASE, 8, 1); // VGA_G - for(x=0; x<(val>>6); x++) { - } - VGA_B_HIGH; - VGA_G_HIGH; - VGA_G_LOW; - VGA_B_LOW; - //VGA_R_HIGH; - //val = (val + analogRead(ANALOG_PIN))/2; - val = analogRead(ANALOG_PIN); - + if (!v_active) { + return; + } + VGA_COLOR(BORDER_COLOR); + for (int x = 0; x < val; x++) { + VGA_COLOR(COLOR_BLACK); + } + VGA_COLOR(COLOR_WHITE); + VGA_COLOR(COLOR_BLACK); } + void isr_stop(void) { - if(!v_active) { return; } - VGA_R_LOW; - VGA_G_LOW; - VGA_B_LOW; + if (!v_active) { + return; + } + VGA_COLOR(COLOR_BLACK); } + void isr_update(void) { VGA_H_LOW; } void loop() { - //val = analogRead(ANALOG_PIN); + toggleLED(); + delay(100); } +__attribute__((constructor)) void premain() { + init(); +} int main(void) { - init(); setup(); while (1) { -- cgit v1.2.3 From 4a56b462cfa7c54c623374f966b853a7b0790613 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 11 Apr 2011 20:45:35 -0400 Subject: Resolving some FIXMEs. --- examples/test-session.cpp | 10 ++++++++-- examples/vga-scope.cpp | 7 ++++++- libmaple/usb/usb.c | 24 ++---------------------- libmaple/usb/usb_config.h | 2 +- 4 files changed, 17 insertions(+), 26 deletions(-) (limited to 'examples/vga-scope.cpp') diff --git a/examples/test-session.cpp b/examples/test-session.cpp index 03fb248..01dd184 100644 --- a/examples/test-session.cpp +++ b/examples/test-session.cpp @@ -780,17 +780,23 @@ void init_all_timers(uint16 prescale) { } void enable_usarts(void) { - // FIXME generalize after USART refactor Serial1.begin(BAUD); Serial2.begin(BAUD); Serial3.begin(BAUD); +#ifdef STM32_HIGH_DENSITY + Serial4.begin(BAUD); + Serial5.begin(BAUD); +#endif } void disable_usarts(void) { - // FIXME generalize after USART refactor Serial1.end(); Serial2.end(); Serial3.end(); +#ifdef STM32_HIGH_DENSITY + Serial4.end(); + Serial5.end(); +#endif } void print_board_array(const char* msg, const uint8 arr[], int len) { diff --git a/examples/vga-scope.cpp b/examples/vga-scope.cpp index 9c6dca5..66e72e9 100644 --- a/examples/vga-scope.cpp +++ b/examples/vga-scope.cpp @@ -28,12 +28,17 @@ - http://www.epanorama.net/documents/pc/vga_timing.html This code is released into the public domain. + + Authors: + + Bryan Newbold + Marti Bolivar */ #include "wirish.h" #include "systick.h" -// FIXME generalize for Native and Mini +// FIXME: generalize for Native and Mini #define LED_PIN BOARD_LED_PIN #define ANALOG_PIN 18 diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 2fc4eb2..7b1dd4c 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -35,6 +35,7 @@ #include "usb_lib.h" #include "gpio.h" #include "usb_hardware.h" +#include "delay.h" #include "usb_config.h" #include "usb_callbacks.h" @@ -318,29 +319,8 @@ if (wIstr & ISTR_CTR & wInterrupt_Mask) { } -static void FIXME_delayMicroseconds_copy(uint32 us) { - /* So (2^32)/12 micros max, or less than 6 minutes */ - us *= 12; - - /* fudge for function call overhead */ - us--; - asm volatile(" mov r0, %[us] \n\t" - "1: subs r0, #1 \n\t" - " bhi 1b \n\t" - : - : [us] "r" (us) - : "r0"); -} - -static void FIXME_delay_copy(unsigned long ms) { - uint32 i; - for (i = 0; i < ms; i++) { - FIXME_delayMicroseconds_copy(1000); - } -} - void usbWaitReset(void) { - FIXME_delay_copy(RESET_DELAY); + delay_us(RESET_DELAY); systemHardReset(); } diff --git a/libmaple/usb/usb_config.h b/libmaple/usb/usb_config.h index 0860b90..23b49ee 100644 --- a/libmaple/usb/usb_config.h +++ b/libmaple/usb/usb_config.h @@ -25,7 +25,7 @@ *****************************************************************************/ #define VCOM_ID_VENDOR 0x1EAF -#define RESET_DELAY (100) +#define RESET_DELAY (100000) #define USB_CONFIG_MAX_POWER (100 >> 1) #if defined(BOARD_maple) || defined(BOARD_maple_RET6) -- cgit v1.2.3 From 11a0da5c63faffd45bde43da2777a9771cfdf5e9 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 2 May 2011 14:33:05 -0400 Subject: /examples/ cleanups. --- examples/blinky.cpp | 9 ++--- examples/debug-dtrrts.cpp | 5 +-- examples/spi_master.cpp | 65 +++++++++++++++++---------------- examples/test-dac.cpp | 9 +++-- examples/test-ring-buffer-insertion.cpp | 2 +- examples/test-serial-flush.cpp | 20 +++++----- examples/test-serialusb.cpp | 31 +++++++--------- examples/test-systick.cpp | 15 +++----- examples/test-timers.cpp | 9 ++--- examples/vga-leaf.cpp | 21 ++++------- examples/vga-scope.cpp | 17 ++++----- 11 files changed, 91 insertions(+), 112 deletions(-) (limited to 'examples/vga-scope.cpp') diff --git a/examples/blinky.cpp b/examples/blinky.cpp index 209a6e6..91d1a47 100644 --- a/examples/blinky.cpp +++ b/examples/blinky.cpp @@ -2,11 +2,8 @@ #include "wirish.h" -// Use the pin attached to the built-in LED -#define PIN BOARD_LED_PIN - void setup() { - pinMode(PIN, OUTPUT); + pinMode(BOARD_LED_PIN, OUTPUT); } int toggle = 1; @@ -14,7 +11,7 @@ int toggle = 1; void loop() { // You could just use toggleLED() instead, but this illustrates // the use of digitalWrite(): - digitalWrite(PIN, toggle); + digitalWrite(BOARD_LED_PIN, toggle); toggle ^= 1; delay(100); } @@ -28,7 +25,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/debug-dtrrts.cpp b/examples/debug-dtrrts.cpp index 61c061a..3829208 100644 --- a/examples/debug-dtrrts.cpp +++ b/examples/debug-dtrrts.cpp @@ -3,12 +3,9 @@ #include "wirish.h" #include "usb.h" -#define LED_PIN BOARD_LED_PIN -#define PWM_PIN 2 - void setup() { /* Set up the LED to blink */ - pinMode(LED_PIN, OUTPUT); + pinMode(BOARD_LED_PIN, OUTPUT); /* Send a message out USART2 */ Serial2.begin(9600); diff --git a/examples/spi_master.cpp b/examples/spi_master.cpp index 06cad02..af3e709 100644 --- a/examples/spi_master.cpp +++ b/examples/spi_master.cpp @@ -1,61 +1,62 @@ -/* ***************************************************************************** +/****************************************************************************** * The MIT License * * Copyright (c) 2010 LeafLabs LLC. * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + *****************************************************************************/ /** - * @brief Sample main.cpp file. Sends "Hello world!" out SPI1. + * @brief Sample main.cpp file. Sends "Hello world!" out SPI1. * - * SPI1 is set up to be a master transmitter at 4.5MHz, little endianness, - * and SPI mode 0. - * - * Pin 10 is used as Chip Select + * SPI1 is set up to be a master transmitter at 4.5MHz, little + * endianness, and SPI mode 0. * + * Pin 10 is used as slave select. */ #include "wirish.h" -#define CS 10 +#define NSS 10 byte buf[] = "Hello world!"; HardwareSPI spi1(1); void setup() { - /* Set up chip select as output */ - pinMode(CS, OUTPUT); + /* Set up chip select as output */ + pinMode(NSS, OUTPUT); - /* CS is usually active low, so initialize it high */ - digitalWrite(CS, HIGH); + /* NSS is usually active LOW, so initialize it HIGH */ + digitalWrite(NSS, HIGH); - /* Initialize SPI */ + /* Initialize SPI */ spi1.begin(SPI_4_5MHZ, LSBFIRST, 0); } void loop() { - /* Send message */ - digitalWrite(CS, LOW); - spi1.send(buf, sizeof buf); - digitalWrite(CS,HIGH); + /* Send message */ + digitalWrite(NSS, LOW); + spi1.write(buf, sizeof buf); + digitalWrite(NSS, HIGH); delay(1000); } @@ -68,7 +69,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/test-dac.cpp b/examples/test-dac.cpp index ba766a4..40ae5d5 100644 --- a/examples/test-dac.cpp +++ b/examples/test-dac.cpp @@ -13,7 +13,7 @@ uint16 count = 0; void setup() { pinMode(BOARD_LED_PIN, OUTPUT); - digitalWrite(BOARD_LED_PIN,1); + digitalWrite(BOARD_LED_PIN, HIGH); Serial1.begin(9600); Serial1.println("**** Beginning DAC test"); @@ -36,11 +36,14 @@ void loop() { dac_write_channel(DAC, 2, count); } -int main(void) { +__attribute__((constructor)) void premain() { init(); +} + +int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/test-ring-buffer-insertion.cpp b/examples/test-ring-buffer-insertion.cpp index 8372a96..e86372a 100644 --- a/examples/test-ring-buffer-insertion.cpp +++ b/examples/test-ring-buffer-insertion.cpp @@ -4,7 +4,7 @@ * Does a basic test of functionality on rb_full_count(), rb_reset(), * rb_push_insert(), and rb_safe_insert(). * - * To test (no external hardware required): + * To test: * * - Connect a serial monitor to SerialUSB * - Press any key diff --git a/examples/test-serial-flush.cpp b/examples/test-serial-flush.cpp index 6c4e100..adc9c3e 100644 --- a/examples/test-serial-flush.cpp +++ b/examples/test-serial-flush.cpp @@ -4,23 +4,21 @@ #include "wirish.h" -#define COMM Serial1 - void setup() { - COMM.begin(9600); - COMM.println("Hello world!"); + Serial1.begin(9600); + Serial1.println("Hello world!"); } void loop() { - COMM.println("Waiting for multiple input..."); - while (COMM.available() < 5) + Serial1.println("Waiting for multiple input..."); + while (Serial1.available() < 5) ; - COMM.println(COMM.read()); - COMM.println(COMM.read()); - COMM.flush(); + Serial1.println(Serial1.read()); + Serial1.println(Serial1.read()); + Serial1.flush(); - if (COMM.available()) { - COMM.println("FAIL! Still had junk in the buffer..."); + if (Serial1.available()) { + Serial1.println("FAIL! Still had junk in the buffer..."); } } diff --git a/examples/test-serialusb.cpp b/examples/test-serialusb.cpp index 678c2b9..15ab913 100644 --- a/examples/test-serialusb.cpp +++ b/examples/test-serialusb.cpp @@ -3,27 +3,24 @@ #include "wirish.h" #include "usb.h" -#define LED_PIN BOARD_LED_PIN -#define BUT_PIN BOARD_BUTTON_PIN - -uint32 state = 0; #define QUICKPRINT 0 #define BIGSTUFF 1 #define NUMBERS 2 #define SIMPLE 3 #define ONOFF 4 +uint32 state = 0; + void setup() { /* Set up the LED to blink */ - pinMode(LED_PIN, OUTPUT); - - /* Set up the Button */ - pinMode(BUT_PIN, INPUT); + pinMode(BOARD_LED_PIN, OUTPUT); + /* Set up Serial2 for use as a debug channel */ Serial2.begin(9600); - Serial2.println("This is the debug channel. Press BUT."); - - waitForButtonPress(0); + Serial2.println("This is the debug channel. Press any key."); + while (!Serial2.available()) + ; + Serial2.read(); } uint8 c1 = '-'; @@ -32,14 +29,15 @@ void loop() { toggleLED(); delay(1000); - if(isButtonPressed()) { + if (Serial2.available()) { + Serial2.read(); state++; } - switch(state) { + switch (state) { case QUICKPRINT: - for(int i = 0; i<30; i++) { - usbSendBytes(&c1,1); + for (int i = 0; i < 30; i++) { + usbSendBytes(&c1, 1); SerialUSB.print('.'); SerialUSB.print('|'); } @@ -121,9 +119,8 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; } - diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp index bbf0adf..78c7307 100644 --- a/examples/test-systick.cpp +++ b/examples/test-systick.cpp @@ -1,16 +1,11 @@ // Tests the SysTick enable/disable functions -// + #include "wirish.h" #include "systick.h" -#define LED_PIN BOARD_LED_PIN -#define PWM_PIN 2 -#define BUT BOARD_BUTTON_PIN - void setup() { - /* Set up the LED to blink */ - pinMode(LED_PIN, OUTPUT); - pinMode(BUT, INPUT); + pinMode(BOARD_LED_PIN, OUTPUT); + pinMode(BOARD_BUTTON_PIN, INPUT); } bool disable = true; @@ -24,7 +19,7 @@ void loop() { for(i = 0; i < 150000; i++) ; - if(isButtonPressed()) { + if (isButtonPressed()) { if (disable) { systick_disable(); SerialUSB.println("Disabling SysTick"); @@ -47,7 +42,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/test-timers.cpp b/examples/test-timers.cpp index a4fbc8a..545597f 100644 --- a/examples/test-timers.cpp +++ b/examples/test-timers.cpp @@ -26,7 +26,7 @@ uint16 val2 = 10000; uint16 val3 = 10000; uint16 val4 = 10000; -// FIXME high density timer test (especially basic timers + DAC) +// FIXME [0.1.0] high density timer test (especially basic timers + DAC) timer_dev *timers[] = {TIMER1, TIMER2, TIMER3, TIMER4}; voidFuncPtr handlers[] = {handler1, handler2, handler3, handler4}; @@ -46,7 +46,6 @@ void setup() { // Send a message out Serial2 Serial2.begin(115200); Serial2.println("*** Initializing timers..."); - Serial2.println("foo"); timer_foreach(initTimer); Serial2.println("*** Done. Beginning timer test."); } @@ -110,7 +109,7 @@ void loop() { testSetTimerPeriod(30000); Serial2.println("Sanity check (with hand-coded reload and prescaler for " - "72 MHz timers):"); + "72 MHz timers):"); timer_set_mode(TIMER4, TIMER_CH1, TIMER_OUTPUT_COMPARE); timer_set_prescaler(TIMER4, 33); timer_set_reload(TIMER4, 65454); @@ -238,7 +237,7 @@ void testTimerChannels(timer_dev *dev) { } } -// FIXME move this into the new wirish timer implementation +// FIXME [0.0.10] move this into the new wirish timer implementation void setTimerPeriod(timer_dev *dev, uint32 period_us) { if (!period_us) { // FIXME handle this case @@ -291,7 +290,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/vga-leaf.cpp b/examples/vga-leaf.cpp index 9d9fce2..e663639 100644 --- a/examples/vga-leaf.cpp +++ b/examples/vga-leaf.cpp @@ -28,18 +28,12 @@ Created 20 July 2010 By Bryan Newbold for LeafLabs This code is released with no strings attached. - - Modified 4 March 2011 - By Marti Bolivar - Disabled SysTick, kept up-to-date with libmaple. */ // FIXME: generalize for Native and Mini #include "wirish.h" -#define LED_PIN BOARD_LED_PIN - // Pinouts -- you also must change the GPIO macros below if you change // these #define VGA_R 6 // STM32: A8 @@ -110,7 +104,7 @@ uint32 logo[y_max][x_max] = { void setup() { // Setup our pins - pinMode(LED_PIN, OUTPUT); + pinMode(BOARD_LED_PIN, OUTPUT); pinMode(VGA_R, OUTPUT); pinMode(VGA_G, OUTPUT); pinMode(VGA_B, OUTPUT); @@ -166,7 +160,6 @@ void loop() { // Everything happens in the interrupts! } - // This ISR will end horizontal sync for most of the image and // setup the vertical sync for higher line counts void isr_porch(void) { @@ -174,22 +167,22 @@ void isr_porch(void) { y++; logo_y = map(y, 0, 478, 0, y_max); // Back to the top - if(y >= 523) { + if (y >= 523) { y = 1; logo_y = 0; v_active = true; return; } // Other vsync stuff below the image - if(y >= 492) { + if (y >= 492) { VGA_V_HIGH; return; } - if(y >= 490) { + if (y >= 490) { VGA_V_LOW; return; } - if(y >= 479) { + if (y >= 479) { v_active = false; return; } @@ -207,7 +200,7 @@ void isr_start(void) { VGA_R_HIGH; // For each "pixel", go ON_COLOR or OFF_COLOR - for(x = 0; x < 16; x++) { + for (x = 0; x < 16; x++) { // setting the color several times is just an easy way to // delay, so the image is wider. if you only do the following // once, you'll be able to make the logo array a lot wider: @@ -242,7 +235,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; diff --git a/examples/vga-scope.cpp b/examples/vga-scope.cpp index 66e72e9..9aa8bcb 100644 --- a/examples/vga-scope.cpp +++ b/examples/vga-scope.cpp @@ -40,7 +40,6 @@ // FIXME: generalize for Native and Mini -#define LED_PIN BOARD_LED_PIN #define ANALOG_PIN 18 // Pinouts -- you also must change the GPIO macros below if you change @@ -90,9 +89,9 @@ void isr_stop(void); void isr_update(void); void setup() { - pinMode(LED_PIN, OUTPUT); + pinMode(BOARD_LED_PIN, OUTPUT); pinMode(ANALOG_PIN, INPUT_ANALOG); - digitalWrite(LED_PIN, 1); + digitalWrite(BOARD_LED_PIN, 1); pinMode(VGA_R, OUTPUT); pinMode(VGA_G, OUTPUT); pinMode(VGA_B, OUTPUT); @@ -138,26 +137,26 @@ void setup() { uint16 y = 0; uint16 val = 0; bool v_active = true; -const uint16 x_max = 60; // empirically (and lazily) determined +const uint16 x_max = 60; // empirically (and sloppily) determined void isr_porch(void) { VGA_H_HIGH; y++; val = map(analogRead(ANALOG_PIN), 0, 4095, 0, x_max); - if(y >= 523) { + if (y >= 523) { y = 1; v_active = true; return; } - if(y >= 492) { + if (y >= 492) { VGA_V_HIGH; return; } - if(y >= 490) { + if (y >= 490) { VGA_V_LOW; return; } - if(y >= 479) { + if (y >= 479) { v_active = false; return; } @@ -199,7 +198,7 @@ __attribute__((constructor)) void premain() { int main(void) { setup(); - while (1) { + while (true) { loop(); } return 0; -- cgit v1.2.3 From f432df24764cee2f7d1590650eeac4f3a121f25e Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Fri, 6 May 2011 20:11:48 -0400 Subject: Updating VGA examples for use with new timer API. --- examples/vga-leaf.cpp | 42 ++++++++++++++++++++++-------------------- examples/vga-scope.cpp | 18 +++++++++--------- 2 files changed, 31 insertions(+), 29 deletions(-) (limited to 'examples/vga-scope.cpp') diff --git a/examples/vga-leaf.cpp b/examples/vga-leaf.cpp index e663639..f31dc87 100644 --- a/examples/vga-leaf.cpp +++ b/examples/vga-leaf.cpp @@ -102,6 +102,8 @@ uint32 logo[y_max][x_max] = { {0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}, }; +HardwareTimer timer(4); + void setup() { // Setup our pins pinMode(BOARD_LED_PIN, OUTPUT); @@ -132,25 +134,25 @@ void setup() { systick_disable(); // Configure - Timer4.pause(); // while we configure - Timer4.setPrescaleFactor(1); // Full speed - Timer4.setChannel1Mode(TIMER_OUTPUTCOMPARE); - Timer4.setChannel2Mode(TIMER_OUTPUTCOMPARE); - Timer4.setChannel3Mode(TIMER_OUTPUTCOMPARE); - Timer4.setChannel4Mode(TIMER_OUTPUTCOMPARE); - Timer4.setOverflow(2287); // Total line time - - Timer4.setCompare1(200); - Timer4.attachCompare1Interrupt(isr_porch); - Timer4.setCompare2(300); - Timer4.attachCompare2Interrupt(isr_start); - Timer4.setCompare3(2170); - Timer4.attachCompare3Interrupt(isr_stop); - Timer4.setCompare4(1); // Could be zero I guess - Timer4.attachCompare4Interrupt(isr_update); - - Timer4.setCount(0); // Ready... - Timer4.resume(); // Go! + timer.pause(); // while we configure + timer.setPrescaleFactor(1); // Full speed + timer.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE); + timer.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE); + timer.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE); + timer.setMode(TIMER_CH4, TIMER_OUTPUT_COMPARE); + timer.setOverflow(2287); // Total line time + + timer.setCompare(TIMER_CH1, 200); + timer.attachInterrupt(TIMER_CH1, isr_porch); + timer.setCompare(TIMER_CH2, 300); + timer.attachInterrupt(TIMER_CH2, isr_start); + timer.setCompare(TIMER_CH3, 2170); + timer.attachInterrupt(TIMER_CH3, isr_stop); + timer.setCompare(TIMER_CH4, 1); // Could be zero, I guess + timer.attachInterrupt(TIMER_CH4, isr_update); + + timer.setCount(0); // Ready... + timer.resume(); // Go! } void loop() { @@ -203,7 +205,7 @@ void isr_start(void) { for (x = 0; x < 16; x++) { // setting the color several times is just an easy way to // delay, so the image is wider. if you only do the following - // once, you'll be able to make the logo array a lot wider: + // once, you'll be able to make the logo array bigger: VGA_COLOR(logo[logo_y][x]); VGA_COLOR(logo[logo_y][x]); VGA_COLOR(logo[logo_y][x]); diff --git a/examples/vga-scope.cpp b/examples/vga-scope.cpp index 9aa8bcb..b5fa8a5 100644 --- a/examples/vga-scope.cpp +++ b/examples/vga-scope.cpp @@ -76,7 +76,7 @@ // set has priority, so clear every bit and set some given bits: #define VGA_COLOR(c) (*ABSRR = c | \ - BIT(RBIT+16) | BIT(GBIT+16) | BIT(BBIT+16)) + BIT(RBIT + 16) | BIT(GBIT + 16) | BIT(BBIT + 16)) #define VGA_V_HIGH *ABSRR = BIT(6) #define VGA_V_LOW *ABRR = BIT(6) @@ -116,15 +116,15 @@ void setup() { timer_pause(TIMER4); timer_set_prescaler(TIMER4, 0); - timer_set_mode(TIMER4, 1, TIMER_OUTPUTCOMPARE); - timer_set_mode(TIMER4, 2, TIMER_OUTPUTCOMPARE); - timer_set_mode(TIMER4, 3, TIMER_OUTPUTCOMPARE); - timer_set_mode(TIMER4, 4, TIMER_OUTPUTCOMPARE); + timer_set_mode(TIMER4, 1, TIMER_OUTPUT_COMPARE); + timer_set_mode(TIMER4, 2, TIMER_OUTPUT_COMPARE); + timer_set_mode(TIMER4, 3, TIMER_OUTPUT_COMPARE); + timer_set_mode(TIMER4, 4, TIMER_OUTPUT_COMPARE); timer_set_reload(TIMER4, 2287); - timer_set_compare_value(TIMER4, 1, 200); - timer_set_compare_value(TIMER4, 2, 250); - timer_set_compare_value(TIMER4, 3, 2170); // 2219 max... - timer_set_compare_value(TIMER4, 4, 1); + timer_set_compare(TIMER4, 1, 200); + timer_set_compare(TIMER4, 2, 250); + timer_set_compare(TIMER4, 3, 2170); // 2219 max... + timer_set_compare(TIMER4, 4, 1); timer_attach_interrupt(TIMER4, 1, isr_porch); timer_attach_interrupt(TIMER4, 2, isr_start); timer_attach_interrupt(TIMER4, 3, isr_stop); -- cgit v1.2.3