diff --git a/README.md b/README.md index 0546307..48b1085 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,23 @@ The procedure: * `Arduino MKR WiFi 1010`: short the pin 7 to GND until the led turns off * `Arduino GIGA R1 WiFi`: short the pin 7 to GND until the led turns off * `Arduino Nano RP2040 Connect`: short the pin 2 to 3.3V until the led turns off +* `Arduino Portenta H7`: short the pin 0 to GND until the led turns off +* `Arduino Portenta C33`: short the pin 0 to GND until the led turns off * Other boards: short the pin 2 to GND until the led turns off +* `Portenta Machine Control`: currently the reset procedure is not available + +### More on the reconfiguration pin +Internally, the pin indicated in the procedure is set as `INPUT_PULLUP` (except for `Arduino Opta` ) and it's attached to an ISR fired on every change of the pin's status. + +In order to be notified when the ISR is fired, it's possible to register a callback function using the function `NetworkConfigurator.addReconfigurePinCallback(callback)`. Please take the example as reference. + +### Change the reconfiguration pin +In order to change the default pin for resetting the board, it's possible to use the function `NetworkConfigurator.setReconfigurePin(your_pin)` specifying the new pin. +The pin must be in the list of digital pins usable for interrupts. Please refer to the Arduino documentation for more details: https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/ + +### Disable the reconfiguration feature +In order to disable the reconfiguration procedure, use this function in the sketch `NetworkConfigurator.setReconfigurePin(DISABLE_PIN)` + ## Configurator Agents The library provides a set of *Configurator Agents* that added as plug-in to the sketch handle the communication between the Arduino Network Configurator and an external client ([*Arduino IoT App*](https://cloud.arduino.cc/iot-remote-app/) and Arduino IoT Cloud) for configuring the board. diff --git a/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino b/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino index 1bb8e6c..bc03b42 100644 --- a/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino +++ b/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino @@ -21,6 +21,9 @@ * - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off * - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off * - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off + * - Portenta H7: short the pin 0 to GND until the led turns off + * - Portenta C33: short the pin 0 to GND until the led turns off + * - Portenta Machine Control: the reset is not available * - Other boards: short the pin 2 to GND until the led turns off * * In this sketch the BLE and Serial interfaces are always enabled and ready for accepting diff --git a/src/ANetworkConfigurator_Config.h b/src/ANetworkConfigurator_Config.h index e1ca4cd..b6e3593 100644 --- a/src/ANetworkConfigurator_Config.h +++ b/src/ANetworkConfigurator_Config.h @@ -57,7 +57,9 @@ #if defined(ARDUINO_PORTENTA_H7_M7) #define NETWORK_CONFIGURATOR_COMPATIBLE 1 #define ZERO_TOUCH_ENABLED 1 - #define PIN_RECONFIGURE 2 + #define I2C_ADD_DETECT_MACHINE_CONTROL_1 0x23 + #define I2C_ADD_DETECT_MACHINE_CONTROL_2 0x22 + #define PIN_RECONFIGURE 0 #define LED_RECONFIGURE LED_BUILTIN #define BOARD_HAS_RGB #define GREEN_LED LEDG @@ -108,7 +110,7 @@ #if defined(ARDUINO_PORTENTA_C33) #define NETWORK_CONFIGURATOR_COMPATIBLE 1 #define ZERO_TOUCH_ENABLED 1 - #define PIN_RECONFIGURE 2 + #define PIN_RECONFIGURE 0 #define LED_RECONFIGURE LEDG #define BOARD_HAS_RGB #define GREEN_LED LEDG diff --git a/src/Arduino_NetworkConfigurator.cpp b/src/Arduino_NetworkConfigurator.cpp index f448b1f..40c33c4 100644 --- a/src/Arduino_NetworkConfigurator.cpp +++ b/src/Arduino_NetworkConfigurator.cpp @@ -122,6 +122,9 @@ NetworkConfiguratorStates NetworkConfiguratorClass::update() { * - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off * - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off * - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off + * - Portenta H7: short the pin 0 to GND until the led turns off + * - Portenta C33: short the pin 0 to GND until the led turns off + * - Portenta Machine Control: the reset is not available * - Other boards: short the pin 2 to GND until the led turns off */ diff --git a/src/Arduino_NetworkConfigurator.h b/src/Arduino_NetworkConfigurator.h index d68bbdb..fafe125 100644 --- a/src/Arduino_NetworkConfigurator.h +++ b/src/Arduino_NetworkConfigurator.h @@ -58,6 +58,9 @@ enum class NetworkConfiguratorStates { ZERO_TOUCH_CONFIG, * - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off * - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off * - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off + * - Portenta H7: short the pin 0 to GND until the led turns off + * - Portenta C33: short the pin 0 to GND until the led turns off + * - Portenta Machine Control: the reset is not available * - Other boards: short the pin 2 to GND until the led turns off * */ diff --git a/src/utility/ResetInput.cpp b/src/utility/ResetInput.cpp index 0df5fc0..70d322e 100644 --- a/src/utility/ResetInput.cpp +++ b/src/utility/ResetInput.cpp @@ -11,6 +11,28 @@ #include "ResetInput.h" #include "utility/LEDFeedback.h" +#if defined(ARDUINO_PORTENTA_H7_M7) +#include + + +bool isPortentaMachineControlAttached() { + Wire.begin(); + Wire.beginTransmission(I2C_ADD_DETECT_MACHINE_CONTROL_1); + if (Wire.endTransmission() != 0) { + return false; + } + + Wire.beginTransmission(I2C_ADD_DETECT_MACHINE_CONTROL_2); + if (Wire.endTransmission() != 0) { + return false; + } + + Wire.end(); + return true; +} + +#endif + ResetInput &ResetInput::getInstance() { static ResetInput instance; return instance; @@ -25,6 +47,12 @@ ResetInput::ResetInput() { } void ResetInput::begin() { +#if defined(ARDUINO_PORTENTA_H7_M7) + if(isPortentaMachineControlAttached()) { + return; // Portenta Machine Control is not supported + } +#endif + if(_pin == DISABLE_PIN){ return; } @@ -35,7 +63,6 @@ void ResetInput::begin() { #endif pinMode(LED_RECONFIGURE, OUTPUT); digitalWrite(LED_RECONFIGURE, LED_OFF); - attachInterrupt(digitalPinToInterrupt(_pin),_pressedCallback, CHANGE); }