aboutsummaryrefslogtreecommitdiff
path: root/spi_usi.h
blob: 51a4f4040e3f2317be8d930c0a2880234cb8a1a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>

#ifndef _IOE_SPI_USI_H_
#define _IOE_SPI_USI_H_

/*
 * Initialize USI as SPI
 *
 * NOTE: Global interrupt must be enabled for right function.
 * { SREG |= _BV(7) }
 */
inline void ioe_spi_usi_init(void);
#ifdef IOE_SPI_USI_MASTER
/*
 * Swaps byte with slave over SPI.
 */
inline int8_t ioe_spi_usi_transfer(int8_t data);
#else
/*
 * Expose data for next master request.
 * Please don't use this when device is busy.
 * Best place to call this is ioe_spi_usi_retrieve().
 */
inline void ioe_spi_usi_expose(int8_t data);
/*
 * Returns NULL when device is no busy.
 * When device is busy, returned value is number of already send bits.
 */
inline uint8_t ioe_spi_usi_busy(void);
/*
 * Blocks processor until device is not busy.
 */
inline void ioe_spi_usi_join(void);

// Following function must be user defined
/*
 * This function must be defined by user.
 * This function is called every time transfer is finished.
 * And until return from this function interrupts are disabled.
 */
inline void ioe_spi_usi_retrieve(int8_t data);
#endif /* IOE_SPI_USI_MASTER */


#endif /* _IOE_SPI_USI_H_ */