Support for Arduino #Include files


I am having issues porting existing code to Spark from working Arduino examples. The problems is that the #include documents are not easily referenced. Eg/ code below;

/////////////////// Includes ///////////////////////////
#include <EEPROM.h>
#include <avr/io.h>
#include <avr/interrupt.h>

… and this continues for each included file

Have tried to add all files to spark on web without luck, any suggestions how to more easily port this working arduino code?

VL53L0X Time-of-Flight Ranging Sensor

This might help you out. I had to include the application.h file at the top of my .h file to get it to compile right.


Can you give us a little more detail about what you are trying to port over to the Spark? Is it possible to share all of your code, maybe a github repo link?

The EEPROM.h library requirement is going to be a problem. There is currently nothing exactly like that for the Spark. The Spark Core has non-volatile flash memory, but it’s usage is different than your Arduino EEPROM library. Check this out here:


DanC, the libraries you listed are not compatible with Spark. As RWB pointed out, most of the “low level” includes are taken care of in application.h. Not all arduino libraries are straight forward to port to Spark and why so many members are working so hard to port as many of them as possible. Soon, the Spark Team will implement a library feature in the web IDE that will allow the sharing of successfully ported libraries. :smile:


Thanks for the quick replies.

I have several arduino projects, sound like it is not that simple to port over to this “arduino” compatible board (or a too early in the spark core project). An optimistic CTRL+C … CTLR+V would have been nice!

Some header files i am using are highlighted below (Various net sources);

/* HT1621 - Holtek RAM Mapping 32x4 LCD Controller */
#ifndef HT1621_H
#define HT1621_H

#include <inttypes.h>
#include "Arduino.h"

class HT1621 {
    enum {
        SYS_DIS   = 0b00000000,
        SYS_EN    = 0b00000001,
        LCD_OFF   = 0b00000010,
        LCD_ON    = 0b00000011,
        TIMER_DIS = 0b00000100,
        WDT_DIS   = 0b00000101,
        TIMER_EN  = 0b00000110,
        WDT_EN    = 0b00000111,
        TONE_OFF  = 0b00001000,
        TONE_ON   = 0b00001001,
        RC_256K  = 0b00011000,
        IRQ_DIS  = 0b10000000,
        CLR_WDT  = 0b00001111,
        //Set bias to 1/2 or 1/3 cycle
        //Set to 2,3 or 4 connected COM lines
        BIAS_HALF_2_COM  = 0b00100000,
        BIAS_HALF_3_COM  = 0b00100100,
        BIAS_HALF_4_COM  = 0b00101000,
        BIAS_THIRD_2_COM = 0b00100001,
        BIAS_THIRD_3_COM = 0b00100101,
        BIAS_THIRD_4_COM = 0b00101001,
        //Don't use
        TEST_ON   = 0b11100000,
        TEST_OFF  = 0b11100011
    } Commands;

    HT1621(uint8_t data, uint8_t wr, uint8_t rd, uint8_t cs) : 
        data_pin(data), wr_pin(wr), rd_pin(rd), cs_pin(cs) {}

    bool begin();

    void sendCommand(uint8_t cmd, bool first = true, bool last = true);

    void write(uint8_t address, uint8_t *data, uint8_t cnt);
    void read(uint8_t address, uint8_t *data, uint8_t cnt);

    void writeMem(uint8_t address, uint8_t data);
    uint8_t readMem(uint8_t address);

    void memset(uint8_t address, uint8_t data, uint8_t cnt);

    void writeBits(uint8_t data, uint8_t cnt);
    uint8_t readBits(uint8_t cnt);

    inline void initControlBus();
    inline bool testMem();
    uint8_t data_pin;
    uint8_t wr_pin;
    uint8_t rd_pin;
    uint8_t cs_pin;

#endif //HT1621_H

// PaLFI_Transponder.h //
// RFID Module //


#define BIT0                (0x0001)
#define BIT1                (0x0002)
#define BIT2                (0x0004)
#define BIT3                (0x0008)
#define BIT4                (0x0010)
#define BIT5                (0x0020)
#define BIT6                (0x0040)
#define BIT7                (0x0080)
#define BIT8                (0x0100)
#define BIT9                (0x0200)
#define BITA                (0x0400)
#define BITB                (0x0800)
#define BITC                (0x1000)
#define BITD                (0x2000)
#define BITE                (0x4000)
#define BITF                (0x8000)

/**************Configuration for eZ430-PaLFI******************************/
#define	SPI_SIMO		    (0x0002)	    // P3.1 Output:	Output to Frontend = TMS37157
#define	SPI_SOMI		    (0x0004)	    // P3.2 Input:	Input from Frontend = TMS37157
#define	SPI_CLK 		    (0x0008)		// P3.3 Output:	SPI clock
#define	CU_BUSY	            (0x0001)        // P2.0 Input:	Busy signal from Frontend
#define CLK_AM				(0x0002)		// P2.1 Input: CLK_AM signal from Frontend
#define	CU_PUSH	            (0x0004)        // P2.2 Output:	Push signal to Frontend

/**************SPI Libary definitions for TMS37157***************************/

#define false               (0x00)
#define true                (0x01)

#define STOP_OPERATION      true


  unsigned char ucPCU_Mode;			// Defines in MSP_Access or Push Button Command
  unsigned char Command;
  unsigned char SerialNumber[4];	// Serial Number + Manu Code Page3
  unsigned char KeyNumber;	      	// equal to User data 1/Page 2
  unsigned char SelectiveAddress;	// Page 1, in eZ430-PaLFI locked to FF
  unsigned char PushButtonMask;		// Page 18
  unsigned char RollingCode[5];		// Page 55, not important

union unChar2Int
unsigned char ucChar[2];
unsigned int  uiInt;

struct _stByteRC
  unsigned char  ucData[5];

struct _stLongRC
  unsigned long  ulLong;
  unsigned char  ucChar;

union _unRC
struct _stByteRC stCharRC;
struct _stLongRC stLongRC;

#define     PCU_PUSH_BUTTON     1
#define     PCU_MSP_ACCESS      2

#define		Page1		0x04		// SELECTIVE ADDRESS
#define		Page2	  	0x08		// USER DATA 1
#define		Page3 		0x0C		// UNIQUE IDENTIFICATION
#define		Page8		0x20		// USER DATA 2
#define		Page9  		0x24		// USER DATA 3
#define		Page10		0x28		// USER DATA 4
#define		Page11		0x2C		// USER DATA 5   
#define		Page12		0x30		// USER DATA 6   
#define		Page13		0x34		// USER DATA 7
#define		Page14		0x38		// USER DATA 8
#define		Page15		0x3C		// USER DATA 9
#define		Page30		0x78		// CONFIGURATION

#define		Page40		0xA0		// User data 10
#define		Page41		0xA4		// User data 11
#define		Page42		0xA8		// User data 12
#define		Page43		0xAC		// User data 13
#define		Page44		0xB0		// User data 14
#define		Page45		0xB4		// User data 15
#define		Page46		0xB8		// User data 16
#define		Page47		0xBC		// User data 17
#define		Page48		0xC0		// User data 18
#define		Page49		0xC4		// User data 19
#define		Page50		0xC8		// User data 20
#define		Page51		0xCC		// User data 21
#define		Page52		0xD0		// User data 22
#define		Page53		0xD4		// User data 23
#define		Page54		0xD8		// User data 24
#define		Page55		0xDC		// User data 25


// Transponder Access Command
#define		TAC_COMMAND_BYTE		  0x00

// Enhanced Commands
#define		MSP430_Read_CU_Status		  0xB4	// Get Status from TMS37157
#define		MSP430_PowerDownMode		  0xB8	// Power Down 37157
#define     MSP430_CU_GetData             0xB0	// Request Data from MSP Access
#define     MSP430_CU_SendData            0xB1	// Send Data for MSP Access
#define 	MSP430_Trim_w_prog			  0x89	// Trim TMS37157 with Trim EEPROM
#define		MSP430_Trim_wo_prog			  0xA9	// Trim TMS37157 without Trim EEPROM

#define		CU_CRC_Calculation	          0x80	// Perform CRC16 Calculation
#define		CU_Oscillator_Off		  	  0x94	// Switch off the LC Tank Circuit
#define		CU_Oscillator_134KHz		  0x95	// Switch on LC Tank Circuit
#define		CU_Oscillator_134KHz_DIV4	  0x96	// Switch on LC Tank Circuit with 1/4 of the Frequency
#define		CU_CLKA_Off			  		  0x9C	// Switch of LC Tank Circuit at CLK_AM Pin
#define		CU_CLKA_On			          0x9D	// Switch LC Tank Circuit to CLK_AM Pin


#define		Okay				  0x00
#define		Fail				  0x01

/*****************SPI functions to communicate with TMS37157**********************/

void ErrorMode(void);
void MSP430_SPI_Init(void);
void Wake_PaLFI(void);

void SPI_Prog_RC(void);
void SPI_Power_Down(void);
void TRP_Read_PCU_Data(void);
void SPI_Read_SerialNum(void);
void SPI_Read_PCU_State(void);
void SPI_Read_UserPage(unsigned char ucPage, unsigned char *ucData);
void SPI_Program_UserPage(unsigned char ucPage, unsigned char *ucData);
void SPI_CRC_Calc(unsigned char ucStart,unsigned char ucLength, unsigned char *ucData, unsigned char *ucCRC);

void SPI_CLKA_Config(unsigned char ucMode);
void SPI_CLKA_ON(void);
void SPI_CLKA_OFF(void);
void SPI_TRIM_W_PROG(char data);
void SPI_TRIM_WO_PROG(char data);

void SPI_Read_CU_Data(unsigned char *ucData);
unsigned char SPI_Write_CU_Data(unsigned char *ucData);

unsigned char MSP430_SPI_Rx(unsigned char *RxBuffer, unsigned char size);

void Wait_for_Busy_low (void);

void LED_ON (int LED);
void LED_OFF (int LED);
void Toggle_LED_500ms (int LED);
void Delay_500ms (void);

#endif /*CED80_TRANSPONDER_H_*/


@DanC in your example at the top, see the line:

#include <avr/io.h>

Our micro-controller is not the same as the Arduino’s micro-controller. Theirs is an AVR architecture, ours is an ARM architecture. That means anything that includes AVR-specific code will not be a copy-paste port. But overall this is a Good Thing™ because ARM is the future, and our chip is a lot more powerful than the ATmega328p in an Arduino Uno.

The great thing about a strong community like this one is that porting is happening for many libraries, one step at a time :slight_smile:


DanC, not all arduinos are created the same! Hardware specific libraries are always tricky to use. Spark has an amazing community that is working hard at porting libraries over to the Spark. I suggest you post the code you need ported (on github for example) and see if the community can take a crack at it! :smile: