From 636989a0268d904cc1e85c18f633e505823c751a Mon Sep 17 00:00:00 2001 From: cfif Date: Wed, 4 Dec 2024 13:10:48 +0300 Subject: [PATCH] Init --- SpiPorts.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ SpiPorts.h | 31 ++++++++++++++++++++++++ modular.json | 17 ++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 SpiPorts.c create mode 100644 SpiPorts.h create mode 100644 modular.json diff --git a/SpiPorts.c b/SpiPorts.c new file mode 100644 index 0000000..9bf81fb --- /dev/null +++ b/SpiPorts.c @@ -0,0 +1,66 @@ +// +// Created by cfif on 27.09.22. +// +#include "SpiPorts.h" +#include "n32g45x.h" + +tSpiPorts SPI_PORTS; + +static void vSpiPort_InitClocks() { + + RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_SPI2, ENABLE); + RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE); + +} + +static void vSpiPort_InitSPI2RxTxPin() { + + GPIO_InitType GPIO_InitStructure; + // SCLK MOSI + GPIO_InitStructure.Pin = GPIO_PIN_13 | GPIO_PIN_15; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + + // MISO + GPIO_InitStructure.Pin = GPIO_PIN_14; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure); + +} + +static void vSpiPort_InitSPI1RxTxPin() { + + GPIO_InitType GPIO_InitStructure; + // SCLK MOSI + GPIO_InitStructure.Pin = GPIO_PIN_5 | GPIO_PIN_7; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + + // MISO + GPIO_InitStructure.Pin = GPIO_PIN_6; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure); + +} + +// Настройка порта акселерометра +static tSpiPortNation SpiPort_InitSPI2(tGpioPin *chipSelect) { + vSpiPort_InitSPI2RxTxPin(); + return SpiPort_InitName(SPI2, SPI_DATA_SIZE_8BITS, chipSelect); +} + +static tSpiPortNation SpiPort_InitSPI1(tGpioPin *chipSelect) { + vSpiPort_InitSPI1RxTxPin(); + return SpiPort_InitName(SPI1, SPI_DATA_SIZE_8BITS, chipSelect); +} + +void SpiPorts_Init(tAccelPins *accelPins, tFlashPins *flashPins) { + vSpiPort_InitClocks(); + + SPI_PORTS.accelHW = SpiPort_InitSPI2(&accelPins->spiChipSelect); + SPI_PORTS.accelIO = SpiPort_GetIo(&SPI_PORTS.accelHW); + SPI_PORTS.flashHW = SpiPort_InitSPI1(&flashPins->spiChipSelect); + SPI_PORTS.flashIO = SpiPort_GetIo(&SPI_PORTS.flashHW); +} diff --git a/SpiPorts.h b/SpiPorts.h new file mode 100644 index 0000000..68c2210 --- /dev/null +++ b/SpiPorts.h @@ -0,0 +1,31 @@ +// +// Created by cfif on 28.09.22. +// + +#ifndef SPIPORTS_H +#define SPIPORTS_H + +#include "SpiPortNation.h" + +typedef struct { + tGpioPin spiChipSelect; + tGpioPin int1; +} tAccelPins; + +typedef struct { + tGpioPin spiChipSelect; + //tGpioPin int1; +} tFlashPins; + +typedef struct { + tSpiPortNation accelHW; + tSpiPortIO accelIO; + tSpiPortNation flashHW; + tSpiPortIO flashIO; +} tSpiPorts; + +extern tSpiPorts SPI_PORTS; + +void SpiPorts_Init(tAccelPins *accelPins,tFlashPins *flashPins); + +#endif //SPIPORTS_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0427e70 --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "SpiPort_NATION_N32G45X" + } + ], + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file