Folks, with the Photon being so new, a lot of new functionality is being introduced to the firmware, including the HAL (Hardware Abstraction Layer) and the modular system/user code. These changes are impacting library code that was adapted specifically for the Core when future products were not known. Well, now that we know that future, it is time to generalize libraries for all Particle devices including the future Electron.
One key function used for doing faster bit I/O uses the PIN_MAP reference. Until @mdma can formalize a method (API, macros) for using PIN_MAP to set and reset pins faster than using (the safer) digitalWrite() command, the following code may be used to implement the functions:
The solution to the PIN_MAP issue is a little more complex due to the differences in the bit set and reset registers on the STM32F103 (core) and the STM32F205 (photon). Here is a set of macros I used to port the SparkIntervalTimer library:
#if defined(PLATFORM_ID) //Only defined if a Particle device #include "application.h" STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); // Pointer required for highest access speed #if (PLATFORM_ID == 0) // Core #define pinLO(_pin) (PIN_MAP[_pin].gpio_peripheral->BRR = PIN_MAP[_pin].gpio_pin) #define pinHI(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRR = PIN_MAP[_pin].gpio_pin) #elif (PLATFORM_ID == 6) // Photon #define pinLO(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRH = PIN_MAP[_pin].gpio_pin) #define pinHI(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRL = PIN_MAP[_pin].gpio_pin) #else #error "*** PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***" #endif #endif
You will need to replace any PIN_MAP operation in the code with pinHI and pinLO if you want the code to be common for both the Core and the Photon (and future Electron).
UPDATE: including pinmap_impl.h is not necessary it seems