mikroSDK Reference Manual

GPIO Port Driver API Reference. More...

Macros

#define port_read   port_read_output
 Read from port.
 

Functions list

err_t port_init (port_t *port, port_name_t name, port_size_t mask, pin_direction_t direction)
 Initialize GPIO port.
 
err_t port_write (port_t *port, port_size_t value)
 Write to port.
 
port_size_t port_read_input (port_t *port)
 Read from port.
 
port_size_t port_read_output (port_t *port)
 Read from port.
 

Macro Definition Documentation

◆ port_read

#define port_read   port_read_output

Reads from beforehand initialized port.

Parameters
[in]portPort driver context structure. See port_t structure definition for detailed explanation.
Returns
Value read from port output state.
Precondition
Make sure that port structure has been declared and initialized beforehand. See port_t structure definition and port_init for detailed explanation.

Example

// Read value holder.
static port_size_t read_value;
// Read port.
read_value = port_read( &port );
hal_port_size_t port_size_t
Definition drv_name.h:78
#define port_read
Read from port.
Definition drv_port.h:241

Function Documentation

◆ port_init()

err_t port_init ( port_t * port,
port_name_t name,
port_size_t mask,
pin_direction_t direction )

Initializes port driver context structure and masked GPIO pins as digital output or digital input.

Parameters
[in,out]portPort driver context structure. See port_t structure definition for detailed explanation.
[in]namePort name. See port_name_t structure definition for detailed explanation.
[in]maskGPIO pin mask. See port_size_t structure definition for detailed explanation.
[in]directionGPIO pin direction. See pin_direction_t structure definition for detailed explanation.
Returns
The function can return one of the values defined in the port_err_t enum list.
Precondition
Make sure that port structure has been declared. See port_t structure definition for detailed explanation.
Warning
The following example includes pin mapping. Take into consideration that different hardware might not have the same pins. Make sure to accommodate pin name based on your hardware specifics.

Example

// Port driver context structure.
static port_t port;
// Initialize PORT_B as output.
if ( PORT_SUCCESS == port_init( &port, PORT_B, 0xFF, PIN_DIRECTION_DIGITAL_OUTPUT ) ) {
// No error
} else {
// Handle the error
}
@ PORT_SUCCESS
Definition drv_port.h:59
@ PIN_DIRECTION_DIGITAL_OUTPUT
Definition drv_port.h:69
err_t port_init(port_t *port, port_name_t name, port_size_t mask, pin_direction_t direction)
Initialize GPIO port.
Port driver context structure, consisted of the following fields :
Definition drv_port.h:82

◆ port_read_input()

port_size_t port_read_input ( port_t * port)

Reads from beforehand initialized port.

Parameters
[in]portPort driver context structure. See port_t structure definition for detailed explanation.
Returns
Value read from port input state.
Precondition
Make sure that port structure has been declared and initialized beforehand. See port_t structure definition and port_init for detailed explanation.

Example

// Read value holder.
static port_size_t read_value;
// Read port.
read_value = port_read_input( &port );
port_size_t port_read_input(port_t *port)
Read from port.

◆ port_read_output()

port_size_t port_read_output ( port_t * port)

Reads from beforehand initialized port.

Parameters
[in]portPort driver context structure. See port_t structure definition for detailed explanation.
Returns
Value read from port output state.
Precondition
Make sure that port structure has been declared and initialized beforehand. See port_t structure definition and port_init for detailed explanation.

Example

// Read value holder.
static port_size_t read_value;
// Read port.
read_value = port_read_output( &port );
port_size_t port_read_output(port_t *port)
Read from port.

◆ port_write()

err_t port_write ( port_t * port,
port_size_t value )

Writes value to beforehand initialized port.

Parameters
[in]portPort driver context structure. See port_t structure definition for detailed explanation.
[in]valueBit map to write on port. See port_size_t structure definition for detailed explanation.
Returns
The function can return one of the values defined in the port_err_t enum list.
Precondition
Make sure that port structure has been declared and initialized beforehand. See port_t structure definition and port_init for detailed explanation.

Example

// Write value to defined port.
if ( PORT_SUCCESS == port_write( &port, value ) ) {
// No error
} else {
// Handle the error
}
err_t port_write(port_t *port, port_size_t value)
Write to port.