code clean up!
[my-code/arm.git] / betty / spi.c
diff --git a/betty/spi.c b/betty/spi.c
new file mode 100644 (file)
index 0000000..198213d
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * spi.c - serial peripheral interface 0/1
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#include "spi.h"
+
+/*
+ * functions
+ */
+
+void spi1_init(u8 width,u8 type,u8 div) {
+
+       if((width<8)|(width>16))
+               width=8;
+       if(width==16)
+               width=0;
+
+       div&=0xfe;
+       if(div<8)
+               div=8;
+
+       S1SPCR=(1<<2)|(width<<8)|(type<<5);
+       S1SPCCR=div;
+}
+
+void spi1_send(u16 data) {
+
+       S1SPDR=data;
+
+       while(!(S1SPSR&(1<<7)))
+               continue;
+}