I changed one line of code in the file with path name: USBDeviceHT/targets/TARGET_Maxim

Fork of USBDeviceHT by Helmut Tschemernjak

Committer:
dev_alexander
Date:
Fri Jun 01 21:43:55 2018 +0000
Revision:
6:c1f162fd7777
Parent:
0:a3ea811f80f2
Fixed Error with code not compiling due to an issue with there not being a (uint32_t) cast of a (void) pointer. Maxim was the only mbed vendor to not have this one (uint32_t) cast in the spot it was added to. Look into public repos for similar cases.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:a3ea811f80f2 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Helmut64 0:a3ea811f80f2 2 *
Helmut64 0:a3ea811f80f2 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Helmut64 0:a3ea811f80f2 4 * and associated documentation files (the "Software"), to deal in the Software without
Helmut64 0:a3ea811f80f2 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Helmut64 0:a3ea811f80f2 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Helmut64 0:a3ea811f80f2 7 * Software is furnished to do so, subject to the following conditions:
Helmut64 0:a3ea811f80f2 8 *
Helmut64 0:a3ea811f80f2 9 * The above copyright notice and this permission notice shall be included in all copies or
Helmut64 0:a3ea811f80f2 10 * substantial portions of the Software.
Helmut64 0:a3ea811f80f2 11 *
Helmut64 0:a3ea811f80f2 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Helmut64 0:a3ea811f80f2 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Helmut64 0:a3ea811f80f2 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Helmut64 0:a3ea811f80f2 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Helmut64 0:a3ea811f80f2 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Helmut64 0:a3ea811f80f2 17 */
Helmut64 0:a3ea811f80f2 18
Helmut64 0:a3ea811f80f2 19 #ifndef USBSERIAL_H
Helmut64 0:a3ea811f80f2 20 #define USBSERIAL_H
Helmut64 0:a3ea811f80f2 21
Helmut64 0:a3ea811f80f2 22 #include "USBCDC.h"
Helmut64 0:a3ea811f80f2 23 #include "Stream.h"
Helmut64 0:a3ea811f80f2 24 #include "CircBuffer.h"
Helmut64 0:a3ea811f80f2 25 #include "Callback.h"
Helmut64 0:a3ea811f80f2 26
Helmut64 0:a3ea811f80f2 27 /**
Helmut64 0:a3ea811f80f2 28 * USBSerial example
Helmut64 0:a3ea811f80f2 29 *
Helmut64 0:a3ea811f80f2 30 * @code
Helmut64 0:a3ea811f80f2 31 * #include "mbed.h"
Helmut64 0:a3ea811f80f2 32 * #include "USBSerial.h"
Helmut64 0:a3ea811f80f2 33 *
Helmut64 0:a3ea811f80f2 34 * //Virtual serial port over USB
Helmut64 0:a3ea811f80f2 35 * USBSerial serial;
Helmut64 0:a3ea811f80f2 36 *
Helmut64 0:a3ea811f80f2 37 * int main(void) {
Helmut64 0:a3ea811f80f2 38 *
Helmut64 0:a3ea811f80f2 39 * while(1)
Helmut64 0:a3ea811f80f2 40 * {
Helmut64 0:a3ea811f80f2 41 * serial.printf("I am a virtual serial port\n");
Helmut64 0:a3ea811f80f2 42 * wait(1);
Helmut64 0:a3ea811f80f2 43 * }
Helmut64 0:a3ea811f80f2 44 * }
Helmut64 0:a3ea811f80f2 45 * @endcode
Helmut64 0:a3ea811f80f2 46 */
Helmut64 0:a3ea811f80f2 47 class USBSerial: public USBCDC, public Stream {
Helmut64 0:a3ea811f80f2 48 public:
Helmut64 0:a3ea811f80f2 49
Helmut64 0:a3ea811f80f2 50 /**
Helmut64 0:a3ea811f80f2 51 * Constructor
Helmut64 0:a3ea811f80f2 52 *
Helmut64 0:a3ea811f80f2 53 * @param vendor_id Your vendor_id (default: 0x1f00)
Helmut64 0:a3ea811f80f2 54 * @param product_id Your product_id (default: 0x2012)
Helmut64 0:a3ea811f80f2 55 * @param product_release Your preoduct_release (default: 0x0001)
Helmut64 0:a3ea811f80f2 56 * @param connect_blocking define if the connection must be blocked if USB not plugged in
Helmut64 0:a3ea811f80f2 57 *
Helmut64 0:a3ea811f80f2 58 */
Helmut64 0:a3ea811f80f2 59 USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking){
Helmut64 0:a3ea811f80f2 60 settingsChangedCallback = 0;
Helmut64 0:a3ea811f80f2 61 };
Helmut64 0:a3ea811f80f2 62
Helmut64 0:a3ea811f80f2 63
Helmut64 0:a3ea811f80f2 64 /**
Helmut64 0:a3ea811f80f2 65 * Send a character. You can use puts, printf.
Helmut64 0:a3ea811f80f2 66 *
Helmut64 0:a3ea811f80f2 67 * @param c character to be sent
Helmut64 0:a3ea811f80f2 68 * @returns true if there is no error, false otherwise
Helmut64 0:a3ea811f80f2 69 */
Helmut64 0:a3ea811f80f2 70 virtual int _putc(int c);
Helmut64 0:a3ea811f80f2 71
Helmut64 0:a3ea811f80f2 72 /**
Helmut64 0:a3ea811f80f2 73 * Read a character: blocking
Helmut64 0:a3ea811f80f2 74 *
Helmut64 0:a3ea811f80f2 75 * @returns character read
Helmut64 0:a3ea811f80f2 76 */
Helmut64 0:a3ea811f80f2 77 virtual int _getc();
Helmut64 0:a3ea811f80f2 78
Helmut64 0:a3ea811f80f2 79 /**
Helmut64 0:a3ea811f80f2 80 * Check the number of bytes available.
Helmut64 0:a3ea811f80f2 81 *
Helmut64 0:a3ea811f80f2 82 * @returns the number of bytes available
Helmut64 0:a3ea811f80f2 83 */
Helmut64 0:a3ea811f80f2 84 uint8_t available();
Helmut64 0:a3ea811f80f2 85
Helmut64 0:a3ea811f80f2 86 /**
Helmut64 0:a3ea811f80f2 87 * Check if the terminal is connected.
Helmut64 0:a3ea811f80f2 88 *
Helmut64 0:a3ea811f80f2 89 * @returns connection status
Helmut64 0:a3ea811f80f2 90 */
Helmut64 0:a3ea811f80f2 91 bool connected();
Helmut64 0:a3ea811f80f2 92
Helmut64 0:a3ea811f80f2 93 /** Determine if there is a character available to read
Helmut64 0:a3ea811f80f2 94 *
Helmut64 0:a3ea811f80f2 95 * @returns
Helmut64 0:a3ea811f80f2 96 * 1 if there is a character available to read,
Helmut64 0:a3ea811f80f2 97 * 0 otherwise
Helmut64 0:a3ea811f80f2 98 */
Helmut64 0:a3ea811f80f2 99 int readable() { return available() ? 1 : 0; }
Helmut64 0:a3ea811f80f2 100
Helmut64 0:a3ea811f80f2 101 /** Determine if there is space available to write a character
Helmut64 0:a3ea811f80f2 102 *
Helmut64 0:a3ea811f80f2 103 * @returns
Helmut64 0:a3ea811f80f2 104 * 1 if there is space to write a character,
Helmut64 0:a3ea811f80f2 105 * 0 otherwise
Helmut64 0:a3ea811f80f2 106 */
Helmut64 0:a3ea811f80f2 107 int writeable() { return 1; } // always return 1, for write operation is blocking
Helmut64 0:a3ea811f80f2 108
Helmut64 0:a3ea811f80f2 109 /**
Helmut64 0:a3ea811f80f2 110 * Write a block of data.
Helmut64 0:a3ea811f80f2 111 *
Helmut64 0:a3ea811f80f2 112 * For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written.
Helmut64 0:a3ea811f80f2 113 *
Helmut64 0:a3ea811f80f2 114 * @param buf pointer on data which will be written
Helmut64 0:a3ea811f80f2 115 * @param size size of the buffer. The maximum size of a block is limited by the size of the endpoint (64 bytes)
Helmut64 0:a3ea811f80f2 116 *
Helmut64 0:a3ea811f80f2 117 * @returns true if successfull
Helmut64 0:a3ea811f80f2 118 */
Helmut64 0:a3ea811f80f2 119 bool writeBlock(uint8_t * buf, uint16_t size);
Helmut64 0:a3ea811f80f2 120
Helmut64 0:a3ea811f80f2 121 /**
Helmut64 0:a3ea811f80f2 122 * Attach a member function to call when a packet is received.
Helmut64 0:a3ea811f80f2 123 *
Helmut64 0:a3ea811f80f2 124 * @param tptr pointer to the object to call the member function on
Helmut64 0:a3ea811f80f2 125 * @param mptr pointer to the member function to be called
Helmut64 0:a3ea811f80f2 126 */
Helmut64 0:a3ea811f80f2 127 template<typename T>
Helmut64 0:a3ea811f80f2 128 void attach(T* tptr, void (T::*mptr)(void)) {
Helmut64 0:a3ea811f80f2 129 if((mptr != NULL) && (tptr != NULL)) {
Helmut64 0:a3ea811f80f2 130 rx = Callback<void()>(mptr, tptr);
Helmut64 0:a3ea811f80f2 131 }
Helmut64 0:a3ea811f80f2 132 }
Helmut64 0:a3ea811f80f2 133
Helmut64 0:a3ea811f80f2 134 /**
Helmut64 0:a3ea811f80f2 135 * Attach a callback called when a packet is received
Helmut64 0:a3ea811f80f2 136 *
Helmut64 0:a3ea811f80f2 137 * @param fptr function pointer
Helmut64 0:a3ea811f80f2 138 */
Helmut64 0:a3ea811f80f2 139 void attach(void (*fptr)(void)) {
Helmut64 0:a3ea811f80f2 140 if(fptr != NULL) {
Helmut64 0:a3ea811f80f2 141 rx = Callback<void()>(fptr);
Helmut64 0:a3ea811f80f2 142 }
Helmut64 0:a3ea811f80f2 143 }
Helmut64 0:a3ea811f80f2 144
Helmut64 0:a3ea811f80f2 145 /**
Helmut64 0:a3ea811f80f2 146 * Attach a Callback called when a packet is received
Helmut64 0:a3ea811f80f2 147 *
Helmut64 0:a3ea811f80f2 148 * @param cb Callback to attach
Helmut64 0:a3ea811f80f2 149 */
Helmut64 0:a3ea811f80f2 150 void attach(Callback<void()> &cb) {
Helmut64 0:a3ea811f80f2 151 rx = cb;
Helmut64 0:a3ea811f80f2 152 }
Helmut64 0:a3ea811f80f2 153
Helmut64 0:a3ea811f80f2 154 /**
Helmut64 0:a3ea811f80f2 155 * Attach a callback to call when serial's settings are changed.
Helmut64 0:a3ea811f80f2 156 *
Helmut64 0:a3ea811f80f2 157 * @param fptr function pointer
Helmut64 0:a3ea811f80f2 158 */
Helmut64 0:a3ea811f80f2 159 void attach(void (*fptr)(int baud, int bits, int parity, int stop)) {
Helmut64 0:a3ea811f80f2 160 settingsChangedCallback = fptr;
Helmut64 0:a3ea811f80f2 161 }
Helmut64 0:a3ea811f80f2 162
Helmut64 0:a3ea811f80f2 163 protected:
Helmut64 0:a3ea811f80f2 164 virtual bool EPBULK_OUT_callback();
Helmut64 0:a3ea811f80f2 165 virtual void lineCodingChanged(int baud, int bits, int parity, int stop){
Helmut64 0:a3ea811f80f2 166 if (settingsChangedCallback) {
Helmut64 0:a3ea811f80f2 167 settingsChangedCallback(baud, bits, parity, stop);
Helmut64 0:a3ea811f80f2 168 }
Helmut64 0:a3ea811f80f2 169 }
Helmut64 0:a3ea811f80f2 170
Helmut64 0:a3ea811f80f2 171 private:
Helmut64 0:a3ea811f80f2 172 Callback<void()> rx;
Helmut64 0:a3ea811f80f2 173 CircBuffer<uint8_t,128> buf;
Helmut64 0:a3ea811f80f2 174 void (*settingsChangedCallback)(int baud, int bits, int parity, int stop);
Helmut64 0:a3ea811f80f2 175 };
Helmut64 0:a3ea811f80f2 176
Helmut64 0:a3ea811f80f2 177 #endif