@ -86,6 +86,22 @@ static gpio_error_t gpio_linux_update(void) {
return T_GPIO_ERR_UNSUPPORTED_MODE ;
return T_GPIO_ERR_UNSUPPORTED_MODE ;
}
}
/* === Static GPIO Function Table Instance === */
/**
* @ brief Shared Linux GPIO function table for all gpio_t instances .
*
* Each GPIO object holds a pointer to this table via its ` vtable ` field .
* This avoids redundant copies of function pointers per object .
*/
static const gpio_fn_ptr_t gpio_linux_fn = {
. set = gpio_linux_set ,
. read = gpio_linux_read ,
. toggle = gpio_linux_toggle ,
. update = gpio_linux_update ,
. on_error = gpio_linux_handle_error
} ;
/* === Public API Implementation === */
/* === Public API Implementation === */
/**
/**
@ -97,7 +113,7 @@ static gpio_error_t gpio_linux_update(void) {
* @ param callbacks Optional pointer to gpio_fn_ptr_t to receive platform - specific handlers
* @ param callbacks Optional pointer to gpio_fn_ptr_t to receive platform - specific handlers
* @ return T_GPIO_ERR_OK on success , or appropriate error code
* @ return T_GPIO_ERR_OK on success , or appropriate error code
*/
*/
gpio_error_t ked_gpio_init ( gpio_t * gpio , const gpio_fn_ptr_t * callbacks ) {
gpio_error_t ked_gpio_init ( gpio_t * gpio ) {
gpio_ctx . chip = gpiod_chip_open ( gpio - > chipname ) ;
gpio_ctx . chip = gpiod_chip_open ( gpio - > chipname ) ;
if ( ! gpio_ctx . chip ) {
if ( ! gpio_ctx . chip ) {
gpio_linux_handle_error ( T_GPIO_ERR_NOT_AVAILABLE ) ;
gpio_linux_handle_error ( T_GPIO_ERR_NOT_AVAILABLE ) ;
@ -134,13 +150,7 @@ gpio_error_t ked_gpio_init(gpio_t* gpio, const gpio_fn_ptr_t* callbacks) {
return T_GPIO_ERR_BUS_BUSY ;
return T_GPIO_ERR_BUS_BUSY ;
}
}
if ( callbacks ) {
gpio - > func = & gpio_linux_fn ;
( ( gpio_fn_ptr_t * ) callbacks ) - > set = gpio_linux_set ;
( ( gpio_fn_ptr_t * ) callbacks ) - > read = gpio_linux_read ;
( ( gpio_fn_ptr_t * ) callbacks ) - > toggle = gpio_linux_toggle ;
( ( gpio_fn_ptr_t * ) callbacks ) - > update = gpio_linux_update ;
( ( gpio_fn_ptr_t * ) callbacks ) - > on_error = gpio_linux_handle_error ;
}
return T_GPIO_ERR_OK ;
return T_GPIO_ERR_OK ;
}
}
@ -151,7 +161,7 @@ gpio_error_t ked_gpio_init(gpio_t* gpio, const gpio_fn_ptr_t* callbacks) {
* @ param gpio Unused in this implementation
* @ param gpio Unused in this implementation
* @ param callbacks Pointer to callback table that includes ` deinit `
* @ param callbacks Pointer to callback table that includes ` deinit `
*/
*/
void ked_gpio_deinit ( gpio_t * gpio , const gpio_fn_ptr_t * callbacks ) {
void ked_gpio_deinit ( gpio_t * gpio ) {
if ( gpio_ctx . line ) {
if ( gpio_ctx . line ) {
gpiod_line_release ( gpio_ctx . line ) ;
gpiod_line_release ( gpio_ctx . line ) ;
gpio_ctx . line = NULL ;
gpio_ctx . line = NULL ;