Logo
UNICENS V2.1.0-3491
User Manual and API Reference
Ucs_Return_t Ucs_Gpio_SetPinMode ( Ucs_Inst_t self,
uint16_t  destination_address,
uint16_t  gpio_port_handle,
uint8_t  pin,
Ucs_Gpio_PinMode_t  mode,
Ucs_Gpio_ConfigPinModeResCb_t  result_fptr 
)

Configures the pin mode of the given GPIO port.

 This function corresponds with the INIC function INIC.GPIOPortPinMode.
Parameters
selfThe UNICENS instance pointer
destination_addressAddress of the target device. Use the UCS_ADDR_LOCAL_DEV macro to target the local device.
The following address ranges are supported:
  • [0x10 ... 0x2FF]
  • [0x500 ... 0xFEF]
  • UCS_ADDR_LOCAL_DEV
gpio_port_handleThe GPIO Port resource handle.
 GPIOPortHandle
pinThe GPIO pin that is to be configured.
 Pin
modeThe mode of the GPIO pin.
 Mode
result_fptrRequired result callback function pointer.
Returns
Possible return values are shown in the table below.
Value Description
UCS_RET_SUCCESS No error
UCS_RET_ERR_PARAM At least one parameter is wrong
UCS_RET_ERR_BUFFER_OVERFLOW No message buffer available
UCS_RET_ERR_API_LOCKED API is currently locked
UCS_RET_ERR_NOT_INITIALIZED UNICENS is not initialized


Example

// Main function
void main()
{
// Set configuration of GPIO pin no. 3
Ucs_Return_t result = Ucs_Gpio_SetPinMode(0x221U, 0x1D00, 0x03U, UCS_GPIO_OUT_DEFAULT_LOW, &App_GpioConfigPinModeResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle GpioConfigPinMode event
static void App_GpioConfigPinModeResCb(uint16_t device_id, uint16_t port_handle, Ucs_Gpio_PinConfiguration_t pin_cfg_list[], uint8_t list_sz, Ucs_Gpio_Result_t result, void * user_ptr)
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
uint8_t i;
for (i = 0U; i < list_sz; i++)
{
// Configuration list of all GPIO pins
// Check configuration of GPIO pin no. 3 here
if (pin_cfg_list[i].pin == 3 && pin_cfg_list[i].mode != UCS_GPIO_OUT_DEFAULT_LOW)
{
// Error handling
}
}
}
else
{
// Error handling here
}
}