aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/usrp3/include/wb_spi.h
blob: ebbb20b161f1a0e9a3d141286e365f553ccc8897 (plain)
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
49
50
51
52
53
54
55
// Copyright 2012 Ettus Research LLC

#ifndef INCLUDED_WB_SPI_H
#define INCLUDED_WB_SPI_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

typedef enum {
    WRITE, WRITE_READ
} wb_spi_rw_mode_t;

typedef enum {
    RISING, FALLING
} wb_spi_edge_t;

typedef struct {
    void*           base;
    uint32_t        slave_sel;
    uint32_t        clk_div;
    wb_spi_edge_t   mosi_edge;
    wb_spi_edge_t   miso_edge;
    bool            lsb_first;
} wb_spi_slave_t;

/*!
 * \brief Initialize SPI slave device
 */
void wb_spi_init(const wb_spi_slave_t* slave);

/*!
 * \brief Perform a SPI transaction in auto chip-select mode.
 */
inline void wb_spi_transact(const wb_spi_slave_t* slave,
    wb_spi_rw_mode_t rw_mode, const void* mosi_buf, void* miso_buf, uint32_t length);

/*!
 * \brief Perform a SPI transaction in manual chip-select mode.
 */
inline void wb_spi_transact_man_ss(const wb_spi_slave_t* slave,
    wb_spi_rw_mode_t rw_mode, const void* mosi_buf, void* miso_buf, uint32_t length);

/*!
 * \brief Select SPI slave
 */
void wb_spi_slave_select(const wb_spi_slave_t* slave);

/*!
 * \brief Deselect SPI slave
 */
void wb_spi_slave_deselect(const wb_spi_slave_t* slave);

#endif /* INCLUDED_WB_SPI_H */