瀏覽代碼

teensy3: usb_serial: Parameterize wrappers

Add preprocessor macros to control the naming of functions, structures
and classes, to ease the creation of multiple USB serial instances.
Name generation for each instance is controlled using the
USB_SERIAL_SUFFIX and SERIAL_CLASS_SUFFIX defines.

Move the preprocessor macro wrappers around the usb_serial_port data
members to usb_serial.h, as preprocessor macro names cannot be
parameterized.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
main
Geert Uytterhoeven 4 年之前
父節點
當前提交
68b0b84c58
共有 2 個文件被更改,包括 48 次插入5 次删除
  1. +8
    -0
      teensy3/usb_serial.h
  2. +40
    -5
      teensy3/usb_serial_template.h

+ 8
- 0
teensy3/usb_serial.h 查看文件

@@ -34,7 +34,15 @@
#include "usb_desc.h"

#if (defined(CDC_STATUS_INTERFACE) && defined(CDC_DATA_INTERFACE)) || defined(USB_DISABLED)
#define USB_SERIAL_SUFFIX /* none */
#define SERIAL_CLASS_SUFFIX /* none */

#include "usb_serial_template.h"

#define usb_cdc_line_coding usb_serial_instance.cdc_line_coding
#define usb_cdc_line_rtsdtr_millis usb_serial_instance.cdc_line_rtsdtr_millis
#define usb_cdc_line_rtsdtr usb_serial_instance.cdc_line_rtsdtr
#define usb_cdc_transmit_flush_timer usb_serial_instance.cdc_transmit_flush_timer
#endif // CDC_STATUS_INTERFACE && CDC_DATA_INTERFACE

#endif // USBserial_h_

+ 40
- 5
teensy3/usb_serial_template.h 查看文件

@@ -29,9 +29,28 @@
*/

#include <inttypes.h>
#include <sys/cdefs.h> // for __CONCAT()

#include "usb_serial_port.h"

#define USB_SERIAL_PREFIX __CONCAT(usb_serial, USB_SERIAL_SUFFIX)
#define USB_SERIAL_NAME(func) __CONCAT(USB_SERIAL_PREFIX, _ ## func)
#define usb_serial_available USB_SERIAL_NAME(available)
#define usb_serial_class USB_SERIAL_NAME(class)
#define usb_serial_flush_callback USB_SERIAL_NAME(flush_callback)
#define usb_serial_flush_input USB_SERIAL_NAME(flush_input)
#define usb_serial_flush_output USB_SERIAL_NAME(flush_output)
#define usb_serial_getchar USB_SERIAL_NAME(getchar)
#define usb_serial_instance USB_SERIAL_NAME(instance)
#define usb_serial_peekchar USB_SERIAL_NAME(peekchar)
#define usb_serial_putchar USB_SERIAL_NAME(putchar)
#define usb_serial_read USB_SERIAL_NAME(read)
#define usb_serial_write_buffer_free USB_SERIAL_NAME(write_buffer_free)
#define usb_serial_write USB_SERIAL_NAME(write)

#define Serial __CONCAT(Serial, SERIAL_CLASS_SUFFIX)
#define serialEvent __CONCAT(serialEvent, SERIAL_CLASS_SUFFIX)

#if F_CPU >= 20000000 && !defined(USB_DISABLED)

#include "core_pins.h" // for millis()
@@ -92,11 +111,6 @@ static inline void usb_serial_flush_callback(void)
__usb_serial_flush_callback(&usb_serial_instance);
}

#define usb_cdc_line_coding usb_serial_instance.cdc_line_coding
#define usb_cdc_line_rtsdtr_millis usb_serial_instance.cdc_line_rtsdtr_millis
#define usb_cdc_line_rtsdtr usb_serial_instance.cdc_line_rtsdtr
#define usb_cdc_transmit_flush_timer usb_serial_instance.cdc_transmit_flush_timer

#ifdef __cplusplus
}
#endif
@@ -222,3 +236,24 @@ extern void serialEvent(void);


#endif // F_CPU

#undef usb_serial_available
#undef usb_serial_class
#undef usb_serial_flush_callback
#undef usb_serial_flush_input
#undef usb_serial_flush_output
#undef usb_serial_getchar
#undef usb_serial_instance
#undef usb_serial_peekchar
#undef usb_serial_putchar
#undef usb_serial_read
#undef usb_serial_write_buffer_free
#undef usb_serial_write

#undef Serial
#undef serialEvent

#undef USB_SERIAL_SUFFIX
#undef USB_SERIAL_PREFIX
#undef USB_SERIAL_NAME
#undef SERIAL_CLASS_SUFFIX

Loading…
取消
儲存