Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTR Support #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions digistump-avr/libraries/DigisparkCDC/DigiCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and Digistump LLC (digistump.com)

uchar sendEmptyFrame;
static uchar intr3Status; /* used to control interrupt endpoint transmissions */
static uchar portB_dtr_bit;

DigiCDCDevice::DigiCDCDevice(void){}

Expand Down Expand Up @@ -143,8 +144,8 @@ void DigiCDCDevice::usbBegin()
RingBuffer_InitBuffer(&rxBuf,rxBuf_Data,sizeof(rxBuf_Data));

intr3Status = 0;
sendEmptyFrame = 0;

sendEmptyFrame = 0;
portB_dtr_bit = 255;
sei();
}

Expand Down Expand Up @@ -186,11 +187,11 @@ void DigiCDCDevice::usbPollWrapper()

}






void DigiCDCDevice::setDtrPin(uint8_t dtrPin){
portB_dtr_bit = dtrPin;
PORTB &= ~(_BV(portB_dtr_bit));
DDRB |= (1 << portB_dtr_bit);
}

#ifdef __cplusplus
extern "C"{
Expand Down Expand Up @@ -320,6 +321,8 @@ usbRequest_t *rq = (usbRequest_t*)((void *)data);
/* SET_LINE_CODING -> usbFunctionWrite() */
}
if(rq->bRequest == SET_CONTROL_LINE_STATE){
if(portB_dtr_bit != 0xFF)
PORTB = (PORTB&~(1<<portB_dtr_bit))|((rq->wValue.word&1)<<portB_dtr_bit);
/* Report serial state (carrier detect). On several Unix platforms,
* tty devices can only be opened when carrier detect is set.
*/
Expand Down
1 change: 1 addition & 0 deletions digistump-avr/libraries/DigisparkCDC/DigiCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DigiCDCDevice : public Stream {
void refresh();
void task();
void delay(long milli);
void setDtrPin(uint8_t dtrPin);
virtual int available(void);
virtual int peek(void);
virtual int read(void);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <DigiCDC.h>
void setup() {
SerialUSB.begin();
// initialize the digital pin 1 as an DTR output.
SerialUSB.setDtrPin(1);
}

// the loop routine runs over and over again forever:
void loop() {
SerialUSB.delay(10);
}