summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/md_parser.cpp
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2021-05-07 12:37:27 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-05-08 02:49:03 +0300
commitdf36fb4abb37c216d1eaf60a1772047b5205d0b7 (patch)
treeb8d4e7088c48eb6a3cc0f2c8b4e2da6cc4bd40ff /src/ipa/raspberrypi/md_parser.cpp
parent414babb60b5453bf2a2d206088c0b4a1b48da15e (diff)
ipa: raspberrypi: Make sensor embedded data parser use Span class
Improve MdParser::Parse() by taking a Span, pointing to const data that it should not change, as its input buffer. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/raspberrypi/md_parser.cpp')
-rw-r--r--src/ipa/raspberrypi/md_parser.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/ipa/raspberrypi/md_parser.cpp b/src/ipa/raspberrypi/md_parser.cpp
index d82c102c..852a1d34 100644
--- a/src/ipa/raspberrypi/md_parser.cpp
+++ b/src/ipa/raspberrypi/md_parser.cpp
@@ -27,12 +27,13 @@ using namespace RPiController;
#define REG_VALUE 0x5a
#define REG_SKIP 0x55
-MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,
+MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span<const uint8_t> buffer,
uint32_t regs[], int offsets[],
unsigned int num_regs)
{
assert(num_regs > 0);
- if (data[0] != LINE_START)
+
+ if (buffer[0] != LINE_START)
return NO_LINE_START;
unsigned int current_offset = 1; // after the LINE_START
@@ -40,15 +41,15 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,
unsigned int reg_num = 0, first_reg = 0;
ParseStatus retcode = PARSE_OK;
while (1) {
- int tag = data[current_offset++];
+ int tag = buffer[current_offset++];
if ((bits_per_pixel_ == 10 &&
(current_offset + 1 - current_line_start) % 5 == 0) ||
(bits_per_pixel_ == 12 &&
(current_offset + 1 - current_line_start) % 3 == 0)) {
- if (data[current_offset++] != REG_SKIP)
+ if (buffer[current_offset++] != REG_SKIP)
return BAD_DUMMY;
}
- int data_byte = data[current_offset++];
+ int data_byte = buffer[current_offset++];
//printf("Offset %u, tag 0x%02x data_byte 0x%02x\n", current_offset-1, tag, data_byte);
if (tag == LINE_END_TAG) {
if (data_byte != LINE_END_TAG)
@@ -59,18 +60,18 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,
current_offset =
current_line_start + line_length_bytes_;
// Require whole line to be in the buffer (if buffer size set).
- if (buffer_size_bytes_ &&
+ if (buffer.size() &&
current_offset + line_length_bytes_ >
- buffer_size_bytes_)
+ buffer.size())
return MISSING_REGS;
- if (data[current_offset] != LINE_START)
+ if (buffer[current_offset] != LINE_START)
return NO_LINE_START;
} else {
// allow a zero line length to mean "hunt for the next line"
- while (data[current_offset] != LINE_START &&
- current_offset < buffer_size_bytes_)
+ while (buffer[current_offset] != LINE_START &&
+ current_offset < buffer.size())
current_offset++;
- if (current_offset == buffer_size_bytes_)
+ if (current_offset == buffer.size())
return NO_LINE_START;
}
// inc current_offset to after LINE_START