WL865E4-P  36.07.001
M2MB GPIO

This section describes the M2MB APIs to perform various GPIO operations. More...

enum  M2MB_GPIO_IOCTL_REQUEST {
  M2MB_GPIO_IOCTL_SET_CFG,
  M2MB_GPIO_IOCTL_GET_CFG
}
 
enum  M2MB_GPIOINT_IOCTL_REQUEST {
  M2MB_GPIOINT_IOCTL_SET_CFG,
  M2MB_GPIOINT_IOCTL_GET_CFG,
  M2MB_GPIOINT_IOCTL_SET_TRIGGER_TYPE,
  M2MB_GPIOINT_IOCTL_GET_TRIGGER_TYPE,
  M2MB_GPIOINT_IOCTL_GET_INT_PRIO,
  M2MB_GPIOINT_IOCTL_GET_INT_MASK,
  M2MB_GPIOINT_IOCTL_GET_GPIO_NUM,
  M2MB_GPIOINT_IOCTL_SET_INT_EN,
  M2MB_GPIOINT_IOCTL_SET_INT_DIS,
  M2MB_GPIOINT_IOCTL_SET_TRIGGER_INT,
  M2MB_GPIOINT_IOCTL_GET_INT_PENDING,
  M2MB_GPIOINT_IOCTL_SET_CALLBACK_FN,
  M2MB_GPIOINT_IOCTL_GET_CALLBACK_FN,
  M2MB_GPIOINT_IOCTL_SET_CALLBACK_CTXT,
  M2MB_GPIOINT_IOCTL_GET_CALLBACK_CTXT
}
 
enum  M2MB_GPIO_DIRECTION_T {
  M2MB_GPIO_INPUT_E = 0,
  M2MB_GPIO_OUTPUT_E = 1,
  M2MB_GPIO_INVALID_DIR_E = 0x7fffffff
}
 
enum  M2MB_GPIO_PULL_T {
  M2MB_GPIO_NO_PULL_E = 0x0,
  M2MB_GPIO_PULL_DOWN_E = 0x1,
  M2MB_GPIO_PULL_UP_E = 0x2,
  M2MB_GPIO_INVALID_PULL_E = 0x7fffffff
}
 
enum  M2MB_GPIO_DRIVE_T {
  M2MB_GPIO_1P6MA_E = 0,
  M2MB_GPIO_2P7MA_E = 1,
  M2MB_GPIO_4P0MA_E = 2,
  M2MB_GPIO_INVALID_STRENGTH_E = 0x7fffffff
}
 
enum  M2MB_GPIO_VALUE_T {
  M2MB_GPIO_LOW_VALUE_E,
  M2MB_GPIO_HIGH_VALUE_E,
  M2MB_GPIO_INVALID_VALUE_E = 0x7fffffff
}
 
enum  M2MB_GPIOINT_TRIGGER_TYPE_T {
  M2MB_GPIOINT_TRIGGER_HIGH_LEVEL_E = 0,
  M2MB_GPIOINT_TRIGGER_LOW_LEVEL_E = 1,
  M2MB_GPIOINT_TRIGGER_RISING_EDGE_E = 2,
  M2MB_GPIOINT_TRIGGER_FALLING_EDGE_E = 3,
  M2MB_GPIOINT_TRIGGER_DUAL_EDGE_E = 4,
  M2MB_GPIOINT_TRIGGER_INVALID_E = 0x7fffffff
}
 
enum  M2MB_GPIOINT_INTERRUPT_PRIORITY_T {
  M2MB_GPIOINT_INTERRUPT_PRIORITY_HIGHEST_E = 0,
  M2MB_GPIOINT_INTERRUPT_PRIORITY_HIGH_E = 1,
  M2MB_GPIOINT_INTERRUPT_PRIORITY_MEDIUM_E = 2,
  M2MB_GPIOINT_INTERRUPT_PRIORITY_LOW_E = 3,
  M2MB_GPIOINT_INTERRUPT_PRIORITY_LOWEST_E = 4,
  M2MB_GPIOINT_INTERRUPT_PRIORITY_INVALID_E = 0x7fffffff
}
 
enum  M2MB_GPIOINT_INTERRUPT_MASK_T {
  M2MB_GPIOINT_INTERRUPT_MASKABLE_E = 0,
  M2MB_GPIOINT_INTERRUPT_NONMASKABLE_E = 1,
  M2MB_GPIOINT_INTERRUPT_MASK_INVALID_E = 0x7fffffff
}
 
typedef enum M2MB_GPIO_IOCTL_REQUEST M2MB_GPIO_IOCTL_REQUEST_T
 
typedef enum M2MB_GPIOINT_IOCTL_REQUEST M2MB_GPIOINT_IOCTL_REQUEST_T
 
typedef uint32_t M2MB_GPIO_ID_T
 
typedef uint32_t M2MB_GPIO_PIN_T
 
typedef void * M2MB_GPIOINT_ID_T
 
typedef uint32_t M2MB_GPIOINT_PIN_T
 
typedef uint32_t M2MB_GPIOINT_CALLBACK_DATA_T
 
typedef void(* M2MB_GPIOINT_CB_T) (M2MB_GPIOINT_CALLBACK_DATA_T)
 
INT32 m2mb_gpio_open (const CHAR *path, INT32 flags,...)
 Open a GPIO port. More...
 
INT32 m2mb_gpio_close (INT32 fd)
 Closes a GPIO port. More...
 
INT32 m2mb_gpio_ioctl (INT32 fd, M2MB_GPIO_IOCTL_REQUEST_T request,...)
 Configure the GPIO port. More...
 
SSIZE_T m2mb_gpio_read (INT32 fd, void *buf, SIZE_T nbyte)
 Read the GPIO port. More...
 
SSIZE_T m2mb_gpio_write (INT32 fd, const void *buf, SIZE_T nbyte)
 Write to GPIO port. More...
 
INT32 m2mb_gpioint_open (const CHAR *path, INT32 cfg,...)
 Open a GPIO port and enable the interrupt. More...
 
INT32 m2mb_gpioint_close (INT32 fd)
 Closes a GPIO port. More...
 
INT32 m2mb_gpioint_ioctl (INT32 fd, M2MB_GPIOINT_IOCTL_REQUEST_T request,...)
 Configure the GPIO port. More...
 

Detailed Description

This section describes the M2MB APIs to perform various GPIO operations.

Typedef Documentation

◆ M2MB_GPIO_ID_T

typedef uint32_t M2MB_GPIO_ID_T

SoC pin access ID.

This is a unique ID provided by the module to the client. Clients must pass this ID as a token with subsequent calls. Note that the clients should cache the ID.

Definition at line 91 of file m2mb_gpio.h.

◆ M2MB_GPIO_IOCTL_REQUEST_T

◆ M2MB_GPIO_PIN_T

typedef uint32_t M2MB_GPIO_PIN_T

Definition at line 93 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_CALLBACK_DATA_T

typedef uint32_t M2MB_GPIOINT_CALLBACK_DATA_T

GPIO interrupt callback data type.

This is the data type of the argument passed into the callback that is registered with the GPIO interrupt module. The value to pass will be given by the client at registration time.

Definition at line 218 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_CB_T

typedef void(* M2MB_GPIOINT_CB_T) (M2MB_GPIOINT_CALLBACK_DATA_T)

GPIO interrupt callback function definition.

GPIO interrupt clients will pass a function pointer of this format into the registration API.

Definition at line 226 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_ID_T

typedef void* M2MB_GPIOINT_ID_T

Definition at line 95 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_IOCTL_REQUEST_T

◆ M2MB_GPIOINT_PIN_T

typedef uint32_t M2MB_GPIOINT_PIN_T

GPIO pin no.

This is a GPIO pin no to be configured for Interrupt

Definition at line 101 of file m2mb_gpio.h.

Enumeration Type Documentation

◆ M2MB_GPIO_DIRECTION_T

Pin direction enumeration, which is used to specify the direction while configuring a GPIO pin.

Enumerator
M2MB_GPIO_INPUT_E 

Specify pin as an INPUT to the SoC.

M2MB_GPIO_OUTPUT_E 

Specify pin as an OUTPUT to the SoC.

M2MB_GPIO_INVALID_DIR_E 

Definition at line 107 of file m2mb_gpio.h.

◆ M2MB_GPIO_DRIVE_T

GPIO pin drive strength.

This enumeration specifies the drive strength to use when specifying the configuration of a GPIO pin.

Enumerator
M2MB_GPIO_1P6MA_E 

Specify a 1.6 mA drive.

M2MB_GPIO_2P7MA_E 

Specify a 2.7 mA drive.

M2MB_GPIO_4P0MA_E 

Specify a 4.0 mA drive.

M2MB_GPIO_INVALID_STRENGTH_E 

Placeholder - Do not use

Definition at line 138 of file m2mb_gpio.h.

◆ M2MB_GPIO_IOCTL_REQUEST

Enumerator
M2MB_GPIO_IOCTL_SET_CFG 

set gpio device configuration

M2MB_GPIO_IOCTL_GET_CFG 

get gpio device configuration

Definition at line 57 of file m2mb_gpio.h.

◆ M2MB_GPIO_PULL_T

GPIO pin pull type.

This enumeration specifies the type of pull (if any) to use when specifying the configuration for a GPIO pin.

Enumerator
M2MB_GPIO_NO_PULL_E 

Specify no pull.

M2MB_GPIO_PULL_DOWN_E 

Pull the GPIO down.

M2MB_GPIO_PULL_UP_E 

Pull the GPIO up.

M2MB_GPIO_INVALID_PULL_E 

Definition at line 122 of file m2mb_gpio.h.

◆ M2MB_GPIO_VALUE_T

GPIO output state specification.

This enumeration specifies the value to write to a GPIO pin configured as an OUTPUT. This functionality is also known as bit banging.

Enumerator
M2MB_GPIO_LOW_VALUE_E 

Drive the output LOW.

M2MB_GPIO_HIGH_VALUE_E 

Drive the output HIGH.

M2MB_GPIO_INVALID_VALUE_E 

Definition at line 154 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_INTERRUPT_MASK_T

GPIO Interrupt Maskable type enumeration, which is used to specify if the GPIO interrupt is Maskable or not.

Enumerator
M2MB_GPIOINT_INTERRUPT_MASKABLE_E 

Interrupt is Makable.

M2MB_GPIOINT_INTERRUPT_NONMASKABLE_E 

Interrupt is Non-Makable.

M2MB_GPIOINT_INTERRUPT_MASK_INVALID_E 

Placeholder - Do not use

Definition at line 200 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_INTERRUPT_PRIORITY_T

GPIO Interrupt Priority type enumeration, which is used to specify the different level of the interrupt in the GPIO interrupt.

Enumerator
M2MB_GPIOINT_INTERRUPT_PRIORITY_HIGHEST_E 

Interrupt priority is Highest.

M2MB_GPIOINT_INTERRUPT_PRIORITY_HIGH_E 

Interrupt priority is High.

M2MB_GPIOINT_INTERRUPT_PRIORITY_MEDIUM_E 

Interrupt priority is Medium.

M2MB_GPIOINT_INTERRUPT_PRIORITY_LOW_E 

Interrupt priority is Low.

M2MB_GPIOINT_INTERRUPT_PRIORITY_LOWEST_E 

Interrupt priority is Lowest.

M2MB_GPIOINT_INTERRUPT_PRIORITY_INVALID_E 

Definition at line 184 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_IOCTL_REQUEST

Enumerator
M2MB_GPIOINT_IOCTL_SET_CFG 

set gpio interrupt device configuration

M2MB_GPIOINT_IOCTL_GET_CFG 

get gpio interrupt device configuration

M2MB_GPIOINT_IOCTL_SET_TRIGGER_TYPE 

set gpio interrupt trigger type

M2MB_GPIOINT_IOCTL_GET_TRIGGER_TYPE 

get gpio interrupt trigger type

M2MB_GPIOINT_IOCTL_GET_INT_PRIO 

get gpio interrupt priority

M2MB_GPIOINT_IOCTL_GET_INT_MASK 

get gpio interrupt mask

M2MB_GPIOINT_IOCTL_GET_GPIO_NUM 

get gpio pin number

M2MB_GPIOINT_IOCTL_SET_INT_EN 

set gpio interrupt enable

M2MB_GPIOINT_IOCTL_SET_INT_DIS 

set gpio interrupt disable

M2MB_GPIOINT_IOCTL_SET_TRIGGER_INT 

set gpio interrupt trigger

M2MB_GPIOINT_IOCTL_GET_INT_PENDING 

get gpio interrupt pending

M2MB_GPIOINT_IOCTL_SET_CALLBACK_FN 

set gpio interrupt callback function

M2MB_GPIOINT_IOCTL_GET_CALLBACK_FN 

get gpio interrupt callback function

M2MB_GPIOINT_IOCTL_SET_CALLBACK_CTXT 

set gpio interrupt callback context

M2MB_GPIOINT_IOCTL_GET_CALLBACK_CTXT 

get gpio interrupt callback context

Definition at line 63 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_TRIGGER_TYPE_T

GPIO Trigger type enumeration, which is used to specify the trigger type to be used in the GPIO pin interrupt.

Enumerator
M2MB_GPIOINT_TRIGGER_HIGH_LEVEL_E 

High Level Trigger Type.

M2MB_GPIOINT_TRIGGER_LOW_LEVEL_E 

Low Level Trigger Type.

M2MB_GPIOINT_TRIGGER_RISING_EDGE_E 

Rising Edge Trigger Type.

M2MB_GPIOINT_TRIGGER_FALLING_EDGE_E 

Falling Edge Trigger Type.

M2MB_GPIOINT_TRIGGER_DUAL_EDGE_E 

Dual Edge Trigger Type.

M2MB_GPIOINT_TRIGGER_INVALID_E 

Definition at line 168 of file m2mb_gpio.h.

Function Documentation

◆ m2mb_gpio_close()

INT32 m2mb_gpio_close ( INT32  fd)

Closes a GPIO port.

This API closes the requested GPIO port

Parameters
[in]fdFile Descriptor of GPIO port
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API frees the allocated memory to the configuration of type M2MB_GPIO_CFG_T and releases the GPIO port. On successful closing of GPIO port, allocated memory to the configuration is freed. In case of error, memory allocation to the configuration is not freed. Allowed From De-initialization and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
status = m2mb_gpio_close( fd );
if(status == -1)
app_dbg_printf("ERROR CLOSING GPIO port\r\n");

◆ m2mb_gpio_ioctl()

INT32 m2mb_gpio_ioctl ( INT32  fd,
M2MB_GPIO_IOCTL_REQUEST_T  request,
  ... 
)

Configure the GPIO port.

This API set/get the GPIO port configuration

Parameters
[in]fdFile Descriptor of GPIO port
[in]requestrequired operation set/get configuration(see M2MB_GPIO_IOCTL_REQUEST)
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API allows to read/write the GPIO configuration of type M2MB_GPIO_CFG_T. On successful, the requested operation (set/get configuration) is done. In case of error, the requested operation (set/get configuration) couldn't be completed. Allowed From Events and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
M2MB_GPIO_CFG_T *P_CFG, *P_ReadCFG;
fd = m2mb_gpio_open("/dev/gpio5", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING GPIO port\r\n");
P_CFG->direction = QAPI_GPIO_OUTPUT_E;
P_CFG->pull = QAPI_GPIO_PULL_UP_E;
P_CFG->drive = QAPI_GPIO_2MA_E;
status = m2mb_gpio_ioctl( fd, M2MB_GPIO_IOCTL_SET_CFG, P_CFG );
if(status == -1)
app_dbg_printf("ERROR IN SET GPIO\r\n");
status = m2mb_gpio_ioctl( fd, M2MB_GPIO_IOCTL_GET_CFG, P_ReadCFG );
if(status == -1)
app_dbg_printf("ERROR IN GET GPIO\r\n");

◆ m2mb_gpio_open()

INT32 m2mb_gpio_open ( const CHAR path,
INT32  flags,
  ... 
)

Open a GPIO port.

This API opens the requested GPIO port

Parameters
[in]pathPointer to GPIO device to open
[in]flagsCurrently unused
Returns
File Descriptor on SUCCESS
-1 on FAILURE
Note
This API allocates memory to the configuration of type M2MB_GPIO_CFG_T. After the successful opening of I2C port, the File Descriptor points to M2MB_GPIO_CFG_T. In case of an error in memory allocation or opening of GPIO port, it returns -1 Allowed From Initialization and tasks Preemption Possible No

Example

INT32 fd;
fd = m2mb_gpio_open("/dev/gpio5", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING GPIO port\r\n");

◆ m2mb_gpio_read()

SSIZE_T m2mb_gpio_read ( INT32  fd,
void *  buf,
SIZE_T  nbyte 
)

Read the GPIO port.

This API reads the data byte from the GPIO port

Parameters
[in]fdFile Descriptor of GPIO port
[in,out]bufreference to the data to be read
[in]nbytenumber of data bytes to be read (always 1 byte)
Returns
number of data bytes read on SUCCESS (always 1 byte)
-1 on FAILURE
Note
This API reads the data byte from the GPIO port. On success, the read data byte is updated in reference provided. In case of error, data byte is not read from GPIO port. Every API is allowed from events and tasks no preemption possible.

Example

bytecnt = m2mb_gpio_read( fd, (void* )P_ReadByte, size);

◆ m2mb_gpio_write()

SSIZE_T m2mb_gpio_write ( INT32  fd,
const void *  buf,
SIZE_T  nbyte 
)

Write to GPIO port.

This API writes the data byte to the GPIO port

Parameters
[in]fdFile Descriptor of GPIO port
[in]bufreference to the data to be written
[in]nbytenumber of data bytes to be write (always 1 byte)
Returns
number of data bytes written on SUCCESS (always 1 byte)
-1 on FAILURE
Note
This API writes the data byte to the GPIO port. On success, the data byte are successfully written to GPIO port. In case of error, write data byte to GPIO port has failed. Every API is allowed from events and tasks no preemption possible.

Example

bytecnt = m2mb_gpio_write( fd, (void* )P_WriteByte, size);

◆ m2mb_gpioint_close()

INT32 m2mb_gpioint_close ( INT32  fd)

Closes a GPIO port.

This API closes the requested interrupt enabledGPIO port

Parameters
[in]fdFile Descriptor of GPIO port
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API frees the interrupt configuration of GPIO and releases the GPIO port. Allowed From De-initialization and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
status = m2mb_gpio_close( fd );
if(status == -1)
app_dbg_printf("ERROR CLOSING GPIO port\r\n");

◆ m2mb_gpioint_ioctl()

INT32 m2mb_gpioint_ioctl ( INT32  fd,
M2MB_GPIOINT_IOCTL_REQUEST_T  request,
  ... 
)

Configure the GPIO port.

This API set/get the GPIO port Interrupt configuration

Parameters
[in]fdFile Descriptor of GPIO port
[in]requestrequired operation set/get configuration(see M2MB_GPIOINT_IOCTL_REQUEST)
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API allows to read/write the GPIO configuration of type M2MB_GPIOINT_CFG_T. On successful, the requested operation (set/get configuration) is done. In case of error, the requested operation (set/get configuration) could not be completed. Allowed From Events and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
M2MB_GPIOINT_CFG_T input_cfg;
M2MB_GPIOINT_TRIGGER_type_t Trigger_Type
input_cfg.callback_fn = GPIO_ISR;
input_cfg.callback_ctxt = NULL;
//open interrupt enable gpio port
fd = m2mb_gpioint_open("/dev/gpio4", &input_cfg);
if(fd == -1)
app_dbg_printf("ERROR OPENING & CONFIGURING GPIO INTERRUPT\r\n");
//get interrupt enable gpio port cfg
status = m2mb_gpio_ioctl( fd, M2MB_GPIOINT_IOCTL_GET_CFG, &read_cfg );
if(status == -1)
app_dbg_printf("ERROR IN GET GPIO INT CFG\r\n");
//set the gpio port trigger type
status = m2mb_gpio_ioctl( fd, M2MB_GPIOINT_IOCTL_SET_TRIGGER_TYPE, &Trigger_Type );
if(status == -1)
app_dbg_printf("ERROR IN SET GPIO INT CFG\r\n");
//get interrupt enable gpio port cfg
status = m2mb_gpio_ioctl( fd, M2MB_GPIOINT_IOCTL_GET_CFG, &read_cfg );
if(status == -1)
app_dbg_printf("ERROR IN GET GPIO INT CFG\r\n");

◆ m2mb_gpioint_open()

INT32 m2mb_gpioint_open ( const CHAR path,
INT32  cfg,
  ... 
)

Open a GPIO port and enable the interrupt.

This API opens the requested GPIO port as input with the required configuration and enables the Interrupt

Parameters
[in]pathpointer to GPIO device to open
[in]cfgconfiguration to be configured
Returns
File Descriptor on SUCCESS
-1 on FAILURE
Note
This API opens the GPIO port as an input port with the requested configuration. This API also enables the Interrupt. In case of an error in the opening of GPIO port, it returns -1 Allowed From Initialization and tasks Preemption Possible No

Example

INT32 fd;
cfg.callback_fn = GPIO_ISR;
fd = m2mb_gpioint_open("/dev/gpioint4", cfg);
if(fd == -1)
app_dbg_printf("ERROR OPENING & CONFIGURING GPIO INTERRUPT\r\n");