electro-smith / DaisyDuino

Arduino Support for the Daisy Audio Platform.
https://www.electro-smith.com/daisy
MIT License
92 stars 20 forks source link

Add ResetToBootloader function #51

Closed ndonald2 closed 1 year ago

ndonald2 commented 2 years ago

Summary

Adds a method to the DaisyDuino hardware class interface to reset the device into bootloader mode from software.

Details

This is a simple port of the System::ResetToBootloader() function from libDaisy so it can be used from Arduino as well. I could not figure out the correct pin identifier to use the Arduino pinMode and digitalWrite functions but I don't think that matters for adding the function directly to the hardware class interface, since we can just include the gpio utility header from the cpp file.

Related Daisy Forum Thread

Example Usage

#include "DaisyDuino.h"

DaisyHardware hw;

void MyCallback(float **in, float **out, size_t size) {
  for (size_t i = 0; i < size; i++) {
    out[0][i] = in[0][i];
    out[1][i] = in[1][i];
  }
}

void setup() {
  float sample_rate;
  hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
  sample_rate = DAISY.get_samplerate();

  DAISY.begin(MyCallback);

  // blink for 2 seconds
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

  hw.ResetToBootloader();
}

void loop() {}
stephenhensley commented 1 year ago

Ou, this is great! (Somehow just noticed this PR was here!) Sorry for the delay.

It looks good. We just realized the last release didn't go as planned, and missed the library manager. So we'll take a look this week, and see about getting this merged, and included in a v1.7 release!

Thanks again for the PR!

beserge commented 1 year ago

Looks good to me! Tested your example code on the daisy pod and it worked great. Could probably change the GPIO stuff to be more arduino-ish, but it would require digging through the pindefs like you mentioned so I'm fine with it as is.

🚀