IOTON boards API using mbed SDK - http://ioton.cc/plataforma-ton

Dependents:   ton-bot_teste ton-bot_seguidor_linha ton-bot_seguidor_parede

Fork of IOTON-API by Kleber Silva

Committer:
krebyy
Date:
Thu Jun 29 20:20:49 2017 +0000
Revision:
3:9c7195d31602
Parent:
1:3a73d77c2cef
Update to TON Board V1.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krebyy 1:3a73d77c2cef 1 #ifndef USBTON_H
krebyy 1:3a73d77c2cef 2 #define USBTON_H
krebyy 1:3a73d77c2cef 3
krebyy 1:3a73d77c2cef 4 #include "Stream.h"
krebyy 1:3a73d77c2cef 5 #include "usb_user.h"
krebyy 1:3a73d77c2cef 6 #include "USBCDC.h"
krebyy 1:3a73d77c2cef 7
krebyy 1:3a73d77c2cef 8 /**
krebyy 1:3a73d77c2cef 9 * USBTon example
krebyy 1:3a73d77c2cef 10 *
krebyy 1:3a73d77c2cef 11 * @code
krebyy 1:3a73d77c2cef 12 * #include "mbed.h"
krebyy 1:3a73d77c2cef 13 * #include "USBTon.h"
krebyy 1:3a73d77c2cef 14 *
krebyy 1:3a73d77c2cef 15 * //Virtual serial port over USB
krebyy 1:3a73d77c2cef 16 * USBTon usb;
krebyy 1:3a73d77c2cef 17 *
krebyy 1:3a73d77c2cef 18 * int main(void) {
krebyy 1:3a73d77c2cef 19 *
krebyy 1:3a73d77c2cef 20 * while(1)
krebyy 1:3a73d77c2cef 21 * {
krebyy 1:3a73d77c2cef 22 * usb.printf("I am a virtual serial port\n");
krebyy 1:3a73d77c2cef 23 * wait(1);
krebyy 1:3a73d77c2cef 24 * }
krebyy 1:3a73d77c2cef 25 * }
krebyy 1:3a73d77c2cef 26 * @endcode
krebyy 1:3a73d77c2cef 27 */
krebyy 1:3a73d77c2cef 28 class USBTon: public Stream {
krebyy 1:3a73d77c2cef 29 public:
krebyy 1:3a73d77c2cef 30
krebyy 1:3a73d77c2cef 31 /**
krebyy 1:3a73d77c2cef 32 * Constructor
krebyy 1:3a73d77c2cef 33 *
krebyy 1:3a73d77c2cef 34 * @param vendor_id Your vendor_id (default: 0x1f00)
krebyy 1:3a73d77c2cef 35 * @param product_id Your product_id (default: 0x2012)
krebyy 1:3a73d77c2cef 36 * @param product_release Your preoduct_release (default: 0x0001)
krebyy 1:3a73d77c2cef 37 * @param connect_blocking define if the connection must be blocked if USB not plugged in
krebyy 1:3a73d77c2cef 38 *
krebyy 1:3a73d77c2cef 39 */
krebyy 1:3a73d77c2cef 40 USBTon(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true) {
krebyy 1:3a73d77c2cef 41
krebyy 1:3a73d77c2cef 42 };
krebyy 1:3a73d77c2cef 43
krebyy 1:3a73d77c2cef 44
krebyy 1:3a73d77c2cef 45 /**
krebyy 1:3a73d77c2cef 46 * Send a character. You can use puts, printf.
krebyy 1:3a73d77c2cef 47 *
krebyy 1:3a73d77c2cef 48 * @param c character to be sent
krebyy 1:3a73d77c2cef 49 * @returns true if there is no error, false otherwise
krebyy 1:3a73d77c2cef 50 */
krebyy 1:3a73d77c2cef 51 virtual int _putc(int c);
krebyy 1:3a73d77c2cef 52
krebyy 1:3a73d77c2cef 53 /**
krebyy 1:3a73d77c2cef 54 * Read a character: blocking
krebyy 1:3a73d77c2cef 55 *
krebyy 1:3a73d77c2cef 56 * @returns character read
krebyy 1:3a73d77c2cef 57 */
krebyy 1:3a73d77c2cef 58 virtual int _getc();
krebyy 1:3a73d77c2cef 59
krebyy 1:3a73d77c2cef 60 /**
krebyy 1:3a73d77c2cef 61 * Check the number of bytes available.
krebyy 1:3a73d77c2cef 62 *
krebyy 1:3a73d77c2cef 63 * @returns the number of bytes available
krebyy 1:3a73d77c2cef 64 */
krebyy 1:3a73d77c2cef 65 uint8_t available();
krebyy 1:3a73d77c2cef 66
krebyy 1:3a73d77c2cef 67 /** Determine if there is a character available to read
krebyy 1:3a73d77c2cef 68 *
krebyy 1:3a73d77c2cef 69 * @returns
krebyy 1:3a73d77c2cef 70 * 1 if there is a character available to read,
krebyy 1:3a73d77c2cef 71 * 0 otherwise
krebyy 1:3a73d77c2cef 72 */
krebyy 1:3a73d77c2cef 73 int readable() { return available() ? 1 : 0; }
krebyy 1:3a73d77c2cef 74
krebyy 1:3a73d77c2cef 75 /** Determine if there is space available to write a character
krebyy 1:3a73d77c2cef 76 *
krebyy 1:3a73d77c2cef 77 * @returns
krebyy 1:3a73d77c2cef 78 * 1 if there is space to write a character,
krebyy 1:3a73d77c2cef 79 * 0 otherwise
krebyy 1:3a73d77c2cef 80 */
krebyy 1:3a73d77c2cef 81 int writeable() { return 1; } // always return 1, for write operation is blocking
krebyy 1:3a73d77c2cef 82
krebyy 1:3a73d77c2cef 83 };
krebyy 1:3a73d77c2cef 84
krebyy 1:3a73d77c2cef 85 #endif