Midnight Sun Firmware
Loading...
Searching...
No Matches
spi.h
1#pragma once
2
3/************************************************************************************************
4 * @file spi.h
5 *
6 * @brief SPI Library Header file
7 *
8 * @date 2024-11-02
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stddef.h>
14#include <stdint.h>
15
16/* Inter-component Headers */
17
18/* Intra-component Headers */
19#include "gpio.h"
20#include "status.h"
21
29#define SPI_TIMEOUT_MS 100U
31#define SPI_MAX_NUM_DATA 32U
32
34typedef enum {
39} SpiPort;
40
42typedef enum {
48} SpiMode;
49
58typedef struct {
59 uint32_t baudrate;
60 SpiMode mode;
61 GpioAddress sdo;
62 GpioAddress sdi;
63 GpioAddress sclk;
64 GpioAddress cs;
66
78StatusCode spi_init(SpiPort spi, const SpiSettings *settings);
79
95StatusCode spi_exchange(SpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *rx_data, size_t rx_len);
96
104#define spi_tx(spi, tx_data, tx_len) spi_exchange(spi, tx_data, tx_len, NULL, 0U)
105
113#define spi_rx(spi, rx_data, rx_len) spi_exchange(spi, NULL, 0U, rx_data, rx_len)
114
115#ifdef MS_PLATFORM_X86
116
125StatusCode spi_get_tx_data(SpiPort spi, uint8_t *data, uint8_t len);
126
135StatusCode spi_set_rx(SpiPort spi, uint8_t *data, uint8_t len);
136
137#endif
138
SpiMode
SPI Mode selection.
Definition: spi.h:42
SpiPort
SPI Port selection.
Definition: spi.h:34
StatusCode spi_exchange(SpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *rx_data, size_t rx_len)
Performs a SPI data exchange.
Definition: spi.c:81
StatusCode spi_init(SpiPort spi, const SpiSettings *settings)
Initialize SPI instance.
Definition: spi.c:77
@ SPI_MODE_0
Definition: spi.h:43
@ SPI_MODE_2
Definition: spi.h:45
@ NUM_SPI_MODES
Definition: spi.h:47
@ SPI_MODE_1
Definition: spi.h:44
@ SPI_MODE_3
Definition: spi.h:46
@ SPI_PORT_3
Definition: spi.h:37
@ SPI_PORT_1
Definition: spi.h:35
@ SPI_PORT_2
Definition: spi.h:36
@ NUM_SPI_PORTS
Definition: spi.h:38
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Port and pin data.
Definition: gpio.h:112
SPI settings struct.
Definition: spi.h:58