Skip to content

Commit

Permalink
Soft reset on DTR change
Browse files Browse the repository at this point in the history
  • Loading branch information
tbfleming committed Jan 16, 2017
1 parent e043823 commit 3ebbfa4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ build/%.hex : build/%.elf

.PHONY: flash
flash: build/grbl.hex
fm COM(13, 115200) DEVICE(LPC1769, 0.000000, 0) HARDWARE(BOOTEXEC, 50, 100) ERASEUSED(build\grbl.hex, PROTECTISP) HEXFILE(build\grbl.hex, NOCHECKSUMS, NOFILL, PROTECTISP)
fm COM(15, 115200) DEVICE(LPC1769, 0.000000, 0) HARDWARE(BOOTEXEC, 50, 100) ERASEUSED(build\grbl.hex, PROTECTISP) HEXFILE(build\grbl.hex, NOCHECKSUMS, NOFILL, PROTECTISP)

.PHONY: clean
clean:
Expand Down
15 changes: 10 additions & 5 deletions VCOM_lib/usbSerial.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static U8 txdata[VCOM_FIFO_SIZE];
static fifo_t txfifo;
//static fifo_t rxfifo;

static UsbSerialLineStateCallback* usbSerialLineStateCallback = nullptr;
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;

// forward declaration of interrupt handler
Expand Down Expand Up @@ -299,10 +300,13 @@ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
break;

// set control line state
case SET_CONTROL_LINE_STATE:
// bit0 = DTR, bit = RTS

break;
case SET_CONTROL_LINE_STATE: {
bool dtr = (pSetup->wValue >> 0) & 1;
bool rts = (pSetup->wValue >> 1) & 1;
if (usbSerialLineStateCallback)
usbSerialLineStateCallback(dtr, rts);
break;
}

default:
return FALSE;
Expand Down Expand Up @@ -376,8 +380,9 @@ void enable_USB_interrupts(void);
main
====
**************************************************************************/
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback)
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback)
{
::usbSerialLineStateCallback = usbSerialLineStateCallback;
::usbSerialReadCallback = usbSerialReadCallback;

// initialise stack
Expand Down
5 changes: 4 additions & 1 deletion VCOM_lib/usbSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec

#include "serial_fifo.h"

// Receives line state. Called by an interrupt.
typedef void UsbSerialLineStateCallback(bool dtr, bool rts);

// Receives serial data. Called by an interrupt.
typedef void UsbSerialReadCallback(const U8* data, unsigned len);

int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts.
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts.

/*
Writes one character to VCOM port
Expand Down
18 changes: 14 additions & 4 deletions grbl/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void serialInterrupt(uint32_t event);
void legacy_ISR(uint8_t data);
uint8_t arm_rx_buf[1];

bool lastDtr = false;

// Returns the number of bytes available in the RX serial buffer.
uint16_t serial_get_rx_buffer_available()
{
Expand Down Expand Up @@ -80,10 +82,18 @@ uint8_t serial_get_tx_buffer_count()
void serial_init()
{
#ifdef USE_USB
usbSerialInit([](const U8* data, unsigned len) {
while(len--)
legacy_ISR(*data++);
});
usbSerialInit(
[](bool dtr, bool rts) {
if (dtr != lastDtr)
{
lastDtr = dtr;
mc_reset();
}
},
[](const U8* data, unsigned len) {
while (len--)
legacy_ISR(*data++);
});
#else
int32_t uartFlags = ARM_USART_MODE_ASYNCHRONOUS |
ARM_USART_DATA_BITS_8 |
Expand Down

0 comments on commit 3ebbfa4

Please sign in to comment.