diff --git a/Makefile b/Makefile index 5cc6dd7..ef5b6fc 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/VCOM_lib/usbSerial.c b/VCOM_lib/usbSerial.c index 1bddc1e..3be5257 100644 --- a/VCOM_lib/usbSerial.c +++ b/VCOM_lib/usbSerial.c @@ -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 @@ -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; @@ -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 diff --git a/VCOM_lib/usbSerial.h b/VCOM_lib/usbSerial.h index e05db60..3007a9e 100644 --- a/VCOM_lib/usbSerial.h +++ b/VCOM_lib/usbSerial.h @@ -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 diff --git a/grbl/serial.c b/grbl/serial.c index 9e1fa1b..85eff99 100644 --- a/grbl/serial.c +++ b/grbl/serial.c @@ -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() { @@ -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 |