From 768fc9d49096aa8a8247f31ec8d5b8dd09d6b0ad Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Thu, 20 May 2021 19:18:16 +0200 Subject: camera test app --- fw/fe310/test/Makefile | 6 +- fw/fe310/test/cam.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ fw/fe310/test/cam.h | 2 + fw/fe310/test/main.c | 15 ++++- fw/fe310/test/phone.c | 4 +- 5 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 fw/fe310/test/cam.c create mode 100644 fw/fe310/test/cam.h (limited to 'fw/fe310') diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile index aef5f29..c5f68fb 100644 --- a/fw/fe310/test/Makefile +++ b/fw/fe310/test/Makefile @@ -1,9 +1,11 @@ include ../common.mk -CFLAGS += -I../eos -I../bsp/include -I../bsp/drivers +CRYPTO_DIR = ../../../crypto + +CFLAGS += -I.. -I../eos -I../bsp/include -I../bsp/drivers -I$(CRYPTO_DIR) LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds -DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o +DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o test.o TARGET = phone all: $(TARGET) diff --git a/fw/fe310/test/cam.c b/fw/fe310/test/cam.c new file mode 100644 index 0000000..caab2cc --- /dev/null +++ b/fw/fe310/test/cam.c @@ -0,0 +1,166 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include + +#include "cam.h" + +#include + +static int cam_init = 0; +static int cam_capture = 0; + +#define CHUNK_SIZE 512 + +#define CAM_W 640 +#define CAM_H 480 + +static void transfer_chunk(uint8_t *fbuf, size_t size, int first, int last, uint32_t addr) { + int rv; + + eos_cam_fbuf_read(fbuf, size, first); + if (last) { + eos_cam_fbuf_done(); + eos_cam_capture(); + } + + eos_spi_select(EOS_SPI_DEV_EVE); + eve_cmd_burst_start(); + if (first) eve_cmd(CMD_LOADIMAGE, "ww+", addr, EVE_OPT_NODL); + eve_cmd_write(fbuf, size); + if (last) eve_cmd_end(); + eve_cmd_burst_end(); + rv = eve_cmd_exec(last); + if (rv) printf("CMD EXEC ERR\n"); + if (!last) eos_spi_select(EOS_SPI_DEV_CAM); +} + +static void transfer_img(uint32_t addr) { + int i; + uint32_t fb_size; + uint32_t fb_div; + uint32_t fb_mod; + uint8_t fbuf[CHUNK_SIZE]; + + cam_capture = 1; + fb_size = eos_cam_fbuf_size(); + + fb_div = fb_size / CHUNK_SIZE; + fb_mod = fb_size % CHUNK_SIZE; + for (i=0; imem_next; + + transfer_img(addr); + eve_window_root_draw(root); + } + eos_spi_deselect(); + eos_evtq_push(EOS_EVT_USER, NULL, 0); +} + +static void image_draw(EVEFreeWidget *widget) { + EVEWindowRoot *root = widget->w.page->v.window->root; + uint32_t addr = root->mem_next; + + if (cam_capture) { + // eve_freew_tag(widget); + eve_cmd_dl(TAG_MASK(0)); + eve_cmd_dl(BEGIN(EVE_BITMAPS)); + // eve_cmd_dl(BITMAP_HANDLE(15)); + eve_cmd_dl(BITMAP_SOURCE(addr)); + eve_cmd_dl(BITMAP_LAYOUT(EVE_RGB565, CAM_W * 2, CAM_H)); + eve_cmd_dl(BITMAP_LAYOUT_H(CAM_W * 2, CAM_H)); + eve_cmd_dl(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, CAM_H, CAM_W)); + eve_cmd_dl(BITMAP_SIZE_H(CAM_H, CAM_W)); + eve_cmd(CMD_LOADIDENTITY, ""); + eve_cmd(CMD_TRANSLATE, "ww", CAM_H * 65536, 0); + eve_cmd(CMD_ROTATE, "w", 90 * 65536 / 360); + eve_cmd(CMD_SETMATRIX, ""); + eve_cmd_dl(VERTEX2F(0, 0)); + eve_cmd_dl(TAG_MASK(1)); + } +} + +static int image_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt) { + return 0; +} + +void fbuf_print(uint8_t *fbuf, size_t size) { + int i; + + for (i=0; i