diff options
Diffstat (limited to 'drivers/avr/spi_master.h')
| -rw-r--r-- | drivers/avr/spi_master.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/avr/spi_master.h b/drivers/avr/spi_master.h new file mode 100644 index 000000000..0bab2dc24 --- /dev/null +++ b/drivers/avr/spi_master.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* Copyright 2020 | ||
| 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 "quantum.h" | ||
| 20 | |||
| 21 | typedef int16_t spi_status_t; | ||
| 22 | |||
| 23 | // Hardware SS pin is defined in the header so that user code can refer to it | ||
| 24 | #if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) | ||
| 25 | # define SPI_SS_PIN B0 | ||
| 26 | #elif defined(__AVR_ATmega32A__) | ||
| 27 | # define SPI_SS_PIN B4 | ||
| 28 | #elif defined(__AVR_ATmega328P__) | ||
| 29 | # define SPI_SS_PIN B2 | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #define SPI_STATUS_SUCCESS (0) | ||
| 33 | #define SPI_STATUS_ERROR (-1) | ||
| 34 | #define SPI_STATUS_TIMEOUT (-2) | ||
| 35 | |||
| 36 | #define SPI_TIMEOUT_IMMEDIATE (0) | ||
| 37 | #define SPI_TIMEOUT_INFINITE (0xFFFF) | ||
| 38 | |||
| 39 | #ifdef __cplusplus | ||
| 40 | extern "C" { | ||
| 41 | #endif | ||
| 42 | void spi_init(void); | ||
| 43 | |||
| 44 | void spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint8_t divisor); | ||
| 45 | |||
| 46 | spi_status_t spi_write(uint8_t data, uint16_t timeout); | ||
| 47 | |||
| 48 | spi_status_t spi_read(uint16_t timeout); | ||
| 49 | |||
| 50 | spi_status_t spi_transmit(const uint8_t *data, uint16_t length, uint16_t timeout); | ||
| 51 | |||
| 52 | spi_status_t spi_receive(uint8_t *data, uint16_t length, uint16_t timeout); | ||
| 53 | |||
| 54 | void spi_stop(void); | ||
| 55 | #ifdef __cplusplus | ||
| 56 | } | ||
| 57 | #endif | ||
