Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
Make USB_SERIAL fit for the Arduino IDE.
Browse files Browse the repository at this point in the history
This also includes renaming of USE_USB to USB_SERIAL for more
consistency.
  • Loading branch information
Traumflug committed Dec 3, 2012
1 parent ef6036c commit 9b018b7
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 49 deletions.
16 changes: 4 additions & 12 deletions Makefile
Expand Up @@ -94,7 +94,10 @@ PROGID = stk500v2


PROGRAM = mendel 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- ARCH = avr-
CC = $(ARCH)gcc CC = $(ARCH)gcc
Expand All @@ -111,17 +114,6 @@ LIBS = -lm
LIBDEPS = LIBDEPS =
SUBDIRS = 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) ifeq ($(PROGBAUD),0)
PROGBAUD_FLAG = PROGBAUD_FLAG =
else else
Expand Down
14 changes: 11 additions & 3 deletions config.default.h
Expand Up @@ -384,10 +384,18 @@ DEFINE_HEATER(bed, PB4, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.gen3.h
Expand Up @@ -388,10 +388,18 @@ DEFINE_TEMP_SENSOR(bed, TT_INTERCOM, AIO1, 0)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.gen6.h
Expand Up @@ -372,10 +372,18 @@ DEFINE_HEATER(extruder, PD6, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.gen7-v1.1-v1.3.h
Expand Up @@ -383,10 +383,18 @@ DEFINE_HEATER(bed, DIO3, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.gen7-v1.4.h
Expand Up @@ -383,10 +383,18 @@ DEFINE_HEATER(bed, DIO3, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.ramps-v1.2.h
Expand Up @@ -381,10 +381,18 @@ DEFINE_HEATER(fan, PH6, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.ramps-v1.3.h
Expand Up @@ -383,10 +383,18 @@ DEFINE_HEATER(extruder, PB4, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.sanguinololu-v1.1.h
Expand Up @@ -379,10 +379,18 @@ DEFINE_HEATER(bed, PD6, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.sanguinololu-v1.2.h
Expand Up @@ -379,10 +379,18 @@ DEFINE_HEATER(bed, PD4, 1)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
14 changes: 11 additions & 3 deletions config.teensy.h
Expand Up @@ -438,10 +438,18 @@ DEFINE_HEATER(fan, DIO8, 0)
// #define REPRAP_HOST_COMPATIBILITY 20110509 // #define REPRAP_HOST_COMPATIBILITY 20110509
// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break> // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>


/** /** \def BAUD
Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600. 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 /** \def XONXOFF
Xon/Xoff flow control. Xon/Xoff flow control.
Expand Down
5 changes: 2 additions & 3 deletions serial.c
Expand Up @@ -13,7 +13,6 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "memory_barrier.h" #include "memory_barrier.h"


#include "config.h"
#include "arduino.h" #include "arduino.h"


/// size of TX and RX buffers. MUST be a \f$2^n\f$ value /// size of TX and RX buffers. MUST be a \f$2^n\f$ value
Expand All @@ -24,7 +23,7 @@
/// ascii XON character /// ascii XON character
#define ASCII_XON 17 #define ASCII_XON 17


#ifndef USE_USB #ifndef USB_SERIAL
/// rx buffer head pointer. Points to next available space. /// rx buffer head pointer. Points to next available space.
volatile uint8_t rxhead = 0; volatile uint8_t rxhead = 0;
/// rx buffer tail pointer. Points to last character in buffer /// rx buffer tail pointer. Points to last character in buffer
Expand Down Expand Up @@ -224,7 +223,7 @@ void serial_writechar(uint8_t data)
// enable TX interrupt so we can send this character // enable TX interrupt so we can send this character
UCSR0B |= MASK(UDRIE0); UCSR0B |= MASK(UDRIE0);
} }
#endif /* USE_USB */ #endif /* USB_SERIAL */


/// send a whole block /// send a whole block
void serial_writeblock(void *data, int datalen) void serial_writeblock(void *data, int datalen)
Expand Down
5 changes: 3 additions & 2 deletions serial.h
@@ -1,11 +1,12 @@
#ifndef _SERIAL_H #ifndef _SERIAL_H
#define _SERIAL_H #define _SERIAL_H


#include "config.h"
#include <stdint.h> #include <stdint.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>


#ifdef USE_USB #ifdef USB_SERIAL
#include "usb_serial.h" #include "usb_serial.h"
#define serial_init() usb_init() #define serial_init() usb_init()
#define serial_rxchars() usb_serial_available() #define serial_rxchars() usb_serial_available()
Expand All @@ -24,7 +25,7 @@
uint8_t serial_popchar(void); uint8_t serial_popchar(void);
// send one character // send one character
void serial_writechar(uint8_t data); void serial_writechar(uint8_t data);
#endif #endif /* USB_SERIAL */


// read/write many characters // read/write many characters
// uint8_t serial_recvblock(uint8_t *block, int blocksize); // uint8_t serial_recvblock(uint8_t *block, int blocksize);
Expand Down
6 changes: 4 additions & 2 deletions usb_serial.c
Expand Up @@ -31,8 +31,10 @@
// Version 1.7: fix usb_serial_set_control // Version 1.7: fix usb_serial_set_control
// 2012-10-17: Import to Teacup firmware // 2012-10-17: Import to Teacup firmware


#include "config.h"

/* protect this file from Arduino IDE */ /* protect this file from Arduino IDE */
#ifdef USE_USB #ifdef USB_SERIAL


#define USB_SERIAL_PRIVATE_INCLUDE #define USB_SERIAL_PRIVATE_INCLUDE
#include "usb_serial.h" #include "usb_serial.h"
Expand Down Expand Up @@ -937,4 +939,4 @@ ISR(USB_COM_vect)
UECONX = (1<<STALLRQ) | (1<<EPEN); // stall UECONX = (1<<STALLRQ) | (1<<EPEN); // stall
} }


#endif /* USE_USB */ #endif /* USB_SERIAL */

0 comments on commit 9b018b7

Please sign in to comment.