[CapacitiveSensor] Can't compile with Zero

I'm fairly new to the Zero but can't seem to get the CapacitiveSensor library to compile for the Zero.

Any suggestions are appreciated.

Currently getting:

Arduino: 1.6.6 (Mac OS X), Board: "Arduino/Genuino Zero (Programming Port)"

Warning: platform.txt from core 'Arduino SAMD (32-bits ARM Cortex-M0+) Boards' contains deprecated recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}", automatically converted to recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}". Consider upgrading this core.
In file included from /Users/ckey/Documents/projects/structure/arduino-capsense/capsense_test/capsense_test.ino:1:0:
/Users/ckey/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.h:97:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE sBit;   // send pin's ports and bitmask
  ^
/Users/ckey/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.h:98:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE *sReg;
           ^
/Users/ckey/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.h:99:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE rBit;    // receive pin's ports and bitmask
  ^
/Users/ckey/Documents/Arduino/libraries/CapacitiveSensor/CapacitiveSensor.h:100:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE *rReg;
           ^
exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

your code try to use AVR register to do some port manipulation. These registers are not the same on the ARM platform...

It's because the Zero's microcontroller isn't supported in the "CapactiveSensor.h" file.

To get it to work you need to define the preprocessor directive and macros for the Zero's SAMD21G18A microcontroller.

You could try adding this code to the CapacitiveSensor.h file together with the code for the other processors and see if it works (untested):

#elif defined(__SAMD21G18A__)
#define PIN_TO_BASEREG(pin)             portModeRegister(digitalPinToPort(pin))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*((base)+8)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*((base)+1)) = (mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*((base)+2)) = (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*((base)+5)) = (mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*((base)+6)) = (mask))

Failing that, you could try to contact Paul Stoffregen on the PJRC forum. Paul wrote the non-AVR support for this library and is also the creator of the PJRC's Teensy boards.

Thanks for the info I'll give the updated header defs a try.

I'm watching..... :wink:

If anyone can confirm that code works, I'll be happy to merge it.

Capacitive sensor "hacks" tend to be very chip-specific, since they typically rely on the analog behavior of the digital IO pins. I wouldn't really expect the AVR library to work on the ARM chips even if you DID convery the low-level primitives correctly.

OTOH, the SAMD21 processor used on the Zero has a built-in Touch Controller interface...

The #defines in #2 do not work. I put them into CapacitiveSensor.h anyway with a comment, as a starting point for someone to hopefully contribute a fix.

Hi,

I know this is an old thread but I have found a library made by Adafruit which is compatible with ARM
devices (I tried it on a feather m0 express and responded well). it's called Adafruit_FreeTouch.

Is there any way to mix both? I kinda like the CapacitiveSensor library better.