Permalink
Browse files

Split posix cli v.s. embedded - generates frame on run or dofbit gene…

…rates a C file
  • Loading branch information...
tz
tz committed Feb 26, 2010
1 parent 7473ea8 commit e84988f06dd3d504d207f227909e9d2b8f3f07ad
Showing with 213 additions and 222 deletions.
  1. +2 −4 Makefile
  2. +10 −4 Makefile.avr
  3. +13 −0 README
  4. +42 −42 dofbit.c
  5. +0 −7 ecctable.h
  6. +0 −81 framask.h
  7. +3 −3 qrbits.h
  8. +11 −3 qrenc.c
  9. +47 −28 qrencode.c
  10. +7 −12 qrencode.h
  11. +77 −34 qrframe.c
  12. +1 −4 regtest.sh
View
@@ -2,15 +2,13 @@ CFLAGS:=-Wall -g -Os
#CC=avr-gcc -mmcu=atmega328p
CC=gcc
-all: dofbit qrencode
+all: qrencode
qrduino: qrduino.o qrencode.o
dofbit: dofbit.o qrframe.o
-qrenc.o qrencode.o: qrencode.h framask.h
-
-qrencode: qrenc.o qrencode.o
+qrencode: qrenc.o qrencode.o qrframe.o
clean:
rm -rf qrencode *.o qrdunio dofbit
View
@@ -1,3 +1,5 @@
+HOSTGCC=gcc
+
all: lcd.hex
.SUFFIXES: .elf .hex .eep .lss .sym .upload .dsm
@@ -26,12 +28,16 @@ MAP=-Wl,"-Map" -Wl,"$@.map" -Wl,"--cref"
.hex.upload:
avrdude -F -p $(CPU) -P $(PORT) -c arduino -b 57600 -U $^
-lcd.elf: lcd.o qrencode.o
+lcd.elf: lcd.o qrencode.o qrv6l1.o
avr-gcc $(CFLAGS) -Wall -mmcu=$(CPU) $^ -o $@
-qrencode.o: qrencode.h framask.h qrencode.c
-
qrduino.elf: qrduino.o qrencode.o
clean:
- rm -rf qrencode *.o qrdunio
+ rm -rf qrencode *.o qrdunio dofbit qrv6l1.*
+
+qrv6l1.c: dofbit
+ ./dofbit 6 1 >qrv6l1.c
+
+dofbit: dofbit.c qrframe.c
+ $(HOSTGCC) $^ -o $@
View
13 README
@@ -0,0 +1,13 @@
+EMBEDDED QR CODE GENERATOR
+
+Copyright 2010, tz@execpc.com.
+
+Relased under ther terms of the GNU General Public License v3.
+
+Targetd toward limited RAM systems - it tends to use more code and is slower but fits within an Arduino.
+
+For linux/posix, type make. For arduino, type make -f Makefile.avr.
+
+qrenc defaults to version 6, level L ecc, but you can specify the version, or the version and the error level.
+
+dofbits will generate a C file with the frame for one version/ecc level which will save a lot of RAM. This file will link with qrencode.c
View
@@ -1,25 +1,36 @@
#include <string.h>
-unsigned char qrframe[177*177];
-unsigned char framask[177*89];
-unsigned char qrwidth, qrwidbytes;
-
-#include "qrbits.h"
-
-void initframe(unsigned char vers);
-
+extern void initframe(void);
+extern void initecc(unsigned char, unsigned char);
+extern unsigned char neccblk1;
+extern unsigned char neccblk2 ;
+extern unsigned char datablkw;
+extern unsigned char eccblkwid;
+extern unsigned char VERSION;
+extern unsigned char ECCLEVEL;
+extern unsigned char WD, WDB; // filled in from verison by initframe
+extern unsigned char *framebase;
+extern unsigned char *framask;
+
+#ifndef __AVR__
+#define PROGMEM
+#define memcpy_P memcpy
+#define __LPM(x) x
+#else
+#include <avr/pgmspace.h>
+#endif
#include "ecctable.h"
#include <stdio.h>
#include <stdlib.h>
+
int main(int argc, char *argv[])
{
unsigned char i, j, b;
- unsigned char v,w;
if( argc != 3 )
- printf( "ruires Version ECC-level (1-4)" );
+ printf( "params: Version (1-40) ECC-level (1-4)" );
unsigned ecc = atoi(argv[2]);
if( ecc < 1 || ecc > 4 )
@@ -28,52 +39,41 @@ int main(int argc, char *argv[])
if( vers > 40 )
return -1;
- printf( "#define VERSION (%d)\n", vers );
- printf( "#define ECCLEVEL (%d)\n", ecc );
-
- ecc -= 1;
- ecc *= 4;
- ecc += (vers - 1) * 16;
-
- printf( "#define BLOCKS1 (%d)\n", eccblocks[ecc++] );
- printf( "#define BLOCKS2 (%d)\n", eccblocks[ecc++] );
- printf( "#define DATAWID (%d)\n", eccblocks[ecc++] );
- printf( "#define ECCWID (%d)\n", eccblocks[ecc++] );
+ initecc(ecc, vers);
- initframe(vers);
- v = vers * 4 + 17;
-
- printf( "#define WD (%d)\n#define WDB ((WD+7)/8)\n", v ); // width
- printf( "static const unsigned char qrwidbytes = ((WD+7)/8);\n" );
+ printf( "const unsigned char neccblk1 = %d;\n", neccblk1 );
+ printf( "const unsigned char neccblk2 = %d;\n", neccblk2 );
+ printf( "const unsigned char datablkw = %d;\n", datablkw );
+ printf( "const unsigned char eccblkwid = %d;\n", eccblkwid );
+ printf( "const unsigned char VERSION = %d;\n", VERSION );
+ printf( "const unsigned char ECCLEVEL = %d;\n", ECCLEVEL );
+ printf( "const unsigned char WD = %d;\n", WD );
+ printf( "const unsigned char WDB = %d;\n", WDB );
+ printf( "unsigned char strinbuf[%d];\n", (datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2 );
+ printf( "unsigned char qrframe[%d];\n", WD*WDB < 600? 600 : WD*WDB );
+ printf( "unsigned char rlens[%d];\n", WD+1 );
printf( "#ifndef __AVR__\n#define PROGMEM\n#define memcpy_P memcpy\n#define __LPM(x) *x\n#else\n"
- "#include <avr/pgmspace.h>\n#endif\nstatic const unsigned char framebase[] PROGMEM = {\n" );
+ "#include <avr/pgmspace.h>\n#endif\nconst unsigned char framebase[] PROGMEM = {\n" );
+
+ initframe();
- w = (v+7)>>3;
- for (j = 0; j < v; j++) {
- for (i = 0; i < v; i+= 8) {
- b = qrframe[j*w+(i>>3)];
+ for (j = 0; j < WD; j++) {
+ for (i = 0; i < WDB; i++) {
+ b = framebase[j*WDB+i];
printf("0x%02x,", b );
}
printf("\n");
}
- printf( "};\n\nstatic const unsigned char framask[] PROGMEM = {\n" );
- unsigned tt, tri = v*(v+1)/2;
+ printf( "};\n\nconst unsigned char framask[] PROGMEM = {" );
+ unsigned tt, tri = WD*(WD+1)/2;
tri = (tri+7)/8;
for( tt = 0; tt < tri; tt++ ) {
- if( !(tt % w) )
+ if( !(tt % WDB) )
printf("\n");
printf("0x%02x,", framask[tt] );
}
printf( "\n};\n" );
-#if 0
- for (j = 0; j < v; j++) {
- for (i = 0; i < v; i++) {
- printf(" %d", FIXEDBIT(j,i) );
- }
- printf("\n");
- }
-#endif
return 0;
}
View
@@ -1,10 +1,3 @@
-#ifndef __AVR__
-#define PROGMEM
-#define memcpy_P memcpy
-#define __LPM(x) x
-#else
-#include <avr/pgmspace.h>
-#endif
static const unsigned char eccblocks[] PROGMEM = {
1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17,
1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28,
View
@@ -1,81 +0,0 @@
-#define VERSION (6)
-#define ECCLEVEL (1)
-#define BLOCKS1 (2)
-#define BLOCKS2 (0)
-#define DATAWID (68)
-#define ECCWID (18)
-#define WD (41)
-#define WDB ((WD+7)/8)
-static const unsigned char qrwidbytes = ((WD+7)/8);
-#ifndef __AVR__
-#define PROGMEM
-#define memcpy_P memcpy
-#define __LPM(x) *x
-#else
-#include <avr/pgmspace.h>
-#endif
-static const unsigned char framebase[] PROGMEM = {
-0xfe,0x00,0x00,0x00,0x3f,0x80,
-0x82,0x00,0x00,0x00,0x20,0x80,
-0xba,0x00,0x00,0x00,0x2e,0x80,
-0xba,0x00,0x00,0x00,0x2e,0x80,
-0xba,0x00,0x00,0x00,0x2e,0x80,
-0x82,0x00,0x00,0x00,0x20,0x80,
-0xfe,0xaa,0xaa,0xaa,0xbf,0x80,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0xf8,0x00,
-0x00,0x80,0x00,0x00,0x88,0x00,
-0xfe,0x00,0x00,0x00,0xa8,0x00,
-0x82,0x00,0x00,0x00,0x88,0x00,
-0xba,0x00,0x00,0x00,0xf8,0x00,
-0xba,0x00,0x00,0x00,0x00,0x00,
-0xba,0x00,0x00,0x00,0x00,0x00,
-0x82,0x00,0x00,0x00,0x00,0x00,
-0xfe,0x00,0x00,0x00,0x00,0x00,
-};
-
-static const unsigned char framask[] PROGMEM = {
-
-0xff,0xff,0xff,0xff,0xff,0xf8,
-0x10,0x04,0x00,0x80,0x08,0x00,
-0x40,0x01,0x00,0x02,0x00,0x02,
-0x00,0x01,0x00,0x00,0x40,0x00,
-0x08,0x00,0x00,0x80,0x00,0x04,
-0x00,0x00,0x10,0x00,0x00,0x20,
-0x00,0x00,0x20,0x00,0x00,0x10,
-0x00,0x00,0x04,0x00,0x00,0x00,
-0x80,0x00,0x00,0x08,0x00,0x00,
-0x00,0x40,0x00,0x00,0x01,0x00,
-0x00,0x00,0x02,0x00,0x00,0x00,
-0x02,0x00,0x00,0x00,0xff,0xc0,
-0x00,0x00,0x7f,0xf0,0x00,0x00,
-0x1f,0xfe,0x00,0x00,0x03,0xff,
-0xe0,0x00,0x00,0x3f,0xff,0x00,
-0x00,0x00,0x07,0xfc,0x00,0x00,
-0x00,0x0f,0xf8,0x00,0x00,0x00,
-0x0f,0xf8,0x00,0x00,0x00,0x00,
-};
View
@@ -1,3 +1,3 @@
-#define QRBIT(x,y) ( ( qrframe[((x)>>3) + (y) * qrwidbytes] >> (7-((x) & 7 ))) & 1 )
-#define SETQRBIT(x,y) qrframe[((x)>>3) + (y) * qrwidbytes] |= 0x80 >> ((x) & 7)
-#define TOGQRBIT(x,y) qrframe[((x)>>3) + (y) * qrwidbytes] ^= 0x80 >> ((x) & 7)
+#define QRBIT(x,y) ( ( qrframe[((x)>>3) + (y) * WDB] >> (7-((x) & 7 ))) & 1 )
+#define SETQRBIT(x,y) qrframe[((x)>>3) + (y) * WDB] |= 0x80 >> ((x) & 7)
+#define TOGQRBIT(x,y) qrframe[((x)>>3) + (y) * WDB] ^= 0x80 >> ((x) & 7)
View
14 qrenc.c
@@ -9,11 +9,19 @@ int main(int argc, char **argv)
int x, y;
int ret;
- ret = fread(strinbuf, 1, sizeof(strinbuf), stdin);
- strinbuf[ret] = '\0';
+ x = 1;
+ if( argc > 2 )
+ x = atoi(argv[2]);
+ y = 6;
+ if( argc > 1 )
+ y = atoi(argv[1]);
+
+ y = initecc(x,y);
- // strcpy((char *)strinbuf, "Hello World!");
+ ret = fread(strinbuf, 1, y, stdin);
+ strinbuf[ret] = '\0';
+ initframe();
qrencode();
/* data */
Oops, something went wrong.

2 comments on commit e84988f

Hi, I'm trying to use the QRduino for make a QR code and show it in a 3,2 touch panel display, but I can´t understand about the files for do it, can you upload an example please? or tutorial about use it.

Thanks you.

Owner

tz1 replied Jun 25, 2015

It is rude to usemcommemts on commits instead of using an issue. Ask in the right place and i might answer

Please sign in to comment.