blob: 02200e8ae87903c41f4bb84b5872a3ae3bc86d3b [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef USECASE_COMMON_UTILS_HPP
18#define USECASE_COMMON_UTILS_HPP
19
20#include "hal.h"
21#include "Model.hpp"
22#include "AppContext.hpp"
23#include "Profiler.hpp"
24
25/* Helper macro to convert RGB888 to RGB565 format. */
26#define RGB888_TO_RGB565(R8,G8,B8) ((((R8>>3) & 0x1F) << 11) | \
27 (((G8>>2) & 0x3F) << 5) | \
28 ((B8>>3) & 0x1F))
29
30constexpr uint16_t COLOR_BLACK = 0;
31constexpr uint16_t COLOR_GREEN = RGB888_TO_RGB565( 0, 255, 0); // 2016;
32constexpr uint16_t COLOR_YELLOW = RGB888_TO_RGB565(255, 255, 0); // 65504;
33
34namespace arm {
35namespace app {
36
37 /**
38 * @brief Run inference using given model
39 * object. If profiling is enabled, it will log the
40 * statistics too.
41 * @param[in] platform Reference to the hal platform object.
42 * @param[in] model Reference to the initialised model.
43 * @return true if inference succeeds, false otherwise.
44 **/
45 bool RunInference(hal_platform& platform, arm::app::Model& model);
46
47 /**
48 * @brief Read input and return as an integer.
49 * @param[in] platform Reference to the hal platform object.
50 * @param[in] model Reference to the initialised model.
51 * @return Integer value corresponding to the user input.
52 **/
53 int ReadUserInputAsInt(hal_platform& platform);
54
55#if VERIFY_TEST_OUTPUT
56 /**
57 * @brief Helper function to dump a tensor to stdout
58 * @param[in] tensor tensor to be dumped
59 * @param[in] lineBreakForNumElements number of elements
60 * after which line break will be added.
61 **/
62 void DumpTensor(TfLiteTensor* tensor,
63 const size_t lineBreakForNumElements = 16);
64#endif /* VERIFY_TEST_OUTPUT */
65
66 /**
67 * @brief List the files baked in the application.
68 * @param[in] ctx Reference to the application context.
69 * @return true or false based on event being handled.
70 **/
71 bool ListFilesHandler(ApplicationContext& ctx);
72
73} /* namespace app */
74} /* namespace arm */
75
76#endif /* USECASE_COMMON_UTILS_HPP */