mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-04-28 07:39:02 -07:00
Compare commits
69 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
111396ffe5 | ||
![]() |
d208cb7669 | ||
![]() |
684c36af77 | ||
![]() |
d457051fd4 | ||
![]() |
b9a79d8b2e | ||
![]() |
7841eb24ff | ||
![]() |
f402493d27 | ||
![]() |
41c25785db | ||
![]() |
2b684b9034 | ||
![]() |
280b22b652 | ||
![]() |
822a2e4f55 | ||
![]() |
2c40bcdd6f | ||
![]() |
af7c58d1e5 | ||
![]() |
ab01715320 | ||
![]() |
c16eb3cf70 | ||
![]() |
40be695f81 | ||
![]() |
fbd4d79324 | ||
![]() |
92260e2acd | ||
![]() |
badec8f822 | ||
![]() |
0d4830288d | ||
![]() |
3577e4a637 | ||
![]() |
eed2ff45ba | ||
![]() |
6844d32b06 | ||
![]() |
bd916e2eea | ||
![]() |
4a1f9c7ac5 | ||
![]() |
836e363726 | ||
![]() |
2de159b44d | ||
![]() |
7533853c57 | ||
![]() |
7d52a0cfb9 | ||
![]() |
60edebc52b | ||
![]() |
008b95382b | ||
![]() |
528559488d | ||
![]() |
487b621a89 | ||
![]() |
2f8eec51b4 | ||
![]() |
aeb7af566f | ||
![]() |
8810516130 | ||
![]() |
92c97e3b2b | ||
![]() |
4e2f6ffa1c | ||
![]() |
68ad726f9b | ||
![]() |
6ca6b114d5 | ||
![]() |
bc55c9bb45 | ||
![]() |
32573857c0 | ||
![]() |
df42601d87 | ||
![]() |
6e29ad8d17 | ||
![]() |
7f0e4124e0 | ||
![]() |
a83f085330 | ||
![]() |
d56454e098 | ||
![]() |
52f444d221 | ||
![]() |
fb93846380 | ||
![]() |
02c36dfd60 | ||
![]() |
ae86668681 | ||
![]() |
d8e0256a91 | ||
![]() |
f92e829acd | ||
![]() |
a9864c18e8 | ||
![]() |
56dda1007d | ||
![]() |
e09b5f479b | ||
![]() |
d5fa60a1ec | ||
![]() |
1fd5034261 | ||
![]() |
48053b678c | ||
![]() |
c9c6354e5e | ||
![]() |
3a65e107c1 | ||
![]() |
80a8414444 | ||
![]() |
887be86cd5 | ||
![]() |
9d3fff43c0 | ||
![]() |
9d7d91d80b | ||
![]() |
e654e59a54 | ||
![]() |
6c75499202 | ||
![]() |
58157e2dc1 | ||
![]() |
536d3a90b4 |
22
README.md
22
README.md
@ -1,19 +1,23 @@
|
|||||||
DigistumpArduino
|
DigistumpArduino
|
||||||
================
|
================
|
||||||
|
|
||||||
Files to add Digistump support (Digispark, Pro, DigiX) to Arduino 1.5.X (1.5.7+)
|
Files to add Digistump support (Digispark, Pro, DigiX) to Arduino 1.6.X (1.6.4+)
|
||||||
|
|
||||||
|
**These files are designed for install via the Arduino Boards Manager:**
|
||||||
|
|
||||||
**Binary downloads of the bundled IDE can be found here:** https://github.com/digistump/DigistumpArduino/releases/tag/v1.5.8A
|
Board manager URL: http://digistump.com/package_digistump_index.json
|
||||||
|
|
||||||
To manually install:
|
**Full Install Instructions:**
|
||||||
|
|
||||||
Place digistump folder inside the Arduino /hardware folder.
|
Digispark: http://digistump.com/wiki/digispark/tutorials/connecting
|
||||||
|
|
||||||
To compile tools for other platforms or from scratch use:
|
Digispark Pro: http://digistump.com/wiki/digispark/tutorials/connectingpro
|
||||||
|
|
||||||
|
DigiX: http://digistump.com/wiki/digix/tutorials/software
|
||||||
|
|
||||||
|
**To compile:**
|
||||||
|
|
||||||
|
Micronucleus is the only executable in these packages that is pre-compiled:
|
||||||
|
|
||||||
Micronucleus: https://github.com/micronucleus/micronucleus/tree/80419704f68bf0783c5de63a6a4b9d89b45235c7
|
Micronucleus: https://github.com/micronucleus/micronucleus/tree/80419704f68bf0783c5de63a6a4b9d89b45235c7
|
||||||
|
Dependencies: libusb and possibly lib32stdc on linux - (on ubuntu get it by issuing: apt-get install lib32stdc++6)
|
||||||
AVR-Dummy: https://github.com/digistump/avr-dummy
|
|
||||||
|
|
||||||
ld from a more recent install of avr-gcc then Arduino uses
|
|
@ -62,4 +62,46 @@ digispark-pro64.build.core=pro
|
|||||||
digispark-pro64.build.variant=pro64buffer
|
digispark-pro64.build.variant=pro64buffer
|
||||||
digispark-pro64.upload.wait_for_upload_port = false
|
digispark-pro64.upload.wait_for_upload_port = false
|
||||||
digispark-pro64.upload.use_1200bps_touch = false
|
digispark-pro64.upload.use_1200bps_touch = false
|
||||||
digispark-pro64.upload.disable_flushing = false
|
digispark-pro64.upload.disable_flushing = false
|
||||||
|
|
||||||
|
digispark-tiny16.name=Digispark (16mhz - No USB)
|
||||||
|
digispark-tiny16.upload.using=micronucleusprog
|
||||||
|
digispark-tiny16.upload.protocol=usb
|
||||||
|
digispark-tiny16.upload.tool=micronucleus
|
||||||
|
digispark-tiny16.upload.maximum_size=6012
|
||||||
|
digispark-tiny16.build.mcu=attiny85
|
||||||
|
digispark-tiny16.build.f_cpu=16000000L
|
||||||
|
digispark-tiny16.build.board=AVR_DIGISPARK
|
||||||
|
digispark-tiny16.build.core=tiny
|
||||||
|
digispark-tiny16.build.variant=digispark
|
||||||
|
digispark-tiny16.upload.wait_for_upload_port = false
|
||||||
|
digispark-tiny16.upload.use_1200bps_touch = false
|
||||||
|
digispark-tiny16.upload.disable_flushing = false
|
||||||
|
|
||||||
|
digispark-tiny8.name=Digispark (8mhz - No USB)
|
||||||
|
digispark-tiny8.upload.using=micronucleusprog
|
||||||
|
digispark-tiny8.upload.protocol=usb
|
||||||
|
digispark-tiny8.upload.tool=micronucleus
|
||||||
|
digispark-tiny8.upload.maximum_size=6012
|
||||||
|
digispark-tiny8.build.mcu=attiny85
|
||||||
|
digispark-tiny8.build.f_cpu=8000000L
|
||||||
|
digispark-tiny8.build.board=AVR_DIGISPARK
|
||||||
|
digispark-tiny8.build.core=tiny
|
||||||
|
digispark-tiny8.build.variant=digispark
|
||||||
|
digispark-tiny8.upload.wait_for_upload_port = false
|
||||||
|
digispark-tiny8.upload.use_1200bps_touch = false
|
||||||
|
digispark-tiny8.upload.disable_flushing = false
|
||||||
|
|
||||||
|
digispark-tiny1.name=Digispark (1mhz - No USB)
|
||||||
|
digispark-tiny1.upload.using=micronucleusprog
|
||||||
|
digispark-tiny1.upload.protocol=usb
|
||||||
|
digispark-tiny1.upload.tool=micronucleus
|
||||||
|
digispark-tiny1.upload.maximum_size=6012
|
||||||
|
digispark-tiny1.build.mcu=attiny85
|
||||||
|
digispark-tiny1.build.f_cpu=1000000L
|
||||||
|
digispark-tiny1.build.board=AVR_DIGISPARK
|
||||||
|
digispark-tiny1.build.core=tiny
|
||||||
|
digispark-tiny1.build.variant=digispark
|
||||||
|
digispark-tiny1.upload.wait_for_upload_port = false
|
||||||
|
digispark-tiny1.upload.use_1200bps_touch = false
|
||||||
|
digispark-tiny1.upload.disable_flushing = false
|
@ -103,6 +103,11 @@ int digitalRead(uint8_t);
|
|||||||
int analogRead(uint8_t);
|
int analogRead(uint8_t);
|
||||||
void analogReference(uint8_t mode);
|
void analogReference(uint8_t mode);
|
||||||
void analogWrite(uint8_t, int);
|
void analogWrite(uint8_t, int);
|
||||||
|
void pwmWrite(uint8_t, int);
|
||||||
|
void pwmConnect(uint8_t);
|
||||||
|
void pwmDisconnect(uint8_t);
|
||||||
|
void pwmReset(void);
|
||||||
|
|
||||||
|
|
||||||
unsigned long millis(void);
|
unsigned long millis(void);
|
||||||
unsigned long micros(void);
|
unsigned long micros(void);
|
||||||
@ -160,6 +165,9 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
|
|||||||
#define TIMER1B 4
|
#define TIMER1B 4
|
||||||
#define TIMER1D 5
|
#define TIMER1D 5
|
||||||
|
|
||||||
|
#define CHANNELA 3 //TIMER1A
|
||||||
|
#define CHANNELB 4 //TIMER1B
|
||||||
|
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
#ifndef USE_SOFTWARE_SERIAL
|
#ifndef USE_SOFTWARE_SERIAL
|
@ -45,6 +45,8 @@ void analogReference(uint8_t mode)
|
|||||||
analog_reference = mode;
|
analog_reference = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int analogRead(uint8_t pin)
|
int analogRead(uint8_t pin)
|
||||||
{
|
{
|
||||||
#if defined( NUM_DIGITAL_PINS )
|
#if defined( NUM_DIGITAL_PINS )
|
||||||
@ -83,6 +85,80 @@ int analogRead(uint8_t pin)
|
|||||||
return LOW;
|
return LOW;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pwmReset()
|
||||||
|
{
|
||||||
|
cbi(TCCR1D, OC1AV);
|
||||||
|
cbi(TCCR1D, OC1AU);
|
||||||
|
cbi(TCCR1D, OC1AW);
|
||||||
|
cbi(TCCR1D, OC1AX);
|
||||||
|
cbi(TCCR1D, OC1BV);
|
||||||
|
cbi(TCCR1D, OC1BU);
|
||||||
|
cbi(TCCR1D, OC1BW);
|
||||||
|
cbi(TCCR1D, OC1BX);
|
||||||
|
}
|
||||||
|
void pwmWrite(uint8_t channel, int val)
|
||||||
|
{
|
||||||
|
if( channel == TIMER1A){
|
||||||
|
// connect pwm to pin on timer 1, channel A
|
||||||
|
sbi(TCCR1A, COM1A1);
|
||||||
|
sbi(TCCR1A, WGM10);
|
||||||
|
cbi(TCCR1A, COM1A0);
|
||||||
|
sbi(TCCR1B, WGM10);
|
||||||
|
sbi(TCCR1B, CS11);
|
||||||
|
//sbi(TCCR1B, CS10);
|
||||||
|
OCR1A = val; // set pwm duty
|
||||||
|
} else if( channel == TIMER1B){
|
||||||
|
// connect pwm to pin on timer 1, channel B
|
||||||
|
sbi(TCCR1A, COM1B1);
|
||||||
|
sbi(TCCR1A, WGM10);
|
||||||
|
cbi(TCCR1A, COM1B0);
|
||||||
|
sbi(TCCR1B, WGM10);
|
||||||
|
sbi(TCCR1B, CS11);
|
||||||
|
//sbi(TCCR1B, CS10);
|
||||||
|
OCR1B = val; // set pwm duty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwmConnect(uint8_t pin)
|
||||||
|
{
|
||||||
|
pinMode(pin,OUTPUT);
|
||||||
|
if(pin == 2)
|
||||||
|
sbi(TCCR1D, OC1AV);
|
||||||
|
else if(pin == 0)
|
||||||
|
sbi(TCCR1D, OC1AU);
|
||||||
|
// cbi(TCCR1D, OC1AW);//used by crystal
|
||||||
|
else if(pin == 3)
|
||||||
|
sbi(TCCR1D, OC1AX);
|
||||||
|
else if(pin == 4)
|
||||||
|
sbi(TCCR1D, OC1BV);
|
||||||
|
else if(pin == 1)
|
||||||
|
sbi(TCCR1D, OC1BU);
|
||||||
|
// cbi(TCCR1D, OC1BW);//used by crystal
|
||||||
|
// sbi(TCCR1D, OC1BX);//reset pin
|
||||||
|
|
||||||
|
}
|
||||||
|
void pwmDisconnect(uint8_t pin)
|
||||||
|
{
|
||||||
|
pinMode(pin,OUTPUT);
|
||||||
|
if(pin == 2)
|
||||||
|
cbi(TCCR1D, OC1AV);
|
||||||
|
else if(pin == 0)
|
||||||
|
cbi(TCCR1D, OC1AU);
|
||||||
|
// cbi(TCCR1D, OC1AW);//used by crystal
|
||||||
|
else if(pin == 3)
|
||||||
|
cbi(TCCR1D, OC1AX);
|
||||||
|
else if(pin == 4)
|
||||||
|
cbi(TCCR1D, OC1BV);
|
||||||
|
else if(pin == 1)
|
||||||
|
cbi(TCCR1D, OC1BU);
|
||||||
|
// cbi(TCCR1D, OC1BW);//used by crystal
|
||||||
|
// cbi(TCCR1D, OC1BX);//reset pin
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Right now, PWM output only works on the pins with
|
// Right now, PWM output only works on the pins with
|
||||||
// hardware support. These are defined in the appropriate
|
// hardware support. These are defined in the appropriate
|
||||||
// pins_*.c file. For the rest of the pins, we default
|
// pins_*.c file. For the rest of the pins, we default
|
||||||
@ -109,15 +185,15 @@ void analogWrite(uint8_t pin, int val)
|
|||||||
uint8_t timer = digitalPinToTimer(pin);
|
uint8_t timer = digitalPinToTimer(pin);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if( timer == TIMER0B){
|
|
||||||
// connect pwm to pin on timer 0, channel B
|
|
||||||
sbi(TCCR0A, COM0B1);
|
|
||||||
cbi(TCCR0A, COM0B0);
|
|
||||||
OCR0B = val; // set pwm duty
|
|
||||||
} else
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
if( timer == TIMER0A){
|
||||||
|
// connect pwm to pin 8 on timer 0, channel A
|
||||||
|
sbi(TCCR0A, COM0A1);
|
||||||
|
cbi(TCCR0A, COM0A0);
|
||||||
|
sbi(TCCR0A, WGM01);
|
||||||
|
sbi(TCCR0A, WGM00);
|
||||||
|
OCR0A = val; // set pwm duty
|
||||||
|
} else
|
||||||
|
|
||||||
if( timer == TIMER1A){
|
if( timer == TIMER1A){
|
||||||
// connect pwm to pin on timer 1, channel A
|
// connect pwm to pin on timer 1, channel A
|
||||||
@ -129,10 +205,19 @@ void analogWrite(uint8_t pin, int val)
|
|||||||
//sbi(TCCR1B, CS10);
|
//sbi(TCCR1B, CS10);
|
||||||
|
|
||||||
cbi(TCCR1D, OC1AV);
|
cbi(TCCR1D, OC1AV);
|
||||||
sbi(TCCR1D, OC1AU);
|
cbi(TCCR1D, OC1AU);
|
||||||
cbi(TCCR1D, OC1AW);
|
cbi(TCCR1D, OC1AW);
|
||||||
cbi(TCCR1D, OC1AX);
|
cbi(TCCR1D, OC1AX);
|
||||||
|
|
||||||
|
if(pin == 2)
|
||||||
|
sbi(TCCR1D, OC1AV);
|
||||||
|
else if(pin == 0)
|
||||||
|
sbi(TCCR1D, OC1AU);
|
||||||
|
else if(pin == 3)
|
||||||
|
sbi(TCCR1D, OC1AX);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OCR1A = val; // set pwm duty
|
OCR1A = val; // set pwm duty
|
||||||
} else
|
} else
|
||||||
|
|
||||||
@ -150,16 +235,17 @@ void analogWrite(uint8_t pin, int val)
|
|||||||
//sbi(TCCR1B, CS10);
|
//sbi(TCCR1B, CS10);
|
||||||
|
|
||||||
cbi(TCCR1D, OC1BV);
|
cbi(TCCR1D, OC1BV);
|
||||||
sbi(TCCR1D, OC1BU);
|
cbi(TCCR1D, OC1BU);
|
||||||
cbi(TCCR1D, OC1BW);
|
cbi(TCCR1D, OC1BW);
|
||||||
cbi(TCCR1D, OC1BX);
|
cbi(TCCR1D, OC1BX);
|
||||||
|
|
||||||
|
if(pin == 4)
|
||||||
|
sbi(TCCR1D, OC1BV);
|
||||||
|
else if(pin == 1)
|
||||||
|
sbi(TCCR1D, OC1BU);
|
||||||
|
|
||||||
OCR1B = val; // set pwm duty
|
OCR1B = val; // set pwm duty
|
||||||
} else
|
} else
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
{
|
{
|
18
digistump-avr/cores/tiny/new.cpp
Normal file
18
digistump-avr/cores/tiny/new.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <new.h>
|
||||||
|
|
||||||
|
void * operator new(size_t size)
|
||||||
|
{
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator delete(void * ptr)
|
||||||
|
{
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
|
||||||
|
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
|
||||||
|
void __cxa_guard_abort (__guard *) {};
|
||||||
|
|
||||||
|
void __cxa_pure_virtual(void) {};
|
||||||
|
|
22
digistump-avr/cores/tiny/new.h
Normal file
22
digistump-avr/cores/tiny/new.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* Header to define new/delete operators as they aren't provided by avr-gcc by default
|
||||||
|
Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEW_H
|
||||||
|
#define NEW_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void * operator new(size_t size);
|
||||||
|
void operator delete(void * ptr);
|
||||||
|
|
||||||
|
__extension__ typedef int __guard __attribute__((mode (__DI__)));
|
||||||
|
|
||||||
|
extern "C" int __cxa_guard_acquire(__guard *);
|
||||||
|
extern "C" void __cxa_guard_release (__guard *);
|
||||||
|
extern "C" void __cxa_guard_abort (__guard *);
|
||||||
|
|
||||||
|
extern "C" void __cxa_pure_virtual(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -43,6 +43,7 @@ extern "C"{
|
|||||||
|
|
||||||
#define INPUT 0x0
|
#define INPUT 0x0
|
||||||
#define OUTPUT 0x1
|
#define OUTPUT 0x1
|
||||||
|
#define INPUT_PULLUP 0x2
|
||||||
|
|
||||||
#define true 0x1
|
#define true 0x1
|
||||||
#define false 0x0
|
#define false 0x0
|
@ -35,21 +35,28 @@ void pinMode(uint8_t pin, uint8_t mode)
|
|||||||
{
|
{
|
||||||
uint8_t bit = digitalPinToBitMask(pin);
|
uint8_t bit = digitalPinToBitMask(pin);
|
||||||
uint8_t port = digitalPinToPort(pin);
|
uint8_t port = digitalPinToPort(pin);
|
||||||
volatile uint8_t *reg;
|
volatile uint8_t *reg, *out;
|
||||||
|
|
||||||
if (port == NOT_A_PIN) return;
|
if (port == NOT_A_PIN) return;
|
||||||
|
|
||||||
// JWS: can I let the optimizer do this?
|
// JWS: can I let the optimizer do this?
|
||||||
reg = portModeRegister(port);
|
reg = portModeRegister(port);
|
||||||
|
out = portOutputRegister(port);
|
||||||
|
|
||||||
if (mode == INPUT) {
|
if (mode == INPUT) {
|
||||||
uint8_t oldSREG = SREG;
|
uint8_t oldSREG = SREG;
|
||||||
cli();
|
cli();
|
||||||
*reg &= ~bit;
|
*reg &= ~bit;
|
||||||
SREG = oldSREG;
|
SREG = oldSREG;
|
||||||
|
} else if (mode == INPUT_PULLUP) {
|
||||||
|
uint8_t oldSREG = SREG;
|
||||||
|
cli();
|
||||||
|
*reg &= ~bit;
|
||||||
|
*out |= bit;
|
||||||
|
SREG = oldSREG;
|
||||||
} else {
|
} else {
|
||||||
uint8_t oldSREG = SREG;
|
uint8_t oldSREG = SREG;
|
||||||
cli();
|
cli();
|
||||||
*reg |= bit;
|
*reg |= bit;
|
||||||
SREG = oldSREG;
|
SREG = oldSREG;
|
||||||
}
|
}
|
@ -17,7 +17,6 @@ and Digistump LLC (digistump.com)
|
|||||||
uchar sendEmptyFrame;
|
uchar sendEmptyFrame;
|
||||||
static uchar intr3Status; /* used to control interrupt endpoint transmissions */
|
static uchar intr3Status; /* used to control interrupt endpoint transmissions */
|
||||||
|
|
||||||
|
|
||||||
DigiCDCDevice::DigiCDCDevice(void){}
|
DigiCDCDevice::DigiCDCDevice(void){}
|
||||||
|
|
||||||
|
|
||||||
@ -40,23 +39,30 @@ void DigiCDCDevice::flush(){
|
|||||||
void DigiCDCDevice::begin(){
|
void DigiCDCDevice::begin(){
|
||||||
|
|
||||||
usbBegin();
|
usbBegin();
|
||||||
|
DigiCDCDevice::delay(500);//delay to allow enumeration and such
|
||||||
|
|
||||||
}
|
}
|
||||||
size_t DigiCDCDevice::write(uint8_t chr)
|
|
||||||
|
size_t DigiCDCDevice::write(uint8_t c)
|
||||||
{
|
{
|
||||||
if(RingBuffer_IsFull(&txBuf))
|
if(RingBuffer_IsFull(&txBuf))
|
||||||
{
|
{
|
||||||
|
refresh();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RingBuffer_Insert(&txBuf,chr);
|
RingBuffer_Insert(&txBuf,c);
|
||||||
|
DigiCDCDevice::delay(5); //gives 4.2-4.7ms per character for usb transfer at low speed
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DigiCDCDevice::available()
|
int DigiCDCDevice::available()
|
||||||
{
|
{
|
||||||
|
refresh();
|
||||||
return RingBuffer_GetCount(&rxBuf);
|
return RingBuffer_GetCount(&rxBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +70,15 @@ int DigiCDCDevice::read()
|
|||||||
{
|
{
|
||||||
if(RingBuffer_IsEmpty(&rxBuf))
|
if(RingBuffer_IsEmpty(&rxBuf))
|
||||||
{
|
{
|
||||||
|
refresh();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
refresh();
|
||||||
return RingBuffer_Remove(&rxBuf);
|
return RingBuffer_Remove(&rxBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DigiCDCDevice::peek()
|
int DigiCDCDevice::peek()
|
||||||
@ -82,22 +91,21 @@ int DigiCDCDevice::peek()
|
|||||||
{
|
{
|
||||||
return RingBuffer_Peek(&rxBuf);
|
return RingBuffer_Peek(&rxBuf);
|
||||||
}
|
}
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DigiCDCDevice::task(void)
|
void DigiCDCDevice::task(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
usbPollWrapper();
|
refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DigiCDCDevice::refresh(void)
|
void DigiCDCDevice::refresh(void)
|
||||||
{
|
{
|
||||||
|
_delay_ms(1);
|
||||||
usbPollWrapper();
|
usbPollWrapper();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +120,7 @@ void DigiCDCDevice::end(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DigiCDCDevice::operator bool() {
|
DigiCDCDevice::operator bool() {
|
||||||
usbPollWrapper();
|
refresh();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,4 +385,4 @@ void usbFunctionWriteOut( uchar *data, uchar len )
|
|||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DigiCDCDevice SerialUSB;
|
DigiCDCDevice SerialUSB;
|
@ -47,10 +47,6 @@ class DigiCDCDevice : public Stream {
|
|||||||
virtual int read(void);
|
virtual int read(void);
|
||||||
virtual void flush(void);
|
virtual void flush(void);
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
inline size_t write(unsigned long n) { return write((uint8_t)n); }
|
|
||||||
inline size_t write(long n) { return write((uint8_t)n); }
|
|
||||||
inline size_t write(unsigned int n) { return write((uint8_t)n); }
|
|
||||||
inline size_t write(int n) { return write((uint8_t)n); }
|
|
||||||
using Print::write;
|
using Print::write;
|
||||||
operator bool();
|
operator bool();
|
||||||
private:
|
private:
|
||||||
@ -62,4 +58,4 @@ class DigiCDCDevice : public Stream {
|
|||||||
extern DigiCDCDevice SerialUSB;
|
extern DigiCDCDevice SerialUSB;
|
||||||
|
|
||||||
|
|
||||||
#endif // __DigiCDC_h__
|
#endif // __DigiCDC_h__
|
@ -0,0 +1,22 @@
|
|||||||
|
#include <DigiCDC.h>
|
||||||
|
void setup() {
|
||||||
|
// initialize the digital pin as an output.
|
||||||
|
SerialUSB.begin();
|
||||||
|
pinMode(1,OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the loop routine runs over and over again forever:
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
//turns led on and off based on sending 0 or 1 from serial terminal
|
||||||
|
if (SerialUSB.available()) {
|
||||||
|
char input = SerialUSB.read();
|
||||||
|
if(input == '0')
|
||||||
|
digitalWrite(1,LOW);
|
||||||
|
else if(input == '1')
|
||||||
|
digitalWrite(1,HIGH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialUSB.delay(100); // keep usb alive // can alos use SerialUSB.refresh();
|
||||||
|
}
|
21
digistump-avr/libraries/DigisparkCDC/examples/Echo/Echo.ino
Normal file
21
digistump-avr/libraries/DigisparkCDC/examples/Echo/Echo.ino
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <DigiCDC.h>
|
||||||
|
void setup() {
|
||||||
|
// initialize the digital pin as an output.
|
||||||
|
SerialUSB.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
// the loop routine runs over and over again forever:
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
if (SerialUSB.available()) {
|
||||||
|
SerialUSB.write(SerialUSB.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
//SerialUSB.delay(10);
|
||||||
|
/*
|
||||||
|
if you don't call a SerialUSB function (write, print, read, available, etc)
|
||||||
|
every 10ms or less then you must throw in some SerialUSB.refresh();
|
||||||
|
for the USB to keep alive - also replace your delays - ie. delay(100);
|
||||||
|
with SerialUSB.delays ie. SerialUSB.delay(100);
|
||||||
|
*/
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
#include <DigiCDC.h>
|
||||||
|
void setup() {
|
||||||
|
// initialize the digital pin as an output.
|
||||||
|
SerialUSB.begin();
|
||||||
|
/*
|
||||||
|
remember the SerialUSB starts as soon as you call begin
|
||||||
|
and doesn't restart the board when you open the serial monitor
|
||||||
|
(like the uno does) - so if you print to it and you don't
|
||||||
|
have a serial monitor open that text is lost.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// the loop routine runs over and over again forever:
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
SerialUSB.println(F("TEST!")); //wrap your strings in F() to save ram!
|
||||||
|
|
||||||
|
//SerialUSB.delay(10);
|
||||||
|
/*
|
||||||
|
if you don't call a SerialUSB function (write, print, read, available, etc)
|
||||||
|
every 10ms or less then you must throw in some SerialUSB.refresh();
|
||||||
|
for the USB to keep alive - also replace your delays - ie. delay(100);
|
||||||
|
with SerialUSB.delays ie. SerialUSB.delay(100);
|
||||||
|
*/
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user