Init
This commit is contained in:
commit
636989a026
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"dep": [
|
||||
{
|
||||
"type": "git",
|
||||
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||
"repo": "SpiPort_NATION_N32G45X"
|
||||
}
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"./"
|
||||
],
|
||||
"srcs": [
|
||||
"./**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue