mikroSDK Reference Manual

GPIO Port Driver API Reference. More...

Macros

#define port_read   port_read_output
 Read from port. More...
 

Functions list

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

Detailed Description

Driver for configuring GPIO ports as digital output/input and setting/reading logical value.

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 );

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_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
}

◆ 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_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_read
#define port_read
Read from port.
Definition: drv_port.h:240
port_read_output
port_size_t port_read_output(port_t *port)
Read from port.
PIN_DIRECTION_DIGITAL_OUTPUT
Definition: drv_port.h:68
port_write
err_t port_write(port_t *port, port_size_t value)
Write to port.
port_size_t
hal_port_size_t port_size_t
Definition: drv_name.h:77
port_init
err_t port_init(port_t *port, port_name_t name, port_size_t mask, pin_direction_t direction)
Initialize GPIO port.
port_t
Port driver context structure, consisted of the following fields :
Definition: drv_port.h:80
PORT_SUCCESS
Definition: drv_port.h:58
port_read_input
port_size_t port_read_input(port_t *port)
Read from port.