aboutsummaryrefslogtreecommitdiff
path: root/lib/spi.c
diff options
context:
space:
mode:
authorUwe Hermann2009-12-30 23:28:40 +0100
committerUwe Hermann2009-12-30 23:28:40 +0100
commit98997691d314b6143fab27bfa1832c200e39bb57 (patch)
tree2ae6e494a4a1896f7e08c7786982733fe5e9f5a2 /lib/spi.c
parenta7a3770d5198d26c963127094a18175696f04827 (diff)
Add first version of spi_enable()/spi_disable().
Diffstat (limited to 'lib/spi.c')
-rw-r--r--lib/spi.c21
1 files changed, 21 insertions, 0 deletions
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. */