Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CircuitPlayground.readCap() breaks Adafruit_NeoPixel_ZeroDMA on CPX #39

Open
buxit opened this issue Feb 5, 2019 · 7 comments
Open

Comments

@buxit
Copy link

buxit commented Feb 5, 2019

On Circuit Playground Express, calling CircuitPlayground.readCap() makes Adafruit_NeoPixel_ZeroDMA display random pixels. Try with the following sketch:

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_NeoPixel_ZeroDMA.h>

#define PIXELS_PIN     8
#define PIXELS_NUM    10

#define TOUCH_PIN     A1

Adafruit_NeoPixel_ZeroDMA pixels(PIXELS_NUM, PIXELS_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  CircuitPlayground.begin();
  pixels.begin();
  pixels.setBrightness(24);
}

void loop() {
  int c = CircuitPlayground.readCap(TOUCH_PIN);

  pixels.fill(pixels.Color(128, 0, 255));
  pixels.show();
  delay(10);
}

This is just the simplest example to show the problem without additional hardware. I'm in fact trying to use Adafruit_NeoMatrix_ZeroDMA on pin A2, but it exhibits exactly the same problem. When commenting out the readCap() line everything works as expected.

@ladyada
Copy link
Member

ladyada commented Feb 5, 2019

weird - we're not sure if/when we'll get to figuring this out because its more advanced usage - let us know if you figure it out!

@buxit
Copy link
Author

buxit commented Feb 6, 2019

by trial and error (inserting returns at random positions, commenting out code lines) i have just found out that changing the clock source_generator in Adafruit_CPlay_FreeTouch::setupClock() to 3 (instead of 1) makes it work in my case, though i have absolutely no idea what this means and why it works.

@ladyada
Copy link
Member

ladyada commented Feb 6, 2019

yeah that could do it - wanna send a PR in? we'll look at it next time we do a sweep

@buxit
Copy link
Author

buxit commented Feb 7, 2019

that's what i thought … until i tested the part of the sketch that uses the microphone. with source_generator = 3 the call to pdm.configure() – oddly enough – again breaks Adafruit_NeoMatrix_ZeroDMA. i would have expected it to break the PTC, if at all. so if i then use 4 as gclk for Adafruit_ZeroPDM Adafruit_CPlay_Mic::pdm = Adafruit_ZeroPDM(34, 35, 4); in Adafruit_CPlay_Mic.cpp everything i currently need works as expected. not being able to use arbitrary sources/generators for the touch clock tells me that there's probably something wrong with clock setup in Adafruit_CPlay_FreeTouch.cpp

i think i'll have to read up on samd21 clocks and gain some more understanding before i can send a PR.

maybe you can persuade atmel / microchip / arm to provide full low-level documentation for the PTC?

@ladyada
Copy link
Member

ladyada commented Feb 7, 2019

there's no documentation for PTC - we've asked :( its all under NDA - we had to hand reverse engineer it from binary ;)

@ladyada
Copy link
Member

ladyada commented Feb 7, 2019

@PaintYourDragon do you know what this could be? its an obscure one but perhpas you're like "oh yeah i know this!"

@mzero
Copy link

mzero commented Dec 26, 2021

I know why! See adafruit/Adafruit_FreeTouch#17 for full details of how FreeTouch code affects DMA.

The copy of FreeTouch in Circuit Playground has the same issue.

This sketch demonstrates the issue using the Circuit Playground version of the code: https://gist.github.com/mzero/89955e14d41d7e37a439ba806746f632

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants