Test program for PwmSound class. Provides tests (demos) for the various sound generating functions in the class. Includes several MML melodies and music clips to test the play() function. Tested on an mbed LPC1768.

Dependencies:   PwmSound mbed

Committer:
paulg
Date:
Tue May 06 13:23:02 2014 +0000
Revision:
1:46f098444d0c
Play music written in Music Macro Language (MML) with your mbed! This program fully tests the revised PwmSound library including the new play() function. It includes several MML melodies and music clips.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
paulg 1:46f098444d0c 1 /******************************************************************************
paulg 1:46f098444d0c 2 * File: FastOut.h
paulg 1:46f098444d0c 3 * Author: Paul Griffith
paulg 1:46f098444d0c 4 * Created: 18 Jun 2011
paulg 1:46f098444d0c 5 * Last Edit: 29 Sep 2013
paulg 1:46f098444d0c 6 * Version: 1.10
paulg 1:46f098444d0c 7 *
paulg 1:46f098444d0c 8 * Description:
paulg 1:46f098444d0c 9 * High-speed digital output class for mbed
paulg 1:46f098444d0c 10 *
paulg 1:46f098444d0c 11 * Usage: FastOut<PinName> name;
paulg 1:46f098444d0c 12 * PinName uses the same assignment operators as with DigitalOut
paulg 1:46f098444d0c 13 * Example: FastOut<LED2> led2;
paulg 1:46f098444d0c 14 * A simple loop as below takes 4 clocks. This gives a 24MHz output waveform
paulg 1:46f098444d0c 15 * while (1) { out = 1; out = 0; }
paulg 1:46f098444d0c 16 *
paulg 1:46f098444d0c 17 * Class code by Igor Skochinsky. Copied from posting by Sylvain Azerian:
paulg 1:46f098444d0c 18 * http://sylvain.azarian.org/doku.php?id=mbed.
paulg 1:46f098444d0c 19 *
paulg 1:46f098444d0c 20 * Copyright (c) 2011-2013 Paul Griffith, MIT License
paulg 1:46f098444d0c 21 *
paulg 1:46f098444d0c 22 * Permission is hereby granted, free of charge, to any person obtaining a copy
paulg 1:46f098444d0c 23 * of this software and associated documentation files (the "Software"), to
paulg 1:46f098444d0c 24 * deal in the Software without restriction, including without limitation the
paulg 1:46f098444d0c 25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
paulg 1:46f098444d0c 26 * sell copies of the Software, and to permit persons to whom the Software is
paulg 1:46f098444d0c 27 * furnished to do so, subject to the following conditions:
paulg 1:46f098444d0c 28 *
paulg 1:46f098444d0c 29 * The above copyright notice and this permission notice shall be included in
paulg 1:46f098444d0c 30 * all copies or substantial portions of the Software.
paulg 1:46f098444d0c 31 *
paulg 1:46f098444d0c 32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
paulg 1:46f098444d0c 33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
paulg 1:46f098444d0c 34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
paulg 1:46f098444d0c 35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
paulg 1:46f098444d0c 36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
paulg 1:46f098444d0c 37 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
paulg 1:46f098444d0c 38 * IN THE SOFTWARE.
paulg 1:46f098444d0c 39 *
paulg 1:46f098444d0c 40 * Modifications:
paulg 1:46f098444d0c 41 * Ver Date By Details
paulg 1:46f098444d0c 42 * 1.00 18Jun11 PG File created.
paulg 1:46f098444d0c 43 * 1.01 20Jun11 PG Tidied up, added header block.
paulg 1:46f098444d0c 44 * 1.10 29Sep13 PG Replaced link to MIT Licence with full MIT Licence text.
paulg 1:46f098444d0c 45 *
paulg 1:46f098444d0c 46 ******************************************************************************/
paulg 1:46f098444d0c 47
paulg 1:46f098444d0c 48 #ifndef MBED_FASTOUT_H
paulg 1:46f098444d0c 49 #define MBED_FASTOUT_H
paulg 1:46f098444d0c 50
paulg 1:46f098444d0c 51 #include "mbed.h"
paulg 1:46f098444d0c 52
paulg 1:46f098444d0c 53 template <PinName pin> class FastOut {
paulg 1:46f098444d0c 54 // pin = LPC_GPIO0_BASE + port * 32 + bit
paulg 1:46f098444d0c 55 // port = (pin - LPC_GPIO0_BASE) / 32
paulg 1:46f098444d0c 56 // bit = (pin - LPC_GPIO0_BASE) % 32
paulg 1:46f098444d0c 57
paulg 1:46f098444d0c 58 // helper function to calculate the GPIO port definition for the pin
paulg 1:46f098444d0c 59 // we rely on the fact that port structs are 0x20 bytes apart
paulg 1:46f098444d0c 60 inline LPC_GPIO_TypeDef* portdef() {
paulg 1:46f098444d0c 61 return (LPC_GPIO_TypeDef*)(LPC_GPIO0_BASE + ((pin - P0_0)/32)*0x20);
paulg 1:46f098444d0c 62 };
paulg 1:46f098444d0c 63
paulg 1:46f098444d0c 64 // helper function to calculate the mask for the pin's bit in the port
paulg 1:46f098444d0c 65 inline uint32_t mask() {
paulg 1:46f098444d0c 66 return 1UL<<((pin - LPC_GPIO0_BASE) % 32);
paulg 1:46f098444d0c 67 };
paulg 1:46f098444d0c 68
paulg 1:46f098444d0c 69 public:
paulg 1:46f098444d0c 70 FastOut() {
paulg 1:46f098444d0c 71 // set FIODIR bit to 1 (output)
paulg 1:46f098444d0c 72 portdef()->FIODIR |= mask();
paulg 1:46f098444d0c 73 }
paulg 1:46f098444d0c 74 void write(int value) {
paulg 1:46f098444d0c 75 if ( value )
paulg 1:46f098444d0c 76 portdef()->FIOSET = mask();
paulg 1:46f098444d0c 77 else
paulg 1:46f098444d0c 78 portdef()->FIOCLR = mask();
paulg 1:46f098444d0c 79 }
paulg 1:46f098444d0c 80 int read() {
paulg 1:46f098444d0c 81 return (portdef()->FIOPIN) & mask() != 0;
paulg 1:46f098444d0c 82 }
paulg 1:46f098444d0c 83 FastOut& operator= (int value) {
paulg 1:46f098444d0c 84 write(value);
paulg 1:46f098444d0c 85 return *this;
paulg 1:46f098444d0c 86 };
paulg 1:46f098444d0c 87 FastOut& operator= (FastOut& rhs) {
paulg 1:46f098444d0c 88 return write(rhs.read());
paulg 1:46f098444d0c 89 };
paulg 1:46f098444d0c 90 operator int() {
paulg 1:46f098444d0c 91 return read();
paulg 1:46f098444d0c 92 };
paulg 1:46f098444d0c 93 };
paulg 1:46f098444d0c 94
paulg 1:46f098444d0c 95 #endif
paulg 1:46f098444d0c 96
paulg 1:46f098444d0c 97 // END of FastOut.h