m2mb API docs  30.00.007
m2mb API sets documentation
m2mb_gpio.h File Reference

GPIO library implementation. More...

Go to the source code of this file.

Macros

#define NULL   0
 
#define MAX_GPIO_PIN_NBR   11
 ME910 products have 10 GPIOs.
 

Typedefs

typedef void(* m2mb_gpio_intr_callback) (UINT32 fd, void *userdata)
 GPIO interrupt callback function definition. More...
 

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_ISR_COUNTER, M2MB_GPIO_IOCTL_GET_ISR_COUNTER
}
 
enum  M2MB_GPIO_DIRECTION_E { M2MB_GPIO_MODE_INPUT = 0, M2MB_GPIO_MODE_OUTPUT = 1 }
 enum used for gpio direction More...
 
enum  M2MB_GPIO_TRIGGER_E { M2MB_GPIO_INTR_POSEDGE, M2MB_GPIO_INTR_NEGEDGE, M2MB_GPIO_INTR_ANYEDGE }
 
enum  M2MB_GPIO_PULL_MODE_E { M2MB_GPIO_NO_PULL, M2MB_GPIO_PULL_DOWN, M2MB_GPIO_PULL_KEEPER, M2MB_GPIO_PULL_UP }
 
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 More...
 
INT32 m2mb_gpio_close (INT32 fd)
 close a GPIO device More...
 
INT32 m2mb_gpio_ioctl (INT32 fd, INT32 cmd, UINT32 arg)
 configure a GPIO device More...
 
INT32 m2mb_gpio_multi_ioctl (INT32 fd, UINT8 nCmds,...)
 : multiple configuration of a GPIO device. More...
 
INT32 m2mb_gpio_read (INT32 fd, M2MB_GPIO_VALUE_E *value)
 Reads the state of a GPIO pin. More...
 
INT32 m2mb_gpio_write (INT32 fd, M2MB_GPIO_VALUE_E value)
 write the value of a GPIO device 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_multi_ioctl m2mb_gpio_open m2mb_gpio_read m2mb_gpio_write m2mb_gpio_close

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

Author
Morgan Deidda

@changes Dino Apostoli

Date
31/08/2017

Typedef Documentation

◆ m2mb_gpio_intr_callback

typedef void( * m2mb_gpio_intr_callback) (UINT32 fd, void *userdata)

GPIO interrupt callback function definition.

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

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

◆ M2MB_GPIO_DIRECTION_E

enum used for gpio direction

Enumerator
M2MB_GPIO_MODE_INPUT 

GPIO mode : input

M2MB_GPIO_MODE_OUTPUT 

GPIO mode : output

◆ 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.

◆ 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 

Set gpio device pull configuration

M2MB_GPIO_IOCTL_GET_PULL 

Get gpio device pull configuration

M2MB_GPIO_IOCTL_SET_DRIVE 

Set gpio pin drive strength

M2MB_GPIO_IOCTL_GET_DRIVE 

Get gpio pin drive strength

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 

Set the interrupt type: INTR_CB_SET or INTR_COUNTER_SET

M2MB_GPIO_IOCTL_GET_INTR_TYPE 

Get the interrupt type: INTR_CB_SET or INTR_COUNTER_SET

M2MB_GPIO_IOCTL_SET_INTR_CB 

Set the callback function for the interrupt service

M2MB_GPIO_IOCTL_GET_INTR_CB 

Get the callback function used for the interrupt service

M2MB_GPIO_IOCTL_SET_INTR_ARG 

Argument to be passed in the callback function of the interrupt

M2MB_GPIO_IOCTL_GET_INTR_ARG 

Get the Argument of the callback function of the interrupt

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 

Get the trigger type of a registered GPIO interrupt, as in M2MB_GPIO_TRIGGER_E

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

◆ M2MB_GPIO_PULL_MODE_E

Enumerator
M2MB_GPIO_NO_PULL 

Specify no pull

M2MB_GPIO_PULL_DOWN 

Gpio pull down

M2MB_GPIO_PULL_KEEPER 

Keep the GPIO as it is

M2MB_GPIO_PULL_UP 

Gpio pull up

◆ M2MB_GPIO_TRIGGER_E

Enumerator
M2MB_GPIO_INTR_POSEDGE 

Rising edge triggered, to trigger when the pin goes from low to high,

M2MB_GPIO_INTR_NEGEDGE 

Falling edge triggered.

M2MB_GPIO_INTR_ANYEDGE 

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

◆ 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.

Function Documentation

◆ m2mb_gpio_close()

INT32 m2mb_gpio_close ( INT32  fd)

close a GPIO device

This function close a GPIO device

Parameters
[in]fdfile descriptor returned by m2mb_gpio_open
Returns
0 on SUCCESS, -1 on FAILURE

◆ m2mb_gpio_ioctl()

INT32 m2mb_gpio_ioctl ( INT32  fd,
INT32  cmd,
UINT32  arg 
)

configure a GPIO device

This function configure a GPIO using the M2MB_GPIO_IOCTL_REQUEST_E enum

Parameters
[in]fdfile descriptor returned by m2mb_gpio_open
[in]cmdrequired operation (see M2MB_GPIO_IOCTL_REQUEST_E)
[in]argpointer to the value to set
Returns
0 on SUCCESS -1 on FAILURE

Example

example of usage
INT32 ret;
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 )
{
....
}
.....
m2mb_gpio_ioctl( fd, M2MB_GPIO_IOCTL_SET_INTR_CB, (UINT32)myUptrigg_callbk );
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
ret = m2mb_gpio_ioctl( fd, M2MB_GPIO_IOCTL_GET_DIR, (UINT32)&dir );
if( ret )
......
ret = m2mb_gpio_ioctl( fd, M2MB_GPIO_IOCTL_GET_PULL, (UINT32)&pull );
if( ret )
......
@code
example of usage for set and get interrupt argument
CHAR str_test[] = "hello";
CHAR *ptr_str;
ret = m2mb_gpio_ioctl(fd2, M2MB_GPIO_IOCTL_GET_INTR_ARG, (UINT32)&ptr_str);

◆ m2mb_gpio_multi_ioctl()

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

: multiple configuration of a GPIO device.

allow a multiple configuration of a GPIO device. Can not be used in order to get data. In order to use interrupts it is mandatory to initialize the interrupt with M2MB_GPIO_IOCTL_INIT_INTR

Parameters
[in]fdfile descriptor returned by m2mb_gpio_open
[in]nCmdsnumber of commands to be issued at once
[in]...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

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;
ret = m2mb_gpio_multi_ioctl( fd1, CMDS_ARGS( M2MB_GPIO_IOCTL_INIT_INTR, NULL,
M2MB_GPIO_IOCTL_SET_INTR_CB, myUptrigg_callbk,
) );
if( ret == -1 )
{
m2mb_trace_printf(M2MB_TC_M2M_USER, M2MB_TL_ERROR, "GPIO1 - FAIL" );
}

◆ m2mb_gpio_open()

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

open a GPIO device

This function open a GPIO device (from 1 to 10)

Parameters
[in]paththe path has a string of this type: /dev/GPIO# where # is in decimal format
[in]flagscurrently unused
Returns
file descriptor on SUCCESS, 1 on FAILURE

Example

fd = m2mb_gpio_open( "/dev/GPIO7", 0 );

◆ m2mb_gpio_read()

INT32 m2mb_gpio_read ( INT32  fd,
M2MB_GPIO_VALUE_E value 
)

Reads the state of a GPIO pin.

Reads the state of a GPIO pin, used only for M2MB_GPIO_MODE_INPUT

Parameters
[in]fdfile descriptor returned by m2mb_gpio_open
[out]valueget the M2MB_GPIO_VALUE_E LOW or HIGH
Returns
0 on SUCCESS -1 on FAILURE

Example

M2MB_GPIO_VALUE_E value_read;
ret = m2mb_gpio_read(fd, &value_read );

◆ m2mb_gpio_write()

INT32 m2mb_gpio_write ( INT32  fd,
M2MB_GPIO_VALUE_E  value 
)

write the value of a GPIO device

write the value high or low to a GPIO device, used only for M2MB_GPIO_MODE_OUTPUT

Parameters
[in]fdfile descriptor returned by m2mb_gpio_open
[in]valueset high or low
Returns
0 on SUCCESS -1 on FAILURE
M2MB_GPIO_IOCTL_SET_DRIVE
Definition: m2mb_gpio.h:67
m2mb_gpio_multi_ioctl
INT32 m2mb_gpio_multi_ioctl(INT32 fd, UINT8 nCmds,...)
: multiple configuration of a GPIO device.
M2MB_GPIO_IOCTL_GET_PULL
Definition: m2mb_gpio.h:66
m2mb_gpio_open
INT32 m2mb_gpio_open(const CHAR *path, INT32 flags,...)
open a GPIO device
m2mb_gpio_ioctl
INT32 m2mb_gpio_ioctl(INT32 fd, INT32 cmd, UINT32 arg)
configure a GPIO device
M2MB_GPIO_IOCTL_SET_DIR
Definition: m2mb_gpio.h:63
M2MB_GPIO_IOCTL_INIT_INTR
Definition: m2mb_gpio.h:69
M2MB_GPIO_LOW_VALUE
Definition: m2mb_gpio.h:133
M2MB_GPIO_PULL_MODE_E
M2MB_GPIO_PULL_MODE_E
Definition: m2mb_gpio.h:103
m2mb_gpio_read
INT32 m2mb_gpio_read(INT32 fd, M2MB_GPIO_VALUE_E *value)
Reads the state of a GPIO pin.
M2MB_GPIO_VALUE_E
M2MB_GPIO_VALUE_E
GPIO output state specification.
Definition: m2mb_gpio.h:131
M2MB_GPIO_PULL_UP
Definition: m2mb_gpio.h:108
M2MB_GPIO_DIRECTION_E
M2MB_GPIO_DIRECTION_E
enum used for gpio direction
Definition: m2mb_gpio.h:88
M2MB_GPIO_IOCTL_SET_INTR_TRIGGER
Definition: m2mb_gpio.h:77
M2MB_GPIO_MODE_INPUT
Definition: m2mb_gpio.h:90
M2MB_GPIO_IOCTL_SET_INTR_CB
Definition: m2mb_gpio.h:73
M2MB_GPIO_IOCTL_GET_INTR_ARG
Definition: m2mb_gpio.h:76
M2MB_GPIO_IOCTL_SET_INTR_TYPE
Definition: m2mb_gpio.h:71
M2MB_GPIO_IOCTL_SET_INTR_ARG
Definition: m2mb_gpio.h:75
M2MB_GPIO_MEDIUM_DRIVE
Definition: m2mb_gpio.h:121
m2mb_gpio_write
INT32 m2mb_gpio_write(INT32 fd, M2MB_GPIO_VALUE_E value)
write the value of a GPIO device
M2MB_GPIO_MODE_OUTPUT
Definition: m2mb_gpio.h:91
INTR_CB_SET
Definition: m2mb_gpio.h:145
M2MB_GPIO_IOCTL_SET_PULL
Definition: m2mb_gpio.h:65
M2MB_GPIO_IOCTL_SET_ISR_COUNTER
Definition: m2mb_gpio.h:79
M2MB_GPIO_INTR_POSEDGE
Definition: m2mb_gpio.h:97
M2MB_GPIO_IOCTL_GET_DIR
Definition: m2mb_gpio.h:64