[Feature][MD310EU][task-view-1009] Create MD310EU project code directory

Change-Id: I57cd3c474efe4493ae8a242d7e2fa643ad8ecbde
diff --git a/lynq/MD310EU/ap/app/qrencode/Makefile b/lynq/MD310EU/ap/app/qrencode/Makefile
new file mode 100755
index 0000000..1acdf99
--- /dev/null
+++ b/lynq/MD310EU/ap/app/qrencode/Makefile
@@ -0,0 +1,59 @@
+#*******************************************************************************
+# include ZTE application makefile
+#*******************************************************************************
+include $(COMMON_MK)
+		
+##############USER COMIZE BEGIN################
+EXEC1 = qrencode
+EXEC2 = png2bmp
+EXEC3 = fb
+EXEC4 = fbtest
+OBJS1 = bitstream.o mask.o mmask.o mqrspec.o qrenc.o qrencode.o \
+	qrinput.o qrspec.o rscode.o split.o
+OBJS2 = common.o png2bmp.o
+OBJS3 = fb.o
+OBJS4 = fbtest.o
+
+LDLIBS += -lpng -L$(zte_lib_path)/libpng/install/lib
+LDLIBS += -L$(zte_lib_path)/zlib/install/lib -lz -lm
+CFLAGS += -I./
+CFLAGS += -I$(zte_lib_path)/libpng/install/include
+CFLAGS += -I$(zte_lib_path)/zlib/install/include
+
+
+
+##############USER COMIZE END##################
+
+#*******************************************************************************
+# targets
+#*******************************************************************************
+all: $(EXEC1) $(EXEC2) $(EXEC3) $(EXEC4)
+
+$(EXEC1): $(OBJS1)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+$(EXEC2): $(OBJS2)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+$(EXEC3): $(OBJS3)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+$(EXEC4): $(OBJS4)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+romfs:
+	$(ROMFSINST) $(EXEC1) /sbin/$(EXEC1)
+	$(ROMFSINST) $(EXEC2) /sbin/$(EXEC2)
+	$(ROMFSINST) $(EXEC3) /sbin/$(EXEC3)
+	$(ROMFSINST) $(EXEC4) /sbin/$(EXEC4)
+
+clean:
+	-rm -f $(EXEC1) *.elf *.gdb *.o
+	-rm -f $(EXEC2) *.elf *.gdb *.o
+	-rm -f $(EXEC3) *.elf *.gdb *.o
+	-rm -f $(EXEC4) *.elf *.gdb *.o
+
diff --git a/lynq/MD310EU/ap/app/qrencode/fb.c b/lynq/MD310EU/ap/app/qrencode/fb.c
new file mode 100755
index 0000000..b46a197
--- /dev/null
+++ b/lynq/MD310EU/ap/app/qrencode/fb.c
@@ -0,0 +1,196 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include <string.h>

+#include <fcntl.h>

+#include <unistd.h>

+#include <sys/mman.h>

+#include <sys/ioctl.h>

+#include <linux/fb.h>

+

+#pragma pack(1)

+typedef struct {

+    unsigned short bfType;

+    unsigned int bfSize;

+    unsigned short bfReserved1;

+    unsigned short bfReserved2;

+    unsigned int bfOffBits;

+} BMPFILEHEADER;

+

+typedef struct {

+    unsigned int biSize;

+    int biWidth;

+    int biHeight;

+    unsigned short biPlanes;

+    unsigned short biBitCount;

+    unsigned int biCompression;

+    unsigned int biSizeImage;

+    int biXPelsPerMeter;

+    int biYPelsPerMeter;

+    unsigned int biClrUsed;

+    unsigned int biClrImportant;

+} BMPINFOHEADER;

+#pragma pack()

+

+#define SWAP_ENDIAN_USHORT(value) ((unsigned short)((((unsigned short)(value) & 0xFF) << 8) | (((unsigned short)(value) & 0xFF00) >> 8)))

+

+// Convert 24-bit RGB to 16-bit RGB565

+unsigned short rgb24_to_rgb565(unsigned char r, unsigned char g, unsigned char b) {

+	unsigned short color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);

+    unsigned short swapped = SWAP_ENDIAN_USHORT(color);

+	return swapped;

+}

+

+int main(int argc, char *argv[]) {

+	FILE *fp = NULL;

+	unsigned char *line = NULL;

+    BMPFILEHEADER fileHeader;

+    BMPINFOHEADER infoHeader;

+

+    if (argc < 2) {

+        printf("No para. Please input bmp filepath.\n");

+		return;

+    }

+

+    // Open BMP file

+    fp = fopen(argv[1], "rb");

+    if (!fp) {

+        perror("Cannot open BMP file");

+        return -1;

+    }

+

+    // Read BMP headers

+    if (fread(&fileHeader, sizeof(BMPFILEHEADER), 1, fp) != 1) {

+        perror("Failed to read file header");

+        fclose(fp);

+        return -1;

+    }

+	printf("fileHeader: bfType=%x, bfSize=%u, bfOffBits=%u\n", 

+	fileHeader.bfType, fileHeader.bfSize, fileHeader.bfOffBits);

+

+    if (fread(&infoHeader, sizeof(BMPINFOHEADER), 1, fp) != 1) {

+        perror("Failed to read info header");

+        fclose(fp);

+        return -1;

+    }

+	printf("infoHeader: biSize=%u, biWidth=%d, biHeight=%d\n", 

+	infoHeader.biSize, infoHeader.biWidth, infoHeader.biHeight);

+	printf("infoHeader: biPlanes=%u, biBitCount=%u, biCompression=%u\n", 

+	infoHeader.biPlanes, infoHeader.biBitCount, infoHeader.biCompression);

+	printf("infoHeader: biSizeImage=%u, biXPelsPerMeter=%d, biYPelsPerMeter=%d\n", 

+	infoHeader.biSizeImage, infoHeader.biXPelsPerMeter, infoHeader.biYPelsPerMeter);

+	printf("infoHeader: biClrUsed=%u, biClrImportant=%d\n", 

+	infoHeader.biClrUsed, infoHeader.biClrImportant);

+

+    // Check BMP format

+    if (fileHeader.bfType != 0x4D42) { // ASCII code for "BM"

+        printf("Not a valid BMP file\n");

+        fclose(fp);

+        return -1;

+    }

+

+    // Check bit depth

+    if (infoHeader.biBitCount != 24 && infoHeader.biBitCount != 16) {

+        printf("Only 16-bit or 24-bit BMP supported, current image is %d-bit\n", infoHeader.biBitCount);

+        fclose(fp);

+        return -1;

+    }

+

+    // Open framebuffer device

+    int fbfd = open("/dev/fb0", O_RDWR);

+    if (fbfd < 0) {

+        perror("Cannot open framebuffer device");

+        fclose(fp);

+        return -1;

+    }

+

+    // Get screen information

+    struct fb_var_screeninfo vinfo;

+    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) < 0) {

+        perror("Cannot get screen info");

+        close(fbfd);

+        fclose(fp);

+        return -1;

+    }

+

+    // Check screen color depth

+    if (vinfo.bits_per_pixel != 16) {

+        printf("This program only supports 16-bit color depth display\n");

+        close(fbfd);

+        fclose(fp);

+        return -1;

+    }

+

+    // Calculate screen size and map framebuffer

+    long screensize = vinfo.xres * vinfo.yres * 2; // 16-bit = 2 bytes

+    unsigned char *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

+    if (fbp == MAP_FAILED) {

+        perror("Cannot map framebuffer");

+        close(fbfd);

+        fclose(fp);

+        return -1;

+    }

+

+    // Move file pointer to image data

+    fseek(fp, fileHeader.bfOffBits, SEEK_SET);

+

+    // Prepare to read image data

+    unsigned short *fb16 = (unsigned short *)fbp;

+    int bytes_per_pixel = infoHeader.biBitCount / 8;

+    int padding = (4 - (infoHeader.biWidth * bytes_per_pixel) % 4) % 4;

+    line = malloc(infoHeader.biWidth * bytes_per_pixel + padding);

+

+    if (line == NULL) {

+        perror("Memory allocation failed");

+        munmap(fbp, screensize);

+        close(fbfd);

+        fclose(fp);

+        return -1;

+    }

+

+    // Read and display image data

+    int y = 0;

+    for (y = infoHeader.biHeight - 1; y >= 0; y--) {

+        if (fread(line, infoHeader.biWidth * bytes_per_pixel + padding, 1, fp) != 1) {

+            printf("Failed to read image data\n");

+            free(line);

+            munmap(fbp, screensize);

+            close(fbfd);

+            fclose(fp);

+            return -1;

+        }

+        int x = 0;

+        for (x = 0; x < infoHeader.biWidth; x++) {

+            unsigned short pixel;

+            int location = x + y * vinfo.xres;

+

+            if (infoHeader.biBitCount == 24) {

+                // 24-bit BMP (BGR format)

+                unsigned char b = line[x * 3];

+                unsigned char g = line[x * 3 + 1];

+                unsigned char r = line[x * 3 + 2];

+                pixel = rgb24_to_rgb565(r, g, b);

+            } else {

+                // 16-bit BMP (already in RGB565 format)

+                pixel = *(unsigned short*)&line[x * 2];

+            }

+

+            // Check if within display bounds

+            if (x < vinfo.xres && y < vinfo.yres) {

+                fb16[location] = pixel;

+            }

+        }

+    }

+

+	// To display

+    write(fbfd, "1", 1);

+    usleep(1000*100);

+

+    // Cleanup resources

+    free(line);

+	fclose(fp);

+    munmap(fbp, screensize);

+    close(fbfd);

+

+    printf("Image display completed\n");

+    return 0;

+}
\ No newline at end of file
diff --git a/lynq/MD310EU/ap/app/qrencode/fbtest.c b/lynq/MD310EU/ap/app/qrencode/fbtest.c
new file mode 100644
index 0000000..df6b0bd
--- /dev/null
+++ b/lynq/MD310EU/ap/app/qrencode/fbtest.c
@@ -0,0 +1,121 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include <string.h>

+#include <fcntl.h>

+#include <unistd.h>

+#include <sys/mman.h>

+#include <sys/ioctl.h>

+#include <linux/fb.h>

+

+// Define colors in RGB565 format

+#define COLOR_WHITE  0xFFFF  // 11111 111111 11111

+#define COLOR_BLACK  0x0000  // 00000 000000 00000

+#define COLOR_RED    0xF800  // 11111 000000 00000

+#define COLOR_GREEN  0x07E0  // 00000 111111 00000

+#define COLOR_BLUE   0x001F  // 00000 000000 11111

+

+#define SWAP_ENDIAN_USHORT(value) ((unsigned short)((((unsigned short)(value) & 0xFF) << 8) | (((unsigned short)(value) & 0xFF00) >> 8)))

+

+// Structure to hold color information

+typedef struct {

+    const char* name;

+    unsigned short value;

+} ColorInfo;

+

+// Array of supported colors

+const ColorInfo COLORS[] = {

+    {"WHITE", COLOR_WHITE},

+    {"BLACK", COLOR_BLACK},

+    {"RED", COLOR_RED},

+    {"GREEN", COLOR_GREEN},

+    {"BLUE", COLOR_BLUE}

+};

+

+const int NUM_COLORS = sizeof(COLORS) / sizeof(COLORS[0]);

+int fbfd = 0;

+

+// Function to fill screen with a color

+void fill_screen(unsigned short* fb, int width, int height, unsigned short color) {

+	//unsigned short color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);

+    unsigned short swapped = SWAP_ENDIAN_USHORT(color);

+	int i = 0;

+    for (i = 0; i < width * height; i++) {

+        fb[i] = swapped;

+    }

+	

+	write(fbfd, "1", 1);

+	usleep(500000);

+}

+

+// Function to display color by name

+int display_color(const char* color_name, unsigned short* fb, int width, int height) {

+	int i = 0;

+    for (i = 0; i < NUM_COLORS; i++) {

+        if (strcmp(color_name, COLORS[i].name) == 0) {

+            fill_screen(fb, width, height, COLORS[i].value);

+            return 0;

+        }

+    }

+    return -1;

+}

+

+int main(int argc, char *argv[]) {

+    if (argc != 2) {

+        printf("Usage: %s [WHITE|BLACK|RED|GREEN|BLUE|AUTO]\n", argv[0]);

+        return -1;

+    }

+

+    // Open framebuffer device

+    fbfd = open("/dev/fb0", O_RDWR);

+    if (fbfd < 0) {

+        perror("Cannot open framebuffer device");

+        return -1;

+    }

+

+    // Get screen information

+    struct fb_var_screeninfo vinfo;

+    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) < 0) {

+        perror("Cannot get screen info");

+        close(fbfd);

+        return -1;

+    }

+

+    // Check if screen is 16-bit

+    if (vinfo.bits_per_pixel != 16) {

+        printf("Only 16-bit display is supported\n");

+        close(fbfd);

+        return -1;

+    }

+

+    // Map framebuffer

+    long screensize = vinfo.xres * vinfo.yres * 2; // 16 bits = 2 bytes

+    unsigned short *fbp = (unsigned short *)mmap(0, screensize, 

+                                               PROT_READ | PROT_WRITE, 

+                                               MAP_SHARED, fbfd, 0);

+    if (fbp == MAP_FAILED) {

+        perror("Cannot map framebuffer");

+        close(fbfd);

+        return -1;

+    }

+

+    if (strcmp(argv[1], "AUTO") == 0) {

+        // Auto mode: display each color

+		int i = 0;

+		for (i = 0; i < NUM_COLORS; i++) {

+			fill_screen(fbp, vinfo.xres, vinfo.yres, COLORS[i].value);

+		}

+    } else {

+        // Single color mode

+        if (display_color(argv[1], fbp, vinfo.xres, vinfo.yres) < 0) {

+            printf("Invalid color. Supported colors: WHITE, BLACK, RED, GREEN, BLUE, AUTO\n");

+            munmap(fbp, screensize);

+            close(fbfd);

+            return -1;

+        }

+    }

+

+    // Cleanup

+    munmap(fbp, screensize);

+    close(fbfd);

+    return 0;

+}
\ No newline at end of file