1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef UINPUT_CONFIG_PARSER_H 17 #define UINPUT_CONFIG_PARSER_H 18 19 #include "hdf_types.h" 20 #include "device_resource_if.h" 21 22 #define REG_CONFIG_LEN 2 23 24 typedef struct { 25 uint8_t devType; 26 const char *devName; 27 uint32_t resolutionX; 28 uint32_t resolutionY; 29 } BoardAttrCfg; 30 31 typedef struct { 32 uint8_t busNum; 33 uint16_t clkGpio; 34 uint16_t dataGpio; 35 uint32_t i2cClkReg[REG_CONFIG_LEN]; 36 uint32_t i2cDataReg[REG_CONFIG_LEN]; 37 } BoardI2cCfg; 38 39 typedef struct { 40 uint8_t busNum; 41 uint16_t clkGpio; 42 uint16_t csGpio; 43 uint16_t misoGpio; 44 uint16_t mosiGpio; 45 uint32_t spiClkReg[REG_CONFIG_LEN]; 46 uint32_t spiCsReg[REG_CONFIG_LEN]; 47 uint32_t spiMisoReg[REG_CONFIG_LEN]; 48 uint32_t spiMosiReg[REG_CONFIG_LEN]; 49 } BoardSpiCfg; 50 51 typedef struct { 52 uint8_t busType; 53 union { 54 BoardI2cCfg i2c; 55 BoardSpiCfg spi; 56 }; 57 } BoardBusCfg; 58 59 typedef struct { 60 uint16_t rstGpio; 61 uint16_t intGpio; 62 uint32_t rstPinReg[REG_CONFIG_LEN]; 63 uint32_t intPinReg[REG_CONFIG_LEN]; 64 } BoardPinCfg; 65 66 typedef struct { 67 uint16_t pwrType; 68 uint16_t pwrNum; 69 uint32_t pwrValue; 70 } PwrDesc; 71 72 typedef struct { 73 PwrDesc vcc; 74 PwrDesc vci; 75 } BoardPwrCfg; 76 77 typedef struct { 78 uint8_t capacitanceTest; 79 uint8_t gestureMode; 80 uint8_t gloverMOde; 81 uint8_t coverMode; 82 uint8_t chargeMode; 83 uint8_t knuckleMode; 84 } BoardFeatureCfg; 85 86 typedef struct { 87 const struct DeviceResourceNode *boardNode; 88 BoardAttrCfg attr; 89 BoardBusCfg bus; 90 BoardPinCfg pins; 91 BoardPwrCfg power; 92 BoardFeatureCfg feature; 93 } TouchBoardCfg; 94 95 typedef struct { 96 uint32_t *buf; 97 uint32_t count; 98 } SeqArray; 99 100 typedef struct { 101 SeqArray pwrOn; 102 SeqArray pwrOff; 103 SeqArray resume; 104 SeqArray suspend; 105 } ChipPwrSeq; 106 107 typedef struct { 108 uint16_t irqFlag; 109 uint8_t wordMode; // 0, 1 , 2, 3 polar & phase 110 uint8_t commMode; // 2:DMA 1:polling 0:interrupt 111 uint32_t maxSpeed; 112 uint32_t csSetupTime; 113 uint32_t csHoldTime; 114 uint32_t csRecoveryTime; 115 } ChipSpiCfg; 116 117 typedef struct { 118 uint16_t irqFlag; 119 uint32_t commAddr; // i2c device addr 120 uint32_t maxSpeed; 121 } ChipI2cCfg; 122 123 typedef struct { 124 uint8_t busType; 125 union { 126 ChipI2cCfg chipI2c; 127 ChipSpiCfg chipSpi; 128 }; 129 } ChipBusCfg; 130 131 typedef struct { 132 const struct DeviceResourceNode *chipNode; 133 const char *chipName; 134 const char *vendorName; 135 const char *chipInfo; 136 uint16_t chipVersion; 137 ChipBusCfg bus; 138 ChipPwrSeq pwrSeq; 139 } TouchChipCfg; 140 141 typedef struct { 142 struct HdfDeviceObject *hdfKeyDev; 143 const char *keyName; 144 uint8_t devType; 145 uint16_t gpioNum; 146 uint16_t irqFlag; 147 uint32_t debounceTime; 148 } KeyChipCfg; 149 150 typedef struct { 151 struct HdfDeviceObject *hdfEncoderDev; 152 uint8_t devType; 153 uint16_t gpioClk; 154 uint16_t gpioData; 155 uint16_t gpioSW; 156 } EncoderCfg; 157 158 typedef struct { 159 struct HdfDeviceObject *hdfInfraredDev; 160 const char *infraredName; 161 uint8_t devType; 162 uint16_t gpioNum; 163 uint16_t irqFlag; 164 } InfraredCfg; 165 166 int32_t ParseTouchBoardConfig(const struct DeviceResourceNode *node, TouchBoardCfg *config); 167 int32_t ParseTouchChipConfig(const struct DeviceResourceNode *node, TouchChipCfg *config); 168 int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config); 169 int32_t ParseEncoderConfig(const struct DeviceResourceNode *node, EncoderCfg *config); 170 int32_t ParseInfraredConfig(const struct DeviceResourceNode *node, InfraredCfg *config); 171 172 #endif // UINPUT_CONFIG_PARSER_H