9ceb218f80
Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.7 KiB
C
77 lines
2.7 KiB
C
/*!
|
|
\file spi5_analog.h
|
|
\brief header file of SPI5 for analog data acquisition
|
|
|
|
\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 SPI5_ANALOG_H
|
|
#define SPI5_ANALOG_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/* SPI5引脚定义 for analog acquisition */
|
|
#define SPI5_CS_PIN GPIO_PIN_12 // PG12 - 片选
|
|
#define SPI5_SCK_PIN GPIO_PIN_13 // PG13 - 时钟
|
|
#define SPI5_MISO_PIN GPIO_PIN_14 // PG14 - 数据输入
|
|
#define SPI5_MOSI_PIN GPIO_PIN_6 // PA6 - 数据输出
|
|
|
|
#define SPI5_CS_PORT GPIOG
|
|
#define SPI5_SCK_PORT GPIOG
|
|
#define SPI5_MISO_PORT GPIOG
|
|
#define SPI5_MOSI_PORT GPIOA
|
|
|
|
/* SPI5复用功能编号 */
|
|
#define SPI5_AF GPIO_AF_5
|
|
|
|
/* 本项目启用通道数 */
|
|
#define ANALOG_MAX_CHANNELS 8
|
|
|
|
/* 函数声明 */
|
|
/* GPIO配置 */
|
|
int adc_spi5_batVoltCurr_init(void);
|
|
|
|
/* 完整初始化和去初始化 */
|
|
int spi5_analog_init(void);
|
|
void spi5_analog_deinit(void);
|
|
|
|
/* 状态检查 */
|
|
uint8_t spi5_analog_is_initialized(void);
|
|
|
|
/* 基本读取操作 */
|
|
uint16_t spi5_read_analog_raw(uint8_t channel);
|
|
float spi5_read_analog_voltage(uint8_t channel);
|
|
uint8_t spi5_read_all_channels(float *voltages, uint8_t max_channels);
|
|
|
|
void spi5_analog_self_test(void);
|
|
|
|
#endif /* SPI5_ANALOG_H */
|
|
|