From 9e6f65ca9d145846d1f7a46636c932ea3009806d Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 10 Apr 2019 20:58:16 +0200 Subject: [PATCH 1/2] Code maintenance --- .mystools/README.md | 2 +- core/MySensorsCore.cpp | 52 +++++++++++++-------- core/MySensorsCore.h | 25 ++++++++-- core/MySigning.h | 2 +- core/MyTransport.cpp | 8 ++-- core/MyTransport.h | 51 ++++++++++---------- hal/architecture/AVR/MyHwAVR.cpp | 1 - hal/architecture/ESP8266/MyHwESP8266.cpp | 1 - hal/architecture/ESP8266/MyHwESP8266.h | 1 + hal/architecture/Linux/MyHwLinuxGeneric.cpp | 10 ---- hal/architecture/Linux/MyHwLinuxGeneric.h | 9 ++++ hal/architecture/MyHwHAL.h | 6 +++ hal/architecture/NRF5/MyHwNRF5.cpp | 5 -- hal/architecture/SAMD/MyHwSAMD.h | 3 +- hal/architecture/Teensy3/MyHwTeensy3.h | 2 +- 15 files changed, 102 insertions(+), 76 deletions(-) diff --git a/.mystools/README.md b/.mystools/README.md index 19a674251..fc002ffe5 100644 --- a/.mystools/README.md +++ b/.mystools/README.md @@ -4,7 +4,7 @@ This directory hosts MySensors development tools. The following conventions are employed to facilitate consistent re-use/invocation -across modalitiies (e.g. local development, continuous integration, +across modalities (e.g. local development, continuous integration, editor linters, etc.) 1. All common tools are hosted and managed in diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 9ecbbfee3..0cfe219ad 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -19,16 +19,11 @@ #include "MySensorsCore.h" -#if defined(__linux__) -#include -#include -#endif - // debug output #if defined(MY_DEBUG_VERBOSE_CORE) #define CORE_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) //!< debug #else -#define CORE_DEBUG(x,...) //!< debug NULL +#define CORE_DEBUG(x,...) //!< debug NULL #endif // message buffers @@ -44,7 +39,7 @@ static uint8_t waitLock = 0; #endif #if defined(DEBUG_OUTPUT_ENABLED) -char _convBuf[MAX_PAYLOAD*2+1]; +char _convBuf[MAX_PAYLOAD * 2 + 1]; #endif // Callback for transport=ok transition @@ -83,12 +78,13 @@ void _process(void) void _infiniteLoop(void) { +#if defined(__linux__) + exit(1); +#else while(1) { doYield(); -#if defined(__linux__) - exit(1); -#endif } +#endif } void _begin(void) @@ -117,7 +113,7 @@ void _begin(void) #if defined(F_CPU) CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=%" PRIu16 ",REL=%" PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000), + MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000UL), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #else CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=NA,REL=%" @@ -147,7 +143,7 @@ void _begin(void) // Read latest received controller configuration from EEPROM // Note: _coreConfig.isMetric is bool, hence empty EEPROM (=0xFF) evaluates to true (default) - hwReadConfigBlock((void*)&_coreConfig.controllerConfig, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, + hwReadConfigBlock((void *)&_coreConfig.controllerConfig, (void *)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(controllerConfig_t)); #if defined(MY_OTA_FIRMWARE_FEATURE) @@ -309,15 +305,13 @@ bool _sendRoute(MyMessage &message) { #if defined(MY_CORE_ONLY) (void)message; -#endif -#if defined(MY_GATEWAY_FEATURE) +#elif defined(MY_GATEWAY_FEATURE) if (message.destination == getNodeId()) { // This is a message sent from a sensor attached on the gateway node. // Pass it directly to the gateway transport layer. return gatewayTransportSend(message); } -#endif -#if defined(MY_SENSOR_NETWORK) +#elif defined(MY_SENSOR_NETWORK) return transportSendRoute(message); #else return false; @@ -560,6 +554,28 @@ void wait(const uint32_t waitingMS) #endif } +bool wait(const uint32_t waitingMS, const uint8_t cmd) +{ +#if defined(MY_DEBUG_VERBOSE_CORE) + if (waitLock) { + CORE_DEBUG(PSTR("!MCO:WAI:RC=%" PRIu8 "\n"), waitLock); // recursive call detected + } + waitLock++; +#endif + const uint32_t enteringMS = hwMillis(); + // invalidate cmd + mSetCommand(_msg, !cmd); + bool expectedResponse = false; + while ((hwMillis() - enteringMS < waitingMS) && !expectedResponse) { + _process(); + expectedResponse = (mGetCommand(_msg) == cmd); + } +#if defined(MY_DEBUG_VERBOSE_CORE) + waitLock--; +#endif + return expectedResponse; +} + bool wait(const uint32_t waitingMS, const uint8_t cmd, const uint8_t msgType) { #if defined(MY_DEBUG_VERBOSE_CORE) @@ -585,9 +601,7 @@ bool wait(const uint32_t waitingMS, const uint8_t cmd, const uint8_t msgType) void doYield(void) { hwWatchdogReset(); - yield(); - #if defined (MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN) ledsProcess(); #endif @@ -740,7 +754,7 @@ int8_t smartSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t i -void _nodeLock(const char* str) +void _nodeLock(const char *str) { #ifdef MY_NODE_LOCK_FEATURE // Make sure EEPROM is updated to locked status diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index 0a9cf40e1..93604036d 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -51,16 +51,15 @@ * |!| MCO | SND | NODE NOT REG | Node is not registered, cannot send message * | | MCO | PIM | NODE REG=%%d | Registration response received, registration status (REG) * |!| MCO | WAI | RC=%%d | Recursive call detected in wait(), level (RC) -* | | MCO | SLP | MS=%%lu,SMS=%%d,I1=%%d,M1=%%d,I2=%%d,M2=%%d | Sleep node, time (MS), smartSleep (SMS), Int1/M1, Int2/M2 +* | | MCO | SLP | MS=%%lu,SMS=%%d,I1=%%d,M1=%%d,I2=%%d,M2=%%d | Sleep node, time (MS), smartSleep (SMS), Int1 (I1), Mode1 (M1), Int2 (I2), Mode2 (M2) * | | MCO | SLP | WUP=%%d | Node woke-up, reason/IRQ (WUP) * |!| MCO | SLP | NTL | Sleeping not possible, no time left * |!| MCO | SLP | FWUPD | Sleeping not possible, FW update ongoing * |!| MCO | SLP | REP | Sleeping not possible, repeater feature enabled -* |!| MCO | SLP | TNR | Transport not ready, attempt to reconnect until timeout (MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS) +* |!| MCO | SLP | TNR | Transport not ready, attempt to reconnect until timeout (@ref MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS) * | | MCO | NLK | NODE LOCKED. UNLOCK: GND PIN %%d AND RESET | Node locked during booting, see signing chapter for additional information * | | MCO | NLK | TSL | Set transport to sleep * -* * @brief API declaration for MySensorsCore */ @@ -68,13 +67,18 @@ #ifndef MySensorsCore_h #define MySensorsCore_h -#include "Version.h" // Auto generated by bot +#include "Version.h" #include "MyConfig.h" #include "MyEepromAddresses.h" #include "MyMessage.h" #include #include +#if defined(__linux__) +#include +#include +#endif + #define GATEWAY_ADDRESS ((uint8_t)0) //!< Node ID for GW sketch #define NODE_SENSOR_ID ((uint8_t)255) //!< Node child is always created/presented when a node is started #define MY_CORE_VERSION ((uint8_t)2) //!< core version @@ -249,6 +253,17 @@ uint8_t loadState(const uint8_t pos); */ void wait(const uint32_t waitingMS); +/** + * Wait for a specified amount of time to pass or until specified message received. Keeps process()ing. + * This does not power-down the radio nor the Arduino. + * Because this calls process() in a loop, it is a good way to wait + * in your loop() on a repeater node or sensor that listens to messages. + * @param waitingMS Number of milliseconds to wait. + * @param cmd Command of incoming message. + * @return True if specified message received + */ +bool wait(const uint32_t waitingMS, const uint8_t cmd); + /** * Wait for a specified amount of time to pass or until specified message received. Keeps process()ing. * This does not power-down the radio nor the Arduino. @@ -372,7 +387,7 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep = false, * * @param str The string to transmit. */ -void _nodeLock(const char* str); +void _nodeLock(const char *str); /** * @brief Check node lock status and prevent node execution if locked. diff --git a/core/MySigning.h b/core/MySigning.h index 4b79a1763..ecc9717c6 100644 --- a/core/MySigning.h +++ b/core/MySigning.h @@ -765,7 +765,7 @@ int signerMemcmp(const void* a, const void* b, size_t sz); * | | SGN | PRE | SGN NREQ,FROM='node' | Node 'node' does not require signing * |!| SGN | PRE | SGN NREQ,FROM='node' REJ | Node 'node' does not require signing but used to (requirement remain unchanged) * | | SGN | PRE | WHI REQ | Whitelisting required - * | | SGN | PRE | WHI REQ;TO='node' | Tell 'node' that we require whitelisting + * | | SGN | PRE | WHI REQ,TO='node' | Tell 'node' that we require whitelisting * | | SGN | PRE | WHI REQ,FROM='node' | Node 'node' require whitelisting * | | SGN | PRE | WHI NREQ | Whitelisting not required * | | SGN | PRE | WHI NREQ,TO='node' | Tell 'node' that we do not require whitelisting diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index f97a2117c..2de81a9b8 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -648,8 +648,8 @@ void transportProcessMessage(void) (void)signerCheckTimer(); // receive message setIndication(INDICATION_RX); - uint8_t payloadLength = transportReceive((uint8_t *) - &_msg.last); // last is the first byte of the payload buffer + // last is the first byte of the payload buffer + uint8_t payloadLength = transportReceive((uint8_t *)&_msg.last); // get message length and limit size const uint8_t msgLength = min(mGetLength(_msg), (uint8_t)MAX_PAYLOAD); // calculate expected length @@ -722,8 +722,8 @@ void transportProcessMessage(void) if (mGetRequestAck(_msg)) { TRANSPORT_DEBUG(PSTR("TSF:MSG:ACK REQ\n")); // ACK requested _msgTmp = _msg; // Copy message - mSetRequestAck(_msgTmp, - false); // Reply without ack flag (otherwise we would end up in an eternal loop) + // Reply without ack flag (otherwise we would end up in an eternal loop) + mSetRequestAck(_msgTmp, false); mSetAck(_msgTmp, true); // set ACK flag _msgTmp.sender = _transportConfig.nodeId; _msgTmp.destination = sender; diff --git a/core/MyTransport.h b/core/MyTransport.h index b5bad93d1..00ade072b 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -192,13 +192,13 @@ #define MY_TRANSPORT_STATE_RETRIES (3u) //!< retries before switching to FAILURE #endif -#define AUTO (255u) //!< ID 255 is reserved +#define AUTO (255u) //!< ID 255 is reserved #define BROADCAST_ADDRESS (255u) //!< broadcasts are addressed to ID 255 #define DISTANCE_INVALID (255u) //!< invalid distance when searching for parent -#define MAX_HOPS (254u) //!< maximal number of hops for ping/pong -#define INVALID_HOPS (255u) //!< invalid hops -#define MAX_SUBSEQ_MSGS (5u) //!< Maximum number of subsequently processed messages in FIFO (to prevent transport deadlock if HW issue) -#define UPLINK_QUALITY_WEIGHT (0.05f) //!< UPLINK_QUALITY_WEIGHT +#define MAX_HOPS (254u) //!< maximal number of hops for ping/pong +#define INVALID_HOPS (255u) //!< invalid hops +#define MAX_SUBSEQ_MSGS (5u) //!< Maximum number of subsequently processed messages in FIFO (to prevent transport deadlock if HW issue) +#define UPLINK_QUALITY_WEIGHT (0.05f) //!< UPLINK_QUALITY_WEIGHT // parent node check @@ -222,10 +222,10 @@ typedef void(*transportCallback_t)(void); */ typedef struct { uint8_t nodeId; //!< Current node id - uint8_t parentNodeId; //!< Where this node sends its messages - uint8_t distanceGW; //!< This nodes distance to sensor net gateway (number of hops) - uint8_t passiveMode : 1; //!< Passive mode - uint8_t reserved : 7; //!< Reserved + uint8_t parentNodeId; //!< Where this node sends its messages + uint8_t distanceGW; //!< This nodes distance to sensor net gateway (number of hops) + uint8_t passiveMode : 1; //!< Passive mode + uint8_t reserved : 7; //!< Reserved } transportConfig_t; /** @@ -243,8 +243,8 @@ typedef struct { typedef int16_t transportRSSI_t; //!< Datatype for internal RSSI storage // helper macro for conversion -#define transportInternalToRSSI(__value) ((int16_t)__value>>4) //!< Convert internal RSSI to RSSI -#define transportRSSItoInternal(__value) ((transportRSSI_t)__value<<4) //!< Convert RSSI to internal RSSI +#define transportInternalToRSSI(__value) ((int16_t)__value >> 4) //!< Convert internal RSSI to RSSI +#define transportRSSItoInternal(__value) ((transportRSSI_t)__value << 4) //!< Convert RSSI to internal RSSI /** * @brief Status variables and SM state @@ -253,31 +253,30 @@ typedef int16_t transportRSSI_t; //!< Datatype for internal RSSI storage */ typedef struct { // SM variables - transportState_t *currentState; //!< pointer to current FSM state - uint32_t stateEnter; //!< state enter timepoint + transportState_t *currentState; //!< pointer to current FSM state + uint32_t stateEnter; //!< state enter timepoint // general transport variables - uint32_t lastUplinkCheck; //!< last uplink check, required to prevent GW flooding + uint32_t lastUplinkCheck; //!< last uplink check, required to prevent GW flooding // 8 bits - bool findingParentNode : 1; //!< flag finding parent node is active - bool preferredParentFound : 1; //!< flag preferred parent found - bool uplinkOk : 1; //!< flag uplink ok - bool pingActive : 1; //!< flag ping active - bool transportActive : 1; //!< flag transport active - uint8_t stateRetries : 3; //!< retries / state re-enter (max 7) + bool findingParentNode : 1; //!< flag finding parent node is active + bool preferredParentFound : 1; //!< flag preferred parent found + bool uplinkOk : 1; //!< flag uplink ok + bool pingActive : 1; //!< flag ping active + bool transportActive : 1; //!< flag transport active + uint8_t stateRetries : 3; //!< retries / state re-enter (max 7) // 8 bits uint8_t failedUplinkTransmissions : 4; //!< counter failed uplink transmissions (max 15) - uint8_t failureCounter : 3; //!< counter for TSM failures (max 7) - bool msgReceived : 1; //!< flag message received - - uint8_t pingResponse; //!< stores I_PONG hops - transportRSSI_t uplinkQualityRSSI; //!< Uplink quality, internal RSSI representation + uint8_t failureCounter : 3; //!< counter for TSM failures (max 7) + bool msgReceived : 1; //!< flag message received + uint8_t pingResponse; //!< stores I_PONG hops + transportRSSI_t uplinkQualityRSSI; //!< Uplink quality, internal RSSI representation } transportSM_t; /** * @brief RAM routing table */ typedef struct { - uint8_t route[SIZE_ROUTES]; //!< route for node + uint8_t route[SIZE_ROUTES]; //!< route for node } routingTable_t; // PRIVATE functions diff --git a/hal/architecture/AVR/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp index 28fc7f983..ad5c53198 100644 --- a/hal/architecture/AVR/MyHwAVR.cpp +++ b/hal/architecture/AVR/MyHwAVR.cpp @@ -31,7 +31,6 @@ bool hwInit(void) } #define WDTO_SLEEP_FOREVER (0xFFu) -#define INVALID_INTERRUPT_NUM (0xFFu) volatile uint8_t _wokeUpByInterrupt = INVALID_INTERRUPT_NUM; // Interrupt number that woke the mcu. diff --git a/hal/architecture/ESP8266/MyHwESP8266.cpp b/hal/architecture/ESP8266/MyHwESP8266.cpp index a391d5c2c..75a149b53 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.cpp +++ b/hal/architecture/ESP8266/MyHwESP8266.cpp @@ -18,7 +18,6 @@ */ #include "MyHwESP8266.h" -#include bool hwInit(void) { diff --git a/hal/architecture/ESP8266/MyHwESP8266.h b/hal/architecture/ESP8266/MyHwESP8266.h index 97e095977..85eea61c7 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.h +++ b/hal/architecture/ESP8266/MyHwESP8266.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef __cplusplus #include diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.cpp b/hal/architecture/Linux/MyHwLinuxGeneric.cpp index 4c09a6169..351d248b1 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.cpp +++ b/hal/architecture/Linux/MyHwLinuxGeneric.cpp @@ -19,16 +19,6 @@ #include "MyHwLinuxGeneric.h" -#include -#include -#include -#include -#include -#include -#include "SoftEeprom.h" -#include "log.h" -#include "config.h" - static SoftEeprom eeprom; static FILE *randomFp = NULL; diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.h b/hal/architecture/Linux/MyHwLinuxGeneric.h index 2ef0f961d..53e8e7fed 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.h +++ b/hal/architecture/Linux/MyHwLinuxGeneric.h @@ -25,6 +25,15 @@ #include "SerialPort.h" #include "StdInOutStream.h" #include +#include +#include +#include +#include +#include +#include +#include "SoftEeprom.h" +#include "log.h" +#include "config.h" #define CRYPTO_LITTLE_ENDIAN diff --git a/hal/architecture/MyHwHAL.h b/hal/architecture/MyHwHAL.h index 68aca1e65..7bddb0d01 100644 --- a/hal/architecture/MyHwHAL.h +++ b/hal/architecture/MyHwHAL.h @@ -26,6 +26,12 @@ #ifndef MyHwHAL_h #define MyHwHAL_h +/** +* @def INVALID_INTERRUPT_NUM +* @brief Invalid interrupt +*/ +#define INVALID_INTERRUPT_NUM (0xFFu) + /** * @def MY_HWID_PADDING_BYTE * @brief HwID padding byte diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp index 7988ef174..c1122716c 100644 --- a/hal/architecture/NRF5/MyHwNRF5.cpp +++ b/hal/architecture/NRF5/MyHwNRF5.cpp @@ -21,11 +21,6 @@ */ #include "MyHwNRF5.h" -#include - -#define CRYPTO_LITTLE_ENDIAN - -#define INVALID_INTERRUPT_NUM (0xFFu) volatile uint8_t _wokeUpByInterrupt = INVALID_INTERRUPT_NUM; // Interrupt number that woke the mcu. volatile uint8_t _wakeUp1Interrupt = diff --git a/hal/architecture/SAMD/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h index fd67ef069..ecaf83907 100644 --- a/hal/architecture/SAMD/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.h @@ -20,13 +20,12 @@ #define MyHwSAMD_h #include +#include #ifdef __cplusplus #include #endif -#include - #define CRYPTO_LITTLE_ENDIAN #ifndef MY_SERIALDEVICE diff --git a/hal/architecture/Teensy3/MyHwTeensy3.h b/hal/architecture/Teensy3/MyHwTeensy3.h index 4cf1e27d8..eef400c7a 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.h +++ b/hal/architecture/Teensy3/MyHwTeensy3.h @@ -29,11 +29,11 @@ #define MyHwTeensy3_h #include +#include "util/atomic.h" #ifdef __cplusplus #include #endif -#include "util/atomic.h" #define CRYPTO_LITTLE_ENDIAN From ca1624578763340c8d3c80774190817ae1575366 Mon Sep 17 00:00:00 2001 From: Olivier Date: Thu, 11 Apr 2019 10:43:55 +0200 Subject: [PATCH 2/2] Code maintenance --- .ci/doxygen.groovy | 2 +- MyConfig.h | 1 - MySensors.h | 1 + configure | 13 +- core/MySensorsCore.cpp | 3 +- core/MySensorsCore.h | 7 +- .../AVR/drivers/DigitalIO/DigitalIO.h | 4 +- .../AVR/drivers/DigitalIO/DigitalPin.h | 685 +++++++----------- .../AVR/drivers/DigitalIO/I2cConstants.h | 3 +- .../AVR/drivers/DigitalIO/PinIO.cpp | 14 +- .../AVR/drivers/DigitalIO/PinIO.h | 85 +-- .../AVR/drivers/DigitalIO/SoftI2cMaster.cpp | 9 +- .../AVR/drivers/DigitalIO/SoftI2cMaster.h | 67 +- .../AVR/drivers/DigitalIO/SoftSPI.h | 33 +- .../AVR/drivers/DigitalIO/attic/ADS7818.h | 140 ---- .../AVR/drivers/DigitalIO/attic/MCP320X.h | 305 -------- .../AVR/drivers/DigitalIO/attic/MCP355X.h | 153 ---- .../boards/AvrDevelopersGpioPinMap.h | 37 + .../DigitalIO/boards/BobuinoGpioPinMap.h | 37 + .../AVR/drivers/DigitalIO/boards/GpioPinMap.h | 64 ++ .../DigitalIO/boards/LeonardoGpioPinMap.h | 35 + .../drivers/DigitalIO/boards/MegaGpioPinMap.h | 75 ++ .../boards/SleepingBeautyGpioPinMap.h | 37 + .../DigitalIO/boards/Standard1284GpioPinMap.h | 37 + .../DigitalIO/boards/Teensy2GpioPinMap.h | 30 + .../DigitalIO/boards/Teensy2ppGpioPinMap.h | 51 ++ .../drivers/DigitalIO/boards/UnoGpioPinMap.h | 25 + .../DigitalPinBlink/DigitalPinBlink.ino | 13 - .../DigitalPinConfigToggle.ino | 20 - .../DigitalPinReadWrite.ino | 12 - .../DigitalPinShiftOut/DigitalPinShiftOut.ino | 43 -- .../examples/PinIOBegin/PinIOBegin.ino | 26 - .../PinIOConfigToggle/PinIOConfigToggle.ino | 18 - .../PinIOReadWrite/PinIOReadWrite.ino | 18 - .../examples/ScanI2cBus/ScanI2cBus.ino | 85 --- .../SoftDS1307Utility/SoftDS1307Utility.ino | 365 ---------- .../examples/testArduino/testArduino.ino | 16 - .../testDigitalPin/testDigitalPin.ino | 21 - .../testFastDigital/testFastDigital.ino | 15 - .../examples/testPinIO/testPinIO.ino | 21 - .../examples/testSoftSPI/testSoftSPI.ino | 43 -- hal/architecture/NRF5/MyHwNRF5.cpp | 4 +- 42 files changed, 775 insertions(+), 1898 deletions(-) delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/AvrDevelopersGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/BobuinoGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/GpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/LeonardoGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/MegaGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/SleepingBeautyGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/Standard1284GpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2GpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2ppGpioPinMap.h create mode 100644 hal/architecture/AVR/drivers/DigitalIO/boards/UnoGpioPinMap.h delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino delete mode 100644 hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino diff --git a/.ci/doxygen.groovy b/.ci/doxygen.groovy index c8b9a5378..08913f465 100644 --- a/.ci/doxygen.groovy +++ b/.ci/doxygen.groovy @@ -6,7 +6,7 @@ def call(config) { Documentation/doxygen.sh""" warnings canComputeNew: false, canResolveRelativePaths: false, defaultEncoding: '', - excludePattern: '''.*/hal/architecture/Linux/drivers/.*,.*/drivers/TinyGSM/.*''', + excludePattern: '''.*/hal/architecture/Linux/drivers/.*,.*/hal/architecture/AVR/drivers/.*,.*/drivers/TinyGSM/.*''', failedTotalAll: '', healthy: '', includePattern: '', messagesPattern: '', parserConfigurations: [[parserName: 'Doxygen', pattern: config.repository_root+'doxygen.log']], unHealthy: '', unstableTotalAll: '0' diff --git a/MyConfig.h b/MyConfig.h index 0e8278f8d..e91e07fb2 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -28,7 +28,6 @@ */ #ifndef MyConfig_h #define MyConfig_h -#include /** * @defgroup SerialDebugGrpPub Serial and debugging diff --git a/MySensors.h b/MySensors.h index 83ac31638..e6b8048f3 100644 --- a/MySensors.h +++ b/MySensors.h @@ -38,6 +38,7 @@ #ifdef __cplusplus #include #endif +#include #include "MyConfig.h" #include "core/MyHelperFunctions.cpp" diff --git a/configure b/configure index a4e68aaba..f47e73977 100755 --- a/configure +++ b/configure @@ -4,7 +4,7 @@ # Original work: https://github.com/TMRh20/RF24/blob/master/configure function help { -cat < MQTT subscribe topic prefix. - --my-transport=[none|rf24|rs485|rfm95|rfm69] + --my-transport=[none|rf24|rfm69|rfm95|rs485] Set the transport to be used to communicate with other nodes. [rf24] --my-rf24-channel=<0-125> RF channel for the sensor net. [76] - --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW] + --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_HIGH|RF24_PA_LOW|RF24_PA_MIN] RF24 PA level. [RF24_PA_MAX] --my-rf24-ce-pin= Pin number to use for rf24 Chip-Enable. --my-rf24-cs-pin= Pin number to use for rf24 Chip-Select. @@ -318,7 +318,7 @@ for opt do CFLAGS="$optarg" ;; --extra-cxxflags=*) - CXXFLAGS="$optarg" + CXXFLAGS="$optarg $CXXFLAGS" ;; --extra-ldflags=*) LDFLAGS="$optarg" @@ -542,6 +542,7 @@ BINDIR=${BINDIR:-bin} GATEWAY_DIR=${GATEWAY_DIR:-${PREFIX}/bin} CC=${CC:-gcc} CXX=${CXX:-g++} +CXXFLAGS="-std=c++11" if [ -z "${SOC}" ]; then printf "${SECTION} Detecting target machine.\n" @@ -625,10 +626,10 @@ elif [[ ${transport_type} == "rf24" ]]; then CPPFLAGS="-DMY_RADIO_RF24 $CPPFLAGS" elif [[ ${transport_type} == "rfm69" ]]; then CPPFLAGS="-DMY_RADIO_RFM69 -DMY_RFM69_NEW_DRIVER $CPPFLAGS" -elif [[ ${transport_type} == "rs485" ]]; then - CPPFLAGS="-DMY_RS485 $CPPFLAGS" elif [[ ${transport_type} == "rfm95" ]]; then CPPFLAGS="-DMY_RADIO_RFM95 $CPPFLAGS" +elif [[ ${transport_type} == "rs485" ]]; then + CPPFLAGS="-DMY_RS485 $CPPFLAGS" else die "Invalid transport type." 3 fi diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 0cfe219ad..2022b2b1a 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -27,7 +27,6 @@ #endif // message buffers - MyMessage _msg; // Buffer for incoming messages MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces among others) @@ -305,12 +304,14 @@ bool _sendRoute(MyMessage &message) { #if defined(MY_CORE_ONLY) (void)message; + return false; #elif defined(MY_GATEWAY_FEATURE) if (message.destination == getNodeId()) { // This is a message sent from a sensor attached on the gateway node. // Pass it directly to the gateway transport layer. return gatewayTransportSend(message); } + return false; #elif defined(MY_SENSOR_NETWORK) return transportSendRoute(message); #else diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index 93604036d..bf9bdafbc 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -74,11 +74,6 @@ #include #include -#if defined(__linux__) -#include -#include -#endif - #define GATEWAY_ADDRESS ((uint8_t)0) //!< Node ID for GW sketch #define NODE_SENSOR_ID ((uint8_t)255) //!< Node child is always created/presented when a node is started #define MY_CORE_VERSION ((uint8_t)2) //!< core version @@ -140,7 +135,7 @@ void presentNode(void); * @param description A textual description of the sensor. * @return true Returns true if message reached the first stop on its way to destination. */ -bool present(const uint8_t sensorId, const uint8_t sensorType, const char *description="", +bool present(const uint8_t sensorId, const uint8_t sensorType, const char *description = "", const bool ack = false); #if !defined(__linux__) bool present(const uint8_t childSensorId, const uint8_t sensorType, diff --git a/hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h b/hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h index f984ef8c3..4b4ca77e7 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h +++ b/hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h @@ -26,11 +26,11 @@ #define DigitalIO_h 1 //------------------------------------------------------------------------------ /** DigitalPin version YYYYMMDD */ -#define DIGITAL_IO_VERSION 20140217 +#define DIGITAL_IO_VERSION 20151127 //------------------------------------------------------------------------------ #include "DigitalPin.h" #include "I2cConstants.h" #include "PinIO.h" #include "SoftI2cMaster.h" #include "SoftSPI.h" -#endif // DigitalIO_h +#endif // DigitalIO_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h b/hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h index b59897fd7..cf5467528 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h +++ b/hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h @@ -22,379 +22,27 @@ * @brief Fast Digital Pin functions * * @defgroup digitalPin Fast Pin I/O - * @ingroup internals * @details Fast Digital I/O functions and template class. * @{ */ #ifndef DigitalPin_h #define DigitalPin_h +#if defined(__AVR__) || defined(DOXYGEN) #include -#include -#include -/** @brief Helper macro for complex inline attributes */ -#define ALWAYS_INLINE inline __attribute__((always_inline)) -//------------------------------------------------------------------------------ -/** - * @class pin_map_t - * @brief struct for mapping digital pins - */ -struct pin_map_t { - volatile uint8_t* ddr; /**< address of DDR for this pin */ +/** GpioPinMap type */ +struct GpioPinMap_t { volatile uint8_t* pin; /**< address of PIN for this pin */ + volatile uint8_t* ddr; /**< address of DDR for this pin */ volatile uint8_t* port; /**< address of PORT for this pin */ - uint8_t bit; /**< bit number for this pin */ -}; -//------------------------------------------------------------------------------ -#if defined(__AVR_ATmega168__)\ -||defined(__AVR_ATmega168P__)\ -||defined(__AVR_ATmega328P__) -// 168 and 328 Arduinos -const static pin_map_t pinMap[] = { - {&DDRD, &PIND, &PORTD, 0}, // D0 0 - {&DDRD, &PIND, &PORTD, 1}, // D1 1 - {&DDRD, &PIND, &PORTD, 2}, // D2 2 - {&DDRD, &PIND, &PORTD, 3}, // D3 3 - {&DDRD, &PIND, &PORTD, 4}, // D4 4 - {&DDRD, &PIND, &PORTD, 5}, // D5 5 - {&DDRD, &PIND, &PORTD, 6}, // D6 6 - {&DDRD, &PIND, &PORTD, 7}, // D7 7 - {&DDRB, &PINB, &PORTB, 0}, // B0 8 - {&DDRB, &PINB, &PORTB, 1}, // B1 9 - {&DDRB, &PINB, &PORTB, 2}, // B2 10 - {&DDRB, &PINB, &PORTB, 3}, // B3 11 - {&DDRB, &PINB, &PORTB, 4}, // B4 12 - {&DDRB, &PINB, &PORTB, 5}, // B5 13 - {&DDRC, &PINC, &PORTC, 0}, // C0 14 - {&DDRC, &PINC, &PORTC, 1}, // C1 15 - {&DDRC, &PINC, &PORTC, 2}, // C2 16 - {&DDRC, &PINC, &PORTC, 3}, // C3 17 - {&DDRC, &PINC, &PORTC, 4}, // C4 18 - {&DDRC, &PINC, &PORTC, 5} // C5 19 -}; -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega1280__)\ -|| defined(__AVR_ATmega2560__) -// Mega -static const pin_map_t pinMap[] = { - {&DDRE, &PINE, &PORTE, 0}, // E0 0 - {&DDRE, &PINE, &PORTE, 1}, // E1 1 - {&DDRE, &PINE, &PORTE, 4}, // E4 2 - {&DDRE, &PINE, &PORTE, 5}, // E5 3 - {&DDRG, &PING, &PORTG, 5}, // G5 4 - {&DDRE, &PINE, &PORTE, 3}, // E3 5 - {&DDRH, &PINH, &PORTH, 3}, // H3 6 - {&DDRH, &PINH, &PORTH, 4}, // H4 7 - {&DDRH, &PINH, &PORTH, 5}, // H5 8 - {&DDRH, &PINH, &PORTH, 6}, // H6 9 - {&DDRB, &PINB, &PORTB, 4}, // B4 10 - {&DDRB, &PINB, &PORTB, 5}, // B5 11 - {&DDRB, &PINB, &PORTB, 6}, // B6 12 - {&DDRB, &PINB, &PORTB, 7}, // B7 13 - {&DDRJ, &PINJ, &PORTJ, 1}, // J1 14 - {&DDRJ, &PINJ, &PORTJ, 0}, // J0 15 - {&DDRH, &PINH, &PORTH, 1}, // H1 16 - {&DDRH, &PINH, &PORTH, 0}, // H0 17 - {&DDRD, &PIND, &PORTD, 3}, // D3 18 - {&DDRD, &PIND, &PORTD, 2}, // D2 19 - {&DDRD, &PIND, &PORTD, 1}, // D1 20 - {&DDRD, &PIND, &PORTD, 0}, // D0 21 - {&DDRA, &PINA, &PORTA, 0}, // A0 22 - {&DDRA, &PINA, &PORTA, 1}, // A1 23 - {&DDRA, &PINA, &PORTA, 2}, // A2 24 - {&DDRA, &PINA, &PORTA, 3}, // A3 25 - {&DDRA, &PINA, &PORTA, 4}, // A4 26 - {&DDRA, &PINA, &PORTA, 5}, // A5 27 - {&DDRA, &PINA, &PORTA, 6}, // A6 28 - {&DDRA, &PINA, &PORTA, 7}, // A7 29 - {&DDRC, &PINC, &PORTC, 7}, // C7 30 - {&DDRC, &PINC, &PORTC, 6}, // C6 31 - {&DDRC, &PINC, &PORTC, 5}, // C5 32 - {&DDRC, &PINC, &PORTC, 4}, // C4 33 - {&DDRC, &PINC, &PORTC, 3}, // C3 34 - {&DDRC, &PINC, &PORTC, 2}, // C2 35 - {&DDRC, &PINC, &PORTC, 1}, // C1 36 - {&DDRC, &PINC, &PORTC, 0}, // C0 37 - {&DDRD, &PIND, &PORTD, 7}, // D7 38 - {&DDRG, &PING, &PORTG, 2}, // G2 39 - {&DDRG, &PING, &PORTG, 1}, // G1 40 - {&DDRG, &PING, &PORTG, 0}, // G0 41 - {&DDRL, &PINL, &PORTL, 7}, // L7 42 - {&DDRL, &PINL, &PORTL, 6}, // L6 43 - {&DDRL, &PINL, &PORTL, 5}, // L5 44 - {&DDRL, &PINL, &PORTL, 4}, // L4 45 - {&DDRL, &PINL, &PORTL, 3}, // L3 46 - {&DDRL, &PINL, &PORTL, 2}, // L2 47 - {&DDRL, &PINL, &PORTL, 1}, // L1 48 - {&DDRL, &PINL, &PORTL, 0}, // L0 49 - {&DDRB, &PINB, &PORTB, 3}, // B3 50 - {&DDRB, &PINB, &PORTB, 2}, // B2 51 - {&DDRB, &PINB, &PORTB, 1}, // B1 52 - {&DDRB, &PINB, &PORTB, 0}, // B0 53 - {&DDRF, &PINF, &PORTF, 0}, // F0 54 - {&DDRF, &PINF, &PORTF, 1}, // F1 55 - {&DDRF, &PINF, &PORTF, 2}, // F2 56 - {&DDRF, &PINF, &PORTF, 3}, // F3 57 - {&DDRF, &PINF, &PORTF, 4}, // F4 58 - {&DDRF, &PINF, &PORTF, 5}, // F5 59 - {&DDRF, &PINF, &PORTF, 6}, // F6 60 - {&DDRF, &PINF, &PORTF, 7}, // F7 61 - {&DDRK, &PINK, &PORTK, 0}, // K0 62 - {&DDRK, &PINK, &PORTK, 1}, // K1 63 - {&DDRK, &PINK, &PORTK, 2}, // K2 64 - {&DDRK, &PINK, &PORTK, 3}, // K3 65 - {&DDRK, &PINK, &PORTK, 4}, // K4 66 - {&DDRK, &PINK, &PORTK, 5}, // K5 67 - {&DDRK, &PINK, &PORTK, 6}, // K6 68 - {&DDRK, &PINK, &PORTK, 7} // K7 69 + uint8_t mask; /**< bit mask for this pin */ }; -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega1284P__)\ -|| defined(__AVR_ATmega1284__)\ -|| defined(__AVR_ATmega644P__)\ -|| defined(__AVR_ATmega644__)\ -|| defined(__AVR_ATmega64__)\ -|| defined(__AVR_ATmega32__)\ -|| defined(__AVR_ATmega324__)\ -|| defined(__AVR_ATmega16__) -#ifdef defined(VARIANT_MIGHTY) -// Mighty Layout -static const pin_map_t pinMap[] = { - {&DDRB, &PINB, &PORTB, 0}, // B0 0 - {&DDRB, &PINB, &PORTB, 1}, // B1 1 - {&DDRB, &PINB, &PORTB, 2}, // B2 2 - {&DDRB, &PINB, &PORTB, 3}, // B3 3 - {&DDRB, &PINB, &PORTB, 4}, // B4 4 - {&DDRB, &PINB, &PORTB, 5}, // B5 5 - {&DDRB, &PINB, &PORTB, 6}, // B6 6 - {&DDRB, &PINB, &PORTB, 7}, // B7 7 - {&DDRD, &PIND, &PORTD, 0}, // D0 8 - {&DDRD, &PIND, &PORTD, 1}, // D1 9 - {&DDRD, &PIND, &PORTD, 2}, // D2 10 - {&DDRD, &PIND, &PORTD, 3}, // D3 11 - {&DDRD, &PIND, &PORTD, 4}, // D4 12 - {&DDRD, &PIND, &PORTD, 5}, // D5 13 - {&DDRD, &PIND, &PORTD, 6}, // D6 14 - {&DDRD, &PIND, &PORTD, 7}, // D7 15 - {&DDRC, &PINC, &PORTC, 0}, // C0 16 - {&DDRC, &PINC, &PORTC, 1}, // C1 17 - {&DDRC, &PINC, &PORTC, 2}, // C2 18 - {&DDRC, &PINC, &PORTC, 3}, // C3 19 - {&DDRC, &PINC, &PORTC, 4}, // C4 20 - {&DDRC, &PINC, &PORTC, 5}, // C5 21 - {&DDRC, &PINC, &PORTC, 6}, // C6 22 - {&DDRC, &PINC, &PORTC, 7}, // C7 23 - {&DDRA, &PINA, &PORTA, 0}, // A0 24 - {&DDRA, &PINA, &PORTA, 1}, // A1 25 - {&DDRA, &PINA, &PORTA, 2}, // A2 26 - {&DDRA, &PINA, &PORTA, 3}, // A3 27 - {&DDRA, &PINA, &PORTA, 4}, // A4 28 - {&DDRA, &PINA, &PORTA, 5}, // A5 29 - {&DDRA, &PINA, &PORTA, 6}, // A6 30 - {&DDRA, &PINA, &PORTA, 7} // A7 31 -}; -#elif defined(VARIANT_BOBUINO) -// Bobuino Layout -static const pin_map_t pinMap[] = { - {&DDRD, &PIND, &PORTD, 0}, // D0 0 - {&DDRD, &PIND, &PORTD, 1}, // D1 1 - {&DDRD, &PIND, &PORTD, 2}, // D2 2 - {&DDRD, &PIND, &PORTD, 3}, // D3 3 - {&DDRB, &PINB, &PORTB, 0}, // B0 4 - {&DDRB, &PINB, &PORTB, 1}, // B1 5 - {&DDRB, &PINB, &PORTB, 2}, // B2 6 - {&DDRB, &PINB, &PORTB, 3}, // B3 7 - {&DDRD, &PIND, &PORTD, 5}, // D5 8 - {&DDRD, &PIND, &PORTD, 6}, // D6 9 - {&DDRB, &PINB, &PORTB, 4}, // B4 10 - {&DDRB, &PINB, &PORTB, 5}, // B5 11 - {&DDRB, &PINB, &PORTB, 6}, // B6 12 - {&DDRB, &PINB, &PORTB, 7}, // B7 13 - {&DDRA, &PINA, &PORTA, 7}, // A7 14 - {&DDRA, &PINA, &PORTA, 6}, // A6 15 - {&DDRA, &PINA, &PORTA, 5}, // A5 16 - {&DDRA, &PINA, &PORTA, 4}, // A4 17 - {&DDRA, &PINA, &PORTA, 3}, // A3 18 - {&DDRA, &PINA, &PORTA, 2}, // A2 19 - {&DDRA, &PINA, &PORTA, 1}, // A1 20 - {&DDRA, &PINA, &PORTA, 0}, // A0 21 - {&DDRC, &PINC, &PORTC, 0}, // C0 22 - {&DDRC, &PINC, &PORTC, 1}, // C1 23 - {&DDRC, &PINC, &PORTC, 2}, // C2 24 - {&DDRC, &PINC, &PORTC, 3}, // C3 25 - {&DDRC, &PINC, &PORTC, 4}, // C4 26 - {&DDRC, &PINC, &PORTC, 5}, // C5 27 - {&DDRC, &PINC, &PORTC, 6}, // C6 28 - {&DDRC, &PINC, &PORTC, 7}, // C7 29 - {&DDRD, &PIND, &PORTD, 4}, // D4 30 - {&DDRD, &PIND, &PORTD, 7} // D7 31 -}; -#elif defined(VARIANT_STANDARD) -// Standard Layout -static const pin_map_t pinMap[] = { - {&DDRB, &PINB, &PORTB, 0}, // B0 0 - {&DDRB, &PINB, &PORTB, 1}, // B1 1 - {&DDRB, &PINB, &PORTB, 2}, // B2 2 - {&DDRB, &PINB, &PORTB, 3}, // B3 3 - {&DDRB, &PINB, &PORTB, 4}, // B4 4 - {&DDRB, &PINB, &PORTB, 5}, // B5 5 - {&DDRB, &PINB, &PORTB, 6}, // B6 6 - {&DDRB, &PINB, &PORTB, 7}, // B7 7 - {&DDRD, &PIND, &PORTD, 0}, // D0 8 - {&DDRD, &PIND, &PORTD, 1}, // D1 9 - {&DDRD, &PIND, &PORTD, 2}, // D2 10 - {&DDRD, &PIND, &PORTD, 3}, // D3 11 - {&DDRD, &PIND, &PORTD, 4}, // D4 12 - {&DDRD, &PIND, &PORTD, 5}, // D5 13 - {&DDRD, &PIND, &PORTD, 6}, // D6 14 - {&DDRD, &PIND, &PORTD, 7}, // D7 15 - {&DDRC, &PINC, &PORTC, 0}, // C0 16 - {&DDRC, &PINC, &PORTC, 1}, // C1 17 - {&DDRC, &PINC, &PORTC, 2}, // C2 18 - {&DDRC, &PINC, &PORTC, 3}, // C3 19 - {&DDRC, &PINC, &PORTC, 4}, // C4 20 - {&DDRC, &PINC, &PORTC, 5}, // C5 21 - {&DDRC, &PINC, &PORTC, 6}, // C6 22 - {&DDRC, &PINC, &PORTC, 7}, // C7 23 - {&DDRA, &PINA, &PORTA, 7}, // A7 24 - {&DDRA, &PINA, &PORTA, 6}, // A6 25 - {&DDRA, &PINA, &PORTA, 5}, // A5 26 - {&DDRA, &PINA, &PORTA, 4}, // A4 27 - {&DDRA, &PINA, &PORTA, 3}, // A3 28 - {&DDRA, &PINA, &PORTA, 2}, // A2 29 - {&DDRA, &PINA, &PORTA, 1}, // A1 30 - {&DDRA, &PINA, &PORTA, 0} // A0 31 -}; -#else // VARIANT_MIGHTY -#error Undefined variant 1284, 644, 324, 64, 32 -#endif // VARIANT_MIGHTY -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega32U4__) -#ifdef CORE_TEENSY -// Teensy 2.0 -static const pin_map_t pinMap[] = { - {&DDRB, &PINB, &PORTB, 0}, // B0 0 - {&DDRB, &PINB, &PORTB, 1}, // B1 1 - {&DDRB, &PINB, &PORTB, 2}, // B2 2 - {&DDRB, &PINB, &PORTB, 3}, // B3 3 - {&DDRB, &PINB, &PORTB, 7}, // B7 4 - {&DDRD, &PIND, &PORTD, 0}, // D0 5 - {&DDRD, &PIND, &PORTD, 1}, // D1 6 - {&DDRD, &PIND, &PORTD, 2}, // D2 7 - {&DDRD, &PIND, &PORTD, 3}, // D3 8 - {&DDRC, &PINC, &PORTC, 6}, // C6 9 - {&DDRC, &PINC, &PORTC, 7}, // C7 10 - {&DDRD, &PIND, &PORTD, 6}, // D6 11 - {&DDRD, &PIND, &PORTD, 7}, // D7 12 - {&DDRB, &PINB, &PORTB, 4}, // B4 13 - {&DDRB, &PINB, &PORTB, 5}, // B5 14 - {&DDRB, &PINB, &PORTB, 6}, // B6 15 - {&DDRF, &PINF, &PORTF, 7}, // F7 16 - {&DDRF, &PINF, &PORTF, 6}, // F6 17 - {&DDRF, &PINF, &PORTF, 5}, // F5 18 - {&DDRF, &PINF, &PORTF, 4}, // F4 19 - {&DDRF, &PINF, &PORTF, 1}, // F1 20 - {&DDRF, &PINF, &PORTF, 0}, // F0 21 - {&DDRD, &PIND, &PORTD, 4}, // D4 22 - {&DDRD, &PIND, &PORTD, 5}, // D5 23 - {&DDRE, &PINE, &PORTE, 6} // E6 24 -}; -//------------------------------------------------------------------------------ -#else // CORE_TEENSY -// Leonardo -static const pin_map_t pinMap[] = { - {&DDRD, &PIND, &PORTD, 2}, // D2 0 - {&DDRD, &PIND, &PORTD, 3}, // D3 1 - {&DDRD, &PIND, &PORTD, 1}, // D1 2 - {&DDRD, &PIND, &PORTD, 0}, // D0 3 - {&DDRD, &PIND, &PORTD, 4}, // D4 4 - {&DDRC, &PINC, &PORTC, 6}, // C6 5 - {&DDRD, &PIND, &PORTD, 7}, // D7 6 - {&DDRE, &PINE, &PORTE, 6}, // E6 7 - {&DDRB, &PINB, &PORTB, 4}, // B4 8 - {&DDRB, &PINB, &PORTB, 5}, // B5 9 - {&DDRB, &PINB, &PORTB, 6}, // B6 10 - {&DDRB, &PINB, &PORTB, 7}, // B7 11 - {&DDRD, &PIND, &PORTD, 6}, // D6 12 - {&DDRC, &PINC, &PORTC, 7}, // C7 13 - {&DDRB, &PINB, &PORTB, 3}, // B3 14 - {&DDRB, &PINB, &PORTB, 1}, // B1 15 - {&DDRB, &PINB, &PORTB, 2}, // B2 16 - {&DDRB, &PINB, &PORTB, 0}, // B0 17 - {&DDRF, &PINF, &PORTF, 7}, // F7 18 - {&DDRF, &PINF, &PORTF, 6}, // F6 19 - {&DDRF, &PINF, &PORTF, 5}, // F5 20 - {&DDRF, &PINF, &PORTF, 4}, // F4 21 - {&DDRF, &PINF, &PORTF, 1}, // F1 22 - {&DDRF, &PINF, &PORTF, 0}, // F0 23 - {&DDRD, &PIND, &PORTD, 4}, // D4 24 - {&DDRD, &PIND, &PORTD, 7}, // D7 25 - {&DDRB, &PINB, &PORTB, 4}, // B4 26 - {&DDRB, &PINB, &PORTB, 5}, // B5 27 - {&DDRB, &PINB, &PORTB, 6}, // B6 28 - {&DDRD, &PIND, &PORTD, 6} // D6 29 -}; -#endif // CORE_TEENSY -//------------------------------------------------------------------------------ -#elif defined(__AVR_AT90USB646__)\ -|| defined(__AVR_AT90USB1286__) -// Teensy++ 1.0 & 2.0 -static const pin_map_t pinMap[] = { - {&DDRD, &PIND, &PORTD, 0}, // D0 0 - {&DDRD, &PIND, &PORTD, 1}, // D1 1 - {&DDRD, &PIND, &PORTD, 2}, // D2 2 - {&DDRD, &PIND, &PORTD, 3}, // D3 3 - {&DDRD, &PIND, &PORTD, 4}, // D4 4 - {&DDRD, &PIND, &PORTD, 5}, // D5 5 - {&DDRD, &PIND, &PORTD, 6}, // D6 6 - {&DDRD, &PIND, &PORTD, 7}, // D7 7 - {&DDRE, &PINE, &PORTE, 0}, // E0 8 - {&DDRE, &PINE, &PORTE, 1}, // E1 9 - {&DDRC, &PINC, &PORTC, 0}, // C0 10 - {&DDRC, &PINC, &PORTC, 1}, // C1 11 - {&DDRC, &PINC, &PORTC, 2}, // C2 12 - {&DDRC, &PINC, &PORTC, 3}, // C3 13 - {&DDRC, &PINC, &PORTC, 4}, // C4 14 - {&DDRC, &PINC, &PORTC, 5}, // C5 15 - {&DDRC, &PINC, &PORTC, 6}, // C6 16 - {&DDRC, &PINC, &PORTC, 7}, // C7 17 - {&DDRE, &PINE, &PORTE, 6}, // E6 18 - {&DDRE, &PINE, &PORTE, 7}, // E7 19 - {&DDRB, &PINB, &PORTB, 0}, // B0 20 - {&DDRB, &PINB, &PORTB, 1}, // B1 21 - {&DDRB, &PINB, &PORTB, 2}, // B2 22 - {&DDRB, &PINB, &PORTB, 3}, // B3 23 - {&DDRB, &PINB, &PORTB, 4}, // B4 24 - {&DDRB, &PINB, &PORTB, 5}, // B5 25 - {&DDRB, &PINB, &PORTB, 6}, // B6 26 - {&DDRB, &PINB, &PORTB, 7}, // B7 27 - {&DDRA, &PINA, &PORTA, 0}, // A0 28 - {&DDRA, &PINA, &PORTA, 1}, // A1 29 - {&DDRA, &PINA, &PORTA, 2}, // A2 30 - {&DDRA, &PINA, &PORTA, 3}, // A3 31 - {&DDRA, &PINA, &PORTA, 4}, // A4 32 - {&DDRA, &PINA, &PORTA, 5}, // A5 33 - {&DDRA, &PINA, &PORTA, 6}, // A6 34 - {&DDRA, &PINA, &PORTA, 7}, // A7 35 - {&DDRE, &PINE, &PORTE, 4}, // E4 36 - {&DDRE, &PINE, &PORTE, 5}, // E5 37 - {&DDRF, &PINF, &PORTF, 0}, // F0 38 - {&DDRF, &PINF, &PORTF, 1}, // F1 39 - {&DDRF, &PINF, &PORTF, 2}, // F2 40 - {&DDRF, &PINF, &PORTF, 3}, // F3 41 - {&DDRF, &PINF, &PORTF, 4}, // F4 42 - {&DDRF, &PINF, &PORTF, 5}, // F5 43 - {&DDRF, &PINF, &PORTF, 6}, // F6 44 - {&DDRF, &PINF, &PORTF, 7} // F7 45 -}; -//------------------------------------------------------------------------------ -#else // CPU type -#error unknown CPU type -#endif // CPU type +/** Initializer macro. */ +#define GPIO_PIN(reg, bit) {&PIN##reg, &DDR##reg, &PORT##reg, 1 << bit} + +// Include pin map for current board. +#include "boards/GpioPinMap.h" //------------------------------------------------------------------------------ -/** count of pins */ -static const uint8_t digitalPinCount = sizeof(pinMap)/sizeof(pin_map_t); -//============================================================================== /** generate bad pin number error */ void badPinNumber(void) __attribute__((error("Pin number is too large or not a constant"))); @@ -402,100 +50,269 @@ __attribute__((error("Pin number is too large or not a constant"))); /** Check for valid pin number * @param[in] pin Number of pin to be checked. */ -static ALWAYS_INLINE void badPinCheck(uint8_t pin) +static inline __attribute__((always_inline)) +void badPinCheck(uint8_t pin) { - if (!__builtin_constant_p(pin) || pin >= digitalPinCount) { + if (!__builtin_constant_p(pin) || pin >= NUM_DIGITAL_PINS) { badPinNumber(); } } //------------------------------------------------------------------------------ -/** fast write helper +/** DDR register address + * @param[in] pin Arduino pin number + * @return register address + */ +static inline __attribute__((always_inline)) +volatile uint8_t* ddrReg(uint8_t pin) +{ + badPinCheck(pin); + return GpioPinMap[pin].ddr; +} +//------------------------------------------------------------------------------ +/** Bit mask for pin + * @param[in] pin Arduino pin number + * @return mask + */ +static inline __attribute__((always_inline)) +uint8_t pinMask(uint8_t pin) +{ + badPinCheck(pin); + return GpioPinMap[pin].mask; +} +//------------------------------------------------------------------------------ +/** PIN register address + * @param[in] pin Arduino pin number + * @return register address + */ +static inline __attribute__((always_inline)) +volatile uint8_t* pinReg(uint8_t pin) +{ + badPinCheck(pin); + return GpioPinMap[pin].pin; +} +//------------------------------------------------------------------------------ +/** PORT register address + * @param[in] pin Arduino pin number + * @return register address + */ +static inline __attribute__((always_inline)) +volatile uint8_t* portReg(uint8_t pin) +{ + badPinCheck(pin); + return GpioPinMap[pin].port; +} +//------------------------------------------------------------------------------ +/** Fast write helper. * @param[in] address I/O register address - * @param[in] bit bit number to write + * @param[in] mask bit mask for pin * @param[in] level value for bit */ -static ALWAYS_INLINE void fastBitWriteSafe(volatile uint8_t* address, uint8_t bit, bool level) +static inline __attribute__((always_inline)) +void fastBitWriteSafe(volatile uint8_t* address, uint8_t mask, bool level) { - uint8_t oldSREG; - if (address > (uint8_t*)0X5F) { - oldSREG = SREG; + uint8_t s; + if (address > reinterpret_cast(0X3F)) { + s = SREG; cli(); } if (level) { - *address |= 1 << bit; + *address |= mask; } else { - *address &= ~(1 << bit); + *address &= ~mask; } - if (address > (uint8_t*)0X5F) { - SREG = oldSREG; + if (address > reinterpret_cast(0X3F)) { + SREG = s; } } //------------------------------------------------------------------------------ -/** read pin value +/** Read pin value. * @param[in] pin Arduino pin number * @return value read */ -static ALWAYS_INLINE bool fastDigitalRead(uint8_t pin) +static inline __attribute__((always_inline)) +bool fastDigitalRead(uint8_t pin) { - badPinCheck(pin); - return (*pinMap[pin].pin >> pinMap[pin].bit) & 1; + return *pinReg(pin) & pinMask(pin); } //------------------------------------------------------------------------------ -/** toggle a pin +/** Toggle a pin. * @param[in] pin Arduino pin number * * If the pin is in output mode toggle the pin level. * If the pin is in input mode toggle the state of the 20K pullup. */ -static ALWAYS_INLINE void fastDigitalToggle(uint8_t pin) +static inline __attribute__((always_inline)) +void fastDigitalToggle(uint8_t pin) { - badPinCheck(pin); - if (pinMap[pin].pin > (uint8_t*)0X5F) { + if (pinReg(pin) > reinterpret_cast(0X3F)) { // must write bit to high address port - *pinMap[pin].pin = 1 << pinMap[pin].bit; + *pinReg(pin) = pinMask(pin); } else { // will compile to sbi and PIN register will not be read. - *pinMap[pin].pin |= 1 << pinMap[pin].bit; + *pinReg(pin) |= pinMask(pin); } } //------------------------------------------------------------------------------ -/** Set pin value +/** Set pin value. * @param[in] pin Arduino pin number * @param[in] level value to write */ -static ALWAYS_INLINE void fastDigitalWrite(uint8_t pin, bool level) +static inline __attribute__((always_inline)) +void fastDigitalWrite(uint8_t pin, bool level) { - badPinCheck(pin); - fastBitWriteSafe(pinMap[pin].port, pinMap[pin].bit, level); + fastBitWriteSafe(portReg(pin), pinMask(pin), level); +} +//------------------------------------------------------------------------------ +/** Write the DDR register. + * @param[in] pin Arduino pin number + * @param[in] level value to write + */ +static inline __attribute__((always_inline)) +void fastDdrWrite(uint8_t pin, bool level) +{ + fastBitWriteSafe(ddrReg(pin), pinMask(pin), level); } //------------------------------------------------------------------------------ -/** set pin mode +/** Set pin mode. * @param[in] pin Arduino pin number - * @param[in] mode if true set output mode else input mode + * @param[in] mode INPUT, OUTPUT, or INPUT_PULLUP. * - * fastPinMode does not enable or disable the 20K pullup for input mode. + * The internal pullup resistors will be enabled if mode is INPUT_PULLUP + * and disabled if the mode is INPUT. */ -static ALWAYS_INLINE void fastPinMode(uint8_t pin, bool mode) +static inline __attribute__((always_inline)) +void fastPinMode(uint8_t pin, uint8_t mode) { - badPinCheck(pin); - fastBitWriteSafe(pinMap[pin].ddr, pinMap[pin].bit, mode); + fastDdrWrite(pin, mode == OUTPUT); + if (mode != OUTPUT) { + fastDigitalWrite(pin, mode == INPUT_PULLUP); + } } +#else // defined(__AVR__) +#if defined(CORE_TEENSY) +//------------------------------------------------------------------------------ +/** read pin value + * @param[in] pin Arduino pin number + * @return value read + */ +static inline __attribute__((always_inline)) +bool fastDigitalRead(uint8_t pin) +{ + return *portInputRegister(pin); +} +//------------------------------------------------------------------------------ +/** Set pin value + * @param[in] pin Arduino pin number + * @param[in] level value to write + */ +static inline __attribute__((always_inline)) +void fastDigitalWrite(uint8_t pin, bool value) +{ + if (value) { + *portSetRegister(pin) = 1; + } else { + *portClearRegister(pin) = 1; + } +} +#elif defined(__SAM3X8E__) || defined(__SAM3X8H__) +//------------------------------------------------------------------------------ +/** read pin value + * @param[in] pin Arduino pin number + * @return value read + */ +static inline __attribute__((always_inline)) +bool fastDigitalRead(uint8_t pin) +{ + return g_APinDescription[pin].pPort->PIO_PDSR & g_APinDescription[pin].ulPin; +} +//------------------------------------------------------------------------------ +/** Set pin value + * @param[in] pin Arduino pin number + * @param[in] level value to write + */ +static inline __attribute__((always_inline)) +void fastDigitalWrite(uint8_t pin, bool value) +{ + if (value) { + g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin; + } else { + g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin; + } +} +#elif defined(ESP8266) +//------------------------------------------------------------------------------ +/** Set pin value + * @param[in] pin Arduino pin number + * @param[in] val value to write + */ +static inline __attribute__((always_inline)) +void fastDigitalWrite(uint8_t pin, uint8_t val) +{ + if (pin < 16) { + if (val) { + GPOS = (1 << pin); + } else { + GPOC = (1 << pin); + } + } else if (pin == 16) { + if (val) { + GP16O |= 1; + } else { + GP16O &= ~1; + } + } +} +//------------------------------------------------------------------------------ +/** Read pin value + * @param[in] pin Arduino pin number + * @return value read + */ +static inline __attribute__((always_inline)) +bool fastDigitalRead(uint8_t pin) +{ + if (pin < 16) { + return GPIP(pin); + } else if (pin == 16) { + return GP16I & 0x01; + } + return 0; +} +#else // CORE_TEENSY +//------------------------------------------------------------------------------ +inline void fastDigitalWrite(uint8_t pin, bool value) +{ + digitalWrite(pin, value); +} +//------------------------------------------------------------------------------ +inline bool fastDigitalRead(uint8_t pin) +{ + return digitalRead(pin); +} +#endif // CORE_TEENSY +//------------------------------------------------------------------------------ +inline void fastDigitalToggle(uint8_t pin) +{ + fastDigitalWrite(pin, !fastDigitalRead(pin)); +} +//------------------------------------------------------------------------------ +inline void fastPinMode(uint8_t pin, uint8_t mode) +{ + pinMode(pin, mode); +} +#endif // __AVR__ //------------------------------------------------------------------------------ /** set pin configuration * @param[in] pin Arduino pin number - * @param[in] mode If true set output mode else input mode + * @param[in] mode mode INPUT or OUTPUT. * @param[in] level If mode is output, set level high/low. * If mode is input, enable or disable the pin's 20K pullup. */ -static ALWAYS_INLINE void fastPinConfig(uint8_t pin, bool mode, bool level) -{ - fastPinMode(pin, mode); - fastDigitalWrite(pin, level); -} +#define fastPinConfig(pin, mode, level)\ + {fastPinMode(pin, mode); fastDigitalWrite(pin, level);} //============================================================================== /** * @class DigitalPin - * @brief Fast AVR digital port I/O + * @brief Fast digital port I/O */ template class DigitalPin @@ -505,25 +322,7 @@ class DigitalPin /** Constructor */ DigitalPin() {} //---------------------------------------------------------------------------- - /** Constructor - * @param[in] pinMode if true set output mode else input mode. - */ - explicit DigitalPin(bool pinMode) - { - mode(pinMode); - } - //---------------------------------------------------------------------------- - /** Constructor - * @param[in] mode If true set output mode else input mode - * @param[in] level If mode is output, set level high/low. - * If mode is input, enable or disable the pin's 20K pullup. - */ - DigitalPin(bool mode, bool level) - { - config(mode, level); - } - //---------------------------------------------------------------------------- - /** Asignment operator + /** Asignment operator. * @param[in] value If true set the pin's level high else set the * pin's level low. * @@ -535,7 +334,7 @@ class DigitalPin return *this; } //---------------------------------------------------------------------------- - /** Parenthesis operator + /** Parenthesis operator. * @return Pin's level */ inline operator bool () const __attribute__((always_inline)) @@ -543,12 +342,13 @@ class DigitalPin return read(); } //---------------------------------------------------------------------------- - /** set pin configuration - * @param[in] mode If true set output mode else input mode - * @param[in] level If mode is output, set level high/low. - * If mode is input, enable or disable the pin's 20K pullup. + /** Set pin configuration. + * @param[in] mode: INPUT or OUTPUT. + * @param[in] level If mode is OUTPUT, set level high/low. + * If mode is INPUT, enable or disable the pin's 20K pullup. */ - ALWAYS_INLINE void config(bool mode, bool level) + inline __attribute__((always_inline)) + void config(uint8_t mode, bool level) { fastPinConfig(PinNumber, mode, level); } @@ -556,7 +356,8 @@ class DigitalPin /** * Set pin level high if output mode or enable 20K pullup if input mode. */ - ALWAYS_INLINE void high() + inline __attribute__((always_inline)) + void high() { write(true); } @@ -564,34 +365,39 @@ class DigitalPin /** * Set pin level low if output mode or disable 20K pullup if input mode. */ - ALWAYS_INLINE void low() + inline __attribute__((always_inline)) + void low() { write(false); } //---------------------------------------------------------------------------- /** - * Set pin mode - * @param[in] pinMode if true set output mode else input mode. + * Set pin mode. + * @param[in] mode: INPUT, OUTPUT, or INPUT_PULLUP. * - * mode() does not enable or disable the 20K pullup for input mode. + * The internal pullup resistors will be enabled if mode is INPUT_PULLUP + * and disabled if the mode is INPUT. */ - ALWAYS_INLINE void mode(bool pinMode) + inline __attribute__((always_inline)) + void mode(uint8_t mode) { - fastPinMode(PinNumber, pinMode); + fastPinMode(PinNumber, mode); } //---------------------------------------------------------------------------- - /** @return Pin's level */ - ALWAYS_INLINE bool read() const + /** @return Pin's level. */ + inline __attribute__((always_inline)) + bool read() const { return fastDigitalRead(PinNumber); } //---------------------------------------------------------------------------- - /** toggle a pin + /** Toggle a pin. * * If the pin is in output mode toggle the pin's level. * If the pin is in input mode toggle the state of the 20K pullup. */ - ALWAYS_INLINE void toggle() + inline __attribute__((always_inline)) + void toggle() { fastDigitalToggle(PinNumber); } @@ -600,10 +406,11 @@ class DigitalPin * @param[in] value If true set the pin's level high else set the * pin's level low. */ - ALWAYS_INLINE void write(bool value) + inline __attribute__((always_inline)) + void write(bool value) { fastDigitalWrite(PinNumber, value); } }; #endif // DigitalPin_h -/** @} */ \ No newline at end of file +/** @} */ diff --git a/hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h b/hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h index eb99c6bd1..f2d07671e 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h +++ b/hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h @@ -22,7 +22,6 @@ * @brief Two Wire Interface constants. * * @defgroup twoWire I2C constants - * @ingroup internals * @details Two Wire Interface library. * @{ */ @@ -60,4 +59,4 @@ const uint8_t I2C_NO_PULLUPS = 0; /** Enable internal pull-ups on SDA and SCL. Used by TwiMaster class. */ const uint8_t I2C_INTERNAL_PULLUPS = 1; #endif // I2cConstants_h -/** @} */ \ No newline at end of file +/** @} */ diff --git a/hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp b/hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp index e2b842bec..b34034265 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp +++ b/hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp @@ -25,6 +25,7 @@ * @details Two Wire Interface library. * @{ */ +#if defined(__AVR__) || defined(DOXYGEN) // AVR only #include "PinIO.h" #include #include @@ -54,20 +55,21 @@ bool PinIO::begin(uint8_t pin) return true; } //------------------------------------------------------------------------------ -/** Configure the pin +/** Configure the pin. * - * @param[in] mode Configure as output mode if true else input mode. - * @param[in] data For output mode set pin high if true else low. - * For input mode enable 20K pullup if true else Hi-Z. + * @param[in] mode: INPUT or OUTPUT. + * @param[in] level If mode is OUTPUT, set level high/low. + * If mode is INPUT, enable or disable the pin's 20K pullup. * * This function may be used with interrupts enabled or disabled. * The previous interrupt state will be restored. */ -void PinIO::config(bool mode, bool data) +void PinIO::config(uint8_t mode, bool level) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { modeI(mode); - writeI(data); + writeI(level); } } +#endif // __AVR__ /** @} */ diff --git a/hal/architecture/AVR/drivers/DigitalIO/PinIO.h b/hal/architecture/AVR/drivers/DigitalIO/PinIO.h index 694646031..2bb218e2e 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/PinIO.h +++ b/hal/architecture/AVR/drivers/DigitalIO/PinIO.h @@ -22,16 +22,15 @@ * @brief Digital AVR port I/O with runtime pin number. * * @defgroup runtimeDigital Runtime Pin I/O - * @ingroup internals * @details Two Wire Interface library. * @{ */ #ifndef PinIO_h #define PinIO_h +#if defined(__AVR__) || defined(DOXYGEN) // AVR only +#include #include #include -/** @brief Helper macro for complex inline attributes */ -#define ALWAYS_INLINE inline __attribute__((always_inline)) //------------------------------------------------------------------------------ /** * @class PinIO @@ -41,33 +40,15 @@ class PinIO { public: /** Create a PinIO object with no assigned pin. */ - // Suppress warning about uninitialized variables because initializing them in an init function - // allows the compiler to optimize away the variables in case the class is only instantiated but - // never used. // cppcheck-suppress uninitMemberVar PinIO() : bit_(0), mask_(0XFF) {} - /** Constructor - * @param[in] pin Pin assigned to this object. - */ explicit PinIO(uint8_t pin); - /** Initialize pin bit mask and port address. - * @param[in] pin Arduino board pin number. - * @return true for success or false if invalid pin number. - */ bool begin(uint8_t pin); - /** Configure the pin - * - * @param[in] mode Configure as output mode if true else input mode. - * @param[in] data For output mode set pin high if true else low. - * For input mode enable 20K pullup if true else Hi-Z. - * - * This function may be used with interrupts enabled or disabled. - * The previous interrupt state will be restored. - */ - void config(bool mode, bool data); + void config(uint8_t mode, bool data); //---------------------------------------------------------------------------- /** @return Pin's level */ - ALWAYS_INLINE bool read() + inline __attribute__((always_inline)) + bool read() { return *pinReg_ & bit_; } @@ -77,7 +58,8 @@ class PinIO * If the pin is in output mode toggle the pin's level. * If the pin is in input mode toggle the state of the 20K pullup. */ - ALWAYS_INLINE void toggle() + inline __attribute__((always_inline)) + void toggle() { *pinReg_ = bit_; } @@ -88,7 +70,8 @@ class PinIO * This function must be called with interrupts disabled. * This function will not change the interrupt state. */ - ALWAYS_INLINE void highI() + inline __attribute__((always_inline)) + void highI() { writeI(1); } @@ -98,24 +81,31 @@ class PinIO * This function must be called with interrupts disabled. * This function will not change the interrupt state. */ - ALWAYS_INLINE void lowI() + inline __attribute__((always_inline)) + void lowI() { writeI(0); } - /** - * Set pin mode - * @param[in] mode if true set output mode else input mode. + /** Set pin mode. + * + * @param[in] mode: INPUT, OUTPUT, or INPUT_PULLUP. * - * mode() does not enable or disable the 20K pullup for input mode. + * The internal pullup resistors will be enabled if mode is INPUT_PULLUP + * and disabled if the mode is INPUT. * * This function must be called with interrupts disabled. * This function will not change the interrupt state. */ - ALWAYS_INLINE void modeI(bool mode) + inline __attribute__((always_inline)) + void modeI(uint8_t mode) { volatile uint8_t* ddrReg = pinReg_ + 1; - *ddrReg = mode ? *ddrReg | bit_ : *ddrReg & mask_; + *ddrReg = mode == OUTPUT ? *ddrReg | bit_ : *ddrReg & mask_; + if (mode != OUTPUT) { + writeI(mode == INPUT_PULLUP); + } } + /** Write pin. * * @param[in] level If output mode set pin high if true else low. @@ -124,7 +114,8 @@ class PinIO * This function must be called with interrupts disabled. * This function will not change the interrupt state. */ - ALWAYS_INLINE void writeI(bool level) + inline __attribute__((always_inline)) + void writeI(bool level) { *portReg_ = level ? *portReg_ | bit_ : *portReg_ & mask_; } @@ -135,39 +126,47 @@ class PinIO * This function will enable interrupts. This function should not be * called in an ISR or where interrupts are disabled. */ - ALWAYS_INLINE void high() + inline __attribute__((always_inline)) + void high() { ATOMIC_BLOCK(ATOMIC_FORCEON) { highI(); } } + /** * Set pin level low if output mode or disable 20K pullup if input mode. * * This function will enable interrupts. This function should not be * called in an ISR or where interrupts are disabled. */ - ALWAYS_INLINE void low() + inline __attribute__((always_inline)) + void low() { ATOMIC_BLOCK(ATOMIC_FORCEON) { lowI(); } } + /** - * Set pin mode - * @param[in] pinMode if true set output mode else input mode. + * Set pin mode. + * + * @param[in] mode: INPUT, OUTPUT, or INPUT_PULLUP. * - * mode() does not enable or disable the 20K pullup for input mode. + * The internal pullup resistors will be enabled if mode is INPUT_PULLUP + * and disabled if the mode is INPUT. * * This function will enable interrupts. This function should not be * called in an ISR or where interrupts are disabled. */ - ALWAYS_INLINE void mode(bool pinMode) + inline __attribute__((always_inline)) + void mode(uint8_t mode) { ATOMIC_BLOCK(ATOMIC_FORCEON) { - modeI(pinMode); + modeI(mode); } } + /** Write pin. * * @param[in] level If output mode set pin high if true else low. @@ -176,7 +175,8 @@ class PinIO * This function will enable interrupts. This function should not be * called in an ISR or where interrupts are disabled. */ - ALWAYS_INLINE void write(bool level) + inline __attribute__((always_inline)) + void write(bool level) { ATOMIC_BLOCK(ATOMIC_FORCEON) { writeI(level); @@ -189,5 +189,6 @@ class PinIO volatile uint8_t* pinReg_; volatile uint8_t* portReg_; }; +#endif // __AVR__ #endif // PinIO_h /** @} */ diff --git a/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp index e504d3fc2..e3c6d372a 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp +++ b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp @@ -17,9 +17,10 @@ * along with the Arduino DigitalIO Library. If not, see * . */ +#if defined(__AVR__) || defined(DOXYGEN) // AVR only /** * @file - * @brief Software I2C library + * @brief AVR Software I2C library * * @defgroup softI2C Software I2C * @details Software Two Wire Interface library. @@ -55,10 +56,10 @@ bool I2cMasterBase::transfer(uint8_t addrRW, start(); } if (!write(addrRW)) { - _state = addrRW & I2C_READ ? STATE_RX_ADDR_NACK : STATE_TX_ADDR_NACK; + _state = (addrRW & I2C_READ) ? STATE_RX_ADDR_NACK : STATE_TX_ADDR_NACK; return false; } - _state = addrRW & I2C_READ ? STATE_RX_DATA : STATE_TX_DATA; + _state = (addrRW & I2C_READ) ? STATE_RX_DATA : STATE_TX_DATA; return transferContinue(buf, nbytes, option); } //------------------------------------------------------------------------------ @@ -246,4 +247,6 @@ bool SoftI2cMaster::write(uint8_t data) writeSda(LOW); return rtn == 0; } +#endif // __AVR__ /** @} */ + diff --git a/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h index dd250eb9b..480459270 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h +++ b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h @@ -21,18 +21,14 @@ #define SOFT_I2C_MASTER_H /** * @file - * @brief Software I2C library + * @brief AVR Software I2C library * * @defgroup softI2C Software I2C - * @ingroup internals * @details Software Two Wire Interface library. * @{ */ -#if ARDUINO < 100 -#error Requires Arduino 1.0 or greater. -#else // ARDUINO +#if defined(__AVR__) || defined(DOXYGEN) // AVR only #include -#endif // ARDUINO #include #include "DigitalPin.h" #include "I2cConstants.h" @@ -92,45 +88,9 @@ class I2cMasterBase */ virtual void stop() = 0; - /** - * Start an I2C transfer with possible continuation. - * - * @param[in] addressRW I2C slave address plus R/W bit. - * The I2C slave address is in the high seven bits - * and is ORed with on of the following: - * - I2C_READ for a read transfer. - * - I2C_WRITE for a write transfer. - * . - * @param[in,out] buf Source or destination for transfer. - * @param[in] nbyte Number of bytes to transfer (may be zero). - * @param[in] option Option for ending the transfer, one of: - * - I2C_STOP end the transfer with an I2C stop - * condition. - * - I2C_REP_START end the transfer with an I2C - * repeated start condition. - * - I2C_CONTINUE allow additional transferContinue() - * calls. - * . - * @return true for success else false. - */ bool transfer(uint8_t addressRW, void *buf, size_t nbyte, uint8_t option = I2C_STOP); - /** - * Continue an I2C transfer. - * - * @param[in,out] buf Source or destination for transfer. - * @param[in] nbyte Number of bytes to transfer (may be zero). - * @param[in] option Option for ending the transfer, one of: - * - I2C_STOP end the transfer with an I2C stop - * condition. - * - I2C_REP_START end the transfer with an I2C - * repeated start condition. - * - I2C_CONTINUE allow additional transferContinue() - * calls. - * . - * @return true for success else false. - */ bool transferContinue(void *buf, size_t nbyte, uint8_t option = I2C_STOP); /** Write a byte * @@ -147,27 +107,13 @@ class I2cMasterBase //============================================================================== /** * @class SoftI2cMaster - * @brief Software I2C master class + * @brief AVR Software I2C master class */ class SoftI2cMaster : public I2cMasterBase { public: SoftI2cMaster() {} - /** - * Constructor, initialize SCL/SDA pins and set the bus high. - * - * @param[in] sdaPin The software SDA pin number. - * - * @param[in] sclPin The software SCL pin number. - */ SoftI2cMaster(uint8_t sclPin, uint8_t sdaPin); - /** - * Initialize SCL/SDA pins and set the bus high. - * - * @param[in] sdaPin The software SDA pin number. - * - * @param[in] sclPin The software SCL pin number. - */ void begin(uint8_t sclPin, uint8_t sdaPin); uint8_t read(uint8_t last); void start(); @@ -224,7 +170,7 @@ class SoftI2cMaster : public I2cMasterBase //------------------------------------------------------------------------------ /** * @class FastI2cMaster - * @brief Fast software I2C master class. + * @brief AVR Fast software I2C master class. */ template class FastI2cMaster : public I2cMasterBase @@ -323,13 +269,13 @@ class FastI2cMaster : public I2cMasterBase inline __attribute__((always_inline)) void sclWrite(bool value) { - fastPinMode(sclPin, !value); + fastDdrWrite(sclPin, !value); } //---------------------------------------------------------------------------- inline __attribute__((always_inline)) void sdaWrite(bool value) { - fastPinMode(sdaPin, !value); + fastDdrWrite(sdaPin, !value); } //---------------------------------------------------------------------------- inline __attribute__((always_inline)) @@ -362,6 +308,7 @@ class FastI2cMaster : public I2cMasterBase sclDelay(5); } }; +#endif // __AVR__ #endif // SOFT_I2C_MASTER_H /** @} */ diff --git a/hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h b/hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h index d71405521..1cccc9d03 100644 --- a/hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h +++ b/hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h @@ -22,7 +22,6 @@ * @brief Software SPI. * * @defgroup softSPI Software SPI - * @ingroup internals * @details Software SPI Template Class. * @{ */ @@ -35,13 +34,13 @@ #define nop asm volatile ("nop\n\t") //------------------------------------------------------------------------------ /** Pin Mode for MISO is input.*/ -const bool MISO_MODE = false; +#define MISO_MODE INPUT /** Pullups disabled for MISO are disabled. */ -const bool MISO_LEVEL = false; +#define MISO_LEVEL false /** Pin Mode for MOSI is output.*/ -const bool MOSI_MODE = true; +#define MOSI_MODE OUTPUT /** Pin Mode for SCK is output. */ -const bool SCK_MODE = true; +#define SCK_MODE OUTPUT //------------------------------------------------------------------------------ /** * @class SoftSPI @@ -63,7 +62,8 @@ class SoftSPI /** Soft SPI receive byte. * @return Data byte received. */ - ALWAYS_INLINE uint8_t receive() + inline __attribute__((always_inline)) + uint8_t receive() { uint8_t data = 0; receiveBit(7, &data); @@ -80,7 +80,8 @@ class SoftSPI /** Soft SPI send byte. * @param[in] data Data byte to send. */ - ALWAYS_INLINE void send(uint8_t data) + inline __attribute__((always_inline)) + void send(uint8_t data) { sendBit(7, data); sendBit(6, data); @@ -96,7 +97,8 @@ class SoftSPI * @param[in] txData Data byte to send. * @return Data byte received. */ - ALWAYS_INLINE uint8_t transfer(uint8_t txData) + inline __attribute__((always_inline)) + uint8_t transfer(uint8_t txData) { uint8_t rxData = 0; transferBit(7, &rxData, txData); @@ -112,15 +114,18 @@ class SoftSPI private: //---------------------------------------------------------------------------- - ALWAYS_INLINE bool MODE_CPHA(uint8_t mode) + inline __attribute__((always_inline)) + bool MODE_CPHA(uint8_t mode) { return (mode & 1) != 0; } - ALWAYS_INLINE bool MODE_CPOL(uint8_t mode) + inline __attribute__((always_inline)) + bool MODE_CPOL(uint8_t mode) { return (mode & 2) != 0; } - ALWAYS_INLINE void receiveBit(uint8_t bit, uint8_t* data) + inline __attribute__((always_inline)) + void receiveBit(uint8_t bit, uint8_t* data) { if (MODE_CPHA(Mode)) { fastDigitalWrite(SckPin, !MODE_CPOL(Mode)); @@ -137,7 +142,8 @@ class SoftSPI } } //---------------------------------------------------------------------------- - ALWAYS_INLINE void sendBit(uint8_t bit, uint8_t data) + inline __attribute__((always_inline)) + void sendBit(uint8_t bit, uint8_t data) { if (MODE_CPHA(Mode)) { fastDigitalWrite(SckPin, !MODE_CPOL(Mode)); @@ -152,7 +158,8 @@ class SoftSPI } } //---------------------------------------------------------------------------- - ALWAYS_INLINE void transferBit(uint8_t bit, uint8_t* rxData, uint8_t txData) + inline __attribute__((always_inline)) + void transferBit(uint8_t bit, uint8_t* rxData, uint8_t txData) { if (MODE_CPHA(Mode)) { fastDigitalWrite(SckPin, !MODE_CPOL(Mode)); diff --git a/hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h b/hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h deleted file mode 100644 index 4e6f5d8ba..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef ADS7818_h -#define ADS7871_h -//------------------------------------------------------------------------------ -/** nop to tune soft SPI timing */ -#define nop asm volatile ("nop\n\t") -//------------------------------------------------------------------------------ -/** doxygen can't handle __attribute__ very well */ -#define STATIC_ALWAYS_INLINE static inline __attribute__((always_inline)) -//------------------------------------------------------------------------------ -template -/** ADS7818 class */ -class ADS7818 -{ -public: - //---------------------------------------------------------------------------- - /** Set pin modes and initial levels. */ - void begin() - { - fastPinMode(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - fastPinMode(ConvPin, 1); - fastDigitalWrite(ConvPin, 1); - fastPinMode(DataPin, 0); - } - //---------------------------------------------------------------------------- - /** Read ADS7818 12-bit ADC - * \return 16-bit value read. - */ - inline __attribute__((always_inline)) - uint16_t read() - { - uint16_t v = 0; - fastDigitalWrite(ConvPin, 0); - fastDigitalWrite(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - fastDigitalWrite(ConvPin, 1); - fastDigitalWrite(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - - readBitFast16(v, 11); - readBitFast16(v, 10); - readBitFast16(v, 9); - readBitFast16(v, 8); - readBitFast16(v, 7); - readBitFast16(v, 6); - readBitFast16(v, 5); - readBitFast16(v, 4); - readBitFast16(v, 3); - readBitFast16(v, 2); - readBitFast16(v, 1); - readBitFast16(v, 0); - return v; - } -private: - //---------------------------------------------------------------------------- - inline __attribute__((always_inline)) - void readBitFast16(uint16_t &v, uint8_t b) - { - fastDigitalWrite(ClkPin, 1); - if (fastDigitalRead(DataPin)) { - v |= (1 << b); - } - fastDigitalWrite(ClkPin, 0); - } -}; -#if 0 -/** initialize I/O ports */ -STATIC_ALWAYS_INLINE void adcBegin() -{ - fastPinMode(ADC_CLK_PIN, 1); - fastDigitalWrite(ADC_CLK_PIN, 0); - fastPinMode(ADC_CONV_PIN, 1); - fastDigitalWrite(ADC_CONV_PIN, 1); - fastPinMode(ADC_DATA_PIN, 0); -} -//------------------------------------------------------------------------------ -/** clock for don't care bits - *\param[in] delayBefore if true, delay before raising clock*/ -STATIC_ALWAYS_INLINE void fastDummy(bool first) -{ - if (!first) { - nop; - } - fastDigitalWrite(ADC_CLK_PIN, 1); - nop; - fastDigitalWrite(ADC_CLK_PIN, 0); -} -//------------------------------------------------------------------------------ -/** read next bit fast as possible - * \param[in] v word to receive bit - * \param[in] b bit number to be set. v |= (1 << b) if next bit is high. - */ -STATIC_ALWAYS_INLINE void readBitFast16(uint16_t &v, uint8_t b) -{ - fastDigitalWrite(ADC_CLK_PIN, 1); - if (fastDigitalRead(ADC_DATA_PIN)) { - v |= (1 << b); - } - fastDigitalWrite(ADC_CLK_PIN, 0); -} -//------------------------------------------------------------------------------ -/** Read AD7680 16-bit ADC in less than 8 microseconds - * cs is chip select pin - */ -STATIC_ALWAYS_INLINE uint16_t adcRead(bool centered = false) -{ - uint16_t v = 0; - fastDigitalWrite(ADC_CONV_PIN, 0); - fastDigitalWrite(ADC_CLK_PIN, 1); - fastDigitalWrite(ADC_CLK_PIN, 0); - fastDigitalWrite(ADC_CONV_PIN, 1); - fastDigitalWrite(ADC_CLK_PIN, 1); - fastDigitalWrite(ADC_CLK_PIN, 0); - // uint16_t v = 0; - - // fastDummy(1); - // fastDummy(0); - // fastDummy(0); - // fastDummy(0); - - // readBitFast16(v, 15); - // readBitFast16(v, 14); - // readBitFast16(v, 13); - // readBitFast16(v, 12); - readBitFast16(v, 11); - readBitFast16(v, 10); - readBitFast16(v, 9); - readBitFast16(v, 8); - readBitFast16(v, 7); - readBitFast16(v, 6); - readBitFast16(v, 5); - readBitFast16(v, 4); - readBitFast16(v, 3); - readBitFast16(v, 2); - readBitFast16(v, 1); - readBitFast16(v, 0); - return centered ? v ^ 0X8000 : v; -} -#endif // 0 -#endif // ADS7818_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h b/hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h deleted file mode 100644 index 9da32dc5a..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h +++ /dev/null @@ -1,305 +0,0 @@ -#ifndef MCP320X_h -#define MCP320X_h -#include -//============================================================================== -template -/** MCP3201 class */ -class MCP3201 -{ -public: - //---------------------------------------------------------------------------- - /** Set pin modes and initial levels. */ - void begin() - { - fastPinMode(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - fastPinMode(CsPin, 1); - fastDigitalWrite(CsPin, 1); - fastPinMode(DoutPin, 0); - } - //---------------------------------------------------------------------------- - /** Read MCP3201 12-bit ADC - * \return 16-bit value read. - */ - inline __attribute__((always_inline)) - uint16_t read() - { - fastDigitalWrite(CsPin, 0); - // Start sample. - mcpAdcDummy(3); - // Extra sample time. - if (UsecDelay) { - delayMicroseconds(UsecDelay); - } - // End sample. - mcpAdcDummy(3); - // Null bit. - mcpAdcDummy(3); - uint16_t v = 0; - readBit(v, 11); - readBit(v, 10); - readBit(v, 9); - readBit(v, 8); - readBit(v, 7); - readBit(v, 6); - readBit(v, 5); - readBit(v, 4); - readBit(v, 3); - readBit(v, 2); - readBit(v, 1); - readBit(v, 0); - fastDigitalWrite(CsPin, 1); - return v; - } -private: - //---------------------------------------------------------------------------- - /** delay n nops - * \param[in] n nops to delay, must be a constant so compiler optimizes if(). - */ - inline __attribute__((always_inline)) - void delayCycles(uint8_t n) - { - if (n & 1) { - asm volatile("nop\n\t"); - } - if (n & 2) { - asm volatile("nop\n\t" "nop\n\t"); - } - if (n & 4) { - asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t"); - } - } - //---------------------------------------------------------------------------- - /** clock for don't care bits - *\param[in] delayBefore if true, delay before raising clock*/ - inline __attribute__((always_inline)) - void mcpAdcDummy(uint8_t delayBefore) - { - delayCycles(delayBefore); - fastDigitalWrite(ClkPin, 1); - delayCycles(3); - fastDigitalWrite(ClkPin, 0); - } - //---------------------------------------------------------------------------- - inline __attribute__((always_inline)) - void readBit(uint16_t &v, uint8_t b, uint8_t delayRead = 2) - { - delayCycles(3); - fastDigitalWrite(ClkPin, 1); - delayCycles(delayRead); - if (fastDigitalRead(DoutPin)) { - v |= (1 << b); - } - fastDigitalWrite(ClkPin, 0); - } -}; -//============================================================================== -template -/** MCP3202 class */ -class MCP3202 -{ -public: - //---------------------------------------------------------------------------- - /** Set pin modes and initial levels. */ - void begin() - { - fastPinMode(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - fastPinMode(CsPin, 1); - fastDigitalWrite(CsPin, 1); - fastPinMode(DoutPin, 0); - fastPinMode(DinPin, 1); - } - //---------------------------------------------------------------------------- - /** Read MCP3202 12-bit ADC - * \return 16-bit value read. - */ - inline __attribute__((always_inline)) - uint16_t read(uint8_t config) - { - uint16_t v = 0; - fastDigitalWrite(CsPin, 0); - // Start bit. - writeBit(true); - // Mode bit. - writeBit(config & 2); - // Channel Selection and start sample. - writeBit(config & 1); - // Extra sample time. - if (UsecDelay) { - delayMicroseconds(UsecDelay); - } - // MSB first format and end sample. - writeBit(true); - // Null bit. - writeBit(true); - // Data bits. - readBit(v, 11); - readBit(v, 10); - readBit(v, 9); - readBit(v, 8); - readBit(v, 7); - readBit(v, 6); - readBit(v, 5); - readBit(v, 4); - readBit(v, 3); - readBit(v, 2); - readBit(v, 1); - readBit(v, 0); - fastDigitalWrite(CsPin, 1); - return v; - } -private: - //---------------------------------------------------------------------------- - /** delay n nops - * \param[in] n nops to delay, must be a constant so compiler optimizes if(). - */ - inline __attribute__((always_inline)) - void delayCycles(uint8_t n) - { - if (n & 1) { - asm volatile("nop\n\t"); - } - if (n & 2) { - asm volatile("nop\n\t" "nop\n\t"); - } - if (n & 4) { - asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t"); - } - } - //---------------------------------------------------------------------------- - /** clock for don't care bits - *\param[in] delayBefore if true, delay before raising clock*/ - inline __attribute__((always_inline)) - void writeBit(bool value) - { - fastDigitalWrite(DinPin, value); - fastDigitalWrite(ClkPin, 1); - delayCycles(2); - fastDigitalWrite(ClkPin, 0); - } - //---------------------------------------------------------------------------- - inline __attribute__((always_inline)) - void readBit(uint16_t &v, uint8_t b, uint8_t delayRead = 1) - { - delayCycles(2); - fastDigitalWrite(ClkPin, 1); - delayCycles(delayRead); - if (fastDigitalRead(DoutPin)) { - v |= (1 << b); - } - fastDigitalWrite(ClkPin, 0); - } -}; -//============================================================================== -template -/** MCP3204 class */ -class MCP3204 -{ -public: - //---------------------------------------------------------------------------- - /** Set pin modes and initial levels. */ - void begin() - { - fastPinMode(ClkPin, 1); - fastDigitalWrite(ClkPin, 0); - fastPinMode(CsPin, 1); - fastDigitalWrite(CsPin, 1); - fastPinMode(DoutPin, 0); - fastPinMode(DinPin, 1); - } - //---------------------------------------------------------------------------- - /** Read MCP3204 12-bit ADC - * \return 16-bit value read. - */ - inline __attribute__((always_inline)) - uint16_t read(uint8_t config) - { - uint16_t v = 0; - fastDigitalWrite(CsPin, 0); - // Start bit. - writeBit(true); - // Mode bit. - writeBit(config & 8); - // D2 channel bit. - writeBit(config & 4); - // D1 channel bit. - writeBit(config & 2); - // D0 channel bit and start sample. - writeBit(config & 1); - // Extra sample time. - if (UsecDelay) { - delayMicroseconds(UsecDelay); - } - // End sample cycle. - writeBit(true); - // Null bit. - writeBit(true); - // Data bits. - readBit(v, 11); - readBit(v, 10); - readBit(v, 9); - readBit(v, 8); - readBit(v, 7); - readBit(v, 6); - readBit(v, 5); - readBit(v, 4); - readBit(v, 3); - readBit(v, 2); - readBit(v, 1); - readBit(v, 0); - fastDigitalWrite(CsPin, 1); - return v; - } -private: - //---------------------------------------------------------------------------- - /** delay n nops - * \param[in] n nops to delay, must be a constant so compiler optimizes if(). - */ - inline __attribute__((always_inline)) - void delayCycles(uint8_t n) - { - if (n & 1) { - asm volatile("nop\n\t"); - } - if (n & 2) { - asm volatile("nop\n\t" "nop\n\t"); - } - if (n & 4) { - asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t"); - } - } - //---------------------------------------------------------------------------- - /** clock for don't care bits - *\param[in] delayBefore if true, delay before raising clock*/ - inline __attribute__((always_inline)) - void writeBit(bool value) - { - fastDigitalWrite(DinPin, value); - fastDigitalWrite(ClkPin, 1); - delayCycles(2); - fastDigitalWrite(ClkPin, 0); - } - //---------------------------------------------------------------------------- - inline __attribute__((always_inline)) - void readBit(uint16_t &v, uint8_t b, uint8_t delayRead = 1) - { - delayCycles(2); - fastDigitalWrite(ClkPin, 1); - delayCycles(delayRead); - if (fastDigitalRead(DoutPin)) { - v |= (1 << b); - } - fastDigitalWrite(ClkPin, 0); - } -}; -//============================================================================== -// MCP3204 and MCP3208 use the same code. -template -class MCP3208 : public MCP3204 -{ -}; -#endif // MCP320X_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h b/hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h deleted file mode 100644 index fb66d4a47..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef MCP355X_h -#define MCP355X_h -#include -// Overflow values. -const int32_t MCP355X_OVH = 2097152L; -const int32_t MCP355X_OVL = -2097153L; -const int32_t MCP355X_ERR = 0X80000000; -const uint8_t MCP355X_TO_MS = 100; -//============================================================================== -template -/** MCP355X class */ -class MCP355X -{ -public: - //---------------------------------------------------------------------------- - /** Set pin modes and initial levels. */ - void begin(bool singleMode = true) - { - m_singleMode = singleMode; - fastPinMode(SdoPin, 0); - fastPinMode(SckPin, 1); - fastDigitalWrite(SckPin, 1); - fastPinMode(CsPin, 1); - fastDigitalWrite(CsPin, 1); - if (!m_singleMode) { - // Wait for conversion to complete. - delay(100); - // Start continuous conversion mode. - fastDigitalWrite(CsPin, 0); - } - } - //---------------------------------------------------------------------------- - /** Read MCP355X 22-bit ADC - * \return 22-bit value. - */ - inline __attribute__((always_inline)) - int32_t read() - { - uint8_t t = 0; - uint8_t v3 = 0; - if (m_singleMode) { - // Start conversion. - fastDigitalWrite(CsPin, 0); - // Delay at least 10 usec to avoid RDY glitch on exit from Shutdown. - delay(1); - // Toggle CsPin to indicate single conversion mode. - fastDigitalWrite(CsPin, 1); - // Wait for conversion to complete. - while (1) { - delay(1); - fastDigitalWrite(CsPin, 0); - // Delay while RDY settles. - delayCycles(4); - if (!fastDigitalRead(SdoPin)) { - break; - } - fastDigitalWrite(CsPin, 1); - if (t++ > MCP355X_TO_MS) { - return MCP355X_ERR; - } - } - } else { - while (1) { - if (!fastDigitalRead(SdoPin)) { - break; - } - delay(1); - if (t++ > MCP355X_TO_MS) { - return MCP355X_ERR; - } - } - } - uint8_t v2 = readByte(); - uint8_t v1 = readByte(); - uint8_t v0 = readByte(); - - // The 25th falling edge of SCK changes SDO/RDY from Data mode to RDY mode. - uint8_t dummy = 0; - readBit(dummy, 0); - - if (m_singleMode) { - fastDigitalWrite(CsPin, 1); - } - if ((v2 & 0XE0) == 0X20) { - // Negative in range so extend sign bit. - v2 |= 0XC0; - v3 = 0XFF; - } else if (v2 & 0X40) { - // Overflow high. Cause value to be >= MCP355X_OVH. - if (v2 & 0X20) { - v2 &= 0X3F; - } - } else if (v2 & 0X80) { - // Overflow low. Cause value to be <= MCP355X_OVH. - if ((v2 & 0X20) == 0) { - v2 |= 0X40; - } - v3 = 0XFF; - } - uint16_t v_high = (v3 << 8) | v2; - uint16_t v_low = (v1 << 8) | v0; - return ((uint32_t)v_high << 16) | v_low; - } -private: - //---------------------------------------------------------------------------- - /** delay n nops - * \param[in] n nops to delay, must be a constant so compiler optimizes if(). - */ - inline __attribute__((always_inline)) - void delayCycles(uint8_t n) - { - if (n & 1) { - asm volatile("nop\n\t"); - } - if (n & 2) { - asm volatile("nop\n\t" "nop\n\t"); - } - if (n & 4) { - asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t"); - } - } - //---------------------------------------------------------------------------- - // Default delay yields about 2 MHz clock. - inline __attribute__((always_inline)) - void readBit(uint8_t &v, uint8_t b, uint8_t delayRead = 0) - { - fastDigitalWrite(SckPin, 0); - delayCycles(2 + delayRead); - fastDigitalWrite(SckPin, 1); - if (fastDigitalRead(SdoPin)) { - v |= (1 << b); - } - delayCycles(delayRead); - } - //---------------------------------------------------------------------------- - inline __attribute__((always_inline)) - uint8_t readByte() - { - uint8_t v = 0; - readBit(v, 7); - readBit(v, 6); - readBit(v, 5); - readBit(v, 4); - readBit(v, 3); - readBit(v, 2); - readBit(v, 1); - readBit(v, 0); - return v; - } - //---------------------------------------------------------------------------- - bool m_singleMode; -}; -#endif // MCP355X_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/AvrDevelopersGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/AvrDevelopersGpioPinMap.h new file mode 100644 index 000000000..3da106316 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/AvrDevelopersGpioPinMap.h @@ -0,0 +1,37 @@ +#ifndef AvrDevelopersGpioPinMap_h +#define AvrDevelopersGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(B, 0), // D0 + GPIO_PIN(B, 1), // D1 + GPIO_PIN(B, 2), // D2 + GPIO_PIN(B, 3), // D3 + GPIO_PIN(B, 4), // D4 + GPIO_PIN(B, 5), // D5 + GPIO_PIN(B, 6), // D6 + GPIO_PIN(B, 7), // D7 + GPIO_PIN(D, 0), // D8 + GPIO_PIN(D, 1), // D9 + GPIO_PIN(D, 2), // D10 + GPIO_PIN(D, 3), // D11 + GPIO_PIN(D, 4), // D12 + GPIO_PIN(D, 5), // D13 + GPIO_PIN(D, 6), // D14 + GPIO_PIN(D, 7), // D15 + GPIO_PIN(C, 0), // D16 + GPIO_PIN(C, 1), // D17 + GPIO_PIN(C, 2), // D18 + GPIO_PIN(C, 3), // D19 + GPIO_PIN(C, 4), // D20 + GPIO_PIN(C, 5), // D21 + GPIO_PIN(C, 6), // D22 + GPIO_PIN(C, 7), // D23 + GPIO_PIN(A, 7), // D24 + GPIO_PIN(A, 6), // D25 + GPIO_PIN(A, 5), // D26 + GPIO_PIN(A, 4), // D27 + GPIO_PIN(A, 3), // D28 + GPIO_PIN(A, 2), // D29 + GPIO_PIN(A, 1), // D30 + GPIO_PIN(A, 0) // D31 +}; +#endif // AvrDevelopersGpioPinMap_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/BobuinoGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/BobuinoGpioPinMap.h new file mode 100644 index 000000000..170611a55 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/BobuinoGpioPinMap.h @@ -0,0 +1,37 @@ +#ifndef BobuinoGpioPinMap_h +#define BobuinoGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(B, 0), // D0 + GPIO_PIN(B, 1), // D1 + GPIO_PIN(B, 2), // D2 + GPIO_PIN(B, 3), // D3 + GPIO_PIN(B, 4), // D4 + GPIO_PIN(B, 5), // D5 + GPIO_PIN(B, 6), // D6 + GPIO_PIN(B, 7), // D7 + GPIO_PIN(D, 0), // D8 + GPIO_PIN(D, 1), // D9 + GPIO_PIN(D, 2), // D10 + GPIO_PIN(D, 3), // D11 + GPIO_PIN(D, 4), // D12 + GPIO_PIN(D, 5), // D13 + GPIO_PIN(D, 6), // D14 + GPIO_PIN(D, 7), // D15 + GPIO_PIN(C, 0), // D16 + GPIO_PIN(C, 1), // D17 + GPIO_PIN(C, 2), // D18 + GPIO_PIN(C, 3), // D19 + GPIO_PIN(C, 4), // D20 + GPIO_PIN(C, 5), // D21 + GPIO_PIN(C, 6), // D22 + GPIO_PIN(C, 7), // D23 + GPIO_PIN(A, 0), // D24 + GPIO_PIN(A, 1), // D25 + GPIO_PIN(A, 2), // D26 + GPIO_PIN(A, 3), // D27 + GPIO_PIN(A, 4), // D28 + GPIO_PIN(A, 5), // D29 + GPIO_PIN(A, 6), // D30 + GPIO_PIN(A, 7) // D31 +}; +#endif // BobuinoGpioPinMap_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/GpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/GpioPinMap.h new file mode 100644 index 000000000..901ad3e78 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/GpioPinMap.h @@ -0,0 +1,64 @@ +/* Arduino DigitalIO Library + * Copyright (C) 2013 by William Greiman + * + * This file is part of the Arduino DigitalIO Library + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the Arduino DigitalIO Library. If not, see + * . + */ +#ifndef GpioPinMap_h +#define GpioPinMap_h +#if defined(__AVR_ATmega168__)\ +||defined(__AVR_ATmega168P__)\ +||defined(__AVR_ATmega328P__) +// 168 and 328 Arduinos +#include "UnoGpioPinMap.h" +#elif defined(__AVR_ATmega1280__)\ +|| defined(__AVR_ATmega2560__) +// Mega ADK +#include "MegaGpioPinMap.h" +#elif defined(__AVR_ATmega32U4__) +#ifdef CORE_TEENSY +#include "Teensy2GpioPinMap.h" +#else // CORE_TEENSY +// Leonardo or Yun +#include "LeonardoGpioPinMap.h" +#endif // CORE_TEENSY +#elif defined(__AVR_AT90USB646__)\ +|| defined(__AVR_AT90USB1286__) +// Teensy++ 1.0 & 2.0 +#include "Teensy2ppGpioPinMap.h" +#elif defined(__AVR_ATmega1284P__)\ +|| defined(__AVR_ATmega1284__)\ +|| defined(__AVR_ATmega644P__)\ +|| defined(__AVR_ATmega644__)\ +|| defined(__AVR_ATmega64__)\ +|| defined(__AVR_ATmega32__)\ +|| defined(__AVR_ATmega324__)\ +|| defined(__AVR_ATmega16__) +#ifdef ARDUINO_1284P_AVR_DEVELOPERS +#include "AvrDevelopersGpioPinMap.h" +#elif defined(ARDUINO_1284P_BOBUINO) +#include "BobuinoGpioPinMap.h" +#elif defined(ARDUINO_1284P_SLEEPINGBEAUTY) +#include "SleepingBeautyGpioPinMap.h" +#elif defined(ARDUINO_1284P_STANDARD) +#include "Standard1284GpioPinMap.h" +#else // ARDUINO_1284P_SLEEPINGBEAUTY +#error Undefined variant 1284, 644, 324 +#endif // ARDUINO_1284P_SLEEPINGBEAUTY +#else // 1284P, 1284, 644 +#error Unknown board type. +#endif // end all boards +#endif // GpioPinMap_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/LeonardoGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/LeonardoGpioPinMap.h new file mode 100644 index 000000000..48e173453 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/LeonardoGpioPinMap.h @@ -0,0 +1,35 @@ +#ifndef LeonardoGpioPinMap_h +#define LeonardoGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(D, 2), // D0 + GPIO_PIN(D, 3), // D1 + GPIO_PIN(D, 1), // D2 + GPIO_PIN(D, 0), // D3 + GPIO_PIN(D, 4), // D4 + GPIO_PIN(C, 6), // D5 + GPIO_PIN(D, 7), // D6 + GPIO_PIN(E, 6), // D7 + GPIO_PIN(B, 4), // D8 + GPIO_PIN(B, 5), // D9 + GPIO_PIN(B, 6), // D10 + GPIO_PIN(B, 7), // D11 + GPIO_PIN(D, 6), // D12 + GPIO_PIN(C, 7), // D13 + GPIO_PIN(B, 3), // D14 + GPIO_PIN(B, 1), // D15 + GPIO_PIN(B, 2), // D16 + GPIO_PIN(B, 0), // D17 + GPIO_PIN(F, 7), // D18 + GPIO_PIN(F, 6), // D19 + GPIO_PIN(F, 5), // D20 + GPIO_PIN(F, 4), // D21 + GPIO_PIN(F, 1), // D22 + GPIO_PIN(F, 0), // D23 + GPIO_PIN(D, 4), // D24 + GPIO_PIN(D, 7), // D25 + GPIO_PIN(B, 4), // D26 + GPIO_PIN(B, 5), // D27 + GPIO_PIN(B, 6), // D28 + GPIO_PIN(D, 6) // D29 +}; +#endif // LeonardoGpioPinMap_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/MegaGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/MegaGpioPinMap.h new file mode 100644 index 000000000..aded09a64 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/MegaGpioPinMap.h @@ -0,0 +1,75 @@ +#ifndef MegaGpioPinMap_h +#define MegaGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(E, 0), // D0 + GPIO_PIN(E, 1), // D1 + GPIO_PIN(E, 4), // D2 + GPIO_PIN(E, 5), // D3 + GPIO_PIN(G, 5), // D4 + GPIO_PIN(E, 3), // D5 + GPIO_PIN(H, 3), // D6 + GPIO_PIN(H, 4), // D7 + GPIO_PIN(H, 5), // D8 + GPIO_PIN(H, 6), // D9 + GPIO_PIN(B, 4), // D10 + GPIO_PIN(B, 5), // D11 + GPIO_PIN(B, 6), // D12 + GPIO_PIN(B, 7), // D13 + GPIO_PIN(J, 1), // D14 + GPIO_PIN(J, 0), // D15 + GPIO_PIN(H, 1), // D16 + GPIO_PIN(H, 0), // D17 + GPIO_PIN(D, 3), // D18 + GPIO_PIN(D, 2), // D19 + GPIO_PIN(D, 1), // D20 + GPIO_PIN(D, 0), // D21 + GPIO_PIN(A, 0), // D22 + GPIO_PIN(A, 1), // D23 + GPIO_PIN(A, 2), // D24 + GPIO_PIN(A, 3), // D25 + GPIO_PIN(A, 4), // D26 + GPIO_PIN(A, 5), // D27 + GPIO_PIN(A, 6), // D28 + GPIO_PIN(A, 7), // D29 + GPIO_PIN(C, 7), // D30 + GPIO_PIN(C, 6), // D31 + GPIO_PIN(C, 5), // D32 + GPIO_PIN(C, 4), // D33 + GPIO_PIN(C, 3), // D34 + GPIO_PIN(C, 2), // D35 + GPIO_PIN(C, 1), // D36 + GPIO_PIN(C, 0), // D37 + GPIO_PIN(D, 7), // D38 + GPIO_PIN(G, 2), // D39 + GPIO_PIN(G, 1), // D40 + GPIO_PIN(G, 0), // D41 + GPIO_PIN(L, 7), // D42 + GPIO_PIN(L, 6), // D43 + GPIO_PIN(L, 5), // D44 + GPIO_PIN(L, 4), // D45 + GPIO_PIN(L, 3), // D46 + GPIO_PIN(L, 2), // D47 + GPIO_PIN(L, 1), // D48 + GPIO_PIN(L, 0), // D49 + GPIO_PIN(B, 3), // D50 + GPIO_PIN(B, 2), // D51 + GPIO_PIN(B, 1), // D52 + GPIO_PIN(B, 0), // D53 + GPIO_PIN(F, 0), // D54 + GPIO_PIN(F, 1), // D55 + GPIO_PIN(F, 2), // D56 + GPIO_PIN(F, 3), // D57 + GPIO_PIN(F, 4), // D58 + GPIO_PIN(F, 5), // D59 + GPIO_PIN(F, 6), // D60 + GPIO_PIN(F, 7), // D61 + GPIO_PIN(K, 0), // D62 + GPIO_PIN(K, 1), // D63 + GPIO_PIN(K, 2), // D64 + GPIO_PIN(K, 3), // D65 + GPIO_PIN(K, 4), // D66 + GPIO_PIN(K, 5), // D67 + GPIO_PIN(K, 6), // D68 + GPIO_PIN(K, 7) // D69 +}; +#endif // MegaGpioPinMap_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/SleepingBeautyGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/SleepingBeautyGpioPinMap.h new file mode 100644 index 000000000..3dacb1f4d --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/SleepingBeautyGpioPinMap.h @@ -0,0 +1,37 @@ +#ifndef SleepingBeautyGpioPinMap_h +#define SleepingBeautyGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(D, 0), // D0 + GPIO_PIN(D, 1), // D1 + GPIO_PIN(D, 2), // D2 + GPIO_PIN(D, 3), // D3 + GPIO_PIN(B, 0), // D4 + GPIO_PIN(B, 1), // D5 + GPIO_PIN(B, 2), // D6 + GPIO_PIN(B, 3), // D7 + GPIO_PIN(D, 6), // D8 + GPIO_PIN(D, 5), // D9 + GPIO_PIN(B, 4), // D10 + GPIO_PIN(B, 5), // D11 + GPIO_PIN(B, 6), // D12 + GPIO_PIN(B, 7), // D13 + GPIO_PIN(C, 7), // D14 + GPIO_PIN(C, 6), // D15 + GPIO_PIN(A, 5), // D16 + GPIO_PIN(A, 4), // D17 + GPIO_PIN(A, 3), // D18 + GPIO_PIN(A, 2), // D19 + GPIO_PIN(A, 1), // D20 + GPIO_PIN(A, 0), // D21 + GPIO_PIN(D, 4), // D22 + GPIO_PIN(D, 7), // D23 + GPIO_PIN(C, 2), // D24 + GPIO_PIN(C, 3), // D25 + GPIO_PIN(C, 4), // D26 + GPIO_PIN(C, 5), // D27 + GPIO_PIN(C, 1), // D28 + GPIO_PIN(C, 0), // D29 + GPIO_PIN(A, 6), // D30 + GPIO_PIN(A, 7) // D31 +}; +#endif // SleepingBeautyGpioPinMap_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/Standard1284GpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/Standard1284GpioPinMap.h new file mode 100644 index 000000000..887797a6c --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/Standard1284GpioPinMap.h @@ -0,0 +1,37 @@ +#ifndef Standard1284GpioPinMap_h +#define Standard1284GpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(B, 0), // D0 + GPIO_PIN(B, 1), // D1 + GPIO_PIN(B, 2), // D2 + GPIO_PIN(B, 3), // D3 + GPIO_PIN(B, 4), // D4 + GPIO_PIN(B, 5), // D5 + GPIO_PIN(B, 6), // D6 + GPIO_PIN(B, 7), // D7 + GPIO_PIN(D, 0), // D8 + GPIO_PIN(D, 1), // D9 + GPIO_PIN(D, 2), // D10 + GPIO_PIN(D, 3), // D11 + GPIO_PIN(D, 4), // D12 + GPIO_PIN(D, 5), // D13 + GPIO_PIN(D, 6), // D14 + GPIO_PIN(D, 7), // D15 + GPIO_PIN(C, 0), // D16 + GPIO_PIN(C, 1), // D17 + GPIO_PIN(C, 2), // D18 + GPIO_PIN(C, 3), // D19 + GPIO_PIN(C, 4), // D20 + GPIO_PIN(C, 5), // D21 + GPIO_PIN(C, 6), // D22 + GPIO_PIN(C, 7), // D23 + GPIO_PIN(A, 0), // D24 + GPIO_PIN(A, 1), // D25 + GPIO_PIN(A, 2), // D26 + GPIO_PIN(A, 3), // D27 + GPIO_PIN(A, 4), // D28 + GPIO_PIN(A, 5), // D29 + GPIO_PIN(A, 6), // D30 + GPIO_PIN(A, 7) // D31 +}; +#endif // Standard1284GpioPinMap_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2GpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2GpioPinMap.h new file mode 100644 index 000000000..90515965b --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2GpioPinMap.h @@ -0,0 +1,30 @@ +#ifndef Teensy2GpioPinMap_h +#define Teensy2GpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(B, 0), // D0 + GPIO_PIN(B, 1), // D1 + GPIO_PIN(B, 2), // D2 + GPIO_PIN(B, 3), // D3 + GPIO_PIN(B, 7), // D4 + GPIO_PIN(D, 0), // D5 + GPIO_PIN(D, 1), // D6 + GPIO_PIN(D, 2), // D7 + GPIO_PIN(D, 3), // D8 + GPIO_PIN(C, 6), // D9 + GPIO_PIN(C, 7), // D10 + GPIO_PIN(D, 6), // D11 + GPIO_PIN(D, 7), // D12 + GPIO_PIN(B, 4), // D13 + GPIO_PIN(B, 5), // D14 + GPIO_PIN(B, 6), // D15 + GPIO_PIN(F, 7), // D16 + GPIO_PIN(F, 6), // D17 + GPIO_PIN(F, 5), // D18 + GPIO_PIN(F, 4), // D19 + GPIO_PIN(F, 1), // D20 + GPIO_PIN(F, 0), // D21 + GPIO_PIN(D, 4), // D22 + GPIO_PIN(D, 5), // D23 + GPIO_PIN(E, 6), // D24 +}; +#endif // Teensy2GpioPinMap_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2ppGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2ppGpioPinMap.h new file mode 100644 index 000000000..e184f6c11 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/Teensy2ppGpioPinMap.h @@ -0,0 +1,51 @@ +#ifndef Teensypp2GpioPinMap_h +#define Teensypp2GpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(D, 0), // D0 + GPIO_PIN(D, 1), // D1 + GPIO_PIN(D, 2), // D2 + GPIO_PIN(D, 3), // D3 + GPIO_PIN(D, 4), // D4 + GPIO_PIN(D, 5), // D5 + GPIO_PIN(D, 6), // D6 + GPIO_PIN(D, 7), // D7 + GPIO_PIN(E, 0), // D8 + GPIO_PIN(E, 1), // D9 + GPIO_PIN(C, 0), // D10 + GPIO_PIN(C, 1), // D11 + GPIO_PIN(C, 2), // D12 + GPIO_PIN(C, 3), // D13 + GPIO_PIN(C, 4), // D14 + GPIO_PIN(C, 5), // D15 + GPIO_PIN(C, 6), // D16 + GPIO_PIN(C, 7), // D17 + GPIO_PIN(E, 6), // D18 + GPIO_PIN(E, 7), // D19 + GPIO_PIN(B, 0), // D20 + GPIO_PIN(B, 1), // D21 + GPIO_PIN(B, 2), // D22 + GPIO_PIN(B, 3), // D23 + GPIO_PIN(B, 4), // D24 + GPIO_PIN(B, 5), // D25 + GPIO_PIN(B, 6), // D26 + GPIO_PIN(B, 7), // D27 + GPIO_PIN(A, 0), // D28 + GPIO_PIN(A, 1), // D29 + GPIO_PIN(A, 2), // D30 + GPIO_PIN(A, 3), // D31 + GPIO_PIN(A, 4), // D32 + GPIO_PIN(A, 5), // D33 + GPIO_PIN(A, 6), // D34 + GPIO_PIN(A, 7), // D35 + GPIO_PIN(E, 4), // D36 + GPIO_PIN(E, 5), // D37 + GPIO_PIN(F, 0), // D38 + GPIO_PIN(F, 1), // D39 + GPIO_PIN(F, 2), // D40 + GPIO_PIN(F, 3), // D41 + GPIO_PIN(F, 4), // D42 + GPIO_PIN(F, 5), // D43 + GPIO_PIN(F, 6), // D44 + GPIO_PIN(F, 7), // D45 +}; +#endif // Teensypp2GpioPinMap_h diff --git a/hal/architecture/AVR/drivers/DigitalIO/boards/UnoGpioPinMap.h b/hal/architecture/AVR/drivers/DigitalIO/boards/UnoGpioPinMap.h new file mode 100644 index 000000000..4b82e82b9 --- /dev/null +++ b/hal/architecture/AVR/drivers/DigitalIO/boards/UnoGpioPinMap.h @@ -0,0 +1,25 @@ +#ifndef UnoGpioPinMap_h +#define UnoGpioPinMap_h +static const GpioPinMap_t GpioPinMap[] = { + GPIO_PIN(D, 0), // D0 + GPIO_PIN(D, 1), // D1 + GPIO_PIN(D, 2), // D2 + GPIO_PIN(D, 3), // D3 + GPIO_PIN(D, 4), // D4 + GPIO_PIN(D, 5), // D5 + GPIO_PIN(D, 6), // D6 + GPIO_PIN(D, 7), // D7 + GPIO_PIN(B, 0), // D8 + GPIO_PIN(B, 1), // D9 + GPIO_PIN(B, 2), // D10 + GPIO_PIN(B, 3), // D11 + GPIO_PIN(B, 4), // D12 + GPIO_PIN(B, 5), // D13 + GPIO_PIN(C, 0), // D14 + GPIO_PIN(C, 1), // D15 + GPIO_PIN(C, 2), // D16 + GPIO_PIN(C, 3), // D17 + GPIO_PIN(C, 4), // D18 + GPIO_PIN(C, 5) // D19 +}; +#endif // UnoGpioPinMap_h \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino deleted file mode 100644 index d8fd19f30..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino +++ /dev/null @@ -1,13 +0,0 @@ -#include -// Create object for pin 13 in output mode and demo toggle(). -DigitalPin<13> pin13(OUTPUT); - -void setup() {} - -void loop() -{ - // toggle is a two byte instruction that executes - // in two cycles or 125 ns on a 16 MHz CPU - pin13.toggle(); - delay(250); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino deleted file mode 100644 index 78a75c989..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino +++ /dev/null @@ -1,20 +0,0 @@ -// Demo of config() and fast toggle() function. -#include - -// Class with compile time pin number. -DigitalPin<13> pin13; - -void setup() -{ - // Set mode to OUTPUT and level LOW. - pin13.config(OUTPUT, LOW); -} -void loop() -{ - // toggle is a two byte instruction that executes - // in two cycles or 125 ns on a 16 MHz CPU - pin13.toggle(); - delay(100); - pin13.toggle(); - delay(400); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino deleted file mode 100644 index 09fb8d2ea..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino +++ /dev/null @@ -1,12 +0,0 @@ -// Read pin 12 and write value to pin 13. -#include - -DigitalPin<12> pin12(INPUT); -DigitalPin<13> pin13(OUTPUT); - -void setup() {} - -void loop() -{ - pin13 = pin12; -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino deleted file mode 100644 index 6a31ee6eb..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino +++ /dev/null @@ -1,43 +0,0 @@ -// Scope test for fast shiftOut function. -#include - -// Create clockPin in output mode with inital level LOW. -DigitalPin<12> clockPin(OUTPUT, LOW); - -// Create dataPin in output mode with inital level HIGH. -DigitalPin<13> dataPin(OUTPUT, HIGH); - -//------------------------------------------------------------------------------ -// Time to send one bit is ten cycles or 625 ns for 16 MHz CPU. -inline __attribute__((always_inline)) -void sendBit(uint8_t bit, uint8_t data) -{ - dataPin = data & (1 << bit); - clockPin = 1; - // may want a nop here - clock pulse is 125 ns wide - clockPin = 0; -} -//------------------------------------------------------------------------------ -// Time to send one byte is 5 usec. -void shiftOut(uint8_t bits) -{ - sendBit(7, bits); - sendBit(6, bits); - sendBit(5, bits); - sendBit(4, bits); - sendBit(3, bits); - sendBit(2, bits); - sendBit(1, bits); - sendBit(0, bits); -} -//------------------------------------------------------------------------------ -void setup() -{ - // Not used. -} -//------------------------------------------------------------------------------ -void loop() -{ - shiftOut(0X55); - delay(2); -} diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino deleted file mode 100644 index 0ddcb1e05..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino +++ /dev/null @@ -1,26 +0,0 @@ -// Use begin to assign pin numbers. -// Read pin 12 and write the value to pin 13. -#include - -// Declare the PinIO instances. -PinIO readPin; -PinIO writePin; -//------------------------------------------------------------------------------ -void setup() -{ - // Assign pin 12 to readPin. - readPin.begin(12); - - // input mode with pull-ups disabled - readPin.config(INPUT, LOW); - - // Assign pin 13 to writePin and set mode to output. - writePin.begin(13); - writePin.mode(OUTPUT); -} -//------------------------------------------------------------------------------ -void loop() -{ - // Copy the value read from readPin to writePin. - writePin.write(readPin.read()); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino deleted file mode 100644 index b9b981845..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino +++ /dev/null @@ -1,18 +0,0 @@ -// Test the config() and toggle() functions. -#include - -// Set runtime pin number. -PinIO pin13(13); - -void setup() -{ - // set mode to OUTPUT and level LOW - pin13.config(OUTPUT, LOW); -} -void loop() -{ - pin13.toggle(); - delay(100); - pin13.toggle(); - delay(400); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino deleted file mode 100644 index 3019a05a4..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino +++ /dev/null @@ -1,18 +0,0 @@ -// Read pin 12 and write the value to pin 13. -#include - -PinIO readPin(12); -PinIO writePin(13); - -void setup() -{ - // Set input mode and disable pull-up. - readPin.config(INPUT, LOW); - - // set output mode - writePin.mode(OUTPUT); -} -void loop() -{ - writePin.write(readPin.read()); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino deleted file mode 100644 index 18e5b6e11..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* Scan I2C bus for devices. - * - * For I2C write addresses: the scanner sends a start, - * the write address, looks for an ACK, then sends a stop. - * - * For I2C read addresses: the scanner sends a start, the - * read address, looks for an ACK. If there is an ACK, it - * reads a byte and NACKs it. Finally it sends a stop. - * - * When the I2C chip responds to the read address, it - * outputs data and will miss a stop condition sent - * immediately after the read address (bus contention). - * - * If the I2C chip misses the stop condition, the - * address scanner will see ghost addresses until the - * read ends randomly. By reading a byte after any read - * address that ACKs, there is a chance to NACK the read - * and properly end the I2C transaction. - */ -#include - -// Set pin numbers for your configuration. -const uint8_t SDA_PIN = A4; -const uint8_t SCL_PIN = A5; - -SoftI2cMaster i2c(SCL_PIN, SDA_PIN); -//FastI2cMaster i2c; -//------------------------------------------------------------------------------ -void setup() -{ - - Serial.begin(9600); - while (!Serial); - - if (!digitalRead(SDA_PIN) && !digitalRead(SCL_PIN)) { - Serial.println("External pull-up resistors appear to be missing."); - Serial.println("Many false responses may be detected."); - Serial.println("Type any character to continue."); - - while (!Serial.available()); - Serial.println(); - - } - uint8_t add = 0; - bool found = false; - do { - bool wr = i2c.transfer(add | I2C_WRITE, 0, 0); - bool rd = i2c.transfer(add | I2C_READ, 0, 0, I2C_CONTINUE); - if (rd) { - uint8_t dummy; - // Must read byte, send NACK, and issue STOP. - i2c.transferContinue(&dummy, 1); - } - if (rd || wr) { - found = true; - Serial.print("Device at address: 0X"); - Serial.print(add, HEX); - Serial.print(" responds to "); - if (rd) { - Serial.print("Read"); - } - if (rd && wr) { - Serial.print(" and "); - } - if (wr) { - Serial.print("Write"); - } - Serial.println('.'); - } - add += 2; - } while (add); - - if (!found) { - Serial.println("No devices found."); - } - Serial.println("Done"); -} -//------------------------------------------------------------------------------ -void loop() -{ - // Not used. -} - - - diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino deleted file mode 100644 index 3009db79a..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino +++ /dev/null @@ -1,365 +0,0 @@ -// Utility sketch to explore DS1307 and demonstrate software I2C Master. -// - -#include - -// Set pin numbers for your configuration. -const uint8_t SDA_PIN = A4; -const uint8_t SCL_PIN = A5; - -//SoftI2cMaster rtc(SCL_PIN, SDA_PIN); -FastI2cMaster rtc; - -// i2c 8-bit address for DS1307. low bit is read/write -#define DS1307ADDR 0XD0 -//------------------------------------------------------------------------------ -/* - * Read 'count' bytes from the DS1307 starting at 'address'. - */ -uint8_t readDS1307(uint8_t address, uint8_t *buf, uint8_t count) -{ - - // Send address of data. - if (!rtc.transfer(DS1307ADDR | I2C_WRITE, &address, 1)) { - return false; - } - - // Read data. - return rtc.transfer(DS1307ADDR | I2C_READ, buf, count); -} -//------------------------------------------------------------------------------ -/* - * write 'count' bytes to DS1307 starting at 'address'. - */ -uint8_t writeDS1307(uint8_t address, uint8_t *buf, uint8_t count) -{ - - // Write address and continue transfer for write of data. - if (!rtc.transfer(DS1307ADDR | I2C_WRITE, &address, 1, I2C_CONTINUE)) { - return false; - } - // Write data. - return rtc.transferContinue(buf, count); -} -//------------------------------------------------------------------------------ -void setup(void) -{ - Serial.begin(9600); -} -//------------------------------------------------------------------------------ -/** Store and print a string in flash memory.*/ -#define PgmPrint(x) Serial.print(F(x)) -/** Store and print a string in flash memory followed by a CR/LF.*/ -#define PgmPrintln(x) Serial.println(F(x)) -//------------------------------------------------------------------------------- -// Day of week U.S. convention. -char *Ddd[] = {"Bad", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -//------------------------------------------------------------------------------ -void hexPrint(uint8_t v) -{ - Serial.print(v >> 4, HEX); - Serial.print(v & 0XF, HEX); -} -//------------------------------------------------------------------------------ -void hexPrintln(uint8_t v) -{ - hexPrint(v); - Serial.println(); -} -//------------------------------------------------------------------------------ -// read hex input -uint8_t hexRead(uint16_t* v) -{ - bool valid = false; - uint16_t n = 0; - while (!Serial.available()); - while (Serial.available()) { - uint8_t c = Serial.read(); - // Exit if end-of-line. - if (c == '\n' || c == '\r') { - delay(10); - // If CR/LF. - Serial.read(); - break; - } - n <<= 4; - if ('a' <= c && c <= 'f') { - n += c - ('a' - 10); - } else if ('A' <= c && c <= 'F') { - n += c - ('A' - 10); - } else if ('0' <= c && c <= '9') { - n += c - '0'; - } else { - valid = false; - break; - } - delay(10); - valid = true; - } - if (!valid) { - PgmPrintln("Invalid entry"); - return false; - } - *v = n; - return true; -} -//------------------------------------------------------------------------------ -uint8_t bcdRead(uint8_t min, uint8_t max, uint8_t* n) -{ - uint16_t v; - if (!hexRead(&v)) { - return false; - } - uint8_t d = 10 * (v >> 4) + (v & 0XF); - if ((v >> 4) > 9 || (v & 0XF) > 9 || d < min || d > max) { - PgmPrintln("Invalid"); - return false; - } - *n = v; - return true; -} -//------------------------------------------------------------------------------ -void displayTime(void) -{ - uint8_t r[8]; - if (!readDS1307(0, r, 8)) { - PgmPrintln("Read Failed for display time"); - return; - } - PgmPrint("The current time is 20"); - // year - hexPrint(r[6]); - Serial.write('-'); - - // month - hexPrint(r[5]); - Serial.write('-'); - - // day - hexPrint(r[4]); - Serial.write(' '); - - Serial.print(Ddd[r[3] < 8 ? r[3] : 0]); - Serial.write(' '); - - // hour - hexPrint(r[2]); - Serial.write(':'); - - // minute - hexPrint(r[1]); - Serial.write(':'); - - // second - hexPrintln(r[0]); - - // Control register. - PgmPrint("Control Register: "); - hexPrintln(r[7]); -} -//------------------------------------------------------------------------------ -// dump registers and 56 bytes of RAM -void dumpAll(void) -{ - uint8_t buf[8]; - for (uint8_t a = 0; a < 64; a += 8) { - hexPrint(a); - Serial.write(' '); - if (!readDS1307(a, buf, 8)) { - PgmPrint("read failed for dumpAll"); - return; - } - for (uint8_t i = 0; i < 8; i++) { - Serial.write(' '); - hexPrint(buf[i]); - } - Serial.println(); - } -} -//------------------------------------------------------------------------------ -void fillNvRam(void) -{ - PgmPrint("Enter HEX value for all NV RAM locations (00-FF): "); - uint16_t v; - if (!hexRead(&v)) { - return; - } - hexPrint(v); - for (uint8_t a = 8; a < 64; a ++) { - if (!writeDS1307(a, (uint8_t *)&v, 1)) { - PgmPrintln("write failed for fillNvRam"); - } - } -} -//------------------------------------------------------------------------------ -// set control register -/* -The DS1307 control register is used to control the operation of the SQW/OUT pin. -+-----------------------------------------------+ -|BIT 7|BIT 6|BIT 5|BIT 4|BIT 3|BIT 2|BIT 1|BIT 0| -+-----------------------------------------------+ -|OUT | 0 | 0 |SQWE | 0 | 0 | RS1 | RS0 | -+-----------------------------------------------+ - -OUT (Output control): This bit controls the output level of the SQW/OUT pin -when the square wave output is disabled. If SQWE = 0, the logic level on the -SQW/OUT pin is 1 if OUT = 1 and is 0 if OUT = 0. - -SQWE (Square Wave Enable): This bit, when set to a logic 1, will enable the -oscillator output. The frequency of the square wave output depends upon the -value of the RS0 and RS1 bits. With the square wave output set to 1Hz, the -clock registers update on the falling edge of the square wave. - -Square wave Output Frequency for SQWE = 1. -RS1 RS0 FREQUENCY - 0 0 1Hz - 0 1 4.096kHz - 1 0 8.192kHz - 1 1 32.768kHz -*/ -void setControl(void) -{ - PgmPrintln("SQW/OUT pin: "); - PgmPrintln("(00) Low"); - PgmPrintln("(10) 1Hz"); - PgmPrintln("(11) 4.096kHz"); - PgmPrintln("(12) 8.192kHz"); - PgmPrintln("(13) 32.768kHz"); - PgmPrintln("(80) High"); - PgmPrint("Enter control: "); - uint16_t r; - if (!hexRead(&r)) { - return; - } - hexPrintln(r); - if (!writeDS1307(7, (uint8_t *)&r, 1)) { - PgmPrint("Write Failed for setControl"); - } -} -//------------------------------------------------------------------------------ -void setDate(void) -{ - uint8_t r[4]; - PgmPrint("Enter year (00-99): "); - if (!bcdRead(0, 99, &r[3])) { - return; - } - hexPrintln(r[3]); - PgmPrint("Enter month (01-12): "); - if (!bcdRead(1, 12, &r[2])) { - return; - } - hexPrintln(r[2]); - PgmPrint("Enter day (01-31): "); - if (!bcdRead(1, 31, &r[1])) { - return; - } - hexPrintln(r[1]); - PgmPrint("Enter day of week (01-07, Sun-Sat): "); - if (!bcdRead(1, 7, &r[0])) { - return; - } - hexPrintln(r[0]); - - if (!writeDS1307(3, r, 4)) { - PgmPrintln("Write failed for setDate"); - } -} -//------------------------------------------------------------------------------ -void setNvRam() -{ - uint8_t u; - uint16_t a, v; - while (true) { - PgmPrint("Enter zero to quit or Hex address (8-3F):"); - if (!hexRead(&a) || a == 0) { - return; - } - if (a < 8 || a > 0X3F) { - PgmPrintln("Invalid address"); - return; - } - hexPrintln(a); - if (!readDS1307(a, &u, 1)) { - PgmPrintln("Read failed"); - return; - } - PgmPrint("Current value: "); - hexPrintln(u); - PgmPrint("Enter new HEX value (00-FF): "); - if (!hexRead(&v)) { - return; - } - hexPrintln(v); - if (!writeDS1307(a, (uint8_t *)&v, 1)) { - PgmPrint("Write Failed"); - return; - } - } -} -//------------------------------------------------------------------------------ -void setTime(void) -{ - uint8_t r[3]; - PgmPrint("Enter hours (00-23): "); - if (!bcdRead(0, 23, &r[2])) { - return; - } - hexPrintln(r[2]); - PgmPrint("Enter minutes (00-59): "); - if (!bcdRead(0, 59, &r[1])) { - return; - } - hexPrintln(r[1]); - PgmPrint("Enter seconds (00-59): "); - if (!bcdRead(0, 59, &r[0])) { - return; - } - hexPrintln(r[0]); - - if (!writeDS1307(0, r, 3)) { - PgmPrintln("write failed in setTime"); - return; - } -} -//------------------------------------------------------------------------------ -void loop(void) -{ - Serial.println(); - displayTime(); - while (Serial.read() >= 0) {} - PgmPrintln("\nOptions are:"); - PgmPrintln("(0) Display date and time"); - PgmPrintln("(1) Set time"); - PgmPrintln("(2) Set date"); - PgmPrintln("(3) Set Control"); - PgmPrintln("(4) Dump all"); - PgmPrintln("(5) Fill NV RAM"); - PgmPrintln("(6) Set NV RAM value"); - PgmPrint("Enter option: "); - - uint16_t n; - if (!hexRead(&n)) { - return; - } - Serial.println(n, DEC); - if (n == 0) { - return; - } - Serial.println(); - if (n == 1) { - setTime(); - } else if (n == 2) { - setDate(); - } else if (n == 3) { - setControl(); - } else if (n == 4) { - dumpAll(); - } else if (n == 5) { - fillNvRam(); - } else if (n == 6) { - setNvRam(); - } else { - PgmPrintln("Invalid option"); - } -} diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino deleted file mode 100644 index 144c7fb3a..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino +++ /dev/null @@ -1,16 +0,0 @@ -// Scope test for write timing with Arduino digitaWrite(). -const uint8_t PIN13 = 13; - -void setup() -{ - // Set mode to OUTPUT. - pinMode(PIN13, OUTPUT); -} -void loop() -{ - digitalWrite(PIN13, HIGH); - digitalWrite(PIN13, LOW); - digitalWrite(PIN13, HIGH); - digitalWrite(PIN13, LOW); - delay(1); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino deleted file mode 100644 index 5b4f562aa..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino +++ /dev/null @@ -1,21 +0,0 @@ -// Scope test for write timing of DigitalPin functions. -#include - -// Class with compile time pin number. -DigitalPin<13> pin13; - -void setup() -{ - // set mode to OUTPUT - pin13.mode(OUTPUT); -} -void loop() -{ - pin13.high(); - pin13.low(); - pin13.write(1); - pin13.write(0); - pin13.toggle(); - pin13.toggle(); - delay(1); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino deleted file mode 100644 index 6fca39ab3..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino +++ /dev/null @@ -1,15 +0,0 @@ -// Test fastDigital function timing with a scope. -#include -const uint8_t PIN = 13; -void setup() -{ - fastPinMode(PIN, OUTPUT); -} -void loop() -{ - fastDigitalWrite(PIN, HIGH); - fastDigitalWrite(PIN, LOW); - fastDigitalToggle(PIN); - fastDigitalToggle(PIN); - delay(1); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino deleted file mode 100644 index 3cf8a8516..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino +++ /dev/null @@ -1,21 +0,0 @@ -// Scope test for PinIO class write timing. -#include - -// Class with runtime pin numbers. -PinIO pin(13); - -void setup() -{ - // Set mode to OUTPUT. - pin.mode(OUTPUT); -} -void loop() -{ - pin.high(); - pin.low(); - pin.write(1); - pin.write(0); - pin.toggle(); - pin.toggle(); - delay(1); -} \ No newline at end of file diff --git a/hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino deleted file mode 100644 index f457a3fcb..000000000 --- a/hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino +++ /dev/null @@ -1,43 +0,0 @@ -// Scope test for development - assumes 328 processor. -#include - -const uint8_t SOFT_SPI_MISO_PIN = 7; -const uint8_t SOFT_SPI_MOSI_PIN = 8; -const uint8_t SOFT_SPI_SCK_PIN = 9; -const uint8_t SPI_MODE = 0; - -SoftSPI spi; - -int test; -void setup() -{ - Serial.begin(9600); - spi.begin(); - while(1) { - Serial.println("Enter:"); - Serial.println("R - Receive"); - Serial.println("S - Send"); - Serial.println("T - Transfer"); - while ((test = Serial.read()) <= 0) {} - test = toupper(test); - if (strchr("RST", test)) { - break; - } - Serial.println("Invalid entry"); - }; - Serial.print("Starting test "); - Serial.println((char)test); -} -void loop() -{ - if (test == 'S') { - spi.send(0X55); - } - if (test == 'R') { - Serial.println(spi.receive(), HEX); - } - if (test == 'T') { - Serial.println(spi.transfer(0XAA), HEX); - } - delay(10); -} \ No newline at end of file diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp index c1122716c..5a4b558d9 100644 --- a/hal/architecture/NRF5/MyHwNRF5.cpp +++ b/hal/architecture/NRF5/MyHwNRF5.cpp @@ -204,8 +204,8 @@ ssize_t hwGetentropy(void *__buffer, size_t __length) } } hwRndDataReadPos=0; - for (uint8_t i=0; i