# DALTLMM APIs Source: [https://docs.qualcomm.com/doc/80-88500-4/topic/29_DALTLMM_interface_description.html](https://docs.qualcomm.com/doc/80-88500-4/topic/29_DALTLMM_interface_description.html) The DALTLMM APIs provide functionalities for GPIO configuration, read, write, and so on. The actual implementation of these APIs is in DALTLMM.c. ## DalTlmm\_GetGpioId This API retrieves a GPIO identifier corresponding to an input string. DALResult DalTlmm_GetGpioId(DalDeviceHandle * _h, const char* pszGpio, DALGpioIdType* pnGpioId);Copy to clipboard - The string name must exactly match the expected name for the hardware functionality as defined in the xml file that is described in runtime configuration. For more information, see [GPIO configurations](https://docs.qualcomm.com/doc/80-88500-4/topic/26_GPIO_configurations.html). - If the API returns successfully, the retrieved ID is associated with the alternate function as defined in the xml file. ## DalTlmm\_ConfigGpioId When this function is called to configure the GPIO, the nGpioId passed in (which is requested through DalTlmm\_GetGpioId) is checked to see whether it matches the internal ID stored in the data structure ganGpioIdUsers. If yes, it configures the GPIO. If not, it returns DAL\_ERROR. DALResult DalTlmm_ConfigGpioId(DalDeviceHandle * _h, DALGpioIdType nGpioId, DalTlmm_GpioConfigIdType* pUserSettings);Copy to clipboard ## DalTlmm\_ConfigGpioIdInactive This function sets the GPIO to its sleep configuration based on the GPIO ID passed in. The sleep configuration stored in the TLMM\_GPIO\_LP\_CFGn is used. DALResult DalTlmm_ConfigGpioIdInactive(DalDeviceHandle * _h, DALGpioIdType nGpioId);Copy to clipboard This function also checks the nGpioId to see whether it matches the ID stored internally. If yes, it configures the GPIO. If not, it returns DAL\_ERROR. ## DalTlmm\_SelectGpioIdMode This API sets a GPIO to a general purpose I/O pin or alternate function based on the eMode parameter. It also checks nGpioId to verify that it matches the GPIO ID that is stored in the xml file described in runtime configuration. For more information, see [GPIO configurations](https://docs.qualcomm.com/doc/80-88500-4/topic/26_GPIO_configurations.html). DALResult DalTlmm_SelectGpioIdMode( DalDeviceHandle * _h, DALGpioIdType nGpioId, DalGpioModeType eMode, DalTlmm_GpioConfigIdType* pUserSettings);Copy to clipboard - If nGpioId does not match the internal GPIO ID, it returns DAL\_ERROR. - If eMode is TRUE, the GPIO is set as a general purpose I/O pin. If eMode is FALSE, the GPIO is set to its alternate function based on nGpioId. ## DalTlmm\_GpioIdIn This function checks the nGpioId passed in to see whether it matches the ID stored in the internal data structure. If stored ID is not matched, it returns DAL\_ERROR. If stored ID is matched, it reads out the GPIO state. DALResult DalTlmm_GpioIdIn(DalDeviceHandle * _h, DALGpioIdType nGpioId, DALGpioValueType *eValue);Copy to clipboard ## DalTlmm\_GpioIdOut This function checks the nGpioId passed in to see whether it matches the ID stored in the internal data structure. If stored ID does not match, it returns DAL\_ERROR. If stored ID is matched, it sets the GPIO state. DALResult DalTlmm_GpioIdOut(DalDeviceHandle * _h, DALGpioIdType nGpioId, DALGpioValueType eValue);Copy to clipboard A GPIO must be configured as GP OUTPUT for this function to take effect. ## DalTlmm\_GetCurrentConfig This function retrieves the currently programmed configuration for a specific GPIO. DALResult DalTlmm_GetCurrentConfig(DalDeviceHandle *_h, uint32 gpio_number, DALGpioSignalType *gpio_config);Copy to clipboard It reads and returns the GPIO configuration from the hardware register. ## DalTlmm\_ReleaseGpioId This function releases the lock that is automatically applied when the GPIO ID is retrieved. Only the owner of GPIO ID can release the lock. DALResult DalTlmm_ReleaseGpioId( DalDeviceHandle * _h, DALGpioIdType nGpioId);Copy to clipboard After the lock is released, other modules can use a GPIO. The following code sample shows how to get a GPIO ID and configure a GPIO: DalDeviceHandle *htlmm; DALGpioIdType Gpio0_Id; DalTlmm_GpioConfigIdType Gpio0_ConfigId; DALResult result; Gpio0_ConfigId.eDirection = DAL_GPIO_OUTPUT; Gpio0_ConfigId.ePull = DAL_GPIO_NO_PULL; Gpio0_ConfigId.eDriveStrength = DAL_GPIO_2MA; // Create a TLMM handle result = DAL_DeviceAttach(DALDEVICEID_TLMM, &htlmm); if (htlmm == NULL || result != DAL_SUCCESS) { goto error; } // Get GPIO ID for GPIO0 result = DalTlmm_GetGpioId(htlmm, “qup_l0[0]”, &Gpio0_Id); if (result != DAL_SUCCESS) { goto error; } // Set GPIO0 to alternate function 1 with NO_PULL, 2mA drive strength result = DalTlmm_ConfigGpioId(htlmm, Gpio0_Id, &Gpio0_ConfigId); if (result != DAL_SUCCESS) { goto error; } // GPIO operation … // Set GPIO0 to general purpose OUTPUT, NO_PULL, 2mA drive strength result = DalTlmm_SelectGpioIdMode(htlmm, Gpio0_Id, DAL_GPIO_MODE_IO, &Gpio0_ConfigId); if (result != DAL_SUCCESS) { goto error; } // Set GPIO0 low result = DalTlmm_GpioIdOut(htlmm, Gpio0_Id, DAL_GPIO_LOW_VALUE); if (result != DAL_SUCCESS) { goto error; } // Release GPIO0 result = DalTlmm_ReleaseGpioId(htlmm, Gpio0_Id); if (result != DAL_SUCCESS) { goto error; } // Remove the handle DAL_DeviceDetach(htlmm); Copy to clipboard ## DalTlmm\_ConfigGpio Based on the parameters passed in, this function configures a single GPIO. It requires a DAL device handle. - If the enabled value is DAL\_TLMM\_GPIO\_DISABLE, the sleep configuration of the GPIO is applied instead of the configuration passed in. - If another module uses DalTlmm\_ConfigGpioId to program a GPIO, which locks the GPIO, using this API returns an error because it cannot access the GPIO without the appropriate ID. DALResult DalTlmm_ConfigGpio(DALDeviceHandle* _h, DALGpioSignalType gpio_config, DALGpioEnableType enable); Copy to clipboard If the GPIO is previously configured using DalTlmm\_ConfigGpioId, calling DalTlmm\_ConfigGpio does not take effect because the GPIO is locked in software. The following is an example of using the DALTLMM API to configure GPIO 0 as a pull-up input pin and disable it after usage: DalDeviceHandle *htlmm; DALResult result; uint32 gpio0_cfg = DAL_GPIO_CFG(0, 0, DAL_GPIO_INPUT, \ DAL_GPIO_PULL_UP, DAL_GPIO_2MA); // Create a TLMM handle result = DAL_DeviceAttach(DALDEVICEID_TLMM, &htlmm); if (result != DAL_SUCCESS) { goto error; } result = DalDevice_Open(htlmm, DAL_OPEN_SHARED); if (result != DAL_SUCCESS) { goto error; } // Enable GPIO0 result = DalTlmm_ConfigGpio(htlmm, gpio0_sig, DAL_TLMM_GPIO_ENABLE); if (result != DAL_SUCCESS) { goto error; } // GPIO operation … // Disable GPIO0 result = DalTlmm_ConfigGpio(htlmm, gpio0_sig, DAL_TLMM_GPIO_DISABLE); if (result != DAL_SUCCESS) { goto error; } // Remove the handle DalDevice_Close(htlmm); DAL_DeviceDetach(htlmm); Copy to clipboard Note: A TLMM device handle must be created before calling any DALTLMM APIs. Disabling a GPIO causes the TLMM driver to apply the sleep configuration on the GPIO. ## DalTlmm\_ConfigGpioGroup This function configures a group of GPIOs passed in as a pointer to an array of configurations. It returns a DAL\_ERROR result when the group value passed in is not of the correct value. Depending on the enable flag enumeration, the GPIO group is either configured to its active configuration or its sleep configuration. DALResult DalTlmm_ConfigGpioGroup ( DalDeviceHandle * _h, DALGpioEnableType enable, DALGpioSignalType* gpio_group, uint32 size ); Copy to clipboard ## DalTlmm\_GetCurrentConfig This API returns the current configuration of the GPIO. It reads the configuration from the hardware register and converts it into a DALGpioSignalType using the DAL\_GPIO\_CFG macro. DALResult DalTlmm_GetCurrentConfig ( DalDeviceHandle *_h, uint32 gpio_number, DALGpioSignalType *gpio_config ); Copy to clipboard ## DalTlmm\_GetGpioNumber This function returns the GPIO number based on the GPIO configuration passed in. DALResult DalTlmm_GetGpioNumber ( DalDeviceHandle *_h, DALGpioSignalType gpio_config, uint32 *gpio_number ); Copy to clipboard ## DalTlmm\_GetGpioStatus This API returns the status (active or inactive, that is, whether the GPIO is in sleep configuration) of a GPIO. DALResult DalTlmm_GetGpioStatus ( DalDeviceHandle *_h, uint32 gpio_number, DALGpioStatusType *status ); Copy to clipboard ## DalTlmm\_GetInactiveConfig This API returns the sleep configuration of a GPIO. DALResult DalTlmm_GetInactiveConfig ( DalDeviceHandle *_h, uint32 gpio_number, DALGpioSignalType *gpio_config ); Copy to clipboard ## DalTlmm\_SetInactiveConfig The following API sets the inactive configuration of a GPIO. It writes the low-power configuration into the TLMM\_GPIO\_LP\_CFGn register. The low-power configuration parameter should use the DAL\_GPIO\_CFG\_OUT macro to specify the output state if the GPIO is set to an output pin during sleep. DALResult DalTlmm_SetInactiveConfig ( DalDeviceHandle *_h, uint32 gpio_number, DALGpioSignalType *gpio_config ); Copy to clipboard ## DalTlmm\_SetPort This API sets a specific TLMM port, for example, user identity module (UIM), for certain GPIOs. DALResult DalTlmm_SetPort ( DalDeviceHandle *_h, DALGpioPortType port, uint32 value ) Copy to clipboard ## DalTlmm\_GpioIn This function returns the value DAL\_GPIO\_HIGH\_VALUE or DAL\_GPIO\_LOW\_VALUE corresponding to the input value of the GPIO. DALResult DalTlmm_GpioIn ( DalDeviceHandle *_h, DALGpioSignalType gpio_config, DALGpioValueType*value ); Copy to clipboard ## DalTlmm\_GpioOut This function drives an output GPIO pin to the High or Low state. The acceptable values are DAL\_GPIO\_HIGH\_VALUE and DAL\_GPIO\_LOW\_VALUE. Note: The values do not take effect if the ownership is not configured correctly. DALResult DalTlmm_GpioOut ( DalDeviceHandle *_h, DALGpioSignalType gpio_config, DALGpioValueType value ); Copy to clipboard This API sets a group of output GPIOs to the same state at one time. DALResult DalTlmm_GpioOutGroup ( DalDeviceHandle *_h, DALGpioSignalType *gpio_group, uint32 size, DALGpioValueType value ); Copy to clipboard **Parent Topic:** [GPIO DAL driver](https://docs.qualcomm.com/doc/80-88500-4/topic/25_GPIO_DAL_driver.html) Last Published: Aug 18, 2023 [Previous Topic DALTLMM data definitions](https://docs.qualcomm.com/bundle/publicresource/80-88500-4/topics/28_DALTLMM_data_definitions.md) [Next Topic GPIO configuration in XBL](https://docs.qualcomm.com/bundle/publicresource/80-88500-4/topics/30_Customize_GPIO_in_XBL.md)