From 8fe8470067c91c7cc96a4d0f44044e0a6d2f1fd8 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 5 Dec 2019 11:13:27 -0800 Subject: [PATCH] Blindly pull all plugins up to current --- avr/libraries/Kaleidoscope | 2 +- virtual/cores/virtual/Arduino.h | 36 +++- virtual/cores/virtual/EEPROM.h | 241 ++++++++++++++++--------- virtual/cores/virtual/PluggableUSB.h | 76 ++++---- virtual/cores/virtual/main.cpp | 22 +-- virtual/cores/virtual/mcu/atmega32u4.h | 4 +- virtual/cores/virtual/virtual_io.cpp | 2 +- 7 files changed, 233 insertions(+), 150 deletions(-) diff --git a/avr/libraries/Kaleidoscope b/avr/libraries/Kaleidoscope index 54ec4d6..eb52795 160000 --- a/avr/libraries/Kaleidoscope +++ b/avr/libraries/Kaleidoscope @@ -1 +1 @@ -Subproject commit 54ec4d63cf214db6d73245d5aa4cb98d78d46f79 +Subproject commit eb52795c799e5da66c6b45965b2281c7dd374662 diff --git a/virtual/cores/virtual/Arduino.h b/virtual/cores/virtual/Arduino.h index 77362fe..1f303d0 100644 --- a/virtual/cores/virtual/Arduino.h +++ b/virtual/cores/virtual/Arduino.h @@ -282,15 +282,33 @@ long map(long, long, long, long, long); #ifdef __cplusplus // Not sure if these are acceptable substitute definitions in our context or not -inline uint8_t pgm_read_byte_near(const uint8_t *addr) { return *addr; } -inline int8_t pgm_read_byte_near(const int8_t *addr) { return *addr; } -inline char pgm_read_byte_near(const char *addr) { return *addr; } -inline uint16_t pgm_read_word_near(const uint16_t *addr) { return *addr; } -inline int16_t pgm_read_word_near(const int16_t *addr) { return *addr; } -inline uint32_t pgm_read_dword_near(const uint32_t *addr) { return *addr; } -inline int32_t pgm_read_dword_near(const int32_t *addr) { return *addr; } -inline float pgm_read_float_near(const float *addr) { return *addr; } -inline const void *pgm_read_ptr_near(const void **addr) { return *addr; } +inline uint8_t pgm_read_byte_near(const uint8_t *addr) { + return *addr; +} +inline int8_t pgm_read_byte_near(const int8_t *addr) { + return *addr; +} +inline char pgm_read_byte_near(const char *addr) { + return *addr; +} +inline uint16_t pgm_read_word_near(const uint16_t *addr) { + return *addr; +} +inline int16_t pgm_read_word_near(const int16_t *addr) { + return *addr; +} +inline uint32_t pgm_read_dword_near(const uint32_t *addr) { + return *addr; +} +inline int32_t pgm_read_dword_near(const int32_t *addr) { + return *addr; +} +inline float pgm_read_float_near(const float *addr) { + return *addr; +} +inline const void *pgm_read_ptr_near(const void **addr) { + return *addr; +} #else #define pgm_read_byte_near(addr) (*(const byte*)(addr)) #define pgm_read_word_near(addr) (*(const word*)(addr)) diff --git a/virtual/cores/virtual/EEPROM.h b/virtual/cores/virtual/EEPROM.h index 07e5690..d9a3d6d 100644 --- a/virtual/cores/virtual/EEPROM.h +++ b/virtual/cores/virtual/EEPROM.h @@ -29,121 +29,186 @@ /*** EERef class. - + This object references an EEPROM cell. Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM. This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell. ***/ -struct EERef{ +struct EERef { - EERef( const int index ) - : index( index ) {} - - //Access/read members. - uint8_t operator*() const { return eeprom_[index]; } - operator uint8_t() const { return **this; } - - //Assignment/write members. - EERef &operator=( const EERef &ref ) { return *this = *ref; } - EERef &operator=( uint8_t in ) { eeprom_[index] = in; return *this; } - EERef &operator +=( uint8_t in ) { return *this = **this + in; } - EERef &operator -=( uint8_t in ) { return *this = **this - in; } - EERef &operator *=( uint8_t in ) { return *this = **this * in; } - EERef &operator /=( uint8_t in ) { return *this = **this / in; } - EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; } - EERef &operator %=( uint8_t in ) { return *this = **this % in; } - EERef &operator &=( uint8_t in ) { return *this = **this & in; } - EERef &operator |=( uint8_t in ) { return *this = **this | in; } - EERef &operator <<=( uint8_t in ) { return *this = **this << in; } - EERef &operator >>=( uint8_t in ) { return *this = **this >> in; } - - EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; } - - /** Prefix increment/decrement **/ - EERef& operator++() { return *this += 1; } - EERef& operator--() { return *this -= 1; } - - /** Postfix increment/decrement **/ - uint8_t operator++ (int){ - uint8_t ret = **this; - return ++(*this), ret; - } + EERef(const int index) + : index(index) {} - uint8_t operator-- (int){ - uint8_t ret = **this; - return --(*this), ret; - } - - int index; //Index of current EEPROM cell. - - static uint8_t eeprom_[kaleidoscope::hardware::mcu::eeprom_size]; + //Access/read members. + uint8_t operator*() const { + return eeprom_[index]; + } + operator uint8_t() const { + return **this; + } + + //Assignment/write members. + EERef &operator=(const EERef &ref) { + return *this = *ref; + } + EERef &operator=(uint8_t in) { + eeprom_[index] = in; + return *this; + } + EERef &operator +=(uint8_t in) { + return *this = **this + in; + } + EERef &operator -=(uint8_t in) { + return *this = **this - in; + } + EERef &operator *=(uint8_t in) { + return *this = **this * in; + } + EERef &operator /=(uint8_t in) { + return *this = **this / in; + } + EERef &operator ^=(uint8_t in) { + return *this = **this ^ in; + } + EERef &operator %=(uint8_t in) { + return *this = **this % in; + } + EERef &operator &=(uint8_t in) { + return *this = **this & in; + } + EERef &operator |=(uint8_t in) { + return *this = **this | in; + } + EERef &operator <<=(uint8_t in) { + return *this = **this << in; + } + EERef &operator >>=(uint8_t in) { + return *this = **this >> in; + } + + EERef &update(uint8_t in) { + return in != *this ? *this = in : *this; + } + + /** Prefix increment/decrement **/ + EERef& operator++() { + return *this += 1; + } + EERef& operator--() { + return *this -= 1; + } + + /** Postfix increment/decrement **/ + uint8_t operator++ (int) { + uint8_t ret = **this; + return ++(*this), ret; + } + + uint8_t operator-- (int) { + uint8_t ret = **this; + return --(*this), ret; + } + + int index; //Index of current EEPROM cell. + + static uint8_t eeprom_[kaleidoscope::hardware::mcu::eeprom_size]; }; /*** EEPtr class. - + This object is a bidirectional pointer to EEPROM cells represented by EERef objects. - Just like a normal pointer type, this can be dereferenced and repositioned using + Just like a normal pointer type, this can be dereferenced and repositioned using increment/decrement operators. ***/ -struct EEPtr{ +struct EEPtr { - EEPtr( const int index ) - : index( index ) {} - - operator int() const { return index; } - EEPtr &operator=( int in ) { return index = in, *this; } - - //Iterator functionality. - bool operator!=( const EEPtr &ptr ) { return index != ptr.index; } - EERef operator*() { return index; } - - /** Prefix & Postfix increment/decrement **/ - EEPtr& operator++() { return ++index, *this; } - EEPtr& operator--() { return --index, *this; } - EEPtr operator++ (int) { return index++; } - EEPtr operator-- (int) { return index--; } + EEPtr(const int index) + : index(index) {} - int index; //Index of current EEPROM cell. + operator int() const { + return index; + } + EEPtr &operator=(int in) { + return index = in, *this; + } + + //Iterator functionality. + bool operator!=(const EEPtr &ptr) { + return index != ptr.index; + } + EERef operator*() { + return index; + } + + /** Prefix & Postfix increment/decrement **/ + EEPtr& operator++() { + return ++index, *this; + } + EEPtr& operator--() { + return --index, *this; + } + EEPtr operator++ (int) { + return index++; + } + EEPtr operator-- (int) { + return index--; + } + + int index; //Index of current EEPROM cell. }; /*** EEPROMClass class. - + This object represents the entire EEPROM space. It wraps the functionality of EEPtr and EERef into a basic interface. This class is also 100% backwards compatible with earlier Arduino core releases. ***/ -struct EEPROMClass{ +struct EEPROMClass { - //Basic user access methods. - EERef operator[]( const int idx ) { return idx; } - uint8_t read( int idx ) { return EERef( idx ); } - void write( int idx, uint8_t val ) { (EERef( idx )) = val; } - void update( int idx, uint8_t val ) { EERef( idx ).update( val ); } - - //STL and C++11 iteration capability. - EEPtr begin() { return 0x00; } - EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. - uint16_t length() { return kaleidoscope::hardware::mcu::eeprom_size; } - - //Functionality to 'get' and 'put' objects to and from EEPROM. - template< typename T > T &get( int idx, T &t ){ - EEPtr e = idx; - uint8_t *ptr = (uint8_t*) &t; - for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e; - return t; - } - - template< typename T > const T &put( int idx, const T &t ){ - EEPtr e = idx; - const uint8_t *ptr = (const uint8_t*) &t; - for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ ); - return t; - } + //Basic user access methods. + EERef operator[](const int idx) { + return idx; + } + uint8_t read(int idx) { + return EERef(idx); + } + void write(int idx, uint8_t val) { + (EERef(idx)) = val; + } + void update(int idx, uint8_t val) { + EERef(idx).update(val); + } + + //STL and C++11 iteration capability. + EEPtr begin() { + return 0x00; + } + EEPtr end() { + return length(); //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. + } + uint16_t length() { + return kaleidoscope::hardware::mcu::eeprom_size; + } + + //Functionality to 'get' and 'put' objects to and from EEPROM. + template< typename T > T &get(int idx, T &t) { + EEPtr e = idx; + uint8_t *ptr = (uint8_t*) &t; + for (int count = sizeof(T) ; count ; --count, ++e) *ptr++ = *e; + return t; + } + + template< typename T > const T &put(int idx, const T &t) { + EEPtr e = idx; + const uint8_t *ptr = (const uint8_t*) &t; + for (int count = sizeof(T) ; count ; --count, ++e)(*e).update(*ptr++); + return t; + } }; extern EEPROMClass EEPROM; diff --git a/virtual/cores/virtual/PluggableUSB.h b/virtual/cores/virtual/PluggableUSB.h index fafec09..51a6a25 100644 --- a/virtual/cores/virtual/PluggableUSB.h +++ b/virtual/cores/virtual/PluggableUSB.h @@ -36,53 +36,53 @@ struct EndpointDescriptor { struct USBSetup; class PluggableUSBModule { - public: - PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : - numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) - { } + public: + PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : + numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) + { } - protected: - virtual bool setup(USBSetup &setup) = 0; - virtual int getInterface(uint8_t *interfaceCount) = 0; - virtual int getDescriptor(USBSetup &setup) = 0; - virtual uint8_t getShortName(char *name) { - name[0] = 'A'+pluggedInterface; - return 1; - } + protected: + virtual bool setup(USBSetup &setup) = 0; + virtual int getInterface(uint8_t *interfaceCount) = 0; + virtual int getDescriptor(USBSetup &setup) = 0; + virtual uint8_t getShortName(char *name) { + name[0] = 'A' + pluggedInterface; + return 1; + } - uint8_t pluggedInterface = 0; - uint8_t pluggedEndpoint; + uint8_t pluggedInterface = 0; + uint8_t pluggedEndpoint; - const uint8_t numEndpoints; - const uint8_t numInterfaces; - const uint8_t *endpointType; + const uint8_t numEndpoints; + const uint8_t numInterfaces; + const uint8_t *endpointType; - PluggableUSBModule *next = nullptr; + PluggableUSBModule *next = nullptr; - friend class PluggableUSB_; + friend class PluggableUSB_; }; class PluggableUSB_ { - public: - PluggableUSB_() {} - bool plug(PluggableUSBModule *node) { - return true; - } - int getInterface(uint8_t *interfaceCount) { - return 1; - } - int getDescriptor(USBSetup &setup) { - return 1; - } - bool setup(USBSetup &setup) { - return true; - } - void getShortName(char *iSerialNum) {} + public: + PluggableUSB_() {} + bool plug(PluggableUSBModule *node) { + return true; + } + int getInterface(uint8_t *interfaceCount) { + return 1; + } + int getDescriptor(USBSetup &setup) { + return 1; + } + bool setup(USBSetup &setup) { + return true; + } + void getShortName(char *iSerialNum) {} - private: - uint8_t lastIf; - uint8_t lastEp; - PluggableUSBModule *rootNode; + private: + uint8_t lastIf; + uint8_t lastEp; + PluggableUSBModule *rootNode; }; // Replacement for global singleton. diff --git a/virtual/cores/virtual/main.cpp b/virtual/cores/virtual/main.cpp index a744f72..a5870a4 100644 --- a/virtual/cores/virtual/main.cpp +++ b/virtual/cores/virtual/main.cpp @@ -44,18 +44,18 @@ void init(void) { } int main(int argc, char* argv[]) { - - // Enable consumer code to read command line args. - // - parseCommandLine(argc, argv); - + + // Enable consumer code to read command line args. + // + parseCommandLine(argc, argv); + if (!initVirtualInput(argc, argv)) return 1; - - if(testFunctionExecutionRequested()) { - if(executeTestFunction) { - executeTestFunction(); - } - return 0; + + if (testFunctionExecutionRequested()) { + if (executeTestFunction) { + executeTestFunction(); + } + return 0; } init(); diff --git a/virtual/cores/virtual/mcu/atmega32u4.h b/virtual/cores/virtual/mcu/atmega32u4.h index 7133c9c..6f5b675 100644 --- a/virtual/cores/virtual/mcu/atmega32u4.h +++ b/virtual/cores/virtual/mcu/atmega32u4.h @@ -24,9 +24,9 @@ namespace mcus { class atmega32u4 { - public: + public: - static constexpr int eeprom_size = 1024; + static constexpr int eeprom_size = 1024; }; } // namespace mcus diff --git a/virtual/cores/virtual/virtual_io.cpp b/virtual/cores/virtual/virtual_io.cpp index 9cd2f1d..c23c262 100644 --- a/virtual/cores/virtual/virtual_io.cpp +++ b/virtual/cores/virtual/virtual_io.cpp @@ -63,7 +63,7 @@ bool initVirtualInput(int argc, char* argv[]) { if (strcmp(argv[1], "-i") == 0) { interactive = true; input = &std::cin; - } else if(strcmp(argv[1], "-t") == 0) { + } else if (strcmp(argv[1], "-t") == 0) { test_function = true; } else { interactive = false;