1e41f4b71Sopenharmony_ci# Pin 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci### Function 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe pin module, also called pin controller, manages pin resources of the system on a chip (SoC) and implements the pin multiplexing function. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciThe pin module provides a set of APIs for pin management, including: 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci- Obtaining or releasing a pin description handle 12e41f4b71Sopenharmony_ci- Setting or obtaining the pull type (pull-up, pull-down, or floating) of a pin 13e41f4b71Sopenharmony_ci- Setting or obtaining the pull strength of a pin 14e41f4b71Sopenharmony_ci- Setting or obtaining the function of a pin to implement pin multiplexing 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci### Basic Concepts 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciPin is a software concept designed to uniformly manage SoC pins, implement pin multiplexing, and set electrical features of pins. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci- SoC 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci An SoC is a chip that integrates microprocessors, analog IP cores, digital IP cores, and memory for specific purposes. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci- Pin multiplexing 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci When the number of pins of a chip cannot handle the increasing connection requests, you can set software registers to make the pins to work in different states. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci### Working Principles 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ciIn the Hardware Driver Foundation (HDF), the pin module uses the unified service mode for API adaptation. In this mode, a device service is used as the pin manager to handle access requests from the devices of the same type in a unified manner. The unified service mode applies to the scenario where there are many device objects of the same type. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciIn the unified service mode, the core layer manages all controllers in a unified manner and publishes a service for the interface layer. That is, the driver does not need to publish a service for each controller. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciThe pin module is divided into the following layers: 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci- Interface layer: provides APIs for obtaining a pin, setting or obtaining the pull type, pull strength, and function of a pin, and releasing a pin. 37e41f4b71Sopenharmony_ci- Core layer: provides the capabilities of matching pin resources, adding and removing a pin controller, and managing pins. The core layer interacts with the adaptation layer through hook functions. 38e41f4b71Sopenharmony_ci- Adaptation layer: instantiates the hook functions to implement specific features. 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Figure 1** Unified service mode 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci### Constraints 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciThe pin module supports only the LiteOS-A kernel of the small system. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci## Usage Guidelines 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci### When to Use 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciThe pin module is a software concept used to manage pin resources. You can set the function, pull type, and pull strength of pins to implement pin multiplexing. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci### Available APIs 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ciThe following table describes the APIs of the pin module. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**Table 1** Pin driver APIs 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci| **API** | **Description** | 60e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------- | 61e41f4b71Sopenharmony_ci| DevHandle PinGet(const char *pinName) | Obtains a pin description handle.| 62e41f4b71Sopenharmony_ci| void PinPut(DevHandle handle) | Releases the pin description handle.| 63e41f4b71Sopenharmony_ci| int32_t PinSetPull(DevHandle handle, enum PinPullType pullType) | Sets the pull type of a pin.| 64e41f4b71Sopenharmony_ci| int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType) | Obtains the pull type of a pin.| 65e41f4b71Sopenharmony_ci| int32_t PinSetStrength(DevHandle handle, uint32_t strength) | Sets the pull strength of a pin.| 66e41f4b71Sopenharmony_ci| int32_t PinGetStrength(DevHandle handle, uint32_t *strength) | Obtains the pull strength of a pin.| 67e41f4b71Sopenharmony_ci| int32_t PinSetFunc(DevHandle handle, const char *funcName) | Sets the pin function.| 68e41f4b71Sopenharmony_ci| int32_t PinGetFunc(DevHandle handle, const char **funcName) | Obtains the pin function. | 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci> **NOTE** 71e41f4b71Sopenharmony_ci> 72e41f4b71Sopenharmony_ci>All the pin APIs described in this document can be used in kernel mode and user mode. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci### How to Develop 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciThe following figure illustrates how to use pin driver APIs. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci **Figure 2** Using pin driver APIs<br> 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci#### Obtaining a Pin Description Handle 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciBefore performing an operation on a pin, use **PinGet()** to obtain the pin description handle based on the pin name. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci```c 86e41f4b71Sopenharmony_ciDevHandle PinGet(const char *pinName); 87e41f4b71Sopenharmony_ci``` 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Table 2** Description of PinGet 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci| Parameter | Description | 92e41f4b71Sopenharmony_ci| ---------- | ----------------------- | 93e41f4b71Sopenharmony_ci| pinName | Pointer to the pin name. | 94e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 95e41f4b71Sopenharmony_ci| NULL | The operation fails.| 96e41f4b71Sopenharmony_ci| handle | The operation is successful. The pin description handle obtained is returned. | 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciExample: Obtain the pin description handle of P18. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci```c 101e41f4b71Sopenharmony_ciDevHandle handle = NULL; // Pin description handle. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_cichar pinName = "P18"; // Pin name. 104e41f4b71Sopenharmony_cihandle = PinGet(pinName); 105e41f4b71Sopenharmony_ciif (handle == NULL) { 106e41f4b71Sopenharmony_ci HDF_LOGE("PinGet: get handle failed!\n"); 107e41f4b71Sopenharmony_ci return; 108e41f4b71Sopenharmony_ci} 109e41f4b71Sopenharmony_ci``` 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci#### Setting the Pull Type of a Pin 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ciUse **PinSetPull()** to set the pull type of a pin. 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci```c 116e41f4b71Sopenharmony_ciint32_t PinSetPull(DevHandle handle, enum PinPullType pullType); 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Table 3** Description of PinSetPull 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| Parameter | Description | 122e41f4b71Sopenharmony_ci| ---------- | ----------------------- | 123e41f4b71Sopenharmony_ci| handle | Pin description handle. | 124e41f4b71Sopenharmony_ci| pullType | Pull type to set. | 125e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 126e41f4b71Sopenharmony_ci| 0 | The operation is successful.| 127e41f4b71Sopenharmony_ci| Negative value | The operation fails.| 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciExample: Set the pull type to pull-up. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci```c 132e41f4b71Sopenharmony_ciint32_t ret; 133e41f4b71Sopenharmony_cienum PinPullType pullTypeNum; 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci/* Set the pull type of a pin. */ 136e41f4b71Sopenharmony_cipullTypeNum = 1; 137e41f4b71Sopenharmony_ciret = PinSetPull(handle, pullTypeNum); 138e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 139e41f4b71Sopenharmony_ci HDF_LOGE("PinSetPull: failed, ret %d\n", ret); 140e41f4b71Sopenharmony_ci return ret; 141e41f4b71Sopenharmony_ci} 142e41f4b71Sopenharmony_ci``` 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci#### Obtaining the Pull Type of a Pin 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ciUse **PinGetPull()** to obtain the pull type of a pin. 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci```c 149e41f4b71Sopenharmony_ciint32_t PinGetPull(DevHandle handle, enum PinPullType *pullType); 150e41f4b71Sopenharmony_ci``` 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Table 4** Description of PinGetPull 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci| Parameter | Description | 155e41f4b71Sopenharmony_ci| ---------- | ------------------------- | 156e41f4b71Sopenharmony_ci| handle | Pin description handle. | 157e41f4b71Sopenharmony_ci| pullType | Pointer to the pull type obtained.| 158e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 159e41f4b71Sopenharmony_ci| 0 | The operation is successful. | 160e41f4b71Sopenharmony_ci| Negative value | The operation fails. | 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ciExample: Obtain the pull type of a pin. 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci```c 165e41f4b71Sopenharmony_ciint32_t ret; 166e41f4b71Sopenharmony_cienum PinPullType pullTypeNum; 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci/* Obtain the pull type of a pin. */ 169e41f4b71Sopenharmony_ciret = PinGetPull(handle, &pullTypeNum); 170e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 171e41f4b71Sopenharmony_ci HDF_LOGE("PinGetPull: failed, ret %d\n", ret); 172e41f4b71Sopenharmony_ci return ret; 173e41f4b71Sopenharmony_ci} 174e41f4b71Sopenharmony_ci``` 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci#### Setting the Pull Strength of a Pin 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ciUse **PinSetStrength()** to set the pull type of a pin. 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci```c 181e41f4b71Sopenharmony_ciint32_t PinSetStrength(DevHandle handle, uint32_t strength); 182e41f4b71Sopenharmony_ci``` 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**Table 5** Description of PinSetStrength 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| Parameter | Description | 187e41f4b71Sopenharmony_ci| ---------- | ----------------------- | 188e41f4b71Sopenharmony_ci| handle | Pin description handle. | 189e41f4b71Sopenharmony_ci| strength | Pull strength to set. | 190e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 191e41f4b71Sopenharmony_ci| 0 | The operation is successful.| 192e41f4b71Sopenharmony_ci| Negative value | The operation fails.| 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ciExample: Set the pull strength of the pin to 2. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci```c 197e41f4b71Sopenharmony_ciint32_t ret; 198e41f4b71Sopenharmony_ciuint32_t strengthNum; 199e41f4b71Sopenharmony_ci/* Set the pull strength of the pin. */ 200e41f4b71Sopenharmony_cistrengthNum = 2; 201e41f4b71Sopenharmony_ciret = PinSetStrength(handle, strengthNum); 202e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 203e41f4b71Sopenharmony_ci HDF_LOGE("PinSetStrength: failed, ret %d\n", ret); 204e41f4b71Sopenharmony_ci return ret; 205e41f4b71Sopenharmony_ci} 206e41f4b71Sopenharmony_ci``` 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci#### Obtaining the Pull Strength of a Pin 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciUse **PinGetStrength()** to obtain the pull strength of a pin. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci```c 213e41f4b71Sopenharmony_ciint32_t PinGetStrength(DevHandle handle, uint32_t *strength); 214e41f4b71Sopenharmony_ci``` 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**Table 6** Description of PinGetStrength 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci| Parameter | Description | 219e41f4b71Sopenharmony_ci| ---------- | ------------------------- | 220e41f4b71Sopenharmony_ci| handle | Pin description handle. | 221e41f4b71Sopenharmony_ci| strength | Pointer to the pull strength obtained.| 222e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 223e41f4b71Sopenharmony_ci| 0 | The operation is successful. | 224e41f4b71Sopenharmony_ci| Negative value | The operation fails. | 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciExample: Obtain the pull strength of a pin. 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci```c 229e41f4b71Sopenharmony_ciint32_t ret; 230e41f4b71Sopenharmony_ciuint32_t strengthNum; 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci/* Obtain the pull strength of the pin. */ 233e41f4b71Sopenharmony_ciret = PinGetStrength(handle, &strengthNum); 234e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 235e41f4b71Sopenharmony_ci HDF_LOGE("PinGetStrength: failed, ret %d\n", ret); 236e41f4b71Sopenharmony_ci return ret; 237e41f4b71Sopenharmony_ci} 238e41f4b71Sopenharmony_ci``` 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci#### Setting the Pin Function 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciThe pin function refers to the multiplexed pin function. The function of each pin is different. For details about the pin function name, see **//device/soc/hisilicon/hi3516dv300/sdk_liteos/hdf_config/pin/pin_config.hcs**. 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ciUse **PinSetFunc()** to set the pin function. 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci```c 247e41f4b71Sopenharmony_ciint32_t PinSetFunc(DevHandle handle, const char *funcName); 248e41f4b71Sopenharmony_ci``` 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Table 7** Description of PinSetFunc 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci| Parameter | Description | 253e41f4b71Sopenharmony_ci| ---------- | ------------------- | 254e41f4b71Sopenharmony_ci| handle | Pin description handle. | 255e41f4b71Sopenharmony_ci| funcName | Pointer to the pin function to set. | 256e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 257e41f4b71Sopenharmony_ci| 0 | The operation is successful.| 258e41f4b71Sopenharmony_ci| Negative value | The operation fails.| 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ciExample: Set the pin function to LSADC_CH1 (ADC channel 1). 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci```c 263e41f4b71Sopenharmony_ciint32_t ret; 264e41f4b71Sopenharmony_cichar funcName = "LSADC_CH1"; 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci/* Sets the pin function. */ 267e41f4b71Sopenharmony_ciret = PinSetFunc(handle, funcName); 268e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 269e41f4b71Sopenharmony_ci HDF_LOGE("PinSetFunc: failed, ret %d\n", ret); 270e41f4b71Sopenharmony_ci return ret; 271e41f4b71Sopenharmony_ci} 272e41f4b71Sopenharmony_ci``` 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci#### Obtaining the Pin Function 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ciUse **PinGetFunc()** to obtain the pin function. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci```c 279e41f4b71Sopenharmony_ciint32_t PinGetFunc(DevHandle handle, const char **funcName); 280e41f4b71Sopenharmony_ci``` 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**Table 8** Description of PinGetFunc 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci| Parameter | Description | 285e41f4b71Sopenharmony_ci| ---------- | --------------------- | 286e41f4b71Sopenharmony_ci| handle | Pin description handle. | 287e41f4b71Sopenharmony_ci| funcName | Pointer to the function name obtained.| 288e41f4b71Sopenharmony_ci| **Return Value**| **Description** | 289e41f4b71Sopenharmony_ci| 0 | The operation is successful. | 290e41f4b71Sopenharmony_ci| Negative value | The operation fails. | 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciExample: Obtain the pin function. 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci```c 295e41f4b71Sopenharmony_ciint32_t ret; 296e41f4b71Sopenharmony_cichar *funcName = NULL; 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci/* Obtain the pin function. */ 299e41f4b71Sopenharmony_ciret = PinGetFunc(handle, &funcName); 300e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 301e41f4b71Sopenharmony_ci HDF_LOGE("PinGetFunc: failed, ret %d\n", ret); 302e41f4b71Sopenharmony_ci return ret; 303e41f4b71Sopenharmony_ci} 304e41f4b71Sopenharmony_ci``` 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci#### Releasing a Pin Description Handle 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ciAfter the operations on a pin are complete, use **PinPut()** to release the pin description handle. 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci```c 311e41f4b71Sopenharmony_civoid PinPut(DevHandle handle); 312e41f4b71Sopenharmony_ci``` 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**Table 9** Description of PinPut 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci| Parameter | Description | 317e41f4b71Sopenharmony_ci| ---------- | -------------- | 318e41f4b71Sopenharmony_ci| handle | Pin description handle. | 319e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 320e41f4b71Sopenharmony_ci| NA | No value is returned. | 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ciExample: Release a pin description handle. 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci```c 325e41f4b71Sopenharmony_ciPinPut(handle); 326e41f4b71Sopenharmony_ci``` 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci## Example 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ciThe following uses the Hi3516D V300 development board as an example. The procedure is as follows: 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci1. Pass in the pin name to obtain the pin description handle. 333e41f4b71Sopenharmony_ci2. Set the pull type of the pin. If the operation fails, release the pin description handle. 334e41f4b71Sopenharmony_ci3. Obtain the pull type of the pin. If the operation fails, release the pin description handle. 335e41f4b71Sopenharmony_ci4. Set the pull strength of the pin. If the operation fails, release the pin description handle. 336e41f4b71Sopenharmony_ci5. Obtain the pin pull strength. If the operation fails, release the pin description handle. 337e41f4b71Sopenharmony_ci5. Set the pin function. If the operation fails, release the pin description handle. 338e41f4b71Sopenharmony_ci6. Obtain the pin function. If the operation fails, release the pin description handle. 339e41f4b71Sopenharmony_ci7. Release the pin description handle if no operation needs to be performed on the pin. 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci```c 342e41f4b71Sopenharmony_ci#include "hdf_log.h" /* Header file of the HDF log APIs. */ 343e41f4b71Sopenharmony_ci#include "pin_if.h" /* Header file of standard pin APIs. */ 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ciint32_t PinTestSample(void) 346e41f4b71Sopenharmony_ci{ 347e41f4b71Sopenharmony_ci int32_t ret; 348e41f4b71Sopenharmony_ci uint32_t strengthNum; 349e41f4b71Sopenharmony_ci enum PinPullType pullTypeNum; 350e41f4b71Sopenharmony_ci char pinName; 351e41f4b71Sopenharmony_ci char *funName; 352e41f4b71Sopenharmony_ci DevHandle handle = NULL; 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci /* Pin name. Set it to the actual pin name. */ 355e41f4b71Sopenharmony_ci pinName = "P18"; 356e41f4b71Sopenharmony_ci /* Obtain the pin description handle. */ 357e41f4b71Sopenharmony_ci handle = PinGet(pinName); 358e41f4b71Sopenharmony_ci if (handle == NULL) { 359e41f4b71Sopenharmony_ci HDF_LOGE("PinGet: pin get failed!\n"); 360e41f4b71Sopenharmony_ci return; 361e41f4b71Sopenharmony_ci } 362e41f4b71Sopenharmony_ci /* Set the pull type to pull-up for the pin. */ 363e41f4b71Sopenharmony_ci pullTypeNum = 1; 364e41f4b71Sopenharmony_ci ret = PinSetPull(handle, pullTypeNum); 365e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 366e41f4b71Sopenharmony_ci HDF_LOGE("PinSetPull: failed, ret %d\n", ret); 367e41f4b71Sopenharmony_ci goto ERR; 368e41f4b71Sopenharmony_ci } 369e41f4b71Sopenharmony_ci /* Obtain the pull type of the pin. */ 370e41f4b71Sopenharmony_ci ret = PinGetPull(handle, &pullTypeNum); 371e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 372e41f4b71Sopenharmony_ci HDF_LOGE("PinGetPull: failed, ret %d\n", ret); 373e41f4b71Sopenharmony_ci goto ERR; 374e41f4b71Sopenharmony_ci } 375e41f4b71Sopenharmony_ci /* Set the pull strength of the pin to 2. */ 376e41f4b71Sopenharmony_ci strengthNum = 2; 377e41f4b71Sopenharmony_ci ret = PinSetStrength(handle, strengthNum); 378e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 379e41f4b71Sopenharmony_ci HDF_LOGE("PinSetStrength: failed, ret %d\n", ret); 380e41f4b71Sopenharmony_ci goto ERR; 381e41f4b71Sopenharmony_ci } 382e41f4b71Sopenharmony_ci /* Obtain the pull strength of the pin. */ 383e41f4b71Sopenharmony_ci ret = PinGetStrength(handle, &strengthNum); 384e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 385e41f4b71Sopenharmony_ci HDF_LOGE("PinGetStrength: failed, ret %d\n", ret); 386e41f4b71Sopenharmony_ci goto ERR; 387e41f4b71Sopenharmony_ci } 388e41f4b71Sopenharmony_ci /* Set the pin function to LSADC_CH1. */ 389e41f4b71Sopenharmony_ci funName = "LSADC_CH1"; 390e41f4b71Sopenharmony_ci ret = PinSetFunc(handle, funName); 391e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 392e41f4b71Sopenharmony_ci HDF_LOGE("PinSetFunc: failed, ret %d\n", ret); 393e41f4b71Sopenharmony_ci goto ERR; 394e41f4b71Sopenharmony_ci } 395e41f4b71Sopenharmony_ci /* Obtain the pin function. */ 396e41f4b71Sopenharmony_ci ret = PinGetFunc(handle, &funcName); 397e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 398e41f4b71Sopenharmony_ci HDF_LOGE("PinGetFunc: failed, ret %d\n", ret); 399e41f4b71Sopenharmony_ci goto ERR; 400e41f4b71Sopenharmony_ci } 401e41f4b71Sopenharmony_ciERR: 402e41f4b71Sopenharmony_ci /* Release the pin description handle. */ 403e41f4b71Sopenharmony_ci PinPut(handle); 404e41f4b71Sopenharmony_ci return ret; 405e41f4b71Sopenharmony_ci} 406e41f4b71Sopenharmony_ci``` 407