/**************************************************************************** * * Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. * * This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics Ltd and MAY NOT * be copied by any method or incorporated into another program without * the express written consent of Aerospace C.Power. This Information or any portion * thereof remains the property of Aerospace C.Power. The Information contained herein * is believed to be accurate and Aerospace C.Power assumes no responsibility or * liability for its use in any way and conveys no license or title under * any patent or copyright and makes no representation or warranty that this * Information is free from patent or copyright infringement. * * ****************************************************************************/ /* os shim includes */ #include "os_types.h" #include "os_task.h" #include "os_utils.h" #include "iot_errno_api.h" /* common includes */ #include "iot_io.h" #include "iot_bitops.h" #include "iot_pkt_api.h" #include "iot_ipc.h" #include "iot_plc_lib.h" #include "iot_dbglog_api.h" #include "iot_config.h" /* driver includes */ #include "iot_clock.h" #include "iot_uart.h" #include "iot_led.h" /* cli includes */ #include "iot_cli.h" #include "iot_uart_h.h" /* debug includes*/ #include "dbg_io.h" #include "gpio.h" #include "apb_glb_reg.h" #include "hw_reg_api.h" #include "gpio_mtx_reg.h" #include "pin_rf.h" #include "gpio_mtx.h" #include "gpio_reg.h" #include "i2c_reg.h" #include "iot_i2c_api.h" #include "iot_gpio_api.h" #include "xc7027_reg.h" #include "ov9282_reg.h" struct mp3336_module_reg_t { uint8_t reg; uint8_t val; }; const struct mp3336_module_reg_t mp3336_flash_mode[] = { {0x1, 0xE6}, //{0x6, 0x33}, {0x6, 200}, {0x3, 0x18}, {0x1, 0xF6}, }; iot_i2c_module_cfg_t g_cfg = {0}; iot_i2c_module_cfg_t g_sgm_cfg = {0}; extern int platform_init(); os_task_h test_init_handle; int xc7027_gpio_rst(uint8_t gpio) { uint8_t r = ERR_FAIL; r = iot_gpio_open_as_output(gpio); if(r != 0) { iot_printf("\ngpio_set_direction failed!\n"); } if (0 != iot_gpio_value_set(gpio, 1)) { iot_printf("\n WRITE 0 FAILED\n"); r = ERR_FAIL; } else { os_delay(1000); if (0 != iot_gpio_value_set(gpio, 0)) { iot_printf("\n WRITE 1 FAILED\n"); r = ERR_FAIL; } else { r = ERR_OK; } os_delay(1000); if (0 != iot_gpio_value_set(gpio, 1)) { iot_printf("\n WRITE 1 FAILED\n"); r = ERR_FAIL; } else { r = ERR_OK; } } return r; } int xc7027_write_command(uint8_t addr, uint8_t reg1, uint8_t reg2, uint8_t val) { uint8_t ret = 0; char buf[4] = {0}; buf[0] = reg1; buf[1] = reg2; buf[2] = val; ret = iot_i2c_write(g_cfg.port, addr, buf, 3); os_delay(10); return ret; } int ov9282_write_command(uint8_t addr, uint16_t reg, uint8_t val) { uint8_t ret = 0; char buf[4] = {0}; buf[0] = reg >> 8; buf[1] = reg & 0xff; buf[2] = val; ret = iot_i2c_write(g_cfg.port, addr, buf, 3); os_delay(10); return ret; } int xc7027_read_command(uint8_t addr, uint16_t reg, uint8_t *data, uint8_t len) { uint8_t ret = 0; char buf[4] = {0}; buf[0] = reg >> 8; buf[1] = reg & 0xff; ret = iot_i2c_write(g_cfg.port, addr, buf, 2); if (ret) { iot_printf("xc7027_read_command write addr error\n"); return ret; } os_delay(10); ret = iot_i2c_read(g_cfg.port, addr, (char *)data, len); if (ret) { iot_printf("xc7027_read_command get value error\n"); return ret; } return ret; } int mp3336_write_command(uint8_t addr, uint8_t reg, uint8_t val) { uint8_t ret = 0; char buf[4] = {0}; buf[0] = reg; buf[1] = val; ret = iot_i2c_write(g_sgm_cfg.port, addr, buf, 2); os_delay(10); return ret; } int mp3336_read_command(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { uint8_t ret = 0; char buf[4] = {0}; buf[0] = reg; ret = iot_i2c_write(g_sgm_cfg.port, addr, buf, 1); if (ret) { iot_printf("xc7027_read_command write addr error\n"); return ret; } os_delay(10); ret = iot_i2c_read(g_sgm_cfg.port, addr, (char *)data, len); if (ret) { iot_printf("xc7027_read_command get value error\n"); return ret; } return ret; } uint8_t g_xc7027_addr = 0x1b; uint8_t g_ov9282_addr = 0x60; uint8_t g_mp3336_addr = 0x27; uint8_t g_xc7027_rst_gpio = 56; uint8_t g_cfg_test = 0; void mp3336_flash_mode_cfg() { uint8_t val = 0; int reg_len = 0; uint8_t reg; reg_len = sizeof(mp3336_flash_mode)/sizeof(struct mp3336_module_reg_t); for(uint32_t i = 0; i