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

unroll F macro and restore print const __FlashStringHelper * #187

Merged
merged 4 commits into from
May 8, 2014

Conversation

jacobrosenthal
Copy link
Contributor

Make F and other Flash based functions work. Please test with the below. Note the inclusionion of Teensy's avr/pgmspace.h definitions. I dont know if you want to include them yourself or maintain that as an external include.

#include "application.h"


//Teensy's /avr/pgmspace
#include <inttypes.h>

#define PROGMEM
#define PGM_P  const char *
#define PSTR(str) (str)

typedef void prog_void;
typedef char prog_char;
typedef unsigned char prog_uchar;
typedef int8_t prog_int8_t;
typedef uint8_t prog_uint8_t;
typedef int16_t prog_int16_t;
typedef uint16_t prog_uint16_t;
typedef int32_t prog_int32_t;
typedef uint32_t prog_uint32_t;

#define strcpy_P(dest, src) strcpy((dest), (src))
#define strcat_P(dest, src) strcat((dest), (src))
#define strcmp_P(a, b) strcmp((a), (b))

#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#define pgm_read_float(addr) (*(const float *)(addr))

#define pgm_read_byte_near(addr) pgm_read_byte(addr)
#define pgm_read_word_near(addr) pgm_read_word(addr)
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
#define pgm_read_float_near(addr) pgm_read_float(addr)
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
#define pgm_read_word_far(addr) pgm_read_word(addr)
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
#define pgm_read_float_far(addr) pgm_read_float(addr)


const char TEST1[] PROGMEM = { "hello world" } ;

//wifi client->print has a buffer that so far we've been unable to locate
//under 154 (our identify size) for sure.. so sending char by char for now
void printlnF(PGM_P data) 
{
  char buffer[20];
  strcpy_P(buffer, data);
  Serial.println(buffer);
}

/* This function is called once at start up ----------------------------------*/
void setup()
{
  Serial.begin(9600);
  delay(5000);
  Serial.println((F("Hello World")));
  printlnF(TEST1);
}

/* This function loops forever --------------------------------------------*/
void loop()
{
    //This will run in a loop
}

@pkourany
Copy link
Contributor

I could not compile this example without errors.

@jacobrosenthal
Copy link
Contributor Author

Boy, Id like to see those errors :) Works for me still.

@pkourany
Copy link
Contributor

pkourany commented May 1, 2014

Compiled with spark CLI. Here are the errors:

attempting to compile firmware
pushing file: application.cpp
Errors
In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:31,
from application.cpp:1:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
application.cpp: In function 'void setup()':
application.cpp:56:36: error: call of overloaded 'println(const _FlashStringHelper)' is ambiguous
application.cpp:56:36: note: candidates are:
In file included from ../inc/spark_wiring_stream.h:38:0,
from ../inc/spark_wiring.h:35,
from ../inc/application.h:31,
from application.cpp:1:
../inc/spark_wiring_print.h:79:12: note: size_t Print::println(char)
../inc/spark_wiring_print.h:79:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'char'
../inc/spark_wiring_print.h:80:12: note: size_t Print::println(unsigned char, int)
../inc/spark_wiring_print.h:80:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'unsigned char'
../inc/spark_wiring_print.h:81:12: note: size_t Print::println(int, int)
../inc/spark_wiring_print.h:81:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'int'
../inc/spark_wiring_print.h:82:12: note: size_t Print::println(unsigned int, int)
../inc/spark_wiring_print.h:82:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'unsigned int'
../inc/spark_wiring_print.h:83:12: note: size_t Print::println(long int, int)
../inc/spark_wiring_print.h:83:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'long int'
../inc/spark_wiring_print.h:84:12: note: size_t Print::println(long unsigned int, int)
../inc/spark_wiring_print.h:84:12: note: no known conversion for argument 1 from 'const _FlashStringHelper' to 'long unsigned int'
make: *_* [application.o] Error 1

@jacobrosenthal
Copy link
Contributor Author

Of course! The cli code is weeks old and what this pull request is
attempting to fix. :)

To test you would need to follow the directions here
https://github.com/spark/core-firmware

to get a local copy to compile from, Then merge my pull request
feature/pgm-fixes which explicitly fixes the errors you've found :)

On Wed, Apr 30, 2014 at 8:56 PM, Paul Kourany notifications@gh.neting.ccwrote:

Compiled with spark CLI. Here are the errors:

attempting to compile firmware
pushing file: application.cpp
Errors
In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:31,
from application.cpp:1:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning:
#warning "Defaulting to Release Build" [-Wcpp]
application.cpp: In function 'void setup()':
application.cpp:56:36: error: call of overloaded 'println(const
_FlashStringHelper)' is ambiguous
application.cpp:56:36: note: candidates are:
In file included from ../inc/spark_wiring_stream.h:38:0,
from ../inc/spark_wiring.h:35,
from ../inc/application.h:31,
from application.cpp:1:
../inc/spark_wiring_print.h:79:12: note: size_t Print::println(char)
../inc/spark_wiring_print.h:79:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'char'
../inc/spark_wiring_print.h:80:12: note: size_t Print::println(unsigned
char, int)
../inc/spark_wiring_print.h:80:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'unsigned char'
../inc/spark_wiring_print.h:81:12: note: size_t Print::println(int, int)
../inc/spark_wiring_print.h:81:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'int'
../inc/spark_wiring_print.h:82:12: note: size_t Print::println(unsigned
int, int)
../inc/spark_wiring_print.h:82:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'unsigned int'
../inc/spark_wiring_print.h:83:12: note: size_t Print::println(long int,
int)
../inc/spark_wiring_print.h:83:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'long int'
../inc/spark_wiring_print.h:84:12: note: size_t Print::println(long
unsigned int, int)
../inc/spark_wiring_print.h:84:12: note: no known conversion for argument
1 from 'const _FlashStringHelper' to 'long unsigned int'
make: *_* [application.o] Error 1


Reply to this email directly or view it on GitHubhttps://github.com//pull/187#issuecomment-41877900
.

@pkourany
Copy link
Contributor

pkourany commented May 1, 2014

DOH, if I had only read the actual pull changes then I would have understood! I gotta stop doing stuff at one in the morning! :)

@jacobrosenthal
Copy link
Contributor Author

Eagerly awaiting this. Let me know if theres something else I need to do

@towynlin
Copy link
Contributor

towynlin commented May 5, 2014

Thanks for the ping Jacob. We're planning the sprint today. I hope to review this tomorrow. Oh! Hey, you haven't signed our CLA; I can't merge until you do that: https://docs.google.com/a/spark.io/forms/d/1_2P-vRKGUFg5bmpcKLHO_qNZWGi5HKYnfrrkd-sbZoA/viewform

towynlin pushed a commit that referenced this pull request May 8, 2014
unroll F macro and restore print const __FlashStringHelper *
@towynlin towynlin merged commit b30298d into particle-iot:master May 8, 2014
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

Successfully merging this pull request may close these issues.

3 participants