diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/blinky.cpp | 22 | ||||
| -rw-r--r-- | examples/spi_master.cpp | 71 | 
2 files changed, 73 insertions, 20 deletions
| diff --git a/examples/blinky.cpp b/examples/blinky.cpp index 8a8b0d8..e156bf2 100644 --- a/examples/blinky.cpp +++ b/examples/blinky.cpp @@ -23,20 +23,10 @@   * ****************************************************************************/
  /**
 - *  @file example_main_blinky.cpp
 - *
 - *  @brief Example main.cpp. Blinks the LED, pin 13
 + *  @brief blinky.cpp. Blinks the LED, pin 13
   */
 -#ifndef _EXAMPLE_MAIN_BLINKY_H_
 -#define _EXAMPLE_MAIN_BLINKY_H_
 -
 -#endif
 -#include "wiring.h"
 -#include "HardwareSerial.h"
 -#include "wiring_math.h"
 -#include "HardwareUsb.h"
 -#include "usb.h"
 +#include "wirish.h"
  #define TEST_PIN 13
 @@ -61,11 +51,3 @@ int main(void) {      }
      return 0;
  }
 -
 -/* Required for C++ hackery */
 -/* TODO: This really shouldn't go here... move it later
 - * */
 -extern "C" void __cxa_pure_virtual(void) {
 -    while(1)
 -        ;
 -}
 diff --git a/examples/spi_master.cpp b/examples/spi_master.cpp new file mode 100644 index 0000000..19679f7 --- /dev/null +++ b/examples/spi_master.cpp @@ -0,0 +1,71 @@ +/* *****************************************************************************
 + * 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
 + * 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 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.
 + *
 + *  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
 + *
 + */
 +
 +#include "wirish.h"
 +#include "HardwareSPI.h"
 +
 +#define CS      10
 +
 +byte buf[] = "Hello world!";
 +
 +HardwareSPI spi1(1);
 +
 +void setup() {
 +   /* Set up chip select as output  */
 +   pinMode(CS, OUTPUT);
 +
 +   /* CS is usually active low, so initialize it high  */
 +   digitalWrite(CS, HIGH);
 +
 +   /* Initialize SPI   */
 +   spi1.begin(SPI_4_5MHZ, LSBFIRST, 0);
 +}
 +
 +void loop() {
 +   /* Send message  */
 +   digitalWrite(CS, LOW);
 +   spi1.send(buf, sizeof buf);
 +   digitalWrite(CS,HIGH);
 +   delay(1000);
 +}
 +
 +int main(void) {
 +   init();
 +   setup();
 +
 +   while (1) {
 +      loop();
 +   }
 +   return 0;
 +}
 | 
