Soft reset on DTR change
This commit is contained in:
parent
e0438230b5
commit
3ebbfa4dd3
2
Makefile
2
Makefile
@ -157,7 +157,7 @@ build/%.hex : build/%.elf
|
|||||||
|
|
||||||
.PHONY: flash
|
.PHONY: flash
|
||||||
flash: build/grbl.hex
|
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
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
@ -86,6 +86,7 @@ static U8 txdata[VCOM_FIFO_SIZE];
|
|||||||
static fifo_t txfifo;
|
static fifo_t txfifo;
|
||||||
//static fifo_t rxfifo;
|
//static fifo_t rxfifo;
|
||||||
|
|
||||||
|
static UsbSerialLineStateCallback* usbSerialLineStateCallback = nullptr;
|
||||||
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;
|
static UsbSerialReadCallback* usbSerialReadCallback = nullptr;
|
||||||
|
|
||||||
// forward declaration of interrupt handler
|
// forward declaration of interrupt handler
|
||||||
@ -299,10 +300,13 @@ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// set control line state
|
// set control line state
|
||||||
case SET_CONTROL_LINE_STATE:
|
case SET_CONTROL_LINE_STATE: {
|
||||||
// bit0 = DTR, bit = RTS
|
bool dtr = (pSetup->wValue >> 0) & 1;
|
||||||
|
bool rts = (pSetup->wValue >> 1) & 1;
|
||||||
|
if (usbSerialLineStateCallback)
|
||||||
|
usbSerialLineStateCallback(dtr, rts);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -376,8 +380,9 @@ void enable_USB_interrupts(void);
|
|||||||
main
|
main
|
||||||
====
|
====
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
int usbSerialInit(UsbSerialReadCallback* usbSerialReadCallback)
|
int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback)
|
||||||
{
|
{
|
||||||
|
::usbSerialLineStateCallback = usbSerialLineStateCallback;
|
||||||
::usbSerialReadCallback = usbSerialReadCallback;
|
::usbSerialReadCallback = usbSerialReadCallback;
|
||||||
|
|
||||||
// initialise stack
|
// initialise stack
|
||||||
|
@ -98,10 +98,13 @@ void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and ec
|
|||||||
|
|
||||||
#include "serial_fifo.h"
|
#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.
|
// Receives serial data. Called by an interrupt.
|
||||||
typedef void UsbSerialReadCallback(const U8* data, unsigned len);
|
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
|
Writes one character to VCOM port
|
||||||
|
@ -49,6 +49,8 @@ void serialInterrupt(uint32_t event);
|
|||||||
void legacy_ISR(uint8_t data);
|
void legacy_ISR(uint8_t data);
|
||||||
uint8_t arm_rx_buf[1];
|
uint8_t arm_rx_buf[1];
|
||||||
|
|
||||||
|
bool lastDtr = false;
|
||||||
|
|
||||||
// Returns the number of bytes available in the RX serial buffer.
|
// Returns the number of bytes available in the RX serial buffer.
|
||||||
uint16_t serial_get_rx_buffer_available()
|
uint16_t serial_get_rx_buffer_available()
|
||||||
{
|
{
|
||||||
@ -80,8 +82,16 @@ uint8_t serial_get_tx_buffer_count()
|
|||||||
void serial_init()
|
void serial_init()
|
||||||
{
|
{
|
||||||
#ifdef USE_USB
|
#ifdef USE_USB
|
||||||
usbSerialInit([](const U8* data, unsigned len) {
|
usbSerialInit(
|
||||||
while(len--)
|
[](bool dtr, bool rts) {
|
||||||
|
if (dtr != lastDtr)
|
||||||
|
{
|
||||||
|
lastDtr = dtr;
|
||||||
|
mc_reset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[](const U8* data, unsigned len) {
|
||||||
|
while (len--)
|
||||||
legacy_ISR(*data++);
|
legacy_ISR(*data++);
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user