An input/output controller for virtual pinball machines, with plunger position tracking, accelerometer-based nudge sensing, button input encoding, and feedback device control.

Dependencies:   USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA

/media/uploads/mjr/pinscape_no_background_small_L7Miwr6.jpg

The Pinscape Controller is a special-purpose software project that I wrote for my virtual pinball machine.

New version: V2 is now available! The information below is for version 1, which will continue to be available for people who prefer the original setup.

What exactly is a virtual pinball machine? It's basically a video-game pinball emulator built to look like a real pinball machine. (The picture at right is the one I built.) You start with a standard pinball cabinet, either built from scratch or salvaged from a real machine. Inside, you install a PC motherboard to run the software, and install TVs in place of the playfield and backglass. Several Windows pinball programs can take advantage of this setup, including the open-source project Visual Pinball, which has hundreds of tables available. Building one of these makes a great DIY project, and it's a good way to add to your skills at woodworking, computers, and electronics. Check out the Cabinet Builders' Forum on vpforums.org for lots of examples and advice.

This controller project is a key piece in my setup that helps integrate the video game into the pinball cabinet. It handles several input/output tasks that are unique to virtual pinball machines. First, it lets you connect a mechanical plunger to the software, so you can launch the ball like on a real machine. Second, it sends "nudge" data to the software, based on readings from an accelerometer. This lets you interact with the game physically, which makes the playing experience more realistic and immersive. Third, the software can handle button input (for wiring flipper buttons and other cabinet buttons), and fourth, it can control output devices (for tactile feedback, button lights, flashers, and other special effects).

Documentation

The Hardware Build Guide (PDF) has detailed instructions on how to set up a Pinscape Controller for your own virtual pinball cabinet.

Update notes

December 2015 version: This version fully supports the new Expansion Board project, but it'll also run without it. The default configuration settings haven't changed, so existing setups should continue to work as before.

August 2015 version: Be sure to get the latest version of the Config Tool for windows if you're upgrading from an older version of the firmware. This update adds support for TSL1412R sensors (a version of the 1410 sensor with a slightly larger pixel array), and a config option to set the mounting orientation of the board in the firmware rather than in VP (for better support for FP and other pinball programs that don't have VP's flexibility for setting the rotation).

Feb/March 2015 software versions: If you have a CCD plunger that you've been using with the older versions, and the plunger stops working (or doesn't work as well) after you update to the latest version, you might need to increase the brightness of your light source slightly. Check the CCD exposure with the Windows config tool to see if it looks too dark. The new software reads the CCD much more quickly than the old versions did. This makes the "shutter speed" faster, which might require a little more light to get the same readings. The CCD is actually really tolerant of varying light levels, so you probably won't have to change anything for the update - I didn't. But if you do have any trouble, have a look at the exposure meter and try a slightly brighter light source if the exposure looks too dark.

Downloads

  • Config tool for Windows (.exe and C# source): this is a Windows program that lets you view the raw pixel data from the CCD sensor, trigger plunger calibration mode, and configure some of the software options on the controller.
  • Custom VP builds: I created modified versions of Visual Pinball 9.9 and Physmod5 that you might want to use in combination with this controller. The modified versions have special handling for plunger calibration specific to the Pinscape Controller, as well as some enhancements to the nudge physics. If you're not using the plunger, you might still want it for the nudge improvements. The modified version also works with any other input controller, so you can get the enhanced nudging effects even if you're using a different plunger/nudge kit. The big change in the modified versions is a "filter" for accelerometer input that's designed to make the response to cabinet nudges more realistic. It also makes the response more subdued than in the standard VP, so it's not to everyone's taste. The downloads include both the updated executables and the source code changes, in case you want to merge the changes into your own custom version(s).

    Note! These features are now standard in the official VP 9.9.1 and VP 10 releases, so you don't need my custom builds if you're using 9.9.1 or 10 or later. I don't think there's any reason to use my 9.9 instead of the official 9.9.1, but I'm leaving it here just in case. In the official VP releases, look for the checkbox "Enable Nudge Filter" in the Keys preferences dialog. (There's no checkbox in my custom builds, though; the filter is simply always on in those.)
  • Output circuit shopping list: This is a saved shopping cart at mouser.com with the parts needed for each output driver, if you want to use the LedWiz emulator feature. Note that quantities in the cart are for one output channel, so multiply everything by the number of channels you plan to use, except that you only need one of the ULN2803 transistor array chips for each eight output circuits.
  • Lemming77's potentiometer mounting bracket and shooter rod connecter: Sketchup designs for 3D-printable parts for mounting a slide potentiometer as the plunger sensor. These were designed for a particular slide potentiometer that used to be available from an Aliexpress.com seller but is no longer listed. You can probably use this design as a starting point for other similar devices; just check the dimensions before committing the design to plastic.

Features

  • Plunger position sensing, using a TAOS TSL 1410R CCD linear array sensor. This sensor is a 1280 x 1 pixel array at 400 dpi, which makes it about 3" long - almost exactly the travel distance of a standard pinball plunger. The idea is that you install the sensor just above (within a few mm of) the shooter rod on the inside of the cabinet, with the CCD window facing down, aligned with and centered on the long axis of the shooter rod, and positioned so that the rest position of the tip is about 1/2" from one end of the window. As you pull back the plunger, the tip will travel down the length of the window, and the maximum retraction point will put the tip just about at the far end of the window. Put a light source below, facing the sensor - I'm using two typical 20 mA blue LEDs about 8" away (near the floor of the cabinet) with good results. The principle of operation is that the shooter rod casts a shadow on the CCD, so pixels behind the rod will register lower brightness than pixels that aren't in the shadow. We scan down the length of the sensor for the edge between darker and brighter, and this tells us how far back the rod has been pulled. We can read the CCD at about 25-30 ms intervals, so we can get rapid updates. We pass the readings reports to VP via our USB joystick reports.

    The hardware build guide includes schematics showing how to wire the CCD to the KL25Z. It's pretty straightforward - five wires between the two devices, no external components needed. Two GPIO ports are used as outputs to send signals to the device and one is used as an ADC in to read the pixel brightness inputs. The config tool has a feature that lets you display the raw pixel readings across the array, so you can test that the CCD is working and adjust the light source to get the right exposure level.

    Alternatively, you can use a slide potentiometer as the plunger sensor. This is a cheaper and somewhat simpler option that seems to work quite nicely, as you can see in Lemming77's video of this setup in action. This option is also explained more fully in the build guide.
  • Nudge sensing via the KL25Z's on-board accelerometer. Mounting the board in your cabinet makes it feel the same accelerations the cabinet experiences when you nudge it. Visual Pinball already knows how to interpret accelerometer input as nudging, so we simply feed the acceleration readings to VP via the joystick interface.
  • Cabinet button wiring. Up to 24 pushbuttons and switches can be wired to the controller for input controls (for example, flipper buttons, the Start button, the tilt bob, coin slot switches, and service door buttons). These appear to Windows as joystick buttons. VP can map joystick buttons to pinball inputs via its keyboard preferences dialog. (You can raise the 24-button limit by editing the source code, but since all of the GPIO pins are allocated, you'll have to reassign pins currently used for other functions.)
  • LedWiz emulation (limited). In addition to emulating a joystick, the device emulates the LedWiz USB interface, so controllers on the PC side such as DirectOutput Framework can recognize it and send it commands to control lights, solenoids, and other feedback devices. 22 GPIO ports are assigned by default as feedback device outputs. This feature has some limitations. The big one is that the KL25Z hardware only has 10 PWM channels, which isn't enough for a fully decked-out cabinet. You also need to build some external power driver circuitry to use this feature, because of the paltry 4mA output capacity of the KL25Z GPIO ports. The build guide includes instructions for a simple and robust output circuit, including part numbers for the exact components you need. It's not hard if you know your way around a soldering iron, but just be aware that it'll take a little work.

Warning: This is not replacement software for the VirtuaPin plunger kit. If you bought the VirtuaPin kit, please don't try to install this software. The VP kit happens to use the same microcontroller board, but the rest of its hardware is incompatible. The VP kit uses a different type of sensor for its plunger and has completely different button wiring, so the Pinscape software won't work properly with it.

Files at this revision

API Documentation at this revision

Comitter:
mjr
Date:
Mon Feb 15 20:30:32 2016 +0000
Parent:
44:b5ac89b9cd5d
Commit message:
More work in progress on CCD speedups;

Changed in this revision

AltAnalogIn/AltAnalogIn.h Show annotated file Show diff for this revision Revisions of this file
AltAnalogIn/AltAnalogIn_KL25Z.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleDMA.lib Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA.h Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_KL25.h Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_KL25_46.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_KL46.h Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_LPC1768.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_LPC1768.h Show annotated file Show diff for this revision Revisions of this file
SimpleDMA/SimpleDMA_common.cpp Show annotated file Show diff for this revision Revisions of this file
TSL1410R/tsl1410r.h Show annotated file Show diff for this revision Revisions of this file
TSL1410R/tsl1410r_dma.cpp Show annotated file Show diff for this revision Revisions of this file
TSL1410R/tsl1410r_orig.h Show annotated file Show diff for this revision Revisions of this file
ccdSensor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
plunger.h Show annotated file Show diff for this revision Revisions of this file
--- a/AltAnalogIn/AltAnalogIn.h	Sun Feb 07 03:07:11 2016 +0000
+++ b/AltAnalogIn/AltAnalogIn.h	Mon Feb 15 20:30:32 2016 +0000
@@ -23,65 +23,64 @@
  */
 #include "mbed.h"
 #include "pinmap.h"
+#include "SimpleDMA.h"
+
+// KL25Z definitions
+#if defined TARGET_KLXX
+
+// Maximum ADC clock for KL25Z in 12-bit mode - 18 MHz per the data sheet
+#define MAX_FADC_12BIT      18000000
+
+#define CHANNELS_A_SHIFT     5          // bit position in ADC channel number of A/B mux
+#define ADC_CFG1_ADLSMP      0x10       // long sample time mode
+#define ADC_SC1_AIEN         0x40       // interrupt enable
+#define ADC_SC2_ADLSTS(mode) (mode)     // long sample time select - bits 1:0 of CFG2
+#define ADC_SC2_DMAEN        0x04       // DMA enable
+#define ADC_SC3_CONTINUOUS   0x08       // continuous conversion mode
+
+#else
+    #error "This target is not currently supported"
+#endif
 
 #if !defined TARGET_LPC1768 && !defined TARGET_KLXX && !defined TARGET_LPC408X && !defined TARGET_LPC11UXX && !defined TARGET_K20D5M
     #error "Target not supported"
 #endif
 
- /** A class similar to AnalogIn, only faster, for LPC1768, LPC408X and KLxx
- *
- * AnalogIn does a single conversion when you read a value (actually several conversions and it takes the median of that).
- * This library runns the ADC conversion automatically in the background.
- * When read is called, it immediatly returns the last sampled value.
- *
- * LPC1768 / LPC4088
- * Using more ADC pins in continuous mode will decrease the conversion rate (LPC1768:200kHz/LPC4088:400kHz).
- * If you need to sample one pin very fast and sometimes also need to do AD conversions on another pin,
- * you can disable the continuous conversion on that ADC channel and still read its value.
+ /** A class similar to AnalogIn, but much faster.  This class is optimized 
+ * for taking a string of readings from a single input.
  *
- * KLXX
- * Multiple Fast instances can be declared of which only ONE can be continuous (all others must be non-continuous).
- *
- * When continuous conversion is disabled, a read will block until the conversion is complete
- * (much like the regular AnalogIn library does).
- * Each ADC channel can be enabled/disabled separately.
- *
- * IMPORTANT : It does not play nicely with regular AnalogIn objects, so either use this library or AnalogIn, not both at the same time!!
- *
- * Example for the KLxx processors:
- * @code
- * // Print messages when the AnalogIn is greater than 50%
- *
- * #include "mbed.h"
+ * This is a heavily modified version of the popular FastAnalogIn class.
+ * Like FastAnalogIn, this class uses the continuous conversion mode to
+ * achieve faster read times.  It adds interrupt callbacks on each
+ * conversion, and DMA transfer of the input data to memory (or to another
+ * peripheral) using the SimpleDMA class.  DMA makes a huge difference -
+ * it speeds up the sampling time by about 3x and gets us fairly close to
+ * the speeds claimed by the manufacturer.  Reading through the MCU code
+ * seems to add at least a few microseconds per sample, which is significant
+ * when trying to get close to the theoretical speed limits for the ADC
+ * hardware, which are around 1.5us.
  *
- * AltAnalogIn temperature(PTC2); //Fast continuous sampling on PTC2
- * AltAnalogIn speed(PTB3, 0);    //Fast non-continuous sampling on PTB3
+ * This class can be used with or without DMA.  By default, you take samples
+ * directly.  Call start() to initiate sampling, and call one of the
+ * read routines (read() or read_u16()) to wait for the sample to complete
+ * and fetch the value.  In this mode, samples are taken individually.
+ * The start() and read routines are separated so that the caller can
+ * perform other work, if desired, while the ADC hardware takes the sample.
  *
- * int main() {
- *     while(1) {
- *         if(temperature > 0.5) {
- *             printf("Too hot! (%f) at speed %f", temperature.read(), speed.read());
- *         }
- *     }
- * }
- * @endcode
- * Example for the LPC1768 processor:
- * @code
- * // Print messages when the AnalogIn is greater than 50%
+ * To use with DMA, set up a SimpleDMA object, and call initDMA() to tie
+ * it to the analog input.  Call startDMA() to initiate a transfer.  We'll
+ * start reading the analog input in continuous mode; each time a sample
+ * completes, it will trigger a DMA transfer to the destination.  startDMA()
+ * returns immediately, so the caller can continue with other tasks while
+ * the samples are taken.
  *
- * #include "mbed.h"
- *
- * AltAnalogIn temperature(p20);
- *
- * int main() {
- *     while(1) {
- *         if(temperature > 0.5) {
- *             printf("Too hot! (%f)", temperature.read());
- *         }
- *     }
- * }
- * @endcode
-*/
+ * IMPORTANT!  This class does not play nicely with regular AnalogIn objects,
+ * nor with the original FastAnalogIn, because all of these classes set global
+ * configuration registers in the ADC hardware at setup time and then will 
+ * assume that no one else is messing with them.  Each library requires
+ * exclusive access to and control over the hardware, so they can't be mixed
+ * in the same program.
+ */
 class AltAnalogIn {
 
 public:
@@ -90,12 +89,70 @@
      * @param pin AnalogIn pin to connect to
      * @param enabled Enable the ADC channel (default = true)
      */
-    AltAnalogIn( PinName pin, bool enabled = true );
+    AltAnalogIn(PinName pin, bool continuous = false);
     
     ~AltAnalogIn( void )
     {
+#if 0//$$$
+        if (intInstance == this)
+            intInstance = 0;
+#endif
     }
     
+    // Initialize DMA.  This connects the analog in port to the
+    // given DMA object.
+    //
+    // DMA transfers from the analog in port often use continuous
+    // conversion mode.  Note, however, that we don't automatically
+    // assume this - single sample mode is the default, which means
+    // that you must manually start each sample.  If you want to use
+    // continuous mode, you need to set that separately (via the 
+    // constructor).
+    void initDMA(SimpleDMA *dma);
+    
+    // Start a DMA transfer.  'nele' is the number of elements (not
+    // bytes) in the buffer.
+    template<typename T> void startDMA(T *buf, int nele, bool autoInc) 
+    {
+        // set the DMA destination buffer
+        dma->destination(buf, autoInc);
+        
+        // start the DMA transfer
+        dma->start(nele * sizeof(T));
+    }
+            
+#if 0 // $$$
+    // set up an interrupt callback and enable interrupt mode
+    template<typename T> void attach(T *object, void (T::*member)(void))
+    {
+        // attach the callback
+        _callback.attach(object, member);
+        
+        // set our internal interrupt handler
+        NVIC_SetVector(ADC0_IRQn, (uint32_t)&_aiIRQ);
+        NVIC_EnableIRQ(ADC0_IRQn);
+        
+        // enable interrupt mode
+        enableInterruptMode();
+    }
+#endif
+
+    // turn on interrupt mode
+    void enableInterruptMode()
+    {
+        // set interrupt mode
+        sc1 |= ADC_SC1_AIEN;        
+    }
+
+#if 0 // $$$    
+    // interrupt handler
+    static void _aiIRQ()
+    {
+        if (intInstance != 0)
+            intInstance->_callback.call();
+    }
+#endif
+    
     /** Start a sample.  This sets the ADC multiplexer to read from
     * this input and activates the sampler.
     */
@@ -115,11 +172,37 @@
                 ADC0->CFG2 &= ~ADC_CFG2_MUXSEL_MASK;
         }
         
-        // select our ADC channel in the control register - this initiates sampling
-        // on the channel
-        ADC0->SC1[0] = startMask;
+        // update the SC2 and SC3 bits only if we're changing inputs
+        static uint32_t lastid = 0;
+        if (id != lastid) 
+        {
+            // set our ADC0 SC2 and SC3 configuration bits
+            ADC0->SC2 = sc2;
+            ADC0->SC3 = sc3;
+        
+            // we're the active one now
+            lastid = id;
+            
+            // handle any interrupts through this object
+//$$$            intInstance = this;
+        }
+        
+        // set our SC1 bits - this initiates the sample
+        ADC0->SC1[0] = sc1;
     }
  
+    // stop sampling
+    void stop()
+    {
+        // set the channel bits to binary 11111 to disable sampling
+        ADC0->SC1[0] = 0x1F;
+    }
+    
+    // wait for the current sample to complete
+    inline void wait()
+    {
+        while ((ADC0->SC1[0] & ADC_SC1_COCO_MASK) == 0);
+    }
 
     
     /** Returns the raw value
@@ -129,7 +212,7 @@
     inline uint16_t read_u16()
     {
         // wait for the hardware to signal that the sample is completed
-        while ((ADC0->SC1[0] & ADC_SC1_COCO_MASK) == 0);
+        wait();
     
         // return the result register value
         return (uint16_t)ADC0->R[0] << 4;  // convert 12-bit to 16-bit, padding with zeroes
@@ -151,9 +234,17 @@
 
     
 private:
-    char ADCnumber;         // ADC number of our input pin
-    char ADCmux;            // multiplexer for our input pin (0=A, 1=B)
-    uint32_t startMask;
+    uint32_t id;                // unique ID
+    SimpleDMA *dma;             // DMA controller, if used
+    FunctionPointer _callback;  // interrupt callback
+    char ADCnumber;             // ADC number of our input pin
+    char ADCmux;                // multiplexer for our input pin (0=A, 1=B)
+    uint32_t sc1;               // SC1 register settings for this input
+    uint32_t sc2;               // SC2 register settings for this input
+    uint32_t sc3;               // SC3 register settings for this input
+    
+    // interrupt handler instance
+    //$$$static AltAnalogIn *intInstance;
 };
 
 #endif
--- a/AltAnalogIn/AltAnalogIn_KL25Z.cpp	Sun Feb 07 03:07:11 2016 +0000
+++ b/AltAnalogIn/AltAnalogIn_KL25Z.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -3,17 +3,7 @@
 #include "AltAnalogIn.h"
 #include "clk_freqs.h"
 
-// Maximum ADC clock for KL25Z in 12-bit mode.  The data sheet says this is
-// limited to 18MHz, but we seem to get good results at higher rates.  The
-// data sheet is actually slightly vague on this because it's only in the
-// table for the 16-bit ADC, even though the ADC we're using is a 12-bit ADC,
-// which seems to have slightly different properties.  So there's room to
-// think the data sheet omits the data for the 12-bit ADC.
-#define MAX_FADC_12BIT      25000000
-
-#define CHANNELS_A_SHIFT     5          // bit position in ADC channel number of A/B mux
-#define ADC_CFG1_ADLSMP      0x10       // long sample time mode
-#define ADC_SC2_ADLSTS(mode) (mode)     // long sample time select - bits 1:0 of CFG2
+//$$$AltAnalogIn *AltAnalogIn::intInstance = 0;
 
 #ifdef TARGET_K20D50M
 static const PinMap PinMap_ADC[] = {
@@ -31,8 +21,15 @@
 };
 #endif
 
-AltAnalogIn::AltAnalogIn(PinName pin, bool enabled)
+AltAnalogIn::AltAnalogIn(PinName pin, bool continuous)
 {
+    // set our unique ID
+    static uint32_t nextID = 1;
+    id = nextID++;
+    
+    // presume no DMA 
+    dma = 0;
+    
     // do nothing if explicitly not connected
     if (pin == NC)
         return;
@@ -57,38 +54,72 @@
     // run the ADC at up to 18 MHz per the KL25Z data sheet.  (16-bit mode
     // is limited to 12 MHz.)
     int clkdiv = 0;
-    uint32_t ourfreq = bus_frequency();
-    for ( ; ourfreq > MAX_FADC_12BIT ; ourfreq /= 2, clkdiv += 1) ;
+    uint32_t adcfreq = bus_frequency();
+    for ( ; adcfreq > MAX_FADC_12BIT ; adcfreq /= 2, clkdiv += 1) ;
     
-    // Set the "high speed" configuration only if we're right at the bus speed
-    // limit.  This bit is somewhat confusingly named, in that it actually
-    // *slows down* the conversions.  "High speed" means that the *other*
-    // options are set right at the limits of the ADC, so this option adds
-    // a few extra cycle delays to every conversion to compensate for living
-    // on the edge.
-    uint32_t adhsc_bit = (ourfreq == MAX_FADC_12BIT ? ADC_CFG2_ADHSC_MASK : 0);
+    // The "high speed configuration" bit is required if the ADC clock 
+    // frequency is above a certain threshold.  The actual threshold is 
+    // poorly documented: the reference manual only says that it's required
+    // when running the ADC at "high speed" but doesn't define how high
+    // "high" is.  The only numerical figure I can find is in the Freescale
+    // ADC sample time calculator tool (a Windows program downloadable from
+    // the Freescale site), which has a little notation on the checkbox for
+    // the ADHSC bit that says to use it when the ADC clock is 8 MHz or
+    // higher.
+    //
+    // Note that this bit is somewhat confusingly named.  It doesn't mean
+    // "make the ADC go faster".  It actually means just the opposite.
+    // What it really means is that the external clock is running so fast 
+    // that the ADC has to pad out its sample time slightly to compensate,
+    // by adding a couple of extra clock cycles to each sampling interval.
+    const uint32_t ADHSC_SPEED_LIMIT = 8000000;
+    uint32_t adhsc_bit = (adcfreq >= ADHSC_SPEED_LIMIT ? ADC_CFG2_ADHSC_MASK : 0);
     
-    printf("ADCnumber=%d, cfg2_muxsel=%d, bus freq=%ld, clkdiv=%d\r\n", ADCnumber, ADCmux, bus_frequency(), clkdiv);
+    // $$$
+    printf("ADCnumber=%d, cfg2_muxsel=%d, bus freq=%ld, clkdiv=%d, adc freq=%d, high speed config=%s\r\n", 
+        ADCnumber, ADCmux, bus_frequency(), clkdiv, adcfreq, adhsc_bit ? "Y" : "N");//$$$
 
-    // set up the ADC control registers 
-
+    // map the GPIO pin in the system multiplexer to the ADC
+    pinmap_pinout(pin, PinMap_ADC);
+    
+    // set up the ADC control registers - these are common to all users of this class
+    
     ADC0->CFG1 = ADC_CFG1_ADIV(clkdiv)  // Clock Divide Select (as calculated above)
+               //| ADC_CFG1_ADLSMP        // Long sample time
                | ADC_CFG1_MODE(1)       // Sample precision = 12-bit
                | ADC_CFG1_ADICLK(0);    // Input Clock = bus clock
 
     ADC0->CFG2 = adhsc_bit              // High-Speed Configuration, if needed
-               | ADC_CFG2_ADLSTS(3);    // Long sample time mode 3 -> 6 ADCK cycles total
+               //| ADC_CFG2_ADLSTS(0);    // Long sample time mode 0 -> 24 ADCK cycles total
+               //| ADC_CFG2_ADLSTS(1);    // Long sample time mode 1 -> 16 ADCK cycles total
+               //| ADC_CFG2_ADLSTS(2);    // Long sample time mode 2 -> 10 ADCK cycles total
+               | ADC_CFG2_ADLSTS(3);    // Long sample time mode 2 -> 6 ADCK cycles total
                
-    ADC0->SC2 = ADC_SC2_REFSEL(0);      // Default Voltage Reference
-    
-    ADC0->SC3 = 0;                      // Calibration mode off, single sample, averaging disabled
+    // Figure our SC1 register bits
+    sc1 = ADC_SC1_ADCH(ADCnumber & ~(1 << CHANNELS_A_SHIFT));
 
-    // map the GPIO pin in the system multiplexer to the ADC
-    pinmap_pinout(pin, PinMap_ADC);
-    
-    // figure our 'start' mask - this is the value we write to the SC1A register
-    // to initiate a new sample
-    startMask = ADC_SC1_ADCH(ADCnumber & ~(1 << CHANNELS_A_SHIFT));
+    // figure our SC2 register bits
+    sc2 = ADC_SC2_REFSEL(0);            // Default Voltage Reference
+
+    // Set our SC3 bits.  The defaults (0 bits) are calibration mode off,
+    // single sample, averaging disabled.
+    sc3 = (continuous ? ADC_SC3_CONTINUOUS : 0);    // enable continuous mode if desired
 }
 
+void AltAnalogIn::initDMA(SimpleDMA *dma)
+{
+    // remember the DMA interface object
+    this->dma = dma;
+    
+    // set to read from the ADC result register
+    dma->source(&ADC0->R[0], false, 16);
+    
+    // set to trigger on the ADC
+    dma->trigger(Trigger_ADC0);
+
+    // enable DMA in our SC2 bits
+    sc2 |= ADC_SC2_DMAEN;
+}
+
+
 #endif //defined TARGET_KLXX
--- a/SimpleDMA.lib	Sun Feb 07 03:07:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/SimpleDMA/#876f3b55e6f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA.h	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,210 @@
+#ifndef SIMPLEDMA_H
+#define SIMPLEDMA_H
+
+#ifdef RTOS_H
+#include "rtos.h"
+#endif
+
+#include "mbed.h"
+#include "SimpleDMA_KL25.h"
+#include "SimpleDMA_KL46.h"
+#include "SimpleDMA_LPC1768.h"
+
+
+/**
+* SimpleDMA, DMA made simple! (Okay that was bad)
+*
+* A class to easily make basic DMA operations happen. Not all features
+* of the DMA peripherals are used, but the main ones are: From and to memory
+* and peripherals, either continiously or triggered
+*/
+class SimpleDMA {
+public:
+/**
+* Constructor
+*
+* @param channel - optional parameter which channel should be used, default is automatic channel selection
+*/
+SimpleDMA(int channel = -1);
+
+/**
+* Set the source of the DMA transfer
+*
+* Autoincrement increments the pointer after each transfer. If the source
+* is an array this should be true, if it is a peripheral or a single memory
+* location it should be false.
+*
+* The source can be any pointer to any memory location. Automatically
+* the wordsize is calculated depending on the type, if required you can
+* also override this.
+*
+* @param pointer - pointer to the memory location
+* @param autoinc - should the pointer be incremented by the DMA module
+* @param size - wordsize in bits (optional, generally can be omitted)
+* @return - 0 on success
+*/
+template<typename Type>
+void source(Type* pointer, bool autoinc, int size = sizeof(Type) * 8, int mod = 0) {
+    _source = (uint32_t)pointer;
+    source_inc = autoinc;
+    source_size = size;
+    source_mod = mod;
+}
+
+/**
+* Set the destination of the DMA transfer
+*
+* Autoincrement increments the pointer after each transfer. If the source
+* is an array this should be true, if it is a peripheral or a single memory
+* location it should be false.
+*
+* The destination can be any pointer to any memory location. Automatically
+* the wordsize is calculated depending on the type, if required you can
+* also override this.
+*
+* @param pointer - pointer to the memory location
+* @param autoinc - should the pointer be incremented by the DMA module
+* @param size - wordsize in bits (optional, generally can be omitted)
+* @return - 0 on success
+*/
+template<typename Type>
+void destination(Type* pointer, bool autoinc, int size = sizeof(Type) * 8, int mod = 0) {
+    _destination = (uint32_t)pointer;
+    destination_inc = autoinc;
+    destination_size = size;
+    destination_mod = mod;
+}
+
+/**
+* Set cycle-steal mode.  In cycle-steal mode, we do one DMA transfer per
+* trigger.  In continuous mode, we do the entire transfer on a single trigger.
+*/
+void setCycleSteal(bool f) { cycle_steal = f; }
+
+/**
+* Set the trigger for the DMA operation
+*
+* In SimpleDMA_[yourdevice].h you can find the names of the different triggers.
+* Trigger_ALWAYS is defined for all devices, it will simply move the data
+* as fast as possible. Used for memory-memory transfers. If nothing else is set
+* that will be used by default.
+*
+* @param trig - trigger to use
+* @param return - 0 on success
+*/
+void trigger(SimpleDMA_Trigger trig) {
+    _trigger = trig;
+}
+
+/**
+* Set the DMA channel
+*
+* Generally you will not need to call this function, the constructor does so for you
+*
+* @param chan - DMA channel to use, -1 = variable channel (highest priority channel which is available)
+*/
+void channel(int chan);
+
+/**
+* Start the transfer
+*
+* @param length - number of BYTES to be moved by the DMA
+*/
+int start(uint32_t length);
+
+/**
+* Start a new transfer with the same parameters as last time
+*/
+int restart(uint32_t length);
+
+/**
+* Is the DMA channel busy
+*
+* @param channel - channel to check, -1 = current channel
+* @return - true if it is busy
+*/
+bool isBusy( int channel = -1 );
+
+/**
+* Number of bytes remaining in running transfer.  This reads the controller
+* register with the remaining byte count, which the hardware updates each
+* time it completes a destination transfer.
+*/
+uint32_t remaining(int channel = -1);
+
+/**
+* Attach an interrupt upon completion of DMA transfer or error
+*
+* @param function - function to call upon completion (may be a member function)
+*/
+void attach(void (*function)(void)) {
+    _callback.attach(function);
+    }
+    
+template<typename T>
+    void attach(T *object, void (T::*member)(void)) {
+        _callback.attach(object, member);
+    }
+
+#ifdef RTOS_H
+/**
+* Start a DMA transfer similar to start, however block current Thread
+* until the transfer is finished
+*
+* When using this function only the current Thread is halted.
+* The Thread is moved to Waiting state: other Threads will continue
+* to run normally. 
+*
+* This function is only available if you included rtos.h before 
+* including SimpleDMA.h.
+*
+* @param length - number of BYTES to be moved by the DMA
+*/
+void wait(int length) {
+    id = Thread::gettid();
+    this->attach(this, &SimpleDMA::waitCallback);
+    this->start(length);
+    Thread::signal_wait(0x1);
+}
+#endif
+
+protected:
+int _channel;
+SimpleDMA_Trigger _trigger;
+uint32_t _source;
+uint32_t _destination;
+bool source_inc;
+bool destination_inc;
+uint8_t source_size;
+uint8_t destination_size;
+uint32_t source_mod;
+uint32_t destination_mod;
+bool cycle_steal;
+
+bool auto_channel;
+
+//IRQ handlers
+FunctionPointer _callback;
+void irq_handler(void);
+
+static SimpleDMA *irq_owner[DMA_CHANNELS];
+
+static void irq_handler0( void ); 
+
+#if DMA_IRQS > 1
+static void irq_handler1( void );
+static void irq_handler2( void );
+static void irq_handler3( void );
+#endif
+
+//Keep searching until we find a non-busy channel, start with lowest channel number
+int getFreeChannel(void);
+
+#ifdef RTOS_H
+osThreadId id;
+void waitCallback(void) {
+    osSignalSet(id, 0x1);    
+}
+#endif
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_KL25.h	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,45 @@
+#if defined TARGET_KL25Z
+
+#define DMA_CHANNELS        4
+#define DMA_IRQS            4
+
+enum SimpleDMA_Trigger {
+    Trigger_ALWAYS = 60,
+    Trigger_UART0_RX = 2,
+    Trigger_UART0_TX,
+    Trigger_UART1_RX,
+    Trigger_UART1_TX,
+    Trigger_UART2_RX,
+    Trigger_UART2_TX,
+    Trigger_SPI0_RX = 16,
+    Trigger_SPI0_TX,
+    Trigger_SPI1_RX,
+    Trigger_SPI1_TX,
+    Trigger_I2C0 = 22,
+    Trigger_I2C1,
+    Trigger_TPM0_C0,
+    Trigger_TPM0_C1,
+    Trigger_TPM0_C2,
+    Trigger_TPM0_C3,
+    Trigger_TPM0_C4,
+    Trigger_TPM0_C5,
+    Trigger_TPM1_C0 = 32,
+    Trigger_TPM1_C1,
+    Trigger_TPM2_C0,
+    Trigger_TPM2_C1,
+    Trigger_ADC0 = 40,
+    Trigger_CMP0 = 42,
+    Trigger_DAC0 = 45,
+    Trigger_PORTA = 49,
+    Trigger_PORTD = 52,
+    Trigger_TPM0 = 54,
+    Trigger_TPM1,
+    Trigger_TPM2,
+    Trigger_TSI,
+    Trigger_ALWAYS0 = 60,
+    Trigger_ALWAYS1,
+    Trigger_ALWAYS2,
+    Trigger_ALWAYS3,
+};    
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_KL25_46.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,149 @@
+#if defined TARGET_KL25Z || defined TARGET_KL46Z
+#include "SimpleDMA.h"
+
+
+
+SimpleDMA *SimpleDMA::irq_owner[4] = {NULL};
+
+SimpleDMA::SimpleDMA(int channel) {
+    this->channel(channel);
+       
+    //Enable DMA
+    SIM->SCGC6 |= 1<<1;     //Enable clock to DMA mux
+    SIM->SCGC7 |= 1<<8;     //Enable clock to DMA
+    
+    trigger(Trigger_ALWAYS);
+   
+    NVIC_SetVector(DMA0_IRQn, (uint32_t)&irq_handler0);
+    NVIC_SetVector(DMA1_IRQn, (uint32_t)&irq_handler1);
+    NVIC_SetVector(DMA2_IRQn, (uint32_t)&irq_handler2);
+    NVIC_SetVector(DMA3_IRQn, (uint32_t)&irq_handler3);
+    NVIC_EnableIRQ(DMA0_IRQn);
+    NVIC_EnableIRQ(DMA1_IRQn);
+    NVIC_EnableIRQ(DMA2_IRQn);
+    NVIC_EnableIRQ(DMA3_IRQn);
+    
+    // presume cycle-steal mode
+    cycle_steal = true;
+}
+
+// Figure the circular buffer MOD bit pattern (SMOD or DMOD)
+// for a given circular buffer size.  The buffer size is
+// required to be a power of 2 from 16 to 256K.
+static uint32_t modsize_to_modbits(uint32_t siz)
+{
+    // The bit pattern is such that 2^(bits+3), so we basically
+    // need to take the base-2 log of the size.  Zero has the
+    // special meaning that the circular buffer is disabled.
+    uint32_t bits = 0;
+    for (bits = 0 ; siz >= 16 ; siz >>= 1, ++bits) ;
+    
+    // return the result, which can't be over binary 1111
+    return bits & 0xF;
+}
+
+int SimpleDMA::start(uint32_t length) {  
+    if (auto_channel)
+        _channel = getFreeChannel();
+    else
+        while(isBusy());
+    
+    if (length > DMA_DSR_BCR_BCR_MASK)
+        return -1;
+
+    irq_owner[_channel] = this;
+    
+    DMA0->DMA[_channel].SAR = _source;
+    DMA0->DMA[_channel].DAR = _destination;
+    DMA0->DMA[_channel].DSR_BCR = length;
+    DMAMUX0->CHCFG[_channel] = _trigger;
+    
+    uint32_t config = 
+        DMA_DCR_EINT_MASK 
+        | DMA_DCR_ERQ_MASK 
+        | (cycle_steal ? DMA_DCR_CS_MASK : 0)
+        | (source_inc << DMA_DCR_SINC_SHIFT) 
+        | (modsize_to_modbits(source_mod) << DMA_DCR_SMOD_SHIFT)
+        | (destination_inc << DMA_DCR_DINC_SHIFT)
+        | (modsize_to_modbits(destination_mod) << DMA_DCR_DMOD_SHIFT);
+    switch (source_size) {
+        case 8:
+            config |= 1 << DMA_DCR_SSIZE_SHIFT;
+            break;
+        case 16:
+            config |= 2 << DMA_DCR_SSIZE_SHIFT; 
+            break;
+    }
+    switch (destination_size) {
+        case 8:
+            config |= 1 << DMA_DCR_DSIZE_SHIFT;
+            break;
+        case 16:
+            config |= 2 << DMA_DCR_DSIZE_SHIFT; 
+            break;
+    }
+    
+    DMA0->DMA[_channel].DCR = config;      
+           
+    //Start
+    DMAMUX0->CHCFG[_channel] |= 1<<7;
+    
+    return 0;
+}
+
+int SimpleDMA::restart(uint32_t length)
+{
+    DMA0->DMA[_channel].SAR = _source;
+    DMA0->DMA[_channel].DAR = _destination;
+    DMA0->DMA[_channel].DSR_BCR = length;
+    DMAMUX0->CHCFG[_channel] |= 1<<7;
+    return 0;
+}
+
+bool SimpleDMA::isBusy( int channel ) {
+    //Busy bit doesn't work as I expect it to do, so just check if counter is at zero
+    //return (DMA0->DMA[_channel].DSR_BCR & (1<<25) == 1<<25);
+    if (channel == -1)
+        channel = _channel;
+    
+    return (DMA0->DMA[channel].DSR_BCR & 0xFFFFF);
+}
+
+/*****************************************************************/
+uint32_t SimpleDMA::remaining(int channel) 
+{
+    // note that the BCR register always reads with binary 1110
+    // (if the configuration is correct) or 1111 (if there's an
+    // error in the configuration) in bits 23-20, so we need
+    // to mask these out - only keep bits 19-0 (low-order 20 
+    // bits = 0xFFFFF)
+    return (DMA0->DMA[channel < 0 ? _channel : channel].DSR_BCR & 0xFFFFF);
+}
+
+/*****************************************************************/
+void SimpleDMA::irq_handler(void) {
+    DMAMUX0->CHCFG[_channel] = 0;
+    DMA0->DMA[_channel].DSR_BCR |= DMA_DSR_BCR_DONE_MASK ; 
+    _callback.call();
+}
+
+void SimpleDMA::irq_handler0( void ) {
+    if (irq_owner[0]!=NULL)
+        irq_owner[0]->irq_handler();
+}
+
+void SimpleDMA::irq_handler1( void ) {
+    if (irq_owner[1]!=NULL)
+        irq_owner[1]->irq_handler();
+}
+
+void SimpleDMA::irq_handler2( void ) {
+    if (irq_owner[2]!=NULL)
+        irq_owner[2]->irq_handler();
+}
+
+void SimpleDMA::irq_handler3( void ) {
+    if (irq_owner[3]!=NULL)
+        irq_owner[3]->irq_handler();
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_KL46.h	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,48 @@
+#if defined TARGET_KL46Z
+
+#define DMA_CHANNELS        4
+#define DMA_IRQS            4
+
+enum SimpleDMA_Trigger {
+    Trigger_ALWAYS = 60,
+    Trigger_UART0_RX = 2,
+    Trigger_UART0_TX,
+    Trigger_UART1_RX,
+    Trigger_UART1_TX,
+    Trigger_UART2_RX,
+    Trigger_UART2_TX,
+    Trigger_I2S0_RX = 14,
+    Trigger_I2S0_TX,
+    Trigger_SPI0_RX = 16,
+    Trigger_SPI0_TX,
+    Trigger_SPI1_RX,
+    Trigger_SPI1_TX,
+    Trigger_I2C0 = 22,
+    Trigger_I2C1,
+    Trigger_TPM0_C0,
+    Trigger_TPM0_C1,
+    Trigger_TPM0_C2,
+    Trigger_TPM0_C3,
+    Trigger_TPM0_C4,
+    Trigger_TPM0_C5,
+    Trigger_TPM1_C0 = 32,
+    Trigger_TPM1_C1,
+    Trigger_TPM2_C0,
+    Trigger_TPM2_C1,
+    Trigger_ADC0 = 40,
+    Trigger_CMP0 = 42,
+    Trigger_DAC0 = 45,
+    Trigger_PORTA = 49,
+    Trigegr_PORTC = 51,
+    Trigger_PORTD = 52,
+    Trigger_TPM0 = 54,
+    Trigger_TPM1,
+    Trigger_TPM2,
+    Trigger_TSI,
+    Trigger_ALWAYS0 = 60,
+    Trigger_ALWAYS1,
+    Trigger_ALWAYS2,
+    Trigger_ALWAYS3,
+};    
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_LPC1768.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,110 @@
+#ifdef TARGET_LPC1768
+
+#include "SimpleDMA.h"
+
+SimpleDMA *SimpleDMA::irq_owner[8] = {NULL};
+LPC_GPDMACH_TypeDef *LPC_GPDMACH[8] = {LPC_GPDMACH0, LPC_GPDMACH1, LPC_GPDMACH2, LPC_GPDMACH3, LPC_GPDMACH4, LPC_GPDMACH5, LPC_GPDMACH6, LPC_GPDMACH7};
+uint32_t getTransferType(SimpleDMA_Trigger trig, uint32_t source, uint32_t destination);
+
+SimpleDMA::SimpleDMA(int channel) {
+    this->channel(channel);
+    
+    //Power up
+    LPC_SC->PCONP |= 1<<29;
+    LPC_GPDMA->DMACConfig = 1;
+    trigger(Trigger_ALWAYS);
+    
+    NVIC_SetVector(DMA_IRQn, (uint32_t)&irq_handler0);
+    NVIC_EnableIRQ(DMA_IRQn);          
+}
+
+int SimpleDMA::start(uint32_t length) {
+    if (auto_channel)
+        _channel = getFreeChannel();
+    else
+        while(isBusy());
+    
+    uint32_t control = (source_inc << 26) | (destination_inc << 27) | (1UL << 31);
+    switch (source_size) {
+        case 16:
+            control |= (1<<18) | (length >> 1);
+            break;
+        case 32:
+            control |= (2<<18) | (length >> 2);  
+            break;
+        default:
+            control |= length;
+    }
+    switch (destination_size) {
+        case 16:
+            control |= (1<<21);
+            break;
+        case 32:
+            control |= (2<<21);  
+            break;
+    } 
+    
+    LPC_GPDMACH[_channel]->DMACCSrcAddr = _source;
+    LPC_GPDMACH[_channel]->DMACCDestAddr = _destination;
+    LPC_GPDMACH[_channel]->DMACCLLI = 0;
+    LPC_GPDMACH[_channel]->DMACCControl = control;     //Enable interrupt also
+    
+    irq_owner[_channel] = this;
+    
+    if (_trigger != Trigger_ALWAYS) {      
+        if (_trigger & 16) 
+            LPC_SC->DMAREQSEL |= 1 << (_trigger - 24);
+        else
+            LPC_SC->DMAREQSEL &= ~(1 << (_trigger - 24));
+        
+        LPC_GPDMACH[_channel]->DMACCConfig = ((_trigger & 15) << 1) + ((_trigger & 15) << 6) + (getTransferType(_trigger, _source, _destination) << 11) +  (1<<15) +1;        //Both parts of the transfer get triggered at same time
+    } else 
+        LPC_GPDMACH[_channel]->DMACCConfig = (getTransferType(_trigger, _source, _destination) << 11) + 1 + (1<<15);               //Enable channel
+    
+    return 0;
+}
+
+bool SimpleDMA::isBusy( int channel ) {
+    if (channel == -1)
+        channel = _channel;
+    return (LPC_GPDMA->DMACEnbldChns & (1<<channel));
+}
+
+void SimpleDMA::irq_handler0(void) {
+    while(LPC_GPDMA->DMACIntTCStat != 0) {
+        
+    uint32_t intloc = 31 - __CLZ(LPC_GPDMA->DMACIntTCStat & 0xFF);
+    if (irq_owner[intloc]!=NULL)
+        irq_owner[intloc]->irq_handler();
+    }
+}
+
+void SimpleDMA::irq_handler(void) {
+    LPC_GPDMA->DMACIntTCClear = 1<<_channel;
+    _callback.call();
+}
+
+static inline bool isMemory(uint32_t addr)
+{
+    return (addr >> 28) == 0 || (addr >> 28) == 1 || ((addr >= 0x2007C000) && (addr < (0x2007C000 + 0x8000)));
+}
+
+uint32_t getTransferType(SimpleDMA_Trigger trig, uint32_t source, uint32_t destination) {
+    //If it is always, simply put it on memory-to-memory
+    if (trig == Trigger_ALWAYS)
+        return 0;
+    else if (isMemory(source)) {       //if source is RAM/Flash
+        if (isMemory(destination))        //if destination is RAM/flash
+            return 3;                                                               //Return p2p for m2m with a trigger (since I have no idea wtf you are trying to do)
+        else
+            return 1;                                                               //Source is memory, destination is peripheral, so m2p
+        }
+    else {
+        if (isMemory(destination))
+            return 2;                                                               //Source is peripheral, destination is memory
+        else
+            return 3;                                                               //Both source and destination are peripherals
+        }
+        
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_LPC1768.h	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,34 @@
+#ifdef TARGET_LPC1768
+
+#define DMA_CHANNELS        8
+#define DMA_IRQS            1
+
+enum SimpleDMA_Trigger {
+    Trigger_ALWAYS = -1,
+    Trigger_SSP0_TX,
+    Trigger_SSP0_RX,
+    Trigger_SSP1_TX,
+    Trigger_SSP1_RX,
+    Trigger_ADC,
+    Trigger_I2S0,
+    Trigger_I2S1,
+    Trigger_DAC,
+    Trigger_UART0_TX,
+    Trigger_UART0_RX,
+    Trigger_UART1_TX,
+    Trigger_UART1_RX,
+    Trigger_UART2_TX,
+    Trigger_UART2_RX,
+    Trigger_UART3_TX,
+    Trigger_UART3_RX,
+    Trigger_MATCH0_0 = 24,
+    Trigger_MATCH0_1,
+    Trigger_MATCH1_0,
+    Trigger_MATCH1_1,
+    Trigger_MATCH2_0,
+    Trigger_MATCH2_1,
+    Trigger_MATCH3_0,
+    Trigger_MATCH3_1
+};  
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleDMA/SimpleDMA_common.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,25 @@
+#include "SimpleDMA.h"
+
+void SimpleDMA::channel(int chan) {
+    if (chan == -1) {
+        auto_channel = true;
+        _channel = 0;
+    } else {
+        auto_channel = false;
+        if (chan >= 0 && chan < DMA_CHANNELS)
+            _channel = chan;
+        else
+            _channel = DMA_CHANNELS-1;
+    }
+}
+
+int SimpleDMA::getFreeChannel(void) {
+    int retval = 0;
+    while(1) {
+        if (!isBusy(retval))
+            return retval;
+        retval++;
+        if (retval >= DMA_CHANNELS)
+            retval = 0;
+    }  
+}
\ No newline at end of file
--- a/TSL1410R/tsl1410r.h	Sun Feb 07 03:07:11 2016 +0000
+++ b/TSL1410R/tsl1410r.h	Mon Feb 15 20:30:32 2016 +0000
@@ -1,3 +1,45 @@
+// DMA VERSION - NOT WORKING
+
+// I'm saving this code for now, since it was somewhat promising but doesn't
+// quite work.  The idea here was to read the ADC via DMA, operating the ADC
+// in continuous mode.  This speeds things up pretty impressively (by about 
+// a factor of 3 vs having the MCU read each result from the ADC sampling 
+// register), but I can't figure out how to get a stable enough signal out of 
+// it.  I think the problem is that the timing isn't precise enough in detecting 
+// when the DMA completes each write.  We have to clock the next pixel onto the 
+// CCD output each time we complete a sample, and we have to do so quickly so 
+// that the next pixel charge is stable at the ADC input pin by the time the 
+// ADC sample interval starts.  I'm seeing a ton of noise, which I think means 
+// that the new pixel isn't ready for the ADC in time. 
+//
+// I've tried a number of approaches, none of which works:
+//
+// - Skip every other sample, so that we can spend one whole sample just 
+// clocking in the next pixel.  We discard the "odds" samples that are taken
+// during pixel changes, and use only the "even" samples where the pixel is
+// stable the entire time.  I'd think the extra sample would give us plenty
+// of time to stabilize the next pixel, but it doesn't seem to work out that
+// way.  I think the problem might be that the latency of the MCU responding
+// to each sample completion is long enough relative to the sampling interval
+// that we can't reliably respond to the ADC done condition fast enough.  I've
+// tried basing the sample completion detection on the DMA byte counter and
+// the ADC interrupt.  The DMA byte counter is updated after the DMA transfer
+// is done, so that's probably just too late in the cycle.  The ADC interrupt
+// should be concurrent with the DMA transfer starting, but in practice it 
+// still doesn't give us good results.
+//
+// - Use DMA, but with the ADC in single-sample mode.  This bypasses the latency
+// problem by ensuring that the ADC doesn't start a new sample until we've
+// definitely finished clocking in the next pixel.  But it defeats the whole
+// purpose by eliminating the speed improvement - the speeds are comparable to
+// doing the transfers via the MCU.  This surprises me because I'd have expected
+// that the DMA would run concurrently with the MCU pixel clocking code, but
+// maybe there's enough bus contention between the MCU and DMA in this case that
+// there's no true overlapping of the operation.  Or maybe the interrupt dispatch
+// adds enough overhead to negate any overlapping.  I haven't actually been able
+// to get good data out of this mode, either, but I gave up early because of the
+// lack of any speed improvement.
+
 /*
  *  TSL1410R interface class.
  *
@@ -7,9 +49,11 @@
 #include "mbed.h"
 #include "config.h"
 #include "AltAnalogIn.h"
+#include "SimpleDMA.h"
  
 #ifndef TSL1410R_H
 #define TSL1410R_H
+#define TSL1410R_DMA
 
 // For faster GPIO on the clock pin, we write the IOPORT registers directly.
 // PORT_BASE gives us the memory mapped location of the IOPORT register set
@@ -49,11 +93,29 @@
         clear();
         clear();
         
+        // set up our DMA channel for reading from our analog in pin
+        ao1.initDMA(&adc_dma);
+        
+        // Set up our DMA channel for writing the sensor SCLK - we use the PTOR
+        // (toggle) register to flip the bit on each write.  To pad the timing
+        // to the rate required by the CCD, do a no-op 0 write to PTOR after
+        // each toggle.  This gives us a 16-byte buffer, which we can make
+        // circular in the DMA controller.
+        static const uint32_t clkseq[] = { clockMask, 0, clockMask, 0 };
+        clk_dma.destination(&clockPort->PTOR, false, 32);
+        clk_dma.source(clkseq, true, 32, 16);   // set up our circular source buffer
+        clk_dma.trigger(Trigger_ADC0);          // software trigger
+        clk_dma.setCycleSteal(false);           // do the entire transfer on each trigger
+        
         totalTime = 0.0; nRuns = 0; // $$$
     }
     
     float totalTime; int nRuns; // $$$
 
+    // ADC interrupt handler - on each ADC event, 
+    static TSL1410R *instance;
+    static void _aiIRQ() { }
+
     // Read the pixels.
     //
     // 'n' specifies the number of pixels to sample, and is the size of
@@ -91,11 +153,10 @@
     // the current pixels and start a fresh integration cycle.
     void read(register uint16_t *pix, int n)
     {
-        Timer t; t.start(); // $$$
+        Timer t; t.start(); //float tDMA, tPix; // $$$
         
         // get the clock pin pointers into local variables for fast access
-        register volatile uint32_t *clockPSOR = &clockPort->PSOR;
-        register volatile uint32_t *clockPCOR = &clockPort->PCOR;
+        register volatile uint32_t *clockPTOR = &clockPort->PTOR;
         register const uint32_t clockMask = this->clockMask;
         
         // start the next integration cycle by pulsing SI and one clock
@@ -111,8 +172,6 @@
 static int done=0;
 if (done++ == 0) printf("nPixSensor=%d, n=%d, skip=%d, parallel=%d\r\n", nPixSensor, n, skip, parallel);
 
-        // get the clock PSOR and PCOR register addresses for fast access
-
         // read all of the pixels
         int dst;
         if (parallel)
@@ -125,7 +184,7 @@
                 // Take the clock high.  The TSL1410R will connect the next
                 // pixel pair's hold capacitors to the A01 and AO2 lines 
                 // (respectively) on the clock rising edge.
-                *clockPSOR = clockMask;
+                *clockPTOR = clockMask;
 
                 // Start the ADC sampler for AO1.  The TSL1410R sample 
                 // stabilization time per the data sheet is 120ns.  This is
@@ -135,7 +194,7 @@
                 ao1.start();
                 
                 // take the clock low while we're waiting for the reading
-                *clockPCOR = clockMask;
+                *clockPTOR = clockMask;
                 
                 // Read the first half-sensor pixel from AO1
                 pix[dst] = ao1.read_u16();
@@ -152,46 +211,61 @@
                 // Clock through the skipped pixels
                 for (int i = skip ; i > 0 ; --i) 
                 {
-                    *clockPSOR = clockMask;
-                    *clockPCOR = clockMask;
+                    *clockPTOR = clockMask;
+                    *clockPTOR = clockMask;
+                    *clockPTOR = 0;         // pad the timing with an extra nop write
                 }
             }
         }
         else
         {
             // serial mode - read all pixels in a single file
-            for (dst = 0 ; dst < n ; ++dst)
+
+            // clock in the first pixel
+            clock = 1;
+            clock = 0;
+            
+            // start the ADC DMA transfer
+            ao1.startDMA(pix, n, true);
+            
+            // We do 4 clock PTOR writes per clocked pixel (the skipped pixels 
+            // plus the pixel we actually want to sample), at 32 bits (4 bytes) 
+            // each, giving 16 bytes per pixel for the overall write.
+            int clk_dma_len = (skip+1)*16;
+            clk_dma.start(clk_dma_len);
+            
+            // start the first sample
+            ao1.start();
+            
+            // read all pixels
+            for (dst = n*2 ; dst > 0 ; dst -= 2)
             {
-                // Clock the next pixel onto the sensor A0 line
-                *clockPSOR = clockMask;
+                // wait for the current ADC sample to finish
+                while (adc_dma.remaining() >= dst) { }
                 
-                // start the ADC sampler
+                // start the next analog read while we're finishing the DMA transfers
                 ao1.start();
                 
-                // take the clock low while we're waiting for the analog reading
-                *clockPCOR = clockMask;
-                
-                // wait for and read the ADC sample; plug it into the output
-                // array, and increment the output pointer to the next position
-                pix[dst] = ao1.read_u16();
-                
-                // clock through the skipped pixels
-                for (int i = skip ; i > 0 ; --i) 
-                {
-                    *clockPSOR = clockMask;
-                    *clockPCOR = clockMask;
-                }
+                // re-arm the clock DMA
+                //clk_dma.restart(clk_dma_len);
             }
+            
+            // wait for the DMA transfer to finish
+            while (adc_dma.isBusy()) { }
+            
+            // apply the 12-bit to 16-bit rescaling to all values
+            for (int i = 0 ; i < n ; ++i)
+                pix[i] <<= 4;
         }
         
 //$$$
 if (done==1) printf(". done: dst=%d\r\n", dst);
         
         // clock out one extra pixel to leave A1 in the high-Z state
-        clock = 1;
-        clock = 0;
+        *clockPTOR = clockMask;
+        *clockPTOR = clockMask;
         
-        if (n >= 80) { totalTime += t.read(); nRuns += 1; } // $$$
+        if (n >= 64) { totalTime += t.read(); nRuns += 1; } // $$$
     }
 
     // Clock through all pixels to clear the array.  Pulses SI at the
@@ -222,6 +296,9 @@
     }
 
 private:
+    SimpleDMA adc_dma;        // DMA controller for reading the analog input
+    SimpleDMA clk_dma;        // DMA controller for the sensor SCLK (writes the PTOR register to toggle the clock bit)
+    char *dmabuf;             // buffer for DMA transfers
     int nPixSensor;           // number of pixels in physical sensor array
     DigitalOut si;            // GPIO pin for sensor SI (serial data) 
     DigitalOut clock;         // GPIO pin for sensor SCLK (serial clock)
@@ -233,3 +310,4 @@
 };
  
 #endif /* TSL1410R_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSL1410R/tsl1410r_dma.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,8 @@
+#include "tsl1410r.h"
+
+#ifdef TSL1410R_DMA
+
+// interrupt counters
+uint32_t TSL1410R::intCounter;
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSL1410R/tsl1410r_orig.h	Mon Feb 15 20:30:32 2016 +0000
@@ -0,0 +1,238 @@
+/*
+ *  TSL1410R interface class.
+ *
+ *  This provides a high-level interface for the Taos TSL1410R linear CCD array sensor.
+ */
+ 
+#include "mbed.h"
+#include "config.h"
+#include "AltAnalogIn.h"
+ 
+#ifndef TSL1410R_H
+#define TSL1410R_H
+
+// For faster GPIO on the clock pin, we write the IOPORT registers directly.
+// PORT_BASE gives us the memory mapped location of the IOPORT register set
+// for a pin; PINMASK gives us the bit pattern to write to the registers.
+//
+// - To turn a pin ON:  PORT_BASE(pin)->PSOR |= PINMASK(pin)
+// - To turn a pin OFF: PORT_BASE(pin)->PCOR |= PINMASK(pin)
+// - To toggle a pin:   PORT_BASE(pin)->PTOR |= PINMASK(pin)
+//
+// When used in a loop where the port address and pin mask are cached in
+// local variables, this runs at the same speed as the FastIO library - about 
+// 78ns per pin write on the KL25Z.  Not surprising since it's doing the same
+// thing, and the compiler should be able to reduce a pin write to a single ARM
+// instruction when the port address and mask are in local register variables.
+// The advantage over the FastIO library is that this approach allows for pins
+// to be assigned dynamically at run-time, which we prefer because it allows for
+// configuration changes to be made on the fly rather than having to recompile
+// the program.
+#define GPIO_PORT(pin)        (((unsigned int)(pin)) >> PORT_SHIFT)
+#define GPIO_PORT_BASE(pin)   ((FGPIO_Type *)(FPTA_BASE + GPIO_PORT(pin) * 0x40))
+#define GPIO_PINMASK(pin)     gpio_set(pin)
+ 
+class TSL1410R
+{
+public:
+    TSL1410R(int nPixSensor, PinName siPin, PinName clockPin, PinName ao1Pin, PinName ao2Pin) 
+        : nPixSensor(nPixSensor), si(siPin), clock(clockPin), ao1(ao1Pin), ao2(ao2Pin)
+    {
+        // we're in parallel mode if ao2 is a valid pin
+        parallel = (ao2Pin != NC);
+        
+        // remember the clock pin port base and pin mask for fast access
+        clockPort = GPIO_PORT_BASE(clockPin);
+        clockMask = GPIO_PINMASK(clockPin);
+        
+        // clear out power-on random data by clocking through all pixels twice
+        clear();
+        clear();
+        
+        totalTime = 0.0; nRuns = 0; // $$$
+    }
+    
+    float totalTime; int nRuns; // $$$
+    
+    // Read the pixels.
+    //
+    // 'n' specifies the number of pixels to sample, and is the size of
+    // the output array 'pix'.  This can be less than the full number
+    // of pixels on the physical device; if it is, we'll spread the
+    // sample evenly across the full length of the device by skipping
+    // one or more pixels between each sampled pixel to pad out the
+    // difference between the sample size and the physical CCD size.
+    // For example, if the physical sensor has 1280 pixels, and 'n' is
+    // 640, we'll read every other pixel and skip every other pixel.
+    // If 'n' is 160, we'll read every 8th pixel and skip 7 between
+    // each sample.
+    // 
+    // The reason that we provide this subset mode (where 'n' is less
+    // than the physical pixel count) is that reading a pixel is the most
+    // time-consuming part of the scan.  For each pixel we read, we have
+    // to wait for the pixel's charge to transfer from its internal smapling
+    // capacitor to the CCD's output pin, for that charge to transfer to
+    // the KL25Z input pin, and for the KL25Z ADC to get a stable reading.
+    // This all takes on the order of 20us per pixel.  Skipping a pixel
+    // only requires a clock pulse, which takes about 350ns.  So we can
+    // skip 60 pixels in the time it takes to sample 1 pixel.
+    //
+    // We clock an SI pulse at the beginning of the read.  This starts the
+    // next integration cycle: the pixel array will reset on the SI, and 
+    // the integration starts 18 clocks later.  So by the time this method
+    // returns, the next sample will have been integrating for npix-18 clocks.  
+    // That's usually enough time to allow immediately reading the next
+    // sample.  If more integration time is required, the caller can simply
+    // sleep/spin for the desired additional time, or can do other work that
+    // takes the desired additional time.
+    //
+    // If the caller has other work to tend to that takes longer than the
+    // desired maximum integration time, it can call clear() to clock out
+    // the current pixels and start a fresh integration cycle.
+    void read(register uint16_t *pix, int n)
+    {
+        Timer t; t.start();//$$$
+        
+        // get the clock pin pointers into local variables for fast access
+        register volatile uint32_t *clockPSOR = &clockPort->PSOR;
+        register volatile uint32_t *clockPCOR = &clockPort->PCOR;
+        register const uint32_t clockMask = this->clockMask;
+        
+        // start the next integration cycle by pulsing SI and one clock
+        si = 1;
+        clock = 1;
+        si = 0;
+        clock = 0;
+        
+        // figure how many pixels to skip on each read
+        int skip = nPixSensor/n - 1;
+        
+///$$$
+static int done=0;
+if (done++ == 0) printf("nPixSensor=%d, n=%d, skip=%d, parallel=%d\r\n", nPixSensor, n, skip, parallel);
+
+        // read all of the pixels
+        int dst;
+        if (parallel)
+        {
+            // Parallel mode - read pixels from each half sensor concurrently.
+            // Divide 'n' (the output pixel count) by 2 to get the loop count,
+            // since we're going to do 2 pixels on each iteration.
+            for (n /= 2, dst = 0 ; dst < n ; ++dst)
+            {
+                // Take the clock high.  The TSL1410R will connect the next
+                // pixel pair's hold capacitors to the A01 and AO2 lines 
+                // (respectively) on the clock rising edge.
+                *clockPSOR = clockMask;
+
+                // Start the ADC sampler for AO1.  The TSL1410R sample 
+                // stabilization time per the data sheet is 120ns.  This is
+                // fast enough that we don't need an explicit delay, since
+                // the instructions to execute this call will take longer
+                // than that.
+                ao1.start();
+                
+                // take the clock low while we're waiting for the reading
+                *clockPCOR = clockMask;
+                
+                // Read the first half-sensor pixel from AO1
+                pix[dst] = ao1.read_u16();
+                
+                // Read the second half-sensor pixel from AO2, and store it
+                // in the destination array at the current index PLUS 'n',
+                // which you will recall contains half the output pixel count.
+                // This second pixel is halfway up the sensor from the first 
+                // pixel, so it goes halfway up the output array from the
+                // current output position.
+                ao2.start();
+                pix[dst + n] = ao2.read_u16();
+                
+                // Clock through the skipped pixels
+                for (int i = skip ; i > 0 ; --i) 
+                {
+                    *clockPSOR = clockMask;
+                    *clockPCOR = clockMask;
+                }
+            }
+        }
+        else
+        {
+            // serial mode - read all pixels in a single file
+
+            // clock in the first pixel
+            *clockPSOR = clockMask;
+            *clockPCOR = clockMask;
+            
+            // clock through the pixels            
+            for (dst = 0 ; dst < n ; ++dst)
+            {
+                // Read this sample
+                ao1.start();
+                pix[dst] = ao1.read_u16();
+                
+                // clock in the next pixel
+                for (int i = skip ; i >= 0 ; --i) 
+                {
+                    *clockPSOR = clockMask;
+                    *clockPCOR = clockMask;
+                    *clockPCOR = clockMask;
+                }
+            }
+
+            // we're done - stop the ADC sampler            
+            ao1.stop();
+        }
+        
+//$$$
+//static int xxx = 0; xxx = (xxx+1)%2500; if (xxx==0) printf("tPix=%f, tDMA=%f, diff=%f\r\n", tPix*1000, tDMA*1000, (tDMA - tPix)*1000);
+if (done==1) printf(". done: dst=%d\r\n", dst);
+        
+        // clock out one extra pixel to leave A1 in the high-Z state
+        clock = 1;
+        clock = 0;
+        
+        if (n >= 64) { totalTime += t.read(); nRuns += 1; } // $$$
+    }
+
+    // Clock through all pixels to clear the array.  Pulses SI at the
+    // beginning of the operation, which starts a new integration cycle.
+    // The caller can thus immediately call read() to read the pixels 
+    // integrated while the clear() was taking place.
+    void clear()
+    {
+        // get the clock pin pointers into local variables for fast access
+        register FGPIO_Type *clockPort = this->clockPort;
+        register uint32_t clockMask = this->clockMask;
+
+        // clock in an SI pulse
+        si = 1;
+        clockPort->PSOR = clockMask;
+        si = 0;
+        clockPort->PCOR = clockMask;
+        
+        // if in serial mode, clock all pixels across both sensor halves;
+        // in parallel mode, the pixels are clocked together
+        int n = parallel ? nPixSensor/2 : nPixSensor;
+        
+        // clock out all pixels
+        for (int i = 0 ; i < n + 1 ; ++i) {
+            clock = 1; // $$$clockPort->PSOR = clockMask;
+            clock = 0; // $$$clockPort->PCOR = clockMask;
+        }
+    }
+
+private:
+    SimpleDMA dma;            // DMA controller for reading the analog input
+    char *dmabuf;             // buffer for DMA transfers
+    int nPixSensor;           // number of pixels in physical sensor array
+    DigitalOut si;            // GPIO pin for sensor SI (serial data) 
+    DigitalOut clock;         // GPIO pin for sensor SCLK (serial clock)
+    FGPIO_Type *clockPort;    // IOPORT base address for clock pin - cached for fast writes
+    uint32_t clockMask;       // IOPORT register bit mask for clock pin
+    AltAnalogIn ao1;          // GPIO pin for sensor AO1 (analog output 1) - we read sensor data from this pin
+    AltAnalogIn ao2;          // GPIO pin for sensor AO2 (analog output 2) - 2nd sensor data pin, when in parallel mode
+    bool parallel;            // true -> running in parallel mode (we read AO1 and AO2 separately on each clock)
+};
+ 
+#endif /* TSL1410R_H */
+
--- a/ccdSensor.h	Sun Feb 07 03:07:11 2016 +0000
+++ b/ccdSensor.h	Mon Feb 15 20:30:32 2016 +0000
@@ -200,20 +200,23 @@
         return true;
     }
     
-    // send an exposure report to the joystick interface
-    virtual void sendExposureReport(USBJoystick &js)
+    // Send an exposure report to the joystick interface.
+    // 
+    // Mode bits:
+    //    0x01  -> send processed pixels (default is raw pixels)
+    //    0x02  -> low res scan (default is high res scan)
+    virtual void sendExposureReport(USBJoystick &js, uint8_t mode)
     {
-        // Read a fresh high-res scan, then do another right away.  This
-        // gives us the shortest possible exposure for the sample we report,
-        // which helps ensure that the user inspecting the data sees something
-        // close to what we see when we calculate the plunger position.
-        ccd.read(pix, highResPix);
-        ccd.read(pix, highResPix);
+        // get the number of pixels according to the high res/low res mode
+        int npix = (mode & 0x02 ? lowResPix : highResPix);
+
+        // do a scan
+        ccd.read(pix, npix);
         
         // send reports for all pixels
         int idx = 0;
-        while (idx < highResPix)
-            js.updateExposure(idx, highResPix, pix);
+        while (idx < npix)
+            js.updateExposure(idx, npix, pix);
             
         // The pixel dump requires many USB reports, since each report
         // can only send a few pixel values.  An integration cycle has
@@ -226,7 +229,8 @@
     }
     
 protected:
-    // pixel buffer - we allocate this to be big enough for a high-res scan
+    // Pixel buffer.  We allocate this to be big enough for the high-res scan,
+    // which is the most pixels we'll need to capture.
     uint16_t *pix;
 
     // number of pixels in a high-res scan
@@ -252,7 +256,7 @@
 {
 public:
     PlungerSensorTSL1410R(PinName si, PinName clock, PinName ao1, PinName ao2) 
-        : PlungerSensorCCD(1280, 320, 64, si, clock, ao1, ao2)
+        : PlungerSensorCCD(1280, 256, 80, si, clock, ao1, ao2)
     {
     }
 };
@@ -262,7 +266,7 @@
 {
 public:
     PlungerSensorTSL1412R(PinName si, PinName clock, PinName ao1, PinName ao2)
-        : PlungerSensorCCD(1536, 384, 64, si, clock, ao1, ao2)
+        : PlungerSensorCCD(1536, 256, 128, si, clock, ao1, ao2)
     {
     }
 };
--- a/main.cpp	Sun Feb 07 03:07:11 2016 +0000
+++ b/main.cpp	Mon Feb 15 20:30:32 2016 +0000
@@ -2326,8 +2326,12 @@
 // to distinguish special request reply packets.
 uint16_t statusFlags;
     
-// flag: send a pixel dump after the next read
+// Pixel dump mode - the host requested a dump of image sensor pixels
+// (helpful for installing and setting up the sensor and light source)
 bool reportPix = false;
+uint8_t reportPixMode;  // pixel report mode bits: 
+                        // 0x01 -> raw pixels (0) / processed (1)
+                        // 0x02 -> high res scan (0) / low res (1)
 
 
 // ---------------------------------------------------------------------------
@@ -2508,8 +2512,11 @@
             
         case 3:
             // 3 = pixel dump
-            // (No parameters)
+            //     data[2] = mode bits:
+            //               0x01  -> return processed pixels (default is raw pixels)
+            //               0x02  -> low res scan (default is high res scan)
             reportPix = true;
+            reportPixMode = data[2];
             
             // show purple until we finish sending the report
             diagLED(1, 0, 1);
@@ -3390,7 +3397,7 @@
         if (reportPix)
         {
             // send the report            
-            plungerSensor->sendExposureReport(js);
+            plungerSensor->sendExposureReport(js, reportPixMode);
 
             // we have satisfied this request
             reportPix = false;
--- a/plunger.h	Sun Feb 07 03:07:11 2016 +0000
+++ b/plunger.h	Mon Feb 15 20:30:32 2016 +0000
@@ -50,7 +50,17 @@
     // through special joystick reports.  This is used for PC-side testing tools
     // to let the user check the sensor installation by directly viewing its
     // pixel output.
-    virtual void sendExposureReport(class USBJoystick &js) { }
+    //
+    // Mode bits:
+    //   0x01  -> send processed pixels (default is raw pixels)
+    //   0x02  -> low res scan (default is high res scan)
+    //
+    // If processed mode is selected, the sensor should apply any pixel
+    // processing it normally does when taking a plunger position reading,
+    // such as exposure correction, noise reduction, etc.  In raw mode, we
+    // simply send the pixels as read from the sensor.  Both modes are useful
+    // in setting up the physical sensor.
+    virtual void sendExposureReport(class USBJoystick &js, uint8_t mode) { }
 };
 
 #endif /* PLUNGER_H */