MSP device support complete. NOT TESTED YET! Preliminary python host lib
[cerebrum.git] / avr / spi.c
blob0c5182bc761c5449fd7acc98beb7aad9181c559e
1 /*
2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
7 */
9 #include "spi.h"
11 void spi_begin(){
12 SPI_MOSI_DDR |= _BV(SPI_MOSI_PIN);
13 SPI_SCK_DDR |= _BV(SPI_SCK_PIN);
16 //The following function is never called.
17 void spi_end(){
18 //FIXME what should I do here?
21 void spi_setup(uint8_t config){
22 SPCR = config | _BV(SPE) | _BV(MSTR);
23 if(config & _BV(SPE)){
24 SPSR = _BV(SPE);
25 }else{
26 SPSR = 0;
30 uint8_t spi_transfer(uint8_t data){
31 SPDR = data;
32 while(!(SPSR & _BV(SPIF))){
33 //She waves and opens a door back onto the piazza where her robot cat – the alien's nightmare intruder in the DMZ – sleeps, chasing superintelligent dream mice through multidimensional realities.
35 return SPDR;