Skip to content

# 2.6. Camera接入适配

## 2.6.1. MIPI设备使能

在J6的内核配置中，确认MIPI设备已被使能：

    CONFIG_HOBOT_MIPI_CSI=y
    CONFIG_HOBOT_MIPI_CSI_DRV=m
    CONFIG_HOBOT_MIPI_CSI_DEV=m
    CONFIG_HOBOT_MIPI_HOST=y
    CONFIG_HOBOT_MIPI_HOST_MAX_NUM=6
    CONFIG_HOBOT_MIPI_DEV=y
    CONFIG_HOBOT_MIPI_DEV_MAX_NUM=2
    CONFIG_HOBOT_MIPI_PHY=m
    CONFIG_HOBOT_MIPI_DEBUG=m

同时需要在板级DTS中使能mipi驱动设备:

    mipi_phy: mipi_phy@0x37200000 {
            status = "okay";
    };
    mipi_host0: mipi_host@0x37420000 {
            status = "okay";
    };
    mipi_host1: mipi_host@0x37620000 {
            status = "okay";
    };
    mipi_host4: mipi_host@0x37C20000 {
            status = "okay";
    };
    mipi_dev0: mipi_csi_dev0@37e10000 {
            status = "okay";
    };
    mipi_dev1: mipi_csi_dev1@37e20000 {
            status = "okay";
    };

## 2.6.2. 解串器

在使用前需先确认J6与Deserializer设备之间的GPIO连接关系，及电平等级等信息;

参考如下表将所有解串器连接都列出：

RX0 | MFP | LINE | DESCRIPTION | BASE | GPIOn
MAX96712 | MFP1 | DES1.LOCK | DES_LOCK | PCM0_DATA0 | 478
| MFP3 | DES1.ERR | DES_ERRB | PCM0_DATA1 | 479
| / | / | DES_PWREN | / | /
| PWDNB | DES1.PWRON | DES_PWDN | P01 | 424
| DES1_CFG0 | DES1_CFG0 | DES_CFG0 | / | /
| DES1_CFG1 | DES1_CFG1 | DES_CFG0 | / | /
| MFP15 | DES1.DES_I2C0.SDA | BUS_MAIN | I2C0_SDA | 465
| MFP16 | DES1.DES_I2C0.SCL | BUS_MAIN | I2C0_SCL | 464
| MFP11 | DES1.DES_I2C1.SDA | BUS_SEC | I2C1_SDA | 467
| MFP12 | DES1.DES_I2C1.SCL | BUS_SEC | I2C1_SCL | 466
| MFP4 | DES1.SENSOR_ERR.0 | SENSOR_ERR0 | SENSOR0_ERR | 444
| MFP6 | DES1.SENSOR_ERR.1 | SENSOR_ERR1 | SENSOR1_ERR | 445
| MFP8 | DES1.SENSOR_ERR.2 | SENSOR_ERR2 | SENSOR2_ERR | 446
| MFP10 | DES1.SENSOR_ERR.3 | SENSOR_ERR3 | SENSOR3_ERR | 447
| MFP5 | DES1.TRIGGER.0 | LPWM_CHN0 | LPWM0_DOUT0 | 456
| MFP7 | DES1.TRIGGER.1 | LPWM_CHN1 | LPWM0_DOUT1 | 457
| MFP9 | DES1.TRIGGER.2 | LPWM_CHN2 | LPWM0_DOUT2 | 458
| MFP14 | DES1.TRIGGER.3 | LPWM_CHN3 | LPWM0_DOUT3 | 459
| / | / | POC_PWREN | / | /
| / | DES1.POC.EN | POC_EN | P02 | 425
| / | DES1.POC.INT | POC_INT | MCAM_PINT | 441
| / | / | POC_ENC0 | / | /
| / | / | POC_ENC1 | / | /
| / | / | POC_ENC2 | / | /
| / | / | POC_ENC3 | / | /

RX1 | MFP | LINE | DESCRIPTION | BASE | GPIOn
MAX96724 | MFP4 | DES2.LOCK | DES_LOCK | SPI1_CSN1 | 503
| MFP5 | DES2.ERR | DES_ERRB | SPI1_MOSI | 504
| / | / | DES_PWREN | / | /
| PWDNB | DES2.PWRON | DES_PWDN | P04 | 427
| DES2_CFG0 | DES2_CFG0 | DES_CFG0 | / | /
| DES2_CFG1 | DES2_CFG1 | DES_CFG0 | / | /
| SDA | DES2.DES_I2C0.SDA | BUS_MAIN | I2C2_SDA | 467
| SCL | DES2.DES_I2C0.SCL | BUS_MAIN | I2C2_SCL | 468
| MFP7 | DES2.SENSOR_ERR.0 | SENSOR_ERR0 | SENSOR4_ERR | 448
| MFP8 | DES2.SENSOR_ERR.1 | SENSOR_ERR1 | SENSOR5_ERR | 449
| MFP3 | DES2.SENSOR_ERR.2 | SENSOR_ERR2 | SENSOR6_ERR | 450
| MFP2 | DES2.SENSOR_ERR.3 | SENSOR_ERR3 | SENSOR7_ERR | 451
| MFP0 | DES2.TRIGGER.0 | LPWM_CHN0 | LPWM1_DOUT0 | 460
| MFP1 | DES2.TRIGGER.1 | LPWM_CHN1 | LPWM1_DOUT1 | 461
| / | / | LPWM_CHN2 | / | /
| / | / | LPWM_CHN3 | / | /
| / | / | POC_PWREN | / | /
| / | DES2.POC.EN | POC_EN | P05 | 428
| / | DES2.POC.INT | POC_INT | SPI1_MISO | 505
| / | / | POC_ENC0 | / | /
| / | / | POC_ENC1 | / | /
| / | / | POC_ENC2 | / | /
| / | / | POC_ENC3 | / | /

RX4 | MFP | LINE | DESCRIPTION | BASE | GPIOn
MAX96724 | MFP4 | DES3.LOCK | DES_LOCK | SD_WPORT | 494
| MFP5 | DES3.ERR | DES_ERRB | SD_BUS_POW | 443
| / | / | DES_PWREN | / | /
| PWDNB | DES3.PWRON | DES_PWDN | P07 | 430
| DES2_CFG0 | DES3_CFG0 | DES_CFG0 | / | /
| DES2_CFG1 | DES3_CFG1 | DES_CFG0 | / | /
| SDA | DES3.DES_I2C0.SDA | BUS_MAIN | I2C3_SDA | 471
| SCL | DES3.DES_I2C0.SCL | BUS_MAIN | I2C3_SCL | 470
| MFP7 | DES3.SENSOR_ERR.0 | SENSOR_ERR0 | SENSOR8_ERR | 452
| MFP8 | DES3.SENSOR_ERR.1 | SENSOR_ERR1 | SENSOR9_ERR | 453
| MFP3 | DES3.SENSOR_ERR.2 | SENSOR_ERR2 | SENSOR10_ERR | 454
| MFP2 | DES3.SENSOR_ERR.3 | SENSOR_ERR3 | SENSOR11_ERR | 455
| MFP0 | DES3.TRIGGER.0 | LPWM_CHN0 | SD_1V8 | 442
| / | / | LPWM_CHN1 | / | /
| / | / | LPWM_CHN2 | / | /
| / | / | LPWM_CHN3 | / | /
| / | / | POC_PWREN | / | /
| / | DES2.POC.EN | POC_EN | P10 | 431
| / | DES2.POC.INT | POC_INT | PCM0_MCLK | 475
| / | / | POC_ENC0 | / | /
| / | / | POC_ENC1 | / | /
| / | / | POC_ENC2 | / | /
| / | / | POC_ENC3 | / | /

各GPIO的电平等级确认，并在DTS中适配：

    cam_gpio: cam_gpio_func {
        pinmux {
                function = "cam_gpio";
                pins = "cam_lpwm0_dout0", "cam_lpwm0_dout1",
                       "cam_lpwm0_dout2", "cam_lpwm0_dout3", "cam_lpwm1_dout0",
                       "cam_lpwm1_dout1", "cam_lpwm1_dout2",
                       "cam_lpwm1_dout3", "cam_i2c0_scl", "cam_i2c0_sda",
                       "cam_i2c1_scl", "cam_i2c1_sda", "cam_i2c2_scl",
                       "cam_i2c2_sda", "cam_i2c3_scl", "cam_i2c3_sda",
                       "cam_i2c4_scl", "cam_i2c4_sda";
        };
        pinconf {
                pins = "cam_lpwm0_dout0", "cam_lpwm0_dout1",
                       "cam_lpwm0_dout2", "cam_lpwm0_dout3", "cam_lpwm1_dout0",
                       "cam_lpwm1_dout1", "cam_lpwm1_dout2",
                       "cam_lpwm1_dout3", "cam_i2c0_scl", "cam_i2c0_sda",
                       "cam_i2c1_scl", "cam_i2c1_sda", "cam_i2c2_scl",
                       "cam_i2c2_sda", "cam_i2c3_scl", "cam_i2c3_sda",
                       "cam_i2c4_scl", "cam_i2c4_sda";
                drive-strength = <1>;
        };
    };
        video_gpio: video_gpio_func {
                pinmux {
                        function = "video_gpio";
                        pins = "video_gnss_int", "video_peri_rsto",
                               "video_cam_pint", "video_sd_1v8", "video_sd_bus_pow",
                               "video_sensor0_err", "video_sensor1_err",
                               "video_sensor2_err", "video_sensor3_err", "video_sensor4_err",
                               "video_sensor5_err", "video_sensor6_err",
                               "video_sensor7_err", "video_sensor8_err",
                               "video_sensor9_err", "video_sensor10_err", "video_sensor11_err";
                };
                pinconf {
                        pins = "video_gnss_int", "video_peri_rsto",
                               "video_cam_pint", "video_sd_1v8", "video_sd_bus_pow",
                               "video_sensor0_err", "video_sensor1_err",
                               "video_sensor2_err", "video_sensor3_err", "video_sensor4_err",
                               "video_sensor5_err", "video_sensor6_err",
                               "video_sensor7_err", "video_sensor8_err",
                               "video_sensor9_err", "video_sensor10_err", "video_sensor11_err";
                        drive-strength = <1>;
                };
        };
        peri_gpio: peri_gpio_func {
                pinmux {
                        function = "peri_gpio";
                        pins = "peri_emac_mdc_hsi0", "peri_emac_mdio_hsi0",
                               "peri_sd_clk", "peri_sd_cmd", "peri_sd_data0",
                               "peri_sd_data1", "peri_sd_data2", "peri_sd_data3",
                               "peri_sd_data4", "peri_sd_data5", "peri_sd_data6",
                               "peri_sd_data7", "peri_sd_data_strb",
                               "peri_sd_det_n", "peri_sd_wprot", "peri_i2c5_scl",
                               "peri_i2c5_sda", "peri_spi0_csn0", "peri_spi0_csn1",
                               "peri_spi0_mosi", "peri_spi0_miso", "peri_spi0_sclk",
                               "peri_spi1_csn0", "peri_spi1_csn1",
                               "peri_spi1_mosi", "peri_spi1_miso", "peri_spi1_sclk",
                               "peri_uart0_txd", "peri_uart0_rxd", "peri_uart0_rtsn",
                               "peri_uart0_ctsn", "peri_uart1_txd",
                               "peri_uart1_rxd", "peri_pcm0_mclk", "peri_pcm0_bclk",
                               "peri_pcm0_fsync", "peri_pcm0_data0",
                               "peri_pcm0_data1";
                };
                pinconf {
                        pins = "peri_emac_mdc_hsi0", "peri_emac_mdio_hsi0",
                               "peri_sd_clk", "peri_sd_cmd", "peri_sd_data0",
                               "peri_sd_data1", "peri_sd_data2", "peri_sd_data3",
                               "peri_sd_data4", "peri_sd_data5", "peri_sd_data6",
                               "peri_sd_data7", "peri_sd_data_strb",
                               "peri_sd_det_n", "peri_sd_wprot", "peri_i2c5_scl",
                               "peri_i2c5_sda", "peri_spi0_csn0", "peri_spi0_csn1",
                               "peri_spi0_mosi", "peri_spi0_miso", "peri_spi0_sclk",
                               "peri_spi1_csn0", "peri_spi1_csn1",
                               "peri_spi1_mosi", "peri_spi1_miso", "peri_spi1_sclk",
                               "peri_uart0_txd", "peri_uart0_rxd", "peri_uart0_rtsn",
                               "peri_uart0_ctsn", "peri_uart1_txd",
                               "peri_uart1_rxd", "peri_pcm0_mclk", "peri_pcm0_bclk",
                               "peri_pcm0_fsync", "peri_pcm0_data0",
                               "peri_pcm0_data1";
                        drive-strength = <1>;
                };
        };

同时需要填充VCON DTS中的相关信息，GPIO定义可参考上一章节。

    &vin_vcon0 {
        bus = <0 4>;
        gpio_poc = <0 425 441>;
        gpio_des = <0 424 478 479>;
        gpio_ser = <0 423 476 477>;
        sensor_err = <0 1 2 3>;
        lpwm_chn = <0 1 2 3>;
        rx_phy = <2 0>;
    };
    &vin_vcon1 {
        bus = <2>;
        gpio_poc = <0 428 505>;
        gpio_des = <0 427 503 504>;
        sensor_err = <4 5 6 7>;
        lpwm_chn = <4 5>;
        rx_phy = <2 1>;
    };
    &vin_vcon4 {
        bus = <3>;
        gpio_poc = <0 431 475>;
        gpio_des = <0 430 494 443>;
        sensor_err = <8 9 10 11>;
        lpwm_chn = <8>;
        rx_phy = <1 4>;
    };
    &vin_vcon6 {
        bus = <5>;
        gpio_ser = <0 429 502 506>;
        tx_phy = <1 0>;
    };
    &vin_vcon7 {
        bus = <5>;
        gpio_ser = <0 426 510 493>;
        tx_phy = <1 1>;
    };

还需对LPWM做相关板级配置，参数表示对应通道是否有效，1表示有效，0表示无效。

    &lpwm0 {
        channel = <1 1 1 1>;
    };

    &lpwm1 {
        channel = <1 1 0 0>;
    };

    &lpwm2 {
        channel = <1 0 0 0>;
    };

## 2.6.3. Camera

Camera接入请联系地平线开发人员，确认是否为已有支持模组。

若未支持，则需初次点亮，参考 Camera使用验证

## 2.6.4. 曝光同步

曝光同步功能需要Camera点亮时增加相应适配支持，参考 Camera曝光同步