diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino | 4 | ||||
-rw-r--r-- | libraries/HID/HID.cpp | 26 | ||||
-rw-r--r-- | libraries/HID/HID.h | 8 | ||||
-rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.cpp | 14 | ||||
-rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.h | 5 | ||||
-rw-r--r-- | libraries/Wire/keywords.txt | 2 | ||||
-rw-r--r-- | libraries/Wire/utility/twi.c | 12 |
7 files changed, 47 insertions, 24 deletions
diff --git a/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino index 73d64a7..8b5121c 100644 --- a/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino +++ b/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -11,7 +11,9 @@ #include <EEPROM.h> void setup() { - + // initialize the LED pin as an output. + pinMode(13, OUTPUT); + /*** Iterate through each byte of the EEPROM storage. diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index 411529e..21ede26 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -54,9 +54,24 @@ int HID_::getDescriptor(USBSetup& setup) return -1; total += res; } + + // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol + // due to the USB specs, but Windows and Linux just assumes its in report mode. + protocol = HID_REPORT_PROTOCOL; + return total; } +uint8_t HID_::getShortName(char *name) +{ + name[0] = 'H'; + name[1] = 'I'; + name[2] = 'D'; + name[3] = 'A' + (descriptorSize & 0x0F); + name[4] = 'A' + ((descriptorSize >> 4) & 0x0F); + return 5; +} + void HID_::AppendDescriptor(HIDSubDescriptor *node) { if (!rootNode) { @@ -71,10 +86,13 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node) descriptorSize += node->length; } -void HID_::SendReport(uint8_t id, const void* data, int len) +int HID_::SendReport(uint8_t id, const void* data, int len) { - USB_Send(pluggedEndpoint, &id, 1); - USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len); + auto ret = USB_Send(pluggedEndpoint, &id, 1); + if (ret < 0) return ret; + auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len); + if (ret2 < 0) return ret2; + return ret + ret2; } bool HID_::setup(USBSetup& setup) @@ -130,7 +148,7 @@ bool HID_::setup(USBSetup& setup) HID_::HID_(void) : PluggableUSBModule(1, 1, epType), rootNode(NULL), descriptorSize(0), - protocol(1), idle(1) + protocol(HID_REPORT_PROTOCOL), idle(1) { epType[0] = EP_TYPE_INTERRUPT_IN; PluggableUSB().plug(this); diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index ba08da7..93c4bd5 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -54,6 +54,11 @@ #define HID_BOOT_PROTOCOL 0 #define HID_REPORT_PROTOCOL 1 +// HID Request Type HID1.11 Page 51 7.2.1 Get_Report Request +#define HID_REPORT_TYPE_INPUT 1 +#define HID_REPORT_TYPE_OUTPUT 2 +#define HID_REPORT_TYPE_FEATURE 3 + typedef struct { uint8_t len; // 9 @@ -88,7 +93,7 @@ class HID_ : public PluggableUSBModule public: HID_(void); int begin(void); - void SendReport(uint8_t id, const void* data, int len); + int SendReport(uint8_t id, const void* data, int len); void AppendDescriptor(HIDSubDescriptor* node); protected: @@ -96,6 +101,7 @@ protected: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + uint8_t getShortName(char* name); private: uint8_t epType[1]; diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 527f3f9..0a16ff7 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -57,9 +57,9 @@ volatile uint8_t SoftwareSerial::_receive_buffer_head = 0; //
// This function generates a brief pulse
// for debugging or measuring on an oscilloscope.
+#if _DEBUG
inline void DebugPulse(uint8_t pin, uint8_t count)
{
-#if _DEBUG
volatile uint8_t *pport = portOutputRegister(digitalPinToPort(pin));
uint8_t val = *pport;
@@ -68,8 +68,10 @@ inline void DebugPulse(uint8_t pin, uint8_t count) *pport = val | digitalPinToBitMask(pin);
*pport = val;
}
-#endif
}
+#else
+inline void DebugPulse(uint8_t, uint8_t) {}
+#endif
//
// Private methods
@@ -467,13 +469,7 @@ size_t SoftwareSerial::write(uint8_t b) void SoftwareSerial::flush()
{
- if (!isListening())
- return;
-
- uint8_t oldSREG = SREG;
- cli();
- _receive_buffer_head = _receive_buffer_tail = 0;
- SREG = oldSREG;
+ // There is no tx buffering, simply return
}
int SoftwareSerial::peek()
diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index 274f3df..622e2a5 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -72,12 +72,11 @@ private: static SoftwareSerial *active_object;
// private methods
- void recv() __attribute__((__always_inline__));
+ inline void recv() __attribute__((__always_inline__));
uint8_t rx_pin_read();
- void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__));
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
- void setRxIntMsk(bool enable) __attribute__((__always_inline__));
+ inline void setRxIntMsk(bool enable) __attribute__((__always_inline__));
// Return num - sub, or 1 if the result would be < 1
static uint16_t subtract_cap(uint16_t num, uint16_t sub);
diff --git a/libraries/Wire/keywords.txt b/libraries/Wire/keywords.txt index ff31475..5e3d2b1 100644 --- a/libraries/Wire/keywords.txt +++ b/libraries/Wire/keywords.txt @@ -15,8 +15,6 @@ setClock KEYWORD2 beginTransmission KEYWORD2 endTransmission KEYWORD2 requestFrom KEYWORD2 -send KEYWORD2 -receive KEYWORD2 onReceive KEYWORD2 onRequest KEYWORD2 diff --git a/libraries/Wire/utility/twi.c b/libraries/Wire/utility/twi.c index b436e69..2af0597 100644 --- a/libraries/Wire/utility/twi.c +++ b/libraries/Wire/utility/twi.c @@ -167,7 +167,9 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen // up. Also, don't enable the START interrupt. There may be one pending from the // repeated start that we sent outselves, and that would really confuse things. twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR - TWDR = twi_slarw; + do { + TWDR = twi_slarw; + } while(TWCR & _BV(TWWC)); TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START } else @@ -247,7 +249,9 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait // up. Also, don't enable the START interrupt. There may be one pending from the // repeated start that we sent outselves, and that would really confuse things. twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR - TWDR = twi_slarw; + do { + TWDR = twi_slarw; + } while(TWCR & _BV(TWWC)); TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START } else @@ -476,6 +480,8 @@ ISR(TWI_vect) } break; case TW_SR_STOP: // stop or repeated start condition received + // ack future responses and leave slave receiver state + twi_releaseBus(); // put a null char after data if there's room if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){ twi_rxBuffer[twi_rxBufferIndex] = '\0'; @@ -484,8 +490,6 @@ ISR(TWI_vect) twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex); // since we submit rx buffer to "wire" library, we can reset it twi_rxBufferIndex = 0; - // ack future responses and leave slave receiver state - twi_releaseBus(); break; case TW_SR_DATA_NACK: // data received, returned nack case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack |