2011-09-23 23:56:24 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* The MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 LeafLabs LLC.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2012-05-08 22:22:41 +02:00
|
|
|
* @file libmaple/include/libmaple/usb_cdcacm.h
|
2011-09-23 23:56:24 +02:00
|
|
|
* @brief USB CDC ACM (virtual serial terminal) support
|
2012-07-31 18:33:31 +02:00
|
|
|
*
|
|
|
|
* IMPORTANT: this API is unstable, and may change without notice.
|
2011-09-23 23:56:24 +02:00
|
|
|
*/
|
|
|
|
|
2011-11-16 19:26:34 +01:00
|
|
|
#ifndef _LIBMAPLE_USB_CDCACM_H_
|
|
|
|
#define _LIBMAPLE_USB_CDCACM_H_
|
2011-09-23 23:56:24 +02:00
|
|
|
|
Move public headers to include directories; related cleanups.
Move libmaple/*.h to (new) libmaple/include/libmaple/. The new
accepted way to include a libmaple header foo.h is with:
#include <libmaple/foo.h>
This is more polite in terms of the include namespace. It also allows
us to e.g. implement the Arduino SPI library at all (which has header
SPI.h; providing it was previously impossible on case-insensitive
filesystems due to libmaple's spi.h).
Similarly for Wirish.
The old include style (#include "header.h") is now deprecated.
libmaple/*.h:
- Change include guard #defines from _FOO_H_ to _LIBMAPLE_FOO_H_.
- Add license headers where they're missing
- Add conditional extern "C" { ... } blocks where they're missing
(they aren't always necessary, but we might was well do it against
the future, while we're at it.).
- Change includes from #include "foo.h" to #include <libmaple/foo.h>.
- Move includes after extern "C".
- Remove extra trailing newlines
Note that this doesn't include the headers under libmaple/usb/ or
libmaple/usb/usb_lib. These will get fixed later.
libmaple/*.c:
- Change includes from #include "foo.h" to #include <libmaple/foo.h>.
Makefile:
- Add I$(LIBMAPLE_PATH)/include/libmaple to GLOBAL_FLAGS. This allows
for users (including Wirish) to migrate their code, but should go
away ASAP, since it slows down compilation.
Wirish:
- Move wirish/**/*.h to (new) wirish/include/wirish/. This ignores
the USB headers, which, as usual, are getting handled after
everything else.
- Similarly generify wirish/boards/ structure. For each supported
board "foo", move wirish/boards/foo.h and wirish/boards/foo.cpp to
wirish/boards/foo/include/board/board.h and
wirish/boards/foo/board.cpp, respectively. Also remove the #ifdef
hacks around the .cpp files.
- wirish/rules.mk: put wirish/boards/foo/include in the include path
(and add wirish/boards/foo/board.cpp to the list of sources to be
compiled). This allows saying:
#include <board/board.h>
instead of the hack currently in place. We can allow the user to
override this setting later to make adding custom board definitions
easier.
- Disable -Werror in libmaple/rules.mk, as the current USB warnings
don't let the olimex_stm32_h103 board compile. We can re-enable
-Werror once we've moved the board-specific bits out of libmaple
proper.
libraries, examples:
- Update includes accordingly.
- Miscellaneous cosmetic fixups.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-11-15 18:45:43 +01:00
|
|
|
#include <libmaple/libmaple_types.h>
|
|
|
|
#include <libmaple/gpio.h>
|
2012-08-05 00:28:34 +02:00
|
|
|
#include <libmaple/usb.h>
|
2011-09-23 23:56:24 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 18:33:31 +02:00
|
|
|
/*
|
|
|
|
* CDC ACM Requests
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define USB_CDCACM_SET_LINE_CODING 0x20
|
|
|
|
#define USB_CDCACM_GET_LINE_CODING 0x21
|
|
|
|
#define USB_CDCACM_SET_COMM_FEATURE 0x02
|
|
|
|
#define USB_CDCACM_SET_CONTROL_LINE_STATE 0x22
|
|
|
|
#define USB_CDCACM_CONTROL_LINE_DTR (0x01)
|
|
|
|
#define USB_CDCACM_CONTROL_LINE_RTS (0x02)
|
|
|
|
|
2012-08-04 22:54:07 +02:00
|
|
|
/*
|
|
|
|
* Descriptors, etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CDC_FUNCTIONAL_DESCRIPTOR_SIZE(DataSize) (3 + DataSize)
|
|
|
|
#define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \
|
|
|
|
struct { \
|
|
|
|
uint8 bLength; \
|
|
|
|
uint8 bDescriptorType; \
|
|
|
|
uint8 SubType; \
|
|
|
|
uint8 Data[DataSize]; \
|
|
|
|
} __packed
|
|
|
|
|
|
|
|
#define USB_DEVICE_CLASS_CDC 0x02
|
|
|
|
#define USB_DEVICE_SUBCLASS_CDC 0x00
|
|
|
|
#define USB_INTERFACE_CLASS_CDC 0x02
|
|
|
|
#define USB_INTERFACE_SUBCLASS_CDC_ACM 0x02
|
|
|
|
#define USB_INTERFACE_CLASS_DIC 0x0A
|
|
|
|
|
2013-01-17 17:40:50 +01:00
|
|
|
/*
|
|
|
|
* Endpoint configuration
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define USB_CDCACM_CTRL_ENDP 0
|
|
|
|
#define USB_CDCACM_CTRL_RX_ADDR 0x40
|
|
|
|
#define USB_CDCACM_CTRL_TX_ADDR 0x80
|
|
|
|
#define USB_CDCACM_CTRL_EPSIZE 0x40
|
|
|
|
|
|
|
|
#define USB_CDCACM_TX_ENDP 1
|
|
|
|
#define USB_CDCACM_TX_ADDR 0xC0
|
|
|
|
#define USB_CDCACM_TX_EPSIZE 0x40
|
|
|
|
|
|
|
|
#define USB_CDCACM_MANAGEMENT_ENDP 2
|
|
|
|
#define USB_CDCACM_MANAGEMENT_ADDR 0x100
|
|
|
|
#define USB_CDCACM_MANAGEMENT_EPSIZE 0x40
|
|
|
|
|
|
|
|
#define USB_CDCACM_RX_ENDP 3
|
|
|
|
#define USB_CDCACM_RX_ADDR 0x110
|
|
|
|
#define USB_CDCACM_RX_EPSIZE 0x40
|
|
|
|
|
2012-08-05 00:28:34 +02:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#define USB_CDCACM_DECLARE_DEV_DESC(vid, pid) \
|
|
|
|
{ \
|
|
|
|
.bLength = sizeof(usb_descriptor_device), \
|
|
|
|
.bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE, \
|
|
|
|
.bcdUSB = 0x0200, \
|
|
|
|
.bDeviceClass = USB_DEVICE_CLASS_CDC, \
|
|
|
|
.bDeviceSubClass = USB_DEVICE_SUBCLASS_CDC, \
|
|
|
|
.bDeviceProtocol = 0x00, \
|
|
|
|
.bMaxPacketSize0 = 0x40, \
|
|
|
|
.idVendor = vid, \
|
|
|
|
.idProduct = pid, \
|
|
|
|
.bcdDevice = 0x0200, \
|
|
|
|
.iManufacturer = 0x01, \
|
|
|
|
.iProduct = 0x02, \
|
|
|
|
.iSerialNumber = 0x00, \
|
|
|
|
.bNumConfigurations = 0x01, \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 18:33:31 +02:00
|
|
|
/*
|
|
|
|
* CDC ACM interface
|
|
|
|
*/
|
|
|
|
|
2011-09-23 23:56:24 +02:00
|
|
|
void usb_cdcacm_enable(gpio_dev*, uint8);
|
|
|
|
void usb_cdcacm_disable(gpio_dev*, uint8);
|
|
|
|
|
|
|
|
void usb_cdcacm_putc(char ch);
|
|
|
|
uint32 usb_cdcacm_tx(const uint8* buf, uint32 len);
|
|
|
|
uint32 usb_cdcacm_rx(uint8* buf, uint32 len);
|
2012-07-31 20:36:31 +02:00
|
|
|
uint32 usb_cdcacm_peek(uint8* buf, uint32 len);
|
2011-09-23 23:56:24 +02:00
|
|
|
|
|
|
|
uint32 usb_cdcacm_data_available(void); /* in RX buffer */
|
|
|
|
uint16 usb_cdcacm_get_pending(void);
|
2013-01-17 17:41:02 +01:00
|
|
|
uint8 usb_cdcacm_is_transmitting(void);
|
2011-09-23 23:56:24 +02:00
|
|
|
|
|
|
|
uint8 usb_cdcacm_get_dtr(void);
|
|
|
|
uint8 usb_cdcacm_get_rts(void);
|
|
|
|
|
2012-08-04 07:47:22 +02:00
|
|
|
typedef struct usb_cdcacm_line_coding {
|
|
|
|
uint32 dwDTERate; /* Baud rate */
|
|
|
|
|
|
|
|
#define USB_CDCACM_STOP_BITS_1 0
|
|
|
|
#define USB_CDCACM_STOP_BITS_1_5 1
|
|
|
|
#define USB_CDCACM_STOP_BITS_2 2
|
|
|
|
uint8 bCharFormat; /* Stop bits */
|
|
|
|
|
|
|
|
#define USB_CDCACM_PARITY_NONE 0
|
|
|
|
#define USB_CDCACM_PARITY_ODD 1
|
|
|
|
#define USB_CDCACM_PARITY_EVEN 2
|
|
|
|
#define USB_CDCACM_PARITY_MARK 3
|
|
|
|
#define USB_CDCACM_PARITY_SPACE 4
|
|
|
|
uint8 bParityType; /* Parity type */
|
|
|
|
|
|
|
|
uint8 bDataBits; /* Data bits: 5, 6, 7, 8, or 16 */
|
|
|
|
} __packed usb_cdcacm_line_coding;
|
|
|
|
|
|
|
|
/* Retrieve a copy of the current line coding structure. */
|
|
|
|
void usb_cdcacm_get_line_coding(usb_cdcacm_line_coding*);
|
|
|
|
|
|
|
|
/* Line coding conveniences. */
|
|
|
|
int usb_cdcacm_get_baud(void); /* dwDTERate */
|
|
|
|
int usb_cdcacm_get_stop_bits(void); /* bCharFormat */
|
|
|
|
int usb_cdcacm_get_parity(void); /* bParityType */
|
|
|
|
int usb_cdcacm_get_n_data_bits(void); /* bDataBits */
|
|
|
|
|
2012-07-31 19:03:12 +02:00
|
|
|
/*
|
|
|
|
* Hack: hooks for bootloader reset signalling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define USB_CDCACM_HOOK_RX 0x1
|
|
|
|
#define USB_CDCACM_HOOK_IFACE_SETUP 0x2
|
|
|
|
|
|
|
|
void usb_cdcacm_set_hooks(unsigned hook_flags, void (*hook)(unsigned, void*));
|
|
|
|
|
|
|
|
static __always_inline void usb_cdcacm_remove_hooks(unsigned hook_flags) {
|
|
|
|
usb_cdcacm_set_hooks(hook_flags, 0);
|
|
|
|
}
|
|
|
|
|
2011-09-23 23:56:24 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|