Skip to content

Instantly share code, notes, and snippets.

@me-no-dev
Created September 23, 2016 10:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save me-no-dev/f137a950ce6dedb641d427d8db6355d2 to your computer and use it in GitHub Desktop.
Save me-no-dev/f137a950ce6dedb641d427d8db6355d2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE * fp;
char *buffer;
long flen;
char *fname;
char pname[1024];
if( argc == 2 ) {
fname = argv[1];
strcpy(pname, fname);
char * dot = strchr(pname, '.');
while(dot != NULL){
*dot = '_';
dot = strchr(pname, '.');
}
}else {
printf("Filename not supplied\n");
return 1;
}
fp = fopen(fname, "rb");
fseek(fp, 0, SEEK_END);
flen = ftell(fp);
rewind(fp);
buffer = (char *)malloc((flen+1)*sizeof(char));
fread(buffer, flen, 1, fp);
fclose(fp);
printf("\n//File: %s, Size: %lu\n",fname, flen);
printf("#define %s_len %lu\n", pname, flen);
printf("const uint8_t %s[] PROGMEM = {\n", pname);
long i;
for(i=0;i<flen;i++){
printf(" 0x%02X", (uint8_t)buffer[i]);
if(i<(flen - 1)){
printf(",");
}
if((i%16)==15){
printf("\n");
}
}
printf("\n};\n\n");
free(buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment