From f99437434b0bff44da57797b6b96691289f10631 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Sat, 19 Oct 2013 15:12:57 +0000 Subject: [PATCH] Adding UART git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@121 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- lib/spi.c | 14 ++++---------- lib/uart.c | 16 ++++------------ multitouchglove.c | 1 - 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/spi.c b/lib/spi.c index 242de71..a21609a 100644 --- 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++; } } diff --git a/lib/uart.c b/lib/uart.c index a97b51d..c7e7499 100644 --- a/lib/uart.c +++ b/lib/uart.c @@ -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++)); } diff --git a/multitouchglove.c b/multitouchglove.c index d5bcf38..8691fa5 100644 --- a/multitouchglove.c +++ b/multitouchglove.c @@ -65,7 +65,6 @@ void resetLed() static void blinkerTask(void *p) { - uint8_t buffer[5]; printf("Start blinker task\n"); while (1) { -- 2.30.2