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/test-systick.cpp | 50 +++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'examples/test-systick.cpp') diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp index 247892d..c7b5529 100644 --- a/examples/test-systick.cpp +++ b/examples/test-systick.cpp @@ -3,54 +3,48 @@ #include "wirish.h" #include "systick.h" -#define LED_PIN 13 -#define PWM_PIN 2 -#define BUT 38 +#define LED_PIN BOARD_LED_PIN +#define PWM_PIN 2 +#define BUT BOARD_BUTTON_PIN -void setup() -{ +void setup() { /* Set up the LED to blink */ pinMode(LED_PIN, OUTPUT); - - /* Turn on PWM on pin PWM_PIN */ - pinMode(PWM_PIN, PWM); - pwmWrite(PWM_PIN, 0x8000); - - pinMode(BUT, INPUT_PULLDOWN); + pinMode(BUT, INPUT); } -int toggle = 0; +bool disable = true; long time = 0; void loop() { - toggle ^= 1; - digitalWrite(LED_PIN, toggle); + volatile int i = 0; + toggleLED(); // An artificial delay - int16 i = 1; - float j = 1; - for(i=0; i<6553; i++) { - j = sqrt(j) + 1; - } - - if(digitalRead(BUT)) { - systick_disable(); - } else { - systick_resume(); + for(i = 0; i < 150000; i++) + ; + + if(isButtonPressed()) { + if (disable) { + systick_disable(); + SerialUSB.println("Disabling SysTick"); + } else { + SerialUSB.println("Re-enabling SysTick"); + systick_resume(); + } + disable = !disable; } - //SerialUSB.println(micros()); // there is a bug with this SerialUSB.println(millis()); } // Force init to be called *first*, i.e. before static object allocation. // Otherwise, statically allocated object that need libmaple may fail. - __attribute__(( constructor )) void premain() { +__attribute__((constructor)) void premain() { init(); } -int main(void) -{ +int main(void) { setup(); while (1) { -- cgit v1.2.3 From b835b9864d7fa17de8eeaaafbb1b17f2252e68a5 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Fri, 1 Apr 2011 03:15:27 -0400 Subject: SysTick refactor. For the changelog: * util.h is free of __read(), __write(), etc. macros. * systick_resume() was renamed systick_enable(). --- examples/test-systick.cpp | 2 +- libmaple/systick.c | 54 ++++++++++++++++++++++++----------------------- libmaple/systick.h | 46 +++++++++++++++++++++++++++++++++------- libmaple/util.h | 37 +++++++++++++------------------- 4 files changed, 82 insertions(+), 57 deletions(-) (limited to 'examples/test-systick.cpp') diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp index c7b5529..bbf0adf 100644 --- a/examples/test-systick.cpp +++ b/examples/test-systick.cpp @@ -30,7 +30,7 @@ void loop() { SerialUSB.println("Disabling SysTick"); } else { SerialUSB.println("Re-enabling SysTick"); - systick_resume(); + systick_enable(); } disable = !disable; } diff --git a/libmaple/systick.c b/libmaple/systick.c index b9a52c1..c04f4f3 100644 --- a/libmaple/systick.c +++ b/libmaple/systick.c @@ -26,44 +26,46 @@ * @brief System timer interrupt handler and initialization routines */ -#include "libmaple.h" #include "systick.h" -#define SYSTICK_RELOAD 0xE000E014 // Reload value register -#define SYSTICK_CNT 0xE000E018 // Current value register -#define SYSTICK_CALIB 0xE000E01C // Calibration value register - -#define SYSTICK_SRC_HCLK BIT(2) // Use core clock -#define SYSTICK_TICKINT BIT(1) // Interrupt on systick countdown -#define SYSTICK_ENABLE BIT(0) // Turn on the counter - volatile uint32 systick_timer_millis; +/** + * @brief Initialize and enable SysTick. + * + * Clocks the system timer with the core clock, turns it on, and + * enables interrupts. + * + * @param reload_val Appropriate reload counter to tick every 1 ms. + */ void systick_init(uint32 reload_val) { - /* Set the reload counter to tick every 1ms */ - __write(SYSTICK_RELOAD, reload_val); - - /* Clock the system timer with the core clock and turn it on, - * interrrupt every 1ms to keep track of millis() */ - __write(SYSTICK_CSR, SYSTICK_SRC_HCLK | - SYSTICK_ENABLE | - SYSTICK_TICKINT); + SYSTICK_BASE->RVR = reload_val; + systick_enable(); } +/** + * Clock the system timer with the core clock, but don't turn it + * on or enable interrupt. + */ void systick_disable() { - /* clock the system timer with the core clock, but don't turn it - on or enable interrupt. */ - __write(SYSTICK_CSR, SYSTICK_SRC_HCLK); + SYSTICK_BASE->CSR = SYSTICK_CSR_CLKSOURCE_CORE; } -void systick_resume() { - /* re-enable init registers without changing reload val */ - __write(SYSTICK_CSR, SYSTICK_SRC_HCLK | - SYSTICK_ENABLE | - SYSTICK_TICKINT); +/** + * Clock the system timer with the core clock and turn it on; + * interrupt every 1 ms, for systick_timer_millis. + */ +void systick_enable() { + /* re-enables init registers without changing reload val */ + SYSTICK_BASE->CSR = (SYSTICK_CSR_CLKSOURCE_CORE | + SYSTICK_CSR_ENABLE | + SYSTICK_CSR_TICKINT_PEND); } -/** SysTick interrupt handler. Bumps up the tick counter. */ +/* + * SysTick ISR + */ + void __exc_systick(void) { systick_timer_millis++; } diff --git a/libmaple/systick.h b/libmaple/systick.h index 33a3cf8..35b4cb9 100644 --- a/libmaple/systick.h +++ b/libmaple/systick.h @@ -31,30 +31,60 @@ #ifndef _SYSTICK_H_ #define _SYSTICK_H_ -#include "libmaple.h" +#include "libmaple_types.h" +#include "util.h" #ifdef __cplusplus extern "C"{ #endif -#define SYSTICK_CSR 0xE000E010 // Control and status register -#define SYSTICK_CNT 0xE000E018 // Current value register +/** SysTick register map type */ +typedef struct systick_reg_map { + __io uint32 CSR; /**< Control and status register */ + __io uint32 RVR; /**< Reload value register */ + __io uint32 CNT; /**< Current value register ("count") */ + __io uint32 CVR; /**< Calibration value register */ +} systick_reg_map; -#define SYSTICK_CSR_COUNTFLAG BIT(16) +/** SysTick register map base pointer */ +#define SYSTICK_BASE ((struct systick_reg_map*)0xE000E010) -/** System elapsed time in milliseconds */ +/* + * Register bit definitions. + */ + +/* Control and status register */ + +#define SYSTICK_CSR_COUNTFLAG BIT(16) +#define SYSTICK_CSR_CLKSOURCE BIT(2) +#define SYSTICK_CSR_CLKSOURCE_EXTERNAL 0 +#define SYSTICK_CSR_CLKSOURCE_CORE BIT(2) +#define SYSTICK_CSR_TICKINT BIT(1) +#define SYSTICK_CSR_TICKINT_PEND BIT(1) +#define SYSTICK_CSR_TICKINT_NO_PEND 0 +#define SYSTICK_CSR_ENABLE BIT(0) +#define SYSTICK_CSR_ENABLE_MULTISHOT BIT(0) +#define SYSTICK_CSR_ENABLE_DISABLED 0 + +/* Calibration value register */ + +#define SYSTICK_CVR_NOREF BIT(31) +#define SYSTICK_CVR_SKEW BIT(30) +#define SYSTICK_CVR_TENMS 0xFFFFFF + +/** System elapsed time, in milliseconds */ extern volatile uint32 systick_timer_millis; void systick_init(uint32 reload_val); void systick_disable(); -void systick_resume(); +void systick_enable(); static inline uint32 systick_get_count(void) { - return __read(SYSTICK_CNT); + return SYSTICK_BASE->CNT; } static inline uint32 systick_check_underflow(void) { - return (__read(SYSTICK_CSR) & SYSTICK_CSR_COUNTFLAG); + return SYSTICK_BASE->CSR & SYSTICK_CSR_COUNTFLAG; } #ifdef __cplusplus diff --git a/libmaple/util.h b/libmaple/util.h index 25dd56e..aff70e1 100644 --- a/libmaple/util.h +++ b/libmaple/util.h @@ -23,14 +23,12 @@ *****************************************************************************/ /** - * @file util.h - * - * @brief Various macros and utility procedures. + * @file util.h + * @brief Miscellaneous utility macros and procedures. */ #include "libmaple_types.h" -/* Generally "useful" utility procedures */ #ifndef _UTIL_H_ #define _UTIL_H_ @@ -38,33 +36,23 @@ extern "C"{ #endif -/* Debug configuration */ -#define DEBUG_NONE 0 -#define DEBUG_FAULT 1 -#define DEBUG_ALL 2 - -#ifndef DEBUG_LEVEL -#define DEBUG_LEVEL DEBUG_ALL -#endif +/* + * Bit manipulation + */ #define BIT(shift) (1UL << (shift)) #define BIT_MASK_SHIFT(mask, shift) ((mask) << (shift)) - -/* Return bits m to n of x */ +/* Bits m to n of x */ #define GET_BITS(x, m, n) ((((uint32)x) << (31 - (n))) >> ((31 - (n)) + (m))) +#define IS_POWER_OF_TWO(v) (v && !(v & (v - 1))) /* * Register reads and writes */ -#define __set_bits(addr, mask) (*(volatile uint32*)(addr) |= (uint32)(mask)) -#define __clear_bits(addr, mask) (*(volatile uint32*)(addr) &= (uint32)~(mask)) -#define __get_bits(addr, mask) (*(volatile uint32*)(addr) & (uint32)(mask)) #define __read(reg) (*(volatile uint32*)(reg)) #define __write(reg, value) (*(volatile uint32*)(reg) = (value)) -#define IS_POWER_OF_TWO(v) (v && !(v & (v - 1))) - /* * Failure routines */ @@ -77,13 +65,20 @@ void throb(void); * Asserts and debug levels */ +#define DEBUG_NONE 0 +#define DEBUG_FAULT 1 +#define DEBUG_ALL 2 + +#ifndef DEBUG_LEVEL +#define DEBUG_LEVEL DEBUG_ALL +#endif + #if DEBUG_LEVEL >= DEBUG_ALL #define ASSERT(exp) \ if (exp) { \ } else { \ _fail(__FILE__, __LINE__, #exp); \ } - #else #define ASSERT(exp) (void)((0)) #endif @@ -94,7 +89,6 @@ void throb(void); } else { \ _fail(__FILE__, __LINE__, #exp); \ } - #else #define ASSERT_FAULT(exp) (void)((0)) #endif @@ -104,4 +98,3 @@ void throb(void); #endif #endif - -- 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/test-systick.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