1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #include "sys.h" 19 #include "analog.h" 20 #include "compiler.h" 21 #include "core.h" 22 #include "gpio.h" 23 #include "mspi.h" 24 #include "pm.h" 25 #include "stimer.h" 26 27 unsigned int g_chip_version = 0; 28 29 extern void pm_update_status_info(void); 30 31 /** 32 * @brief This function performs a series of operations of writing digital or analog registers 33 * according to a command table 34 * @param[in] pt - pointer to a command table containing several writing commands 35 * @param[in] size - number of commands in the table 36 * @return number of commands are carried out 37 */ 38 write_reg_table(const tbl_cmd_set_t * pt,int size)39int write_reg_table(const tbl_cmd_set_t *pt, int size) 40 { 41 int l = 0; 42 43 while (l < size) { 44 unsigned int cadr = ((unsigned int)0x80000000) | pt[l].adr; 45 unsigned char cdat = pt[l].dat; 46 unsigned char ccmd = pt[l].cmd; 47 unsigned char cvld = (ccmd & TCMD_UNDER_WR); 48 ccmd &= TCMD_MASK; 49 if (cvld) { 50 if (ccmd == TCMD_WRITE) { 51 write_reg8(cadr, cdat); 52 } else if (ccmd == TCMD_WAREG) { 53 analog_write_reg8(cadr, cdat); 54 } else if (ccmd == TCMD_WAIT) { 55 delay_us(pt[l].adr * 256 + cdat); 56 } 57 } 58 l++; 59 } 60 return size; 61 } 62 63 /********************************************************************************************************************** 64 * local function implementation * 65 *********************************************************************************************************************/ 66