137 lines
4.5 KiB
C
137 lines
4.5 KiB
C
//
|
|
// Created by ilya on 25.03.24.
|
|
//
|
|
#include "SpiPorts.h"
|
|
#include "at32f435_437.h"
|
|
|
|
tSpiPorts SPI_PORTS;
|
|
|
|
static void vSpiPort_InitSPI1RxTxPin() {
|
|
gpio_init_type GPIO_InitStruct;
|
|
|
|
gpio_default_para_init(&GPIO_InitStruct);
|
|
|
|
//// spi1 sck pin
|
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_5;
|
|
gpio_init(GPIOA, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_5);
|
|
|
|
//// spi1 mosi pin
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_7;
|
|
gpio_init(GPIOA, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_5);
|
|
}
|
|
|
|
static tSpiPortArtery vSpiPort_InitSPI1(tGpioPin *chipSelect) {
|
|
vSpiPort_InitSPI1RxTxPin();
|
|
return vSpiPortInitName(SPI1, SPI_FRAME_8BIT, SPI_MCLK_DIV_32, SPI_CLOCK_POLARITY_LOW, SPI_CLOCK_PHASE_1EDGE, chipSelect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vSpiPort_InitSPI2RxTxPin() {
|
|
gpio_init_type GPIO_InitStruct;
|
|
|
|
gpio_default_para_init(&GPIO_InitStruct);
|
|
|
|
//// spi2 sck pin
|
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_1;
|
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE1, GPIO_MUX_6);
|
|
|
|
//// spi2 mosi pin
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_1;
|
|
gpio_init(GPIOC, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOC, GPIO_PINS_SOURCE1, GPIO_MUX_7);
|
|
}
|
|
|
|
static tSpiPortArtery vSpiPort_InitSPI2(tGpioPin *chipSelect) {
|
|
vSpiPort_InitSPI2RxTxPin();
|
|
return vSpiPortInitName(SPI2, SPI_FRAME_8BIT, SPI_MCLK_DIV_32, SPI_CLOCK_POLARITY_LOW, SPI_CLOCK_PHASE_1EDGE, chipSelect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void vSpiPort_InitSPI3RxTxPin() {
|
|
gpio_init_type GPIO_InitStruct;
|
|
|
|
gpio_default_para_init(&GPIO_InitStruct);
|
|
|
|
//// spi3 sck pin
|
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_10;
|
|
gpio_init(GPIOC, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOC, GPIO_PINS_SOURCE10, GPIO_MUX_6);
|
|
|
|
//// spi3 mosi pin
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_0;
|
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE0, GPIO_MUX_7);
|
|
}
|
|
|
|
static tSpiPortArtery vSpiPort_InitSPI3(tGpioPin *chipSelect) {
|
|
vSpiPort_InitSPI3RxTxPin();
|
|
return vSpiPortInitName(SPI3, SPI_FRAME_8BIT, SPI_MCLK_DIV_32, SPI_CLOCK_POLARITY_LOW, SPI_CLOCK_PHASE_1EDGE, chipSelect);
|
|
|
|
}
|
|
|
|
|
|
static void vSpiPort_InitSPI4RxTxPin() {
|
|
gpio_init_type GPIO_InitStruct;
|
|
|
|
gpio_default_para_init(&GPIO_InitStruct);
|
|
|
|
//// spi4 sck pin
|
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_2;
|
|
gpio_init(GPIOE, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOE, GPIO_PINS_SOURCE2, GPIO_MUX_5);
|
|
|
|
//// spi4 mosi pin
|
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_6;
|
|
gpio_init(GPIOE, &GPIO_InitStruct);
|
|
gpio_pin_mux_config(GPIOE, GPIO_PINS_SOURCE6, GPIO_MUX_5);
|
|
}
|
|
|
|
static tSpiPortArtery vSpiPort_InitSPI4(tGpioPin *chipSelect) {
|
|
vSpiPort_InitSPI4RxTxPin();
|
|
return vSpiPortInitName(SPI4, SPI_FRAME_8BIT, SPI_MCLK_DIV_32, SPI_CLOCK_POLARITY_LOW, SPI_CLOCK_PHASE_1EDGE, chipSelect);
|
|
|
|
}
|
|
|
|
|
|
void SpiPorts_Init(tSpiChipSelectPins *SpiChipSelectPins) {
|
|
SPI_PORTS.Spi1 = vSpiPort_InitSPI1(&SpiChipSelectPins->spi1ChipSelect);
|
|
SPI_PORTS.Spi1_IO = vSpiPortGetIo(&SPI_PORTS.Spi1);
|
|
|
|
SPI_PORTS.Spi2 = vSpiPort_InitSPI2(&SpiChipSelectPins->spi2ChipSelect);
|
|
SPI_PORTS.Spi2_IO = vSpiPortGetIo(&SPI_PORTS.Spi2);
|
|
|
|
SPI_PORTS.Spi3 = vSpiPort_InitSPI3(&SpiChipSelectPins->spi3ChipSelect);
|
|
SPI_PORTS.Spi3_IO = vSpiPortGetIo(&SPI_PORTS.Spi3);
|
|
|
|
SPI_PORTS.Spi4 = vSpiPort_InitSPI4(&SpiChipSelectPins->spi4ChipSelect);
|
|
SPI_PORTS.Spi4_IO = vSpiPortGetIo(&SPI_PORTS.Spi4);
|
|
} |