- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# include/spi/spi.h

Go to the documentation of this file.

    00001
    00045 #ifndef SPI_H_INCLUDED
    00046 #define SPI_H_INCLUDED
    00047
    00048 #include <stdint.h>
    00049 #include <stdbool.h>
    00050 #include <compiler.h>
    00051 #include <assert.h>
    00052 #include <gpio/portmux_gpio.h>
    00053 #include <buffer.h>
    00054 #include <dmac/dma_controller.h>
    00055
    00056 #ifdef CONFIG_SPI_USE_DMA
    00057 # include "dma.h"
    00058 #else
    00059 /*
    00060  * We will use the workqueue to achieve async behaviour
    00061  * without drowning in recursive function/callback calls
    00062  */
    00063 # include <workqueue.h>
    00064 #endif
    00065
    00067 typedef uint32_t spi_config_t;
    00068
    00072 struct spi_master
    00073 {
    00074         void *port;
    00075         struct spi_request *first_request;
    00076         struct spi_request **last_next;
    00077 #ifdef CONFIG_SPI_USE_DMA
    00078         struct dmac_channel *dma_tx_channel;
    00079         struct dmac_channel *dma_rx_channel;
    00080         struct dmac_request dma_tx_request;
    00081         struct dmac_request dma_rx_request;
    00082 #else
    00083         struct workqueue_item workqueue_item;
    00084 #endif
    00085 };
    00086
    00090 struct spi_device
    00091 {
    00092         struct spi_master *master;
    00093         spi_config_t config;
    00094         gpio_pin_t cs_pin;
    00095 };
    00096
    00097 enum local_buffer {
    00098         LOCAL_TXBUF,
    00099         LOCAL_RXBUF,
    00100         NONE,
    00101 };
    00102
    00104 #define SPI_REQUEST_STOP        (1 << 0)
    00105
    00109 struct spi_request
    00110 {
    00111         struct spi_device *device;
    00112         struct buffer *txbuf;
    00113         struct buffer *rxbuf;
    00114         size_t bytes_transferred;
    00115         int status;
    00116         enum local_buffer local_buffer;
    00117         unsigned long flags;
    00118         void (*request_done)(struct spi_request *request, void *context);
    00119         void *context;
    00120         struct spi_request *next;
    00121 };
    00122
    00123 #define SPI_CPHA        (1 << 0)
    00124 #define SPI_CPOL        (1 << 1)
    00125 #define SPI_MODE_0      0
    00126 #define SPI_MODE_1      (SPI_CPHA)
    00127 #define SPI_MODE_2      (SPI_CPOL)
    00128 #define SPI_MODE_3      (SPI_CPOL | SPI_CPHA)
    00129
    00130 #ifdef __cplusplus
    00131 extern "C" {
    00132 #endif
    00133
    00134 void spi_setup_master(struct spi_master *master, unsigned int id);
    00135
    00141 static inline void portmux_enable_spi_cs(gpio_pin_t pin)
    00142 {
    00143         portmux_select_gpio_pin(pin, PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
    00144 }
    00145
    00146 void spi_setup_device(
    00147                 struct spi_master *master,
    00148                 struct spi_device *device,
    00149                 unsigned long flags,
    00150                 uint32_t baudrate,
    00151                 gpio_pin_t cs_pin);
    00152
    00153 void spi_submit_request(
    00154                 struct spi_device *device,
    00155                 struct spi_request *request);
    00156
    00157 #ifdef __cplusplus
    00158 } /* extern "C" */
    00159 #endif
    00160
    00161 #endif  //SPI_H_INCLUDED
    00162