Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HSP_RPC_GUI by
HSP/RpcServer/StringInOut.h@0:e4a10ed6eb92, 2016-10-25 (annotated)
- Committer:
- jbradshaw
- Date:
- Tue Oct 25 15:22:11 2016 +0000
- Revision:
- 0:e4a10ed6eb92
- Child:
- 1:9490836294ea
tewt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | #ifndef _STRINGINOUT_H_ |
jbradshaw | 0:e4a10ed6eb92 | 34 | #define _STRINGINOUT_H_ |
jbradshaw | 0:e4a10ed6eb92 | 35 | |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "mbed.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "USBSerial.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | |
jbradshaw | 0:e4a10ed6eb92 | 39 | /// indicates that a string up to a CRLF is being accumulated |
jbradshaw | 0:e4a10ed6eb92 | 40 | #define GETLINE_WAITING 1 |
jbradshaw | 0:e4a10ed6eb92 | 41 | /// indicates that a string is being processes |
jbradshaw | 0:e4a10ed6eb92 | 42 | #define GETLINE_PROCESSING 2 |
jbradshaw | 0:e4a10ed6eb92 | 43 | /// indicates that a CRLF string has been buffered and can be processed |
jbradshaw | 0:e4a10ed6eb92 | 44 | #define GETLINE_DONE 3 |
jbradshaw | 0:e4a10ed6eb92 | 45 | |
jbradshaw | 0:e4a10ed6eb92 | 46 | /** |
jbradshaw | 0:e4a10ed6eb92 | 47 | * @brief Clear the incoming USB read fifo |
jbradshaw | 0:e4a10ed6eb92 | 48 | */ |
jbradshaw | 0:e4a10ed6eb92 | 49 | void clearOutReadFifo(void); |
jbradshaw | 0:e4a10ed6eb92 | 50 | /** |
jbradshaw | 0:e4a10ed6eb92 | 51 | * @brief Block until a character can be read from the USB |
jbradshaw | 0:e4a10ed6eb92 | 52 | * @return the character read |
jbradshaw | 0:e4a10ed6eb92 | 53 | */ |
jbradshaw | 0:e4a10ed6eb92 | 54 | char getch(void); |
jbradshaw | 0:e4a10ed6eb92 | 55 | /** |
jbradshaw | 0:e4a10ed6eb92 | 56 | * @brief Place incoming USB characters into a fifo |
jbradshaw | 0:e4a10ed6eb92 | 57 | * @param lineBuffer buffer to place the incoming characters |
jbradshaw | 0:e4a10ed6eb92 | 58 | * @param bufferLength length of buffer |
jbradshaw | 0:e4a10ed6eb92 | 59 | * @return GETLINE_WAITING if still waiting for a CRLF, GETLINE_DONE |
jbradshaw | 0:e4a10ed6eb92 | 60 | */ |
jbradshaw | 0:e4a10ed6eb92 | 61 | int getLine(char *lineBuffer, int bufferLength); |
jbradshaw | 0:e4a10ed6eb92 | 62 | /** |
jbradshaw | 0:e4a10ed6eb92 | 63 | * @brief Block until a fixed number of characters has been accumulated from the |
jbradshaw | 0:e4a10ed6eb92 | 64 | * incoming USB |
jbradshaw | 0:e4a10ed6eb92 | 65 | * @param lineBuffer buffer to place the incoming characters |
jbradshaw | 0:e4a10ed6eb92 | 66 | * @param maxLength length of buffer |
jbradshaw | 0:e4a10ed6eb92 | 67 | */ |
jbradshaw | 0:e4a10ed6eb92 | 68 | void getStringFixedLength(uint8_t *lineBuffer, int maxLength); |
jbradshaw | 0:e4a10ed6eb92 | 69 | /** |
jbradshaw | 0:e4a10ed6eb92 | 70 | * @brief Output a string out the USB serial port |
jbradshaw | 0:e4a10ed6eb92 | 71 | * @param str output this str the USB channel |
jbradshaw | 0:e4a10ed6eb92 | 72 | */ |
jbradshaw | 0:e4a10ed6eb92 | 73 | int putStr(const char *str); |
jbradshaw | 0:e4a10ed6eb92 | 74 | /** |
jbradshaw | 0:e4a10ed6eb92 | 75 | * @brief Place incoming USB characters into a fifo |
jbradshaw | 0:e4a10ed6eb92 | 76 | * @param data_IN buffer of characters |
jbradshaw | 0:e4a10ed6eb92 | 77 | * @param len length of data |
jbradshaw | 0:e4a10ed6eb92 | 78 | */ |
jbradshaw | 0:e4a10ed6eb92 | 79 | int fifoIncomingChars(uint8_t data_IN[], unsigned int len); |
jbradshaw | 0:e4a10ed6eb92 | 80 | /** |
jbradshaw | 0:e4a10ed6eb92 | 81 | * @brief Outut an array of bytes out the USB serial port |
jbradshaw | 0:e4a10ed6eb92 | 82 | * @param data buffer to output |
jbradshaw | 0:e4a10ed6eb92 | 83 | * @param length length of buffer |
jbradshaw | 0:e4a10ed6eb92 | 84 | */ |
jbradshaw | 0:e4a10ed6eb92 | 85 | int putBytes(uint8_t *data, uint32_t length); |
jbradshaw | 0:e4a10ed6eb92 | 86 | /** |
jbradshaw | 0:e4a10ed6eb92 | 87 | * @brief Outut 256 byte blocks out the USB serial using writeBlock bulk |
jbradshaw | 0:e4a10ed6eb92 | 88 | * transfers |
jbradshaw | 0:e4a10ed6eb92 | 89 | * @param data buffer of blocks to output |
jbradshaw | 0:e4a10ed6eb92 | 90 | * @param length length of 256-byte blocks |
jbradshaw | 0:e4a10ed6eb92 | 91 | */ |
jbradshaw | 0:e4a10ed6eb92 | 92 | int putBytes256Block(uint8_t *data, int numberBlocks); |
jbradshaw | 0:e4a10ed6eb92 | 93 | |
jbradshaw | 0:e4a10ed6eb92 | 94 | #endif // _STRINGINOUT_H_ |