Prusa MINI Firmware overview
private_spi.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 #include "softspi.h"
25 #include <stdint.h>
26 
27 template<uint8_t MisoPin, uint8_t MosiPin, uint8_t SckPin>
28 class SPIclass {
29  static SoftSPI<MisoPin, MosiPin, SckPin> softSPI;
30  public:
31  FORCE_INLINE static void init() { softSPI.begin(); }
32  FORCE_INLINE static void send(uint8_t data) { softSPI.send(data); }
33  FORCE_INLINE static uint8_t receive() { return softSPI.receive(); }
34 };
35 
36 // Hardware SPI
37 template<>
39  public:
40  FORCE_INLINE static void init() {
44  }
46  #if defined(__AVR__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
47  SPDR = 0;
48  for (;!TEST(SPSR, SPIF););
49  return SPDR;
50  #else
51  return spiRec();
52  #endif
53  }
54 };
SPIclass< MISO_PIN, MOSI_PIN, SCK_PIN >::receive
static FORCE_INLINE uint8_t receive()
Definition: private_spi.h:45
OUT_WRITE
#define OUT_WRITE(IO, V)
Definition: fastio.h:108
LOW
#define LOW
Definition: wiring_constants.h:70
spiRec
uint8_t spiRec()
SoftSPI::send
FORCE_INLINE void send(uint8_t data)
Definition: softspi.h:688
data
uint8_t data[8]
Definition: masstorage.h:49
SoftSPI::receive
FORCE_INLINE uint8_t receive()
Definition: softspi.h:671
SPIclass::init
static FORCE_INLINE void init()
Definition: private_spi.h:31
SET_INPUT_PULLUP
#define SET_INPUT_PULLUP(IO)
Definition: fastio.h:100
FORCE_INLINE
#define FORCE_INLINE
Definition: macros.h:40
SPIclass::receive
static FORCE_INLINE uint8_t receive()
Definition: private_spi.h:33
SoftSPI< MisoPin, MosiPin, SckPin >
MISO_PIN
#define MISO_PIN
Definition: spi_pins.h:58
uint8_t
const uint8_t[]
Definition: 404_html.c:3
SCK_PIN
#define SCK_PIN
Definition: spi_pins.h:55
SPIclass::send
static FORCE_INLINE void send(uint8_t data)
Definition: private_spi.h:32
SoftSPI::begin
void begin()
Definition: softspi.h:661
MOSI_PIN
#define MOSI_PIN
Definition: spi_pins.h:61
HIGH
#define HIGH
Definition: wiring_constants.h:71
TEST
#define TEST(n, b)
Definition: macros.h:81
softspi.h
SPIclass< MISO_PIN, MOSI_PIN, SCK_PIN >::init
static FORCE_INLINE void init()
Definition: private_spi.h:40
SPIclass
Definition: private_spi.h:28