summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
Diffstat (limited to 'fw')
-rw-r--r--fw/fe310/eos/dev/cam.c140
-rw-r--r--fw/fe310/eos/dev/cam.h88
-rw-r--r--fw/fe310/eos/dev/drv/arducam.c99
-rw-r--r--fw/fe310/eos/dev/drv/arducam.h8
4 files changed, 107 insertions, 228 deletions
diff --git a/fw/fe310/eos/dev/cam.c b/fw/fe310/eos/dev/cam.c
deleted file mode 100644
index 50a0bdd..0000000
--- a/fw/fe310/eos/dev/cam.c
+++ /dev/null
@@ -1,140 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "eos.h"
-
-#include "soc/spi.h"
-
-#include "cam.h"
-
-const int _eos_cam_resolution[][2] = {
- {0, 0 },
- // C/SIF Resolutions
- {88, 72 }, /* QQCIF */
- {176, 144 }, /* QCIF */
- {352, 288 }, /* CIF */
- {88, 60 }, /* QQSIF */
- {176, 120 }, /* QSIF */
- {352, 240 }, /* SIF */
- // VGA Resolutions
- {40, 30 }, /* QQQQVGA */
- {80, 60 }, /* QQQVGA */
- {160, 120 }, /* QQVGA */
- {320, 240 }, /* QVGA */
- {640, 480 }, /* VGA */
- {60, 40 }, /* HQQQVGA */
- {120, 80 }, /* HQQVGA */
- {240, 160 }, /* HQVGA */
- // FFT Resolutions
- {64, 32 }, /* 64x32 */
- {64, 64 }, /* 64x64 */
- {128, 64 }, /* 128x64 */
- {128, 128 }, /* 128x128 */
- {320, 320 }, /* 128x128 */
- // Other
- {128, 160 }, /* LCD */
- {128, 160 }, /* QQVGA2 */
- {720, 480 }, /* WVGA */
- {752, 480 }, /* WVGA2 */
- {800, 600 }, /* SVGA */
- {1024, 768 }, /* XGA */
- {1280, 1024}, /* SXGA */
- {1600, 1200}, /* UXGA */
- {1280, 720 }, /* HD */
- {1920, 1080}, /* FHD */
- {2560, 1440}, /* QHD */
- {2048, 1536}, /* QXGA */
- {2560, 1600}, /* WQXGA */
- {2592, 1944}, /* WQXGA2 */
-};
-
-#define CAM_REG_CAPTURE_CTRL 0x01
-#define CAM_REG_FIFO_CTRL 0x04
-
-#define CAM_REG_GPIO_DIR 0x05
-#define CAM_REG_GPIO_WR 0x06
-#define CAM_REG_GPIO_RD 0x45
-
-#define CAM_REG_STATUS 0x41
-
-#define CAM_REG_VER 0x40
-
-#define CAM_REG_READ_BURST 0x3c
-#define CAM_REG_READ_BYTE 0x3d
-
-#define CAM_REG_FIFO_SIZE1 0x42
-#define CAM_REG_FIFO_SIZE2 0x43
-#define CAM_REG_FIFO_SIZE3 0x44
-
-#define CAM_VAL_FIFO_CTRL_CLEAR 0x01
-#define CAM_VAL_FIFO_CTRL_START 0x02
-#define CAM_VAL_FIFO_CTRL_RSTWR 0x10
-#define CAM_VAL_FIFO_CTRL_RSTRD 0x20
-
-#define CAM_VAL_STATUS_VSYNC 0x01
-#define CAM_VAL_STATUS_SHUTTER 0x02
-#define CAM_VAL_STATUS_CPTDONE 0x08
-
-#define CAM_VAL_GPIO_RST 0x01
-#define CAM_VAL_GPIO_PWRDN 0x02
-#define CAM_VAL_GPIO_PWREN 0x04
-
-static uint8_t reg_read(uint8_t addr) {
- uint8_t ret;
-
- eos_spi_cs_set();
- eos_spi_xchg8(addr, 0);
- ret = eos_spi_xchg8(0, 0);
- eos_spi_cs_clear();
-
- return ret;
-}
-
-static void reg_write(uint8_t addr, uint8_t val) {
- eos_spi_cs_set();
- eos_spi_xchg8(addr | 0x80, 0);
- eos_spi_xchg8(val, 0);
- eos_spi_cs_clear();
-}
-
-void eos_cam_capture(void) {
- reg_write(CAM_REG_FIFO_CTRL, CAM_VAL_FIFO_CTRL_START);
-}
-
-int eos_cam_capture_done(void) {
- return !!(reg_read(CAM_REG_STATUS) & CAM_VAL_STATUS_CPTDONE);
-}
-
-void eos_cam_capture_wait(void) {
- int done = 0;
-
- while (!done) {
- done = eos_cam_capture_done();
- }
-}
-
-uint32_t eos_cam_fbuf_size(void) {
- uint32_t ret;
-
- ret = reg_read(CAM_REG_FIFO_SIZE1);
- ret |= reg_read(CAM_REG_FIFO_SIZE2) << 8;
- ret |= (reg_read(CAM_REG_FIFO_SIZE3) & 0x7f) << 16;
- return ret;
-}
-
-void eos_cam_fbuf_read(uint8_t *buffer, uint16_t sz, int first) {
- int i;
-
- eos_spi_cs_set();
- eos_spi_xchg8(CAM_REG_READ_BURST, 0);
- if (first) eos_spi_xchg8(0, 0);
-
- for (i=0; i<sz; i++) {
- buffer[i] = eos_spi_xchg8(0, 0);
- }
- eos_spi_cs_clear();
-}
-
-void eos_cam_fbuf_done(void) {
- reg_write(CAM_REG_FIFO_CTRL, CAM_VAL_FIFO_CTRL_CLEAR);
-}
diff --git a/fw/fe310/eos/dev/cam.h b/fw/fe310/eos/dev/cam.h
deleted file mode 100644
index f61757b..0000000
--- a/fw/fe310/eos/dev/cam.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#include <stdint.h>
-
-typedef enum {
- PIXFORMAT_INVALID = 0,
- PIXFORMAT_BINARY, // 1BPP/BINARY
- PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE
- PIXFORMAT_RGB565, // 2BPP/RGB565
- PIXFORMAT_YUV422, // 2BPP/YUV422
- PIXFORMAT_BAYER, // 1BPP/RAW
- PIXFORMAT_JPEG, // JPEG/COMPRESSED
-} pixformat_t;
-
-typedef enum {
- FRAMESIZE_INVALID = 0,
- // C/SIF Resolutions
- FRAMESIZE_QQCIF, // 88x72
- FRAMESIZE_QCIF, // 176x144
- FRAMESIZE_CIF, // 352x288
- FRAMESIZE_QQSIF, // 88x60
- FRAMESIZE_QSIF, // 176x120
- FRAMESIZE_SIF, // 352x240
- // VGA Resolutions
- FRAMESIZE_QQQQVGA, // 40x30
- FRAMESIZE_QQQVGA, // 80x60
- FRAMESIZE_QQVGA, // 160x120
- FRAMESIZE_QVGA, // 320x240
- FRAMESIZE_VGA, // 640x480
- FRAMESIZE_HQQQVGA, // 60x40
- FRAMESIZE_HQQVGA, // 120x80
- FRAMESIZE_HQVGA, // 240x160
- // FFT Resolutions
- FRAMESIZE_64X32, // 64x32
- FRAMESIZE_64X64, // 64x64
- FRAMESIZE_128X64, // 128x64
- FRAMESIZE_128X128, // 128x128
- FRAMESIZE_320X320, // 320x320
- // Other
- FRAMESIZE_LCD, // 128x160
- FRAMESIZE_QQVGA2, // 128x160
- FRAMESIZE_WVGA, // 720x480
- FRAMESIZE_WVGA2, // 752x480
- FRAMESIZE_SVGA, // 800x600
- FRAMESIZE_XGA, // 1024x768
- FRAMESIZE_SXGA, // 1280x1024
- FRAMESIZE_UXGA, // 1600x1200
- FRAMESIZE_HD, // 1280x720
- FRAMESIZE_FHD, // 1920x1080
- FRAMESIZE_QHD, // 2560x1440
- FRAMESIZE_QXGA, // 2048x1536
- FRAMESIZE_WQXGA, // 2560x1600
- FRAMESIZE_WQXGA2, // 2592x1944
-} framesize_t;
-
-typedef enum {
- GAINCEILING_2X,
- GAINCEILING_4X,
- GAINCEILING_8X,
- GAINCEILING_16X,
- GAINCEILING_32X,
- GAINCEILING_64X,
- GAINCEILING_128X,
-} gainceiling_t;
-
-typedef enum {
- SDE_NORMAL,
- SDE_NEGATIVE,
-} sde_t;
-
-extern const int _eos_cam_resolution[][2];
-
-#define IM_LOG2_2(x) (((x) & 0x2ULL) ? ( 2 ) : 1) // NO ({ ... }) !
-#define IM_LOG2_4(x) (((x) & 0xCULL) ? ( 2 + IM_LOG2_2((x) >> 2)) : IM_LOG2_2(x)) // NO ({ ... }) !
-#define IM_LOG2_8(x) (((x) & 0xF0ULL) ? ( 4 + IM_LOG2_4((x) >> 4)) : IM_LOG2_4(x)) // NO ({ ... }) !
-#define IM_LOG2_16(x) (((x) & 0xFF00ULL) ? ( 8 + IM_LOG2_8((x) >> 8)) : IM_LOG2_8(x)) // NO ({ ... }) !
-#define IM_LOG2_32(x) (((x) & 0xFFFF0000ULL) ? (16 + IM_LOG2_16((x) >> 16)) : IM_LOG2_16(x)) // NO ({ ... }) !
-#define IM_LOG2(x) (((x) & 0xFFFFFFFF00000000ULL) ? (32 + IM_LOG2_32((x) >> 32)) : IM_LOG2_32(x)) // NO ({ ... }) !
-
-#define IM_MAX(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
-#define IM_MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
-#define IM_DIV(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _b ? (_a / _b) : 0; })
-#define IM_MOD(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _b ? (_a % _b) : 0; })
-
-void eos_cam_capture(void);
-int eos_cam_capture_done(void);
-void eos_cam_capture_wait(void);
-uint32_t eos_cam_fbuf_size(void);
-void eos_cam_fbuf_read(uint8_t *buffer, uint16_t sz, int first);
-void eos_cam_fbuf_done(void);
diff --git a/fw/fe310/eos/dev/drv/arducam.c b/fw/fe310/eos/dev/drv/arducam.c
new file mode 100644
index 0000000..e41d541
--- /dev/null
+++ b/fw/fe310/eos/dev/drv/arducam.c
@@ -0,0 +1,99 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "eos.h"
+
+#include "soc/spi.h"
+
+#include "arducam.h"
+
+#define ARDUCAM_REG_CAPTURE_CTRL 0x01
+#define ARDUCAM_REG_FIFO_CTRL 0x04
+
+#define ARDUCAM_REG_GPIO_DIR 0x05
+#define ARDUCAM_REG_GPIO_WR 0x06
+#define ARDUCAM_REG_GPIO_RD 0x45
+
+#define ARDUCAM_REG_STATUS 0x41
+
+#define ARDUCAM_REG_VER 0x40
+
+#define ARDUCAM_REG_READ_BURST 0x3c
+#define ARDUCAM_REG_READ_BYTE 0x3d
+
+#define ARDUCAM_REG_FIFO_SIZE1 0x42
+#define ARDUCAM_REG_FIFO_SIZE2 0x43
+#define ARDUCAM_REG_FIFO_SIZE3 0x44
+
+#define ARDUCAM_VAL_FIFO_CTRL_CLEAR 0x01
+#define ARDUCAM_VAL_FIFO_CTRL_START 0x02
+#define ARDUCAM_VAL_FIFO_CTRL_RSTWR 0x10
+#define ARDUCAM_VAL_FIFO_CTRL_RSTRD 0x20
+
+#define ARDUCAM_VAL_STATUS_VSYNC 0x01
+#define ARDUCAM_VAL_STATUS_SHUTTER 0x02
+#define ARDUCAM_VAL_STATUS_CPTDONE 0x08
+
+#define ARDUCAM_VAL_GPIO_RST 0x01
+#define ARDUCAM_VAL_GPIO_PWRDN 0x02
+#define ARDUCAM_VAL_GPIO_PWREN 0x04
+
+static uint8_t reg_read(uint8_t addr) {
+ uint8_t ret;
+
+ eos_spi_cs_set();
+ eos_spi_xchg8(addr, 0);
+ ret = eos_spi_xchg8(0, 0);
+ eos_spi_cs_clear();
+
+ return ret;
+}
+
+static void reg_write(uint8_t addr, uint8_t val) {
+ eos_spi_cs_set();
+ eos_spi_xchg8(addr | 0x80, 0);
+ eos_spi_xchg8(val, 0);
+ eos_spi_cs_clear();
+}
+
+void arducam_capture(void) {
+ reg_write(ARDUCAM_REG_FIFO_CTRL, ARDUCAM_VAL_FIFO_CTRL_START);
+}
+
+int arducam_capture_done(void) {
+ return !!(reg_read(ARDUCAM_REG_STATUS) & ARDUCAM_VAL_STATUS_CPTDONE);
+}
+
+void arducam_capture_wait(void) {
+ int done = 0;
+
+ while (!done) {
+ done = arducam_capture_done();
+ }
+}
+
+uint32_t arducam_fbuf_size(void) {
+ uint32_t ret;
+
+ ret = reg_read(ARDUCAM_REG_FIFO_SIZE1);
+ ret |= reg_read(ARDUCAM_REG_FIFO_SIZE2) << 8;
+ ret |= (reg_read(ARDUCAM_REG_FIFO_SIZE3) & 0x7f) << 16;
+ return ret;
+}
+
+void arducam_fbuf_read(uint8_t *buffer, uint16_t sz, int first) {
+ int i;
+
+ eos_spi_cs_set();
+ eos_spi_xchg8(ARDUCAM_REG_READ_BURST, 0);
+ if (first) eos_spi_xchg8(0, 0);
+
+ for (i=0; i<sz; i++) {
+ buffer[i] = eos_spi_xchg8(0, 0);
+ }
+ eos_spi_cs_clear();
+}
+
+void arducam_fbuf_done(void) {
+ reg_write(ARDUCAM_REG_FIFO_CTRL, ARDUCAM_VAL_FIFO_CTRL_CLEAR);
+}
diff --git a/fw/fe310/eos/dev/drv/arducam.h b/fw/fe310/eos/dev/drv/arducam.h
new file mode 100644
index 0000000..1db9f17
--- /dev/null
+++ b/fw/fe310/eos/dev/drv/arducam.h
@@ -0,0 +1,8 @@
+#include <stdint.h>
+
+void arducam_capture(void);
+int arducam_capture_done(void);
+void arducam_capture_wait(void);
+uint32_t arducam_fbuf_size(void);
+void arducam_fbuf_read(uint8_t *buffer, uint16_t sz, int first);
+void arducam_fbuf_done(void);