aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FT245.c12
-rw-r--r--FT245.h6
-rw-r--r--doc/FT245.md7
3 files changed, 12 insertions, 13 deletions
diff --git a/FT245.c b/FT245.c
index d0d417d..0648c73 100644
--- a/FT245.c
+++ b/FT245.c
@@ -1012,15 +1012,15 @@ bool FT245_write_buffered(ft245_t *ft245, uint8_t *data, size_t size)
return true;
}
-bool FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size)
+size_t FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size)
{
- if(cb_occupation(ft245->buffer_rx) < size)
- return false;
-
- for(size_t i = 0; i < size; i++)
+ for(size_t i = 0; i < size; i++) {
+ if(cb_empty(ft245->buffer_rx))
+ return i;
cb_pop(ft245->buffer_rx, data[i]);
+ }
- return true;
+ return size;
}
bool FT245_write_word_buffered(ft245_t *ft245, uint32_t word)
diff --git a/FT245.h b/FT245.h
index 03280d1..fdaabf6 100644
--- a/FT245.h
+++ b/FT245.h
@@ -7,11 +7,11 @@
#include "circular_buffer.h"
#ifndef FT245_DRIVER_MODE_DYNAMIC
-#define FT245_DRIVER_MODE_DYNAMIC 1
+#define FT245_DRIVER_MODE_DYNAMIC 0
#endif
#ifndef FT245_DRIVER_MODE_STATIC
-#define FT245_DRIVER_MODE_STATIC 0
+#define FT245_DRIVER_MODE_STATIC 1
#endif
#ifndef FT245_BUFFER_SIZE_TX
@@ -444,7 +444,7 @@ extern uint32_t FT245_BE3_read(void);
void FT245_init(ft245_t *ft245);
void FT245_periodic(ft245_t *ft245);
bool FT245_write_buffered(ft245_t *ft245, uint8_t *data, size_t size);
-bool FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size);
+size_t FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size);
bool FT245_write_word_buffered(ft245_t *ft245, uint32_t word);
bool FT245_read_word_buffered(ft245_t *ft245, uint32_t *word);
size_t FT245_available_read(ft245_t *ft245);
diff --git a/doc/FT245.md b/doc/FT245.md
index 7f677ba..7ffea0e 100644
--- a/doc/FT245.md
+++ b/doc/FT245.md
@@ -1240,9 +1240,9 @@ Returns:
- `true`: Data successfully transferred to output buffer.
- `false`: Data could not be transferred to output buffer.
-### `bool FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size)`
+### `size_t FT245_read_buffered(ft245_t *ft245, uint8_t *data, size_t size)`
-Reads the given amount of data from the input buffer, specified with `size`, to the pointer `data`, if available.
+Reads up to the given amount of data from the input buffer, specified with `size`, to the pointer `data`.
Parameters:
@@ -1252,8 +1252,7 @@ Parameters:
Returns:
-- `true`: Data successfully transferred to `data` buffer.
-- `false`: Data could not be transferred to `data` buffer, i.e. no data available at input buffer.
+- Number of bytes actually read.
### `bool FT245_write_word_buffered(ft245_t *ft245, uint32_t word)`