我正在研究硬件抽象层。此 HAL 的目的是在 Linux 驱动程序和 MCU 驱动程序之间轻松切换。
我正在研究 SPI 接口。下面是HAL“打开”SPI接口的函数签名。
hal/spi.h
spi_handle_t spi_open(spi_port_t channel, spi_config_t config);
Run Code Online (Sandbox Code Playgroud)
spi_port_t :
spi_config_t :
所以在mcu/spi.c 中,我在某个时候有:
typedef spiBASE_t spi_channel_t;
typedef spiDAT1_t spi_config_t;
spi_handle_t spi_open(spi_channel_t channel, spi_config_t config) {
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
对于linux/spi.c:
typedef uint32_t spi_channel_t;
typedef ChannelConfig_t spi_config_t;
spi_handle_t spi_open(spi_channel_t channel, spi_config_t config) {
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
现在问题出在hal/spi.h 中,我需要定义什么是 spi_channel_t 和 spi_config_t。
有没有办法制作类似的东西(我知道用 extern 是不可能的,但为了解释问题......): …