Init
This commit is contained in:
commit
d69a0bbafc
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
#include "SpiPorts.h"
|
||||||
|
#include "at32f435_437.h"
|
||||||
|
|
||||||
|
tSpiPorts SPI_PORTS;
|
||||||
|
//todo Проверить правильность инициализации
|
||||||
|
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_13;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE13, GPIO_MUX_5);
|
||||||
|
|
||||||
|
//// spi2 miso pin
|
||||||
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_UP;
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_14;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE14, GPIO_MUX_5);
|
||||||
|
|
||||||
|
//// spi2 mosi pin
|
||||||
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_UP;
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_15;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE15, GPIO_MUX_5);
|
||||||
|
}
|
||||||
|
|
||||||
|
static tSpiPortArtery vSpiPort_InitSPI2(tGpioPin *chipSelect) {
|
||||||
|
|
||||||
|
GpioPinSet(chipSelect, false);
|
||||||
|
vSpiPort_InitSPI2RxTxPin();
|
||||||
|
return vSpiPortInitName(SPI2, SPI_FRAME_8BIT, SPI_MCLK_DIV_16, SPI_CLOCK_POLARITY_HIGH, SPI_CLOCK_PHASE_2EDGE, chipSelect);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpiPorts_Init(tAccelPins *accelPins) {
|
||||||
|
SPI_PORTS.accelSpi2 = vSpiPort_InitSPI2(&accelPins->spiChipSelect);
|
||||||
|
SPI_PORTS.accelSpi2_IO = vSpiPortGetIo(&SPI_PORTS.accelSpi2);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SMART_COMPONENTS_SPIPORTS_H
|
||||||
|
#define SMART_COMPONENTS_SPIPORTS_H
|
||||||
|
|
||||||
|
#include "SpiPortArtery.h"
|
||||||
|
//Пины акселерометра
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin spiChipSelect; //Чипселект
|
||||||
|
tGpioPin int1;//INT1
|
||||||
|
tGpioPin int2;//INT2
|
||||||
|
} tAccelPins;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tSpiPortArtery accelSpi2;
|
||||||
|
tSpiPortIO accelSpi2_IO;
|
||||||
|
} tSpiPorts;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin spiChipSelect;
|
||||||
|
} tFlashPins;
|
||||||
|
|
||||||
|
extern tSpiPorts SPI_PORTS;
|
||||||
|
void SpiPorts_Init(tAccelPins *accelPins);
|
||||||
|
|
||||||
|
#endif //SMART_COMPONENTS_SPIPORTS_H
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"./**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue