Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
33:d832bcab089e
Child:
35:e959ffba78fd
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 0:5acbbe3f4cf4 1 /* USBJoystick.h */
mjr 0:5acbbe3f4cf4 2 /* USB device example: Joystick*/
mjr 0:5acbbe3f4cf4 3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
mjr 0:5acbbe3f4cf4 4 /* Modified Mouse code for Joystick - WH 2012 */
mjr 0:5acbbe3f4cf4 5
mjr 0:5acbbe3f4cf4 6 #ifndef USBJOYSTICK_H
mjr 0:5acbbe3f4cf4 7 #define USBJOYSTICK_H
mjr 0:5acbbe3f4cf4 8
mjr 0:5acbbe3f4cf4 9 #include "USBHID.h"
mjr 0:5acbbe3f4cf4 10
mjr 0:5acbbe3f4cf4 11 #define REPORT_ID_JOYSTICK 4
mjr 0:5acbbe3f4cf4 12
mjr 0:5acbbe3f4cf4 13 /* Common usage */
mjr 0:5acbbe3f4cf4 14 enum JOY_BUTTON {
mjr 0:5acbbe3f4cf4 15 JOY_B0 = 0x0001,
mjr 0:5acbbe3f4cf4 16 JOY_B1 = 0x0002,
mjr 0:5acbbe3f4cf4 17 JOY_B2 = 0x0004,
mjr 0:5acbbe3f4cf4 18 JOY_B3 = 0x0008,
mjr 0:5acbbe3f4cf4 19 JOY_B4 = 0x0010,
mjr 0:5acbbe3f4cf4 20 JOY_B5 = 0x0020,
mjr 0:5acbbe3f4cf4 21 JOY_B6 = 0x0040,
mjr 0:5acbbe3f4cf4 22 JOY_B7 = 0x0080,
mjr 0:5acbbe3f4cf4 23 JOY_B8 = 0x0100,
mjr 0:5acbbe3f4cf4 24 JOY_B9 = 0x0200,
mjr 0:5acbbe3f4cf4 25 JOY_B10 = 0x0400,
mjr 0:5acbbe3f4cf4 26 JOY_B11 = 0x0800,
mjr 0:5acbbe3f4cf4 27 JOY_B12 = 0x1000,
mjr 0:5acbbe3f4cf4 28 JOY_B13 = 0x2000,
mjr 0:5acbbe3f4cf4 29 JOY_B14 = 0x4000,
mjr 0:5acbbe3f4cf4 30 JOY_B15 = 0x8000
mjr 0:5acbbe3f4cf4 31 };
mjr 0:5acbbe3f4cf4 32
mjr 0:5acbbe3f4cf4 33 /* X, Y and T limits */
mjr 0:5acbbe3f4cf4 34 /* These values do not directly map to screen pixels */
mjr 0:5acbbe3f4cf4 35 /* Zero may be interpreted as meaning 'no movement' */
mjr 0:5acbbe3f4cf4 36 #define JX_MIN_ABS (-127) /*!< The maximum value that we can move to the left on the x-axis */
mjr 0:5acbbe3f4cf4 37 #define JY_MIN_ABS (-127) /*!< The maximum value that we can move up on the y-axis */
mjr 0:5acbbe3f4cf4 38 #define JZ_MIN_ABS (-127) /*!< The minimum value for the Z axis */
mjr 0:5acbbe3f4cf4 39 #define JX_MAX_ABS (127) /*!< The maximum value that we can move to the right on the x-axis */
mjr 0:5acbbe3f4cf4 40 #define JY_MAX_ABS (127) /*!< The maximum value that we can move down on the y-axis */
mjr 0:5acbbe3f4cf4 41 #define JZ_MAX_ABS (127) /*!< The maximum value for the Z axis */
mjr 0:5acbbe3f4cf4 42
mjr 0:5acbbe3f4cf4 43 /**
mjr 0:5acbbe3f4cf4 44 *
mjr 0:5acbbe3f4cf4 45 * USBJoystick example
mjr 0:5acbbe3f4cf4 46 * @code
mjr 0:5acbbe3f4cf4 47 * #include "mbed.h"
mjr 0:5acbbe3f4cf4 48 * #include "USBJoystick.h"
mjr 0:5acbbe3f4cf4 49 *
mjr 0:5acbbe3f4cf4 50 * USBJoystick joystick;
mjr 0:5acbbe3f4cf4 51 *
mjr 0:5acbbe3f4cf4 52 * int main(void)
mjr 0:5acbbe3f4cf4 53 * {
mjr 0:5acbbe3f4cf4 54 * while (1)
mjr 0:5acbbe3f4cf4 55 * {
mjr 0:5acbbe3f4cf4 56 * joystick.move(20, 0);
mjr 0:5acbbe3f4cf4 57 * wait(0.5);
mjr 0:5acbbe3f4cf4 58 * }
mjr 0:5acbbe3f4cf4 59 * }
mjr 0:5acbbe3f4cf4 60 *
mjr 0:5acbbe3f4cf4 61 * @endcode
mjr 0:5acbbe3f4cf4 62 *
mjr 0:5acbbe3f4cf4 63 *
mjr 0:5acbbe3f4cf4 64 * @code
mjr 0:5acbbe3f4cf4 65 * #include "mbed.h"
mjr 0:5acbbe3f4cf4 66 * #include "USBJoystick.h"
mjr 0:5acbbe3f4cf4 67 * #include <math.h>
mjr 0:5acbbe3f4cf4 68 *
mjr 0:5acbbe3f4cf4 69 * USBJoystick joystick;
mjr 0:5acbbe3f4cf4 70 *
mjr 0:5acbbe3f4cf4 71 * int main(void)
mjr 0:5acbbe3f4cf4 72 * {
mjr 0:5acbbe3f4cf4 73 * while (1) {
mjr 0:5acbbe3f4cf4 74 * // Basic Joystick
mjr 0:5acbbe3f4cf4 75 * joystick.update(tx, y, z, buttonBits);
mjr 0:5acbbe3f4cf4 76 * wait(0.001);
mjr 0:5acbbe3f4cf4 77 * }
mjr 0:5acbbe3f4cf4 78 * }
mjr 0:5acbbe3f4cf4 79 * @endcode
mjr 0:5acbbe3f4cf4 80 */
mjr 0:5acbbe3f4cf4 81
mjr 0:5acbbe3f4cf4 82
mjr 0:5acbbe3f4cf4 83 class USBJoystick: public USBHID {
mjr 0:5acbbe3f4cf4 84 public:
mjr 0:5acbbe3f4cf4 85
mjr 0:5acbbe3f4cf4 86 /**
mjr 0:5acbbe3f4cf4 87 * Constructor
mjr 0:5acbbe3f4cf4 88 *
mjr 0:5acbbe3f4cf4 89 * @param vendor_id Your vendor_id (default: 0x1234)
mjr 0:5acbbe3f4cf4 90 * @param product_id Your product_id (default: 0x0002)
mjr 0:5acbbe3f4cf4 91 * @param product_release Your product_release (default: 0x0001)
mjr 0:5acbbe3f4cf4 92 */
mjr 4:02c7cd7b2183 93 USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0100, uint16_t product_release = 0x0001, int waitForConnect = true):
mjr 29:582472d0bc57 94 USBHID(16, 64, vendor_id, product_id, product_release, false)
mjr 0:5acbbe3f4cf4 95 {
mjr 0:5acbbe3f4cf4 96 _init();
mjr 4:02c7cd7b2183 97 connect(waitForConnect);
mjr 0:5acbbe3f4cf4 98 };
mjr 0:5acbbe3f4cf4 99
mjr 0:5acbbe3f4cf4 100 /**
mjr 0:5acbbe3f4cf4 101 * Write a state of the mouse
mjr 0:5acbbe3f4cf4 102 *
mjr 0:5acbbe3f4cf4 103 * @param x x-axis position
mjr 0:5acbbe3f4cf4 104 * @param y y-axis position
mjr 0:5acbbe3f4cf4 105 * @param z z-axis position
mjr 0:5acbbe3f4cf4 106 * @param buttons buttons state, as a bit mask (combination with '|' of JOY_Bn values)
mjr 0:5acbbe3f4cf4 107 * @returns true if there is no error, false otherwise
mjr 0:5acbbe3f4cf4 108 */
mjr 11:bd9da7088e6e 109 bool update(int16_t x, int16_t y, int16_t z, uint32_t buttons, uint16_t status);
mjr 10:976666ffa4ef 110
mjr 10:976666ffa4ef 111 /**
mjr 21:5048e16cc9ef 112 * Update just the status
mjr 21:5048e16cc9ef 113 */
mjr 21:5048e16cc9ef 114 bool updateStatus(uint32_t stat);
mjr 21:5048e16cc9ef 115
mjr 21:5048e16cc9ef 116 /**
mjr 10:976666ffa4ef 117 * Write an exposure report. We'll fill out a report with as many pixels as
mjr 10:976666ffa4ef 118 * will fit in the packet, send the report, and update the index to the next
mjr 10:976666ffa4ef 119 * pixel to send. The caller should call this repeatedly to send reports for
mjr 10:976666ffa4ef 120 * all pixels.
mjr 10:976666ffa4ef 121 *
mjr 10:976666ffa4ef 122 * @param idx current index in pixel array, updated to point to next pixel to send
mjr 10:976666ffa4ef 123 * @param npix number of pixels in the overall array
mjr 10:976666ffa4ef 124 * @param pix pixel array
mjr 10:976666ffa4ef 125 */
mjr 10:976666ffa4ef 126 bool updateExposure(int &idx, int npix, const uint16_t *pix);
mjr 33:d832bcab089e 127
mjr 33:d832bcab089e 128 /**
mjr 33:d832bcab089e 129 * Write a configuration report.
mjr 33:d832bcab089e 130 *
mjr 33:d832bcab089e 131 * @param numOutputs the number of configured output channels
mjr 33:d832bcab089e 132 * @param unitNo the device unit number
mjr 33:d832bcab089e 133 */
mjr 33:d832bcab089e 134 bool reportConfig(int numOutputs, int unitNo);
mjr 0:5acbbe3f4cf4 135
mjr 0:5acbbe3f4cf4 136 /**
mjr 0:5acbbe3f4cf4 137 * Write a state of the mouse
mjr 0:5acbbe3f4cf4 138 *
mjr 0:5acbbe3f4cf4 139 * @returns true if there is no error, false otherwise
mjr 0:5acbbe3f4cf4 140 */
mjr 0:5acbbe3f4cf4 141 bool update();
mjr 9:fd65b0a94720 142
mjr 0:5acbbe3f4cf4 143 /**
mjr 0:5acbbe3f4cf4 144 * Move the cursor to (x, y)
mjr 0:5acbbe3f4cf4 145 *
mjr 0:5acbbe3f4cf4 146 * @param x x-axis position
mjr 0:5acbbe3f4cf4 147 * @param y y-axis position
mjr 0:5acbbe3f4cf4 148 * @returns true if there is no error, false otherwise
mjr 0:5acbbe3f4cf4 149 */
mjr 0:5acbbe3f4cf4 150 bool move(int16_t x, int16_t y);
mjr 0:5acbbe3f4cf4 151
mjr 0:5acbbe3f4cf4 152 /**
mjr 0:5acbbe3f4cf4 153 * Set the z position
mjr 0:5acbbe3f4cf4 154 *
mjr 0:5acbbe3f4cf4 155 * @param z z-axis osition
mjr 0:5acbbe3f4cf4 156 */
mjr 0:5acbbe3f4cf4 157 bool setZ(int16_t z);
mjr 0:5acbbe3f4cf4 158
mjr 0:5acbbe3f4cf4 159 /**
mjr 0:5acbbe3f4cf4 160 * Press one or several buttons
mjr 0:5acbbe3f4cf4 161 *
mjr 0:5acbbe3f4cf4 162 * @param buttons button state, as a bitwise combination of JOY_Bn values
mjr 0:5acbbe3f4cf4 163 * @returns true if there is no error, false otherwise
mjr 0:5acbbe3f4cf4 164 */
mjr 11:bd9da7088e6e 165 bool buttons(uint32_t buttons);
mjr 0:5acbbe3f4cf4 166
mjr 0:5acbbe3f4cf4 167 /*
mjr 0:5acbbe3f4cf4 168 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
mjr 0:5acbbe3f4cf4 169 *
mjr 0:5acbbe3f4cf4 170 * @returns pointer to the report descriptor
mjr 0:5acbbe3f4cf4 171 */
mjr 0:5acbbe3f4cf4 172 virtual uint8_t * reportDesc();
mjr 0:5acbbe3f4cf4 173
mjr 0:5acbbe3f4cf4 174 /* USB descriptor string overrides */
mjr 0:5acbbe3f4cf4 175 virtual uint8_t *stringImanufacturerDesc();
mjr 0:5acbbe3f4cf4 176 virtual uint8_t *stringIserialDesc();
mjr 0:5acbbe3f4cf4 177 virtual uint8_t *stringIproductDesc();
mjr 0:5acbbe3f4cf4 178
mjr 0:5acbbe3f4cf4 179 private:
mjr 6:cc35eb643e8f 180 int16_t _x;
mjr 6:cc35eb643e8f 181 int16_t _y;
mjr 6:cc35eb643e8f 182 int16_t _z;
mjr 11:bd9da7088e6e 183 uint16_t _buttonsLo;
mjr 11:bd9da7088e6e 184 uint16_t _buttonsHi;
mjr 10:976666ffa4ef 185 uint16_t _status;
mjr 0:5acbbe3f4cf4 186
mjr 0:5acbbe3f4cf4 187 void _init();
mjr 0:5acbbe3f4cf4 188 };
mjr 0:5acbbe3f4cf4 189
mjr 0:5acbbe3f4cf4 190 #endif