Touch_4Wire library not yet ported for Photon

Since I’m not sure if the compiler flag SPARK is still defined, to make all the Core related branches compile correctly, you could try altering #if defined(SPARK) into #if defined(PLATFORM_ID) && (PLATFORM_ID==6) (and similar directives as you see fit) - unless @peekay123 has a better solution.

@ScruffR, just #if (PLATFORM_ID == 6) for the Photon will do the job in my experience. Also PLATFORM == 0 is for the Core.

1 Like

Actually thinking of it, since it should work for the Core and Photon just the same, as long as the pinSet versions are set correctly in the header, it should suffice to use #if defined(PLATFORM_ID).

Otherwise the more verbose form must definetly work for both: #if (PLATFORM_ID == 0) || (PLATFORM_ID == 6)

@scruffr, @peekay123, I just got my P1 assembled and stared messing around with the code. What platform id is for the P1?

1 Like

Platform ID 8. Or you can use ‘PLATFORM=P1’. Please see build/platform-id.mk.

If you are targeting general STM32F2 features, then it’s a good idea to use #ifdef STM32F2XX as this is forwards compatible with future STM32F2 devices, such as the Electron.

1 Like

Has anyone been able to get the Touch_4Wire library working with the Photon? I have been able to get the code to compile by adding the macro for Photon pin mapping, but no touches register. Can anyone share working code for the Photon? I would greatly appreciate it!

@jones_corey, i have the touch4wire working on my photons and P1 with these additions in the begining of the program:

.cpp file

#if  (PLATFORM_ID) == 6 || (PLATFORM_ID) == 8
  static STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); // Pointer required for highest access speed
#endif

.h file

#if  (PLATFORM_ID) == 6 || (PLATFORM_ID) == 8
    #define pinSetLow(pin) PIN_MAP[pin].gpio_peripheral->BSRRH = PIN_MAP[pin].gpio_pin
    #define pinSetHigh(pin) PIN_MAP[pin].gpio_peripheral->BSRRL = PIN_MAP[pin].gpio_pin
#else
    #define pinSetHigh(pin) PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin
    #define pinSetLow(pin)  PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin
#endif
2 Likes

Thanks a lot @wesner0019! I ended up hitting up your git repository at https://github.com/wesner0019/Ported_Touch4Wire and the code worked right off the bat. Thanks again!

1 Like

Hello old post,

Finally I found some reference to the 4Wire library. I’m trying to get this code working on my Photon 0.5.x and I’m not able to get it to compile on Particle Dev.

This line static STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); in Touch_4Wire.h is causing issues. I’m getting the error:

redefinition of 'STM32_Pin_Info* PIN_Map'

and

'STM32_Pin_Info* PIN_MAP' previously declared here

When I click on the second error I get taken to fast_pin.h

Do you have any idea how to clear the issue? Has this changed in one of the latest Photon revisions? Thanks in advance :smile:

@erikg, I believe you can comment that out

#include "Touch_4Wire.h"
#include "application.h"
//#if  (PLATFORM_ID) == 6 || (PLATFORM_ID) == 8
  //static STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); // Pointer required for highest access speed
//#endif

That does not look like the most recent version of my library port (0.9.2)

https://build.particle.io/libs/562c001ea234e6c145000e8c/tab/Touch_4Wire.cpp

The .cpp reads

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// (c) ladyada / adafruit
// Code under MIT License
//
// ported for Spark Core by ScruffR Nov. 2014

#include "Touch_4Wire.h"

#if defined (SPARK)
#include "application.h"
#else
#include "pins_arduino.h"
#include "wiring_private.h"
#include <avr/pgmspace.h>
#endif

and the .h reads

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// (c) ladyada / adafruit
// Code under MIT License
//
// ported for Spark Core by ScruffR Nov. 2014

#ifndef _ADAFRUIT_TOUCH4WIRE_H_
#define _ADAFRUIT_TOUCH4WIRE_H_

#if defined(SPARK)
#include "application.h"

// some very useful macros for Spark Core and porting Arduino libraries for it

#if (SYSTEM_VERSION < 0x00040400) // no fast pin functions before 0.4.4
#if defined(STM32F2XX)  // for the Photon and friends
#define pinResetFast(_pin)	               (PIN_MAP[_pin].gpio_peripheral->BSRRH = PIN_MAP[_pin].gpio_pin)
#define pinSetFast(_pin)	                 (PIN_MAP[_pin].gpio_peripheral->BSRRL = PIN_MAP[_pin].gpio_pin)
#elif defined(STM32F10X_MD)  // for the Core
#define pinResetFast(_pin)	               (PIN_MAP[_pin].gpio_peripheral->BRR = PIN_MAP[_pin].gpio_pin)
#define pinSetFast(_pin)	                 (PIN_MAP[_pin].gpio_peripheral->BSRR = PIN_MAP[_pin].gpio_pin)
#endif
#define digitalWriteFast(_pin, _hilo)      (_hilo ? pinSetFast(_pin) : pinResetFast(_pin))
#define pinReadFast(_pin)                  (PIN_MAP[_pin].gpio_peripheral->IDR & PIN_MAP[_pin].gpio_pin ? 0xFF : LOW)
#endif

@ScruffR, this is probably an older version. this is the one that I have been using for a while.

Do you know whats been updated in this library since early 2015? Any major changes?

Thanks

No major changes - just the compatibility with Photon/P1/Electron and the use of the then added fast I/O functions.

Why? Are there any issues you’d like to see addressed?

@ScruffR, no issues, if there were any major changes I was going to update my currently library in our product.

1 Like