commit 0234550b76e86fce9e1e06dd279b85f7e2bc4a30 Author: cfif Date: Fri Jan 24 13:22:32 2025 +0300 Перенос на новую организацию GONEC diff --git a/SpiPorts.c b/SpiPorts.c new file mode 100644 index 0000000..37c0ef4 --- /dev/null +++ b/SpiPorts.c @@ -0,0 +1,54 @@ +// +// Created by cfif on 27.09.22. +// +#include "SpiPorts.h" +#include "at32f435_437.h" + +tSpiPorts SPI_PORTS; + +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_DOWN; + GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX; + GPIO_InitStruct.gpio_pins = GPIO_PINS_9; + gpio_init(GPIOA, &GPIO_InitStruct); + gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE9, GPIO_MUX_5); + + // spi2 miso pin + GPIO_InitStruct.gpio_pull = GPIO_PULL_UP; + GPIO_InitStruct.gpio_pins = GPIO_PINS_12; + gpio_init(GPIOA, &GPIO_InitStruct); + gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE12, GPIO_MUX_5); + + // spi2 mosi pin + GPIO_InitStruct.gpio_pull = GPIO_PULL_UP; + GPIO_InitStruct.gpio_pins = GPIO_PINS_10; + gpio_init(GPIOA, &GPIO_InitStruct); + gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE10, GPIO_MUX_5); + + +} + +#define vSpiPortInitName(NAME, spiFrameBit, mclkDIV, clockPolarity, clockPhase, CS) \ + +static tSpiPortArtery vSpiPort_InitSPI2(tGpioPin *chipSelect) { + GpioPinSet(chipSelect, false); + vSpiPort_InitSPI2RxTxPin(); + return vSpiPortInitName(SPI2, SPI_FRAME_8BIT, SPI_MCLK_DIV_4, SPI_CLOCK_POLARITY_LOW, SPI_CLOCK_PHASE_1EDGE, chipSelect); +} + +void SpiPorts_Init(tFlashPins *pins) { + SPI_PORTS.flashSPI1 = vSpiPort_InitSPI2(&pins->spiChipSelect1); + SPI_PORTS.flashSPI1IO = vSpiPortGetIo(&SPI_PORTS.flashSPI1); + SPI_PORTS.flashSPI2 = vSpiPort_InitSPI2(&pins->spiChipSelect2); + SPI_PORTS.flashSPI2IO = vSpiPortGetIo(&SPI_PORTS.flashSPI2); + + GpioPinSet(&pins->spiHold, false); + GpioPinSet(&pins->spiWp, false); +} diff --git a/SpiPorts.h b/SpiPorts.h new file mode 100644 index 0000000..bd725a4 --- /dev/null +++ b/SpiPorts.h @@ -0,0 +1,28 @@ +// +// Created by cfif on 28.09.22. +// + +#ifndef SPIPORTS_H +#define SPIPORTS_H + +#include "SpiPortArtery.h" + +typedef struct { + tGpioPin spiChipSelect1; + tGpioPin spiChipSelect2; + tGpioPin spiHold; + tGpioPin spiWp; +} tFlashPins; + +typedef struct { + tSpiPortArtery flashSPI1; + tSpiPortIO flashSPI1IO; + tSpiPortArtery flashSPI2; + tSpiPortIO flashSPI2IO; +} tSpiPorts; + +extern tSpiPorts SPI_PORTS; + +void SpiPorts_Init(tFlashPins *pins); + +#endif //SPIPORTS_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0dd1901 --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file