# TLMM interface of HAL

Source: [https://docs.qualcomm.com/doc/80-88500-4/topic/23_TLMM_interface_of_HAL.html](https://docs.qualcomm.com/doc/80-88500-4/topic/23_TLMM_interface_of_HAL.html)

The GPIO driver is built on top of the hardware abstraction layer (HAL) framework. The HAL top-level mode multiplexer (TLMM) contains type definitions that define the GPIO direction, pull, and drive strength.

## Type definitions

    Typedef enum
    {
     HAL_TLMM_NO_PULL  = 0,
     HAL_TLMM_PULL_DOWN = 1,
     HAL_TLMM_KEEPER  = 2,
     HAL_TLMM_PULL_UP  = 3
    }HAL_tlmm_PullType;
    
    typedef enum
    {
     HAL_TLMM_INPUT = 0,
     HAL_TLMM_OUTPUT = 1,
    }HAL_tlmm_DirType;
    
    typedef enum
    {
     HAL_TLMM_DRIVE_2MA = 0,
     HAL_TLMM_DRIVE_4MA = 1,
     HAL_TLMM_DRIVE_6MA = 2,
     HAL_TLMM_DRIVE_8MA = 3,
     HAL_TLMM_DRIVE_10MA = 4,
     HAL_TLMM_DRIVE_12MA = 5,
     HAL_TLMM_DRIVE_14MA = 6,
     HAL_TLMM_DRIVE_16MA = 7
    }HAL_tlmm_DriveType;
    
    /*
    The HAL_tlmm_GpioType is the basic GPIO configuration element. It 
    contains information about the configuration of a particular GPIO. 
     */
    typedef struct
    {
     uint8 nFunc;    /* Function select for a GPIO (0-15). */
     uint8 nDir;     /* Direction select for a GPIO (INPUT/OUTPUT). */
     uint8 nPull;    /* Pull (PULL-DOWN, PULL-UP, KEEPER, NO-PULL */
     uint8 nDrive;    /* Drive strength (2-16 mA in even increments). */
    }HAL_tlmm_GpioType;Copy to clipboard

## Macros

Some of the HAL macros are visible to the TLMM driver. These macros extract the GPIO configuration information:

- HAL\_GPIO\_NUMBER – Returns the GPIO number based on configuration data
- HAL\_OUTVAL – Extracts the output state from configuration data
- HAL\_DRVSTR\_VAL – Returns the driving strength
- HAL\_PULL\_VAL – Returns the pull direction
- HAL\_DIR\_VAL – Returns direction information (input or output)
- HAL\_FUNC\_VAL – Returns the function value; 0 is general purpose, nonzero is an alternate function

## Functions

The HAL TLMM API descriptions are provided to help you understand the GPIO driver. Only the GPIO driver should use these functions. The application software should not call these functions directly.

- Initialization
          
    The following function initializes the hardware buffers and address structures. It returns the pointer to the version of the HAL module via the input parameter.

        void HAL_tlmm_Init ( char ** ppszVersion );Copy to clipboard
- Configure GPIOs
          
    The following function configures the specified GPIO to the requested configuration:

        void HAL_tlmm_ConfigGpio(uint32 nWhichConfig);Copy to clipboard

    A few other functions that involve GPIO configuration include the following:

        void HAL_tlmm_ConfigGpioGroup(const uint32 nWhichGpioSet[],uint16 nWhatSize );Copy to clipboard

    The following function obtains the current GPIO configuration from the GPIO\_CFGn register:

        void HAL_tlmm_GetConfig( uint32 nGpioNumber, HAL_tlmm_GpioType* tGpio );Copy to clipboard
- Read and write
          
    The following function reads values from the GPIO\_IN registers of GPIOs. One GPIO is read each time this function is called. The value is returned as a Boolean type. TRUE denotes High state, and FALSE denotes Low state.

        Boolean HAL_tlmm_ReadGpio( uint32 nWhichConfig );Copy to clipboard

    To write a value to the GPIO pin, that is, push a value to the GPIO\_OUT register, the following function is called. As with the HAL\_tlmm\_ReadGpio, the value to be written is stored in a Boolean type parameter.

        void HAL_tlmm_WriteGpio( uint32 nWhichConfig, boolean bValue );Copy to clipboard

    In the TLMM driver, GPIOs are divided into different groups, such as GPIO\_GROUP\_AUDIO\_PCM, GPIO\_GROUP\_USB, GPIO\_GROUP\_SDC1. Sometimes, there is a need to write to a group of GPIOs at the same time. The following HAL API is constructed for this purpose:

        void HAL_tlmm_WriteGpioGroup(const uint32 nWhichConfigSet[],uint16 nWhatSize, boolean bWriteVal); Copy to clipboard

    The following function reads the output value of an output GPIO pin from its GPIO\_IN\_OUTn register:

        boolean HAL_tlmm_GetOutput( uint32 nWhichGpio );Copy to clipboard
- Set port
          
    The set port function sets specific TLMM registers so that the associated GPIOs are set to a particular function, that is, it can set UIM1 and UIM2 pad control.

        void HAL_tlmm_SetPort(HAL_tlmm_PortType ePort, uint32 mask, uint32 value);Copy to clipboard

**Parent Topic:** [GPIO hardware abstraction layer](https://docs.qualcomm.com/doc/80-88500-4/topic/22_GPIO_HAL_and_DAL.html)

Last Published: Aug 18, 2023

[Previous Topic
GPIO hardware abstraction layer](https://docs.qualcomm.com/bundle/publicresource/80-88500-4/topics/22_GPIO_HAL_and_DAL.md) [Next Topic
GPIO interrupt interface of HAL](https://docs.qualcomm.com/bundle/publicresource/80-88500-4/topics/24_GPIO_interrupt_interface_of_HAL.md)