diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-01-02 22:41:25 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-01-02 22:41:25 +0500 |
| commit | 9477bf2b6cce08f648b1d9b3c37a2bf697854e70 (patch) | |
| tree | 7c94f575961e41e50d65052d473735b6daa11f0e /lib/spi_sw.c | |
Not working version
Diffstat (limited to 'lib/spi_sw.c')
| -rw-r--r-- | lib/spi_sw.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 <libopencm3/stm32/gpio.h> +#include <stdint.h> + +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); + } +} |
