From 9d6e4321ebe78a2f6ac9b3eb15f71cb0a0ce5e13 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 30 Mar 2026 16:03:37 +0300 Subject: [PATCH] Init --- SpiPorts.c | 39 +++++++++++++++++++++++++++++++++++++++ SpiPorts.h | 22 ++++++++++++++++++++++ modular.json | 10 ++++++++++ 3 files changed, 71 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..4d7bc78 --- /dev/null +++ b/SpiPorts.c @@ -0,0 +1,39 @@ +// +// Created by ilya on 25.03.24. +// +#include "SpiPorts.h" +#include "at32f435_437.h" + +tSpiPorts SPI_PORTS; + +static void vSpiPort_InitSPI1RxTxPin() { + gpio_init_type GPIO_InitStruct; + + gpio_default_para_init(&GPIO_InitStruct); + + //// spi1 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_5; + gpio_init(GPIOA, &GPIO_InitStruct); + gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_5); + + //// spi1 mosi pin + GPIO_InitStruct.gpio_pull = GPIO_PULL_UP; + GPIO_InitStruct.gpio_pins = GPIO_PINS_7; + gpio_init(GPIOA, &GPIO_InitStruct); + gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE15, GPIO_MUX_5); +} + +static tSpiPortArtery vSpiPort_InitSPI1(tGpioPin *chipSelect) { + vSpiPort_InitSPI1RxTxPin(); + return vSpiPortInitName(SPI1, SPI_FRAME_8BIT, SPI_MCLK_DIV_16, SPI_CLOCK_POLARITY_HIGH, SPI_CLOCK_PHASE_2EDGE, chipSelect); + +} + +void SpiPorts_Init(tSpiChipSelectPins *SpiChipSelectPins) { + SPI_PORTS.Spi1 = vSpiPort_InitSPI1(&SpiChipSelectPins->spi1ChipSelect); + SPI_PORTS.Spi1_IO = vSpiPortGetIo(&SPI_PORTS.Spi1); +} \ No newline at end of file diff --git a/SpiPorts.h b/SpiPorts.h new file mode 100644 index 0000000..ca6738b --- /dev/null +++ b/SpiPorts.h @@ -0,0 +1,22 @@ +// +// Created by ilya on 25.03.24. +// + +#ifndef SMART_COMPONENTS_SPIPORTS_H +#define SMART_COMPONENTS_SPIPORTS_H + +#include "SpiPortArtery.h" + +typedef struct { + tGpioPin spi1ChipSelect; +} tSpiChipSelectPins; + +typedef struct { + tSpiPortArtery Spi1; + tSpiPortIO Spi1_IO; +} tSpiPorts; + +extern tSpiPorts SPI_PORTS; +void SpiPorts_Init(tSpiChipSelectPins *SpiChipSelectPins); + +#endif //SMART_COMPONENTS_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