From 200246949abb240788d89645c572d14f0a0a8b96 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Thu, 29 May 2014 14:07:58 -0700 Subject: Keyborg: provide options on data encoding/printing style For easier developement/experiment, this adds two options: - CONFIG_ENCODE_SEGMENT/CONFIG_ENCODE_RAW SEGMENT style encoding uses less RAM, so it can store the entire frame. However, it sometimes losses data. RAW style encoding is always lossless, but it can only save a bit more than a half frame. - CONFIG_ENCODE_DUMP_PYTHON If this flag is defined, the output style is a 2-D Python list. This is used so that the data can be easily fed into another script. BUG=None TEST=Tries all four combinations. BRANCH=None Change-Id: Ic6a916f1cae20edccee5d05783ef98a1c48dff2e Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/202140 Reviewed-by: Vincent Palatin --- board/keyborg/board.h | 5 ++ board/keyborg/build.mk | 3 +- board/keyborg/encode.c | 114 -------------------------------- board/keyborg/encode_raw.c | 58 +++++++++++++++++ board/keyborg/encode_segment.c | 144 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+), 115 deletions(-) delete mode 100644 board/keyborg/encode.c create mode 100644 board/keyborg/encode_raw.c create mode 100644 board/keyborg/encode_segment.c diff --git a/board/keyborg/board.h b/board/keyborg/board.h index 0acf810514..d0dadffc2d 100644 --- a/board/keyborg/board.h +++ b/board/keyborg/board.h @@ -27,6 +27,11 @@ #undef CONFIG_TASK_PROFILING #undef CONFIG_WATCHDOG_HELP +/* How the touch data is stored and printed */ +#define CONFIG_ENCODE_SEGMENT +#undef CONFIG_ENCODE_RAW +#undef CONFIG_ENCODE_DUMP_PYTHON + #ifndef __ASSEMBLER__ enum gpio_signal; diff --git a/board/keyborg/build.mk b/board/keyborg/build.mk index cdd1a7ff84..be53116402 100644 --- a/board/keyborg/build.mk +++ b/board/keyborg/build.mk @@ -10,5 +10,6 @@ CHIP_FAMILY:=stm32f CHIP_VARIANT:=stm32ts60 board-y=board.o hardware.o runtime.o master_slave.o spi_comm.o touch_scan.o -board-y+=encode.o +board-$(CONFIG_ENCODE_SEGMENT)+=encode_segment.o +board-$(CONFIG_ENCODE_RAW)+=encode_raw.o board-$(CONFIG_DEBUG_PRINTF)+=debug.o diff --git a/board/keyborg/encode.c b/board/keyborg/encode.c deleted file mode 100644 index 266f67d3b3..0000000000 --- a/board/keyborg/encode.c +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Touch data encoding/decoding */ - -/* - * This removes the "whitespace" (i.e. cells below the threshold) and - * group the remaining active cells into "segments". By only storing - * the segments, we can fit a single frame in RAM in most cases. - */ - -#include "common.h" -#include "debug.h" -#include "touch_scan.h" -#include "util.h" - -#define BUF_SIZE 6000 -static uint8_t encoded[BUF_SIZE]; -static int encoded_size; - -void encode_reset(void) -{ - /* Just clear the encoded data */ - encoded_size = 0; -} - -void encode_add_column(const uint8_t *dptr) -{ - uint8_t *seg_count_ptr; - int p, p_start; - uint8_t *eptr = encoded + encoded_size, *e_seg_size; - - seg_count_ptr = eptr; - eptr++; - - *seg_count_ptr = 0; - p = 0; - while (p < ROW_COUNT * 2) { - if (dptr[p] < THRESHOLD) { - ++p; - continue; - } - - /* Give up on overflow */ - if (eptr + 2 >= encoded + BUF_SIZE) - return; - - /* Save current position */ - *(eptr++) = p; - - /* Leave a byte for storing segment size */ - e_seg_size = eptr; - eptr++; - - /* Record segment starting point */ - p_start = p; - - /* Save the segment */ - while (p < ROW_COUNT * 2 && dptr[p] >= THRESHOLD) { - if (eptr >= encoded + BUF_SIZE) - return; - *(eptr++) = dptr[p++]; - } - - /* Fill in the segment size now that we know it */ - *e_seg_size = p - p_start; - - (*seg_count_ptr)++; - } - - /* Update encoded data size now that we're sure it fits */ - encoded_size = eptr - encoded; -} - -void encode_dump_matrix(void) -{ - uint8_t *dptr; - int row, col; - int seg_count; - int seg; - int seg_end; - - debug_printf("Encoded size = %d\n", encoded_size); - - dptr = encoded; - for (col = 0; col < COL_COUNT * 2; ++col) { - if (dptr >= encoded + encoded_size) { - for (row = 0; row < ROW_COUNT * 2; ++row) - debug_printf(" - "); - debug_printf("\n"); - continue; - } - seg_count = *(dptr++); - row = 0; - for (seg = 0; seg < seg_count; ++seg) { - while (row < *dptr) { - debug_printf(" - "); - row++; - } - dptr++; - seg_end = *dptr + row; - dptr++; - for (; row < seg_end; ++row, ++dptr) - debug_printf("%3d ", *dptr); - } - while (row < ROW_COUNT * 2) { - debug_printf(" - "); - row++; - } - debug_printf("\n"); - } -} diff --git a/board/keyborg/encode_raw.c b/board/keyborg/encode_raw.c new file mode 100644 index 0000000000..cf358edc96 --- /dev/null +++ b/board/keyborg/encode_raw.c @@ -0,0 +1,58 @@ +/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Raw touch data recording */ + +#include "common.h" +#include "debug.h" +#include "touch_scan.h" +#include "util.h" + +#define ENC_COL_COUNT 70 +static uint8_t encoded[ENC_COL_COUNT][ROW_COUNT * 2]; +static int encoded_col; + +void encode_reset(void) +{ + encoded_col = 0; +} + +void encode_add_column(const uint8_t *dptr) +{ + if (encoded_col >= ENC_COL_COUNT) + return; + memcpy(encoded[encoded_col], dptr, ROW_COUNT * 2); + encoded_col++; +} + +void encode_dump_matrix(void) +{ + int row, col; + +#ifdef CONFIG_ENCODE_DUMP_PYTHON + debug_printf("heat_map = ["); + for (row = 0; row < ROW_COUNT * 2; ++row) { + debug_printf("["); + for (col = 0; col < encoded_col; ++col) { + if (encoded[col][row] < THRESHOLD) + debug_printf("0,"); + else + debug_printf("%d,", encoded[col][row]); + } + debug_printf("],\n"); + } + debug_printf("]\n"); +#else + for (row = 0; row < ROW_COUNT * 2; ++row) { + for (col = 0; col < encoded_col; ++col) { + if (encoded[col][row] < THRESHOLD) + debug_printf(" - "); + else + debug_printf("%3d ", encoded[col][row]); + } + debug_printf("\n"); + } +#endif +} diff --git a/board/keyborg/encode_segment.c b/board/keyborg/encode_segment.c new file mode 100644 index 0000000000..49eaec64c9 --- /dev/null +++ b/board/keyborg/encode_segment.c @@ -0,0 +1,144 @@ +/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Touch data encoding/decoding */ + +/* + * This removes the "whitespace" (i.e. cells below the threshold) and + * group the remaining active cells into "segments". By only storing + * the segments, we can fit a single frame in RAM in most cases. + */ + +#include "common.h" +#include "debug.h" +#include "touch_scan.h" +#include "util.h" + +#define BUF_SIZE 6000 +static uint8_t encoded[BUF_SIZE]; +static int encoded_size; + +void encode_reset(void) +{ + /* Just clear the encoded data */ + encoded_size = 0; +} + +void encode_add_column(const uint8_t *dptr) +{ + uint8_t *seg_count_ptr; + int p, p_start; + uint8_t *eptr = encoded + encoded_size, *e_seg_size; + + seg_count_ptr = eptr; + eptr++; + + *seg_count_ptr = 0; + p = 0; + while (p < ROW_COUNT * 2) { + if (dptr[p] < THRESHOLD) { + ++p; + continue; + } + + /* Give up on overflow */ + if (eptr + 2 >= encoded + BUF_SIZE) + return; + + /* Save current position */ + *(eptr++) = p; + + /* Leave a byte for storing segment size */ + e_seg_size = eptr; + eptr++; + + /* Record segment starting point */ + p_start = p; + + /* Save the segment */ + while (p < ROW_COUNT * 2 && dptr[p] >= THRESHOLD) { + if (eptr >= encoded + BUF_SIZE) + return; + *(eptr++) = dptr[p++]; + } + + /* Fill in the segment size now that we know it */ + *e_seg_size = p - p_start; + + (*seg_count_ptr)++; + } + + /* Update encoded data size now that we're sure it fits */ + encoded_size = eptr - encoded; +} + +void encode_dump_matrix(void) +{ + uint8_t *dptr; + int row, col; + int seg_count; + int seg; + int seg_end; + + debug_printf("Encoded size = %d\n", encoded_size); + +#ifdef CONFIG_ENCODE_DUMP_PYTHON + debug_printf("heat_map = ["); + dptr = encoded; + for (col = 0; col < COL_COUNT * 2; ++col) { + debug_printf("["); + if (dptr >= encoded + encoded_size) { + debug_printf("0] * %d,\n", ROW_COUNT * 2); + continue; + } + seg_count = *(dptr++); + row = 0; + for (seg = 0; seg < seg_count; ++seg) { + if (row < *dptr) { + debug_printf("] + [0] * %d + [", *dptr - row); + row = *dptr; + } + dptr++; + seg_end = *dptr + row; + dptr++; + for (; row < seg_end; ++row, ++dptr) + debug_printf("%d,", *dptr); + } + if (row < ROW_COUNT * 2) + debug_printf("] + [0] * %d,\n", ROW_COUNT * 2 - row); + else + debug_printf("],\n"); + } + debug_printf("]\n"); +#else + dptr = encoded; + for (col = 0; col < COL_COUNT * 2; ++col) { + if (dptr >= encoded + encoded_size) { + for (row = 0; row < ROW_COUNT * 2; ++row) + debug_printf(" - "); + debug_printf("\n"); + continue; + } + seg_count = *(dptr++); + row = 0; + for (seg = 0; seg < seg_count; ++seg) { + while (row < *dptr) { + debug_printf(" - "); + row++; + } + dptr++; + seg_end = *dptr + row; + dptr++; + for (; row < seg_end; ++row, ++dptr) + debug_printf("%3d ", *dptr); + } + while (row < ROW_COUNT * 2) { + debug_printf(" - "); + row++; + } + debug_printf("\n"); + } +#endif +} -- cgit v1.2.1