From 9477bf2b6cce08f648b1d9b3c37a2bf697854e70 Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Fri, 2 Jan 2026 22:41:25 +0500 Subject: Not working version --- lib/spi_sw.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/spi_sw.c (limited to 'lib/spi_sw.c') diff --git a/lib/spi_sw.c b/lib/spi_sw.c new file mode 100644 index 0000000..1b5656d --- /dev/null +++ b/lib/spi_sw.c @@ -0,0 +1,32 @@ +#include "spi_sw.h" +#include +#include + +SPI_IMPL SpiInit(uint16_t MOSI_pin, uint16_t CLK_pin) { + SPI_IMPL outp = { + .MOSI_pin = MOSI_pin, + .CLK_pin = CLK_pin, + .delay = (uint16_t) 1000, + }; + return outp; +} + +void SpiSend(SPI_IMPL *spi, uint8_t playload) { + if (TRAILING_EDGE) { + gpio_clear(GPIOA, spi->CLK_pin); + } else { + gpio_set(GPIOA, spi->CLK_pin); + } + + for (int i = 0; i < 8; i++) { + gpio_toggle(GPIOA, spi->CLK_pin); + if ((playload >> i) & 1) { + gpio_clear(GPIOA, spi->MOSI_pin); + } else { + gpio_set(GPIOA, spi->MOSI_pin); + } + delayCycles(spi->delay); + gpio_toggle(GPIOA, spi->CLK_pin); + delayCycles(spi->delay); + } +} -- cgit v1.3