Adding UART
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Sat, 19 Oct 2013 15:12:57 +0000 (15:12 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Sat, 19 Oct 2013 15:12:57 +0000 (15:12 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@121 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

lib/spi.c
lib/uart.c
multitouchglove.c

index 242de71da59e12b5b148bca813a861f971a4f289..a21609aece8838b01a69b719724e289988ac6588 100644 (file)
--- a/lib/spi.c
+++ b/lib/spi.c
@@ -99,7 +99,7 @@ void spi_read(uint8_t id, uint8_t *buffer, uint8_t nb)
 
     struct spiInitDef_t * spiInitDef = spiInitDefs + id - 1;
 
-    while(nb >= 1)
+    while(nb--)
     {
         taskENTER_CRITICAL();
 
@@ -109,13 +109,10 @@ void spi_read(uint8_t id, uint8_t *buffer, uint8_t nb)
 
         //read data
         while (SPI_I2S_GetFlagStatus(spiInitDef->id, SPI_I2S_FLAG_RXNE) == RESET);
-        *buffer = (uint8_t) SPI_I2S_ReceiveData(spiInitDef->id);
+        *buffer++ = (uint8_t) SPI_I2S_ReceiveData(spiInitDef->id);
         //printf("%02x", *buffer);
 
         taskEXIT_CRITICAL();
-
-        nb--;
-        buffer++;
     }
 }
 
@@ -126,21 +123,18 @@ void spi_write(uint8_t id, uint8_t *buffer, uint8_t nb)
 
     struct spiInitDef_t * spiInitDef = spiInitDefs + id - 1;
 
-    while(nb >= 1)
+    while(nb--)
     {
         taskENTER_CRITICAL();
 
         //send data
         while (SPI_I2S_GetFlagStatus(spiInitDef->id, SPI_I2S_FLAG_TXE) == RESET);
-        SPI_I2S_SendData(spiInitDef->id, *buffer);
+        SPI_I2S_SendData(spiInitDef->id, *buffer++);
 
         //read, because that's the rule
         while (SPI_I2S_GetFlagStatus(spiInitDef->id, SPI_I2S_FLAG_RXNE) == RESET);
         SPI_I2S_ReceiveData(spiInitDef->id);
 
         taskEXIT_CRITICAL();
-
-        nb--;
-        buffer++;
     }
 }
index a97b51dca41b260baeec675ea163a70fcf9fa14c..c7e74996cf0a2d63774f466f18db1d4735d359b2 100644 (file)
@@ -99,21 +99,13 @@ uint8_t uart_receive_char(uint8_t id)
 
 void uart_read(uint8_t id, uint8_t *buffer, uint8_t nb)
 {
-    while (nb > 0)
-    {
-        *buffer = uart_receive_char(id);
-        buffer++;
-        nb--;
-    }
+    while (nb--)
+        *buffer++ = uart_receive_char(id);
 }
 
 void uart_write(uint8_t id, uint8_t *buffer, uint8_t nb)
 {
-    while (nb > 0)
-    {
-        uart_send_char(id, (uint8_t) (*buffer));
-        buffer++;
-        nb--;
-    }
+    while (nb--)
+        uart_send_char(id, (uint8_t) (*buffer++));
 }
 
index d5bcf38546c59e4a7de8becca7bc6a4ab3556624..8691fa5a888c3d602a50cb20fc56b5686158e187 100644 (file)
@@ -65,7 +65,6 @@ void resetLed()
 
 static void blinkerTask(void *p) 
 {
-    uint8_t buffer[5];
     printf("Start blinker task\n");
     while (1) 
     {