diff --git a/brun.sh b/brun.sh new file mode 100644 index 0000000..9634404 --- /dev/null +++ b/brun.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +K210_BIN_PATH=`pwd`/build + +#here should set to yours +BRUN_SCRIPT_PATH=/home/xel/K210/pyScript + +bin_file=$K210_BIN_PATH"/"$1".bin" + +echo $bin_file + +cd $BRUN_SCRIPT_PATH + +if [ ! -n "$2" ] ;then + python3 isp.py -b 115200 $bin_file -d /dev/ttyUSB0 +else + python3 isp.py -b 115200 $bin_file -d $2 +fi + diff --git a/brun_auto.sh b/brun_auto.sh new file mode 100644 index 0000000..9bb8f31 --- /dev/null +++ b/brun_auto.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ ! -n "$1" ] ;then + echo "you have to select a Bin File!" + exit +fi + +K210_BIN_PATH=`pwd`/build +BRUN_SCRIPT_PATH=/home/xel/K210/pyScript + +bin_file=$K210_BIN_PATH"/"$1".bin" + +echo $bin_file + +cd $BRUN_SCRIPT_PATH + +if [ ! -n "$2" ] ;then + python3 kflash.py -b 2000000 $bin_file -p /dev/ttyUSB0 +else + python3 kflash.py -b 1000000 $bin_file -p $2 +fi + diff --git a/gdb.sh b/gdb.sh new file mode 100644 index 0000000..50cd5fa --- /dev/null +++ b/gdb.sh @@ -0,0 +1,2 @@ +/home/xel/kendryte-toolchain-8.2/bin/riscv64-unknown-elf-gdb -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333" -ex "monitor reset halt" -ex "load" $1 + diff --git a/lib/drivers/dvp.c b/lib/drivers/dvp.c index 9233656..b916a29 100755 --- a/lib/drivers/dvp.c +++ b/lib/drivers/dvp.c @@ -20,7 +20,7 @@ #include "sysctl.h" #include -volatile dvp_t* const dvp = (volatile dvp_t*)DVP_BASE_ADDR; +volatile dvp_t *const dvp = (volatile dvp_t *)DVP_BASE_ADDR; static uint8_t g_sccb_reg_len = 8; static void mdelay(uint32_t ms) @@ -49,7 +49,7 @@ uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate) uint32_t tmp; uint32_t v_sccb_freq = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1); uint16_t v_period_clk_cnt = round(v_sccb_freq / clk_rate / 2.0); - if(v_period_clk_cnt > 255) + if (v_period_clk_cnt > 255) { return 0; } @@ -116,7 +116,7 @@ uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr) dvp_sccb_start_transfer(); - return (uint8_t) DVP_SCCB_RDATA_BYTE(dvp->sccb_cfg); + return (uint8_t)DVP_SCCB_RDATA_BYTE(dvp->sccb_cfg); } static void dvp_reset(void) @@ -145,6 +145,22 @@ void dvp_init(uint8_t reg_len) dvp_reset(); } +uint32_t dvp_set_xclk_rate(uint32_t xclk_rate) +{ + uint32_t v_apb1_clk = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1); + uint32_t v_period; + if (v_apb1_clk > xclk_rate * 2) + v_period = round(v_apb1_clk / (xclk_rate * 2.0)) - 1; + else + v_period = 0; + if (v_period > 255) + v_period = 255; + dvp->cmos_cfg &= (~DVP_CMOS_CLK_DIV_MASK); + dvp->cmos_cfg |= DVP_CMOS_CLK_DIV(v_period) | DVP_CMOS_CLK_ENABLE; + dvp_reset(); + return v_apb1_clk / ((v_period + 1) * 2); +} + void dvp_set_image_format(uint32_t format) { uint32_t tmp; @@ -278,4 +294,3 @@ void dvp_set_output_enable(dvp_output_mode_t index, int enable) dvp->dvp_cfg &= ~DVP_CFG_DISPLAY_OUTPUT_ENABLE; } } - diff --git a/lib/drivers/include/dvp.h b/lib/drivers/include/dvp.h index 6e154f6..7ed9370 100755 --- a/lib/drivers/include/dvp.h +++ b/lib/drivers/include/dvp.h @@ -17,10 +17,11 @@ #include #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -/* clang-format off */ + /* clang-format off */ /** * @brief DVP object */ @@ -94,89 +95,89 @@ typedef struct _dvp #define DVP_STS_DVP_EN_WE 0x00020000U #define DVP_STS_SCCB_EN 0x01000000U #define DVP_STS_SCCB_EN_WE 0x02000000U -/* clang-format on */ + /* clang-format on */ -typedef enum _dvp_output_mode -{ - DVP_OUTPUT_AI, - DVP_OUTPUT_DISPLAY, -} dvp_output_mode_t; + typedef enum _dvp_output_mode + { + DVP_OUTPUT_AI, + DVP_OUTPUT_DISPLAY, + } dvp_output_mode_t; -/** + /** * @brief DVP object instance */ -extern volatile dvp_t* const dvp; + extern volatile dvp_t *const dvp; -/** + /** * @brief Initialize DVP */ -void dvp_init(uint8_t reg_len); + void dvp_init(uint8_t reg_len); -/** + /** * @brief Set image format * * @param[in] format The image format */ -void dvp_set_image_format(uint32_t format); + void dvp_set_image_format(uint32_t format); -/** + /** * @brief Set image size * * @param[in] width The width of image * @param[in] height The height of image */ -void dvp_set_image_size(uint32_t width, uint32_t height); + void dvp_set_image_size(uint32_t width, uint32_t height); -/** + /** * @brief Set the address of RGB for AI * * @param[in] r_addr The R address of RGB * @param[in] g_addr The G address of RGB * @param[in] b_addr The B address of RGB */ -void dvp_set_ai_addr(uint32_t r_addr, uint32_t g_addr, uint32_t b_addr); + void dvp_set_ai_addr(uint32_t r_addr, uint32_t g_addr, uint32_t b_addr); -/** + /** * @brief Set the address of RGB for display * * @param[in] r_addr The R address of RGB * @param[in] g_addr The G address of RGB * @param[in] b_addr The B address of RGB */ -void dvp_set_display_addr(uint32_t addr); + void dvp_set_display_addr(uint32_t addr); -/** + /** * @brief The frame start transfer */ -void dvp_start_frame(void); + void dvp_start_frame(void); -/** + /** * @brief The DVP convert start */ -void dvp_start_convert(void); + void dvp_start_convert(void); -/** + /** * @brief The DVP convert finish */ -void dvp_finish_convert(void); + void dvp_finish_convert(void); -/** + /** * @brief Get the image data * * @note The image data stored in the address of RGB */ -void dvp_get_image(void); + void dvp_get_image(void); -/** + /** * @brief Use SCCB write register * * @param[in] dev_addr The device address * @param[in] reg_addr The register address * @param[in] reg_data The register data */ -void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data); + void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data); -/** + /** * @brief Use SCCB read register * * @param[in] dev_addr The device address @@ -184,28 +185,28 @@ void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data); * * @return The register value */ -uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr); + uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr); -/** + /** * @brief Enable dvp burst */ -void dvp_enable_burst(void); + void dvp_enable_burst(void); -/** + /** * @brief Disable dvp burst */ -void dvp_disable_burst(void); + void dvp_disable_burst(void); -/** + /** * @brief Enable or disable dvp interrupt * * @param[in] interrupt Dvp interrupt * @param[in] status 0:disable 1:enable * */ -void dvp_config_interrupt(uint32_t interrupt, uint8_t enable); + void dvp_config_interrupt(uint32_t interrupt, uint8_t enable); -/** + /** * @brief Get dvp interrupt status * * @param[in] interrupt Dvp interrupt @@ -215,43 +216,45 @@ void dvp_config_interrupt(uint32_t interrupt, uint8_t enable); * - 0 false * - 1 true */ -int dvp_get_interrupt(uint32_t interrupt); + int dvp_get_interrupt(uint32_t interrupt); -/** + /** * @brief Clear dvp interrupt status * * @param[in] interrupt Dvp interrupt * */ -void dvp_clear_interrupt(uint32_t interrupt); + void dvp_clear_interrupt(uint32_t interrupt); -/** + /** * @brief Enable dvp auto mode */ -void dvp_enable_auto(void); + void dvp_enable_auto(void); -/** + /** * @brief Disable dvp auto mode */ -void dvp_disable_auto(void); + void dvp_disable_auto(void); -/** + /** * @brief Dvp ouput data enable or not * * @param[in] index 0:AI, 1:display * @param[in] enable 0:disable, 1:enable * */ -void dvp_set_output_enable(dvp_output_mode_t index, int enable); + void dvp_set_output_enable(dvp_output_mode_t index, int enable); -/** + /** * @brief Set sccb clock rate * * @param[in] clk_rate Sccb clock rate * * @return The real sccb clock rate */ -uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate); + uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate); + + uint32_t dvp_set_xclk_rate(uint32_t xclk_rate); #ifdef __cplusplus } diff --git a/make.sh b/make.sh new file mode 100644 index 0000000..f23c175 --- /dev/null +++ b/make.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd ./build +cmake .. -DPROJ=$1 -DTOOLCHAIN=/home/xel/kendryte-toolchain-8.2/bin && make diff --git a/openmv_sipeed_m1_dock.bin b/openmv_sipeed_m1_dock.bin new file mode 100644 index 0000000..9936717 Binary files /dev/null and b/openmv_sipeed_m1_dock.bin differ diff --git a/src/openmv/src/micropython/ports/k210-standalone/Makefile b/src/openmv/src/micropython/ports/k210-standalone/Makefile index fd808dd..a4a8c7a 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/Makefile +++ b/src/openmv/src/micropython/ports/k210-standalone/Makefile @@ -151,6 +151,7 @@ MODULES_SRC_C= \ $(MPY_MOD_PATH)/machine/machine_timer.c\ $(MPY_MOD_PATH)/machine/machine_nt35310.c\ $(MPY_MOD_PATH)/machine/machine_ov5640.c\ + $(MPY_MOD_PATH)/machine/machine_ov2640.c\ $(MPY_MOD_PATH)/machine/machine_burner.c\ $(MPY_MOD_PATH)/machine/machine_face_detect.c\ $(MPY_MOD_PATH)/machine/machine_spiflash.c\ diff --git a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/include/nt35310.h b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/include/nt35310.h index c61f2f1..7ed1b1f 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/include/nt35310.h +++ b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/include/nt35310.h @@ -96,6 +96,7 @@ #define INTERFACE_CTL 0xF6 #define DCX_GPIONUM (2) +#define RST_GPIONUM (3) #define SPI_CHANNEL 0 #define SPI_SLAVE_SELECT 3 @@ -109,4 +110,3 @@ void tft_write_word(uint32_t *data_buf, uint32_t length, uint32_t flag); void tft_fill_data(uint32_t *data_buf, uint32_t length); #endif - diff --git a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/lcd.c b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/lcd.c index 432f988..2028446 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/lcd.c +++ b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/lcd.c @@ -45,7 +45,7 @@ void lcd_init(void) tft_write_command(PIXEL_FORMAT_SET); data = 0x55; tft_write_byte(&data, 1); - lcd_set_direction(DIR_XY_LRUD); + lcd_set_direction(DIR_YX_RLUD); /*display on*/ tft_write_command(DISPALY_ON); @@ -54,7 +54,7 @@ void lcd_init(void) void lcd_set_direction(lcd_dir_t dir) { - dir |= 0x08; + // dir |= 0x08; lcd_ctl.dir = dir; if (dir & DIR_XY_MASK) { @@ -148,21 +148,21 @@ void lcd_ram_draw_string(char *str, uint32_t *ptr, uint16_t font_color, uint16_t { switch (data >> 6) { - case 0: - *pixel = ((uint32_t)bg_color << 16) | bg_color; - break; - case 1: - *pixel = ((uint32_t)bg_color << 16) | font_color; - break; - case 2: - *pixel = ((uint32_t)font_color << 16) | bg_color; - break; - case 3: - *pixel = ((uint32_t)font_color << 16) | font_color; - break; - default: - *pixel = 0; - break; + case 0: + *pixel = ((uint32_t)bg_color << 16) | bg_color; + break; + case 1: + *pixel = ((uint32_t)bg_color << 16) | font_color; + break; + case 2: + *pixel = ((uint32_t)font_color << 16) | bg_color; + break; + case 3: + *pixel = ((uint32_t)font_color << 16) | font_color; + break; + default: + *pixel = 0; + break; } data <<= 2; pixel++; @@ -202,10 +202,8 @@ void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint tft_write_word(data_buf, ((y2 - y1 + 1) * width + 1) / 2, 0); } - void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr) { lcd_set_area(x1, y1, x1 + width - 1, y1 + height - 1); tft_write_word(ptr, width * height / 2, lcd_ctl.mode ? 2 : 0); } - diff --git a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/nt35310.c b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/nt35310.c index c5ec13a..4bbfa94 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/nt35310.c +++ b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/nt35310.c @@ -15,8 +15,9 @@ #include "nt35310.h" #include "gpiohs.h" #include "spi.h" +// #include "board_config.h" -static void init_dcx(void) +static void init_dcx(void) { gpiohs_set_drive_mode(DCX_GPIONUM, GPIO_DM_OUTPUT); gpiohs_set_pin(DCX_GPIONUM, GPIO_PV_HIGH); @@ -32,38 +33,52 @@ static void set_dcx_data(void) gpiohs_set_pin(DCX_GPIONUM, GPIO_PV_HIGH); } +static void init_rst(void) +{ + gpiohs_set_drive_mode(RST_GPIONUM, GPIO_DM_OUTPUT); + gpiohs_set_pin(RST_GPIONUM, GPIO_PV_HIGH); +} + +static void set_rst(uint8_t val) +{ + gpiohs_set_pin(RST_GPIONUM, val); +} + void tft_hard_init(void) { init_dcx(); + init_rst(); + set_rst(0); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); - spi_set_clk_rate(SPI_CHANNEL, 25000000); + spi_set_clk_rate(SPI_CHANNEL, 20000000); + set_rst(1); } void tft_write_command(uint8_t cmd) { set_dcx_control(); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); - spi_init_non_standard(SPI_CHANNEL, 8/*instrction length*/, 0/*address length*/, 0/*wait cycles*/, - SPI_AITM_AS_FRAME_FORMAT/*spi address trans mode*/); - spi_send_data_normal_dma(DMAC_CHANNEL1, SPI_CHANNEL, SPI_SLAVE_SELECT, (uint8_t *)(&cmd), 1,SPI_TRANS_CHAR); + spi_init_non_standard(SPI_CHANNEL, 8 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, + SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); + spi_send_data_normal_dma(DMAC_CHANNEL0, SPI_CHANNEL, SPI_SLAVE_SELECT, (uint8_t *)(&cmd), 1, SPI_TRANS_CHAR); } void tft_write_byte(uint8_t *data_buf, uint32_t length) { set_dcx_data(); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 8, 0); - spi_init_non_standard(SPI_CHANNEL, 0/*instrction length*/, 8/*address length*/, 0/*wait cycles*/, - SPI_AITM_AS_FRAME_FORMAT/*spi address trans mode*/); - spi_send_data_normal_dma(DMAC_CHANNEL1, SPI_CHANNEL, SPI_SLAVE_SELECT, data_buf, length, SPI_TRANS_CHAR); + spi_init_non_standard(SPI_CHANNEL, 8 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, + SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); + spi_send_data_normal_dma(DMAC_CHANNEL0, SPI_CHANNEL, SPI_SLAVE_SELECT, data_buf, length, SPI_TRANS_CHAR); } void tft_write_half(uint16_t *data_buf, uint32_t length) { set_dcx_data(); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 16, 0); - spi_init_non_standard(SPI_CHANNEL, 0/*instrction length*/, 16/*address length*/, 0/*wait cycles*/, - SPI_AITM_AS_FRAME_FORMAT/*spi address trans mode*/); - spi_send_data_normal_dma(DMAC_CHANNEL1, SPI_CHANNEL, SPI_SLAVE_SELECT,data_buf, length, SPI_TRANS_SHORT); + spi_init_non_standard(SPI_CHANNEL, 16 /*instrction length*/, 0 /*address length*/, 0 /*wait cycles*/, + SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); + spi_send_data_normal_dma(DMAC_CHANNEL0, SPI_CHANNEL, SPI_SLAVE_SELECT, data_buf, length, SPI_TRANS_SHORT); } void tft_write_word(uint32_t *data_buf, uint32_t length, uint32_t flag) @@ -71,17 +86,16 @@ void tft_write_word(uint32_t *data_buf, uint32_t length, uint32_t flag) set_dcx_data(); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 32, 0); - spi_init_non_standard(SPI_CHANNEL, 0/*instrction length*/, 32/*address length*/, 0/*wait cycles*/, - SPI_AITM_AS_FRAME_FORMAT/*spi address trans mode*/); - spi_send_data_normal_dma(DMAC_CHANNEL1, SPI_CHANNEL, SPI_SLAVE_SELECT,data_buf, length, SPI_TRANS_INT); + spi_init_non_standard(SPI_CHANNEL, 0 /*instrction length*/, 32 /*address length*/, 0 /*wait cycles*/, + SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); + spi_send_data_normal_dma(DMAC_CHANNEL0, SPI_CHANNEL, SPI_SLAVE_SELECT, data_buf, length, SPI_TRANS_INT); } void tft_fill_data(uint32_t *data_buf, uint32_t length) { set_dcx_data(); spi_init(SPI_CHANNEL, SPI_WORK_MODE_0, SPI_FF_OCTAL, 32, 0); - spi_init_non_standard(SPI_CHANNEL, 0/*instrction length*/, 32/*address length*/, 0/*wait cycles*/, - SPI_AITM_AS_FRAME_FORMAT/*spi address trans mode*/); - spi_fill_data_dma(DMAC_CHANNEL1, SPI_CHANNEL, SPI_SLAVE_SELECT,data_buf, length); + spi_init_non_standard(SPI_CHANNEL, 0 /*instrction length*/, 32 /*address length*/, 0 /*wait cycles*/, + SPI_AITM_AS_FRAME_FORMAT /*spi address trans mode*/); + spi_fill_data_dma(DMAC_CHANNEL0, SPI_CHANNEL, SPI_SLAVE_SELECT, data_buf, length); } - diff --git a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/ov2640.c b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/ov2640.c index f89e33e..cc77582 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/board-drivers/ov2640.c +++ b/src/openmv/src/micropython/ports/k210-standalone/board-drivers/ov2640.c @@ -4,202 +4,201 @@ #include "plic.h" #include "fpioa.h" -#define OV2640_ADDR 0x60 +#define OV2640_ADDR 0x60 /* QVGA Window Size */ static const uint8_t ov2640_config[][2] = { -{0xff, 0x01}, -{0x12, 0x80}, -{0xff, 0x00}, -{0x2c, 0xff}, -{0x2e, 0xdf}, -{0xff, 0x01}, -{0x3c, 0x32}, -{0x11, 0x00}, -{0x09, 0x02}, -{0x04, 0x58}, -{0x13, 0xe5}, -{0x14, 0x48}, -{0x2c, 0x0c}, -{0x33, 0x78}, -{0x3a, 0x33}, -{0x3b, 0xfb}, -{0x3e, 0x00}, -{0x43, 0x11}, -{0x16, 0x10}, -{0x39, 0x92}, -{0x35, 0xda}, -{0x22, 0x1a}, -{0x37, 0xc3}, -{0x23, 0x00}, -{0x34, 0xc0}, -{0x36, 0x1a}, -{0x06, 0x88}, -{0x07, 0xc0}, -{0x0d, 0x87}, -{0x0e, 0x41}, -{0x4c, 0x00}, -{0x48, 0x00}, -{0x5b, 0x00}, -{0x42, 0x03}, -{0x4a, 0x81}, -{0x21, 0x99}, -{0x24, 0x40}, -{0x25, 0x38}, -{0x26, 0x82}, -{0x5c, 0x00}, -{0x63, 0x00}, -{0x46, 0x22}, -{0x0c, 0x3c}, -{0x61, 0x70}, -{0x62, 0x80}, -{0x7c, 0x05}, -{0x20, 0x80}, -{0x28, 0x30}, -{0x6c, 0x00}, -{0x6d, 0x80}, -{0x6e, 0x00}, -{0x70, 0x02}, -{0x71, 0x94}, -{0x73, 0xc1}, -{0x3d, 0x34}, -{0x5a, 0x57}, -{0x12, 0x40}, -{0x17, 0x11}, -{0x18, 0x43}, -{0x19, 0x00}, -{0x1a, 0x4b}, -{0x32, 0x09}, -{0x37, 0xc0}, -{0x4f, 0xca}, -{0x50, 0xa8}, -{0x5a, 0x23}, -{0x6d, 0x00}, -{0x3d, 0x38}, -{0xff, 0x00}, -{0xe5, 0x7f}, -{0xf9, 0xc0}, -{0x41, 0x24}, -{0xe0, 0x14}, -{0x76, 0xff}, -{0x33, 0xa0}, -{0x42, 0x20}, -{0x43, 0x18}, -{0x4c, 0x00}, -{0x87, 0xd5}, -{0x88, 0x3f}, -{0xd7, 0x03}, -{0xd9, 0x10}, -{0xd3, 0x82}, -{0xc8, 0x08}, -{0xc9, 0x80}, -{0x7c, 0x00}, -{0x7d, 0x00}, -{0x7c, 0x03}, -{0x7d, 0x48}, -{0x7d, 0x48}, -{0x7c, 0x08}, -{0x7d, 0x20}, -{0x7d, 0x10}, -{0x7d, 0x0e}, -{0x90, 0x00}, -{0x91, 0x0e}, -{0x91, 0x1a}, -{0x91, 0x31}, -{0x91, 0x5a}, -{0x91, 0x69}, -{0x91, 0x75}, -{0x91, 0x7e}, -{0x91, 0x88}, -{0x91, 0x8f}, -{0x91, 0x96}, -{0x91, 0xa3}, -{0x91, 0xaf}, -{0x91, 0xc4}, -{0x91, 0xd7}, -{0x91, 0xe8}, -{0x91, 0x20}, -{0x92, 0x00}, -{0x93, 0x06}, -{0x93, 0xe3}, -{0x93, 0x05}, -{0x93, 0x05}, -{0x93, 0x00}, -{0x93, 0x04}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x93, 0x00}, -{0x96, 0x00}, -{0x97, 0x08}, -{0x97, 0x19}, -{0x97, 0x02}, -{0x97, 0x0c}, -{0x97, 0x24}, -{0x97, 0x30}, -{0x97, 0x28}, -{0x97, 0x26}, -{0x97, 0x02}, -{0x97, 0x98}, -{0x97, 0x80}, -{0x97, 0x00}, -{0x97, 0x00}, -{0xc3, 0xed}, -{0xa4, 0x00}, -{0xa8, 0x00}, -{0xc5, 0x11}, -{0xc6, 0x51}, -{0xbf, 0x80}, -{0xc7, 0x10}, -{0xb6, 0x66}, -{0xb8, 0xa5}, -{0xb7, 0x64}, -{0xb9, 0x7c}, -{0xb3, 0xaf}, -{0xb4, 0x97}, -{0xb5, 0xff}, -{0xb0, 0xc5}, -{0xb1, 0x94}, -{0xb2, 0x0f}, -{0xc4, 0x5c}, -{0xc0, 0x64}, -{0xc1, 0x4b}, -{0x8c, 0x00}, -{0x86, 0x3d}, -{0x50, 0x00}, -{0x51, 0xc8}, -{0x52, 0x96}, -{0x53, 0x00}, -{0x54, 0x00}, -{0x55, 0x00}, -{0x5a, 0xc8}, -{0x5b, 0x96}, -{0x5c, 0x00}, -{0xd3, 0x02}, -{0xc3, 0xed}, -{0x7f, 0x00}, -{0xda, 0x08}, -{0xe5, 0x1f}, -{0xe1, 0x67}, -{0xe0, 0x00}, -{0xdd, 0x7f}, -{0x05, 0x00}, -//[OV2640_OutSize_Set] width:320 height:240 -{0xff, 0x00}, -{0xe0, 0x04}, -{0x5a, 0x50}, -{0x5b, 0x3c}, -{0x5c, 0x00}, -{0xe0, 0x00}, -#if 0 //color bar + {0xff, 0x01}, + {0x12, 0x80}, + {0xff, 0x00}, + {0x2c, 0xff}, + {0x2e, 0xdf}, + {0xff, 0x01}, + {0x3c, 0x32}, + {0x11, 0x00}, + {0x09, 0x02}, + {0x04, 0x58}, + {0x13, 0xe5}, + {0x14, 0x48}, + {0x2c, 0x0c}, + {0x33, 0x78}, + {0x3a, 0x33}, + {0x3b, 0xfb}, + {0x3e, 0x00}, + {0x43, 0x11}, + {0x16, 0x10}, + {0x39, 0x92}, + {0x35, 0xda}, + {0x22, 0x1a}, + {0x37, 0xc3}, + {0x23, 0x00}, + {0x34, 0xc0}, + {0x36, 0x1a}, + {0x06, 0x88}, + {0x07, 0xc0}, + {0x0d, 0x87}, + {0x0e, 0x41}, + {0x4c, 0x00}, + {0x48, 0x00}, + {0x5b, 0x00}, + {0x42, 0x03}, + {0x4a, 0x81}, + {0x21, 0x99}, + {0x24, 0x40}, + {0x25, 0x38}, + {0x26, 0x82}, + {0x5c, 0x00}, + {0x63, 0x00}, + {0x46, 0x22}, + {0x0c, 0x3c}, + {0x61, 0x70}, + {0x62, 0x80}, + {0x7c, 0x05}, + {0x20, 0x80}, + {0x28, 0x30}, + {0x6c, 0x00}, + {0x6d, 0x80}, + {0x6e, 0x00}, + {0x70, 0x02}, + {0x71, 0x94}, + {0x73, 0xc1}, + {0x3d, 0x34}, + {0x5a, 0x57}, + {0x12, 0x40}, + {0x17, 0x11}, + {0x18, 0x43}, + {0x19, 0x00}, + {0x1a, 0x4b}, + {0x32, 0x09}, + {0x37, 0xc0}, + {0x4f, 0xca}, + {0x50, 0xa8}, + {0x5a, 0x23}, + {0x6d, 0x00}, + {0x3d, 0x38}, + {0xff, 0x00}, + {0xe5, 0x7f}, + {0xf9, 0xc0}, + {0x41, 0x24}, + {0xe0, 0x14}, + {0x76, 0xff}, + {0x33, 0xa0}, + {0x42, 0x20}, + {0x43, 0x18}, + {0x4c, 0x00}, + {0x87, 0xd5}, + {0x88, 0x3f}, + {0xd7, 0x03}, + {0xd9, 0x10}, + {0xd3, 0x82}, + {0xc8, 0x08}, + {0xc9, 0x80}, + {0x7c, 0x00}, + {0x7d, 0x00}, + {0x7c, 0x03}, + {0x7d, 0x48}, + {0x7d, 0x48}, + {0x7c, 0x08}, + {0x7d, 0x20}, + {0x7d, 0x10}, + {0x7d, 0x0e}, + {0x90, 0x00}, + {0x91, 0x0e}, + {0x91, 0x1a}, + {0x91, 0x31}, + {0x91, 0x5a}, + {0x91, 0x69}, + {0x91, 0x75}, + {0x91, 0x7e}, + {0x91, 0x88}, + {0x91, 0x8f}, + {0x91, 0x96}, + {0x91, 0xa3}, + {0x91, 0xaf}, + {0x91, 0xc4}, + {0x91, 0xd7}, + {0x91, 0xe8}, + {0x91, 0x20}, + {0x92, 0x00}, + {0x93, 0x06}, + {0x93, 0xe3}, + {0x93, 0x05}, + {0x93, 0x05}, + {0x93, 0x00}, + {0x93, 0x04}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x96, 0x00}, + {0x97, 0x08}, + {0x97, 0x19}, + {0x97, 0x02}, + {0x97, 0x0c}, + {0x97, 0x24}, + {0x97, 0x30}, + {0x97, 0x28}, + {0x97, 0x26}, + {0x97, 0x02}, + {0x97, 0x98}, + {0x97, 0x80}, + {0x97, 0x00}, + {0x97, 0x00}, + {0xc3, 0xed}, + {0xa4, 0x00}, + {0xa8, 0x00}, + {0xc5, 0x11}, + {0xc6, 0x51}, + {0xbf, 0x80}, + {0xc7, 0x10}, + {0xb6, 0x66}, + {0xb8, 0xa5}, + {0xb7, 0x64}, + {0xb9, 0x7c}, + {0xb3, 0xaf}, + {0xb4, 0x97}, + {0xb5, 0xff}, + {0xb0, 0xc5}, + {0xb1, 0x94}, + {0xb2, 0x0f}, + {0xc4, 0x5c}, + {0xc0, 0x64}, + {0xc1, 0x4b}, + {0x8c, 0x00}, + {0x86, 0x3d}, + {0x50, 0x00}, + {0x51, 0xc8}, + {0x52, 0x96}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x00}, + {0x5a, 0xc8}, + {0x5b, 0x96}, + {0x5c, 0x00}, + {0xd3, 0x02}, + {0xc3, 0xed}, + {0x7f, 0x00}, + {0xda, 0x08}, + {0xe5, 0x1f}, + {0xe1, 0x67}, + {0xe0, 0x00}, + {0xdd, 0x7f}, + {0x05, 0x00}, + //[OV2640_OutSize_Set] width:320 height:240 + {0xff, 0x00}, + {0xe0, 0x04}, + {0x5a, 0x50}, + {0x5b, 0x3c}, + {0x5c, 0x00}, + {0xe0, 0x00}, +#if 0 //color bar {0xff, 0x01}, {0x12, 0x02}, #endif - {0x00, 0x00} -}; + {0x00, 0x00}}; /** * dvp_pclk io47 @@ -211,7 +210,7 @@ static const uint8_t ov2640_config[][2] = { * dvp_scl io41 * dvp_sda io40 * */ - + static void dvp_io_init(void) { /* @@ -228,32 +227,20 @@ static void dvp_io_init(void) int ov2640_init(void) { - uint16_t index; - - dvp_init(8); - dvp_io_init(); - dvp->cmos_cfg |= DVP_CMOS_CLK_DIV(1) | DVP_CMOS_CLK_ENABLE; - //dvp_reset(); - dvp_enable_burst(); - dvp->dvp_cfg |= (DVP_CFG_AI_OUTPUT_ENABLE | DVP_CFG_DISPLAY_OUTPUT_ENABLE); - printf("Enter the ov2640_init\n"); + uint16_t v_manuf_id; + uint16_t v_device_id; + ov2640_read_id(&v_manuf_id, &v_device_id); + printf("manuf_id:0x%04x,device_id:0x%04x\n", v_manuf_id, v_device_id); + uint16_t index = 0; for (index = 0; ov2640_config[index][0]; index++) dvp_sccb_send_data(OV2640_ADDR, ov2640_config[index][0], ov2640_config[index][1]); - dvp_set_image_format(DVP_CFG_RGB_FORMAT); - dvp_set_image_size(320, 240); - return 0; } int ov2640_read_id(uint16_t *manuf_id, uint16_t *device_id) { dvp_sccb_send_data(OV2640_ADDR, 0xFF, 0x01); - *manuf_id = (dvp_sccb_receive_data(OV2640_ADDR, 0x1C) << 8) | - dvp_sccb_receive_data(OV2640_ADDR, 0x1D); - *device_id = (dvp_sccb_receive_data(OV2640_ADDR, 0x0A) << 8) | - dvp_sccb_receive_data(OV2640_ADDR, 0x0B); + *manuf_id = (dvp_sccb_receive_data(OV2640_ADDR, 0x1C) << 8) | dvp_sccb_receive_data(OV2640_ADDR, 0x1D); + *device_id = (dvp_sccb_receive_data(OV2640_ADDR, 0x0A) << 8) | dvp_sccb_receive_data(OV2640_ADDR, 0x0B); return 0; } - - - diff --git a/src/openmv/src/micropython/ports/k210-standalone/buildin-py/boot.py b/src/openmv/src/micropython/ports/k210-standalone/buildin-py/boot.py index f0e255d..e2a2ea2 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/buildin-py/boot.py +++ b/src/openmv/src/micropython/ports/k210-standalone/buildin-py/boot.py @@ -18,9 +18,14 @@ import init #lcd init st=machine.nt35310() + st.init() + +for i in range(9999): + print() + #ov init -ov=machine.ov5640() +ov=machine.ov2640() ov.init() #ov.lcdshow() diff --git a/src/openmv/src/micropython/ports/k210-standalone/main.c b/src/openmv/src/micropython/ports/k210-standalone/main.c index 093ba6b..796460f 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/main.c +++ b/src/openmv/src/micropython/ports/k210-standalone/main.c @@ -43,7 +43,6 @@ #define MPY_HEAP_SIZE (1 * 1024 * 1024) extern int mp_hal_stdin_rx_chr(void); - static char *stack_top; #if MICROPY_ENABLE_GC static char heap[MPY_HEAP_SIZE]; @@ -58,11 +57,11 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind); static void pll_init() { - + sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_IN0); - sysctl_pll_enable(SYSCTL_PLL0); - sysctl_pll_set_freq(SYSCTL_PLL0, PLL0_OUTPUT_FREQ); + sysctl_pll_enable(SYSCTL_PLL0); + sysctl_pll_set_freq(SYSCTL_PLL0, PLL0_OUTPUT_FREQ); //while (sysctl_pll_is_lock(SYSCTL_PLL0) == 0) // sysctl_pll_clear_slip(SYSCTL_PLL0); //msdelay(100); @@ -71,20 +70,20 @@ static void pll_init() //printf("PLL0 output test:(real)%ld (measure)%ld\n", PLL0_OUTPUT_FREQ, PLL0_OUTPUT_FREQ / 16); sysctl_pll_enable(SYSCTL_PLL1); - sysctl_pll_set_freq(SYSCTL_PLL1, PLL1_OUTPUT_FREQ); + sysctl_pll_set_freq(SYSCTL_PLL1, PLL1_OUTPUT_FREQ); //while (sysctl_pll_is_lock(SYSCTL_PLL1) == 0) - // sysctl_pll_clear_slip(SYSCTL_PLL1); - + // sysctl_pll_clear_slip(SYSCTL_PLL1); + //msdelay(100); - + sysctl_clock_enable(SYSCTL_CLOCK_PLL1); //printf("PLL1 output test:(real)%ld (measure)%ld\n", PLL1_OUTPUT_FREQ, PLL1_OUTPUT_FREQ / 16); sysctl_pll_enable(SYSCTL_PLL2); - sysctl_pll_set_freq(SYSCTL_PLL2, PLL2_OUTPUT_FREQ); + sysctl_pll_set_freq(SYSCTL_PLL2, PLL2_OUTPUT_FREQ); //while (sysctl_pll_is_lock(SYSCTL_PLL2) == 0) - // sysctl_pll_clear_slip(SYSCTL_PLL2); - + // sysctl_pll_clear_slip(SYSCTL_PLL2); + //msdelay(100); sysctl_clock_enable(SYSCTL_CLOCK_PLL2); //printf("PLL2 output test:(real)%ld (measure)%ld\n", PLL2_OUTPUT_FREQ, PLL2_OUTPUT_FREQ / 16); @@ -121,84 +120,95 @@ void mpy_main(void) printf("[lichee]:pll0 freq:%d\r\n",sysctl_clock_get_freq(SYSCTL_CLOCK_PLL0)); printf("[lichee]:pll1 freq:%d\r\n",sysctl_clock_get_freq(SYSCTL_CLOCK_PLL1)); */ - pll_init(); - sysctl->power_sel.power_mode_sel6 = 1; - sysctl->power_sel.power_mode_sel7 = 1; + pll_init(); + sysctl->power_sel.power_mode_sel6 = 1; + sysctl->power_sel.power_mode_sel7 = 1; - uarths_init(); + uarths_init(); uint8_t manuf_id, device_id; - while (1) { - w25qxx_init(3); - w25qxx_read_id(&manuf_id, &device_id); - if (manuf_id != 0xFF && manuf_id != 0x00 && device_id != 0xFF && device_id != 0x00) - break; - } - w25qxx_enable_quad_mode(); + while (1) + { + w25qxx_init(3); + w25qxx_read_id(&manuf_id, &device_id); + if (manuf_id != 0xFF && manuf_id != 0x00 && device_id != 0xFF && device_id != 0x00) + break; + } + w25qxx_enable_quad_mode(); printf("flash init:manuf_id:0x%02x,device_id:0x%02x\n", manuf_id, device_id); - my_spiffs_init(); - int stack_dummy; - stack_top = (char*)&stack_dummy; - #if MICROPY_ENABLE_GC - gc_init(heap, heap + sizeof(heap)); - #endif - mp_init(); - readline_init0(); - readline_process_char(27); - fb_alloc_init0(); - printf("_fb_alloc_point_to:%x\n",_fballoc); - memset(MAIN_FB(), 0, sizeof(*MAIN_FB())); - MAIN_FB()->pixels = (uint8_t *)g_framebuffer; - printf("_fb_base_point_to:%x\n",MAIN_FB()->pixels); - - pyexec_frozen_module("boot.py"); - #if MICROPY_REPL_EVENT_DRIVEN - pyexec_event_repl_init(); - char c = 0; - for (;;) { - //int cnt = read_ringbuff(&c,1); - //if(cnt==0){continue;} - c = (char)uarths_getc(); - if(c == 0xff) - { - //dvp_lcd_show(); - continue; - } - if(pyexec_event_repl_process_char(c)) { - break; - } + my_spiffs_init(); + int stack_dummy; + stack_top = (char *)&stack_dummy; +#if MICROPY_ENABLE_GC + gc_init(heap, heap + sizeof(heap)); +#endif + mp_init(); + readline_init0(); + readline_process_char(27); + fb_alloc_init0(); + printf("_fb_alloc_point_to:%x\n", _fballoc); + memset(MAIN_FB(), 0, sizeof(*MAIN_FB())); + MAIN_FB()->pixels = (uint8_t *)g_framebuffer; + printf("_fb_base_point_to:%x\n", MAIN_FB()->pixels); + + pyexec_frozen_module("boot.py"); +#if MICROPY_REPL_EVENT_DRIVEN + pyexec_event_repl_init(); + char c = 0; + for (;;) + { + //int cnt = read_ringbuff(&c,1); + //if(cnt==0){continue;} + c = (char)uarths_getc(); + if (c == 0xff) + { //dvp_lcd_show(); + continue; } - #else - pyexec_friendly_repl(); - #endif - mp_deinit(); - msleep(1); - printf("prower off\n"); - return; + if (pyexec_event_repl_process_char(c)) + { + break; + } + //dvp_lcd_show(); + } +#else + pyexec_friendly_repl(); +#endif + mp_deinit(); + msleep(1); + printf("prower off\n"); + return; } - while (1); + while (1) + ; } -void do_str(const char *src, mp_parse_input_kind_t input_kind) { +void do_str(const char *src, mp_parse_input_kind_t input_kind) +{ nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { + if (nlr_push(&nlr) == 0) + { mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); mp_call_function_0(module_fun); nlr_pop(); - } else { + } + else + { // uncaught exception mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); } } -void nlr_jump_fail(void *val) { - while (1); +void nlr_jump_fail(void *val) +{ + while (1) + ; } -void gc_collect(void) { +void gc_collect(void) +{ // WARNING: This gc_collect implementation doesn't try to get root // pointers from CPU registers, and thus may function incorrectly. void *dummy; @@ -213,7 +223,8 @@ void gc_collect(void) { // is still needed by esp-open-lwip for debugging output, so define it here. #include int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); -int DEBUG_printf(const char *fmt, ...) { +int DEBUG_printf(const char *fmt, ...) +{ va_list ap; va_start(ap, fmt); int ret = mp_vprintf(MICROPY_DEBUG_PRINTER, fmt, ap); @@ -221,5 +232,3 @@ int DEBUG_printf(const char *fmt, ...) { return ret; } #endif - - diff --git a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/include/modmachine.h b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/include/modmachine.h index ff92d3c..5fbac87 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/include/modmachine.h +++ b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/include/modmachine.h @@ -9,7 +9,8 @@ extern const mp_obj_type_t machine_pin_type; extern const mp_obj_type_t machine_pwm_type; extern const mp_obj_type_t machine_timer_type; extern const mp_obj_type_t machine_nt35310_type; -extern const mp_obj_type_t machine_ov5640_type; +extern const mp_obj_type_t machine_ov2640_type; +// extern const mp_obj_type_t machine_ov5640_type; extern const mp_obj_type_t machine_burner_type; extern const mp_obj_type_t machine_demo_face_detect_type; extern const mp_obj_type_t machine_zmodem_type; diff --git a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_nt35310.c b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_nt35310.c index 5496880..f6d4b9a 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_nt35310.c +++ b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_nt35310.c @@ -45,8 +45,9 @@ int lcd_init_flag = 0; -typedef struct _machine_nt35310_obj_t { - mp_obj_base_t base; +typedef struct _machine_nt35310_obj_t +{ + mp_obj_base_t base; unsigned short color[14]; } machine_nt35310_obj_t; @@ -55,6 +56,7 @@ const mp_obj_type_t machine_nt35310_type; static void io_mux_init(void) { +#if 0 /* Init DVP IO map and function settings */ fpioa_set_function(11, FUNC_CMOS_RST); fpioa_set_function(13, FUNC_CMOS_PWDN); @@ -69,165 +71,186 @@ static void io_mux_init(void) fpioa_set_function(8, FUNC_GPIOHS0 + DCX_GPIONUM); fpioa_set_function(6, FUNC_SPI0_SS3); fpioa_set_function(7, FUNC_SPI0_SCLK); +#else + /* Init DVP IO map and function settings */ + fpioa_set_function(42, FUNC_CMOS_RST); + fpioa_set_function(44, FUNC_CMOS_PWDN); + fpioa_set_function(46, FUNC_CMOS_XCLK); + fpioa_set_function(43, FUNC_CMOS_VSYNC); + fpioa_set_function(45, FUNC_CMOS_HREF); + fpioa_set_function(47, FUNC_CMOS_PCLK); + fpioa_set_function(41, FUNC_SCCB_SCLK); + fpioa_set_function(40, FUNC_SCCB_SDA); - sysctl_set_spi0_dvp_data(1); + /* Init SPI IO map and function settings */ + fpioa_set_function(37, FUNC_GPIOHS0 + RST_GPIONUM); + fpioa_set_function(38, FUNC_GPIOHS0 + DCX_GPIONUM); + fpioa_set_function(36, FUNC_SPI0_SS3); + fpioa_set_function(39, FUNC_SPI0_SCLK); +#endif + sysctl_set_spi0_dvp_data(1); } static void io_set_power(void) { - /* Set dvp and spi pin to 1.8V */ - sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V18); - sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V18); + /* Set dvp and spi pin to 1.8V */ + sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V18); + sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V18); } -STATIC mp_obj_t machine_init_helper(machine_nt35310_obj_t *self) { - /* LCD init */ - io_mux_init(); - io_set_power(); - plic_init(); - - printf("LCD init\n"); - lcd_init(); - //lcd_set_direction(DIR_YX_LRUD); - lcd_set_direction(DIR_YX_RLUD); - lcd_clear(BLACK); - lcd_init_flag = 1; - return mp_const_none; +STATIC mp_obj_t machine_init_helper(machine_nt35310_obj_t *self) +{ + /* LCD init */ + io_mux_init(); + io_set_power(); + plic_init(); + + printf("LCD init\n"); + lcd_init(); + lcd_set_direction(DIR_YX_LRUD); + lcd_clear(BLUE); + + lcd_draw_string(30, 100, "OpenMV Base on MaixPy @ K210", RED); + + lcd_init_flag = 1; + return mp_const_none; } -STATIC mp_obj_t machine_draw_picture(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - machine_nt35310_obj_t* self = pos_args[0]; - enum { - ARG_x, - ARG_y, - ARG_width, - ARG_height, - ARG_buf - }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_x, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_y, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_width, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_height, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_buf, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - }; +STATIC mp_obj_t machine_draw_picture(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) +{ + machine_nt35310_obj_t *self = pos_args[0]; + enum + { + ARG_x, + ARG_y, + ARG_width, + ARG_height, + ARG_buf + }; + static const mp_arg_t allowed_args[] = { + {MP_QSTR_x, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_y, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_width, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_height, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_buf, MP_ARG_OBJ, {.u_obj = mp_const_none}}, + }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args-1, pos_args+1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); uint16_t x = args[ARG_x].u_int; uint16_t y = args[ARG_y].u_int; uint16_t width = args[ARG_width].u_int; uint16_t height = args[ARG_height].u_int; - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_buf].u_obj, &bufinfo, MP_BUFFER_READ); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[ARG_buf].u_obj, &bufinfo, MP_BUFFER_READ); uint32_t *ptr = (uint32_t *)bufinfo.buf; - lcd_draw_picture( x, y, width, height, ptr); - return mp_const_none; + lcd_draw_picture(x, y, width, height, ptr); + return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_draw_picture_obj, 1,machine_draw_picture); - +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_draw_picture_obj, 1, machine_draw_picture); -STATIC mp_obj_t machine_draw_picture_default(machine_nt35310_obj_t *self_in,mp_obj_t buf) { - machine_nt35310_obj_t* self = self_in; +STATIC mp_obj_t machine_draw_picture_default(machine_nt35310_obj_t *self_in, mp_obj_t buf) +{ + machine_nt35310_obj_t *self = self_in; - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); uint32_t *ptr = (uint32_t *)bufinfo.buf; - lcd_draw_picture( 0, 0, 320, 240 , ptr); - return mp_const_none; + lcd_draw_picture(0, 0, 320, 240, ptr); + return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_draw_picture_default_obj,machine_draw_picture_default); - +STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_draw_picture_default_obj, machine_draw_picture_default); - -STATIC mp_obj_t machine_draw_string(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - machine_nt35310_obj_t* self = pos_args[0]; - enum { +STATIC mp_obj_t machine_draw_string(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) +{ + machine_nt35310_obj_t *self = pos_args[0]; + enum + { ARG_x, ARG_y, ARG_str, ARG_color }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_x, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_y, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_str, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_color, MP_ARG_INT, {.u_int = 0} }, + {MP_QSTR_x, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_y, MP_ARG_INT, {.u_int = 0}}, + {MP_QSTR_str, MP_ARG_OBJ, {.u_obj = mp_const_none}}, + {MP_QSTR_color, MP_ARG_INT, {.u_int = 0}}, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args-1, pos_args+1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + uint16_t x = args[ARG_x].u_int; uint16_t y = args[ARG_y].u_int; - if(args[ARG_str].u_obj == mp_const_none) + if (args[ARG_str].u_obj == mp_const_none) { printf("[lichee error]:please enter a string"); return mp_const_none; } - mp_buffer_info_t bufinfo; - mp_obj_str_get_buffer(args[ARG_str].u_obj, &bufinfo, MP_BUFFER_READ); - char *ptr =bufinfo.buf; + mp_buffer_info_t bufinfo; + mp_obj_str_get_buffer(args[ARG_str].u_obj, &bufinfo, MP_BUFFER_READ); + char *ptr = bufinfo.buf; uint16_t color = args[ARG_color].u_int; - if(color > 13) + if (color > 13) { printf("[lichee error]:please enter a right color\n"); return mp_const_none; } - lcd_draw_string( x, y,ptr,self->color[color]); - return mp_const_none; + lcd_draw_string(x, y, ptr, self->color[color]); + return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_draw_string_obj, 1,machine_draw_string); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_draw_string_obj, 1, machine_draw_string); -STATIC mp_obj_t machine_clear(mp_obj_t self_in,mp_obj_t color) { - machine_nt35310_obj_t* self = self_in; +STATIC mp_obj_t machine_clear(mp_obj_t self_in, mp_obj_t color) +{ + machine_nt35310_obj_t *self = self_in; int color_num = 0; - if (MP_OBJ_IS_SMALL_INT(color)) - color_num = MP_OBJ_SMALL_INT_VALUE(color); + if (MP_OBJ_IS_SMALL_INT(color)) + color_num = MP_OBJ_SMALL_INT_VALUE(color); else { printf("[lichee error]:type error\n"); return mp_const_none; } - if(color_num > 13) + if (color_num > 13) { printf("[lichee error]:please enter a right color\n"); return mp_const_none; } lcd_clear(self->color[color_num]); - return mp_const_none; + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_clear_obj, machine_clear); - -STATIC mp_obj_t machine_init(mp_obj_t self_in) { - machine_nt35310_obj_t* self = self_in; - return machine_init_helper(self); +STATIC mp_obj_t machine_init(mp_obj_t self_in) +{ + machine_nt35310_obj_t *self = self_in; + return machine_init_helper(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_init_obj, machine_init); -STATIC mp_obj_t machine_make_new() { - - machine_nt35310_obj_t *self = m_new_obj(machine_nt35310_obj_t); - self->base.type = &machine_nt35310_type; +STATIC mp_obj_t machine_make_new() +{ + + machine_nt35310_obj_t *self = m_new_obj(machine_nt35310_obj_t); + self->base.type = &machine_nt35310_type; - return self; + return self; } STATIC const mp_rom_map_elem_t pyb_nt35310_locals_dict_table[] = { - // instance methods - { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_init_obj) }, - { MP_ROM_QSTR(MP_QSTR_draw_picture), MP_ROM_PTR(&machine_draw_picture_obj) }, - { MP_ROM_QSTR(MP_QSTR_draw_picture_default), MP_ROM_PTR(&machine_draw_picture_default_obj) }, - { MP_ROM_QSTR(MP_QSTR_draw_string), MP_ROM_PTR(&machine_draw_string_obj) }, - { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&machine_clear_obj) }, + // instance methods + {MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_init_obj)}, + {MP_ROM_QSTR(MP_QSTR_draw_picture), MP_ROM_PTR(&machine_draw_picture_obj)}, + {MP_ROM_QSTR(MP_QSTR_draw_picture_default), MP_ROM_PTR(&machine_draw_picture_default_obj)}, + {MP_ROM_QSTR(MP_QSTR_draw_string), MP_ROM_PTR(&machine_draw_string_obj)}, + {MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&machine_clear_obj)}, }; STATIC MP_DEFINE_CONST_DICT(pyb_nt35310_ocals_dict, pyb_nt35310_locals_dict_table); const mp_obj_type_t machine_nt35310_type = { - { &mp_type_type }, - .name = MP_QSTR_nt35310, - .make_new = machine_make_new, - .locals_dict = (mp_obj_dict_t*)&pyb_nt35310_ocals_dict, + {&mp_type_type}, + .name = MP_QSTR_nt35310, + .make_new = machine_make_new, + .locals_dict = (mp_obj_dict_t *)&pyb_nt35310_ocals_dict, }; - - diff --git a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov2640.c b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov2640.c new file mode 100644 index 0000000..66ea306 --- /dev/null +++ b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov2640.c @@ -0,0 +1,325 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * Development of the code in this file was sponsored by Microbric Pty Ltd + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2015 Damien P. George + * Copyright (c) 2016 Paul Sokolovsky + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include +#include "timer.h" +#include "py/obj.h" +#include "py/runtime.h" +#include "py/objtype.h" +#include "mphalport.h" +#include "plic.h" +#include "sysctl.h" +#include "ov2640.h" +#include "dvp.h" +#include "fpioa.h" +#include "lcd.h" +#include "sysctl.h" +#include "nt35310.h" +#include "systick.h" + +#define TIMER_INTR_SEL TIMER_INTR_LEVEL +#define TIMER_DIVIDER 8 + +// TIMER_BASE_CLK is normally 80MHz. TIMER_DIVIDER ought to divide this exactly +#define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) + +#define TIMER_FLAGS 0 +struct dvp_buf +{ + uint32_t *addr[2]; + uint8_t buf_used[2]; + uint8_t buf_sel; +}; +typedef struct _machine_ov2640_obj_t +{ + mp_obj_base_t base; + uint32_t active; + uint16_t device_id; + uint16_t manuf_id; + struct dvp_buf buf; + void *ptr; + //mp_uint_t repeat;//timer mode +} machine_ov2640_obj_t; + +const mp_obj_type_t machine_ov2640_type; + +#define K210_DEBUG 0 +#if K210_DEBUG == 1 +#define debug_print(x, arg...) printf("[lichee_debug]" x, ##arg) +#else +#define debug_print(x, arg...) +#endif +void _ndelay(uint32_t ms) +{ + uint32_t i; + + while (ms && ms--) + { + for (i = 0; i < 25; i++) + __asm__ __volatile__("nop"); + } +} +#if 0 +static int dvp_irq(void *ctx) +{ + + machine_ov2640_obj_t* self = ctx; + + if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) { + debug_print("Enter finish dvp_irq\n"); + dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); + self->buf.buf_used[self->buf.buf_sel] = 1; + self->buf.buf_sel ^= 0x01; + dvp_set_display_addr((uint32_t)self->buf.addr[self->buf.buf_sel]); + } else { + debug_print("Enter start dvp_irq\n"); + dvp_clear_interrupt(DVP_STS_FRAME_START); + if (self->buf.buf_used[self->buf.buf_sel] == 0) + { + dvp_start_convert(); + } + } + debug_print("self->buf.buf_used[0] = %d\n",self->buf.buf_used[0]); + debug_print("self->buf.buf_used[1] = %d\n",self->buf.buf_used[1]); + debug_print("self->buf.buf_sel = %d\n",self->buf.buf_sel); + return 0; +} +#endif +STATIC void machine_ov2640_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) +{ + machine_ov2640_obj_t *self = self_in; + + mp_printf(print, "ov2640(%p) ", self); + mp_printf(print, "ov2640 active = %d, ", self->active); + mp_printf(print, "manuf_id=%d, ", self->manuf_id); + mp_printf(print, "device_id=%d", self->device_id); +} + +STATIC mp_obj_t machine_ov2640_make_new() +{ + + machine_ov2640_obj_t *self = m_new_obj(machine_ov2640_obj_t); + self->base.type = &machine_ov2640_type; + + return self; +} + +STATIC void machine_ov2640_disable(machine_ov2640_obj_t *self) +{ + sysctl_clock_disable(SYSCTL_CLOCK_DVP); + plic_irq_disable(IRQN_DVP_INTERRUPT); + plic_irq_deregister(IRQN_DVP_INTERRUPT); + dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); + free(self->ptr); + self->active = 0; +} + +#if 0 +static void dvp_io_init(void) +{ + /* Init DVP IO map and function settings */ + fpioa_set_function(11, FUNC_CMOS_RST);//15 RESET# + fpioa_set_function(13, FUNC_CMOS_PWDN);//17 PWDN + fpioa_set_function(14, FUNC_CMOS_XCLK);//20 XCLK + fpioa_set_function(12, FUNC_CMOS_VSYNC);//18 VSYNC + fpioa_set_function(17, FUNC_CMOS_HREF);//19 HREF + fpioa_set_function(15, FUNC_CMOS_PCLK);//21 PCLK +// fpioa_set_function(24, FUNC_CMOS_D0); +// fpioa_set_function(25, FUNC_CMOS_D1); +// fpioa_set_function(26, FUNC_CMOS_D2); +// fpioa_set_function(27, FUNC_CMOS_D3); +// fpioa_set_function(28, FUNC_CMOS_D4); +// fpioa_set_function(29, FUNC_CMOS_D5); +// fpioa_set_function(33, FUNC_CMOS_D6); +// fpioa_set_function(35, FUNC_CMOS_D7); + fpioa_set_function(10, FUNC_SCCB_SCLK);//22 SIO_C + fpioa_set_function(9, FUNC_SCCB_SDA);//23 SIO_D + +} +#endif + +uint32_t g_lcd_gram0[38400] __attribute__((aligned(64))); +uint32_t g_lcd_gram1[38400] __attribute__((aligned(64))); + +volatile uint8_t g_dvp_finish_flag; +volatile uint8_t g_ram_mux; + +extern int lcd_init_flag; +typedef void (*on_irq_dvp_callbck)(); + +static on_irq_dvp_callbck on_irq_dvp_callbck_func = NULL; + +static void dvp_lcd_show() +{ + timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 0); + while (g_dvp_finish_flag == 0) + ; + g_dvp_finish_flag = 0; + /* display pic*/ + g_ram_mux ^= 0x01; + lcd_draw_picture(0, 0, 320, 240, g_ram_mux ? g_lcd_gram0 : g_lcd_gram1); +} + +static void dvp_show_start() +{ + timer_init(TIMER_DEVICE_0); + timer_set_interval(TIMER_DEVICE_0, TIMER_CHANNEL_0, 100); + timer_set_irq(TIMER_DEVICE_0, TIMER_CHANNEL_0, dvp_lcd_show, 1); //1 is lowest priority + timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 1); +} + +static int on_irq_dvp(void *ctx) +{ + if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) + { + /* switch gram */ + + dvp_set_display_addr(g_ram_mux ? (uint32_t)g_lcd_gram0 : (uint32_t)g_lcd_gram1); + + dvp_clear_interrupt(DVP_STS_FRAME_FINISH); + g_dvp_finish_flag = 1; + + if (on_irq_dvp_callbck_func && lcd_init_flag) + on_irq_dvp_callbck_func(); + } + else + { + dvp_start_convert(); + dvp_clear_interrupt(DVP_STS_FRAME_START); + } + + return 0; +} + +static void dvp_lcd_show_register() +{ + on_irq_dvp_callbck_func = dvp_show_start; +} + +STATIC mp_obj_t machine_ov2640_init_helper(machine_ov2640_obj_t *self) +{ + /* DVP init */ + printf("DVP init\n"); + + dvp_init(8); + dvp_set_xclk_rate(24000000); + dvp_enable_burst(); + dvp_set_output_enable(0, 1); + dvp_set_output_enable(1, 1); + dvp_set_image_format(DVP_CFG_RGB_FORMAT); + dvp_set_image_size(320, 240); + + ov2640_init(); + + //dvp_set_ai_addr((uint32_t)0x40600000, (uint32_t)0x40612C00, (uint32_t)0x40625800); + dvp_set_display_addr((uint32_t)g_lcd_gram0); + dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); + dvp_disable_auto(); + + /* DVP interrupt config */ + printf("DVP interrupt config\n"); + plic_set_priority(IRQN_DVP_INTERRUPT, 2); + plic_irq_register(IRQN_DVP_INTERRUPT, on_irq_dvp, NULL); + plic_irq_enable(IRQN_DVP_INTERRUPT); + + /* enable global interrupt */ + sysctl_enable_irq(); + + /* system start */ + printf("system start\n"); + g_ram_mux = 0; + g_dvp_finish_flag = 0; + dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); + dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 1); + + self->active = 1; + return mp_const_none; +} + +STATIC mp_obj_t machine_ov2640_deinit(mp_obj_t self_in) +{ + machine_ov2640_disable(self_in); + + return mp_const_none; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov2640_deinit_obj, machine_ov2640_deinit); + +STATIC mp_obj_t machine_ov2640_get_image(mp_obj_t self_in, mp_obj_t buf) +{ + machine_ov2640_obj_t *self = self_in; + // uint32_t length = 0; + // uint8_t* buf_image = 0; + //mp_obj_list_get(buf,&length,&item); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); + while (self->buf.buf_used[self->buf.buf_sel] == 0) + _ndelay(50); + memcpy(bufinfo.buf, self->buf.addr[self->buf.buf_sel], bufinfo.len); + self->buf.buf_used[self->buf.buf_sel] = 0; + //printf("[lichee]:get image!\n"); + return mp_const_none; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_ov2640_get_images_obj, machine_ov2640_get_image); + +STATIC mp_obj_t machine_ov2640_init(mp_obj_t self_in) +{ + machine_ov2640_obj_t *self = self_in; + return machine_ov2640_init_helper(self); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov2640_init_obj, machine_ov2640_init); + +STATIC mp_obj_t machine_ov2640_lcdshow(mp_obj_t self_in) +{ + dvp_lcd_show_register(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov2640_lcdshow_obj, machine_ov2640_lcdshow); + +STATIC const mp_rom_map_elem_t machine_ov2640_locals_dict_table[] = { + {MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_ov2640_deinit_obj)}, + {MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_ov2640_deinit_obj)}, + {MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_ov2640_init_obj)}, + {MP_ROM_QSTR(MP_QSTR_lcdshow), MP_ROM_PTR(&machine_ov2640_lcdshow_obj)}, + {MP_ROM_QSTR(MP_QSTR_get_image), MP_ROM_PTR(&machine_ov2640_get_images_obj)}, +}; + +STATIC MP_DEFINE_CONST_DICT(machine_ov2640_locals_dict, machine_ov2640_locals_dict_table); + +const mp_obj_type_t machine_ov2640_type = { + {&mp_type_type}, + .name = MP_QSTR_ov2640, + .print = machine_ov2640_print, + .make_new = machine_ov2640_make_new, + .locals_dict = (mp_obj_t)&machine_ov2640_locals_dict, +}; diff --git a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov5640.c b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov5640.c index be5b973..e37db80 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov5640.c +++ b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/machine_ov5640.c @@ -1,316 +1,313 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * Development of the code in this file was sponsored by Microbric Pty Ltd - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2015 Damien P. George - * Copyright (c) 2016 Paul Sokolovsky - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include -#include -#include "timer.h" -#include "py/obj.h" -#include "py/runtime.h" -#include "py/objtype.h" -#include "mphalport.h" -#include "plic.h" -#include "sysctl.h" -#include "ov5640.h" -#include "dvp.h" -#include "fpioa.h" -#include "lcd.h" -#include "sysctl.h" -#include "nt35310.h" -#include "systick.h" - -#define TIMER_INTR_SEL TIMER_INTR_LEVEL -#define TIMER_DIVIDER 8 - -// TIMER_BASE_CLK is normally 80MHz. TIMER_DIVIDER ought to divide this exactly -#define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) - -#define TIMER_FLAGS 0 -struct dvp_buf -{ - uint32_t* addr[2]; - uint8_t buf_used[2]; - uint8_t buf_sel; -}; -typedef struct _machine_ov5640_obj_t { - mp_obj_base_t base; - uint32_t active; - uint16_t device_id; - uint16_t manuf_id; - struct dvp_buf buf; - void* ptr; - //mp_uint_t repeat;//timer mode -} machine_ov5640_obj_t; - -const mp_obj_type_t machine_ov5640_type; - -#define K210_DEBUG 0 -#if K210_DEBUG==1 -#define debug_print(x,arg...) printf("[lichee_debug]"x,##arg) -#else -#define debug_print(x,arg...) -#endif -void _ndelay(uint32_t ms) -{ - uint32_t i; - - while (ms && ms--) - { - for (i = 0; i < 25; i++) - __asm__ __volatile__("nop"); - } -} -#if 0 -static int dvp_irq(void *ctx) -{ - - machine_ov5640_obj_t* self = ctx; - - if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) { - debug_print("Enter finish dvp_irq\n"); - dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); - self->buf.buf_used[self->buf.buf_sel] = 1; - self->buf.buf_sel ^= 0x01; - dvp_set_display_addr((uint32_t)self->buf.addr[self->buf.buf_sel]); - } else { - debug_print("Enter start dvp_irq\n"); - dvp_clear_interrupt(DVP_STS_FRAME_START); - if (self->buf.buf_used[self->buf.buf_sel] == 0) - { - dvp_start_convert(); - } - } - debug_print("self->buf.buf_used[0] = %d\n",self->buf.buf_used[0]); - debug_print("self->buf.buf_used[1] = %d\n",self->buf.buf_used[1]); - debug_print("self->buf.buf_sel = %d\n",self->buf.buf_sel); - return 0; -} -#endif -STATIC void machine_ov5640_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - machine_ov5640_obj_t *self = self_in; - - mp_printf(print, "ov5640(%p) ", self); - mp_printf(print, "ov5640 active = %d, ", self->active); - mp_printf(print, "manuf_id=%d, ",self->manuf_id); - mp_printf(print, "device_id=%d", self->device_id); -} - -STATIC mp_obj_t machine_ov5640_make_new() { - - machine_ov5640_obj_t *self = m_new_obj(machine_ov5640_obj_t); - self->base.type = &machine_ov5640_type; - - return self; -} - -STATIC void machine_ov5640_disable(machine_ov5640_obj_t *self) { - sysctl_clock_disable(SYSCTL_CLOCK_DVP); - plic_irq_disable(IRQN_DVP_INTERRUPT); - plic_irq_deregister(IRQN_DVP_INTERRUPT); - dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); - free(self->ptr); - self->active = 0; -} - -#if 0 -static void dvp_io_init(void) -{ - /* Init DVP IO map and function settings */ - fpioa_set_function(11, FUNC_CMOS_RST);//15 RESET# - fpioa_set_function(13, FUNC_CMOS_PWDN);//17 PWDN - fpioa_set_function(14, FUNC_CMOS_XCLK);//20 XCLK - fpioa_set_function(12, FUNC_CMOS_VSYNC);//18 VSYNC - fpioa_set_function(17, FUNC_CMOS_HREF);//19 HREF - fpioa_set_function(15, FUNC_CMOS_PCLK);//21 PCLK -// fpioa_set_function(24, FUNC_CMOS_D0); -// fpioa_set_function(25, FUNC_CMOS_D1); -// fpioa_set_function(26, FUNC_CMOS_D2); -// fpioa_set_function(27, FUNC_CMOS_D3); -// fpioa_set_function(28, FUNC_CMOS_D4); -// fpioa_set_function(29, FUNC_CMOS_D5); -// fpioa_set_function(33, FUNC_CMOS_D6); -// fpioa_set_function(35, FUNC_CMOS_D7); - fpioa_set_function(10, FUNC_SCCB_SCLK);//22 SIO_C - fpioa_set_function(9, FUNC_SCCB_SDA);//23 SIO_D - -} -#endif - -uint32_t g_lcd_gram0[38400] __attribute__((aligned(64))); -uint32_t g_lcd_gram1[38400] __attribute__((aligned(64))); - -volatile uint8_t g_dvp_finish_flag; -volatile uint8_t g_ram_mux; - -extern int lcd_init_flag; -typedef void (*on_irq_dvp_callbck)(); - -static on_irq_dvp_callbck on_irq_dvp_callbck_func = NULL; - -static void dvp_lcd_show() -{ - timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 0); - while (g_dvp_finish_flag == 0) - ; - g_dvp_finish_flag = 0; - /* display pic*/ - g_ram_mux ^= 0x01; - lcd_draw_picture(0, 0, 320, 240, g_ram_mux ? g_lcd_gram0 : g_lcd_gram1); -} - -static void dvp_show_start() -{ - timer_init(TIMER_DEVICE_0); - timer_set_interval(TIMER_DEVICE_0, TIMER_CHANNEL_0, 100); - timer_set_irq(TIMER_DEVICE_0, TIMER_CHANNEL_0, dvp_lcd_show, 1);//1 is lowest priority - timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 1); -} - -static int on_irq_dvp(void* ctx) -{ - if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) - { - /* switch gram */ - - dvp_set_display_addr(g_ram_mux ? (uint32_t)g_lcd_gram0 : (uint32_t)g_lcd_gram1); - - dvp_clear_interrupt(DVP_STS_FRAME_FINISH); - g_dvp_finish_flag = 1; - - if(on_irq_dvp_callbck_func && lcd_init_flag) - on_irq_dvp_callbck_func(); - } - else - { - dvp_start_convert(); - dvp_clear_interrupt(DVP_STS_FRAME_START); - } - - return 0; -} - -static void dvp_lcd_show_register() -{ - on_irq_dvp_callbck_func = dvp_show_start; -} - -STATIC mp_obj_t machine_ov5640_init_helper(machine_ov5640_obj_t *self) { - /* DVP init */ - printf("DVP init\n"); - - dvp_init(16); - dvp_enable_burst(); - dvp_set_output_enable(0, 1); - dvp_set_output_enable(1, 1); - dvp_set_image_format(DVP_CFG_RGB_FORMAT); - dvp_set_image_size(320, 240); - ov5640_init(); - - //dvp_set_ai_addr((uint32_t)0x40600000, (uint32_t)0x40612C00, (uint32_t)0x40625800); - dvp_set_display_addr((uint32_t)g_lcd_gram0); - dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); - dvp_disable_auto(); - - /* DVP interrupt config */ - printf("DVP interrupt config\n"); - plic_set_priority(IRQN_DVP_INTERRUPT, 2); - plic_irq_register(IRQN_DVP_INTERRUPT, on_irq_dvp, NULL); - plic_irq_enable(IRQN_DVP_INTERRUPT); - - /* enable global interrupt */ - sysctl_enable_irq(); - - /* system start */ - printf("system start\n"); - g_ram_mux = 0; - g_dvp_finish_flag = 0; - dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); - dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 1); - - self->active = 1; - return mp_const_none; -} - - -STATIC mp_obj_t machine_ov5640_deinit(mp_obj_t self_in) { - machine_ov5640_disable(self_in); - - return mp_const_none; -} - -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_deinit_obj, machine_ov5640_deinit); - -STATIC mp_obj_t machine_ov5640_get_image(mp_obj_t self_in,mp_obj_t buf) { - machine_ov5640_obj_t* self = self_in; -// uint32_t length = 0; -// uint8_t* buf_image = 0; - //mp_obj_list_get(buf,&length,&item); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); - while(self->buf.buf_used[self->buf.buf_sel] == 0 )_ndelay(50); - memcpy(bufinfo.buf, self->buf.addr[self->buf.buf_sel], bufinfo.len); - self->buf.buf_used[self->buf.buf_sel] = 0; - //printf("[lichee]:get image!\n"); - return mp_const_none; -} - -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_ov5640_get_images_obj, machine_ov5640_get_image); - - -STATIC mp_obj_t machine_ov5640_init(mp_obj_t self_in) { - machine_ov5640_obj_t* self = self_in; - return machine_ov5640_init_helper(self); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_init_obj, machine_ov5640_init); - -STATIC mp_obj_t machine_ov5640_lcdshow(mp_obj_t self_in) { - dvp_lcd_show_register(); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_lcdshow_obj, machine_ov5640_lcdshow); - - -STATIC const mp_rom_map_elem_t machine_ov5640_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_ov5640_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_ov5640_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_ov5640_init_obj) }, - { MP_ROM_QSTR(MP_QSTR_lcdshow), MP_ROM_PTR(&machine_ov5640_lcdshow_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_image), MP_ROM_PTR(&machine_ov5640_get_images_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(machine_ov5640_locals_dict, machine_ov5640_locals_dict_table); - -const mp_obj_type_t machine_ov5640_type = { - { &mp_type_type }, - .name = MP_QSTR_ov5640, - .print = machine_ov5640_print, - .make_new = machine_ov5640_make_new, - .locals_dict = (mp_obj_t)&machine_ov5640_locals_dict, -}; +// /* +// * This file is part of the MicroPython project, http://micropython.org/ +// * +// * Development of the code in this file was sponsored by Microbric Pty Ltd +// * +// * The MIT License (MIT) +// * +// * Copyright (c) 2013-2015 Damien P. George +// * Copyright (c) 2016 Paul Sokolovsky +// * +// * Permission is hereby granted, free of charge, to any person obtaining a copy +// * of this software and associated documentation files (the "Software"), to deal +// * in the Software without restriction, including without limitation the rights +// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// * copies of the Software, and to permit persons to whom the Software is +// * furnished to do so, subject to the following conditions: +// * +// * The above copyright notice and this permission notice shall be included in +// * all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// * THE SOFTWARE. +// */ + +// #include +// #include +// #include +// #include +// #include "timer.h" +// #include "py/obj.h" +// #include "py/runtime.h" +// #include "py/objtype.h" +// #include "mphalport.h" +// #include "plic.h" +// #include "sysctl.h" +// #include "ov5640.h" +// #include "dvp.h" +// #include "fpioa.h" +// #include "lcd.h" +// #include "sysctl.h" +// #include "nt35310.h" +// #include "systick.h" + +// #define TIMER_INTR_SEL TIMER_INTR_LEVEL +// #define TIMER_DIVIDER 8 + +// // TIMER_BASE_CLK is normally 80MHz. TIMER_DIVIDER ought to divide this exactly +// #define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) + +// #define TIMER_FLAGS 0 +// struct dvp_buf +// { +// uint32_t* addr[2]; +// uint8_t buf_used[2]; +// uint8_t buf_sel; +// }; +// typedef struct _machine_ov5640_obj_t { +// mp_obj_base_t base; +// uint32_t active; +// uint16_t device_id; +// uint16_t manuf_id; +// struct dvp_buf buf; +// void* ptr; +// //mp_uint_t repeat;//timer mode +// } machine_ov5640_obj_t; + +// const mp_obj_type_t machine_ov5640_type; + +// #define K210_DEBUG 0 +// #if K210_DEBUG==1 +// #define debug_print(x,arg...) printf("[lichee_debug]"x,##arg) +// #else +// #define debug_print(x,arg...) +// #endif +// void _ndelay(uint32_t ms) +// { +// uint32_t i; + +// while (ms && ms--) +// { +// for (i = 0; i < 25; i++) +// __asm__ __volatile__("nop"); +// } +// } +// #if 0 +// static int dvp_irq(void *ctx) +// { + +// machine_ov5640_obj_t* self = ctx; + +// if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) { +// debug_print("Enter finish dvp_irq\n"); +// dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); +// self->buf.buf_used[self->buf.buf_sel] = 1; +// self->buf.buf_sel ^= 0x01; +// dvp_set_display_addr((uint32_t)self->buf.addr[self->buf.buf_sel]); +// } else { +// debug_print("Enter start dvp_irq\n"); +// dvp_clear_interrupt(DVP_STS_FRAME_START); +// if (self->buf.buf_used[self->buf.buf_sel] == 0) +// { +// dvp_start_convert(); +// } +// } +// debug_print("self->buf.buf_used[0] = %d\n",self->buf.buf_used[0]); +// debug_print("self->buf.buf_used[1] = %d\n",self->buf.buf_used[1]); +// debug_print("self->buf.buf_sel = %d\n",self->buf.buf_sel); +// return 0; +// } +// #endif +// STATIC void machine_ov5640_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +// machine_ov5640_obj_t *self = self_in; + +// mp_printf(print, "ov5640(%p) ", self); +// mp_printf(print, "ov5640 active = %d, ", self->active); +// mp_printf(print, "manuf_id=%d, ",self->manuf_id); +// mp_printf(print, "device_id=%d", self->device_id); +// } + +// STATIC mp_obj_t machine_ov5640_make_new() { + +// machine_ov5640_obj_t *self = m_new_obj(machine_ov5640_obj_t); +// self->base.type = &machine_ov5640_type; + +// return self; +// } + +// STATIC void machine_ov5640_disable(machine_ov5640_obj_t *self) { +// sysctl_clock_disable(SYSCTL_CLOCK_DVP); +// plic_irq_disable(IRQN_DVP_INTERRUPT); +// plic_irq_deregister(IRQN_DVP_INTERRUPT); +// dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); +// free(self->ptr); +// self->active = 0; +// } + +// #if 0 +// static void dvp_io_init(void) +// { +// /* Init DVP IO map and function settings */ +// fpioa_set_function(11, FUNC_CMOS_RST);//15 RESET# +// fpioa_set_function(13, FUNC_CMOS_PWDN);//17 PWDN +// fpioa_set_function(14, FUNC_CMOS_XCLK);//20 XCLK +// fpioa_set_function(12, FUNC_CMOS_VSYNC);//18 VSYNC +// fpioa_set_function(17, FUNC_CMOS_HREF);//19 HREF +// fpioa_set_function(15, FUNC_CMOS_PCLK);//21 PCLK +// // fpioa_set_function(24, FUNC_CMOS_D0); +// // fpioa_set_function(25, FUNC_CMOS_D1); +// // fpioa_set_function(26, FUNC_CMOS_D2); +// // fpioa_set_function(27, FUNC_CMOS_D3); +// // fpioa_set_function(28, FUNC_CMOS_D4); +// // fpioa_set_function(29, FUNC_CMOS_D5); +// // fpioa_set_function(33, FUNC_CMOS_D6); +// // fpioa_set_function(35, FUNC_CMOS_D7); +// fpioa_set_function(10, FUNC_SCCB_SCLK);//22 SIO_C +// fpioa_set_function(9, FUNC_SCCB_SDA);//23 SIO_D + +// } +// #endif + +// uint32_t g_lcd_gram0[38400] __attribute__((aligned(64))); +// uint32_t g_lcd_gram1[38400] __attribute__((aligned(64))); + +// volatile uint8_t g_dvp_finish_flag; +// volatile uint8_t g_ram_mux; + +// extern int lcd_init_flag; +// typedef void (*on_irq_dvp_callbck)(); + +// static on_irq_dvp_callbck on_irq_dvp_callbck_func = NULL; + +// static void dvp_lcd_show() +// { +// timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 0); +// while (g_dvp_finish_flag == 0) +// ; +// g_dvp_finish_flag = 0; +// /* display pic*/ +// g_ram_mux ^= 0x01; +// lcd_draw_picture(0, 0, 320, 240, g_ram_mux ? g_lcd_gram0 : g_lcd_gram1); +// } + +// static void dvp_show_start() +// { +// timer_init(TIMER_DEVICE_0); +// timer_set_interval(TIMER_DEVICE_0, TIMER_CHANNEL_0, 100); +// timer_set_irq(TIMER_DEVICE_0, TIMER_CHANNEL_0, dvp_lcd_show, 1);//1 is lowest priority +// timer_set_enable(TIMER_DEVICE_0, TIMER_CHANNEL_0, 1); +// } + +// static int on_irq_dvp(void* ctx) +// { +// if (dvp_get_interrupt(DVP_STS_FRAME_FINISH)) +// { +// /* switch gram */ + +// dvp_set_display_addr(g_ram_mux ? (uint32_t)g_lcd_gram0 : (uint32_t)g_lcd_gram1); + +// dvp_clear_interrupt(DVP_STS_FRAME_FINISH); +// g_dvp_finish_flag = 1; + +// if(on_irq_dvp_callbck_func && lcd_init_flag) +// on_irq_dvp_callbck_func(); +// } +// else +// { +// dvp_start_convert(); +// dvp_clear_interrupt(DVP_STS_FRAME_START); +// } + +// return 0; +// } + +// static void dvp_lcd_show_register() +// { +// on_irq_dvp_callbck_func = dvp_show_start; +// } + +// STATIC mp_obj_t machine_ov5640_init_helper(machine_ov5640_obj_t *self) { +// /* DVP init */ +// printf("DVP init\n"); + +// dvp_init(16); +// dvp_enable_burst(); +// dvp_set_output_enable(0, 1); +// dvp_set_output_enable(1, 1); +// dvp_set_image_format(DVP_CFG_RGB_FORMAT); +// dvp_set_image_size(320, 240); +// ov5640_init(); + +// //dvp_set_ai_addr((uint32_t)0x40600000, (uint32_t)0x40612C00, (uint32_t)0x40625800); +// dvp_set_display_addr((uint32_t)g_lcd_gram0); +// dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0); +// dvp_disable_auto(); + +// /* DVP interrupt config */ +// printf("DVP interrupt config\n"); +// plic_set_priority(IRQN_DVP_INTERRUPT, 2); +// plic_irq_register(IRQN_DVP_INTERRUPT, on_irq_dvp, NULL); +// plic_irq_enable(IRQN_DVP_INTERRUPT); + +// /* enable global interrupt */ +// sysctl_enable_irq(); + +// /* system start */ +// printf("system start\n"); +// g_ram_mux = 0; +// g_dvp_finish_flag = 0; +// dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH); +// dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 1); + +// self->active = 1; +// return mp_const_none; +// } + +// STATIC mp_obj_t machine_ov5640_deinit(mp_obj_t self_in) { +// machine_ov5640_disable(self_in); + +// return mp_const_none; +// } + +// STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_deinit_obj, machine_ov5640_deinit); + +// STATIC mp_obj_t machine_ov5640_get_image(mp_obj_t self_in,mp_obj_t buf) { +// machine_ov5640_obj_t* self = self_in; +// // uint32_t length = 0; +// // uint8_t* buf_image = 0; +// //mp_obj_list_get(buf,&length,&item); +// mp_buffer_info_t bufinfo; +// mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); +// while(self->buf.buf_used[self->buf.buf_sel] == 0 )_ndelay(50); +// memcpy(bufinfo.buf, self->buf.addr[self->buf.buf_sel], bufinfo.len); +// self->buf.buf_used[self->buf.buf_sel] = 0; +// //printf("[lichee]:get image!\n"); +// return mp_const_none; +// } + +// STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_ov5640_get_images_obj, machine_ov5640_get_image); + +// STATIC mp_obj_t machine_ov5640_init(mp_obj_t self_in) { +// machine_ov5640_obj_t* self = self_in; +// return machine_ov5640_init_helper(self); +// } +// STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_init_obj, machine_ov5640_init); + +// STATIC mp_obj_t machine_ov5640_lcdshow(mp_obj_t self_in) { +// dvp_lcd_show_register(); +// return mp_const_none; +// } +// STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_ov5640_lcdshow_obj, machine_ov5640_lcdshow); + +// STATIC const mp_rom_map_elem_t machine_ov5640_locals_dict_table[] = { +// { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_ov5640_deinit_obj) }, +// { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_ov5640_deinit_obj) }, +// { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_ov5640_init_obj) }, +// { MP_ROM_QSTR(MP_QSTR_lcdshow), MP_ROM_PTR(&machine_ov5640_lcdshow_obj) }, +// { MP_ROM_QSTR(MP_QSTR_get_image), MP_ROM_PTR(&machine_ov5640_get_images_obj) }, +// }; + +// STATIC MP_DEFINE_CONST_DICT(machine_ov5640_locals_dict, machine_ov5640_locals_dict_table); + +// const mp_obj_type_t machine_ov5640_type = { +// { &mp_type_type }, +// .name = MP_QSTR_ov5640, +// .print = machine_ov5640_print, +// .make_new = machine_ov5640_make_new, +// .locals_dict = (mp_obj_t)&machine_ov5640_locals_dict, +// }; diff --git a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/modmachine.c b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/modmachine.c index f76ac68..d7b4345 100755 --- a/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/modmachine.c +++ b/src/openmv/src/micropython/ports/k210-standalone/mpy-mod/machine/modmachine.c @@ -9,31 +9,31 @@ #if MICROPY_PY_MACHINE STATIC const mp_map_elem_t machine_module_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) }, - { MP_ROM_QSTR(MP_QSTR_uarths), MP_ROM_PTR(&machine_uarths_type) }, - { MP_ROM_QSTR(MP_QSTR_uart), MP_ROM_PTR(&machine_uart_type) }, - { MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&machine_pin_type) }, - { MP_ROM_QSTR(MP_QSTR_pwm), MP_ROM_PTR(&machine_pwm_type) }, - { MP_ROM_QSTR(MP_QSTR_timer), MP_ROM_PTR(&machine_timer_type) }, - { MP_ROM_QSTR(MP_QSTR_nt35310), MP_ROM_PTR(&machine_nt35310_type) }, - { MP_ROM_QSTR(MP_QSTR_ov5640), MP_ROM_PTR(&machine_ov5640_type) }, - { MP_ROM_QSTR(MP_QSTR_burner), MP_ROM_PTR(&machine_burner_type) }, - { MP_ROM_QSTR(MP_QSTR_demo_face_detect), MP_ROM_PTR(&machine_demo_face_detect_type) }, - { MP_ROM_QSTR(MP_QSTR_spiflsah), MP_ROM_PTR(&machine_spiflash_type) }, - { MP_ROM_QSTR(MP_QSTR_zmodem), MP_ROM_PTR(&machine_zmodem_type) }, - { MP_ROM_QSTR(MP_QSTR_fpioa), MP_ROM_PTR(&machine_fpioa_type) }, - { MP_ROM_QSTR(MP_QSTR_ws2812), MP_ROM_PTR(&machine_ws2812_type) }, - { MP_ROM_QSTR(MP_QSTR_led), MP_ROM_PTR(&machine_led_type) }, + {MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine)}, + {MP_ROM_QSTR(MP_QSTR_uarths), MP_ROM_PTR(&machine_uarths_type)}, + {MP_ROM_QSTR(MP_QSTR_uart), MP_ROM_PTR(&machine_uart_type)}, + {MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&machine_pin_type)}, + {MP_ROM_QSTR(MP_QSTR_pwm), MP_ROM_PTR(&machine_pwm_type)}, + {MP_ROM_QSTR(MP_QSTR_timer), MP_ROM_PTR(&machine_timer_type)}, + {MP_ROM_QSTR(MP_QSTR_nt35310), MP_ROM_PTR(&machine_nt35310_type)}, + {MP_ROM_QSTR(MP_QSTR_ov2640), MP_ROM_PTR(&machine_ov2640_type)}, + // {MP_ROM_QSTR(MP_QSTR_ov5640), MP_ROM_PTR(&machine_ov5640_type)}, + {MP_ROM_QSTR(MP_QSTR_burner), MP_ROM_PTR(&machine_burner_type)}, + {MP_ROM_QSTR(MP_QSTR_demo_face_detect), MP_ROM_PTR(&machine_demo_face_detect_type)}, + {MP_ROM_QSTR(MP_QSTR_spiflsah), MP_ROM_PTR(&machine_spiflash_type)}, + {MP_ROM_QSTR(MP_QSTR_zmodem), MP_ROM_PTR(&machine_zmodem_type)}, + {MP_ROM_QSTR(MP_QSTR_fpioa), MP_ROM_PTR(&machine_fpioa_type)}, + {MP_ROM_QSTR(MP_QSTR_ws2812), MP_ROM_PTR(&machine_ws2812_type)}, + {MP_ROM_QSTR(MP_QSTR_led), MP_ROM_PTR(&machine_led_type)}, }; -STATIC MP_DEFINE_CONST_DICT ( +STATIC MP_DEFINE_CONST_DICT( machine_module_globals, - machine_module_globals_table -); + machine_module_globals_table); const mp_obj_module_t machine_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&machine_module_globals, + .base = {&mp_type_module}, + .globals = (mp_obj_dict_t *)&machine_module_globals, }; #endif // MICROPY_PY_MACHINE diff --git a/src/openmv/src/micropython/py/makeqstrdata.pyc b/src/openmv/src/micropython/py/makeqstrdata.pyc index fe88a16..aec9c1a 100755 Binary files a/src/openmv/src/micropython/py/makeqstrdata.pyc and b/src/openmv/src/micropython/py/makeqstrdata.pyc differ