uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
spi.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright 2016 Sebastian Neuser
8  *
9  * This file is part of the uMIDI firmware.
10  *
11  * the uMIDI firmware is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * The uMIDI firmware is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with the uMIDI firmware. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef _SPI_H
26 #define _SPI_H
27 
28 
29 //---------------- includes ----------------//
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 
34 #include "gpio.h"
35 
36 
37 //---------------- constants ----------------//
38 
39 
40 //---------------- data types ----------------//
41 
43 struct spi_config {
44  bool clk_phase;
45  bool clk_polarity;
46  uint8_t word_length;
47  const struct gpio_pin* clk_pin;
48  const struct gpio_pin* miso_pin;
49  const struct gpio_pin* mosi_pin;
50  const struct gpio_pin* ncs_pin;
51 };
52 
53 
54 //---------------- functions and procedures ----------------//
55 
60 void init_spi_module(const struct spi_config* config);
61 
66 uint16_t spi_transceive(uint16_t output);
67 
71 void spi_select(bool select);
72 
73 
74 
75 
76 //---------------- EOF ----------------//
77 #endif // _SPI_H
GPIO configuration and service functions.
bool clk_phase
Clock phase.
Definition: spi.h:44
uint16_t spi_transceive(uint16_t output)
Sends and receives a word (full duplex)
Definition: spi.c:66
uint8_t word_length
Word length.
Definition: spi.h:46
const struct gpio_pin * clk_pin
The GPIO pin connected to the clock line.
Definition: spi.h:47
void init_spi_module(const struct spi_config *config)
Configures the SPI module.
Definition: spi.c:43
void spi_select(bool select)
Controls the chip select line.
Definition: spi.c:117
const struct gpio_pin * ncs_pin
The GPIO pin connected to the (inverted) chip select line (may be NULL)
Definition: spi.h:50
const struct gpio_pin * mosi_pin
The GPIO pin connected to the MOSI line (may be NULL if not present)
Definition: spi.h:49
const struct gpio_pin * miso_pin
The GPIO pin connected to the MISO line (may be NULL if not present)
Definition: spi.h:48
bool clk_polarity
Clock polarity.
Definition: spi.h:45
Configuration structure for the SPI emulation module.
Definition: spi.h:43
Configuration of a single GPIO pin.
Definition: gpio.h:57