diff --git a/.github/workflows/build-release-test.yml b/.github/workflows/build-release-test.yml index 55a303d1..5e8174c3 100644 --- a/.github/workflows/build-release-test.yml +++ b/.github/workflows/build-release-test.yml @@ -29,7 +29,7 @@ jobs: - name: Build Projects run: | - projects=("canmv_k1" "canmv_dock" "canmv_k210" "canmv_makerobo" "canmv_dnk210") + projects=("canmv_k1" "canmv_dock" "canmv_k210" "canmv_makerobo" "canmv_dnk210" "canmv_k210_zero") for proj in ${projects[@]};do cd projects/${proj} echo "-------------------" @@ -70,43 +70,43 @@ jobs: artifacts: "release/**.bin" token: ${{ secrets.GITHUB_TOKEN }} - test: - if: endsWith(github.ref, 'main') - runs-on: self-hosted - needs: build - defaults: - run: - shell: bash - env: - SERIAL_DEV: /dev/ttyACM1 + # test: + # if: endsWith(github.ref, 'main') + # runs-on: self-hosted + # needs: build + # defaults: + # run: + # shell: bash + # env: + # SERIAL_DEV: /dev/ttyACM1 - steps: - - name: Check Board - run: | - ls ${{ env.SERIAL_DEV }} - if [ $? -ne 0 ]; then - echo "Runner have no board connected." - exit -1 - fi + # steps: + # - name: Check Board + # run: | + # ls ${{ env.SERIAL_DEV }} + # if [ $? -ne 0 ]; then + # echo "Runner have no board connected." + # exit -1 + # fi - - uses: actions/checkout@v3 + # - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 - with: - path: ./build - name: "canmv-${{ github.sha }}" + # - uses: actions/download-artifact@v3 + # with: + # path: ./build + # name: "canmv-${{ github.sha }}" - - name: Burn Test Firmware - run: | - python3 tools/flash/kflash_py/kflash.py -p ${{ env.SERIAL_DEV }} -b 1500000 build/canmv_k1_standard.bin + # - name: Burn Test Firmware + # run: | + # python3 tools/flash/kflash_py/kflash.py -p ${{ env.SERIAL_DEV }} -b 1500000 build/canmv_k1_standard.bin - - name: Run Tests - run: | - cd tools/tests - python3 run-tests.py --target k210 --device ${{ env.SERIAL_DEV }} --baudrate 115200 - cd - + # - name: Run Tests + # run: | + # cd tools/tests + # python3 run-tests.py --target k210 --device ${{ env.SERIAL_DEV }} --baudrate 115200 + # cd - - - uses: actions/upload-artifact@v3 - with: - name: "canmv-test-results-${{ github.sha }}" - path: tools/tests/results + # - uses: actions/upload-artifact@v3 + # with: + # name: "canmv-test-results-${{ github.sha }}" + # path: tools/tests/results diff --git a/components/micropython/port/src/omv/cambus.c b/components/micropython/port/src/omv/cambus.c index 7c4ee935..3cfee7ee 100644 --- a/components/micropython/port/src/omv/cambus.c +++ b/components/micropython/port/src/omv/cambus.c @@ -13,6 +13,8 @@ #include "gc0328.h" #include "gc2145.h" #include "mt9d111.h" +#include "pgd030k.h" + #include "py/mpprint.h" #include "sysctl.h" #include "fpioa.h" @@ -263,6 +265,22 @@ int cambus_scan_mt9d111(void) return id; } +int cambus_scan_pgd030k(void) +{ + uint8_t id_h = 0, id_l = 0; + uint16_t id = 0; + + sccb_reg_width = 8; + + sccb_i2c_write_byte(i2c_device, PGD030K_I2C_ADDR, 0x03, sccb_reg_width, 0x00, 10); // Bank A + sccb_i2c_read_byte(i2c_device, PGD030K_I2C_ADDR, 0x00, sccb_reg_width, &id_h, 10); // Device ID High + sccb_i2c_read_byte(i2c_device, PGD030K_I2C_ADDR, 0x01, sccb_reg_width, &id_l, 10); // Device ID Low + + id = (id_h << 8) | id_l; + + return (PGD030K_ID_CODE == id) ? PGD030K_ID_CODE : 0x00; +} + int cambus_readb(uint8_t slv_addr, uint16_t reg_addr, uint8_t *reg_data) { diff --git a/components/micropython/port/src/omv/cambus.h b/components/micropython/port/src/omv/cambus.h index 71bbda13..45f7c68a 100644 --- a/components/micropython/port/src/omv/cambus.h +++ b/components/micropython/port/src/omv/cambus.h @@ -14,6 +14,7 @@ int cambus_scan(); int cambus_scan_gc0328(void); int cambus_scan_gc2145(void); int cambus_scan_mt9d111(void); +int cambus_scan_pgd030k(void); int cambus_readb(uint8_t slv_addr, uint16_t reg_addr, uint8_t *reg_data); void cambus_set_writeb_delay(uint32_t delay); int cambus_writeb(uint8_t slv_addr, uint16_t reg_addr, uint8_t reg_data); diff --git a/components/micropython/port/src/omv/include/pgd030k.h b/components/micropython/port/src/omv/include/pgd030k.h new file mode 100644 index 00000000..67a4407f --- /dev/null +++ b/components/micropython/port/src/omv/include/pgd030k.h @@ -0,0 +1,38 @@ +/* + * mt9d111.h + * + * Copyright (C) 2018, Gabriel Mariano Marcelino + * + * This file is part of MT9D111-Driver. + * + * MT9D111-Driver is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MT9D111-Driver is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with MT9D111-Driver. If not, see . + * + */ + +#ifndef PGD030K_H +#define PGD030K_H + +#include + +#include "sensor.h" + +// I2C addresses +#define PGD030K_I2C_ADDR 0x33 /* DVP, fixed to 0x66 */ + +// Device ID code +#define PGD030K_ID_CODE 0xD030 + +int pgd030k_init(sensor_t *sensor); + +#endif // PGD030K_H diff --git a/components/micropython/port/src/omv/pgd030k.c b/components/micropython/port/src/omv/pgd030k.c new file mode 100644 index 00000000..da09a8cd --- /dev/null +++ b/components/micropython/port/src/omv/pgd030k.c @@ -0,0 +1,908 @@ +/* Copyright 2018 Canaan Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS}, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "pgd030k.h" + +#include "dvp.h" +#include "plic.h" +#include "printf.h" +#include "sleep.h" + +#include "cambus.h" +#include "sensor.h" + +#include "mphalport.h" +#include "py/runtime.h" + +/** + * \brief Struct to store an register address and its value. + */ +struct Register { + uint16_t address; /**< struct Register address. */ + uint16_t value; /**< struct Register value. */ +}; + +static const struct Register pgd030k_regs_init_seq[] = { + // ############################################################################### + // # TG Timing Setting + // ############################################################################### + + // # Frame structure setting + { 0x03, 0x00 }, // bank A + { 0x06, 0x03 }, // framewidth_h + { 0x07, 0x59 }, // framewidth_l + { 0x08, 0x02 }, // fheight_a_h + { 0x09, 0x0C }, // fheight_a_l + { 0x03, 0x01 }, // bank B + { 0x04, 0x80 }, // bayer_control_01 + { 0x1B, 0x00 }, // dmyfwa_h + { 0x1C, 0x00 }, // dmyfwa_l + { 0x1D, 0x00 }, // dmyfwb_h + { 0x1E, 0x00 }, // dmyfwb_l + { 0x1F, 0x00 }, // retrace_h + { 0x20, 0x00 }, // retrace_l + { 0x24, 0x00 }, // tgvstart_h + { 0x25, 0x08 }, // tgvstart_l + { 0x26, 0x01 }, // tgvstop_h + { 0x27, 0xEC }, // tgvstop_l + { 0x2C, 0x00 }, // blvstart_0_h + { 0x2D, 0x02 }, // blvstart_0_l + { 0x2E, 0x00 }, // blvstop_0_h + { 0x2F, 0x08 }, // blvstop_0_l + { 0x03, 0x02 }, // bank C + { 0x48, 0x0F }, // illuminance_h + { 0x49, 0xFF }, // illuminance_l + + // # mirror setting + { 0x03, 0x00 }, // bank A + { 0x05, 0x00 }, // mirror + { 0x03, 0x01 }, // bank + { 0x0E, 0x01 }, // bayer_control_11 + { 0x0F, 0x00 }, // bayer_control_12 + + // ############################################################################### + // # Format Timing Setting + // ############################################################################### + + // # Window setting + { 0x03, 0x00 }, // bank + { 0x0C, 0x00 }, // windowx1_h + { 0x0D, 0x01 }, // windowx1_l + { 0x10, 0x01 }, // windowx2_h + { 0x11, 0x41 }, // windowx2_l + { 0x0E, 0x00 }, // windowy1_h + { 0x0F, 0x02 }, // windowy1_l + { 0x12, 0x01 }, // windowy2_h + { 0x13, 0xE2 }, // windowy2_l + + // # Format fifo setting + { 0x03, 0x00 }, // bank + { 0xAC, 0x01 }, // rd_bit_sel + { 0x97, 0x02 }, // rd_cnt_init_h + { 0x98, 0x50 }, // rd_cnt_init_l + { 0x99, 0x00 }, // rd_x_start0_h + { 0x9A, 0x30 }, // rd_x_start0_l + { 0x9B, 0x02 }, // rd_x_stop0_h + { 0x9C, 0xB0 }, // rd_x_stop0_l + { 0x9D, 0x00 }, // rd_y_start_h + { 0x9E, 0x0B }, // rd_y_start_l + { 0x9F, 0x01 }, // rd_y_stop_h + { 0xA0, 0xEB }, // rd_y_stop_l + + // # vsync setting + { 0x03, 0x00 }, // bank + { 0x74, 0x00 }, // vsyncstartrow0_h + { 0x75, 0x0B }, // vsyncstartrow0_l + { 0x76, 0x01 }, // vsyncstoprow0_h + { 0x77, 0xEB }, // vsyncstoprow0_l + + // ############################################################################### + // # TG Data Setting + // ############################################################################### + + // # ADC setting + { 0x03, 0x01 }, // bank + { 0x8B, 0x06 }, // dat_max_h + { 0x8C, 0xCC }, // dat_max_l + { 0x8D, 0x01 }, // dat_ofst_h + { 0x8E, 0x00 }, // dat_ofst_l + { 0x8F, 0x01 }, // max_robp_h + { 0x90, 0xCD }, // max_robp_l + + // # DBLC setting + { 0x03, 0x01 }, // bank + { 0x05, 0xBE }, // bayer_control_02 + + // # ABLC setting + { 0x03, 0x01 }, // bank + { 0x06, 0x80 }, // bayer_control_03 + { 0x07, 0xE0 }, // bayer_control_04 + { 0xDB, 0x01 }, // blc_top_th_h + { 0xDC, 0xB0 }, // blc_top_th_l + { 0xDD, 0x01 }, // blc_bot_th_h + { 0xDE, 0x40 }, // blc_bot_th_l + + // # Column inttime setting + { 0x03, 0x01 }, // bank + { 0x0D, 0x86 }, // bayer_control_10 + { 0x03, 0x03 }, // bank + { 0x4A, 0x0E }, // lineth + { 0x4B, 0xFF }, // expcorr + { 0x4D, 0x80 }, // prestop + + // # Test Pattern setting + // W0301 # bank + // W0D86 # bayer_control_10 [4:3]tp_seq 2'b00 + // W931A # tp_control_0 + // W9403 # tp_control_1_h + // W95FF # tp_control_1_l + // W9603 # tp_control_2_h + // W97FF # tp_control_2_l + // W9803 # tp_control_3_h + // W99FF # tp_control_3_l + // W9A03 # tp_control_4_h + // W9BFF # tp_control_4_l + // W9C02 # hact_width_h + // W9D84 # hact_width_l + // W9E03 # Yos_init_h + // W9F0E # Yos_init_l + // WA002 # Xos_init_h + // WA1BA # Xos_init_l + + // ############################################################################### + // # Format Data Setting + // ############################################################################### + + // # Data max/min setting + { 0x03, 0x00 }, // bank + { 0xB2, 0x02 }, // sync_control_1 //0x22 HSync_all_line + { 0xB4, 0x00 }, // data_min_h + { 0xB5, 0x04 }, // data_min_l + { 0xB6, 0x03 }, // data_max_h + { 0xB7, 0xF8 }, // data_max_l + + // ############################################################################### + // # MIPI Setting + // ############################################################################### + + // //# MIPI setting + // {0x03,0x05}, // bank + // {0x04,0x30}, // mipi_control_0 + // {0x05,0x9B}, // mipi_control_1 + // {0x06,0x99}, // mipi_control_2 + // {0x07,0x99}, // mipi_control_3 + // {0x08,0x01}, // mipi_control_4 + + // //# MIPI packet setting + // //# 640/4*5=800 + // {0x36,0x03}, // mipi_pkt_size0_h + // {0x37,0x20}, // mipi_pkt_size0_l + + // //# MIPI timing setting + // {0x1C,0x00}, // mipi_T_lpx + // {0x1D,0x00}, // mipi_T_clk_prepare + // {0x1E,0x00}, // mipi_T_hs_prepare + // {0x1F,0x00}, // mipi_T_hs_zero + // {0x20,0x00}, // mipi_T_hs_trail + // {0x21,0x00}, // mipi_T_clk_zero + // {0x22,0x00}, // mipi_T_clk_trail + // {0x23,0x00}, // mipi_T_clk_pre + // {0x24,0x00}, // mipi_T_clk_post + // {0x25,0x00}, // mipi_T_wakeup + // {0x26,0x00}, // mipi_T_hsexit + // {0x27,0x00}, // mipi_T_clk_hsexit + + // //# MIPI datatype setting + // {0x42,0x00}, // mipi_data_id0 + + // ############################################################################### + // # DVP Setting + // ############################################################################### + + // # PAD drivability setting + { 0x03, 0x00 }, // bank A + { 0x24, 0xF0 }, // pad_control2 + + // # PAD setting + { 0x03, 0x00 }, // bank + { 0x25, 0x98 }, // pad_control3 + { 0x26, 0x0F }, // pad_control4 + { 0x27, 0xF0 }, // pad_control5 + { 0x28, 0x00 }, // pad_control6 + + // ############################################################################### + // # Clock Setting + // ############################################################################### + + // # pll bandwidth setting + { 0x03, 0x00 }, // bank + { 0x4E, 0x7A }, // pll_control2 + { 0x4F, 0x7E }, // pll_control3 + + // # pll & clock divider setting + { 0x03, 0x00 }, // bank + { 0x1A, 0xF0 }, // i2c_control_1 + { 0x51, 0x20 }, // pll_tg_n_cnt + { 0x52, 0x02 }, // pll_tg_r_cnt + { 0x53, 0x20 }, // pll_mp_n_cnt + { 0x54, 0x02 }, // pll_mp_r_cnt + { 0x56, 0x12 }, // clkdiv1 + { 0x57, 0x10 }, // clkdiv2 + { 0x58, 0x80 }, // clkdiv3 + { 0x1A, 0x50 }, // i2c_control_1 + + // # PLL power & bypass setting + { 0x4E, 0x52 }, // pll_control2 + //$0200 // wait for 200 us; + // {0xffff,0x01}, //for dothinkey delay + { 0xFFFF, 10 }, // delay 1ms + + { 0x4E, 0x42 }, // pll_control2 + + /////! PSD030K_ANALOG_230303 (PSD030K_Analog_global_640x480_DVP_Bayer_240fps_230303.ccf) + + // 0x03,0x00, W0220 W0223 W0203 W0203 + + // ## Analog Setting + + //------------------------------------ for pd to xcp sequency + { 0x03, 0x00 }, // A bank + { 0x3E, 0x7F }, // xcp & cp pd disable + + { 0x03, 0x01 }, // B bank + { 0x0B, 0x54 }, // xcp_clk_en[4]=1 + + { 0x03, 0x00 }, // A bank + { 0x3E, 0x03 }, // xcp & cp pd disable + //------------------------------------ + + { 0x03, 0x00 }, // A bank + { 0x38, 0x27 }, // Pixelbias1 0111 + { 0x3B, 0x67 }, // Ramprange 1.35V --> 1.40625V + { 0x3D, 0x65 }, // S2(VDD/NCP_L), S1(VDD/NCP_L) ==>S2 NCP + { 0x3F, 0x8A }, // NCP_T -0.9 --> -1.1V + { 0x40, 0x81 }, // NCP_LS -0.7-->-0.2V + { 0x41, 0x88 }, // PCP_RT 3.3V-->3.5V + { 0x42, 0x82 }, // PCP_L 4.3V-->3.0V + { 0x43, 0x07 }, // VPC 0.7V + + { 0x03, 0x01 }, // B bank + { 0x7A, 0x10 }, // globalgain x2(global shutter x1) + + { 0x03, 0x02 }, // C bank + { 0xC7, 0x10 }, // blacksun[6:0] 60h-->20h-->10h + { 0xC8, 0x20 }, // blacksun x4 20h + + { 0x03, 0x03 }, // D bank + { 0x4D, 0x00 }, // prestop 80h-->31h(top h-line remove@x8) + + // ## Timing Setting + + { 0x03, 0x02 }, // C bank + + { 0x13, 0x00 }, // row_ls_en_start_h (1) + { 0x14, 0x01 }, // row_ls_en_start_l + { 0x15, 0x03 }, // row_ls_en_stop_h (856) + { 0x16, 0x58 }, // row_ls_en_stop_l + + { 0x1F, 0x00 }, // row_r_ls_rst_start_h (20) + { 0x20, 0x14 }, // row_r_ls_rst_start_l + { 0x21, 0x00 }, // row_r_ls_rst_stop_h (20) + { 0x22, 0x14 }, // row_r_ls_rst_stop_l + + { 0x34, 0x00 }, // row_r_rs_tx_start_h (0) + { 0x35, 0x00 }, // row_r_rs_tx_start_l + { 0x36, 0x00 }, // row_r_rs_tx_stop_h (0) + { 0x37, 0x00 }, // row_r_rs_tx_stop_l + + { 0x38, 0x01 }, // row_r_ls_tx_start_h (350) + { 0x39, 0x5E }, // row_r_ls_tx_start_l + { 0x3A, 0x01 }, // row_r_ls_tx_stop_h (350) + { 0x3B, 0x5E }, // row_r_ls_tx_stop_l + + { 0x1B, 0x00 }, // row_g_pr_rst_stop_rcnt_h (0) + { 0x1C, 0x00 }, // row_g_pr_rst_stop_rcnt_l + { 0x17, 0x00 }, // row_g_pr_rst_start_rcnt_h (0) + { 0x18, 0x00 }, // row_g_pr_rst_start_rcnt_l + + { 0x2F, 0x02 }, // row_g_pr_tx_stop1_rcnt_h (512) + { 0x30, 0x00 }, // row_g_pr_tx_stop1_rcnt_l + { 0x2B, 0x00 }, // row_g_pr_tx_start1_rcnt_h (0) + { 0x2C, 0x00 }, // row_g_pr_tx_start1_rcnt_l + + { 0x27, 0x00 }, // row_g_pr_tx_stop0_rcnt_h (0) + { 0x28, 0x00 }, // row_g_pr_tx_stop0_rcnt_l + { 0x23, 0x00 }, // row_g_pr_tx_start0_rcnt_h (0) + { 0x24, 0x00 }, // row_g_pr_tx_start0_rcnt_l + + { 0x03, 0x01 }, // B bank + + { 0x6C, 0x01 }, // inttime_h (511) + { 0x6D, 0xFF }, // inttime_m + + { 0x03, 0x02 }, // C bank + + { 0x40, 0x00 }, // row_g_pr_s2_stop_rcnt_h (0) + { 0x41, 0x00 }, // row_g_pr_s2_stop_rcnt_l + { 0x3C, 0x00 }, // row_g_pr_s2_start_rcnt_h (0) + { 0x3D, 0x00 }, // row_g_pr_s2_start_rcnt_l + + { 0x5C, 0x00 }, // row_g_pr_s1_stop_rcnt_h (0) + { 0x5D, 0x00 }, // row_g_pr_s1_stop_rcnt_l + { 0x58, 0x00 }, // row_g_pr_s1_start_rcnt_h (0) + { 0x59, 0x00 }, // row_g_pr_s1_start_rcnt_l + + { 0x6C, 0x00 }, // row_g_pr_vpc_stop1_rcnt_h (0) + { 0x6D, 0x00 }, // row_g_pr_vpc_stop1_rcnt_l + { 0x68, 0x00 }, // row_g_pr_vpc_start1_rcnt_h (0) + { 0x69, 0x00 }, // row_g_pr_vpc_start1_rcnt_l + + { 0x64, 0x00 }, // row_g_pr_vpc_stop0_rcnt_h (0) + { 0x65, 0x00 }, // row_g_pr_vpc_stop0_rcnt_l + { 0x60, 0x00 }, // row_g_pr_vpc_start0_rcnt_h (0) + { 0x61, 0x00 }, // row_g_pr_vpc_start0_rcnt_l + + { 0x19, 0x00 }, // row_g_pr_rst_start_ccnt_h (250) + { 0x1A, 0xFA }, // row_g_pr_rst_start_ccnt_l + { 0x1D, 0x03 }, // row_g_pr_rst_stop_ccnt_h (800) + { 0x1E, 0x20 }, // row_g_pr_rst_stop_ccnt_l + + { 0x29, 0x01 }, // row_g_pr_tx_stop0_ccnt_h (380) + { 0x2A, 0x7C }, // row_g_pr_tx_stop0_ccnt_l + { 0x2D, 0x01 }, // row_g_pr_tx_start1_ccnt_h (430) + { 0x2E, 0xAE }, // row_g_pr_tx_start1_ccnt_l + { 0x31, 0x03 }, // row_g_pr_tx_stop1_ccnt_h (831) + { 0x32, 0x3F }, // row_g_pr_tx_stop1_ccnt_l + + { 0x3E, 0x01 }, // row_g_pr_s2_start_ccnt_h (270) + { 0x3F, 0x0E }, // row_g_pr_s2_start_ccnt_l + { 0x42, 0x01 }, // row_g_pr_s2_stop_ccnt_h (368) + { 0x43, 0x70 }, // row_g_pr_s2_stop_ccnt_l + + { 0x5A, 0x01 }, // row_g_pr_s1_start_ccnt_h (270) + { 0x5B, 0x0E }, // row_g_pr_s1_start_ccnt_l + { 0x5E, 0x03 }, // row_g_pr_s1_stop_ccnt_h (785) + { 0x5F, 0x11 }, // row_g_pr_s1_stop_ccnt_l + + { 0x6A, 0x01 }, // row_g_pr_vpc_start1_ccnt_h (280) + { 0x6B, 0x18 }, // row_g_pr_vpc_start1_ccnt_l + { 0x6E, 0x01 }, // row_g_pr_vpc_stop1_ccnt_h (348) + { 0x6F, 0x5C }, // row_g_pr_vpc_stop1_ccnt_l + + { 0x62, 0x01 }, // row_g_pr_vpc_start0_ccnt_h (388) + { 0x63, 0x84 }, // row_g_pr_vpc_start0_ccnt_l + { 0x66, 0x01 }, // row_g_pr_vpc_stop0_ccnt_h (445) + { 0x67, 0xBD }, // row_g_pr_vpc_stop0_ccnt_l + + { 0x48, 0x02 }, // row_s2_pcp_sel_stop_rcnt_h (600) + { 0x49, 0x58 }, // row_s2_pcp_sel_stop_rcnt_l + { 0x44, 0x00 }, // row_s2_pcp_sel_start_rcnt_h (0) + { 0x45, 0x00 }, // row_s2_pcp_sel_start_rcnt_l + + { 0x46, 0x00 }, // row_s2_pcp_sel_start_ccnt_h (1) + { 0x47, 0x01 }, // row_s2_pcp_sel_start_ccnt_l + { 0x4A, 0x03 }, // row_s2_pcp_sel_stop_ccnt_h (802) + { 0x4B, 0x22 }, // row_s2_pcp_sel_stop_ccnt_l + + { 0x50, 0x02 }, // row_s2_ncp_sel_stop_rcnt_h (600) + { 0x51, 0x58 }, // row_s2_ncp_sel_stop_rcnt_l + { 0x4C, 0x00 }, // row_s2_ncp_sel_start_rcnt_h (0) + { 0x4D, 0x00 }, // row_s2_ncp_sel_start_rcnt_l + + { 0x4E, 0x00 }, // row_s2_ncp_sel_start_ccnt_h (1) + { 0x4F, 0x01 }, // row_s2_ncp_sel_start_ccnt_l + { 0x52, 0x03 }, // row_s2_ncp_sel_stop_ccnt_h (802) + { 0x53, 0x22 }, // row_s2_ncp_sel_stop_ccnt_l + + { 0x54, 0x01 }, // row_r_ls_s2_start_h (280) + { 0x55, 0x18 }, // row_r_ls_s2_start_l + { 0x56, 0x03 }, // row_r_ls_s2_stop_h (780) + { 0x57, 0x0C }, // row_r_ls_s2_stop_l + + { 0x05, 0x03 }, // row_flush_start_start_h (855) + { 0x06, 0x57 }, // row_flush_start_start_l + { 0x07, 0x03 }, // row_flush_start_stop_h (855) + { 0x08, 0x57 }, // row_flush_start_stop_l + + { 0x09, 0x00 }, // row_flush_stop_start_h (21) + { 0x0A, 0x15 }, // row_flush_stop_start_l + { 0x0B, 0x00 }, // row_flush_stop_stop_h (21) + { 0x0C, 0x15 }, // row_flush_stop_stop_l + + { 0x0D, 0x03 }, // row_latch_rst_start_h (855) + { 0x0E, 0x57 }, // row_latch_rst_start_l + { 0x0F, 0x03 }, // row_latch_rst_stop_h (855) + { 0x10, 0x57 }, // row_latch_rst_stop_l + + { 0x88, 0x01 }, // cds_bls_en_start_h (300) + { 0x89, 0x2C }, // cds_bls_en_start_l + + { 0x80, 0x00 }, // cds_store1_start_h (10) + { 0x81, 0x0A }, // cds_store1_start_l + { 0x82, 0x00 }, // cds_store1_stop_h (80) + { 0x83, 0x50 }, // cds_store1_stop_l + + { 0x84, 0x00 }, // cds_store2_start_h (10) + { 0x85, 0x0A }, // cds_store2_start_l + { 0x86, 0x00 }, // cds_store2_stop_h (110) + { 0x87, 0x6E }, // cds_store2_stop_l + + { 0x8E, 0x00 }, // cds_pxl_track_start1_h (0) + { 0x8F, 0x00 }, // cds_pxl_track_start1_l + { 0x90, 0x03 }, // cds_pxl_track_stop1_h (857) + { 0x91, 0x59 }, // cds_pxl_track_stop1_l + { 0x92, 0x03 }, // cds_pxl_track_start2_h (857) + { 0x93, 0x59 }, // cds_pxl_track_start2_l + { 0x94, 0x03 }, // cds_pxl_track_stop2_h (857) + { 0x95, 0x59 }, // cds_pxl_track_stop2_l + + { 0x9A, 0x00 }, // cds_amp1_rst_start1_h (155) + { 0x9B, 0x9B }, // cds_amp1_rst_start1_l + { 0x9C, 0x00 }, // cds_amp1_rst_stop1_h (185) + { 0x9D, 0xB9 }, // cds_amp1_rst_stop1_l + { 0x9E, 0x01 }, // cds_amp1_rst_start2_h (330) + { 0x9F, 0x4A }, // cds_amp1_rst_start2_l + { 0xA0, 0x01 }, // cds_amp1_rst_stop2_h (360) + { 0xA1, 0x68 }, // cds_amp1_rst_stop2_l + + { 0xA2, 0x00 }, // cds_amp2_clamp_en_start1_h (155) + { 0xA3, 0x9B }, // cds_amp2_clamp_en_start1_l + { 0xA4, 0x03 }, // cds_amp2_clamp_en_stop1_h (857) + { 0xA5, 0x59 }, // cds_amp2_clamp_en_stop1_l + { 0xA6, 0x03 }, // cds_amp2_clamp_en_start2_h (857) + { 0xA7, 0x59 }, // cds_amp2_clamp_en_start2_l + { 0xA8, 0x03 }, // cds_amp2_clamp_en_stop2_h (857) + { 0xA9, 0x59 }, // cds_amp2_clamp_en_stop2_l + + { 0xAA, 0x03 }, // cds_amp2_rst_start1_h (857) + { 0xAB, 0x59 }, // cds_amp2_rst_start1_l + { 0xAC, 0x03 }, // cds_amp2_rst_stop1_h (857) + { 0xAD, 0x59 }, // cds_amp2_rst_stop1_l + { 0xAE, 0x03 }, // cds_amp2_rst_start2_h (857) + { 0xAF, 0x59 }, // cds_amp2_rst_start2_l + { 0xB0, 0x03 }, // cds_amp2_rst_stop2_h (857) + { 0xB1, 0x59 }, // cds_amp2_rst_stop2_l + + { 0xB2, 0x00 }, // cds_sf_rst_start1_h (157) + { 0xB3, 0x9D }, // cds_sf_rst_start1_l + { 0xB4, 0x00 }, // cds_sf_rst_stop1_h (187) + { 0xB5, 0xBB }, // cds_sf_rst_stop1_l + { 0xB6, 0x01 }, // cds_sf_rst_start2_h (332) + { 0xB7, 0x4C }, // cds_sf_rst_start2_l + { 0xB8, 0x01 }, // cds_sf_rst_stop2_h (362) + { 0xB9, 0x6A }, // cds_sf_rst_stop2_l + + { 0x03, 0x03 }, // D bank + + { 0x06, 0x01 }, // ramp_ablc_sw_en_start1_h (280) + { 0x07, 0x18 }, // ramp_ablc_sw_en_start1_l + { 0x08, 0x01 }, // ramp_ablc_sw_en_stop1_h (282) + { 0x09, 0x1A }, // ramp_ablc_sw_en_stop1_l + + { 0x0A, 0x03 }, // ramp_ablc_sw_en_start2_h (805) + { 0x0B, 0x25 }, // ramp_ablc_sw_en_start2_l + { 0x0C, 0x03 }, // ramp_ablc_sw_en_stop2_h (807) + { 0x0D, 0x27 }, // ramp_ablc_sw_en_stop2_l + + { 0x16, 0x00 }, // ramp_state_lsb_start1_h (115) + { 0x17, 0x73 }, // ramp_state_lsb_start1_l + { 0x18, 0x00 }, // ramp_state_lsb_stop1_h (117) + { 0x19, 0x75 }, // ramp_state_lsb_stop1_l + + { 0x1A, 0x01 }, // ramp_state_lsb_start2_h (280) + { 0x1B, 0x18 }, // ramp_state_lsb_start2_l + { 0x1C, 0x01 }, // ramp_state_lsb_stop2_h (282) + { 0x1D, 0x1A }, // ramp_state_lsb_stop2_l + + { 0x1E, 0x03 }, // ramp_state_lsb_start3_h (805) + { 0x1F, 0x25 }, // ramp_state_lsb_start3_l + { 0x20, 0x03 }, // ramp_state_lsb_stop3_h (807) + { 0x21, 0x27 }, // ramp_state_lsb_stop3_l + + { 0x12, 0x00 }, // ramp_state_msb_start_h (118) + { 0x13, 0x76 }, // ramp_state_msb_start_l + { 0x14, 0x00 }, // ramp_state_msb_stop_h (118) + { 0x15, 0x76 }, // ramp_state_msb_stop_l + + { 0x32, 0x00 }, // ramp_clk_start1_h (118) + { 0x33, 0x76 }, // ramp_clk_start1_l + { 0x24, 0x00 }, // ramp_clk_stop1_y0_h (122) + { 0x25, 0x7A }, // ramp_clk_stop1_y0_l + + { 0x34, 0x00 }, // ramp_clk_start2_h (195) + { 0x35, 0xC3 }, // ramp_clk_start2_l + { 0x36, 0x01 }, // ramp_clk_stop2_h (300) + { 0x37, 0x2C }, // ramp_clk_stop2_l + + { 0x38, 0x01 }, // ramp_clk_start3_h (405) + { 0x39, 0x95 }, // ramp_clk_start3_l + { 0x3A, 0x03 }, // ramp_clk_stop3_h (777) + { 0x3B, 0x09 }, // ramp_clk_stop3_l + + { 0x3C, 0x03 }, // ramp_clk_start4_h (807) + { 0x3D, 0x27 }, // ramp_clk_start4_l + { 0x2C, 0x03 }, // ramp_clk_stop4_y0_h (837) + { 0x2D, 0x45 }, // ramp_clk_stop4_y0_l + + { 0x03, 0x03 }, // D bank + + { 0x0E, 0x03 }, // ramp_ref_sample_start_h (810) + { 0x0F, 0x2A }, // ramp_ref_sample_start_l + { 0x10, 0x03 }, // ramp_ref_sample_stop_h (857) + { 0x11, 0x59 }, // ramp_ref_sample_stop_l + + { 0x3E, 0x03 }, // ramp_dvdd_sample_start_h (810) + { 0x3F, 0x2A }, // ramp_dvdd_sample_start_l + { 0x40, 0x03 }, // ramp_dvdd_sample_stop_h (857) + { 0x41, 0x59 }, // ramp_dvdd_sample_stop_l + + { 0x42, 0x03 }, // ramp_ablc_ref_sample_start_h (810) + { 0x43, 0x2A }, // ramp_ablc_ref_sample_start_l + { 0x44, 0x03 }, // ramp_ablc_ref_sample_stop_h (857) + { 0x45, 0x59 }, // ramp_ablc_ref_sample_stop_l + + { 0x03, 0x02 }, // C bank + + { 0xCA, 0x00 }, // adc_clk_en_start1_h (195) + { 0xCB, 0xC3 }, // adc_clk_en_start1_l + { 0xCC, 0x01 }, // adc_clk_en_stop1_h (275) + { 0xCD, 0x13 }, // adc_clk_en_stop1_l + { 0xCE, 0x01 }, // adc_clk_en_start2_h (405) + { 0xCF, 0x95 }, // adc_clk_en_start2_l + { 0xD0, 0x03 }, // adc_clk_en_stop2_h (777) + { 0xD1, 0x09 }, // adc_clk_en_stop2_l + + { 0xD2, 0x01 }, // cntr_pol_start_h (280) + { 0xD3, 0x18 }, // cntr_pol_start_l + { 0xD4, 0x03 }, // cntr_pol_stop_h (805) + { 0xD5, 0x25 }, // cntr_pol_stop_l + + { 0xDA, 0x00 }, // cntr_load_en_start1_h (191) + { 0xDB, 0xBF }, // cntr_load_en_start1_l + { 0xDC, 0x01 }, // cntr_load_en_stop1_h (279) + { 0xDD, 0x17 }, // cntr_load_en_stop1_l + { 0xDE, 0x01 }, // cntr_load_en_start2_h (401) + { 0xDF, 0x91 }, // cntr_load_en_start2_l + { 0xE0, 0x03 }, // cntr_load_en_stop2_h (781) + { 0xE1, 0x0D }, // cntr_load_en_stop2_l + + { 0xE2, 0x00 }, // cntr_latch_en1_start1_h (193) + { 0xE3, 0xC1 }, // cntr_latch_en1_start1_l + { 0xE4, 0x01 }, // cntr_latch_en1_stop1_h (277) + { 0xE5, 0x15 }, // cntr_latch_en1_stop1_l + { 0xE6, 0x01 }, // cntr_latch_en1_start2_h (403) + { 0xE7, 0x93 }, // cntr_latch_en1_start2_l + { 0xE8, 0x03 }, // cntr_latch_en1_stop2_h (779) + { 0xE9, 0x0B }, // cntr_latch_en1_stop2_l + + { 0xEA, 0x00 }, // cntr_latch_en2_start1_h (193) + { 0xEB, 0xC1 }, // cntr_latch_en2_start1_l + { 0xEC, 0x01 }, // cntr_latch_en2_stop1_h (277) + { 0xED, 0x15 }, // cntr_latch_en2_stop1_l + { 0xEE, 0x01 }, // cntr_latch_en2_start2_h (403) + { 0xEF, 0x93 }, // cntr_latch_en2_start2_l + { 0xF0, 0x03 }, // cntr_latch_en2_stop2_h (779) + { 0xF1, 0x0B }, // cntr_latch_en2_stop2_l + + { 0xD6, 0x03 }, // cntr_rstb_start_h (855) + { 0xD7, 0x57 }, // cntr_rstb_start_l + { 0xD8, 0x03 }, // cntr_rstb_stop_h (857) + { 0xD9, 0x59 }, // cntr_rstb_stop_l + + { 0xF2, 0x03 }, // cntr_transfer_start_h (852) + { 0xF3, 0x54 }, // cntr_transfer_start_l + { 0xF4, 0x03 }, // cntr_transfer_stop_h (854) + { 0xF5, 0x56 }, // cntr_transfer_stop_l + + { 0x8A, 0x03 }, // cds_pxl_bias1_track_start_h (810) + { 0x8B, 0x2A }, // cds_pxl_bias1_track_start_l + { 0x8C, 0x03 }, // cds_pxl_bias1_track_stop_h (857) + { 0x8D, 0x59 }, // cds_pxl_bias1_track_stop_l + + { 0x96, 0x03 }, // cds_amp1_bias1_track_start_h (810) + { 0x97, 0x2A }, // cds_amp1_bias1_track_start_l + { 0x98, 0x03 }, // cds_amp1_bias1_track_stop_h (857) + { 0x99, 0x59 }, // cds_amp1_bias1_track_stop_l + + { 0xBA, 0x00 }, // cds_amp2_clamp_sample_start_h (0) + { 0xBB, 0x00 }, // cds_amp2_clamp_sample_start_l + { 0xBC, 0x03 }, // cds_amp2_clamp_sample_stop_h (857) + { 0xBD, 0x59 }, // cds_amp2_clamp_sample_stop_l + + { 0x03, 0x01 }, // B bank + + { 0x28, 0x02 }, // tghstart_h (528) + { 0x29, 0x10 }, // tghstart_l + { 0x2A, 0x03 }, // tghstop_h (850) + { 0x2B, 0x52 }, // tghstop_l + + { 0x3C, 0x07 }, // coffset_h (1874) + { 0x3D, 0x52 }, // coffset_l + + { 0x38, 0x02 }, // blhstart_h (528) + { 0x39, 0x10 }, // blhstart_l + { 0x3A, 0x03 }, // blhstop_h (850) + { 0x3B, 0x52 }, // blhstop_l + + // ############################################################ + // ########### Don't change setting value stop ################ + // ############################################################ + + // MIPI disable + { 0x03, 0x05 }, // bank F + { 0x04, 0x30 }, // mipi_control_0 + + // 320x240_DVP_8bit + // Window setting + { 0x03, 0x00 }, // bank_A + + // 320 + { 0x0C, 0x00 }, // windowx1_h + { 0x0D, 0x01 }, // windowx1_l + { 0x10, 0x01 }, // windowx2_h + { 0x11, 0x41 }, // windowx2_l + // 240 + { 0x0E, 0x00 }, // windowy1_h + { 0x0F, 0x7A }, // windowy1_l + { 0x12, 0x01 }, // windowy2_h + { 0x13, 0x6A }, // windowy2_l + // vsync setting + // 240 + { 0x74, 0x00 }, // vsyncstartrow0_h + { 0x75, 0x83 }, // vsyncstartrow0_l + { 0x76, 0x01 }, // vsyncstoprow0_h + { 0x77, 0x73 }, // vsyncstoprow0_l + // Format fifo setting + { 0x97, 0x02 }, // rd_cnt_init_h + { 0x98, 0x50 }, // rd_cnt_init_l + // 320 + { 0x99, 0x00 }, // rd_x_start0_h + { 0x9A, 0x30 }, // rd_x_start0_l + { 0x9B, 0x02 }, // rd_x_stop0_h + { 0x9C, 0xB0 }, // rd_x_stop0_l + // 240 + { 0x9D, 0x00 }, // rd_y_start0_h + { 0x9E, 0x83 }, // rd_y_start0_l + { 0x9F, 0x01 }, // rd_y_stop0_h + { 0xA0, 0x73 }, // rd_y_stop0_l + + { 0xAC, 0x01 }, // rd_bit_sel +}; + +static const struct Register pgd030k_regs_qvga_seq[] = { + // 320x240_DVP_8bit + // Window setting + { 0x03, 0x00 }, // bank_A + + // 320 + { 0x0C, 0x00 }, // windowx1_h + { 0x0D, 0x01 }, // windowx1_l + { 0x10, 0x01 }, // windowx2_h + { 0x11, 0x41 }, // windowx2_l + // 240 + { 0x0E, 0x00 }, // windowy1_h + { 0x0F, 0x7A }, // windowy1_l + { 0x12, 0x01 }, // windowy2_h + { 0x13, 0x6A }, // windowy2_l + // vsync setting + // 240 + { 0x74, 0x00 }, // vsyncstartrow0_h + { 0x75, 0x83 }, // vsyncstartrow0_l + { 0x76, 0x01 }, // vsyncstoprow0_h + { 0x77, 0x73 }, // vsyncstoprow0_l + // Format fifo setting + { 0x97, 0x02 }, // rd_cnt_init_h + { 0x98, 0x50 }, // rd_cnt_init_l + // 640 + { 0x99, 0x00 }, // rd_x_start0_h + { 0x9A, 0x30 }, // rd_x_start0_l + { 0x9B, 0x02 }, // rd_x_stop0_h + { 0x9C, 0xB0 }, // rd_x_stop0_l + // 240 + { 0x9D, 0x00 }, // rd_y_start0_h + { 0x9E, 0x83 }, // rd_y_start0_l + { 0x9F, 0x01 }, // rd_y_stop0_h + { 0xA0, 0x73 }, // rd_y_stop0_l + + { 0xAC, 0x01 }, // rd_bit_sel +}; + +static int pgd030k_read_reg(sensor_t* sensor, uint8_t reg_addr) +{ + printk("%s sensor %p\r\n", __func__, sensor); + return 0; +} + +static int pgd030k_write_reg(sensor_t* sensor, uint8_t reg_addr, uint16_t reg_data) +{ + printk("%s sensor %p\r\n", __func__, sensor); + return 0; +} + +static int pgd030k_set_pixformat(sensor_t* sensor, pixformat_t pixformat) +{ + if (PIXFORMAT_GRAYSCALE != pixformat) { + mp_raise_msg(&mp_type_ValueError, "PGD030 only support GRAYSCALE"); + } + + return 0; +} + +static int pgd030k_set_framesize(sensor_t* sensor, framesize_t framesize) +{ + int regs_cnt = 0; + struct Register* regs = (void*)0; + + uint16_t width = resolution[framesize][0]; + uint16_t height = resolution[framesize][1]; + + // if ((640 < width) || (480 < height)) { + // mp_raise_msg(&mp_type_ValueError, "PGD030 max support 640x480"); + // } + + if (FRAMESIZE_QVGA != framesize) { + mp_raise_msg(&mp_type_ValueError, "PGD030 only support QVGA"); + // mp_printf(&mp_plat_print, "PGD030 not support framesize(%dx%d), use QVGA\n", width, height); + } + + regs = &pgd030k_regs_qvga_seq; + regs_cnt = sizeof(pgd030k_regs_qvga_seq) / sizeof(struct Register); + + for (int i = 0; i < regs_cnt; i++) { + if (0xFFFF == regs[i].address) { + mp_hal_delay_ms(regs[i].value); + continue; + } + cambus_writeb(sensor->slv_addr, regs[i].address & 0xFF, regs[i].value); + } + + /* delay n ms */ + mp_hal_delay_ms(100); + dvp_set_image_size(width, height); + + return 0; +} + +static int pgd030k_set_framerate(sensor_t* sensor, framerate_t framerate) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_contrast(sensor_t* sensor, int level) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_brightness(sensor_t* sensor, int level) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_saturation(sensor_t* sensor, int level) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_gainceiling(sensor_t* sensor, gainceiling_t gainceiling) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_quality(sensor_t* sensor, int qs) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_colorbar(sensor_t* sensor, int enable) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_auto_gain(sensor_t* sensor, int enable, float gain_db, float gain_db_ceiling) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_get_gain_db(sensor_t* sensor, float* gain_db) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_auto_exposure(sensor_t* sensor, int enable, int exposure_us) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_get_exposure_us(sensor_t* sensor, int* exposure_us) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_auto_whitebal(sensor_t* sensor, int enable, float r_gain_db, float g_gain_db, float b_gain_db) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_get_rgb_gain_db(sensor_t* sensor, float* r_gain_db, float* g_gain_db, float* b_gain_db) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_hmirror(sensor_t* sensor, int enable) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_set_vflip(sensor_t* sensor, int enable) +{ + mp_printf(&mp_plat_print, "%s %d\n", __func__, __LINE__); + return 0; +} + +static int pgd030k_reset(sensor_t* sensor) +{ + for (int i = 0; i < (sizeof(pgd030k_regs_init_seq) / sizeof(struct Register)); i++) { + if (0xFFFF == pgd030k_regs_init_seq[i].address) { + mp_hal_delay_ms(pgd030k_regs_init_seq[i].value); + continue; + } + cambus_writeb(sensor->slv_addr, pgd030k_regs_init_seq[i].address & 0xFF, pgd030k_regs_init_seq[i].value); + } + + return 0; +} + +int pgd030k_init(sensor_t* sensor) +{ + // Initialize sensor structure. + sensor->gs_bpp = 2; + sensor->reset = pgd030k_reset; + sensor->read_reg = pgd030k_read_reg; + sensor->write_reg = pgd030k_write_reg; + sensor->set_pixformat = pgd030k_set_pixformat; + sensor->set_framesize = pgd030k_set_framesize; + sensor->set_framerate = pgd030k_set_framerate; + sensor->set_contrast = pgd030k_set_contrast; + sensor->set_brightness = pgd030k_set_brightness; + sensor->set_saturation = pgd030k_set_saturation; + sensor->set_gainceiling = pgd030k_set_gainceiling; + sensor->set_quality = pgd030k_set_quality; + sensor->set_colorbar = pgd030k_set_colorbar; + sensor->set_auto_gain = pgd030k_set_auto_gain; + sensor->get_gain_db = pgd030k_get_gain_db; + sensor->set_auto_exposure = pgd030k_set_auto_exposure; + sensor->get_exposure_us = pgd030k_get_exposure_us; + sensor->set_auto_whitebal = pgd030k_set_auto_whitebal; + sensor->get_rgb_gain_db = pgd030k_get_rgb_gain_db; + sensor->set_hmirror = pgd030k_set_hmirror; + sensor->set_vflip = pgd030k_set_vflip; + + return 0; +} diff --git a/components/micropython/port/src/omv/sensor.c b/components/micropython/port/src/omv/sensor.c index 51c3ba23..e90be8a5 100644 --- a/components/micropython/port/src/omv/sensor.c +++ b/components/micropython/port/src/omv/sensor.c @@ -23,6 +23,7 @@ #include "gc0328.h" #include "gc2145.h" #include "mt9d111.h" +#include "pgd030k.h" #include "ov7740.h" #include "mphalport.h" #include "ov3660.h" @@ -564,6 +565,32 @@ int sensro_mt_detect(sensor_t *sensor, bool pwnd) } return 0; } + +int sensro_pgd_detect(sensor_t *sensor, bool pwnd) +{ + if (pwnd) + DCMI_PWDN_LOW(); + DCMI_RESET_LOW(); + mp_hal_delay_ms(10); + DCMI_RESET_HIGH(); + mp_hal_delay_ms(10); + + uint16_t id = cambus_scan_pgd030k(); + + if (0 == id) { + return -3; + } else { + sensor->slv_addr = PGD030K_I2C_ADDR; + sensor->chip_id = id; + sensor->snapshot = sensor_snapshot; + sensor->flush = sensor_flush; + + pgd030k_init(sensor); + } + + return 0; +} + int sensor_init_dvp(mp_int_t freq, bool default_freq) { int init_ret = 0; @@ -625,6 +652,12 @@ int sensor_init_dvp(mp_int_t freq, bool default_freq) mp_printf(&mp_plat_print, "[CANMV]: find mt sensor\r\n"); cambus_set_writeb_delay(2); } + else if ( (limit == false || sensor.choice_dev == 4) && 0 == sensro_pgd_detect(&sensor, true)) + { + //find pgd sensor + mp_printf(&mp_plat_print, "[CANMV]: find pgd sensor\r\n"); + cambus_set_writeb_delay(1); + } else { mp_printf(&mp_plat_print, "[CANMV]: no sensor\r\n"); diff --git a/projects/canmv_k210_zero/.gitignore b/projects/canmv_k210_zero/.gitignore new file mode 100644 index 00000000..dd910fe5 --- /dev/null +++ b/projects/canmv_k210_zero/.gitignore @@ -0,0 +1,6 @@ + + +build +.config.mk +.flash.conf.json + diff --git a/projects/canmv_k210_zero/CMakeLists.txt b/projects/canmv_k210_zero/CMakeLists.txt new file mode 100644 index 00000000..d38b200a --- /dev/null +++ b/projects/canmv_k210_zero/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.9) + + +# Get SDK path +if(NOT SDK_PATH) + get_filename_component(SDK_PATH ../../ ABSOLUTE) + if(EXISTS $ENV{MY_SDK_PATH}) + set(SDK_PATH $ENV{MY_SDK_PATH}) + endif() +endif() + +# Check SDK Path +if(NOT EXISTS ${SDK_PATH}) + message(FATAL_ERROR "SDK path Error, Please set SDK_PATH or MY_SDK_PATH variable") +endif() + +# Get Toolchain path +if(NOT CONFIG_TOOLCHAIN_PATH) + if(EXISTS $ENV{MY_TOOLCHAIN_PATH}) + set(CONFIG_TOOLCHAIN_PATH $ENV{MY_TOOLCHAIN_PATH}) + endif() +endif() + +# Call compile +include(${SDK_PATH}/tools/cmake/compile.cmake) + + +# Project Name +project(canmv) + + + diff --git a/projects/canmv_k210_zero/builtin_py/_boot.py b/projects/canmv_k210_zero/builtin_py/_boot.py new file mode 100644 index 00000000..ea2a928e --- /dev/null +++ b/projects/canmv_k210_zero/builtin_py/_boot.py @@ -0,0 +1,178 @@ +import os, sys, time + +sys.path.append('') +sys.path.append('.') + +# chdir to "/sd" or "/flash" +devices = os.listdir("/") +if "sd" in devices: + os.chdir("/sd") + sys.path.append('/sd') +else: + os.chdir("/flash") +sys.path.append('/flash') +del devices + +print("[CanMV] init end") # for IDE +for i in range(200): + time.sleep_ms(1) # wait for key interrupt(for canmv ide) +del i + +# check IDE mode +ide_mode_conf = "/flash/ide_mode.conf" +ide = True +try: + f = open(ide_mode_conf) + f.close() + del f +except Exception: + ide = False + +if ide: + os.remove(ide_mode_conf) + from machine import UART + import lcd + lcd.init(color=lcd.PINK) + repl = UART.repl_uart() + repl.init(1500000, 8, None, 1, read_buf_len=2048, ide=True, from_ide=False) + sys.exit() +del ide, ide_mode_conf + +# detect boot.py +main_py = ''' +try: + import gc, lcd, image + gc.collect() + lcd.init() + loading = image.Image(size=(lcd.width(), lcd.height())) + loading.draw_rectangle((0, 0, lcd.width(), lcd.height()), fill=True, color=(0, 81, 137)) + info = "Welcome to CanMV" + loading.draw_string(int(lcd.width()//2 - len(info) * 5), (lcd.height())//4, info, color=(255, 255, 255), scale=2, mono_space=0) + v = sys.implementation.version + vers = 'V{}.{}.{} : canaan-creative.com'.format(v[0],v[1],v[2]) + loading.draw_string(int(lcd.width()//2 - len(info) * 6), (lcd.height())//3 + 20, vers, color=(255, 255, 255), scale=1, mono_space=1) + lcd.display(loading) + del loading, v, info, vers + gc.collect() +finally: + gc.collect() +''' + +flash_ls = os.listdir() +if not "main.py" in flash_ls: + f = open("main.py", "wb") + f.write(main_py) + f.close() + del f +del main_py + +flash_ls = os.listdir("/flash") +try: + sd_ls = os.listdir("/sd") +except Exception: + sd_ls = [] +if "cover.boot.py" in sd_ls: + code0 = "" + if "boot.py" in flash_ls: + with open("/flash/boot.py") as f: + code0 = f.read() + with open("/sd/cover.boot.py") as f: + code=f.read() + if code0 != code: + with open("/flash/boot.py", "w") as f: + f.write(code) + import machine + machine.reset() + +if "cover.main.py" in sd_ls: + code0 = "" + if "main.py" in flash_ls: + with open("/flash/main.py") as f: + code0 = f.read() + with open("/sd/cover.main.py") as f: + code = f.read() + if code0 != code: + with open("/flash/main.py", "w") as f: + f.write(code) + import machine + machine.reset() + +try: + del flash_ls + del sd_ls + del code0 + del code +except Exception: + pass + +banner = ''' + _____ __ ____ __ + / ____| | \/ \ \ / / +| | __ _ _ __ | \ / |\ \ / / +| | / _` | '_ \| |\/| | \ \/ / +| |___| (_| | | | | | | | \ / + \_____\__,_|_| |_|_| |_| \/ + +Official Site : https://canaan-creative.com +''' +print(banner) +del banner + +import json + +config = { +"type": "canmv_k210_zero", +"lcd": { + "rst" : 39, + "dcx" : 37, + "ss" : 38, + "clk" : 36, + "height": 240, + "width": 320, + "offset_x1": 0, + "offset_y1": 0, + "offset_x2": 0, + "offset_y2": 0, + "dir": 96 +}, +"freq_cpu": 416000000, +"freq_pll1": 400000000, +"kpu_div": 1, +"sensor": { + "cmos_pclk":47, + "cmos_xclk":46, + "cmos_href":44, + "cmos_pwdn":45, + "cmos_vsync":42, + "cmos_rst":43, + "reg_width":16, + "i2c_num":2, + "pin_clk":41, + "pin_sda":40 +}, +"sdcard":{ + "sclk":34, + "mosi":33, + "miso":35, + "cs":32, + "cs_gpio":29 +}, +"board_info": { + "BOOT_KEY": 16, +} +} + +cfg = json.dumps(config) +print(cfg) + +try: + with open('/flash/config.json', 'rb') as f: + tmp = json.loads(f.read()) + # print(tmp) + if tmp["type"] != config["type"]: + raise Exception('config.json no exist') +except Exception as e: + with open('/flash/config.json', "w") as f: + f.write(cfg) + import machine + machine.reset() diff --git a/projects/canmv_k210_zero/builtin_py/board.py b/projects/canmv_k210_zero/builtin_py/board.py new file mode 100644 index 00000000..3b723f95 --- /dev/null +++ b/projects/canmv_k210_zero/builtin_py/board.py @@ -0,0 +1,18 @@ + +class board_info: + def set(key, value=None): + return setattr(__class__, key, value) + def all(): + return dir(__class__) + def get(): + return getattr(__class__, key) + def load(__map__={}): + for k, v in __map__.items(): + __class__.set(k, v) + +from maix import config +tmp = config.get_value('board_info', None) +if tmp != None: + board_info.load(tmp) +else: + print('[Warning] Not loaded from /flash/config.json to board_info.') diff --git a/projects/canmv_k210_zero/builtin_py/fpioa_manager.py b/projects/canmv_k210_zero/builtin_py/fpioa_manager.py new file mode 100644 index 00000000..78f59ca1 --- /dev/null +++ b/projects/canmv_k210_zero/builtin_py/fpioa_manager.py @@ -0,0 +1,36 @@ +from maix import FPIOA + +class fm: + fpioa = FPIOA() + + def help(): + __class__.fpioa.help() + + def get_pin_by_function(function): + return __class__.fpioa.get_Pin_num(function) + + def register(pin, function, force=True): + pin_used = __class__.get_pin_by_function(function) + if pin_used == pin: + return + if None != pin_used: + info = "[Warning] function is used by %s(pin:%d)" % ( + fm.str_function(function), pin_used) + if force == False: + raise Exception(info) + else: + print(info) + __class__.fpioa.set_function(pin, function) + + def unregister(pin): + __class__.fpioa.set_function(pin, fm.fpioa.RESV0) + + def str_function(function): + if fm.fpioa.GPIOHS0 <= function and function <= fm.fpioa.GPIO7: + if fm.fpioa.GPIO0 <= function: + return 'fm.fpioa.GPIO%d' % (function - fm.fpioa.GPIO0) + return 'fm.fpioa.GPIOHS%d' % (function - fm.fpioa.GPIOHS0) + return 'unknown' + + def get_gpio_used(): + return [(__class__.str_function(f), __class__.get_pin_by_function(f)) for f in range(fm.fpioa.GPIOHS0, fm.fpioa.GPIO7 + 1)] diff --git a/projects/canmv_k210_zero/builtin_py/ide_debug.py b/projects/canmv_k210_zero/builtin_py/ide_debug.py new file mode 100644 index 00000000..76bb3544 --- /dev/null +++ b/projects/canmv_k210_zero/builtin_py/ide_debug.py @@ -0,0 +1,12 @@ +import gc, lcd, json +try: + with open('/flash/config.json', "rb") as f: + cfg = json.loads(f.read()) + if cfg["type"]=="amigo_ips": + lcd.init() + del cfg + gc.collect() +except Exception as e: + pass +finally: + gc.collect() \ No newline at end of file diff --git a/projects/canmv_k210_zero/compile/compile_flags.cmake b/projects/canmv_k210_zero/compile/compile_flags.cmake new file mode 100644 index 00000000..32bc9ba6 --- /dev/null +++ b/projects/canmv_k210_zero/compile/compile_flags.cmake @@ -0,0 +1,114 @@ + +########## set C flags ######### +set(CMAKE_C_FLAGS -mcmodel=medany + -mabi=lp64f + -march=rv64imafc + -fno-common + -ffunction-sections + -fdata-sections + -fstrict-volatile-bitfields + -fno-zero-initialized-in-bss + -ffast-math + -fno-math-errno + -fsingle-precision-constant + -ffloat-store + -std=gnu11 + -Os + -Wall + -Werror=all + -Wno-error=unused-function + -Wno-error=unused-but-set-variable + -Wno-error=unused-variable + -Wno-error=deprecated-declarations + -Wno-error=maybe-uninitialized + -Wextra + -Werror=frame-larger-than=32768 + -Wno-unused-parameter + -Wno-unused-function + -Wno-implicit-fallthrough + -Wno-sign-compare + -Wno-error=missing-braces + -Wno-old-style-declaration + -Wno-error=pointer-sign + -Wno-pointer-to-int-cast + -Wno-strict-aliasing + -Wno-override-init + -Wno-error=format= + -Wno-error=format-truncation= + -Wno-error=restrict + -Wno-error=sequence-point + -Wno-int-to-pointer-cast + ) +################################ + + +###### set CXX(cpp) flags ###### +set(CMAKE_CXX_FLAGS -mcmodel=medany + -mabi=lp64f + -march=rv64imafc + -fno-common + -ffunction-sections + -fdata-sections + -fstrict-volatile-bitfields + -fno-zero-initialized-in-bss + -Os + -std=gnu++17 + -Wall + -Wno-error=unused-function + -Wno-error=unused-but-set-variable + -Wno-error=unused-variable + -Wno-error=deprecated-declarations + -Wno-error=maybe-uninitialized + -Wextra + -Werror=frame-larger-than=32768 + -Wno-unused-parameter + -Wno-unused-function + -Wno-implicit-fallthrough + -Wno-sign-compare + -Wno-error=missing-braces + -Wno-error=pointer-sign + -Wno-strict-aliasing + -Wno-error=format= + -Wno-error=format-truncation= + -Wno-error=restrict + -Wno-error=sequence-point + -Wno-int-to-pointer-cast + ) +################################ + +set(LINK_FLAGS ${LINK_FLAGS} + -static + -Wl,-static + -nostartfiles + -Wl,--gc-sections + -Wl,-EL + -T ${PROJECT_SOURCE_DIR}/compile/kendryte.ld + -Wl,--start-group + -Wl,--whole-archive + kendryte_sdk/libkendryte_sdk.a main/libmain.a + -Wl,--no-whole-archive + -Wl,--end-group + ) +set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} + ${LINK_FLAGS} + ) +set(CMAKE_CXX_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} + #${LINK_FLAGS} + ) +# set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} +# ${LINK_FLAGS} +# ) +# set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} +# ${LINK_FLAGS} +# ) +# set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS} +# ${LINK_FLAGS} +# ) + + +# Convert list to string +string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}") +string(REPLACE ";" " " CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}") +string(REPLACE ";" " " CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}") diff --git a/projects/canmv_k210_zero/compile/kendryte.ld b/projects/canmv_k210_zero/compile/kendryte.ld new file mode 100644 index 00000000..0636f9a7 --- /dev/null +++ b/projects/canmv_k210_zero/compile/kendryte.ld @@ -0,0 +1,262 @@ +/* + * The MEMORY command describes the location and size of blocks of memory + * in the target. You can use it to describe which memory regions may be + * used by the linker, and which memory regions it must avoid. + */ +MEMORY +{ + /* + * Memory with CPU cache. + *6M CPU SRAM + */ + ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = (6 * 1024 * 1024) + /* + * Memory without CPU cache + * 6M CPU SRAM + */ + ram_nocache (wxa!ri) : ORIGIN = 0x40000000, LENGTH = (6 * 1024 * 1024) +} + +PROVIDE( _rom_start = ORIGIN(rom) ); +PROVIDE( _rom_end = ORIGIN(rom) + LENGTH(rom) ); +PROVIDE( _ram_start = ORIGIN(ram) ); +PROVIDE( _ram_end = ORIGIN(ram) + LENGTH(ram) ); +PROVIDE( _io_start = 0x40000000 ); +PROVIDE( _io_end = _io_start + LENGTH(ram) ); +PROVIDE( _stack_size = 1 << 15 ); + + +/* + * The OUTPUT_ARCH command specifies the machine architecture where the + * argument is one of the names used in the Kendryte library. + */ +OUTPUT_ARCH( "riscv" ) + +/* + * The ENTRY command specifies the entry point (ie. first instruction to + * execute). The symbol _start is defined in crt0.S + */ +ENTRY(_start) + +/* + * The GROUP command is special since the listed archives will be + * searched repeatedly until there are no new undefined references. We + * need this since -lc depends on -lgloss and -lgloss depends on -lc. I + * thought gcc would automatically include -lgcc when needed, but + * in this file includes it explicitly here and I was seeing link errors + * without it. + */ +/* GROUP( -lc -lgloss -lgcc ) */ + +/* + * The linker only pays attention to the PHDRS command when generating + * an ELF output file. In other cases, the linker will simply ignore PHDRS. + */ +PHDRS +{ + ram_ro PT_LOAD; + ram_init PT_LOAD; + ram PT_NULL; +} + +/* + * This is where we specify how the input sections map to output + * sections. + */ +SECTIONS +{ + /* Program code segment, also known as a text segment */ + .text : + { + PROVIDE( _text = ABSOLUTE(.) ); + /* Initialization code segment */ + KEEP( *(.text.start) ) + KEEP( *(.text.systick) ) + *(.text.unlikely .text.unlikely.*) + *(.text.startup .text.startup.*) + /* Normal code segment */ + *(.text .text.*) + *(.gnu.linkonce.t.*) + + . = ALIGN(8); + PROVIDE( _etext = ABSOLUTE(.) ); + } >ram AT>ram :ram_ro + + /* Read-only data segment */ + .rodata : + { + *(.rdata) + *(.rodata .rodata.*) + *(.gnu.linkonce.r.*) + } >ram AT>ram :ram_ro + + . = ALIGN(8); + + /* Exception handling */ + .eh_frame : + { + KEEP (*(.eh_frame)) *(.eh_frame.*) + . = ALIGN(8); + } >ram AT>ram :ram_ro + .gnu_extab : { *(.gnu_extab) } >ram AT>ram :ram_ro + .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } >ram AT>ram :ram_ro + .exception_ranges : { *(.exception_ranges .exception_ranges*) } >ram AT>ram :ram_ro + + /* Init array and fini array */ + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >ram AT>ram :ram_ro + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } >ram AT>ram :ram_ro + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >ram AT>ram :ram_ro + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } >ram AT>ram :ram_ro + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } >ram AT>ram :ram_ro + + . = ALIGN(8); + + .lalign : + { + . = ALIGN(8); + PROVIDE( _data_lma = . ); + } >ram AT>ram :ram_ro + + .dalign : + { + . = ALIGN(8); + PROVIDE( _data = . ); + } >ram AT>ram :ram_init + + . = ALIGN(8); + + /* .data, .sdata and .srodata segment */ + .data : + { + /* Writable data segment (.data segment) */ + *(.data .data.*) + *(.gnu.linkonce.d.*) + /* Have _gp point to middle of sdata/sbss to maximize displacement range */ + . = ALIGN(8); + PROVIDE( __global_pointer$ = ABSOLUTE(.) + 0x800); + /* Writable small data segment (.sdata segment) */ + *(.sdata .sdata.*) + *(.gnu.linkonce.s.*) + /* Read-only small data segment (.srodata segment) */ + . = ALIGN(8); + *(.srodata.cst16) + *(.srodata.cst8) + *(.srodata.cst4) + *(.srodata.cst2) + *(.srodata .srodata.*) + /* Align _edata to cache line size */ + . = ALIGN(64); + PROVIDE( _edata = ABSOLUTE(.) ); + } >ram AT>ram :ram_init + + /* .bss and .sbss segment */ + .bss : + { + PROVIDE( _bss = ABSOLUTE(.) ); + /* Writable uninitialized small data segment (.sbss segment)*/ + *(.sbss .sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + /* Uninitialized writeable data section (.bss segment)*/ + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + + . = ALIGN(8); + PROVIDE( _ebss = ABSOLUTE(.) ); + } >ram AT>ram :ram + + PROVIDE( _tls_data = ABSOLUTE(.) ); + /* + * Thread Local Storage (TLS) are per-thread global variables. + * Compilers such as GCC provide a __thread keyword to mark global + * variables as per-thread. Support is required in the program loader + * and thread creator. + */ + + /* Thread-local data segment, .tdata (initialized tls). */ + .tdata : + { + KEEP( *(.tdata.begin) ) + *(.tdata .tdata.*) + *(.gnu.linkonce.td.*) + KEEP( *(.tdata.end) ) + } >ram AT>ram :ram + + /* Thread-local bss segment, .tbss (zero-initialized tls). */ + .tbss : + { + *(.tbss .tbss.*) + *(.gnu.linkonce.tb.*) + KEEP( *(.tbss.end) ) + } >ram AT>ram :ram + + /* + * End of uninitalized data segement + * + * Actually the stack needs 16B alignment, and it won't hurt to also slightly + * increase the alignment to 32 or even 64 (cache line size). + * + * Align _heap_start to cache line size + */ + . = ALIGN(64); + PROVIDE( _end = ABSOLUTE(.) ); + /* Leave 2 holes for stack & TLS, the size can set in kconfig */ + PROVIDE( _heap_start = ABSOLUTE(.) + _stack_size * 2 ); + PROVIDE( _tp0 = (_end + 63) & (-64) ); + PROVIDE( _tp1 = _tp0 + _stack_size ); + PROVIDE( _sp0 = _tp0 + _stack_size ); + PROVIDE( _sp1 = _tp1 + _stack_size ); + + /* Heap end is at the end of memory, the memory size can set in kconfig */ + PROVIDE( _heap_end = _ram_end ); +} + diff --git a/projects/canmv_k210_zero/compile/priority.conf b/projects/canmv_k210_zero/compile/priority.conf new file mode 100644 index 00000000..43e5a3c0 --- /dev/null +++ b/projects/canmv_k210_zero/compile/priority.conf @@ -0,0 +1,11 @@ +# The upper components have higher priority + +utils +kendryte_sdk +drivers +spiffs +boards +micropython +main + + diff --git a/projects/canmv_k210_zero/config_defaults.mk b/projects/canmv_k210_zero/config_defaults.mk new file mode 100644 index 00000000..0745dc6b --- /dev/null +++ b/projects/canmv_k210_zero/config_defaults.mk @@ -0,0 +1,174 @@ + +# +# Toolchain configuration +# +CONFIG_TOOLCHAIN_PATH="/opt/kendryte-toolchain/bin" +CONFIG_TOOLCHAIN_PREFIX="riscv64-unknown-elf-" +# end of Toolchain configuration + +# +# Components configuration +# + +# +# Board config +# +CONFIG_BOARD_MAIX=y +# CONFIG_BOARD_M5STICK is not set +# CONFIG_BOARD_TWATCH is not set +CONFIG_LCD_DEFAULT_WIDTH=320 +CONFIG_LCD_DEFAULT_HEIGHT=240 +CONFIG_LCD_DEFAULT_FREQ=15000000 +CONFIG_SENSOR_FREQ=24000000 +CONFIG_CPU_DEFAULT_FREQ=400000000 +# end of Board config + +CONFIG_COMPONENT_DRIVERS_ENABLE=y + +# +# Drivers configuration +# + +# +# SD card +# +CONFIG_SPI_SD_CARD_FORCE_HIGH_SPEED=y +# end of SD card + +# +# WS2812 +# +CONFIG_WS2812_ENABLE=y +# end of WS2812 + +# +# HTPA thermal sensor +# +# CONFIG_HTPA_ENABLE is not set +# end of HTPA thermal sensor + +# +# AMG88XX thermal sensor +# +# CONFIG_AMG88XX_ENABLE is not set +# end of AMG88XX thermal sensor +# end of Drivers configuration + +CONFIG_COMPONENT_KENDRYTE_SDK_ENABLE=y + +# +# Kendryte SDK configurations +# +CONFIG_SDK_LOG_LEVEL=5 +CONFIG_SDK_LOCK_NUM=64 +CONFIG_FREERTOS_ENABLE=y + +# +# FreeRTOS configurations +# +CONFIG_STATIC_TASK_CLEAN_UP_ENABLE=y +# CONFIG_FREERTOS_MALLOC_CUSTOM is not set +CONFIG_FREEROTS_MINIMUM_STACK_SIZE=2048 +# end of FreeRTOS configurations + +# CONFIG_MIC_ARRAY_ENABLE is not set +# end of Kendryte SDK configurations + +CONFIG_COMPONENT_MICROPYTHON_ENABLE=y + +# +# Micropython configurations +# +CONFIG_MAIXPY_GC_HEAP_SIZE=0xBB9B0 + +# +# Modules configurations +# +CONFIG_CANMV_IDE_SUPPORT=y +CONFIG_MAIXPY_THREAD_ENABLE=y +# CONFIG_MAIXPY_NES_ENABLE is not set +# CONFIG_MAIXPY_VIDEO_ENABLE is not set +# CONFIG_MAIXPY_TOUCH_SCREEN_ENABLE is not set +# CONFIG_MAIXPY_OMV_MINIMUM is not set +# CONFIG_MAIXPY_OMV_CONV_YUV_FAST is not set +CONFIG_MAIXPY_OMV_DOUBLE_BUFF=y +# CONFIG_MAIXPY_MIC_ARRAY_ENABLE is not set +# CONFIG_MAIXPY_LVGL_ENABLE is not set +# CONFIG_MAIXPY_LODEPNG_ENABLE is not set +CONFIG_MAIXPY_WS2812_ENABLE=y +# CONFIG_MAIXPY_HTPA_ENABLE is not set +# CONFIG_MAIXPY_AMG88XX_ENABLE is not set +# CONFIG_MICROPYTHON_ULAB_ENALBE is not set +# CONFIG_MAIXPY_SPEECH_RECOGNIZER_ENABLE is not set +# CONFIG_MICROPY_SSL_ENABLE is not set +CONFIG_MAIXPY_WIZNET5K_ENABLE=y +# CONFIG_MICROPY_LWIP_ENABLE is not set +# CONFIG_NETWORK_ESP32XX_HOSTED is not set +# end of Modules configurations + +# +# Builtin py modules configurations +# +# CONFIG_MAIXPY_BUILTIN_PY_PYE is not set +CONFIG_MAIXPY_BUILTIN_PY_BOARD=y +CONFIG_MAIXPY_BUILTIN_PY_FPIOA_MANAGER=y +# end of Builtin py modules configurations + +# +# Debug configurations +# +# CONFIG_MAIXPY_K210_UARTHS_DEBUG is not set +# end of Debug configurations + +CONFIG_BUILTIN_PY_DIR="${PROJECT_PATH}/builtin_py" +# end of Micropython configurations + +# +# Others +# +# CONFIG_COMPONENT_LIB_SIPEED_KPU_SRC_ENABLE is not set +# end of Others + +CONFIG_COMPONENT_SPIFFS_ENABLE=y + +# +# SPIFFS Configuration +# + +# +# SPIFFS Cache Configuration +# +CONFIG_SPIFFS_CACHE=y +CONFIG_SPIFFS_CACHE_WR=y +# CONFIG_SPIFFS_CACHE_STATS is not set +# end of SPIFFS Cache Configuration + +CONFIG_SPIFFS_SIZE=0x300000 +CONFIG_SPIFFS_START_ADDR=0xD00000 +CONFIG_SPIFFS_EREASE_SIZE=0x1000 +CONFIG_SPIFFS_LOGICAL_BLOCK_SIZE=0x20000 +CONFIG_SPIFFS_LOGICAL_PAGE_SIZE=0x1000 +CONFIG_SPIFFS_OBJ_NAME_LEN=128 +CONFIG_SPIFFS_USE_MAGIC=y +CONFIG_SPIFFS_USE_MAGIC_LENGTH=y +CONFIG_SPIFFS_META_LENGTH=0 + +# +# Debug Configuration +# +# CONFIG_SPIFFS_DBG is not set +# CONFIG_SPIFFS_API_DBG is not set +# CONFIG_SPIFFS_GC_DBG is not set +# CONFIG_SPIFFS_CACHE_DBG is not set +# CONFIG_SPIFFS_CHECK_DBG is not set +# end of Debug Configuration +# end of SPIFFS Configuration + +CONFIG_COMPONENT_UTILS_ENABLE=y +# end of Components configuration + +# +# Others +# +# CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE is not set +# end of Others diff --git a/projects/canmv_k210_zero/config_lite.mk b/projects/canmv_k210_zero/config_lite.mk new file mode 100644 index 00000000..0745dc6b --- /dev/null +++ b/projects/canmv_k210_zero/config_lite.mk @@ -0,0 +1,174 @@ + +# +# Toolchain configuration +# +CONFIG_TOOLCHAIN_PATH="/opt/kendryte-toolchain/bin" +CONFIG_TOOLCHAIN_PREFIX="riscv64-unknown-elf-" +# end of Toolchain configuration + +# +# Components configuration +# + +# +# Board config +# +CONFIG_BOARD_MAIX=y +# CONFIG_BOARD_M5STICK is not set +# CONFIG_BOARD_TWATCH is not set +CONFIG_LCD_DEFAULT_WIDTH=320 +CONFIG_LCD_DEFAULT_HEIGHT=240 +CONFIG_LCD_DEFAULT_FREQ=15000000 +CONFIG_SENSOR_FREQ=24000000 +CONFIG_CPU_DEFAULT_FREQ=400000000 +# end of Board config + +CONFIG_COMPONENT_DRIVERS_ENABLE=y + +# +# Drivers configuration +# + +# +# SD card +# +CONFIG_SPI_SD_CARD_FORCE_HIGH_SPEED=y +# end of SD card + +# +# WS2812 +# +CONFIG_WS2812_ENABLE=y +# end of WS2812 + +# +# HTPA thermal sensor +# +# CONFIG_HTPA_ENABLE is not set +# end of HTPA thermal sensor + +# +# AMG88XX thermal sensor +# +# CONFIG_AMG88XX_ENABLE is not set +# end of AMG88XX thermal sensor +# end of Drivers configuration + +CONFIG_COMPONENT_KENDRYTE_SDK_ENABLE=y + +# +# Kendryte SDK configurations +# +CONFIG_SDK_LOG_LEVEL=5 +CONFIG_SDK_LOCK_NUM=64 +CONFIG_FREERTOS_ENABLE=y + +# +# FreeRTOS configurations +# +CONFIG_STATIC_TASK_CLEAN_UP_ENABLE=y +# CONFIG_FREERTOS_MALLOC_CUSTOM is not set +CONFIG_FREEROTS_MINIMUM_STACK_SIZE=2048 +# end of FreeRTOS configurations + +# CONFIG_MIC_ARRAY_ENABLE is not set +# end of Kendryte SDK configurations + +CONFIG_COMPONENT_MICROPYTHON_ENABLE=y + +# +# Micropython configurations +# +CONFIG_MAIXPY_GC_HEAP_SIZE=0xBB9B0 + +# +# Modules configurations +# +CONFIG_CANMV_IDE_SUPPORT=y +CONFIG_MAIXPY_THREAD_ENABLE=y +# CONFIG_MAIXPY_NES_ENABLE is not set +# CONFIG_MAIXPY_VIDEO_ENABLE is not set +# CONFIG_MAIXPY_TOUCH_SCREEN_ENABLE is not set +# CONFIG_MAIXPY_OMV_MINIMUM is not set +# CONFIG_MAIXPY_OMV_CONV_YUV_FAST is not set +CONFIG_MAIXPY_OMV_DOUBLE_BUFF=y +# CONFIG_MAIXPY_MIC_ARRAY_ENABLE is not set +# CONFIG_MAIXPY_LVGL_ENABLE is not set +# CONFIG_MAIXPY_LODEPNG_ENABLE is not set +CONFIG_MAIXPY_WS2812_ENABLE=y +# CONFIG_MAIXPY_HTPA_ENABLE is not set +# CONFIG_MAIXPY_AMG88XX_ENABLE is not set +# CONFIG_MICROPYTHON_ULAB_ENALBE is not set +# CONFIG_MAIXPY_SPEECH_RECOGNIZER_ENABLE is not set +# CONFIG_MICROPY_SSL_ENABLE is not set +CONFIG_MAIXPY_WIZNET5K_ENABLE=y +# CONFIG_MICROPY_LWIP_ENABLE is not set +# CONFIG_NETWORK_ESP32XX_HOSTED is not set +# end of Modules configurations + +# +# Builtin py modules configurations +# +# CONFIG_MAIXPY_BUILTIN_PY_PYE is not set +CONFIG_MAIXPY_BUILTIN_PY_BOARD=y +CONFIG_MAIXPY_BUILTIN_PY_FPIOA_MANAGER=y +# end of Builtin py modules configurations + +# +# Debug configurations +# +# CONFIG_MAIXPY_K210_UARTHS_DEBUG is not set +# end of Debug configurations + +CONFIG_BUILTIN_PY_DIR="${PROJECT_PATH}/builtin_py" +# end of Micropython configurations + +# +# Others +# +# CONFIG_COMPONENT_LIB_SIPEED_KPU_SRC_ENABLE is not set +# end of Others + +CONFIG_COMPONENT_SPIFFS_ENABLE=y + +# +# SPIFFS Configuration +# + +# +# SPIFFS Cache Configuration +# +CONFIG_SPIFFS_CACHE=y +CONFIG_SPIFFS_CACHE_WR=y +# CONFIG_SPIFFS_CACHE_STATS is not set +# end of SPIFFS Cache Configuration + +CONFIG_SPIFFS_SIZE=0x300000 +CONFIG_SPIFFS_START_ADDR=0xD00000 +CONFIG_SPIFFS_EREASE_SIZE=0x1000 +CONFIG_SPIFFS_LOGICAL_BLOCK_SIZE=0x20000 +CONFIG_SPIFFS_LOGICAL_PAGE_SIZE=0x1000 +CONFIG_SPIFFS_OBJ_NAME_LEN=128 +CONFIG_SPIFFS_USE_MAGIC=y +CONFIG_SPIFFS_USE_MAGIC_LENGTH=y +CONFIG_SPIFFS_META_LENGTH=0 + +# +# Debug Configuration +# +# CONFIG_SPIFFS_DBG is not set +# CONFIG_SPIFFS_API_DBG is not set +# CONFIG_SPIFFS_GC_DBG is not set +# CONFIG_SPIFFS_CACHE_DBG is not set +# CONFIG_SPIFFS_CHECK_DBG is not set +# end of Debug Configuration +# end of SPIFFS Configuration + +CONFIG_COMPONENT_UTILS_ENABLE=y +# end of Components configuration + +# +# Others +# +# CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE is not set +# end of Others diff --git a/projects/canmv_k210_zero/config_standard.mk b/projects/canmv_k210_zero/config_standard.mk new file mode 100644 index 00000000..b786c735 --- /dev/null +++ b/projects/canmv_k210_zero/config_standard.mk @@ -0,0 +1,174 @@ + +# +# Toolchain configuration +# +CONFIG_TOOLCHAIN_PATH="/opt/kendryte-toolchain/bin" +CONFIG_TOOLCHAIN_PREFIX="riscv64-unknown-elf-" +# end of Toolchain configuration + +# +# Components configuration +# + +# +# Board config +# +CONFIG_BOARD_MAIX=y +# CONFIG_BOARD_M5STICK is not set +# CONFIG_BOARD_TWATCH is not set +CONFIG_LCD_DEFAULT_WIDTH=320 +CONFIG_LCD_DEFAULT_HEIGHT=240 +CONFIG_LCD_DEFAULT_FREQ=15000000 +CONFIG_SENSOR_FREQ=24000000 +CONFIG_CPU_DEFAULT_FREQ=400000000 +# end of Board config + +CONFIG_COMPONENT_DRIVERS_ENABLE=y + +# +# Drivers configuration +# + +# +# SD card +# +CONFIG_SPI_SD_CARD_FORCE_HIGH_SPEED=y +# end of SD card + +# +# WS2812 +# +CONFIG_WS2812_ENABLE=y +# end of WS2812 + +# +# HTPA thermal sensor +# +# CONFIG_HTPA_ENABLE is not set +# end of HTPA thermal sensor + +# +# AMG88XX thermal sensor +# +# CONFIG_AMG88XX_ENABLE is not set +# end of AMG88XX thermal sensor +# end of Drivers configuration + +CONFIG_COMPONENT_KENDRYTE_SDK_ENABLE=y + +# +# Kendryte SDK configurations +# +CONFIG_SDK_LOG_LEVEL=5 +CONFIG_SDK_LOCK_NUM=64 +CONFIG_FREERTOS_ENABLE=y + +# +# FreeRTOS configurations +# +CONFIG_STATIC_TASK_CLEAN_UP_ENABLE=y +# CONFIG_FREERTOS_MALLOC_CUSTOM is not set +CONFIG_FREEROTS_MINIMUM_STACK_SIZE=2048 +# end of FreeRTOS configurations + +CONFIG_MIC_ARRAY_ENABLE=y +# end of Kendryte SDK configurations + +CONFIG_COMPONENT_MICROPYTHON_ENABLE=y + +# +# Micropython configurations +# +CONFIG_MAIXPY_GC_HEAP_SIZE=0xBB9B0 + +# +# Modules configurations +# +CONFIG_CANMV_IDE_SUPPORT=y +CONFIG_MAIXPY_THREAD_ENABLE=y +CONFIG_MAIXPY_NES_ENABLE=y +CONFIG_MAIXPY_VIDEO_ENABLE=y +# CONFIG_MAIXPY_TOUCH_SCREEN_ENABLE is not set +# CONFIG_MAIXPY_OMV_MINIMUM is not set +CONFIG_MAIXPY_OMV_CONV_YUV_FAST=y +CONFIG_MAIXPY_OMV_DOUBLE_BUFF=y +CONFIG_MAIXPY_MIC_ARRAY_ENABLE=y +# CONFIG_MAIXPY_LVGL_ENABLE is not set +# CONFIG_MAIXPY_LODEPNG_ENABLE is not set +CONFIG_MAIXPY_WS2812_ENABLE=y +# CONFIG_MAIXPY_HTPA_ENABLE is not set +# CONFIG_MAIXPY_AMG88XX_ENABLE is not set +CONFIG_MICROPYTHON_ULAB_ENALBE=y +# CONFIG_MAIXPY_SPEECH_RECOGNIZER_ENABLE is not set +# CONFIG_MICROPY_SSL_ENABLE is not set +CONFIG_MAIXPY_WIZNET5K_ENABLE=y +# CONFIG_MICROPY_LWIP_ENABLE is not set +# CONFIG_NETWORK_ESP32XX_HOSTED is not set +# end of Modules configurations + +# +# Builtin py modules configurations +# +# CONFIG_MAIXPY_BUILTIN_PY_PYE is not set +CONFIG_MAIXPY_BUILTIN_PY_BOARD=y +CONFIG_MAIXPY_BUILTIN_PY_FPIOA_MANAGER=y +# end of Builtin py modules configurations + +# +# Debug configurations +# +# CONFIG_MAIXPY_K210_UARTHS_DEBUG is not set +# end of Debug configurations + +CONFIG_BUILTIN_PY_DIR="${PROJECT_PATH}/builtin_py" +# end of Micropython configurations + +# +# Others +# +# CONFIG_COMPONENT_LIB_SIPEED_KPU_SRC_ENABLE is not set +# end of Others + +CONFIG_COMPONENT_SPIFFS_ENABLE=y + +# +# SPIFFS Configuration +# + +# +# SPIFFS Cache Configuration +# +CONFIG_SPIFFS_CACHE=y +CONFIG_SPIFFS_CACHE_WR=y +# CONFIG_SPIFFS_CACHE_STATS is not set +# end of SPIFFS Cache Configuration + +CONFIG_SPIFFS_SIZE=0x300000 +CONFIG_SPIFFS_START_ADDR=0xD00000 +CONFIG_SPIFFS_EREASE_SIZE=0x1000 +CONFIG_SPIFFS_LOGICAL_BLOCK_SIZE=0x20000 +CONFIG_SPIFFS_LOGICAL_PAGE_SIZE=0x1000 +CONFIG_SPIFFS_OBJ_NAME_LEN=128 +CONFIG_SPIFFS_USE_MAGIC=y +CONFIG_SPIFFS_USE_MAGIC_LENGTH=y +CONFIG_SPIFFS_META_LENGTH=0 + +# +# Debug Configuration +# +# CONFIG_SPIFFS_DBG is not set +# CONFIG_SPIFFS_API_DBG is not set +# CONFIG_SPIFFS_GC_DBG is not set +# CONFIG_SPIFFS_CACHE_DBG is not set +# CONFIG_SPIFFS_CHECK_DBG is not set +# end of Debug Configuration +# end of SPIFFS Configuration + +CONFIG_COMPONENT_UTILS_ENABLE=y +# end of Components configuration + +# +# Others +# +# CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE is not set +# end of Others diff --git a/projects/canmv_k210_zero/main/CMakeLists.txt b/projects/canmv_k210_zero/main/CMakeLists.txt new file mode 100644 index 00000000..afbb95d0 --- /dev/null +++ b/projects/canmv_k210_zero/main/CMakeLists.txt @@ -0,0 +1,27 @@ +############### Add include ################### +# list(APPEND ADD_INCLUDE "include" +# ) +# list(APPEND ADD_PRIVATE_INCLUDE "") +############################################### + +############ Add source files ################# +list(APPEND ADD_SRCS "src/main.cpp" + ) +# aux_source_directory(src ADD_SRCS) +# list(REMOVE_ITEM COMPONENT_SRCS "src/test2.c") +############################################### + +###### Add required/dependent components ###### +list(APPEND ADD_REQUIREMENTS micropython kendryte_sdk drivers boards utils spiffs) +if(CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE) + list(APPEND ADD_REQUIREMENTS nncase) +endif() +############################################### + +############ Add static libs ################## +# list(APPEND ADD_STATIC_LIB "lib/libtest.a") +############################################### + + +register_component() + diff --git a/projects/canmv_k210_zero/main/src/main.cpp b/projects/canmv_k210_zero/main/src/main.cpp new file mode 100644 index 00000000..d9ac53a2 --- /dev/null +++ b/projects/canmv_k210_zero/main/src/main.cpp @@ -0,0 +1,9 @@ +#include "maixpy.h" + +void * __dso_handle = 0 ; + +int main() +{ + maixpy_main(); + return 0; +} diff --git a/projects/canmv_k210_zero/project.py b/projects/canmv_k210_zero/project.py new file mode 100644 index 00000000..2396fec2 --- /dev/null +++ b/projects/canmv_k210_zero/project.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +#-*- coding = utf-8 -*- + +import sys, os + +sdk_env_name = "MY_SDK_PATH" + + +# # check python version , for kflash not python2 compatable +# check_version = False +# try: +# if sys.implementation.version.major>=3: +# check_version = True +# except Exception: +# pass +# if not check_version: +# print("Please use python3 to run me!") +# exit(1) + +# get SDK absolute path +sdk_path = os.path.abspath(sys.path[0]+"/../../") +try: + sdk_path = os.environ[sdk_env_name] +except Exception: + pass +print("-- SDK_PATH:{}".format(sdk_path)) + +# execute project script from SDK +project_file_path = sdk_path+"/tools/cmake/project.py" +with open(project_file_path) as f: + exec(f.read()) +