Skip to content

Commit 3ebbfa4

Browse files
committed
Soft reset on DTR change
1 parent e043823 commit 3ebbfa4

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ build/%.hex : build/%.elf
157157

158158
.PHONY: flash
159159
flash: build/grbl.hex
160-
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)
160+
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)
161161

162162
.PHONY: clean
163163
clean:

VCOM_lib/usbSerial.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static U8 txdata[VCOM_FIFO_SIZE];
8686
static fifo_t txfifo;
8787
//static fifo_t rxfifo;
8888

89+
static UsbSerialLineStateCallback* usbSerialLineStateCallback = nullptr;
8990
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;
9091

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

301302
// set control line state
302-
case SET_CONTROL_LINE_STATE:
303-
// bit0 = DTR, bit = RTS
304-
305-
break;
303+
case SET_CONTROL_LINE_STATE: {
304+
bool dtr = (pSetup->wValue >> 0) & 1;
305+
bool rts = (pSetup->wValue >> 1) & 1;
306+
if (usbSerialLineStateCallback)
307+
usbSerialLineStateCallback(dtr, rts);
308+
break;
309+
}
306310

307311
default:
308312
return FALSE;
@@ -376,8 +380,9 @@ void enable_USB_interrupts(void);
376380
main
377381
====
378382
**************************************************************************/
379-
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback)
383+
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback)
380384
{
385+
::usbSerialLineStateCallback = usbSerialLineStateCallback;
381386
::usbSerialReadCallback = usbSerialReadCallback;
382387

383388
// initialise stack

VCOM_lib/usbSerial.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec
9898

9999
#include "serial_fifo.h"
100100

101+
// Receives line state. Called by an interrupt.
102+
typedef void UsbSerialLineStateCallback(bool dtr, bool rts);
103+
101104
// Receives serial data. Called by an interrupt.
102105
typedef void UsbSerialReadCallback(const U8* data, unsigned len);
103106

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

106109
/*
107110
Writes one character to VCOM port

grbl/serial.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void serialInterrupt(uint32_t event);
4949
void legacy_ISR(uint8_t data);
5050
uint8_t arm_rx_buf[1];
5151

52+
bool lastDtr = false;
53+
5254
// Returns the number of bytes available in the RX serial buffer.
5355
uint16_t serial_get_rx_buffer_available()
5456
{
@@ -80,10 +82,18 @@ uint8_t serial_get_tx_buffer_count()
8082
void serial_init()
8183
{
8284
#ifdef USE_USB
83-
usbSerialInit([](const U8* data, unsigned len) {
84-
while(len--)
85-
legacy_ISR(*data++);
86-
});
85+
usbSerialInit(
86+
[](bool dtr, bool rts) {
87+
if (dtr != lastDtr)
88+
{
89+
lastDtr = dtr;
90+
mc_reset();
91+
}
92+
},
93+
[](const U8* data, unsigned len) {
94+
while (len--)
95+
legacy_ISR(*data++);
96+
});
8797
#else
8898
int32_t uartFlags = ARM_USART_MODE_ASYNCHRONOUS |
8999
ARM_USART_DATA_BITS_8 |

0 commit comments

Comments
 (0)