/*! \file spi3_charger.h \brief header file of SPI3 for A&B gun charger voltage acquisition and insulation detection \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 SPI3_CHARGER_H #define SPI3_CHARGER_H #include /* SPI3引脚定义 for SGM51652H4XTS38G/T */ #define SPI3_SCK_PORT GPIOE // PE12 - 时钟 #define SPI3_SCK_PIN GPIO_PIN_12 #define SPI3_MISO_PORT GPIOE // PE13 - 数据输入 #define SPI3_MISO_PIN GPIO_PIN_13 #define SPI3_MOSI_PORT GPIOE // PE14 - 数据输出 #define SPI3_MOSI_PIN GPIO_PIN_14 /* SPI3复用功能编号 */ #define SPI3_AF GPIO_AF_5 /* 双芯片片选 */ #define SPI3_CS1_PORT GPIOA // PA4 - 芯片1片选 #define SPI3_CS1_PIN GPIO_PIN_4 #define SPI3_CS2_PORT GPIOA // PA3 - 芯片2片选 #define SPI3_CS2_PIN GPIO_PIN_3 /* SPIC3 时钟 */ #define SPI3_RCU_CS RCU_GPIOA #define SPI3_RCU_SCK_MSIO RCU_GPIOE /* 芯片/通道选择 */ #define CHIP_1 1 //芯片1-CSA #define CHIP_2 2 //芯片2-CSB #define CHNL_0 0 //通道0 #define CHNL_1 1 //通道1 /* 引脚宏操作 */ #define SPI3_CS1_LOW() gpio_bit_reset(SPI3_CS1_PORT, SPI3_CS1_PIN) #define SPI3_CS1_HIGH() gpio_bit_set(SPI3_CS1_PORT, SPI3_CS1_PIN) #define SPI3_CS2_LOW() gpio_bit_reset(SPI3_CS2_PORT, SPI3_CS2_PIN) #define SPI3_CS2_HIGH() gpio_bit_set(SPI3_CS2_PORT, SPI3_CS2_PIN) /* 完整初始化和去初始化 */ int adc_spi3_insuVolt_init(void); void adc_spi3_insuVolt_deinit(void); void spi3_charger_self_test(void); float spi3_read_analog_voltage(uint8_t chip, uint8_t channel); #endif /* SPI3_CHARGER_H */