From 185805cbbe10ab39d3fe4fc5f323106cbf0854d2 Mon Sep 17 00:00:00 2001 From: jzlv Date: Wed, 21 Dec 2022 20:12:17 +0800 Subject: [PATCH] [update][bsp_common] update common driver, add dvp sensor driver --- bsp/common/CMakeLists.txt | 35 +- bsp/common/ethernet/ethernet_phy.c | 2 +- bsp/common/ethernet/ethernet_phy.h | 2 +- bsp/common/ethernet/ethernetif.c | 46 +-- bsp/common/ethernet/phy_8720.c | 10 +- bsp/common/ethernet/phy_8720.h | 2 +- bsp/common/image_sensor/bf2013.h | 186 ++++++++++ bsp/common/image_sensor/gc0308.h | 487 +++++++++++++++++++++++++ bsp/common/image_sensor/gc0328.h | 455 +++++++++++++++++++++++ bsp/common/image_sensor/gc2053.h | 191 ++++++++++ bsp/common/image_sensor/image_sensor.c | 110 ++++++ bsp/common/image_sensor/image_sensor.h | 106 ++++++ bsp/common/lcd/lcd.h | 12 +- 13 files changed, 1593 insertions(+), 51 deletions(-) create mode 100644 bsp/common/image_sensor/bf2013.h create mode 100644 bsp/common/image_sensor/gc0308.h create mode 100644 bsp/common/image_sensor/gc0328.h create mode 100644 bsp/common/image_sensor/gc2053.h create mode 100644 bsp/common/image_sensor/image_sensor.c create mode 100644 bsp/common/image_sensor/image_sensor.h diff --git a/bsp/common/CMakeLists.txt b/bsp/common/CMakeLists.txt index cff4b7ce..b75d36e7 100644 --- a/bsp/common/CMakeLists.txt +++ b/bsp/common/CMakeLists.txt @@ -1,20 +1,17 @@ -if(CONFIG_BSP_COMMON) -sdk_generate_library() - if(CONFIG_ETHERNET) -sdk_library_add_sources(ethernet/ethernet_phy.c) -sdk_library_add_sources(ethernet/phy_8720.c) +target_sources(app PRIVATE ethernet/ethernet_phy.c) +target_sources(app PRIVATE ethernet/phy_8720.c) if(CONFIG_LWIP) -sdk_library_add_sources(ethernet/ethernetif.c) +target_sources(app PRIVATE ethernet/ethernetif.c) endif() -sdk_add_include_directories(ethernet/) +sdk_add_include_directories(ethernet) endif() # sdh sdcard driver if(CONFIG_BSP_SDH_SDCARD) sdk_add_compile_definitions(-DCONFIG_BSP_SDH_SDCARD) -sdk_library_add_sources(sdcard/sdh_sdcard.c) -sdk_add_include_directories(sdcard/) +target_sources(app PRIVATE sdcard/sdh_sdcard.c) +sdk_add_include_directories(sdcard) endif() # spi sdcard driver @@ -24,19 +21,17 @@ endif() # lcd driver if(CONFIG_BSP_LCD) -sdk_library_add_sources(lcd/lcd.c) -sdk_library_add_sources(lcd/font.c) -sdk_library_add_sources(lcd/spi/ili9341_spi.c) -sdk_library_add_sources(lcd/spi/ili9488_spi.c) -sdk_library_add_sources(lcd/spi/st7796_spi.c) -sdk_library_add_sources(lcd/spi/st7789v_spi.c) -sdk_add_include_directories(lcd/) +target_sources(app PRIVATE lcd/lcd.c) +target_sources(app PRIVATE lcd/font.c) +target_sources(app PRIVATE lcd/spi/ili9341_spi.c) +target_sources(app PRIVATE lcd/spi/ili9488_spi.c) +target_sources(app PRIVATE lcd/spi/st7796_spi.c) +target_sources(app PRIVATE lcd/spi/st7789v_spi.c) +sdk_add_include_directories(lcd) endif() # image sensor driver if(CONFIG_BSP_IMAGE_SENSOR) -sdk_library_add_sources(image_sensor/image_sensor.c) -sdk_add_include_directories(image_sensor/) -endif() - +target_sources(app PRIVATE image_sensor/image_sensor.c) +sdk_add_include_directories(image_sensor) endif() \ No newline at end of file diff --git a/bsp/common/ethernet/ethernet_phy.c b/bsp/common/ethernet/ethernet_phy.c index 8afec4b3..2861142c 100644 --- a/bsp/common/ethernet/ethernet_phy.c +++ b/bsp/common/ethernet/ethernet_phy.c @@ -30,7 +30,7 @@ * @return int * */ -int ethernet_phy_init(struct bflb_device_s *emac, struct emac_phy_cfg_s *emac_phy_cfg) +int ethernet_phy_init(struct bflb_device_s *emac, struct bflb_emac_phy_cfg_s *emac_phy_cfg) { return _PHY_FUNC_DEFINE(init, emac, emac_phy_cfg); } diff --git a/bsp/common/ethernet/ethernet_phy.h b/bsp/common/ethernet/ethernet_phy.h index 75394df1..c68f641b 100644 --- a/bsp/common/ethernet/ethernet_phy.h +++ b/bsp/common/ethernet/ethernet_phy.h @@ -50,6 +50,6 @@ typedef enum emac_phy_status { #endif emac_phy_status_t ethernet_phy_status_get(void); -int ethernet_phy_init(struct bflb_device_s *emac, struct emac_phy_cfg_s *emac_phy_cfg); +int ethernet_phy_init(struct bflb_device_s *emac, struct bflb_emac_phy_cfg_s *emac_phy_cfg); #endif diff --git a/bsp/common/ethernet/ethernetif.c b/bsp/common/ethernet/ethernetif.c index 2515e137..09c03032 100644 --- a/bsp/common/ethernet/ethernetif.c +++ b/bsp/common/ethernet/ethernetif.c @@ -50,16 +50,15 @@ // #define BL702_EMAC 0 // #define EMAC_OUTPUT BL702_EMAC -#if LWIP_DHCP #define MAX_DHCP_TRIES 4 uint32_t DHCPfineTimer = 0; uint8_t DHCP_state = DHCP_OFF; -#else + /*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */ -#define IP_ADDR0 (uint8_t)192 -#define IP_ADDR1 (uint8_t)168 -#define IP_ADDR2 (uint8_t)123 -#define IP_ADDR3 (uint8_t)100 +#define IP_ADDR0 (uint8_t)192 +#define IP_ADDR1 (uint8_t)168 +#define IP_ADDR2 (uint8_t)123 +#define IP_ADDR3 (uint8_t)100 /*NETMASK*/ #define NETMASK_ADDR0 (uint8_t)255 @@ -68,15 +67,14 @@ uint8_t DHCP_state = DHCP_OFF; #define NETMASK_ADDR3 (uint8_t)0 /*Gateway Address*/ -#define GW_ADDR0 (uint8_t)192 -#define GW_ADDR1 (uint8_t)168 -#define GW_ADDR2 (uint8_t)123 -#define GW_ADDR3 (uint8_t)1 -#endif +#define GW_ADDR0 (uint8_t)192 +#define GW_ADDR1 (uint8_t)168 +#define GW_ADDR2 (uint8_t)123 +#define GW_ADDR3 (uint8_t)1 /* Private function prototypes -----------------------------------------------*/ struct bflb_device_s *emac0; -struct emac_phy_cfg_s phy_cfg = { +struct bflb_emac_phy_cfg_s phy_cfg = { .auto_negotiation = 1, /*!< Speed and mode auto negotiation */ .full_duplex = 0, /*!< Duplex mode */ .speed = 0, /*!< Speed mode */ @@ -110,7 +108,7 @@ LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(struct pbuf_custom), "Zero-copy RX PBUF * for this ethernetif */ extern void emac_init_txrx_buffer(struct bflb_device_s *emac); -// extern int ethernet_phy_init(struct bflb_device_s *emac, struct emac_phy_cfg_s *emac_phy_cfg); +// extern int ethernet_phy_init(struct bflb_device_s *emac, struct bflb_emac_phy_cfg_s *emac_phy_cfg); void emac_rx_done_callback_app(void); void dhcp_thread(void const *argument); @@ -283,7 +281,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) // copy data to tx buf printf("tx buf is too larger!\r\n"); flags = EMAC_FRAGMENT_PACKET; - // ARCH_MemCpy_Fast(&emac_send_buf[framelength + bufferoffset], q->payload + payloadoffset, (ETH_TX_BUFFER_SIZE - bufferoffset)); + // arch_memcpy_fast(&emac_send_buf[framelength + bufferoffset], q->payload + payloadoffset, (ETH_TX_BUFFER_SIZE - bufferoffset)); } // arch_memcpy_fast(&emac_send_buf[framelength], q->payload, byteslefttocopy); memcpy(&emac_send_buf[framelength], q->payload, byteslefttocopy); @@ -565,17 +563,17 @@ void dhcp_thread(void const *argument) ip_addr_set_zero_ip4(&netif->netmask); ip_addr_set_zero_ip4(&netif->gw); DHCP_state = DHCP_WAIT_ADDRESS; - printf(" State: Looking for DHCP server ...\n"); + printf(" State: Looking for DHCP server ...\r\n"); dhcp_start(netif); } break; case DHCP_WAIT_ADDRESS: { if (dhcp_supplied_address(netif)) { DHCP_state = DHCP_ADDRESS_ASSIGNED; sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("IP address assigned by a DHCP server: %s\n", iptxt); + printf("IP address assigned by a DHCP server: %s\r\n", iptxt); } else { dhcp = (struct dhcp *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); - + // printf("else\r\n"); /* DHCP timeout */ if (dhcp->tries > MAX_DHCP_TRIES) { DHCP_state = DHCP_TIMEOUT; @@ -583,17 +581,21 @@ void dhcp_thread(void const *argument) /* Static address used */ ethernet_set_static_ip(netif); sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("DHCP Timeout !! \n"); - printf("Static IP address: %s\n", iptxt); + printf("DHCP Timeout !! \r\n"); + printf("Static IP address: %s\r\n", iptxt); } } } break; + case DHCP_ADDRESS_ASSIGNED: { + netif->state = DHCP_ADDRESS_ASSIGNED; + } break; case DHCP_LINK_DOWN: { DHCP_state = DHCP_OFF; - printf("The network cable is not connected \n"); + printf("The network cable is not connected \r\n"); + } break; + default: { + printf("dhcp:%d\r\n", DHCP_state); } break; - default: - break; } vTaskDelay(100); } diff --git a/bsp/common/ethernet/phy_8720.c b/bsp/common/ethernet/phy_8720.c index fc205db2..1173de81 100644 --- a/bsp/common/ethernet/phy_8720.c +++ b/bsp/common/ethernet/phy_8720.c @@ -4,7 +4,7 @@ #define CHECK_PARAM(expr) ((void)0) struct bflb_device_s *emac_dev = NULL; -static struct emac_phy_cfg_s *phy_8720_cfg = NULL; +static struct bflb_emac_phy_cfg_s *phy_8720_cfg = NULL; /** * @brief phy 8720 reset @@ -63,7 +63,7 @@ int phy_8720_reset(void) * @return int * */ -int phy_8720_auto_negotiate(struct emac_phy_cfg_s *cfg) +int phy_8720_auto_negotiate(struct bflb_emac_phy_cfg_s *cfg) { uint16_t regval = 0; uint16_t phyid1 = 0, phyid2 = 0; @@ -187,7 +187,7 @@ int phy_8720_auto_negotiate(struct emac_phy_cfg_s *cfg) * @return int * */ -int phy_8720_link_up(struct emac_phy_cfg_s *cfg) +int phy_8720_link_up(struct bflb_emac_phy_cfg_s *cfg) { uint16_t phy_bsr = 0; uint16_t phy_sr = 0; @@ -247,7 +247,7 @@ int phy_8720_link_up(struct emac_phy_cfg_s *cfg) * @return int * */ -int phy_8720_poll_cable_status(struct emac_phy_cfg_s *cfg) +int phy_8720_poll_cable_status(struct bflb_emac_phy_cfg_s *cfg) { uint16_t phy_regval = 0; @@ -268,7 +268,7 @@ int phy_8720_poll_cable_status(struct emac_phy_cfg_s *cfg) * @return int * */ -int phy_8720_init(struct bflb_device_s *emac, struct emac_phy_cfg_s *cfg) +int phy_8720_init(struct bflb_device_s *emac, struct bflb_emac_phy_cfg_s *cfg) { uint16_t phyReg; diff --git a/bsp/common/ethernet/phy_8720.h b/bsp/common/ethernet/phy_8720.h index c53b0724..8bd470ae 100644 --- a/bsp/common/ethernet/phy_8720.h +++ b/bsp/common/ethernet/phy_8720.h @@ -83,7 +83,7 @@ #define PHY_ISFR ((uint16_t)0x1DU) /*!< PHY Interrupt Source Flag register Offset */ #define PHY_ISFR_INT4 ((uint16_t)0x0010U) /*!< PHY Link down inturrupt */ -int phy_8720_init(struct bflb_device_s *emac, struct emac_phy_cfg_s *cfg); +int phy_8720_init(struct bflb_device_s *emac, struct bflb_emac_phy_cfg_s *cfg); emac_phy_status_t phy_8720_status_get(void); #endif /* __PHY_8720_H__ */ \ No newline at end of file diff --git a/bsp/common/image_sensor/bf2013.h b/bsp/common/image_sensor/bf2013.h new file mode 100644 index 00000000..cb1f3320 --- /dev/null +++ b/bsp/common/image_sensor/bf2013.h @@ -0,0 +1,186 @@ +/** + * @file image_sensor.h + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + */ +#ifndef __BF2013_H__ +#define __BF2013_H__ + +#include "image_sensor.h" + +static struct image_sensor_command_s bf2013_init_list[] = { + { 0x12, 0x80 }, + { 0x67, 0x00 }, + { 0x68, 0x00 }, + //{0xb9, 0x80},//use Test pattern + //{0x69,0x20}, + { 0x3a, 0x02 }, + { 0x09, 0x01 }, + { 0x15, 0x02 }, + { 0x12, 0x00 }, + { 0x1e, 0x00 }, + { 0x13, 0x00 }, + { 0x01, 0x14 }, + { 0x02, 0x21 }, + { 0x8c, 0x02 }, + { 0x8d, 0x64 }, + { 0x87, 0x18 }, + { 0x13, 0x07 }, + //{0x11,0x80},//pclk=mclk + { 0x11, 0x30 }, //pclk=mclk/8 + { 0x2b, 0x20 }, + { 0x92, 0x40 }, + { 0x9d, 0x99 }, + { 0x06, 0xe0 }, + { 0x29, 0x54 }, + { 0xeb, 0x30 }, + { 0xbb, 0x20 }, + { 0xf5, 0x21 }, + { 0xe1, 0x3c }, + { 0x16, 0x01 }, + { 0xe0, 0x0b }, + { 0x2f, 0xf6 }, + { 0x33, 0x20 }, + { 0x34, 0x08 }, + { 0x35, 0x50 }, + { 0x65, 0x4a }, + { 0x66, 0x50 }, + { 0x36, 0x05 }, + { 0x37, 0xf6 }, + { 0x38, 0x46 }, + { 0x9b, 0xf6 }, + { 0x9c, 0x46 }, + { 0xbc, 0x01 }, + { 0xbd, 0xf6 }, + { 0xbe, 0x46 }, + { 0x82, 0x14 }, + { 0x83, 0x23 }, + { 0x9a, 0x23 }, + { 0x70, 0x6f }, + { 0x72, 0x3f }, + { 0x73, 0x3f }, + { 0x74, 0x27 }, + { 0x77, 0x90 }, + { 0x79, 0x48 }, + { 0x7a, 0x1e }, + { 0x7b, 0x30 }, + { 0x84, 0x1a }, + { 0x85, 0x20 }, + { 0x89, 0x02 }, + { 0x8a, 0x64 }, + { 0x86, 0x30 }, + { 0x96, 0xa6 }, + { 0x97, 0x0c }, + { 0x98, 0x18 }, + { 0x80, 0x55 }, + { 0x24, 0x70 }, + { 0x25, 0x80 }, + { 0x94, 0x0a }, + { 0x1f, 0x20 }, + { 0x22, 0x20 }, + { 0x26, 0x20 }, + { 0x56, 0x40 }, + { 0x61, 0xd3 }, + { 0x79, 0x48 }, + { 0x3b, 0x60 }, + { 0x3c, 0x20 }, + { 0x39, 0x80 }, + { 0x3f, 0xb0 }, + { 0x39, 0x80 }, + { 0x40, 0x58 }, + { 0x41, 0x54 }, + { 0x42, 0x4e }, + { 0x43, 0x44 }, + { 0x44, 0x3e }, + { 0x45, 0x39 }, + { 0x46, 0x35 }, + { 0x47, 0x31 }, + { 0x48, 0x2e }, + { 0x49, 0x2b }, + { 0x4b, 0x29 }, + { 0x4c, 0x27 }, + { 0x4e, 0x23 }, + { 0x4f, 0x20 }, + { 0x50, 0x1e }, + { 0x51, 0x05 }, + { 0x52, 0x10 }, + { 0x53, 0x0b }, + { 0x54, 0x15 }, + { 0x57, 0x87 }, + { 0x58, 0x72 }, + { 0x59, 0x5f }, + { 0x5a, 0x7e }, + { 0x5b, 0x1f }, + { 0x5c, 0x0e }, + { 0x5d, 0x95 }, + { 0x60, 0x28 }, + { 0xb0, 0xe0 }, + { 0xb1, 0xc0 }, + { 0xb2, 0xb0 }, + { 0xb3, 0x88 }, + { 0x6a, 0x01 }, + { 0x23, 0x66 }, + { 0xa0, 0x03 }, + { 0xa1, 0x31 }, + { 0xa2, 0x0b }, + { 0xa3, 0x26 }, + { 0xa4, 0x05 }, + { 0xa5, 0x25 }, + { 0xa6, 0x06 }, + { 0xa7, 0x80 }, + { 0xa8, 0x80 }, + { 0xa9, 0x20 }, + { 0xaa, 0x20 }, + { 0xab, 0x20 }, + { 0xac, 0x3c }, + { 0xad, 0xf0 }, + { 0xc8, 0x18 }, + { 0xc9, 0x20 }, + { 0xca, 0x17 }, + { 0xcb, 0x1f }, + { 0xaf, 0x00 }, + { 0xc5, 0x18 }, + { 0xc6, 0x00 }, + { 0xc7, 0x20 }, + { 0xae, 0x80 }, + { 0xcc, 0x40 }, + { 0xcd, 0x58 }, + { 0xee, 0x4c }, + { 0x8e, 0x07 }, + { 0x8f, 0x79 }, +}; + +static struct image_sensor_config_s bf2013_config = { + .name = "BF2013", + .output_format = IMAGE_SENSOR_FORMAT_YUV422_YUYV, + .slave_addr = 0x6e, + .id_size = 2, + .reg_size = 1, + .h_blank = 0x90, + .resolution_x = 640, + .resolution_y = 480, + .id_addr = 0xfcfd, + .id_value = 0x3703, + .pixel_clock = 24000000, + .init_list_len = sizeof(bf2013_init_list)/sizeof(bf2013_init_list[0]), + .init_list = bf2013_init_list, +}; + +#endif /* __BF2013_H__ */ diff --git a/bsp/common/image_sensor/gc0308.h b/bsp/common/image_sensor/gc0308.h new file mode 100644 index 00000000..917056bd --- /dev/null +++ b/bsp/common/image_sensor/gc0308.h @@ -0,0 +1,487 @@ +/** + * @file image_sensor.h + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + */ +#ifndef __GC0308_H__ +#define __GC0308_H__ + +#include "image_sensor.h" + +static struct image_sensor_command_s gc0308_init_list[] = { + { 0xfe, 0x80 }, + { 0xfe, 0x00 }, //set page0 + { 0xd2, 0x10 }, //close AEC + { 0x22, 0x55 }, //close AWB + { 0x5a, 0x56 }, + { 0x5b, 0x40 }, + { 0x5c, 0x4a }, + { 0x22, 0x57 }, //Open AWB + //{ 0x2e, 0x02 }, //debug mode +#if 0 + //config for 39 FPS + {0x01, 0x6a}, //h_blank 106 + //{0x02 , 0x70},//VB 112 + {0x02, 0x0c}, //change VB from 112 to 12 + {0x0f, 0x00}, + {0xe2, 0x00}, //anti-flicker step [11:8] + {0xe3, 0x96}, //anti-flicker step [7:0] + {0xe4, 0x01}, //exp level 1 50.00fps or 20ms + {0xe5, 0x2c}, + {0xe6, 0x03}, //exp level 2 16.67fps + {0xe7, 0x84}, + {0xe8, 0x04}, //exp level 3 12.5fps + {0xe9, 0xb0}, + {0xea, 0x09}, //exp level 4 6.00fps + {0xeb, 0xc4}, +#elif 1 + //config for 20 FPS + { 0x01, 0x28 }, //HB 552 + { 0x02, 0x06 }, //VB 6 + { 0x0f, 0x02 }, + { 0xe2, 0x00 }, //anti-flicker step [11:8] + { 0xe3, 0x96 }, //anti-flicker step [7:0] + { 0xe4, 0x01 }, //exp level 1 20fps + { 0xe5, 0x2c }, + { 0xe6, 0x03 }, //exp level 2 16.67fps + { 0xe7, 0x84 }, + { 0xe8, 0x04 }, //exp level 3 12.5fps + { 0xe9, 0xb0 }, + { 0xea, 0x09 }, //exp level 4 6.00fps + { 0xeb, 0xc4 }, +#else + //config for 25 FPS + { 0x01, 0x6a }, //HB 106 + //{0x02 , 0x70},//VB 112 + { 0x02, 0xe8 }, //change VB from 112 to 232 + { 0x0f, 0x00 }, + { 0xe2, 0x00 }, //anti-flicker step [11:8] + { 0xe3, 0x96 }, //anti-flicker step [7:0] + { 0xe4, 0x02 }, //exp level 1 25.00fps or 40ms + { 0xe5, 0x58 }, + { 0xe6, 0x03 }, //exp level 2 16.67fps + { 0xe7, 0x84 }, + { 0xe8, 0x04 }, //exp level 3 12.5fps + { 0xe9, 0xb0 }, + { 0xea, 0x09 }, //exp level 4 6.00fps + { 0xeb, 0xc4 }, +#endif + { 0xec, 0x00 }, //select max exposure level 1 - highest fps + { 0x05, 0x00 }, + { 0x06, 0x00 }, + { 0x07, 0x00 }, + { 0x08, 0x00 }, + { 0x09, 0x01 }, + { 0x0a, 0xe8 }, + //{0x0a , 0x70},//change win_height from 488 to 368 + { 0x0b, 0x02 }, + { 0x0c, 0x88 }, //win_width 648 + { 0x0d, 0x02 }, + { 0x0e, 0x02 }, + { 0x10, 0x22 }, + { 0x11, 0xfd }, + { 0x12, 0x2a }, + { 0x13, 0x00 }, + //{0x14 , 0x10}, + { 0x14, 0x13 }, //enable mirror & flip + //-------------H_V_Switch(4)---------------// + /* + 1://normal + {0x14 , 0x10}, + 2://IMAGE_H_MIRROR + {0x14 , 0x11}, + 3://IMAGE_V_MIRROR + {0x14 , 0x12}, + 4://IMAGE_HV_MIRROR + {0x14 , 0x13},*/ + { 0x15, 0x0a }, + { 0x16, 0x05 }, + { 0x17, 0x01 }, + { 0x18, 0x44 }, + { 0x19, 0x44 }, + { 0x1a, 0x1e }, + { 0x1b, 0x00 }, + { 0x1c, 0xc1 }, + { 0x1d, 0x08 }, + { 0x1e, 0x60 }, + { 0x1f, 0x17 }, + { 0x20, 0xff }, + { 0x21, 0xf8 }, + { 0x22, 0x57 }, + //{ 0x24, 0xa0 }, //Cb Y Cr Y + { 0x24, 0xa2 }, //Y Cb Y Cr + { 0x25, 0x0f }, + //output sync_mode + //{0x26 , 0x02}, //0x03 20101016 zhj + { 0x26, 0x03 }, //sync mode, high high + { 0x2f, 0x01 }, + { 0x30, 0xf7 }, + { 0x31, 0x50 }, + { 0x32, 0x00 }, + { 0x39, 0x04 }, + { 0x3a, 0x18 }, + { 0x3b, 0x20 }, + { 0x3c, 0x00 }, + { 0x3d, 0x00 }, + { 0x3e, 0x00 }, + { 0x3f, 0x00 }, + { 0x50, 0x10 }, + { 0x53, 0x82 }, + { 0x54, 0x80 }, + { 0x55, 0x80 }, + { 0x56, 0x82 }, + { 0x8b, 0x40 }, + { 0x8c, 0x40 }, + { 0x8d, 0x40 }, + { 0x8e, 0x2e }, + { 0x8f, 0x2e }, + { 0x90, 0x2e }, + { 0x91, 0x3c }, + { 0x92, 0x50 }, + { 0x5d, 0x12 }, + { 0x5e, 0x1a }, + { 0x5f, 0x24 }, + { 0x60, 0x07 }, + { 0x61, 0x15 }, + { 0x62, 0x08 }, + { 0x64, 0x03 }, + { 0x66, 0xe8 }, + { 0x67, 0x86 }, + { 0x68, 0xa2 }, + { 0x69, 0x18 }, + { 0x6a, 0x0f }, + { 0x6b, 0x00 }, + { 0x6c, 0x5f }, + { 0x6d, 0x8f }, + { 0x6e, 0x55 }, + { 0x6f, 0x38 }, + { 0x70, 0x15 }, + { 0x71, 0x33 }, + { 0x72, 0xdc }, + { 0x73, 0x80 }, + { 0x74, 0x02 }, + { 0x75, 0x3f }, + { 0x76, 0x02 }, + { 0x77, 0x36 }, + { 0x78, 0x88 }, + { 0x79, 0x81 }, + { 0x7a, 0x81 }, + { 0x7b, 0x22 }, + { 0x7c, 0xff }, + { 0x93, 0x48 }, + { 0x94, 0x00 }, + { 0x95, 0x05 }, + { 0x96, 0xe8 }, + { 0x97, 0x40 }, + { 0x98, 0xf0 }, + { 0xb1, 0x38 }, + { 0xb2, 0x38 }, + { 0xbd, 0x38 }, + { 0xbe, 0x36 }, +#if 1 + { 0xd0, 0xc9 }, + { 0xd1, 0x10 }, + { 0xd3, 0x80 }, + { 0xd5, 0xf2 }, + { 0xd6, 0x16 }, +#else + //default AEC setting + { 0xd0, 0xca }, + { 0xd1, 0xa1 }, + { 0xd3, 0xa0 }, + { 0xd5, 0xf2 }, + { 0xd6, 0x18 }, +#endif + { 0xdb, 0x92 }, + { 0xdc, 0xa5 }, + { 0xdf, 0x23 }, + { 0xd9, 0x00 }, + { 0xda, 0x00 }, + { 0xe0, 0x09 }, + { 0xed, 0x04 }, +#if 0 + //default max dgain + {0xee, 0xa0}, + {0xef, 0x40}, +#else + //increased max dgain + { 0xee, 0xf0 }, + { 0xef, 0x60 }, +#endif + { 0x80, 0x03 }, + { 0x80, 0x03 }, + { 0x9F, 0x10 }, + { 0xA0, 0x20 }, + { 0xA1, 0x38 }, + { 0xA2, 0x4E }, + { 0xA3, 0x63 }, + { 0xA4, 0x76 }, + { 0xA5, 0x87 }, + { 0xA6, 0xA2 }, + { 0xA7, 0xB8 }, + { 0xA8, 0xCA }, + { 0xA9, 0xD8 }, + { 0xAA, 0xE3 }, + { 0xAB, 0xEB }, + { 0xAC, 0xF0 }, + { 0xAD, 0xF8 }, + { 0xAE, 0xFD }, + { 0xAF, 0xFF }, + /* + GC0308_GAMMA_Select, + 1://smallest gamma curve + {0x9F , 0x0B}, + {0xA0 , 0x16}, + {0xA1 , 0x29}, + {0xA2 , 0x3C}, + {0xA3 , 0x4F}, + {0xA4 , 0x5F}, + {0xA5 , 0x6F}, + {0xA6 , 0x8A}, + {0xA7 , 0x9F}, + {0xA8 , 0xB4}, + {0xA9 , 0xC6}, + {0xAA , 0xD3}, + {0xAB , 0xDD}, + {0xAC , 0xE5}, + {0xAD , 0xF1}, + {0xAE , 0xFA}, + {0xAF , 0xFF}, + 2: + {0x9F , 0x0E}, + {0xA0 , 0x1C}, + {0xA1 , 0x34}, + {0xA2 , 0x48}, + {0xA3 , 0x5A}, + {0xA4 , 0x6B}, + {0xA5 , 0x7B}, + {0xA6 , 0x95}, + {0xA7 , 0xAB}, + {0xA8 , 0xBF}, + {0xA9 , 0xCE}, + {0xAA , 0xD9}, + {0xAB , 0xE4}, + {0xAC , 0xEC}, + {0xAD , 0xF7}, + {0xAE , 0xFD}, + {0xAF , 0xFF}, + 3: + {0x9F , 0x10}, + {0xA0 , 0x20}, + {0xA1 , 0x38}, + {0xA2 , 0x4E}, + {0xA3 , 0x63}, + {0xA4 , 0x76}, + {0xA5 , 0x87}, + {0xA6 , 0xA2}, + {0xA7 , 0xB8}, + {0xA8 , 0xCA}, + {0xA9 , 0xD8}, + {0xAA , 0xE3}, + {0xAB , 0xEB}, + {0xAC , 0xF0}, + {0xAD , 0xF8}, + {0xAE , 0xFD}, + {0xAF , 0xFF}, + 4: + {0x9F , 0x14}, + {0xA0 , 0x28}, + {0xA1 , 0x44}, + {0xA2 , 0x5D}, + {0xA3 , 0x72}, + {0xA4 , 0x86}, + {0xA5 , 0x95}, + {0xA6 , 0xB1}, + {0xA7 , 0xC6}, + {0xA8 , 0xD5}, + {0xA9 , 0xE1}, + {0xAA , 0xEA}, + {0xAB , 0xF1}, + {0xAC , 0xF5}, + {0xAD , 0xFB}, + {0xAE , 0xFE}, + {0xAF , 0xFF}, + 5://largest gamma curve + {0x9F , 0x15}, + {0xA0 , 0x2A}, + {0xA1 , 0x4A}, + {0xA2 , 0x67}, + {0xA3 , 0x79}, + {0xA4 , 0x8C}, + {0xA5 , 0x9A}, + {0xA6 , 0xB3}, + {0xA7 , 0xC5}, + {0xA8 , 0xD5}, + {0xA9 , 0xDF}, + {0xAA , 0xE8}, + {0xAB , 0xEE}, + {0xAC , 0xF3}, + {0xAD , 0xFA}, + {0xAE , 0xFD}, + {0xAF , 0xFF}, + */ + //-----------GAMMA Select End--------------// + { 0xc0, 0x00 }, + { 0xc1, 0x10 }, + { 0xc2, 0x1C }, + { 0xc3, 0x30 }, + { 0xc4, 0x43 }, + { 0xc5, 0x54 }, + { 0xc6, 0x65 }, + { 0xc7, 0x75 }, + { 0xc8, 0x93 }, + { 0xc9, 0xB0 }, + { 0xca, 0xCB }, + { 0xcb, 0xE6 }, + { 0xcc, 0xFF }, + { 0xf0, 0x02 }, + { 0xf1, 0x01 }, + { 0xf2, 0x01 }, + { 0xf3, 0x30 }, + { 0xf9, 0x9f }, + { 0xfa, 0x78 }, + //{0xfa , 0x58},//Change measure window Y1 from 480 to 352 + //------------------------------------------------- + { 0xfe, 0x01 }, // set page1 + { 0x00, 0xf5 }, + { 0x02, 0x1a }, + { 0x0a, 0xa0 }, + { 0x0b, 0x60 }, + { 0x0c, 0x08 }, + { 0x0e, 0x4c }, + { 0x0f, 0x39 }, + { 0x11, 0x3f }, + { 0x12, 0x72 }, + { 0x13, 0x13 }, + { 0x14, 0x42 }, + { 0x15, 0x43 }, + { 0x16, 0xc2 }, + { 0x17, 0xa8 }, + { 0x18, 0x18 }, + { 0x19, 0x40 }, + { 0x1a, 0xd0 }, + { 0x1b, 0xf5 }, + { 0x70, 0x40 }, + { 0x71, 0x58 }, + { 0x72, 0x30 }, + { 0x73, 0x48 }, + { 0x74, 0x20 }, + { 0x75, 0x60 }, + { 0x77, 0x20 }, + { 0x78, 0x32 }, + { 0x30, 0x03 }, + { 0x31, 0x40 }, + { 0x32, 0xe0 }, + { 0x33, 0xe0 }, + { 0x34, 0xe0 }, + { 0x35, 0xb0 }, + { 0x36, 0xc0 }, + { 0x37, 0xc0 }, + { 0x38, 0x04 }, + { 0x39, 0x09 }, + { 0x3a, 0x12 }, + { 0x3b, 0x1C }, + { 0x3c, 0x28 }, + { 0x3d, 0x31 }, + { 0x3e, 0x44 }, + { 0x3f, 0x57 }, + { 0x40, 0x6C }, + { 0x41, 0x81 }, + { 0x42, 0x94 }, + { 0x43, 0xA7 }, + { 0x44, 0xB8 }, + { 0x45, 0xD6 }, + { 0x46, 0xEE }, + { 0x47, 0x0d }, + { 0xfe, 0x00 }, //set page0 + //-----------Update the registers 2010/07/06-------------// + //Registers of Page0 + { 0xfe, 0x00 }, //set page0 + { 0x10, 0x26 }, + { 0x11, 0x0d }, //fd,modified by mormo 2010/07/06 + { 0x1a, 0x2a }, //1e,modified by mormo 2010/07/06 + { 0x1c, 0x49 }, //c1,modified by mormo 2010/07/06 + { 0x1d, 0x9a }, //08,modified by mormo 2010/07/06 + { 0x1e, 0x61 }, //60,modified by mormo 2010/07/06 + { 0x3a, 0x20 }, + { 0x50, 0x14 }, //10,modified by mormo 2010/07/06 + { 0x53, 0x80 }, + { 0x56, 0x80 }, + { 0x8b, 0x20 }, //LSC + { 0x8c, 0x20 }, + { 0x8d, 0x20 }, + { 0x8e, 0x14 }, + { 0x8f, 0x10 }, + { 0x90, 0x14 }, + { 0x94, 0x02 }, + { 0x95, 0x07 }, + { 0x96, 0xe0 }, + { 0xb1, 0x40 }, //YCPT + { 0xb2, 0x40 }, + { 0xb3, 0x40 }, + { 0xb6, 0xe0 }, + //{0xd0 , 0xcb},//AECT c9,modifed by mormo 2010/07/06 + //{0xd3 , 0x48},//80,modified by mormor 2010/07/06 + { 0xf2, 0x02 }, + //{0xf7 , 0x12}, + //{0xf8 , 0x0a}, + //Registers + { 0xfe, 0x01 }, // set page1 + { 0x02, 0x20 }, + { 0x04, 0x10 }, + { 0x05, 0x08 }, + { 0x06, 0x20 }, + { 0x08, 0x0a }, + { 0x0e, 0x44 }, + { 0x0f, 0x32 }, + { 0x10, 0x41 }, + { 0x11, 0x37 }, + { 0x12, 0x22 }, + { 0x13, 0x19 }, + { 0x14, 0x44 }, + { 0x15, 0x44 }, + { 0x19, 0x50 }, + { 0x1a, 0xd8 }, + { 0x32, 0x10 }, + { 0x35, 0x00 }, + { 0x36, 0x80 }, + { 0x37, 0x00 }, + //-----------Update the registers end---------// + { 0xfe, 0x00 }, //set page0 + { 0xd2, 0x90 }, +}; + +static struct image_sensor_config_s gc0308_config = { + .name = "GC0308", + .output_format = IMAGE_SENSOR_FORMAT_YUV422_YUYV, + .slave_addr = 0x21, + .id_size = 1, + .reg_size = 1, + .h_blank = 0x6a, + .resolution_x = 640, + .resolution_y = 480, + .id_addr = 0x00, + .id_value = 0x9b, + .pixel_clock = 24000000, + .init_list_len = sizeof(gc0308_init_list)/sizeof(gc0308_init_list[0]), + .init_list = gc0308_init_list, +}; + +#endif /* __GC0308_H__ */ diff --git a/bsp/common/image_sensor/gc0328.h b/bsp/common/image_sensor/gc0328.h new file mode 100644 index 00000000..466b5af8 --- /dev/null +++ b/bsp/common/image_sensor/gc0328.h @@ -0,0 +1,455 @@ +/** + * @file image_sensor.h + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + */ +#ifndef __GC0328_H__ +#define __GC0328_H__ + +#include "image_sensor.h" + +static struct image_sensor_command_s gc0328_init_list[] = { + {0xfe, 0x80}, + {0xfe, 0x80}, + {0xfc, 0x16}, + {0xfc, 0x16}, + {0xfc, 0x16}, + {0xfc, 0x16}, + + {0xfe, 0x00}, + {0x4f, 0x00}, + {0x42, 0x00}, + {0x03, 0x00}, + {0x04, 0xc0}, + {0x77, 0x62}, + {0x78, 0x40}, + {0x79, 0x4d}, + + {0xfe, 0x01}, + {0x4f, 0x00}, + {0x4c, 0x01}, + {0xfe, 0x00}, + ////////////////////////////// + ///////////AWB/////////// + //////////////////////////////// + {0xfe, 0x01}, + {0x51, 0x80}, + {0x52, 0x12}, + {0x53, 0x80}, + {0x54, 0x60}, + {0x55, 0x01}, + {0x56, 0x06}, + {0x5b, 0x02}, + {0xb1, 0xdc}, + {0xb2, 0xdc}, + {0x7c, 0x71}, + {0x7d, 0x00}, + {0x76, 0x00}, + {0x79, 0x20}, + {0x7b, 0x00}, + {0x70, 0xFF}, + {0x71, 0x00}, + {0x72, 0x10}, + {0x73, 0x40}, + {0x74, 0x40}, + ////AWB// + {0x50, 0x00}, + {0xfe, 0x01}, + {0x4f, 0x00}, + {0x4c, 0x01}, + {0x4f, 0x00}, + {0x4f, 0x00}, + {0x4f, 0x00}, + {0x4d, 0x36}, + {0x4e, 0x02}, + {0x4d, 0x46}, + {0x4e, 0x02}, + {0x4e, 0x02}, + {0x4d, 0x53}, + {0x4e, 0x08}, + {0x4e, 0x04}, + {0x4e, 0x04}, + {0x4d, 0x63}, + {0x4e, 0x08}, + {0x4e, 0x08}, + {0x4d, 0x82}, + {0x4e, 0x20}, + {0x4e, 0x20}, + {0x4d, 0x92}, + {0x4e, 0x40}, + {0x4d, 0xa2}, + {0x4e, 0x40}, + {0x4f, 0x01}, + + {0x50, 0x88}, + {0xfe, 0x00}, + //////////////////////////////////////////////// + //////////// BLK ////////////////////// + //////////////////////////////////////////////// + {0x27, 0x00}, + {0x2a, 0x40}, + {0x2b, 0x40}, + {0x2c, 0x40}, + {0x2d, 0x40}, + ////////////////////////////////////////////// + ////////// page 0 //////////////////////// + ////////////////////////////////////////////// + {0xfe, 0x00}, + {0x05, 0x00}, + {0x06, 0xde},//h_blank + {0x07, 0x00}, + {0x08, 0xa7}, + + {0x0d, 0x01}, + {0x0e, 0xe8}, + {0x0f, 0x02}, + {0x10, 0x88}, + {0x09, 0x00}, + {0x0a, 0x00}, + {0x0b, 0x00}, + {0x0c, 0x00}, + {0x16, 0x00}, + {0x17, 0x14 | 0x01}, // dir = 0x01 + {0x18, 0x0e}, + {0x19, 0x06}, + + {0x1b, 0x48}, + {0x1f, 0xC8}, + {0x20, 0x01}, + {0x21, 0x78}, + {0x22, 0xb0}, + {0x23, 0x06}, + {0x24, 0x11}, + {0x26, 0x00}, + + {0x50, 0x01}, // crop mode + // global gain for range + {0x70, 0x85}, + //////////////////////////////////////////////// + //////////// block enable ///////////// + //////////////////////////////////////////////// + {0x40, 0x7f}, + {0x41, 0x24}, + {0x42, 0xff}, + {0x45, 0x00}, + {0x44, 0x02}, //YUYV + {0x46, 0x03}, //[0] VSYNC polarity 0x02 + + {0x4b, 0x01}, + {0x50, 0x01}, + // DN & EEINTP + {0x7e, 0x0a}, + {0x7f, 0x03}, + {0x81, 0x15}, + {0x82, 0x85}, + {0x83, 0x02}, + {0x84, 0xe5}, + {0x90, 0xac}, + {0x92, 0x02}, + {0x94, 0x02}, + {0x95, 0x54}, + ///////YCP + {0xd1, 0x32}, + {0xd2, 0x32}, + {0xdd, 0x58}, + {0xde, 0x36}, + {0xe4, 0x88}, + {0xe5, 0x40}, + {0xd7, 0x0e}, + ///////////////////////////// + //////////////// GAMMA ////// + ///////////////////////////// + // rgb gamma +#if 0 /* RGBGAMMA_test */ + {0xfe, 0x00}, + {0xbf, 0x08}, + {0xc0, 0x10}, + {0xc1, 0x22}, + {0xc2, 0x32}, + {0xc3, 0x43}, + {0xc4, 0x50}, + {0xc5, 0x5e}, + {0xc6, 0x78}, + {0xc7, 0x90}, + {0xc8, 0xa6}, + {0xc9, 0xb9}, + {0xca, 0xc9}, + {0xcb, 0xd6}, + {0xcc, 0xe0}, + {0xcd, 0xee}, + {0xce, 0xf8}, + {0xcf, 0xff}, +#elif 1 /* RGBGAMMA_m6 */ + {0xBF, 0x14}, + {0xc0, 0x28}, + {0xc1, 0x44}, + {0xc2, 0x5D}, + {0xc3, 0x72}, + {0xc4, 0x86}, + {0xc5, 0x95}, + {0xc6, 0xB1}, + {0xc7, 0xC6}, + {0xc8, 0xD5}, + {0xc9, 0xE1}, + {0xcA, 0xEA}, + {0xcB, 0xF1}, + {0xcC, 0xF5}, + {0xcD, 0xFB}, + {0xcE, 0xFE}, + {0xcF, 0xFF}, +#endif + + /// Y gamma + {0xfe, 0x00}, + {0x63, 0x00}, + {0x64, 0x05}, + {0x65, 0x0b}, + {0x66, 0x19}, + {0x67, 0x2e}, + {0x68, 0x40}, + {0x69, 0x54}, + {0x6a, 0x66}, + {0x6b, 0x86}, + {0x6c, 0xa7}, + {0x6d, 0xc6}, + {0x6e, 0xe4}, + {0x6f, 0xFF}, + //////ASDE + {0xfe, 0x01}, + {0x18, 0x02}, + {0xfe, 0x00}, + {0x98, 0x00}, + {0x9b, 0x20}, + {0x9c, 0x80}, + {0xa4, 0x10}, + {0xa8, 0xB0}, + {0xaa, 0x40}, + {0xa2, 0x23}, + {0xad, 0x01}, + ////////////////////////////////////////////// + ////////// AEC //////////////////////// + ////////////////////////////////////////////// + {0xfe, 0x01}, + {0x9c, 0x02}, + {0x08, 0xa0}, + {0x09, 0xe8}, + + {0x10, 0x00}, + {0x11, 0x11}, + {0x12, 0x10}, + // {0x13, 0x80}, + {0x13, 0xB0}, //提高显示的亮度. + {0x15, 0xfc}, + {0x18, 0x03}, + {0x21, 0xc0}, + {0x22, 0x60}, + {0x23, 0x30}, + {0x25, 0x00}, + {0x24, 0x14}, + ////////////////////////////////////// + ////////////LSC////////////////////// + ////////////////////////////////////// + // gc0328 Alight lsc reg setting list + ////Record date: 2013-04-01 15:59:05 + {0xfe, 0x01}, + {0xc0, 0x0d}, + {0xc1, 0x05}, + {0xc2, 0x00}, + {0xc6, 0x07}, + {0xc7, 0x03}, + {0xc8, 0x01}, + {0xba, 0x19}, + {0xbb, 0x10}, + {0xbc, 0x0a}, + {0xb4, 0x19}, + {0xb5, 0x0d}, + {0xb6, 0x09}, + {0xc3, 0x00}, + {0xc4, 0x00}, + {0xc5, 0x0e}, + {0xc9, 0x00}, + {0xca, 0x00}, + {0xcb, 0x00}, + {0xbd, 0x07}, + {0xbe, 0x00}, + {0xbf, 0x0e}, + {0xb7, 0x09}, + {0xb8, 0x00}, + {0xb9, 0x0d}, + {0xa8, 0x01}, + {0xa9, 0x00}, + {0xaa, 0x03}, + {0xab, 0x02}, + {0xac, 0x05}, + {0xad, 0x0c}, + {0xae, 0x03}, + {0xaf, 0x00}, + {0xb0, 0x04}, + {0xb1, 0x04}, + {0xb2, 0x03}, + {0xb3, 0x08}, + {0xa4, 0x00}, + {0xa5, 0x00}, + {0xa6, 0x00}, + {0xa7, 0x00}, + {0xa1, 0x3c}, + {0xa2, 0x50}, + {0xfe, 0x00}, + /// cct + {0xB1, 0x02}, + {0xB2, 0x02}, + {0xB3, 0x07}, + {0xB4, 0xf0}, + {0xB5, 0x05}, + {0xB6, 0xf0}, + + {0xfe, 0x00}, + {0x27, 0xf7}, + {0x28, 0x7F}, + {0x29, 0x20}, + {0x33, 0x20}, + {0x34, 0x20}, + {0x35, 0x20}, + {0x36, 0x20}, + {0x32, 0x08}, + + {0x47, 0x00}, + {0x48, 0x00}, + + {0xfe, 0x01}, + {0x79, 0x00}, + {0x7d, 0x00}, + {0x50, 0x88}, + {0x5b, 0x04}, + {0x76, 0x8f}, + {0x80, 0x70}, + {0x81, 0x70}, + {0x82, 0xb0}, + {0x70, 0xff}, + {0x71, 0x00}, + {0x72, 0x10}, + {0x73, 0x40}, + {0x74, 0x40}, + + {0xfe, 0x00}, + {0x70, 0x45}, + {0x4f, 0x01}, + {0xf1, 0x07}, + + {0xf2, 0x01}, + //////////// Set Frame Rate ///////////// + //{0xfe, 0x00}, + //{0x05, 0x00}, + //{0x06, 0x4c}, // HB + //{0x07, 0x00}, + //{0x08, 0x28}, // VB + + //{0xfe, 0x01}, + //{0x29, 0x00}, + //{0x2a, 0x4e}, // step + // + //{0x2b, 0x02}, //high 4bit + //{0x2c, 0x70}, //low 8bit + // + //{0x2d, 0x03}, + //{0x2e, 0x0c}, + // + //{0x2f, 0x05}, + //{0x30, 0x00}, + // + //{0x31, 0x0f}, //夜间主循环7帧 //高位是4bit,即最大设为0x0f + //{0x32, 0x00}, //low 8bit + // + //{0x33, 0x30}, //4档曝光 + + //////////// Set Window ///////////// + //{0xfe, 0x00}, + //{0x59, 0x22}, // subsampleratio=2 + //{0x5a, 0x03}, + //{0x5b, 0x00}, + //{0x5c, 0x00}, + //{0x5d, 0x00}, + //{0x5e, 0x00}, + //{0x5f, 0x00}, + //{0x60, 0x00}, + //{0x61, 0x00}, + //{0x62, 0x00}, + //{0x50, 0x01}, // crop 320x240 // + //{0x51, 0x00}, + //{0x52, 0x00}, + //{0x53, 0x00}, + //{0x54, 0x00}, + //{0x55, 0x00}, + //{0x56, 0xf0}, // 240 + //{0x57, 0x01}, + //{0x58, 0x40}, // 320 + + /* 640*480 */ + {0xfe, 0x00}, + {0x4b, 0x8b}, + //{0x4c, 0x04},//debug mode + {0x50, 0x01}, + {0x51, 0x00}, + {0x52, 0x00}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x01}, + {0x56, 0xe0}, + {0x57, 0x02}, + {0x58, 0x80}, + {0x59, 0x11}, + {0x5a, 0x02}, + {0x5b, 0x00}, + {0x5c, 0x00}, + {0x5d, 0x00}, + {0x5e, 0x00}, + {0x5f, 0x00}, + {0x60, 0x00}, + {0x61, 0x00}, + {0x62, 0x00}, + + {0xFE, 0x00}, + {0xF1, 0x00}, + {0xF2, 0x00}, + + {0x00, 0x00}, + + {0xFE, 0x00}, + {0xF1, 0x07}, + {0xF2, 0x01}, +}; + +static struct image_sensor_config_s gc0328_config = { + .name = "GC0328", + .output_format = IMAGE_SENSOR_FORMAT_YUV422_YUYV, + .slave_addr = 0x21, + .id_size = 1, + .reg_size = 1, + .h_blank = 0xde, + .resolution_x = 640, + .resolution_y = 480, + .id_addr = 0xf0, + .id_value = 0x9d, + .pixel_clock = 24000000, + .init_list_len = sizeof(gc0328_init_list)/sizeof(gc0328_init_list[0]), + .init_list = gc0328_init_list, +}; + +#endif /* __GC0328_H__ */ diff --git a/bsp/common/image_sensor/gc2053.h b/bsp/common/image_sensor/gc2053.h new file mode 100644 index 00000000..70908901 --- /dev/null +++ b/bsp/common/image_sensor/gc2053.h @@ -0,0 +1,191 @@ +/** + * @file image_sensor.h + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + */ +#ifndef __GC2053_H__ +#define __GC2053_H__ + +#include "image_sensor.h" + +static struct image_sensor_command_s gc2053_init_list[] = { + { 0xfe, 0x80 }, // page select + { 0xfe, 0x80 }, + { 0xfe, 0x80 }, + { 0xfe, 0x00 }, + { 0xf2, 0x00 }, // [7] OTP_clk_gate [6:4] OTP_mode_temp [1] I2C_open_ena [0]pwd_dn + { 0xf3, 0x0f }, // [7] OTP_finish [6] OTP_busy [5] Spad_vb_hiz_mode [4] Spad_buf_mode [3] Sdata_pad_io [2:0] Ssync_pad_io + { 0xf4, 0x36 }, // [7] reduce_power_mode, [6:4]PLL_ldo_set, [3:0]spi_clk_div + { 0xf5, 0xc0 }, // [7] soc_mclk_enable, [6] pll_ldo_en, [5:4]cp_clk_del, [3:0]cp_clk_div + { 0xf6, 0x44 }, // [7:3]wpllclk_div, [2:0]refmp_div + { 0xf7, 0x01 }, // [7]refdiv2d5_en [6]refdiv1d5_en [5:4]scaler_mode(dvpmode) [3]refmp_enb [2]freq div2 [1]div2en [0]pll_en + { 0xf8, 0x63 }, // [7:0]pllmp_div + { 0xf9, 0x40 }, // [7:3]rpllclk_div [2:1]pllmp_prediv [0]analog_pwc + { 0xfc, 0x8e }, // [7] regf clk enable [6] sys_rclk_sel [5] sys_wclk_sel [4:3]spi_sel_mode [2] serail_clk enable [1] re_lock_pll [0] not_use_pll + /*cisctl&analog*/ + { 0xfe, 0x00 }, + { 0x87, 0x18 }, // Debug_mode disable + { 0xee, 0x30 }, + { 0xd0, 0xb7 }, + { 0x03, 0x01 }, + { 0x04, 0x19 }, + { 0x05, 0x05 }, //h_blank, Line length = 1320 *2 [3:0] Line length[11:8] X2 + { 0x06, 0x28 }, // [7:0] Line length[7:0] X2 + { 0x07, 0x00 }, + { 0x08, 0x11 }, + { 0x09, 0x00 }, // row start + { 0x0a, 0x02 }, + { 0x0b, 0x00 }, // col start + { 0x0c, 0x02 }, + { 0x0d, 0x04 }, // valid line time:Window width 1088 + // Windows height default is 1936 + { 0x0e, 0x40 }, + { 0x12, 0xe2 }, + { 0x13, 0x16 }, + { 0x19, 0x0a }, + { 0x21, 0x1c }, + { 0x28, 0x0a }, + { 0x29, 0x24 }, + { 0x2b, 0x04 }, + { 0x32, 0xf8 }, + { 0x37, 0x03 }, + { 0x39, 0x15 }, + { 0x43, 0x07 }, + { 0x44, 0x40 }, + { 0x46, 0x0b }, + { 0x4b, 0x20 }, + { 0x4e, 0x08 }, + { 0x55, 0x20 }, + { 0x66, 0x05 }, + { 0x67, 0x05 }, + { 0x77, 0x01 }, + { 0x78, 0x00 }, + { 0x7c, 0x93 }, + { 0x8c, 0x12 }, + { 0x8d, 0x92 }, + { 0x90, 0x01 }, + { 0x9d, 0x10 }, + { 0xce, 0x7c }, + { 0xd2, 0x41 }, + { 0xd3, 0xdc }, + { 0xe6, 0x50 }, + /*gain*/ + { 0xb6, 0xc0 }, + { 0xb0, 0x70 }, + { 0xb1, 0x01 }, + { 0xb2, 0x14 }, + { 0xb3, 0x30 }, + { 0xb4, 0x00 }, + { 0xb8, 0x01 }, + { 0xb9, 0x2c }, + /*blk*/ + { 0x26, 0x30 }, + { 0xfe, 0x01 }, + { 0x40, 0x23 }, // BLK_mode1. [7] not smooth [6:4] blk_smooth_speed [3]blk_dd_map [2]dark_sel_map [1]dark_current_en [0]offset_en + { 0x55, 0x07 }, + { 0x60, 0x40 }, // DARK OFFSET + { 0xfe, 0x04 }, + { 0x14, 0x78 }, // Ndark_ratio_G1 + { 0x15, 0x78 }, // Ndark_ratio_R1 + { 0x16, 0x78 }, // Ndark_ratio_B2 + { 0x17, 0x78 }, // Ndark_ratio_G2 + /*window*/ + { 0xfe, 0x01 }, + { 0x92, 0x01 }, // output win start y + { 0x94, 0x02 }, // output win start x + { 0x95, 0x04 }, // output win height 1080 + { 0x96, 0x38 }, + { 0x97, 0x07 }, // outout win width 1920 + { 0x98, 0x80 }, + /*ISP*/ + { 0xfe, 0x01 }, + { 0x01, 0x05 }, + { 0x02, 0x89 }, + { 0x04, 0x01 }, + { 0x07, 0xa6 }, + { 0x08, 0xa9 }, + { 0x09, 0xa8 }, + { 0x0a, 0xa7 }, + { 0x0b, 0xff }, + { 0x0c, 0xff }, + { 0x0f, 0x00 }, + { 0x50, 0x1c }, + { 0x89, 0x03 }, + { 0xfe, 0x04 }, + { 0x28, 0x86 }, + { 0x29, 0x86 }, + { 0x2a, 0x86 }, + { 0x2b, 0x68 }, + { 0x2c, 0x68 }, + { 0x2d, 0x68 }, + { 0x2e, 0x68 }, + { 0x2f, 0x68 }, + { 0x30, 0x4f }, + { 0x31, 0x68 }, + { 0x32, 0x67 }, + { 0x33, 0x66 }, + { 0x34, 0x66 }, + { 0x35, 0x66 }, + { 0x36, 0x66 }, + { 0x37, 0x66 }, + { 0x38, 0x62 }, + { 0x39, 0x62 }, + { 0x3a, 0x62 }, + { 0x3b, 0x62 }, + { 0x3c, 0x62 }, + { 0x3d, 0x62 }, + { 0x3e, 0x62 }, + { 0x3f, 0x62 }, + /****DVP & MIPI****/ + { 0xfe, 0x01 }, + // {0x8c,0x01}, // test mode + //{0x9a,0x06}, /* VSYNC low pulse */ + { 0x9a, 0x02 }, /* VSYNC high pulse */ + { 0xfe, 0x00 }, + { 0x7b, 0x2b }, + { 0x23, 0x2d }, + { 0xfe, 0x03 }, + { 0x01, 0x20 }, // DPHY_analog_mode1 + { 0x02, 0x56 }, // DPHY_analog_mode2 + { 0x03, 0xb2 }, // DPHY_analog_mode3 + { 0x12, 0x80 }, // LWC_set[7:0] + { 0x13, 0x07 }, // LWC_set[15:8] + + { 0xfe, 0x00 }, + { 0x3e, 0x40 }, +}; + +static struct image_sensor_config_s gc2053_config = { + .name = "GC2053", + .output_format = IMAGE_SENSOR_FORMAT_YUV422_YUYV, + .slave_addr = 0x37, + .id_size = 2, + .reg_size = 1, + .h_blank = 0x528, + .resolution_x = 1920, + .resolution_y = 1080, + .id_addr = 0xf0f1, + .id_value = 0x2053, + .pixel_clock = 24000000, + .init_list_len = sizeof(gc2053_init_list)/sizeof(gc2053_init_list[0]), + .init_list = gc2053_init_list, +}; + +#endif /* __GC2053_H__ */ diff --git a/bsp/common/image_sensor/image_sensor.c b/bsp/common/image_sensor/image_sensor.c new file mode 100644 index 00000000..b103f86b --- /dev/null +++ b/bsp/common/image_sensor/image_sensor.c @@ -0,0 +1,110 @@ +/** + * @file image_sensor.c + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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 "image_sensor.h" +#include "bf2013.h" +#include "gc0308.h" +#include "gc0328.h" +#include "gc2053.h" +#include "bflb_i2c.h" + +static struct image_sensor_config_s *sensor_list[] = { + NULL, &bf2013_config, &gc0308_config, &gc0328_config, &gc2053_config +}; + +void image_sensor_read(struct bflb_device_s *i2c, uint32_t sensor_index, struct image_sensor_command_s *read_list, uint32_t list_len) +{ + uint32_t i; + struct bflb_i2c_msg_s msgs[2]; + + msgs[0].addr = sensor_list[sensor_index]->slave_addr; + msgs[0].flags = I2C_M_NOSTOP; + msgs[0].buffer = NULL; + msgs[0].length = sensor_list[sensor_index]->reg_size; + + msgs[1].addr = sensor_list[sensor_index]->slave_addr; + msgs[1].flags = I2C_M_READ; + msgs[1].buffer = NULL; + msgs[1].length = 1; + + for(i=0;islave_addr; + msgs[0].flags = I2C_M_NOSTOP; + msgs[0].buffer = NULL; + msgs[0].length = sensor_list[sensor_index]->reg_size; + + msgs[1].addr = sensor_list[sensor_index]->slave_addr; + msgs[1].flags = 0; + msgs[1].buffer = NULL; + msgs[1].length = 1; + + for(i=0;iid_size;j++){ + if(sensor_list[i]->reg_size == 1){ + read_id.address = sensor_list[i]->id_addr>>(8*j)&0xff; + }else{ + read_id.address = sensor_list[i]->id_addr>>(16*j)&0xffff; + } + image_sensor_read(i2c, i, &read_id, 1); + if(read_id.paramete != (sensor_list[i]->id_value>>(8*j)&0xff)){ + sensor_match_flag = 0; + break; + } + sensor_match_flag = 1; + } + + if(sensor_match_flag == 1){ + *config = sensor_list[i]; + image_sensor_write(i2c, i, sensor_list[i]->init_list, sensor_list[i]->init_list_len); + return(i); + } + } + + return 0; +} + diff --git a/bsp/common/image_sensor/image_sensor.h b/bsp/common/image_sensor/image_sensor.h new file mode 100644 index 00000000..3096a130 --- /dev/null +++ b/bsp/common/image_sensor/image_sensor.h @@ -0,0 +1,106 @@ +/** + * @file image_sensor.h + * @brief + * + * Copyright (c) 2022 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + */ +#ifndef __IMAGE_SENSOR_H__ +#define __IMAGE_SENSOR_H__ + +#include "bflb_core.h" + +/** @defgroup IMAGE_SENSOR_FORMAT image sensor output format definition + * @{ + */ +#define IMAGE_SENSOR_FORMAT_YUV422_YUYV 0 +#define IMAGE_SENSOR_FORMAT_YUV422_YVYU 1 +#define IMAGE_SENSOR_FORMAT_YUV422_UYVY 2 +#define IMAGE_SENSOR_FORMAT_YUV422_VYUY 3 +#define IMAGE_SENSOR_FORMAT_GRAY 4 +#define IMAGE_SENSOR_FORMAT_RGB565 5 +#define IMAGE_SENSOR_FORMAT_BGR565 6 +#define IMAGE_SENSOR_FORMAT_RGB888 7 +#define IMAGE_SENSOR_FORMAT_BGR888 8 +#define IMAGE_SENSOR_FORMAT_BAYER_BGRG 9 +#define IMAGE_SENSOR_FORMAT_BAYER_RGBG 10 +#define IMAGE_SENSOR_FORMAT_BAYER_GBGR 11 +#define IMAGE_SENSOR_FORMAT_BAYER_GRGB 12 +/** + * @} + */ + +/** @defgroup IMAGE_SENSOR_INFO image sensor information copy size definition + * @{ + */ +#define IMAGE_SENSOR_INFO_COPY_SIZE 12 +/** + * @} + */ + +/** + * @brief Image sensor command structure + * + * @param address Address of command + * @param paramete Paramete of command + */ +struct image_sensor_command_s +{ + uint16_t address; + uint8_t paramete; +}; + +/** + * @brief Image sensor configuration structure + * + * @param output_format Output format use @IMAGE_SENSOR_FORMAT + * @param resolution_x Resolution X + * @param resolution_y Resolution Y + * @param h_blank Hsync blank + * @param pixel_clock Pixel clock + * @param name Name of sensor + * @param slave_addr Slave address of sensor + * @param id_size Size of sensor ID + * @param reg_size Size of sensor register + * @param id_addr ID address of sensor, size: (id_size * reg_size) bytes + * @param id_value ID value of sensor, size: id_size bytes + * @param init_list_len Length of init list + * @param init_list Pointer of init list + */ +struct image_sensor_config_s +{ + uint8_t output_format; + uint16_t resolution_x; + uint16_t resolution_y; + uint16_t h_blank; + uint32_t pixel_clock; + char name[9]; + uint8_t slave_addr; + uint8_t id_size; + uint8_t reg_size; + uint32_t id_addr; + uint32_t id_value; + uint32_t init_list_len; + struct image_sensor_command_s *init_list; +}; + +void image_sensor_read(struct bflb_device_s *i2c, uint32_t sensor_index, struct image_sensor_command_s *read_list, uint32_t list_len); +void image_sensor_write(struct bflb_device_s *i2c, uint32_t sensor_index, struct image_sensor_command_s *read_list, uint32_t list_len); +uint32_t image_sensor_scan(struct bflb_device_s *i2c, struct image_sensor_config_s **config); + +#endif /* __IMAGE_SENSOR_H__ */ diff --git a/bsp/common/lcd/lcd.h b/bsp/common/lcd/lcd.h index ac9e1092..7826963a 100644 --- a/bsp/common/lcd/lcd.h +++ b/bsp/common/lcd/lcd.h @@ -49,10 +49,11 @@ LCD_SPI_ILI9481 LCD_SPI_ILI9341 LCD_SPI_ST7796 + LCD_SPI_ST7789V */ /* Select screen Type */ -#define LCD_SPI_ST7796 +#define LCD_SPI_ST7789V #define LCD_INTERFACE_SPI 1 #define LCD_INTERFACE_DBI 2 @@ -142,6 +143,15 @@ #define LCD_COLOR_DEPTH ST7796_SPI_COLOR_DEPTH #define _LCD_FUNC_DEFINE(_func, ...) st7796_spi_##_func(__VA_ARGS__) +#elif defined LCD_SPI_ST7789V + +#include "spi/st7789v_spi.h" +#define LCD_INTERFACE_TYPE LCD_INTERFACE_SPI +#define LCD_W ST7789V_SPI_W +#define LCD_H ST7789V_SPI_H +#define LCD_COLOR_DEPTH ST7789V_SPI_COLOR_DEPTH +#define _LCD_FUNC_DEFINE(_func, ...) st7789v_spi_##_func(__VA_ARGS__) + #elif #error "Please select a screen type" #endif