aboutsummaryrefslogtreecommitdiff
path: root/drivers/chibios/spi_master.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/chibios/spi_master.h')
-rw-r--r--drivers/chibios/spi_master.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/drivers/chibios/spi_master.h b/drivers/chibios/spi_master.h
new file mode 100644
index 000000000..0c18587c9
--- /dev/null
+++ b/drivers/chibios/spi_master.h
@@ -0,0 +1,78 @@
1/* Copyright 2020 Nick Brassel (tzarc)
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <ch.h>
20#include <hal.h>
21#include <quantum.h>
22
23#ifndef SPI_DRIVER
24# define SPI_DRIVER SPID2
25#endif
26
27#ifndef SPI_SCK_PIN
28# define SPI_SCK_PIN B13
29#endif
30
31#ifndef SPI_SCK_PAL_MODE
32# define SPI_SCK_PAL_MODE 5
33#endif
34
35#ifndef SPI_MOSI_PIN
36# define SPI_MOSI_PIN B15
37#endif
38
39#ifndef SPI_MOSI_PAL_MODE
40# define SPI_MOSI_PAL_MODE 5
41#endif
42
43#ifndef SPI_MISO_PIN
44# define SPI_MISO_PIN B14
45#endif
46
47#ifndef SPI_MISO_PAL_MODE
48# define SPI_MISO_PAL_MODE 5
49#endif
50
51typedef int16_t spi_status_t;
52
53#define SPI_STATUS_SUCCESS (0)
54#define SPI_STATUS_ERROR (-1)
55#define SPI_STATUS_TIMEOUT (-2)
56
57#define SPI_TIMEOUT_IMMEDIATE (0)
58#define SPI_TIMEOUT_INFINITE (0xFFFF)
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63void spi_init(void);
64
65bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor);
66
67spi_status_t spi_write(uint8_t data);
68
69spi_status_t spi_read(void);
70
71spi_status_t spi_transmit(const uint8_t *data, uint16_t length);
72
73spi_status_t spi_receive(uint8_t *data, uint16_t length);
74
75void spi_stop(void);
76#ifdef __cplusplus
77}
78#endif