/*! \file spi1_fixed.h \brief header file of SPI1 (Corrected Version) \version 2026-03-09, V1.4.0, firmware for GD32H7xx */ /* Copyright (c) 2025, GigaDevice Semiconductor Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef SPI1_FIXED_H #define SPI1_FIXED_H #include /* SPI1引脚定义 */ #define SPI1_NSS_PIN GPIO_PIN_8 // PA8 #define SPI1_SCK_PIN GPIO_PIN_9 // PA9 #define SPI1_MISO_PIN GPIO_PIN_2 // PG2 #define SPI1_MOSI_PIN GPIO_PIN_3 // PG3 #define SPI1_NSS_PORT GPIOA #define SPI1_SCK_PORT GPIOA #define SPI1_MISO_PORT GPIOG #define SPI1_MOSI_PORT GPIOG /* SPI1复用功能编号 */ #define SPI1_AF GPIO_AF_5 /* 函数声明 */ /* GPIO配置 */ void spi1_gpio_config(void); /* SPI外设配置 */ void spi1_config(void); /* 完整初始化和去初始化 */ int spi1_init(void); void spi1_deinit(void); /* 状态检查 */ uint8_t spi1_is_initialized(void); /* 数据传输函数 */ void spi1_send_data(uint8_t data); uint8_t spi1_receive_data(void); uint8_t spi1_transmit_receive(uint8_t tx_data); /* 缓冲区操作 */ int spi1_send_buffer(uint8_t *data, uint16_t size); int spi1_receive_buffer(uint8_t *data, uint16_t size); /* 片选控制 */ void spi1_nss_control(uint8_t enable); /* 中断处理 */ void spi1_irq_handler(void); #endif /* SPI1_FIXED_H */