]> hackdaworld.org Git - my-code/arm.git/blob - betty/spi.c
enhanced linker script and startup
[my-code/arm.git] / betty / spi.c
1 /*
2  * spi.c - serial peripheral interface 0/1
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "spi.h"
9
10 /*
11  * functions
12  */
13
14 void spi1_init(u8 width,u8 type,u8 div) {
15
16         if((width<8)|(width>16))
17                 width=8;
18         if(width==16)
19                 width=0;
20
21         div&=0xfe;
22         if(div<8)
23                 div=8;
24
25         S1SPCR=(1<<2)|(width<<8)|(type<<5);
26         S1SPCCR=div;
27 }
28
29 void spi1_send(u16 data) {
30
31         S1SPDR=data;
32
33         while(!(S1SPSR&(1<<7)))
34                 continue;
35 }