From 98997691d314b6143fab27bfa1832c200e39bb57 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 30 Dec 2009 23:28:40 +0100 Subject: Add first version of spi_enable()/spi_disable(). --- lib/spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/spi.c') diff --git a/lib/spi.c b/lib/spi.c index 02936ee..d11cf5d 100644 --- a/lib/spi.c +++ b/lib/spi.c @@ -51,6 +51,27 @@ int spi_init_master(u32 spi, u32 br, u32 cpol, u32 cpha, u32 dff, u32 lsbfirst) return 0; /* TODO */ } +/* TODO: Error handling? */ +void spi_enable(u32 spi) +{ + u32 reg32; + + reg32 = SPI_CR1(spi); + reg32 |= SPI_CR1_SPE; /* Enable SPI. */ + SPI_CR1(spi) = reg32; +} + +/* TODO: Error handling? */ +void spi_disable(u32 spi) +{ + u32 reg32; + + /* TODO: Follow procedure from section 23.3.8 in the techref manual. */ + reg32 = SPI_CR1(spi); + reg32 &= ~(SPI_CR1_SPE); /* Disable SPI. */ + SPI_CR1(spi) = reg32; +} + void spi_write(u32 spi, u16 data) { /* Write data (8 or 16 bits, depending on DFF) into DR. */ -- cgit v1.2.3