From 9b018b74338f8ac513e8bd022b8bd4a6decd047f Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 24 Nov 2012 15:12:24 +0100 Subject: [PATCH] Make USB_SERIAL fit for the Arduino IDE. This also includes renaming of USE_USB to USB_SERIAL for more consistency. --- Makefile | 16 ++++------------ config.default.h | 14 +++++++++++--- config.gen3.h | 14 +++++++++++--- config.gen6.h | 14 +++++++++++--- config.gen7-v1.1-v1.3.h | 14 +++++++++++--- config.gen7-v1.4.h | 14 +++++++++++--- config.ramps-v1.2.h | 14 +++++++++++--- config.ramps-v1.3.h | 14 +++++++++++--- config.sanguinololu-v1.1.h | 14 +++++++++++--- config.sanguinololu-v1.2.h | 14 +++++++++++--- config.teensy.h | 14 +++++++++++--- serial.c | 5 ++--- serial.h | 5 +++-- usb_serial.c | 6 ++++-- 14 files changed, 123 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 0a1d3aa5b..1e5f13cd3 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,10 @@ PROGID = stk500v2 PROGRAM = mendel -SOURCES = $(PROGRAM).c gcode_parse.c gcode_process.c dda.c dda_maths.c dda_queue.c timer.c temp.c sermsg.c watchdog.c debug.c sersendf.c heater.c analog.c intercom.c pinio.c clock.c home.c crc.c delay.c serial.c +SOURCES = $(PROGRAM).c gcode_parse.c gcode_process.c dda.c dda_maths.c +SOURCES += dda_queue.c timer.c temp.c sermsg.c watchdog.c debug.c sersendf.c +SOURCES += heater.c analog.c intercom.c pinio.c clock.c home.c crc.c delay.c +SOURCES += serial.c usb_serial.c ARCH = avr- CC = $(ARCH)gcc @@ -111,17 +114,6 @@ LIBS = -lm LIBDEPS = SUBDIRS = -ifneq (,$(findstring usb,$(MCU_TARGET))) -USE_USB = true -endif -ifneq (,$(findstring u4,$(MCU_TARGET))) -USE_USB = true -endif -ifdef USE_USB -CFLAGS += -DUSE_USB -SOURCES += usb_serial.c -endif - ifeq ($(PROGBAUD),0) PROGBAUD_FLAG = else diff --git a/config.default.h b/config.default.h index 0e364ecf5..dbd9b0dcd 100644 --- a/config.default.h +++ b/config.default.h @@ -384,10 +384,18 @@ DEFINE_HEATER(bed, PB4, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.gen3.h b/config.gen3.h index 6449527f2..803ded343 100644 --- a/config.gen3.h +++ b/config.gen3.h @@ -388,10 +388,18 @@ DEFINE_TEMP_SENSOR(bed, TT_INTERCOM, AIO1, 0) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.gen6.h b/config.gen6.h index 0aeebbbfa..cf2421754 100644 --- a/config.gen6.h +++ b/config.gen6.h @@ -372,10 +372,18 @@ DEFINE_HEATER(extruder, PD6, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.gen7-v1.1-v1.3.h b/config.gen7-v1.1-v1.3.h index 796fe016f..07b9616d5 100644 --- a/config.gen7-v1.1-v1.3.h +++ b/config.gen7-v1.1-v1.3.h @@ -383,10 +383,18 @@ DEFINE_HEATER(bed, DIO3, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.gen7-v1.4.h b/config.gen7-v1.4.h index aefa422fd..327eba9cd 100644 --- a/config.gen7-v1.4.h +++ b/config.gen7-v1.4.h @@ -383,10 +383,18 @@ DEFINE_HEATER(bed, DIO3, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.ramps-v1.2.h b/config.ramps-v1.2.h index 829aff094..4d8600c2c 100644 --- a/config.ramps-v1.2.h +++ b/config.ramps-v1.2.h @@ -381,10 +381,18 @@ DEFINE_HEATER(fan, PH6, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.ramps-v1.3.h b/config.ramps-v1.3.h index 334b1d28d..02adddead 100644 --- a/config.ramps-v1.3.h +++ b/config.ramps-v1.3.h @@ -383,10 +383,18 @@ DEFINE_HEATER(extruder, PB4, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.sanguinololu-v1.1.h b/config.sanguinololu-v1.1.h index 3e9326806..c3124cdb7 100644 --- a/config.sanguinololu-v1.1.h +++ b/config.sanguinololu-v1.1.h @@ -379,10 +379,18 @@ DEFINE_HEATER(bed, PD6, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.sanguinololu-v1.2.h b/config.sanguinololu-v1.2.h index 72c6d9a4b..62bcd7cf9 100644 --- a/config.sanguinololu-v1.2.h +++ b/config.sanguinololu-v1.2.h @@ -379,10 +379,18 @@ DEFINE_HEATER(bed, PD4, 1) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 115200 +// #define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/config.teensy.h b/config.teensy.h index 46124c263..cecb0b9d1 100644 --- a/config.teensy.h +++ b/config.teensy.h @@ -438,10 +438,18 @@ DEFINE_HEATER(fan, DIO8, 0) // #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY -/** - Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. */ -#define BAUD 57600 +#define USB_SERIAL /** \def XONXOFF Xon/Xoff flow control. diff --git a/serial.c b/serial.c index da7ff61ef..15c675e3a 100644 --- a/serial.c +++ b/serial.c @@ -13,7 +13,6 @@ #include #include "memory_barrier.h" -#include "config.h" #include "arduino.h" /// size of TX and RX buffers. MUST be a \f$2^n\f$ value @@ -24,7 +23,7 @@ /// ascii XON character #define ASCII_XON 17 -#ifndef USE_USB +#ifndef USB_SERIAL /// rx buffer head pointer. Points to next available space. volatile uint8_t rxhead = 0; /// rx buffer tail pointer. Points to last character in buffer @@ -224,7 +223,7 @@ void serial_writechar(uint8_t data) // enable TX interrupt so we can send this character UCSR0B |= MASK(UDRIE0); } -#endif /* USE_USB */ +#endif /* USB_SERIAL */ /// send a whole block void serial_writeblock(void *data, int datalen) diff --git a/serial.h b/serial.h index 2855d44fc..b2e25ff47 100644 --- a/serial.h +++ b/serial.h @@ -1,11 +1,12 @@ #ifndef _SERIAL_H #define _SERIAL_H +#include "config.h" #include #include #include -#ifdef USE_USB +#ifdef USB_SERIAL #include "usb_serial.h" #define serial_init() usb_init() #define serial_rxchars() usb_serial_available() @@ -24,7 +25,7 @@ uint8_t serial_popchar(void); // send one character void serial_writechar(uint8_t data); -#endif +#endif /* USB_SERIAL */ // read/write many characters // uint8_t serial_recvblock(uint8_t *block, int blocksize); diff --git a/usb_serial.c b/usb_serial.c index 84ad021bf..13626e1b5 100644 --- a/usb_serial.c +++ b/usb_serial.c @@ -31,8 +31,10 @@ // Version 1.7: fix usb_serial_set_control // 2012-10-17: Import to Teacup firmware +#include "config.h" + /* protect this file from Arduino IDE */ -#ifdef USE_USB +#ifdef USB_SERIAL #define USB_SERIAL_PRIVATE_INCLUDE #include "usb_serial.h" @@ -937,4 +939,4 @@ ISR(USB_COM_vect) UECONX = (1<