diff --git a/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c b/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c index 59e3d99182..78a8037ed1 100644 --- a/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c +++ b/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c @@ -226,15 +226,6 @@ * Private Type Definition ****************************************************************************/ -/* SLCD incoming stream structure */ - -struct slcd_instream_s -{ - struct lib_instream_s stream; - const char *buffer; - ssize_t nbytes; -}; - /* Global SLCD state */ struct sam_slcdstate_s @@ -514,30 +505,6 @@ static inline void slcd_clrdp(uint8_t curpos) slcd_clrpixel(&g_binfo[curpos + 3]); } -/**************************************************************************** - * Name: slcd_getstream - * - * Description: - * Get one character from the keyboard. - * - ****************************************************************************/ - -static int slcd_getstream(struct lib_instream_s *instream) -{ - struct slcd_instream_s *slcdstream = - (struct slcd_instream_s *)instream; - - DEBUGASSERT(slcdstream && slcdstream->buffer); - if (slcdstream->nbytes > 0) - { - slcdstream->nbytes--; - slcdstream->stream.nget++; - return (int)*slcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: slcd_getcontrast ****************************************************************************/ @@ -899,7 +866,7 @@ static ssize_t slcd_read(struct file *filep, static ssize_t slcd_write(struct file *filep, const char *buffer, size_t len) { - struct slcd_instream_s instream; + struct lib_meminstream_s instream; struct slcdstate_s state; enum slcdret_e result; uint8_t ch; @@ -908,10 +875,7 @@ static ssize_t slcd_write(struct file *filep, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = slcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = len; + lib_meminstream(&instream, buffer, len); /* Initialize the SLCD decode state buffer */ @@ -920,8 +884,8 @@ static ssize_t slcd_write(struct file *filep, /* Decode and process every byte in the input buffer */ options = 0; - while ((result = slcd_decode(&instream.stream, &state, &ch, &count)) != - SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { lcdinfo("slcd_decode returned result=%d char=%d count=%d\n", result, ch, count); diff --git a/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c b/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c index 4832ca4ad1..cebd5eeda7 100644 --- a/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c +++ b/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c @@ -285,15 +285,6 @@ * Private Type Definition ****************************************************************************/ -/* SLCD incoming stream structure */ - -struct slcd_instream_s -{ - struct lib_instream_s stream; - const char *buffer; - ssize_t nbytes; -}; - /* Global SLCD state */ struct stm32_slcdstate_s @@ -530,30 +521,6 @@ static void slcd_clear(void) putreg32(1, SLCD_SR_UDR_BB); } -/**************************************************************************** - * Name: slcd_getstream - * - * Description: - * Get one character from the keyboard. - * - ****************************************************************************/ - -static int slcd_getstream(struct lib_instream_s *instream) -{ - struct slcd_instream_s *slcdstream = (struct slcd_instream_s *) - instream; - - DEBUGASSERT(slcdstream && slcdstream->buffer); - if (slcdstream->nbytes > 0) - { - slcdstream->nbytes--; - slcdstream->stream.nget++; - return (int)*slcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: slcd_getcontrast ****************************************************************************/ @@ -1165,7 +1132,7 @@ static ssize_t slcd_read(struct file *filep, char *buffer, static ssize_t slcd_write(struct file *filep, const char *buffer, size_t len) { - struct slcd_instream_s instream; + struct lib_meminstream_s instream; struct slcdstate_s state; enum slcdret_e result; uint8_t ch; @@ -1175,17 +1142,14 @@ static ssize_t slcd_write(struct file *filep, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = slcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = len; + lib_meminstream(&instream, buffer, len); /* Prime the pump. This is messy, but necessary to handle decoration on a * character based on any following period or colon. */ memset(&state, 0, sizeof(struct slcdstate_s)); - result = slcd_decode(&instream.stream, &state, &prev, &count); + result = slcd_decode(&instream.public, &state, &prev, &count); lcdinfo("slcd_decode returned result=%d char=%d count=%d\n", result, prev, count); @@ -1209,8 +1173,8 @@ static ssize_t slcd_write(struct file *filep, /* Now decode and process every byte in the input buffer */ - while ((result = slcd_decode(&instream.stream, &state, &ch, &count)) != - SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { lcdinfo("slcd_decode returned result=%d char=%d count=%d\n", result, ch, count); diff --git a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c index cae80ad845..6ae3d987c6 100644 --- a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c +++ b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c @@ -119,15 +119,6 @@ * Private Type Definition ****************************************************************************/ -/* SLCD incoming stream structure */ - -struct lcd_instream_s -{ - struct lib_instream_s stream; - const char *buffer; - ssize_t nbytes; -}; - /* Global LCD state */ struct lcd1602_2 @@ -147,7 +138,7 @@ struct lcd1602_2 #ifdef CONFIG_DEBUG_LCD_INFO static void lcd_dumpstate(const char *msg); static void lcd_dumpstream(const char *msg, - const struct lcd_instream_s *stream); + const struct lib_meminstream_s *stream); #else # define lcd_dumpstate(msg) # define lcd_dumpstream(msg, stream) @@ -245,39 +236,15 @@ static void lcd_dumpstate(const char *msg) #ifdef CONFIG_DEBUG_LCD_INFO static void lcd_dumpstream(const char *msg, - const struct lcd_instream_s *stream) + const struct lib_meminstream_s *stream) { lcdinfo("%s:\n", msg); lcdinfo(" nget: %d nbytes: %d\n", - stream->stream.nget, stream->nbytes); - lib_dumpbuffer("STREAM", stream->buffer, stream->nbytes); + stream->public.nget, stream->buflen); + lib_dumpbuffer("STREAM", stream->buffer, stream->buflen); } #endif -/**************************************************************************** - * Name: lcd_getstream - * - * Description: - * Get one character from the keyboard. - * - ****************************************************************************/ - -static int lcd_getstream(struct lib_instream_s *instream) -{ - struct lcd_instream_s *lcdstream = - (struct lcd_instream_s *)instream; - - DEBUGASSERT(lcdstream && lcdstream->buffer); - if (lcdstream->nbytes > 0) - { - lcdstream->nbytes--; - lcdstream->stream.nget++; - return (int)*lcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: lcd_brightness * @@ -829,7 +796,7 @@ static ssize_t lcd_read(struct file *filep, char *buffer, size_t len) static ssize_t lcd_write(struct file *filep, const char *buffer, size_t len) { - struct lcd_instream_s instream; + struct lib_meminstream_s instream; struct slcdstate_s state; enum slcdret_e result; uint8_t ch; @@ -837,18 +804,14 @@ static ssize_t lcd_write(struct file *filep, const char *buffer, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = lcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = len; - + lib_meminstream(&instream, buffer, len); lcd_dumpstream("BEFORE WRITE", &instream); /* Now decode and process every byte in the input buffer */ memset(&state, 0, sizeof(struct slcdstate_s)); - while ((result = slcd_decode(&instream.stream, - &state, &ch, &count)) != SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { lcdinfo("slcd_decode returned result=%d char=%d count=%d\n", result, ch, count); diff --git a/drivers/lcd/ht16k33_14seg.c b/drivers/lcd/ht16k33_14seg.c index e5e0413716..565e569beb 100644 --- a/drivers/lcd/ht16k33_14seg.c +++ b/drivers/lcd/ht16k33_14seg.c @@ -111,13 +111,6 @@ struct ht16k33_dev_s mutex_t lock; }; -struct lcd_instream_s -{ - struct lib_instream_s stream; - FAR const char *buffer; - ssize_t nbytes; -}; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -706,29 +699,6 @@ static void lcd_codec_action(FAR struct ht16k33_dev_s *priv, } } -/**************************************************************************** - * Name: lcd_getstream - * - * Description: - * Get one character from the LCD codec stream. - * - ****************************************************************************/ - -static int lcd_getstream(FAR struct lib_instream_s *instream) -{ - FAR struct lcd_instream_s *lcdstream = - (FAR struct lcd_instream_s *)instream; - - if (lcdstream->nbytes > 0) - { - lcdstream->nbytes--; - lcdstream->stream.nget++; - return (int)*lcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: lcd_init * @@ -798,7 +768,7 @@ static ssize_t ht16k33_write(FAR struct file *filep, FAR const char *buffer, { FAR struct inode *inode = filep->f_inode; FAR struct ht16k33_dev_s *priv = inode->i_private; - struct lcd_instream_s instream; + struct lib_meminstream_s instream; struct slcdstate_s state; enum slcdret_e result; uint8_t ch; @@ -808,16 +778,13 @@ static ssize_t ht16k33_write(FAR struct file *filep, FAR const char *buffer, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = lcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = buflen; + lib_meminstream(&instream, buffer, buflen); /* Now decode and process every byte in the input buffer */ memset(&state, 0, sizeof(struct slcdstate_s)); - while ((result = slcd_decode(&instream.stream, &state, &ch, &count)) != - SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { /* Is there some pending scroll? */ diff --git a/drivers/lcd/pcf8574_lcd_backpack.c b/drivers/lcd/pcf8574_lcd_backpack.c index 50cc6a22db..07dd614baf 100644 --- a/drivers/lcd/pcf8574_lcd_backpack.c +++ b/drivers/lcd/pcf8574_lcd_backpack.c @@ -83,13 +83,6 @@ struct pcf8574_lcd_dev_s mutex_t lock; /* mutex */ }; -struct lcd_instream_s -{ - struct lib_instream_s stream; - FAR const char *buffer; - ssize_t nbytes; -}; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -971,29 +964,6 @@ static void lcd_codec_action(FAR struct pcf8574_lcd_dev_s *priv, } } -/**************************************************************************** - * Name: lcd_getstream - * - * Description: - * Get one character from the LCD codec stream. - * - ****************************************************************************/ - -static int lcd_getstream(FAR struct lib_instream_s *instream) -{ - FAR struct lcd_instream_s *lcdstream = - (FAR struct lcd_instream_s *)instream; - - if (lcdstream->nbytes > 0) - { - lcdstream->nbytes--; - lcdstream->stream.nget++; - return (int)*lcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: lcd_fpos_to_curpos * @@ -1214,7 +1184,7 @@ static ssize_t pcf8574_lcd_write(FAR struct file *filep, FAR struct inode *inode = filep->f_inode; FAR struct pcf8574_lcd_dev_s *priv = (FAR struct pcf8574_lcd_dev_s *)inode->i_private; - struct lcd_instream_s instream; + struct lib_meminstream_s instream; uint8_t row; uint8_t col; struct slcdstate_s state; @@ -1226,10 +1196,7 @@ static ssize_t pcf8574_lcd_write(FAR struct file *filep, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = lcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = buflen; + lib_meminstream(&instream, buffer, buflen); /* Get the current cursor position now; we'll keep track of it as we go */ @@ -1238,8 +1205,8 @@ static ssize_t pcf8574_lcd_write(FAR struct file *filep, /* Now decode and process every byte in the input buffer */ memset(&state, 0, sizeof(struct slcdstate_s)); - while ((result = - slcd_decode(&instream.stream, &state, &ch, &count)) != SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { if (result == SLCDRET_CHAR) /* A normal character was returned */ { diff --git a/drivers/lcd/st7032.c b/drivers/lcd/st7032.c index 403e38d964..d57b94c73e 100644 --- a/drivers/lcd/st7032.c +++ b/drivers/lcd/st7032.c @@ -71,13 +71,6 @@ struct st7032_dev_s mutex_t lock; }; -struct lcd_instream_s -{ - struct lib_instream_s stream; - FAR const char *buffer; - ssize_t nbytes; -}; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -606,29 +599,6 @@ static void lcd_codec_action(FAR struct st7032_dev_s *priv, } } -/**************************************************************************** - * Name: lcd_getstream - * - * Description: - * Get one character from the LCD codec stream. - * - ****************************************************************************/ - -static int lcd_getstream(FAR struct lib_instream_s *instream) -{ - FAR struct lcd_instream_s *lcdstream = - (FAR struct lcd_instream_s *)instream; - - if (lcdstream->nbytes > 0) - { - lcdstream->nbytes--; - lcdstream->stream.nget++; - return (int)*lcdstream->buffer++; - } - - return EOF; -} - /**************************************************************************** * Name: lcd_init * @@ -720,7 +690,7 @@ static ssize_t st7032_write(FAR struct file *filep, FAR const char *buffer, { FAR struct inode *inode = filep->f_inode; FAR struct st7032_dev_s *priv = inode->i_private; - struct lcd_instream_s instream; + struct lib_meminstream_s instream; struct slcdstate_s state; enum slcdret_e result; uint8_t ch; @@ -730,16 +700,13 @@ static ssize_t st7032_write(FAR struct file *filep, FAR const char *buffer, /* Initialize the stream for use with the SLCD CODEC */ - instream.stream.getc = lcd_getstream; - instream.stream.nget = 0; - instream.buffer = buffer; - instream.nbytes = buflen; + lib_meminstream(&instream, buffer, buflen); /* Now decode and process every byte in the input buffer */ memset(&state, 0, sizeof(struct slcdstate_s)); - while ((result = slcd_decode(&instream.stream, &state, &ch, &count)) != - SLCDRET_EOF) + while ((result = slcd_decode(&instream.public, + &state, &ch, &count)) != SLCDRET_EOF) { /* Is there some pending scroll? */