X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=atusb%2Fspi.c;fp=atusb%2Fspi.c;h=3fa571575bf4f77cf72a2504572cb9fd4fba3cc1;hb=dd4bc9ff49b9a7075e579fdd62fd930d27a9a7df;hp=0000000000000000000000000000000000000000;hpb=c164bf7f87f9081fee7e1a186dd7a87a9a020b9e;p=linux-libre-firmware.git diff --git a/atusb/spi.c b/atusb/spi.c new file mode 100644 index 0000000..3fa5715 --- /dev/null +++ b/atusb/spi.c @@ -0,0 +1,51 @@ +/* + * fw/spi.c - ATmega8 family SPI I/O + * + * Written 2011, 2013 by Werner Almesberger + * Copyright 2011, 2013 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include + +#include + +#include "board.h" +#include "spi.h" + + +uint8_t spi_io(uint8_t v) +{ +// while (!(UCSR1A & 1 << UDRE1)); + SPI_DATA = v; + SPI_WAIT_DONE(); + return SPI_DATA; +} + + +void spi_end(void) +{ +// while (!(UCSR1A & 1 << TXC1)); + SET(nSS); +} + + +void spi_recv_block(uint8_t *buf, uint8_t n) +{ + if (!n) + return; + SPI_DATA = 0; + while (--n) { + SPI_WAIT_DONE(); + *buf++ = SPI_DATA; + SPI_DATA = 0; + } + SPI_WAIT_DONE(); + *buf++ = SPI_DATA; +}