Init
This commit is contained in:
commit
c13d57edbd
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"./"
|
||||
],
|
||||
"srcs": [
|
||||
"./**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue