WE310F5  39.00.000
m2mb_gpio.h File Reference

GPIO library implementation. More...

Go to the source code of this file.

Data Structures

struct  M2MB_GPIO_CFG_T
 

Macros

#define NULL   0
 

Typedefs

typedef VOID(* M2MB_GPIOINT_CB_T) (UINT32 id, UINT32 event)
 GPIO interrupt callback function definition. More...
 
typedef UINT32 M2MB_GPIO_PIN_E
 
typedef VOIDM2MB_GPIOINT_CALLBACK_DATA_T
 

Enumerations

enum  M2MB_GPIO_IOCTL_REQUEST_E {
  M2MB_GPIO_IOCTL_SET_DIR,
  M2MB_GPIO_IOCTL_GET_DIR,
  M2MB_GPIO_IOCTL_SET_PULL,
  M2MB_GPIO_IOCTL_GET_PULL,
  M2MB_GPIO_IOCTL_SET_DRIVE,
  M2MB_GPIO_IOCTL_GET_DRIVE,
  M2MB_GPIO_IOCTL_INIT_INTR,
  M2MB_GPIO_IOCTL_DEINIT_INTR,
  M2MB_GPIO_IOCTL_SET_INTR_TYPE,
  M2MB_GPIO_IOCTL_GET_INTR_TYPE,
  M2MB_GPIO_IOCTL_SET_INTR_CB,
  M2MB_GPIO_IOCTL_GET_INTR_CB,
  M2MB_GPIO_IOCTL_SET_INTR_ARG,
  M2MB_GPIO_IOCTL_GET_INTR_ARG,
  M2MB_GPIO_IOCTL_SET_INTR_TRIGGER,
  M2MB_GPIO_IOCTL_GET_INTR_TRIGGER,
  M2MB_GPIO_IOCTL_SET_INTR_POLARITY,
  M2MB_GPIO_IOCTL_GET_INTR_POLARITY,
  M2MB_GPIO_IOCTL_SET_ISR_COUNTER,
  M2MB_GPIO_IOCTL_GET_ISR_COUNTER
}
 
enum  M2MB_GPIO_DIRECTION_E {
  M2MB_GPIO_MODE_INPUT = 0x00,
  M2MB_GPIO_MODE_OUTPUT = 0x01
}
 enum used for gpio direction More...
 
enum  M2MB_GPIO_TRIGGER_E {
  M2MB_GPIO_INTR_LEVEL = 0x0,
  M2MB_GPIO_INTR_EDGE = 0x1,
  M2MB_GPIO_INTR_ANYEDGE = 0x2
}
 enum used for gpio Interrupt trigger More...
 
enum  M2MB_GPIO_POLARITY_E {
  M2MB_GPIO_INTR_POL_LOW = 0x0,
  M2MB_GPIO_INTR_POL_HIGH = 0x1
}
 enum used for gpio Interrupt Polarity More...
 
enum  M2MB_GPIO_DEBOUNCE_E {
  M2MB_GPIO_INT_DEBOUNCE_DISABLE,
  M2MB_GPIO_INT_DEBOUNCE_ENABLE
}
 enum used for gpio interrupt debounce More...
 
enum  M2MB_GPIO_PULL_MODE_E {
  M2MB_GPIO_NO_PULL = 0x00,
  M2MB_GPIO_PULL_DOWN = 0x01,
  M2MB_GPIO_PULL_UP = 0x02,
  M2MB_GPIO_PULL_KEEPER
}
 enum used for gpio Pull More...
 
enum  M2MB_GPIO_DRIVE_E {
  M2MB_GPIO_LOW_DRIVE = 0,
  M2MB_GPIO_MEDIUM_DRIVE = 0x1,
  M2MB_GPIO_HIGH_DRIVE = 0x2
}
 GPIO pin drive strength. More...
 
enum  M2MB_GPIO_VALUE_E {
  M2MB_GPIO_LOW_VALUE = 0,
  M2MB_GPIO_HIGH_VALUE = 1
}
 GPIO output state specification. More...
 
enum  M2M_GPIO_INTR_TYPE_E {
  INTR_CB_SET = 0,
  INTR_COUNTER_SET
}
 GPIO ISR type: callback or counter. More...
 

Functions

INT32 m2mb_gpio_open (const CHAR *path, INT32 flags,...)
 open a GPIO device arguments: path: /dev/GPIO# where # is in decimal format flags currently unused return: file descriptor on SUCCESS -1 on FAILURE i.e.: fd = m2mb_gpio_open( "/dev/GPIO7", 0 ); More...
 
INT32 m2mb_gpio_close (INT32 fd)
 close a GPIO device More...
 
INT32 m2mb_gpio_ioctl (INT32 fd, M2MB_GPIO_IOCTL_REQUEST_E cmd, void *arg)
 configure a GPIO device More...
 
INT32 m2mb_gpio_multi_ioctl (INT32 fd, UINT8 nCmds,...)
 : allow a multiple configuration of a GPIO device. Can not be used in order to get data. More...
 

Detailed Description

GPIO library implementation.

m2m/m2m_generic/common/m2mb_inc/m2mb_gpio.h

The following functions are implemented: m2mb_gpio_ioctl m2mb_gpio_open m2mb_gpio_read m2mb_gpio_write m2mb_gpio_close

Dependencies: m2m/m2m_generic/common/m2mb_inc/m2mb_types.h

Author
Keshava Kumar B

Keshava Kumar B

Date
15/10/2020

Definition in file m2mb_gpio.h.

Macro Definition Documentation

◆ NULL

#define NULL   0

Definition at line 38 of file m2mb_gpio.h.

Typedef Documentation

◆ M2MB_GPIO_PIN_E

Definition at line 178 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_CALLBACK_DATA_T

Definition at line 180 of file m2mb_gpio.h.

◆ M2MB_GPIOINT_CB_T

typedef VOID(* M2MB_GPIOINT_CB_T) (UINT32 id, UINT32 event)

GPIO interrupt callback function definition.

GPIO interrupt clients will pass a function pointer of this format in M2MB_GPIO_CFG_T callback function

Definition at line 176 of file m2mb_gpio.h.

Enumeration Type Documentation

◆ M2M_GPIO_INTR_TYPE_E

GPIO ISR type: callback or counter.

Enumerator
INTR_CB_SET 

Interrupt set with a callback function.

INTR_COUNTER_SET 

Interrupt set a counter for interrupt and no callback

Definition at line 159 of file m2mb_gpio.h.

◆ M2MB_GPIO_DEBOUNCE_E

enum used for gpio interrupt debounce

Enumerator
M2MB_GPIO_INT_DEBOUNCE_DISABLE 

Disable interrupt debounce

M2MB_GPIO_INT_DEBOUNCE_ENABLE 

Enable interrupt debounce

Definition at line 108 of file m2mb_gpio.h.

◆ M2MB_GPIO_DIRECTION_E

enum used for gpio direction

Enumerator
M2MB_GPIO_MODE_INPUT 

GPIO mode : input

M2MB_GPIO_MODE_OUTPUT 

GPIO mode : output

Definition at line 74 of file m2mb_gpio.h.

◆ M2MB_GPIO_DRIVE_E

GPIO pin drive strength.

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

Enumerator
M2MB_GPIO_LOW_DRIVE 

Specify a low drive.

M2MB_GPIO_MEDIUM_DRIVE 

Specify a medium drive.

M2MB_GPIO_HIGH_DRIVE 

Specify a high drive.

Definition at line 134 of file m2mb_gpio.h.

◆ M2MB_GPIO_IOCTL_REQUEST_E

Enumerator
M2MB_GPIO_IOCTL_SET_DIR 

set gpio device direction configuration

M2MB_GPIO_IOCTL_GET_DIR 

get gpio device direction configuration

M2MB_GPIO_IOCTL_SET_PULL 
M2MB_GPIO_IOCTL_GET_PULL 
M2MB_GPIO_IOCTL_SET_DRIVE 
M2MB_GPIO_IOCTL_GET_DRIVE 
M2MB_GPIO_IOCTL_INIT_INTR 

Registers a callback/counter for a GPIO interrupt

M2MB_GPIO_IOCTL_DEINIT_INTR 

Deregisters a callback/counter Interrupt service

M2MB_GPIO_IOCTL_SET_INTR_TYPE 
M2MB_GPIO_IOCTL_GET_INTR_TYPE 
M2MB_GPIO_IOCTL_SET_INTR_CB 
M2MB_GPIO_IOCTL_GET_INTR_CB 
M2MB_GPIO_IOCTL_SET_INTR_ARG 
M2MB_GPIO_IOCTL_GET_INTR_ARG 
M2MB_GPIO_IOCTL_SET_INTR_TRIGGER 

set trigger. N.B.Can dynamically sets the trigger type of a registered GPIO interrupt

M2MB_GPIO_IOCTL_GET_INTR_TRIGGER 
M2MB_GPIO_IOCTL_SET_INTR_POLARITY 
M2MB_GPIO_IOCTL_GET_INTR_POLARITY 
M2MB_GPIO_IOCTL_SET_ISR_COUNTER 

Set a starting value for ISR Counting interrupts

M2MB_GPIO_IOCTL_GET_ISR_COUNTER 

Read ISR interrupt counter value

Definition at line 45 of file m2mb_gpio.h.

◆ M2MB_GPIO_POLARITY_E

enum used for gpio Interrupt Polarity

Enumerator
M2MB_GPIO_INTR_POL_LOW 

Setting interrupt to low active: falling edge or low level

M2MB_GPIO_INTR_POL_HIGH 

Setting interrupt to high active: rising edge or high level

Definition at line 97 of file m2mb_gpio.h.

◆ M2MB_GPIO_PULL_MODE_E

enum used for gpio Pull

Enumerator
M2MB_GPIO_NO_PULL 

Specify no pull

M2MB_GPIO_PULL_DOWN 

Gpio pull down

M2MB_GPIO_PULL_UP 

Gpio pull up

M2MB_GPIO_PULL_KEEPER 

Keep the GPIO as it is

Definition at line 119 of file m2mb_gpio.h.

◆ M2MB_GPIO_TRIGGER_E

enum used for gpio Interrupt trigger

Enumerator
M2MB_GPIO_INTR_LEVEL 

Level triggered, to trigger when the pin goes from low or high, based on Polarity

M2MB_GPIO_INTR_EDGE 

Edge triggered.

M2MB_GPIO_INTR_ANYEDGE 

Dual edge triggered, to trigger the interrupt whenever the pin changes value

Definition at line 85 of file m2mb_gpio.h.

◆ M2MB_GPIO_VALUE_E

GPIO output state specification.

Enumerator
M2MB_GPIO_LOW_VALUE 

Drive the output LOW.

M2MB_GPIO_HIGH_VALUE 

Drive the output HIGH.

Definition at line 147 of file m2mb_gpio.h.

Function Documentation

◆ m2mb_gpio_close()

INT32 m2mb_gpio_close ( INT32  fd)

close a GPIO device

m2mb_gpio_close:

Parameters
fdfile descriptor returned by m2mb_gpio_open
Returns
0 on SUCCESS -1 on FAILURE

◆ m2mb_gpio_ioctl()

INT32 m2mb_gpio_ioctl ( INT32  fd,
M2MB_GPIO_IOCTL_REQUEST_E  cmd,
void *  arg 
)

configure a GPIO device

m2mb_gpio_ioctl:

Parameters
fdfile descriptor returned by m2mb_gpio_open
cmdrequired operation (see M2MB_GPIO_IOCTL_REQUEST_E)
argpointer to the value to set
Returns
0 on SUCCESS -1 on FAILURE
example of usage
INT32 ret;
INT32 fd;
fd = m2mb_gpio_open( "/dev/GPIO1", 0 );
if( fd != -1 )
{
if ( ret == -1 )
return ;
}
example of usage for a interrupt callback:
static void myUptrigg_callbk(UINT32 fd, void *userdata )
{
....
}
.....
In order to use interrupts it is mandatory to initialize the interrupt with M2MB_GPIO_IOCTL_INIT_INTR
example of usage for get data: Must be used with the reference or pointer
if( ret )
......
if( ret )
......
@code
example of usage for get interrupt argument
CHAR str_test[] = "hello";
CHAR *ptr_str;

◆ m2mb_gpio_multi_ioctl()

INT32 m2mb_gpio_multi_ioctl ( INT32  fd,
UINT8  nCmds,
  ... 
)

: allow a multiple configuration of a GPIO device. Can not be used in order to get data.

m2mb_gpio_multi_ioctl:

Parameters
fdfile descriptor returned by m2mb_gpio_open
nCmdsnumber of commands to be issued at once
...variable inputs, N cmds (see M2MB_GPIO_IOCTL_REQUEST_E) followed by N arguments for their respective issued commands. CMDS(...) and CMDS_ARGS(...) macro can be used to better insert cmd and parameters and to better control right insertion
Returns
0 on SUCCESS -1 on FAILURE
example of usage for PMM:
if ( ret )
{
m2mb_trace_printf(M2MB_TC_M2M_USER, M2MB_TL_ERROR, "GPIO1 FAIL" );
}
example of usage for a interrupt callback:
INT32 ret;
M2MB_GPIO_IOCTL_SET_INTR_CB, myUptrigg_callbk,
M2MB_GPIO_IOCTL_SET_INTR_TRIGGER, M2MB_GPIO_INTR_POSEDGE
) );
if( ret == -1 )
{
m2mb_trace_printf(M2MB_TC_M2M_USER, M2MB_TL_ERROR, "GPIO1 - FAIL" );
}

In order to use interrupts it is mandatory to initialize the interrupt with M2MB_GPIO_IOCTL_INIT_INTR

◆ m2mb_gpio_open()

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

open a GPIO device arguments: path: /dev/GPIO# where # is in decimal format flags currently unused return: file descriptor on SUCCESS -1 on FAILURE i.e.: fd = m2mb_gpio_open( "/dev/GPIO7", 0 );

m2mb_gpio_open