CPC GPIO Secondary#
CPC GPIO Expander Secondary Device API.
The CPC GPIO Secondary API provides functions to initialize and manage the GPIO endpoint on the secondary device (Silicon Labs microcontroller). This allows a CPC host (primary device) to discover and control GPIO pins through the CPC protocol.
Overview#
The CPC GPIO Expander enables a CPC host to access GPIO pins on a Silicon Labs microcontroller (secondary device) through the Co-Processor Communication (CPC) protocol. The secondary device exposes GPIO pins as a CPC endpoint that can be discovered and controlled by the host.
Initialization#
The component automatically registers event handlers that integrate with the Silicon Labs platform's service initialization system (sl_main):
**
service_initevent**: Automatically callssl_cpc_gpio_expander_init()during system initialization viasl_main_init()**
service_process_actionevent**: Automatically callssl_cpc_gpio_expander_process_action()during the main loop viasl_main_process_action()
You do not need to manually call these functions - they are handled automatically by the platform's service system.
Processing Commands#
The method for processing incoming GPIO commands depends on whether a kernel/RTOS is present:
Bare-metal Applications: The sl_main_process_action() function must be called in the main loop, which automatically calls sl_cpc_gpio_expander_process_action() through the event handler system.
Kernel/RTOS Applications: When using a kernel or RTOS, processing is handled automatically by a background task created during initialization. The service_process_action event handler is not used in RTOS applications.
This function handles all GPIO operations including:
Reading GPIO values
Setting GPIO values
Configuring GPIO pins (bias, drive mode)
Setting GPIO direction (input/output)
Example Usage#
Bare-metal Application:
#include "sl_main_init.h"
#include "sl_main_process_action.h"
int main(void)
{
// Automatically calls sl_cpc_gpio_expander_init() via service_init event
sl_main_init();
app_init();
while (1) {
// Automatically calls sl_cpc_gpio_expander_process_action()
// via service_process_action event
sl_main_process_action();
app_process_action();
}
}
Kernel/RTOS Application:
#include "sl_main_init.h"
int main(void)
{
// Automatically calls sl_cpc_gpio_expander_init() via service_init event
// Background task is created automatically for processing
sl_main_init();
app_init();
while (1) {
app_process_action();
}
}
Note: You do not need to include
sl_cpc_gpio_expander.hor manually call the initialization/process functions. These are handled automatically by the platform's service system.
Modules#
Functions#
Initialize the CPC GPIO endpoint on the secondary device.
Process incoming GPIO commands from the host.
Function Documentation#
sl_cpc_gpio_expander_init#
sl_status_t sl_cpc_gpio_expander_init (void )
Initialize the CPC GPIO endpoint on the secondary device.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
This function initializes the CPC GPIO endpoint, allowing the CPC host (primary device) to discover and control GPIO pins on the secondary device. The function performs the following operations:
Opens the CPC GPIO endpoint
Registers command handlers for GPIO operations
Prepares the GPIO hardware for remote control
Initializes internal state and buffers
Note
This function is automatically called by the platform's service initialization system (
sl_main) through theservice_initevent handler. You do not need to call this function manually.The GPIO pins that will be exposed to the host are configured through the component configuration system. See
sl_cpc_gpio_expander_gpio_inst_config.hfor GPIO pin definitions.
Returns
SL_STATUS_OK on success
SL_STATUS_FAIL if initialization fails
SL_STATUS_NOT_READY if CPC is not initialized
Other error codes if endpoint cannot be opened
Note
This function is thread-safe and can be called from any context.
Warnings
Do not call this function multiple times without first deinitializing the endpoint (if deinitialization is supported in future versions).
GPIO expander task GPIO endpoint init
sl_cpc_gpio_expander_process_action#
void sl_cpc_gpio_expander_process_action (void )
Process incoming GPIO commands from the host.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
This function processes incoming GPIO commands from the CPC host (primary device) through the CPC endpoint.
Bare-metal Applications: This function is automatically called by sl_main_process_action() through the service_process_action event handler. You do not need to call this function manually - just ensure sl_main_process_action() is called in your main loop.
Kernel/RTOS Applications: When using a kernel or RTOS, this function is called automatically by a background task created during initialization. You do not need to call this function manually in kernel/RTOS applications.
The function handles the following command types:
Get GPIO value (read pin state)
Set GPIO value (write pin state)
Set GPIO configuration (bias, drive mode)
Set GPIO direction (input/output)
Get GPIO information (name, count, etc.)
Note
This function is non-blocking and returns immediately if there are no pending commands. In bare-metal applications, it is called automatically when
sl_main_process_action()is invoked in the main loop.The function processes one command per call. If multiple commands are queued, multiple calls may be needed to process all commands.
This function is thread-safe and can be called from any context, but in bare-metal applications it is called from the main application context through the event handler system.
GPIO endpoint process action