hal_com/cfg/HAL_COM_cfg.c

107 lines
3.8 KiB
C

/******************************************************************************
* File: HAL_COM_cfg.c
* Component: HAL_COM
* Description: Configuration implementation for the HAL_COM abstraction.
* Defines the channel config array that wires each HAL_COM
* channel to a specific MCU-level transport driver via function
* pointers. Also contains thin wrapper functions to normalize
* driver signatures that don't match the generic prototype
* (e.g., MCU_USB which has no instance parameter).
*
* Layer: HAL - configuration
*****************************************************************************/
#include "HAL_COM.h"
#include "HAL_COM_cfg.h"
/* MCU drivers that channels may be wired to */
#include "MCU_USB.h"
#include "MCU_UART.h"
/* ------------------------------------------------------------------------ */
/* SIGNATURE NORMALIZATION WRAPPERS */
/* ------------------------------------------------------------------------ */
/**
* @brief Wrapper for MCU_USB_enuSendByte to match HAL_COM_tpfSendByte.
*
* MCU_USB has only one instance (the RP2040's single USB peripheral),
* so its public API does not take a u8Instance parameter. This wrapper
* adds the parameter and ignores it, making the signature compatible
* with HAL_COM's generic function pointer type.
*/
static STD_tenuResult vUsbSendByte(u8 u8Instance, u8 u8Byte)
{
(void)u8Instance;
return MCU_USB_enuSendByte(u8Byte);
}
/**
* @brief Wrapper for MCU_USB_enuSendBuffer to match HAL_COM_tpfSendBuffer.
*
* Same rationale as vUsbSendByte — normalizes the missing instance
* parameter so USB can be plugged into a HAL_COM channel.
*/
static STD_tenuResult vUsbSendBuffer(u8 u8Instance, const u8 *pu8Data, u16 u16Length)
{
(void)u8Instance;
return MCU_USB_enuSendBuffer(pu8Data, u16Length);
}
/* MCU_UART already matches the HAL_COM function pointer signatures
* (u8 u8Instance as the first parameter), so no wrapper is needed
* for TX or RX. Its functions can be assigned directly. */
/* --- USB RX wrappers (normalize missing instance parameter) --- */
static STD_tenuResult vUsbReadByte(u8 u8Instance, u8 *pu8Byte)
{
(void)u8Instance;
return MCU_USB_enuReadByte(pu8Byte);
}
static STD_tenuResult vUsbReadBuffer(u8 u8Instance, u8 *pu8Data, u16 u16MaxLength, u16 *pu16Read)
{
(void)u8Instance;
return MCU_USB_enuReadBuffer(pu8Data, u16MaxLength, pu16Read);
}
static STD_tBool vUsbIsRxDataAvailable(u8 u8Instance)
{
(void)u8Instance;
return MCU_USB_bIsRxDataAvailable();
}
/* ------------------------------------------------------------------------ */
/* CHANNEL CONFIGURATION ARRAY */
/* ------------------------------------------------------------------------ */
/**
* @brief Per-channel config, indexed by HAL_COM_tenuChannel.
*
* [HAL_COM_CHANNEL_0] = USB-CDC (primary communication path).
*
* To add a UART channel:
* 1. Add HAL_COM_CHANNEL_1 to the enum in HAL_COM_cfg.h
* 2. Add an entry here with MCU_UART functions (no wrapper needed):
* [HAL_COM_CHANNEL_1] = {
* .pfSendByte = MCU_UART_enuSendByte,
* .pfSendBuffer = MCU_UART_enuSendBuffer,
* .pfReceiveByte = MCU_UART_enuReceiveByte,
* .pfIsRxDataAvailable = MCU_UART_bIsRxDataAvailable,
* .u8Instance = 0U,
* },
*/
const HAL_COM_tstrChannelConfig HAL_COM_astrChannelConfig[HAL_COM_NUM_CHANNELS] =
{
[HAL_COM_CHANNEL_0] =
{
.pfSendByte = vUsbSendByte,
.pfSendBuffer = vUsbSendBuffer,
.pfReadByte = vUsbReadByte,
.pfReadBuffer = vUsbReadBuffer,
.pfIsRxDataAvailable = vUsbIsRxDataAvailable,
.u8Instance = 0U,
},
};