Subversion Repositories idreammicro-avr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
67 jlesech 1
/**************************************************************************//**
2
 * \brief SPI library
3
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
4
 * \version 1.0
5
 * \date 20110315
6
 *
7
 * This file is part of the iDreamMicro library.
8
 *
9
 * This library is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program. If not, see http://www.gnu.org/licenses/
21
 ******************************************************************************/
22
 
23
/**************************************************************************//**
24
 * \headerfile spi.h
25
 ******************************************************************************/
26
 
27
#ifndef H__IDREAMMICRO__SPI__H
28
#define H__IDREAMMICRO__SPI__H
29
 
30
#ifdef _cplusplus
31
extern "C"{
32
#endif
33
 
34
/******************************************************************************
35
 * Header file inclusions.
36
 ******************************************************************************/
37
 
38
#include <stdint.h>
39
 
40
/******************************************************************************
41
 * Public types.
42
 ******************************************************************************/
43
 
44
/**************************************************************************//**
45
 *
46
 ******************************************************************************/
47
typedef enum spi__clock_rates
48
{
49
    SPI__CLOCK_RATE__FOSC_OVER_2,
50
    SPI__CLOCK_RATE__FOSC_OVER_4,
51
    SPI__CLOCK_RATE__FOSC_OVER_8,
52
    SPI__CLOCK_RATE__FOSC_OVER_16,
53
    SPI__CLOCK_RATE__FOSC_OVER_32,
54
    SPI__CLOCK_RATE__FOSC_OVER_64,
55
    SPI__CLOCK_RATE__FOSC_OVER_128
56
} spi__clock_rate_t;
57
 
58
/**************************************************************************//**
59
 *
60
 ******************************************************************************/
61
typedef enum spi__data_modes
62
{
63
    SPI__DATA_MODE_0,
64
    SPI__DATA_MODE_1,
65
    SPI__DATA_MODE_2,
66
    SPI__DATA_MODE_3
67
} spi__data_mode_t;
68
 
69
/**************************************************************************//**
70
 *
71
 ******************************************************************************/
72
typedef enum spi__data_orders
73
{
74
    SPI__DATA_ORDER__MSB_FIRST,
75
    SPI__DATA_ORDER__LSB_FIRST
76
} spi__data_order_t;
77
 
78
/******************************************************************************
79
 * Public function prototypes.
80
 ******************************************************************************/
81
 
82
/**************************************************************************//**
83
 * \fn void spi_master__initialize(void)
84
 *
85
 * \brief Initialize SPI in master mode.
86
 ******************************************************************************/
87
void
88
spi_master__initialize
89
(
90
    void
91
);
92
 
93
/**************************************************************************//**
94
 * \fn void spi_master__transmit(uint8_t data)
95
 *
96
 * \brief Transmit data.
97
 *
98
 * \param   data    Data to transmit.
99
 ******************************************************************************/
100
void
101
spi_master__transmit
102
(
103
    uint8_t data
104
);
105
 
106
/**************************************************************************//**
107
 * \fn void spi_slave__initialize(void)
108
 *
109
 * \brief Initialize SPI in slave mode.
110
 ******************************************************************************/
111
void
112
spi_slave__initialize
113
(
114
    void
115
);
116
 
117
/**************************************************************************//**
118
 * \fn uint8_t spi_slave__receive(void)
119
 *
120
 * \brief Receive data.
121
 *
122
 * \return Received data.
123
 ******************************************************************************/
124
uint8_t
125
spi_slave__receive
126
(
127
    void
128
);
129
 
130
/**************************************************************************//**
131
 * \fn void spi__set_clock_rate(spi__clock_rate_t clock_rate)
132
 *
133
 * \brief Set clock rate.
134
 *
135
 * \param[in]   clock_rate  Clock rate to set.
136
 ******************************************************************************/
137
void
138
spi__set_clock_rate
139
(
140
    spi__clock_rate_t   clock_rate
141
);
142
 
143
/**************************************************************************//**
144
 * \fn void spi__set_data_mode(spi__data_mode_t mode)
145
 *
146
 * \brief Set SPI data mode.
147
 *
148
 * \param[in]   mode    Data mode to set.
149
 ******************************************************************************/
150
void
151
spi__set_data_mode
152
(
153
    spi__data_mode_t    data_mode
154
);
155
 
156
/**************************************************************************//**
157
 * \fn void spi__set_data_order(spi__data_order_t data_order)
158
 *
159
 * \brief Set SPI data order.
160
 *
161
 * \param[in]   data_order  Data order to set.
162
 ******************************************************************************/
163
void
164
spi__set_data_order
165
(
166
    spi__data_order_t   data_order
167
);
168
 
169
#ifdef _cplusplus
170
}
171
#endif
172
 
173
#endif /* H__IDREAMMICRO__SPI__H */
174