~ruther/vhdl-spi-2

ref: aab4f8c17b621ba6592449becc2e5a51c6ac9f6c vhdl-spi-2/stm_spi_funduino/include/spi.h -rw-r--r-- 1.3 KiB
aab4f8c1 — Rutherther feat(stm): implement proper slave initialization 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef SPI_H
#define SPI_H

#include <stm32f4xx.h>
#include <stdint.h>
#include <stdbool.h>
#include "pin.h"

typedef enum {
  SPI_FRAME_8_BIT = 0,
  SPI_FRAME_16_BIT = 1,
} spi_frame_format_t;

typedef enum {
  SPI_MSB_FIRST = 0,
  SPI_LSB_FIRST = 1,
} spi_frame_orientation_t;

typedef struct {
  SPI_TypeDef* periph;
  uint8_t idx;
  pin_t csn;
} spi_t;

void spi_init(spi_t* spi, pin_t csn, SPI_TypeDef* peripheral, uint8_t idx);

void spi_master_configure_speed(spi_t *spi,
                                uint8_t divider);

void spi_master_configure(spi_t *spi, bool sw_nss, bool clock_polarity,
                          bool clock_phase, spi_frame_orientation_t orientation, spi_frame_format_t format);
void spi_master_enable(spi_t* spi, bool enable);

void spi_slave_configure(spi_t *spi, bool sw_nss, bool clock_polarity,
                         bool clock_phase, spi_frame_orientation_t orientation, spi_frame_format_t format);
void spi_slave_enable(spi_t *spi, bool enable);

uint16_t spi_transmit(spi_t* spi, uint16_t* data, uint16_t size);
uint16_t spi_receive(spi_t *spi, uint16_t *buffer, uint16_t max_size);

bool spi_can_transmit(spi_t* spi);
uint16_t spi_can_receive(spi_t* spi);

void spi_pulse_csn(spi_t *spi);

bool spi_enable_interrupt(spi_t* spi, bool tx, bool rx);

#endif // SPI_H
Do not follow this link