]>
cloudbase.mooo.com Git - z180-stamp.git/blob - include/spi.h
2 * (C) Copyright 2009,2014 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0+
10 #define SPI_PORT PORTB /* SPI Connection port */
11 #define SPI_DDR DDRB /* SPI Direction port */
20 #define SPI_SET_SPEED_F_2 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0)
21 #define SPI_SET_SPEED_F_4 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0)
22 #define SPI_SET_SPEED_F_8 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (1<<SPI2X); } while(0)
23 #define SPI_SET_SPEED_F_16 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0)
24 #define SPI_SET_SPEED_F_32 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0)
25 #define SPI_SET_SPEED_F_64 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0)
26 #define SPI_SET_SPEED_F_128 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0)
28 /** switch to fast SPI Clock */
29 #define SPISetFastClock() SPI_SET_SPEED_F_2
30 #define SPISetSlowClock() SPI_SET_SPEED_F_8
31 #define SPISetMMCInitClock() SPI_SET_SPEED_F_64
33 #define SPI_OFF() do { SPCR = 0; } while(0)
35 static inline __attribute__((always_inline
)) void spi_wait(void) {
36 loop_until_bit_is_set(SPSR
,SPIF
);
39 static inline __attribute__((always_inline
)) void spi_write(uint8_t a
) {
43 static inline void spi_xmit(uint8_t a
){
48 static inline uint8_t spi_rcvr(void) {