diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-05-24 11:11:48 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-05-24 11:11:48 -0600 |
commit | 4ec39dfdc2134d73a809f1159460156a101c89a5 (patch) | |
tree | a5633412cd7bab19d77ff44a953d4ba282bc34d4 | |
parent | d890cd67c3ef9e702a71bb5ed2f8a5e9e6d4cfac (diff) | |
download | px4-nuttx-4ec39dfdc2134d73a809f1159460156a101c89a5.tar.gz px4-nuttx-4ec39dfdc2134d73a809f1159460156a101c89a5.tar.bz2 px4-nuttx-4ec39dfdc2134d73a809f1159460156a101c89a5.zip |
Fix bugs in SLCD test and in SLCD CODEC
-rw-r--r-- | apps/examples/slcd/slcd_main.c | 88 | ||||
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_lse.c | 15 | ||||
-rw-r--r-- | nuttx/configs/stm32ldiscovery/src/stm32_lcd.c | 2 | ||||
-rw-r--r-- | nuttx/libc/misc/lib_slcddecode.c | 40 |
4 files changed, 113 insertions, 32 deletions
diff --git a/apps/examples/slcd/slcd_main.c b/apps/examples/slcd/slcd_main.c index 8cc88c6fc..1d93993fb 100644 --- a/apps/examples/slcd/slcd_main.c +++ b/apps/examples/slcd/slcd_main.c @@ -73,7 +73,7 @@ struct slcd_test_s /* The I/O buffer */ - char buffer[CONFIG_EXAMPLES_SLCD_BUFSIZE]; + uint8_t buffer[CONFIG_EXAMPLES_SLCD_BUFSIZE]; }; /**************************************************************************** @@ -81,19 +81,84 @@ struct slcd_test_s ****************************************************************************/ static struct slcd_test_s g_slcdtest; -static const char g_slcdhello[] = "hello"; +static const char g_slcdhello[] = "Hello"; /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: slcd_putc + * Name: slcd_dumpbuffer + * + * Description: + * Do a pretty buffer dump + * + ****************************************************************************/ + +void slcd_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen) +{ + int i; + int j; + int k; + + printf("%s (%p):\n", msg, buffer); + for (i = 0; i < buflen; i += 32) + { + printf("%04x: ", i); + for (j = 0; j < 32; j++) + { + k = i + j; + + if (j == 16) + { + printf(" "); + } + + if (k < buflen) + { + printf("%02x", buffer[k]); + } + else + { + printf(" "); + } + } + + printf(" "); + for (j = 0; j < 32; j++) + { + k = i + j; + + if (j == 16) + { + printf(" "); + } + + if (k < buflen) + { + if (buffer[k] >= 0x20 && buffer[k] < 0x7f) + { + printf("%c", buffer[k]); + } + else + { + printf("."); + } + } + } + + printf("\n"); + } +} + +/**************************************************************************** + * Name: slcd_flush ****************************************************************************/ static int slcd_flush(FAR struct lib_outstream_s *stream) { FAR struct slcd_test_s *priv = (FAR struct slcd_test_s *)stream; + FAR const uint8_t *buffer; ssize_t nwritten; ssize_t remaining; @@ -102,9 +167,13 @@ static int slcd_flush(FAR struct lib_outstream_s *stream) */ remaining = stream->nput; - while (remaining > 0); + buffer = priv->buffer; + + slcd_dumpbuffer("WRITING", buffer, remaining); + + while (remaining > 0) { - nwritten = write(priv->fd, priv->buffer, remaining); + nwritten = write(priv->fd, buffer, remaining); if (nwritten < 0) { int errcode = errno; @@ -118,6 +187,7 @@ static int slcd_flush(FAR struct lib_outstream_s *stream) else { remaining -= nwritten; + buffer += nwritten; } } @@ -143,7 +213,7 @@ static void slcd_putc(FAR struct lib_outstream_s *stream, int ch) /* If the buffer is full, flush it */ - if (stream->nput >=- CONFIG_EXAMPLES_SLCD_BUFSIZE) + if (stream->nput >= CONFIG_EXAMPLES_SLCD_BUFSIZE) { (void)slcd_flush(stream); } @@ -199,7 +269,7 @@ int slcd_main(int argc, char *argv[]) ret = ioctl(priv->fd, SLCDIOC_GEOMETRY, (unsigned long)&priv->geo); if (ret < 0) { - printf("Failed to open %s: %d\n", EXAMPLES_SLCD_DEVNAME, errno); + printf("ioctl(SLCDIOC_GEOMETRY) failed: %d\n", errno); goto errout_with_fd; } @@ -208,14 +278,18 @@ int slcd_main(int argc, char *argv[]) /* Home the cursor and clear the display */ + printf("Clear screen\n"); slcd_encode(SLCDCODE_CLEAR, 0, &priv->stream); /* Say hello */ + printf("Print [%s]\n", g_slcdhello); slcd_puts(&priv->stream, g_slcdhello); + slcd_flush(&priv->stream); /* Normal exit */ + printf("Test complete\n"); close(priv->fd); return 0; diff --git a/nuttx/arch/arm/src/stm32/stm32_lse.c b/nuttx/arch/arm/src/stm32/stm32_lse.c index 1080b4b20..56d68b1dc 100644 --- a/nuttx/arch/arm/src/stm32/stm32_lse.c +++ b/nuttx/arch/arm/src/stm32/stm32_lse.c @@ -41,6 +41,7 @@ #include "up_arch.h" +#include "stm32_pwr.h" #include "stm32_rcc.h" #include "stm32_waste.h" @@ -78,6 +79,16 @@ #ifdef CONFIG_STM32_STM32L15XX void stm32_rcc_enablelse(void) { + uint16_t pwrcr; + + /* The LSE is in the RTC domain and write access is denied to this domain + * after reset, you have to enable write access using DBP bit in the PWR CR + * register before to configuring the LSE. + */ + + pwrcr = getreg16(STM32_PWR_CR); + putreg16(pwrcr | PWR_CR_DBP, STM32_PWR_CR); + /* Enable the External Low-Speed (LSE) oscillator by setting the LSEON bit * the RCC CSR register. */ @@ -110,6 +121,10 @@ void stm32_rcc_enablelse(void) modifyreg32(STM32_RCC_CSR, 0, RCC_CSR_RTCEN); #endif #endif + + /* Restore the previous state of the DBP bit */ + + putreg16(pwrcr, STM32_PWR_CR); } #else diff --git a/nuttx/configs/stm32ldiscovery/src/stm32_lcd.c b/nuttx/configs/stm32ldiscovery/src/stm32_lcd.c index c94eeea09..57e09d9cb 100644 --- a/nuttx/configs/stm32ldiscovery/src/stm32_lcd.c +++ b/nuttx/configs/stm32ldiscovery/src/stm32_lcd.c @@ -841,7 +841,7 @@ static void slcd_writech(uint8_t ch, uint8_t curpos, uint8_t options) { segset |= 0x0002; } - else if ((options & SCLD_DP) != 0) + else if ((options & SCLD_COLON) != 0) { segset |= 0x0020; } diff --git a/nuttx/libc/misc/lib_slcddecode.c b/nuttx/libc/misc/lib_slcddecode.c index 04e9e569e..97fa951c8 100644 --- a/nuttx/libc/misc/lib_slcddecode.c +++ b/nuttx/libc/misc/lib_slcddecode.c @@ -109,7 +109,7 @@ static uint8_t slcd_nibble(uint8_t ascii) * Name: slcd_reget * * Description: - * We have unused characters from the last, unsuccessful decode attempt. + * We have unused characters from the last, unsuccessful decode attempt. * Return one of these instead of the new character from the stream. * * Input Parameters: @@ -260,9 +260,14 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream, if (!IS_HEX(ch)) { + /* Decode the value following the bracket */ + + code = CODE_RETURN(ch); + count = 0; + /* Verify the special CLCD action code */ - if (ch < (int)FIRST_SLCDCODE || ch > (int)LAST_SLCDCODE) + if (code < (int)FIRST_SLCDCODE || code > (int)LAST_SLCDCODE) { /* Not a special command code.. put the character in the reget * buffer. @@ -275,11 +280,6 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream, return slcd_reget(state, pch, parg); } - - /* Provide the return values */ - - code = CODE_RETURN(ch); - count = 0; } else { @@ -312,7 +312,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream, return slcd_reget(state, pch, parg); } - + /* Save the second character of the two byte hexidecimal number */ state->buf[NDX_COUNTL] = (uint8_t)ch; @@ -337,28 +337,21 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream, state->buf[NDX_CODE5] = (uint8_t)ch; state->nch = NCH_CODE5; - /* Verify the special CLCD action code */ - - if (ch < (int)FIRST_SLCDCODE || ch > (int)LAST_SLCDCODE) - { - /* Not a special command code. Return the ESC now and the rest - * of the characters later. - */ - - return slcd_reget(state, pch, parg); - } - - /* Provide the return values */ + /* Get the code and the count values. All count values must be greater + * than 0 or something is wrong. + */ code = CODE_RETURN(ch); count = slcd_nibble(state->buf[NDX_COUNTH]) << 4; slcd_nibble(state->buf[NDX_COUNTL]); - /* All count values must be greater than 0 or something is wrong */ + /* Verify the special CLCD action code */ - if (count < 1) + if (code < (int)FIRST_SLCDCODE || code > (int)LAST_SLCDCODE || count < 1) { - /* Return the ESC now and the rest of the characters later. */ + /* Not a special command code. Return the ESC now and the rest + * of the characters later. + */ return slcd_reget(state, pch, parg); } @@ -374,4 +367,3 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream, state->nch = 0; return SLCDRET_SPEC; } - |