eveapps-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/build_matrix.json +17 -0
- package/data/commands.json +8752 -0
- package/data/feature_graph.json +2446 -0
- package/data/registers.json +3312 -0
- package/data/samples.json +685 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +33 -0
- package/dist/context.js.map +1 -0
- package/dist/data/build_matrix.json +17 -0
- package/dist/data/commands.json +8750 -0
- package/dist/data/data/build_matrix.json +17 -0
- package/dist/data/data/commands.json +8752 -0
- package/dist/data/data/feature_graph.json +2446 -0
- package/dist/data/data/registers.json +3312 -0
- package/dist/data/data/samples.json +685 -0
- package/dist/data/data/source_index.json +79 -0
- package/dist/data/feature_graph.json +2444 -0
- package/dist/data/registers.json +3312 -0
- package/dist/data/samples.json +685 -0
- package/dist/data/source_index.json +79 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/loadIndex.d.ts +14 -0
- package/dist/lib/loadIndex.js +27 -0
- package/dist/lib/loadIndex.js.map +1 -0
- package/dist/lib/normalize.d.ts +2 -0
- package/dist/lib/normalize.js +10 -0
- package/dist/lib/normalize.js.map +1 -0
- package/dist/lib/rank.d.ts +5 -0
- package/dist/lib/rank.js +38 -0
- package/dist/lib/rank.js.map +1 -0
- package/dist/lib/workspace.d.ts +4 -0
- package/dist/lib/workspace.js +5 -0
- package/dist/lib/workspace.js.map +1 -0
- package/dist/router/analyzeQuery.d.ts +9 -0
- package/dist/router/analyzeQuery.js +12 -0
- package/dist/router/analyzeQuery.js.map +1 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +6 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/mergeResults.d.ts +2 -0
- package/dist/router/mergeResults.js +12 -0
- package/dist/router/mergeResults.js.map +1 -0
- package/dist/router/retrieveAnswer.d.ts +3 -0
- package/dist/router/retrieveAnswer.js +40 -0
- package/dist/router/retrieveAnswer.js.map +1 -0
- package/dist/router/routeQuery.d.ts +3 -0
- package/dist/router/routeQuery.js +33 -0
- package/dist/router/routeQuery.js.map +1 -0
- package/dist/router/types.d.ts +12 -0
- package/dist/router/types.js +2 -0
- package/dist/router/types.js.map +1 -0
- package/dist/search/searchCore.d.ts +3 -0
- package/dist/search/searchCore.js +64 -0
- package/dist/search/searchCore.js.map +1 -0
- package/dist/search/searchEveApps.d.ts +2 -0
- package/dist/search/searchEveApps.js +107 -0
- package/dist/search/searchEveApps.js.map +1 -0
- package/dist/search/searchSourceFiles.d.ts +6 -0
- package/dist/search/searchSourceFiles.js +49 -0
- package/dist/search/searchSourceFiles.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +229 -0
- package/dist/server.js.map +1 -0
- package/dist/src/context.d.ts +12 -0
- package/dist/src/context.js +71 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/loadIndex.d.ts +14 -0
- package/dist/src/lib/loadIndex.js +27 -0
- package/dist/src/lib/loadIndex.js.map +1 -0
- package/dist/src/lib/normalize.d.ts +2 -0
- package/dist/src/lib/normalize.js +10 -0
- package/dist/src/lib/normalize.js.map +1 -0
- package/dist/src/lib/rank.d.ts +5 -0
- package/dist/src/lib/rank.js +38 -0
- package/dist/src/lib/rank.js.map +1 -0
- package/dist/src/lib/workspace.d.ts +4 -0
- package/dist/src/lib/workspace.js +5 -0
- package/dist/src/lib/workspace.js.map +1 -0
- package/dist/src/router/analyzeQuery.d.ts +9 -0
- package/dist/src/router/analyzeQuery.js +12 -0
- package/dist/src/router/analyzeQuery.js.map +1 -0
- package/dist/src/router/index.d.ts +5 -0
- package/dist/src/router/index.js +6 -0
- package/dist/src/router/index.js.map +1 -0
- package/dist/src/router/mergeResults.d.ts +2 -0
- package/dist/src/router/mergeResults.js +12 -0
- package/dist/src/router/mergeResults.js.map +1 -0
- package/dist/src/router/retrieveAnswer.d.ts +3 -0
- package/dist/src/router/retrieveAnswer.js +64 -0
- package/dist/src/router/retrieveAnswer.js.map +1 -0
- package/dist/src/router/routeQuery.d.ts +3 -0
- package/dist/src/router/routeQuery.js +33 -0
- package/dist/src/router/routeQuery.js.map +1 -0
- package/dist/src/router/types.d.ts +12 -0
- package/dist/src/router/types.js +2 -0
- package/dist/src/router/types.js.map +1 -0
- package/dist/src/search/searchCore.d.ts +3 -0
- package/dist/src/search/searchCore.js +64 -0
- package/dist/src/search/searchCore.js.map +1 -0
- package/dist/src/search/searchEveApps.d.ts +2 -0
- package/dist/src/search/searchEveApps.js +107 -0
- package/dist/src/search/searchEveApps.js.map +1 -0
- package/dist/src/search/searchSourceFiles.d.ts +6 -0
- package/dist/src/search/searchSourceFiles.js +49 -0
- package/dist/src/search/searchSourceFiles.js.map +1 -0
- package/dist/src/server.d.ts +1 -0
- package/dist/src/server.js +214 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/tools/explainEveSymbol.d.ts +56 -0
- package/dist/src/tools/explainEveSymbol.js +54 -0
- package/dist/src/tools/explainEveSymbol.js.map +1 -0
- package/dist/src/tools/findRelevantSample.d.ts +34 -0
- package/dist/src/tools/findRelevantSample.js +33 -0
- package/dist/src/tools/findRelevantSample.js.map +1 -0
- package/dist/src/tools/generateBuildCommand.d.ts +34 -0
- package/dist/src/tools/generateBuildCommand.js +54 -0
- package/dist/src/tools/generateBuildCommand.js.map +1 -0
- package/dist/src/tools/generateScreenScaffold.d.ts +32 -0
- package/dist/src/tools/generateScreenScaffold.js +73 -0
- package/dist/src/tools/generateScreenScaffold.js.map +1 -0
- package/dist/src/tools/traceFeatureToCommands.d.ts +36 -0
- package/dist/src/tools/traceFeatureToCommands.js +84 -0
- package/dist/src/tools/traceFeatureToCommands.js.map +1 -0
- package/dist/src/tools/validateBt820Code.d.ts +28 -0
- package/dist/src/tools/validateBt820Code.js +45 -0
- package/dist/src/tools/validateBt820Code.js.map +1 -0
- package/dist/src/types.d.ts +44 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tools/explainEveSymbol.d.ts +56 -0
- package/dist/tools/explainEveSymbol.js +54 -0
- package/dist/tools/explainEveSymbol.js.map +1 -0
- package/dist/tools/findRelevantSample.d.ts +34 -0
- package/dist/tools/findRelevantSample.js +33 -0
- package/dist/tools/findRelevantSample.js.map +1 -0
- package/dist/tools/generateBuildCommand.d.ts +34 -0
- package/dist/tools/generateBuildCommand.js +54 -0
- package/dist/tools/generateBuildCommand.js.map +1 -0
- package/dist/tools/generateScreenScaffold.d.ts +32 -0
- package/dist/tools/generateScreenScaffold.js +73 -0
- package/dist/tools/generateScreenScaffold.js.map +1 -0
- package/dist/tools/readSourceFile.d.ts +15 -0
- package/dist/tools/readSourceFile.js +26 -0
- package/dist/tools/readSourceFile.js.map +1 -0
- package/dist/tools/traceFeatureToCommands.d.ts +36 -0
- package/dist/tools/traceFeatureToCommands.js +84 -0
- package/dist/tools/traceFeatureToCommands.js.map +1 -0
- package/dist/tools/validateBt820Code.d.ts +28 -0
- package/dist/tools/validateBt820Code.js +45 -0
- package/dist/tools/validateBt820Code.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"sample_id": "sampleapp_animation",
|
|
4
|
+
"relative_path": "SampleApp/Animation/Src/Animation.c",
|
|
5
|
+
"ext": ".c",
|
|
6
|
+
"content": "/**\r\n * @file Animation.c\r\n * @brief Sample usage of animation \r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n#include \"Animation.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define PLAY_CONTROL_ADDR (1024 * 512)\r\n#define ANIM_LOAD_ADDR RAM_G\r\n#define MEDIAFIFO_ADDR DDR_BITMAPS_STARTADDR\r\n#define MEDIAFIFO_LEN (16 * 1024)\r\n#define BUTTON_X 900\r\n#define BUTTON_Y1 250\r\n#define BUTTON_Y2 450\r\n#define BUTTON_W 200\r\n#define BUTTON_H 100\r\n#define BUTTON_FONT 30\r\n#define TEXT_X 200\r\n#define TEXT_Y 100\r\n#define TEXT_FONT 31\r\n#define TEXT_OPT 0\r\n#define ANIM_DELAY_MS 10\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Animation();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of animation\",\r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Animation();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n// Helper to start and play an animation using CMD_RUNANIM\r\nstatic void helperRunAnimation(EVE_HalContext *phost, uint32_t play_control, uint32_t ch, uint32_t addr, uint32_t anim_mode)\r\n{\r\n EVE_CoCmd_memZero(phost, play_control, 1);\r\n EVE_CoCmd_animStart(phost, ch, addr, anim_mode);\r\n EVE_CoCmd_animXY(phost, ch, phost->Width / 2, phost->Height / 2);\r\n EVE_CoCmd_runAnim(phost, (uint32_t)-1, play_control);\r\n EVE_Cmd_waitFlush(phost);\r\n SAMAPP_DELAY;\r\n EVE_CoCmd_memSet(phost, play_control, 1, 1);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RUNANIM from Flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_flash()\r\n{\r\n uint32_t play_control = PLAY_CONTROL_ADDR;\r\n uint32_t ch = 0;\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Flash is not able to switch full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Run animation from Flash\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, ANIM_ADDR_FLASH_ABSTRACT);\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_FLASH);\r\n helperRunAnimation(s_pHalContext, play_control, ch, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RUNANIM from Flash (non-relocatable)\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_flash_no_reloc()\r\n{\r\n uint32_t play_control = PLAY_CONTROL_ADDR;\r\n uint32_t ch = 0;\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Flash is not able to switch full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Run animation from Flash which is not relocatable\");\r\n\r\n EVE_CoCmd_flashRead_flush(s_pHalContext, ANIM_LOAD_ADDR, ANIM_ADDR_FLASH_BICYCLE, ANIM_LEN_FLASH_BICYCLE);\r\n helperRunAnimation(s_pHalContext, play_control, ch, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RUNANIM from SD card\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_SD()\r\n{\r\n uint32_t play_control = PLAY_CONTROL_ADDR;\r\n uint32_t ch = 0;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Run animation from SD card\");\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, ANIM_ABSTRACT, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_FS);\r\n helperRunAnimation(s_pHalContext, play_control, ch, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RUNANIM from command buffer\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_CMDB()\r\n{\r\n uint32_t play_control = PLAY_CONTROL_ADDR;\r\n uint32_t ch = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Run animation from command buffer\");\r\n\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, 0);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR ANIM_ABSTRACT, NULL);\r\n helperRunAnimation(s_pHalContext, play_control, ch, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RUNANIM from Mediafifo\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_mediafifo()\r\n{\r\n uint32_t play_control = PLAY_CONTROL_ADDR;\r\n uint32_t ch = 0;\r\n uint32_t mediafifo = MEDIAFIFO_ADDR;\r\n uint32_t mediafifolen = MEDIAFIFO_LEN;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Run animation from Mediafifo\");\r\n\r\n EVE_MediaFifo_set(s_pHalContext, mediafifo, mediafifolen);\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_MEDIAFIFO);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR ANIM_ABSTRACT, NULL);\r\n helperRunAnimation(s_pHalContext, play_control, ch, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate animation from Flash by AnimDraw\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_control()\r\n{\r\n const char *txtAnim_ONCE = \"Playing Animation by ANIM_ONCE\";\r\n const char *txtAnim_LOOP = \"Playing Animation by ANIM_LOOP\";\r\n const char *txtAnim_HOLD = \"Playing Animation by ANIM_HOLD\";\r\n const char* txtPress2Stop = \"Press \\\"Stop Anim\\\" again to exit\";\r\n\r\n uint32_t prAnimLoop = ANIM_ONCE;\r\n const uint8_t* txtAnimLabel = txtAnim_ONCE;\r\n\r\n int timeout = 10000;\r\n int countStop = 0; // countStop = 2 to exit while loop\r\n uint16_t channel = 30;\r\n uint32_t tag = 0;\r\n uint32_t oldTag = 0;\r\n uint8_t isPlaying = 0;\r\n\r\n /* Switch Flash to FULL Mode */\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Flash is not able to switch full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: ANIM_ONCE, ANIM_LOOP, ANIM_HOLD\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, ANIM_ADDR_FLASH_ABSTRACT);\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_FLASH);\r\n\r\n while (timeout > 0 && countStop < 2) {\r\n timeout--;\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag);\r\n\r\n if (tag != oldTag) {\r\n oldTag = tag;\r\n }\r\n else {\r\n tag = 0;\r\n }\r\n\r\n // Show text information\r\n if (isPlaying) {\r\n EVE_CoCmd_text(s_pHalContext, TEXT_X, TEXT_Y, TEXT_FONT, TEXT_OPT, txtAnimLabel);\r\n EVE_CoCmd_animDraw(s_pHalContext, channel);\r\n\r\n EVE_CoDl_tag(s_pHalContext, 1);\r\n EVE_CoCmd_button(s_pHalContext, BUTTON_X, BUTTON_Y1, BUTTON_W, BUTTON_H, BUTTON_FONT, 0, \"Change Anim\");\r\n }\r\n else {\r\n if (countStop == 0) {\r\n EVE_CoCmd_text(s_pHalContext, TEXT_X, TEXT_Y, TEXT_FONT, TEXT_OPT, \"Press \\\"Start Anim\\\" to start animation\");\r\n }\r\n else if (countStop > 0) {\r\n EVE_CoCmd_text(s_pHalContext, TEXT_X, TEXT_Y, TEXT_FONT, TEXT_OPT, txtPress2Stop);\r\n }\r\n\r\n EVE_CoDl_tag(s_pHalContext, 1);\r\n EVE_CoCmd_button(s_pHalContext, BUTTON_X, BUTTON_Y1, BUTTON_W, BUTTON_H, BUTTON_FONT, 0, \"Start Anim\");\r\n }\r\n\r\n EVE_CoDl_tag(s_pHalContext, 2);\r\n EVE_CoCmd_button(s_pHalContext, BUTTON_X, BUTTON_Y2, BUTTON_W, BUTTON_H, BUTTON_FONT, 0, \"Stop Anim\");\r\n\r\n if (tag == 1) {\r\n if (isPlaying == 1) {\r\n EVE_CoCmd_animStop(s_pHalContext, channel);\r\n }\r\n\r\n isPlaying = 1;\r\n countStop = 0;\r\n\r\n EVE_CoCmd_animStart(s_pHalContext, channel, ANIM_LOAD_ADDR, prAnimLoop);\r\n EVE_CoCmd_animXY(s_pHalContext, channel, 500, 400);\r\n\r\n // change AnimLoop attribute for the next user button press\r\n // change text lable for the current press\r\n // ONCE -> HOLD -> LOOP -> ONCE -> ...\r\n switch (prAnimLoop) {\r\n case ANIM_ONCE:\r\n prAnimLoop = ANIM_HOLD;\r\n txtAnimLabel = txtAnim_ONCE;\r\n break;\r\n case ANIM_HOLD:\r\n prAnimLoop = ANIM_LOOP;\r\n txtAnimLabel = txtAnim_HOLD;\r\n break;\r\n case ANIM_LOOP:\r\n prAnimLoop = ANIM_ONCE;\r\n txtAnimLabel = txtAnim_LOOP;\r\n break;\r\n default: break;\r\n }\r\n }\r\n if (tag == 2) {\r\n isPlaying = 0;\r\n EVE_CoCmd_animStop(s_pHalContext, channel);\r\n countStop++;\r\n }\r\n\r\n Display_End(s_pHalContext);\r\n }\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate 32-bit register REG_ANIM_ACTIVE\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_animAtive() \r\n{\r\n char str[1000];\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Flash is not able to switch full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: REG_ANIM_ACTIVE usage\");\r\n\r\n uint16_t channel = 1;\r\n const int16_t xAnim = (uint16_t)(s_pHalContext->Width / 2);\r\n const int16_t yAnim = (uint16_t)(s_pHalContext->Height/ 2);\r\n uint32_t reg_anim_active = 0;\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, ANIM_ADDR_FLASH_ABSTRACT);\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_FLASH);\r\n\r\n EVE_CoCmd_animStart(s_pHalContext, channel, ANIM_LOAD_ADDR, ANIM_ONCE);\r\n EVE_CoCmd_animXY(s_pHalContext, channel, xAnim, yAnim);\r\n for (int i = 0; i < 100; i++) {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_animDraw(s_pHalContext, channel);\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_ANIM_ACTIVE, ®_anim_active);\r\n snprintf(str, 1000, \"REG_ANIM_ACTIVE: %u\\n\", reg_anim_active);\r\n EVE_CoCmd_text(s_pHalContext, xAnim, 50, 30, OPT_CENTER, str);\r\n Display_End(s_pHalContext);\r\n\r\n if (0 == reg_anim_active) {\r\n break;\r\n }\r\n }\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate animation from Flash by AnimFrame\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation_animFrame() \r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Flash is not able to switch full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: ANIMATION from Flash by AnimFrame\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, ANIM_ADDR_FLASH_ABSTRACT);\r\n EVE_CoCmd_loadAsset(s_pHalContext, ANIM_LOAD_ADDR, OPT_FLASH);\r\n\r\n for (uint16_t frame = 0; frame < ANIMATION_FRAMES; frame++) {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_animFrame(s_pHalContext, s_pHalContext->Width / 2, s_pHalContext->Height / 2, ANIM_LOAD_ADDR, frame);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(ANIM_DELAY_MS);\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all animation demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Animation() \r\n{\r\n SAMAPP_Animation_flash();\r\n SAMAPP_Animation_flash_no_reloc();\r\n SAMAPP_Animation_SD();\r\n SAMAPP_Animation_CMDB();\r\n SAMAPP_Animation_mediafifo();\r\n SAMAPP_Animation_control();\r\n SAMAPP_Animation_animAtive();\r\n SAMAPP_Animation_animFrame();\r\n}\r\n\r\n\r\n"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"sample_id": "sampleapp_audio",
|
|
10
|
+
"relative_path": "SampleApp/Audio/Src/Audio.c",
|
|
11
|
+
"ext": ".c",
|
|
12
|
+
"content": "/**\r\n * @file Audio.c\r\n * @brief Sample usage of Audio\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Audio.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define pgm_read_byte(x) (*(x))\r\n#define STR_NOW_HEAR_MUSIC \"Now you will hear the music\"\r\n#define AUDIO_MAX_VOLUME 0xFF\r\n#define AUDIO_SLIDER_WIDTH 15\r\n#define AUDIO_SLIDER_MARGIN 40\r\n#define AUDIO_SLIDER_TAG 100\r\n#define AUDIO_SLIDER_MAX 88\r\n#define AUDIO_BUTTON_ROWS 7 //number of rows to be created - note that mute and unmute are not played in this application\r\n#define AUDIO_BUTTON_COLS 8 //number of colomns to be created\r\n#define AUDIO_BUTTON_MARGIN 2\r\n#define AUDIO_STR_LENGTH 8\r\n#define AUDIO_STR_FONT 29\r\n#define AUDIO_BUILTIN_LOOP 1000\r\n#define AUDIO_LOAD_ADDR RAM_G\r\n#define AUDIO_WAV_VOL 155\r\n#define AUDIO_MEDIAFIFO_ADDR RAM_G\r\n#define AUDIO_MEDIAFIFO_LEN (16 * 1024)\r\n#define AUDIO_BTN_W 300\r\n#define AUDIO_BTN_H 120\r\n#define AUDIO_BTN_Y_OFFSET 50\r\n#define AUDIO_BTN_FONT 31\r\n#define AUDIO_BTN_PAUSE_TAG 1\r\n#define AUDIO_DELAY_MS 10\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Audio();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n#if defined(VM820B15A) || defined(VM820B10A)\r\n EVE_CMD_I2S_CTL(s_pHalContext, 0xa, 0);\r\n EVE_CoCmd_i2sStartup(s_pHalContext, 48000);\r\n#endif\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] = { \r\n \"EVE Sample Application\",\r\n \"This sample demonstrates the use of Audio\",\r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Audio();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n// Helper to set playback volume\r\nstatic void helperAudioSetVolume(EVE_HalContext *phost, uint8_t left, uint8_t right)\r\n{\r\n EVE_CoCmd_regWrite(phost, REG_VOL_L_PB, left);\r\n EVE_CoCmd_regWrite(phost, REG_VOL_R_PB, right);\r\n}\r\n\r\n// Helper to mute playback\r\nstatic void helperAudioMute(EVE_HalContext *phost)\r\n{\r\n helperAudioSetVolume(phost, 0, 0);\r\n EVE_CoCmd_regWrite(phost, REG_PLAYBACK_LOOP, 0);\r\n EVE_CoCmd_regWrite(phost, REG_PLAYBACK_LENGTH, 0);\r\n EVE_CoCmd_regWrite(phost, REG_PLAYBACK_PLAY, 1);\r\n}\r\n\r\n// Helper to start playback\r\nstatic void helperAudioStartPlayback(EVE_HalContext *phost, uint8_t left, uint8_t right)\r\n{\r\n helperAudioSetVolume(phost, left, right);\r\n EVE_CoCmd_regWrite(phost, REG_PLAYBACK_PLAY, 1);\r\n}\r\n\r\nstatic char SAMAPP_Snd_Array[5 * 58] =\r\n\"Slce\\0Sqrq\\0Sinw\\0Saww\\0Triw\\0Beep\\0Alrm\\0Warb\\0Crsl\\0Pp01\\0Pp02\\0Pp03\\0Pp04\\0Pp05\\0Pp06\\0Pp07\\0Pp08\\0Pp09\\0Pp10\\0Pp11\\0Pp12\\0Pp13\\0Pp14\\0Pp15\\0Pp16\\0DMF#\\0DMF*\\0DMF0\\0DMF1\\0DMF2\\0DMF3\\0DMF4\\0DMF5\\0DMF6\\0DMF7\\0DMF8\\0DMF9\\0Harp\\0Xyph\\0Tuba\\0Glok\\0Orgn\\0Trmp\\0Pian\\0Chim\\0MBox\\0Bell\\0Clck\\0Swth\\0Cowb\\0Noth\\0Hiht\\0Kick\\0Pop\\0Clak\\0Chak\\0Mute\\0uMut\\0\";\r\n\r\nstatic char SAMAPP_Snd_TagArray[58] = { 0x63, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,\r\n0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\r\n0x23, 0x2a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43,\r\n0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x60,\r\n0x61 };\r\n\r\nstatic void helperHighLightBtn(int32_t tagvalsnd, const char *pTagArray, int32_t wbutton, int32_t hbutton)\r\n{\r\n for (int i = 0; i < AUDIO_BUTTON_ROWS; i++)\r\n {\r\n for (int j = 0; j < AUDIO_BUTTON_COLS; j++)\r\n {\r\n EVE_CoDl_tag(s_pHalContext, pgm_read_byte(pTagArray));\r\n if (tagvalsnd == pgm_read_byte(pTagArray))\r\n {\r\n /* red color for highlight effect */\r\n EVE_CoDl_colorRgb(s_pHalContext, 0x80, 0x00, 0x00);\r\n EVE_CoDl_colorA(s_pHalContext, 0x55);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (j * wbutton + AUDIO_BUTTON_MARGIN) * 16, (i * hbutton + AUDIO_BUTTON_MARGIN) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((j + 1) * wbutton - AUDIO_BUTTON_MARGIN) * 16, ((i + 1) * hbutton - AUDIO_BUTTON_MARGIN) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n }\r\n pTagArray++;\r\n }\r\n }\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n}\r\n\r\nstatic void helperDrawBtn(const char *pTagArray, int32_t wbutton, int32_t hbutton, char *StringArray, char *pString)\r\n{\r\n for (int i = 0; i < AUDIO_BUTTON_ROWS; i++)\r\n {\r\n for (int j = 0; j < AUDIO_BUTTON_COLS; j++)\r\n {\r\n EVE_CoDl_tag(s_pHalContext, pgm_read_byte(pTagArray));\r\n EVE_CoDl_colorRgb(s_pHalContext, 0x80, 0x80, 0x00);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (j * wbutton + AUDIO_BUTTON_MARGIN) * 16, (i * hbutton + AUDIO_BUTTON_MARGIN) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((j + 1) * wbutton - AUDIO_BUTTON_MARGIN) * 16, ((i + 1) * hbutton - AUDIO_BUTTON_MARGIN) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n strcpy_s(StringArray, AUDIO_STR_LENGTH, pString);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(j * wbutton + (wbutton / 2)),\r\n (int16_t)(i * hbutton + (hbutton / 2)), AUDIO_STR_FONT, OPT_CENTER, StringArray);\r\n\r\n pString += (strlen(StringArray) + 1);\r\n pTagArray++;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * @brief Sample app API to demonstrate built-in audio\r\n *\r\n * Demonstrates playing built-in sounds and pitches using touch input.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_builtin()\r\n{\r\n int32_t LoopFlag = AUDIO_BUILTIN_LOOP;\r\n int32_t wbutton;\r\n int32_t hbutton;\r\n int32_t tagval;\r\n int32_t tagvalsnd = -1;\r\n int32_t prevtag = -1;\r\n uint32_t freqtrack = 0;\r\n uint32_t currfreq = 0;\r\n uint32_t prevcurrfreq;\r\n char* pString;\r\n char* pTagArray;\r\n char StringArray[AUDIO_STR_LENGTH] = { 0 };\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Play built-in sound\\n\\n\\nPlease touch on screen\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of audio function. All the supported*/\r\n /* sounds and respective pitches are put as part of keys/buttons, by */\r\n /* choosing particular key/button the sound is played */\r\n /*************************************************************************/\r\n wbutton = (s_pHalContext->Width - 2 * AUDIO_SLIDER_MARGIN) / AUDIO_BUTTON_COLS;\r\n hbutton = s_pHalContext->Height / AUDIO_BUTTON_ROWS;\r\n /* set the tracker to track the slider for frequency */\r\n EVE_CoCmd_track(s_pHalContext, (int16_t)(s_pHalContext->Width - AUDIO_SLIDER_MARGIN), AUDIO_SLIDER_MARGIN, AUDIO_SLIDER_WIDTH,\r\n (int16_t)(s_pHalContext->Height - 2 * AUDIO_SLIDER_MARGIN), AUDIO_SLIDER_TAG);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n while (LoopFlag--)\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tagval);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER, &freqtrack);\r\n\r\n if (100 == (freqtrack & 0xff))\r\n {\r\n currfreq = (freqtrack >> 16);\r\n currfreq = (88 * currfreq) / 65536;\r\n if (currfreq > 108)\r\n currfreq = 108;\r\n }\r\n if (tagval > 0)\r\n {\r\n if (tagval <= 99)\r\n {\r\n tagvalsnd = tagval;\r\n }\r\n if (0x63 == tagvalsnd)\r\n {\r\n tagvalsnd = 0;\r\n }\r\n if ((prevtag != tagval) || (prevcurrfreq != currfreq))\r\n {\r\n /* Play sound wrt pitch */\r\n Play_Sound(s_pHalContext, tagvalsnd, AUDIO_MAX_VOLUME, currfreq + 21);\r\n }\r\n if (0 == tagvalsnd)\r\n tagvalsnd = 99;\r\n }\r\n /* start a new display list for construction of screen */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* custom keys for sound input */\r\n pTagArray = SAMAPP_Snd_TagArray;\r\n pString = SAMAPP_Snd_Array;\r\n /* First draw all the rectangles followed by the font */\r\n helperDrawBtn(pTagArray, wbutton, hbutton, StringArray, pString);\r\n\r\n /* draw the highlight rectangle */\r\n pTagArray = SAMAPP_Snd_TagArray;\r\n helperHighLightBtn(tagvalsnd, pTagArray, wbutton, hbutton);\r\n\r\n /* Draw vertical slider bar for frequency control */\r\n StringArray[0] = '\\0';\r\n strcat_s(StringArray, sizeof(StringArray), \"Pt \");\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), (int32_t)(currfreq + 21));\r\n EVE_CoDl_tagMask(s_pHalContext, 0);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width - AUDIO_SLIDER_MARGIN), AUDIO_SLIDER_MARGIN / 4, AUDIO_STR_FONT, OPT_CENTER, StringArray);\r\n EVE_CoDl_tagMask(s_pHalContext, 1);\r\n EVE_CoDl_tag(s_pHalContext, AUDIO_SLIDER_TAG);\r\n EVE_CoCmd_slider(s_pHalContext, (int16_t)(s_pHalContext->Width - AUDIO_SLIDER_MARGIN), AUDIO_SLIDER_MARGIN, AUDIO_SLIDER_WIDTH,\r\n (int16_t)(s_pHalContext->Height - 2 * AUDIO_SLIDER_MARGIN), 0, (int16_t)currfreq, AUDIO_SLIDER_MAX);\r\n\r\n prevtag = tagval;\r\n prevcurrfreq = currfreq;\r\n /* Wait till coprocessor completes the operation */\r\n Display_End(s_pHalContext);\r\n EVE_sleep(AUDIO_DELAY_MS);\r\n }\r\n\r\n Play_Sound(s_pHalContext, 0, 0, 0);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate music playback from raw file\r\n *\r\n * Loads and plays a raw audio file from storage.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_fromEABConvertedRaw()\r\n{\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Play music\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, AUDIO_LOAD_ADDR, TEST_DIR AUDIO_RAW_FILE);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_START, AUDIO_LOAD_ADDR); //Audio playback start address\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LENGTH, AUDIO_WAV_LEN); //Length of raw data buffer in bytes\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_FREQ, AUDIO_WAV_FREQ); //Frequency\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_FORMAT, S16S_SAMPLES); //Current sampling frequency\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n helperAudioStartPlayback(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n\r\n // wait until the end of audio\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_PLAYBACK_PLAY, &result);\r\n } while (result != 0);\r\n\r\n //The file is done, mute the audio first.\r\n helperAudioMute(s_pHalContext);\r\n}\r\n\r\nstatic void SAMAPP_Audio_playWavwithPauseResume()\r\n{\r\n uint32_t result = 0;\r\n uint32_t btnW = AUDIO_BTN_W;\r\n uint32_t btnH = AUDIO_BTN_H;\r\n uint32_t btnX = s_pHalContext->Width / 2 - btnW / 2;\r\n uint32_t btnY = s_pHalContext->Height - btnH - AUDIO_BTN_Y_OFFSET;\r\n static bool isPause = 0;\r\n static bool pressed = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: play wav file with pause/resume button\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, RAM_G, TEST_DIR AUDIO_WAV_FILE);\r\n EVE_CoCmd_mediaFifo(s_pHalContext, RAM_G, AUDIO_WAV_LEN + 1024); // set a mediafifo larger than data\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_READ, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_WRITE, AUDIO_WAV_LEN);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (uint16_t)(s_pHalContext->Width / 2), (uint16_t)(s_pHalContext->Height / 2), AUDIO_BTN_FONT, OPT_CENTERX | OPT_FILL, \"Now you will hear the music\");\r\n\r\n /*** Show a button ***/\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, AUDIO_BTN_FONT, 0, \"Pause/Resume\");\r\n /*** Done button ***/\r\n Display_End(s_pHalContext);\r\n\r\n helperAudioSetVolume(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n EVE_CoCmd_playWav(s_pHalContext, OPT_MEDIAFIFO);\r\n\r\n // wait until the end of audio\r\n while (EVE_Cmd_space(s_pHalContext) != EVE_CMD_FIFO_SPACE)\r\n {\r\n uint32_t touch = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_SCREEN_XY);\r\n uint32_t touch_x = touch >> 16;\r\n uint32_t touch_y = touch & 0xFFFF;\r\n //only change the button when a release happened\r\n if ((touch_x > btnX) && (touch_x < (btnX + btnW)) && (touch_y > btnY) && (touch_y < (btnY + btnH)))\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n isPause = !isPause;\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAYBACK_PAUSE, isPause);\r\n }\r\n }\r\n }\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n helperAudioSetVolume(s_pHalContext, 0, 0);\r\n}\r\n\r\n/**\r\n * @brief Play WAV from command buffer\r\n *\r\n * Loads and plays a WAV file from the command buffer.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_playWavFromCMDB()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: play wav file from command buffer\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n helperAudioSetVolume(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n EVE_CoCmd_playWav(s_pHalContext, 0);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR AUDIO_WAV_FILE, NULL);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n helperAudioSetVolume(s_pHalContext, 0, 0);\r\n}\r\n\r\n/**\r\n * @brief Play WAV from MediaFifo\r\n *\r\n * Loads and plays a WAV file using the MediaFifo buffer.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_playWavFromMediaFifo()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Play wav file from Media FiFo\");\r\n uint32_t mediafifo = AUDIO_MEDIAFIFO_ADDR;\r\n uint32_t mediafifolen = AUDIO_MEDIAFIFO_LEN;\r\n EVE_MediaFifo_set(s_pHalContext, mediafifo, mediafifolen);\r\n\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n helperAudioSetVolume(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n EVE_CoCmd_playWav(s_pHalContext, OPT_MEDIAFIFO);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR AUDIO_WAV_FILE, NULL);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n helperAudioSetVolume(s_pHalContext, 0, 0);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Play WAV from SD card\r\n *\r\n * Loads and plays a WAV file from an SD card.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_playWavFromSD()\r\n{\r\n const char *file = AUDIO_WAV_FILE;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: play wav file from SD card\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, file, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n helperAudioSetVolume(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n EVE_CoCmd_playWav(s_pHalContext, OPT_FS);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n helperAudioSetVolume(s_pHalContext, 0, 0);\r\n}\r\n\r\n/**\r\n * @brief Play WAV from Flash\r\n *\r\n * Loads and plays a WAV file from Flash memory.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_playWavFromFlash()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: play wav file from Flash\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n helperAudioSetVolume(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n EVE_CoCmd_flashSource(s_pHalContext, AUDIO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_playWav(s_pHalContext, OPT_FLASH);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n helperAudioSetVolume(s_pHalContext, 0, 0);\r\n}\r\n\r\n/**\r\n * @brief Load WAV from command buffer with pause/resume\r\n *\r\n * Loads a WAV file from the command buffer and allows pause/resume control.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_loadWavFromCMDBwithPauseResume()\r\n{\r\n uint32_t btnW = AUDIO_BTN_W;\r\n uint32_t btnH = AUDIO_BTN_H;\r\n uint32_t btnX = s_pHalContext->Width / 2 - btnW / 2;\r\n uint32_t btnY = s_pHalContext->Height - btnH - AUDIO_BTN_Y_OFFSET;\r\n static bool isPause = 0;\r\n const uint8_t btnPauseTag = AUDIO_BTN_PAUSE_TAG;\r\n static bool pressed = 0;\r\n uint8_t txtPause[2][20] = { \"PAUSE\", \"RESUME\" };\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Load wav file from command buffer\");\r\n\r\n EVE_CoCmd_loadWav(s_pHalContext, AUDIO_LOAD_ADDR, 0);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR AUDIO_WAV_FILE, NULL);\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n helperAudioStartPlayback(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n // wait until the end of audio\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &result);\r\n //only change the button when a release happened\r\n if ((result & 0xFF) == btnPauseTag)\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n isPause = !isPause;\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_PAUSE, isPause);\r\n }\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (uint16_t)(s_pHalContext->Width / 2), (uint16_t)(s_pHalContext->Height / 2), AUDIO_BTN_FONT, OPT_CENTERX | OPT_FILL, \"Now you will hear the music\");\r\n\r\n /*** Show a button ***/\r\n EVE_CoDl_tag(s_pHalContext, btnPauseTag);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, AUDIO_BTN_FONT, 0, txtPause[isPause]);\r\n /*** Done button ***/\r\n Display_End(s_pHalContext);\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_PLAYBACK_PLAY, &result);\r\n } while (result != 0);\r\n\r\n //The file is done, mute the audio.\r\n helperAudioMute(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Load WAV from MediaFifo\r\n *\r\n * Loads a WAV file using the MediaFifo buffer.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_loadWavFromMediaFifo()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Load wav file from Media FiFo\");\r\n uint32_t result = 0;\r\n uint32_t mediafifo = AUDIO_MEDIAFIFO_ADDR;\r\n uint32_t mediafifolen = AUDIO_MEDIAFIFO_LEN;\r\n EVE_MediaFifo_set(s_pHalContext, mediafifo, mediafifolen);\r\n\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n EVE_CoCmd_loadWav(s_pHalContext, mediafifo + mediafifolen, OPT_MEDIAFIFO);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR AUDIO_WAV_FILE, NULL);\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n helperAudioStartPlayback(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n\r\n // wait until the end of audio\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_PLAYBACK_PLAY, &result);\r\n } while (result != 0);\r\n\r\n //The file is done, mute the audio.\r\n helperAudioMute(s_pHalContext);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Load WAV from SD card\r\n *\r\n * Loads a WAV file from an SD card.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_loadWavFromSD()\r\n{\r\n const char *file = AUDIO_WAV_FILE;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: load wav file from SD card\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, file, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_loadWav(s_pHalContext, AUDIO_LOAD_ADDR, OPT_FS);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n helperAudioStartPlayback(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n\r\n // wait until the end of audio\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_PLAYBACK_PLAY, &result);\r\n } while (result != 0);\r\n\r\n //The file is done, mute the audio.\r\n helperAudioMute(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Load WAV from Flash\r\n *\r\n * Loads a WAV file from Flash memory.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio_loadWavFromFlash()\r\n{\r\n uint32_t result = 0;\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Video display from Flash\");\r\n Draw_Text(s_pHalContext, STR_NOW_HEAR_MUSIC);\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, AUDIO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_loadWav(s_pHalContext, AUDIO_LOAD_ADDR, OPT_FLASH);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n helperAudioStartPlayback(s_pHalContext, AUDIO_WAV_VOL, AUDIO_WAV_VOL);\r\n\r\n // wait until the end of audio\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_PLAYBACK_PLAY, &result);\r\n } while (result != 0);\r\n\r\n //The file is done, mute the audio.\r\n helperAudioMute(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all audio demos\r\n *\r\n * Calls all audio demonstration functions in sequence.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Audio()\r\n{\r\n SAMAPP_Audio_builtin();\r\n SAMAPP_Audio_fromEABConvertedRaw();\r\n SAMAPP_Audio_playWavwithPauseResume();\r\n SAMAPP_Audio_playWavFromCMDB();\r\n SAMAPP_Audio_playWavFromMediaFifo();\r\n SAMAPP_Audio_playWavFromSD();\r\n SAMAPP_Audio_playWavFromFlash();\r\n SAMAPP_Audio_loadWavFromCMDBwithPauseResume();\r\n SAMAPP_Audio_loadWavFromMediaFifo();\r\n SAMAPP_Audio_loadWavFromSD();\r\n SAMAPP_Audio_loadWavFromFlash();\r\n}\r\n\r\n\r\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"sample_id": "sampleapp_bitmap",
|
|
16
|
+
"relative_path": "SampleApp/Bitmap/Src/Bitmap.c",
|
|
17
|
+
"ext": ".c",
|
|
18
|
+
"content": "/**\r\n * @file Bitmap.c\r\n * @brief Sample usage of bitmap\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Bitmap.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define MAX_ANGLE 360\r\n#define MAX_CIRCLE_UNIT 65536\r\n#define SAMAPP_DELAY_MS 3000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define BITMAP_DELAY_MS 10\r\n#define BITMAP_TITLE_FONT 31\r\n#define BITMAP_LOAD_ADDR RAM_G\r\n#define BITMAP_ASTC_CELL_X 20\r\n#define BITMAP_ASTC_CELL_Y 20\r\n#define BITMAP_ASTC_CELL_X_INC 20\r\n#define BITMAP_ASTC_CELL_Y_INC 10\r\n#define BITMAP_ASTC_CELL_MARGIN 10\r\n#define BITMAP_ASTC_CELL_CELL 2\r\n#define BITMAP_ASTC_TITLE_W 30\r\n#define BITMAP_ASTC_CELL_TITLE_FONT 16\r\n#define BITMAP_ASTC_FU_X 20\r\n#define BITMAP_ASTC_FU_Y 50\r\n#define BITMAP_ASTC_FU_MARGIN 5\r\n#define BITMAP_ASTC_FU_CELL1 10\r\n#define BITMAP_ASTC_FU_CELL2 16\r\n#define BITMAP_MANDRILL_ROTATE_XY 100\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Bitmap();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of bitmap\",\r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Bitmap();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n// Helper to draw a bitmap centered on the screen\r\nstatic void helperDrawBitmapCentered(EVE_HalContext* phost, uint32_t addr, uint32_t format, uint16_t w, uint16_t h) \r\n{\r\n Display_Start(phost, (uint8_t[]){255, 255, 255}, (uint8_t[]){255, 255, 255}, 0, 4);\r\n EVE_CoCmd_setBitmap(phost, addr, format, w, h);\r\n EVE_CoDl_begin(phost, BITMAPS);\r\n EVE_CoDl_vertex2f_4(phost, (phost->Width - w) / 2 * 16, (phost->Height - h) / 2 * 16);\r\n EVE_CoDl_end(phost);\r\n Display_End(phost);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_GETIMAGE\r\n *\r\n * Loads and displays an image, then retrieves its properties using CMD_GETIMAGE.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_getImage()\r\n{\r\n uint32_t source, fmt, w, h, palette;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: CMD_GETIMAGE\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_SUNFLOWER, NULL, 0);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - BITMAP_SUNFLOWER_W) / 2 * 16, (s_pHalContext->Height - BITMAP_SUNFLOWER_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n // Now getImage properties\r\n EVE_CoCmd_getImage(s_pHalContext, &source, &fmt, &w, &h, &palette);\r\n eve_printf_debug(\"Loaded image: source: %u, format: %u, width: %u, height: %u, palette: %u\\n\",\r\n source, fmt, w, h, palette);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_LOADIMAGE w/o OPT_DITHER\r\n *\r\n * For PNG decoder, the dithering is enabled/disabled and the result is displayed.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_dithering()\r\n{\r\n uint16_t otp = 0;\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n for (int i = 0; i < 2; i++)\r\n {\r\n if (i == 0)\r\n {\r\n Draw_Text(s_pHalContext, \"Example for PNG dithering: Dithering disable\");\r\n }\r\n else\r\n {\r\n Draw_Text(s_pHalContext, \"Example for PNG dithering: Dithering enable\");\r\n\r\n /// Now enable dithering support\r\n otp |= OPT_DITHER;\r\n }\r\n\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_DITHER, NULL, otp);\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, RGB565, BITMAP_DITHER_W, BITMAP_DITHER_H);\r\n\r\n SAMAPP_DELAY;\r\n }\r\n}\r\n\r\n/**\r\n * @brief Draw ASTC image on screen\r\n *\r\n * @param title Image label\r\n * @param source Image source address\r\n * @param fmt Bitmap format\r\n * @param x Image X position\r\n * @param y Image Y position\r\n * @param w Image width\r\n * @param h Image height\r\n * @param margin Margin between cells\r\n * @param numcell Number of cells to draw\r\n * @return None\r\n */\r\nstatic void helperDrawASTC(const char *title, uint32_t source, uint16_t fmt, uint16_t x, uint16_t y,\r\n uint16_t w, uint16_t h, uint16_t margin, uint16_t numcell)\r\n{\r\n int t_w = BITMAP_ASTC_TITLE_W;\r\n\r\n if (title != 0)\r\n {\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, x, y, BITMAP_ASTC_CELL_TITLE_FONT, 0, title);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n }\r\n EVE_CoCmd_setBitmap(s_pHalContext, source, fmt, w, h);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n for (int i = 0; i < numcell; i++)\r\n {\r\n EVE_CoDl_cell(s_pHalContext, i);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x + t_w + (margin + w) * i) * 16, y * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate ASTC layout\r\n *\r\n * Loads and displays various ASTC bitmap layouts from RAM_G.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_ASTCLayoutRAMG()\r\n{\r\n int16_t x = BITMAP_ASTC_CELL_X;\r\n int16_t y = BITMAP_ASTC_CELL_Y;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: ASTC bitmap on RAM_G\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_ASTC_CELL);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n helperDrawASTC(\"1x1\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, BITMAP_ASTC_CELL_W, BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"1x2\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, BITMAP_ASTC_CELL_W, 2 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"1x3\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, BITMAP_ASTC_CELL_W, 3 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 4 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"1x4\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, BITMAP_ASTC_CELL_W, 4 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 5 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"1x5\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, BITMAP_ASTC_CELL_W, 5 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n\r\n x += 4 * BITMAP_ASTC_CELL_X_INC;\r\n y = BITMAP_ASTC_CELL_Y;\r\n helperDrawASTC(\"2x1\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 2 * BITMAP_ASTC_CELL_W, BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"2x2\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 2 * BITMAP_ASTC_CELL_W, 2 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"2x3\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 2 * BITMAP_ASTC_CELL_W, 3 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 4 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"2x4\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 2 * BITMAP_ASTC_CELL_W, 4 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 5 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"2x5\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 2 * BITMAP_ASTC_CELL_W, 5 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n\r\n x += 6 * BITMAP_ASTC_CELL_X_INC;\r\n y = BITMAP_ASTC_CELL_Y;\r\n helperDrawASTC(\"3x1\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 3 * BITMAP_ASTC_CELL_W, BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"3x2\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 3 * BITMAP_ASTC_CELL_W, 2 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"3x3\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 3 * BITMAP_ASTC_CELL_W, 3 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 4 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"3x4\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 3 * BITMAP_ASTC_CELL_W, 4 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 5 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"3x5\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 3 * BITMAP_ASTC_CELL_W, 5 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n\r\n x += 8 * BITMAP_ASTC_CELL_X_INC;\r\n y = BITMAP_ASTC_CELL_Y;\r\n helperDrawASTC(\"4x1\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 4 * BITMAP_ASTC_CELL_W, BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"4x2\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 4 * BITMAP_ASTC_CELL_W, 2 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"4x3\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 4 * BITMAP_ASTC_CELL_W, 3 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 4 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"4x4\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 4 * BITMAP_ASTC_CELL_W, 4 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 5 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"4x5\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 4 * BITMAP_ASTC_CELL_W, 5 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n\r\n x += 10 * BITMAP_ASTC_CELL_X_INC;\r\n y = BITMAP_ASTC_CELL_Y;\r\n helperDrawASTC(\"5x1\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 5 * BITMAP_ASTC_CELL_W, BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"5x2\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 5 * BITMAP_ASTC_CELL_W, 2 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 3 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"5x3\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 5 * BITMAP_ASTC_CELL_W, 3 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 4 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"5x4\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 5 * BITMAP_ASTC_CELL_W, 4 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n y += 5 * BITMAP_ASTC_CELL_Y_INC;\r\n helperDrawASTC(\"5x5\", 0, COMPRESSED_RGBA_ASTC_12x10_KHR, x, y, 5 * BITMAP_ASTC_CELL_W, 5 * BITMAP_ASTC_CELL_H, BITMAP_ASTC_CELL_MARGIN, BITMAP_ASTC_CELL_CELL);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate multicell ASTC bitmap on RAMG\r\n *\r\n * Loads and displays multicell ASTC bitmaps from RAM_G.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_ASTCMultiCellRAMG()\r\n{\r\n int16_t x = BITMAP_ASTC_FU_X;\r\n int16_t y = BITMAP_ASTC_FU_Y;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Multicell ASTC bitmap on RAM_G\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_ASTC_FU);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0x33, 0x33, 0x33 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, BITMAP_ASTC_FU_X, y, BITMAP_TITLE_FONT, OPT_FILL,\r\n \"Image of 168x96 (10 cells, 1008 blocks / cell):\\n\");\r\n\r\n y += BITMAP_ASTC_FU_Y;\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n helperDrawASTC(0, BITMAP_LOAD_ADDR, COMPRESSED_RGBA_ASTC_4x4_KHR, x, y, BITMAP_ASTC_FU_W, BITMAP_ASTC_FU_H / BITMAP_ASTC_FU_CELL1, BITMAP_ASTC_FU_MARGIN, BITMAP_ASTC_FU_CELL1);\r\n\r\n y += 4 * BITMAP_ASTC_FU_Y;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0x33, 0x33, 0x33);\r\n EVE_CoCmd_text(s_pHalContext, BITMAP_ASTC_FU_X, y, BITMAP_TITLE_FONT, OPT_FILL,\r\n \"Image of 168x60 (16 cells, 630 blocks / cell):\\n\");\r\n y += BITMAP_ASTC_FU_Y;\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n helperDrawASTC(0, BITMAP_LOAD_ADDR, COMPRESSED_RGBA_ASTC_4x4_KHR, x, y, BITMAP_ASTC_FU_W, BITMAP_ASTC_FU_H / BITMAP_ASTC_FU_CELL2, BITMAP_ASTC_FU_MARGIN, BITMAP_ASTC_FU_CELL1);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n\r\n/**\r\n * @brief API to demonstrate image rotate by CMD_ROTATEAROUND\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_rotate()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Bitmap rotate\");\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL, NULL, OPT_RGB565);\r\n\r\n for (uint16_t i = 0; i <= MAX_ANGLE; i++)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, 0, BITMAP_TITLE_FONT, OPT_CENTERX, \"CMD_ROTATEAROUND\"); // text info\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 0);\r\n EVE_CoCmd_setBitmap(s_pHalContext, BITMAP_LOAD_ADDR, RGB565, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_rotateAround(s_pHalContext, BITMAP_MANDRILL_W / 2, BITMAP_MANDRILL_H / 2, i * MAX_CIRCLE_UNIT / MAX_ANGLE, MAX_CIRCLE_UNIT);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2 - BITMAP_MANDRILL_W / 2) * 16, (s_pHalContext->Height / 2 - BITMAP_MANDRILL_H / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n EVE_sleep(BITMAP_DELAY_MS);\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Rotate image by CMD_ROTATEAROUND\r\n *\r\n * @param address Address of image\r\n * @param format Image format\r\n * @param x Image X\r\n * @param y Image Y\r\n * @param w Image W\r\n * @param h Image H\r\n * @param rotation_angle Rotate angle\r\n */\r\nstatic void helperRotateAroundOne(uint32_t address, uint16_t format, uint16_t x, uint16_t y,\r\n uint16_t w, uint16_t h, uint16_t rotation_angle)\r\n{\r\n int16_t lw;\r\n int16_t lh;\r\n const uint16_t TRANSLATE_XY = BITMAP_MANDRILL_ROTATE_XY;\r\n\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoCmd_setBitmap(s_pHalContext, address, format, w, h);\r\n\r\n lw = w + 2 * TRANSLATE_XY;\r\n lh = h + 2 * TRANSLATE_XY;\r\n EVE_CoDl_bitmapSize(s_pHalContext, NEAREST, BORDER, BORDER, lw, lh);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_translate(s_pHalContext, TRANSLATE_XY * MAX_CIRCLE_UNIT, TRANSLATE_XY * MAX_CIRCLE_UNIT);\r\n EVE_CoCmd_rotateAround(s_pHalContext, w / 2, h / 2, rotation_angle * MAX_CIRCLE_UNIT / MAX_ANGLE, MAX_CIRCLE_UNIT);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Rotate image by CMD_ROTATE and CMD_TRANSLATE\r\n *\r\n * @param address Address of image\r\n * @param format Image format\r\n * @param x Image X\r\n * @param y Image Y\r\n * @param w Image W\r\n * @param h Image H\r\n * @param rotation_angle Rotate angle\r\n */\r\nstatic void helperRotateAndTranslateOne(uint32_t address, uint16_t format, uint16_t x, uint16_t y,\r\n uint16_t w, uint16_t h, uint16_t rotation_angle)\r\n{\r\n int16_t lw;\r\n int16_t lh;\r\n const uint16_t TRANSLATE_XY = BITMAP_MANDRILL_ROTATE_XY;\r\n\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoCmd_setBitmap(s_pHalContext, address, format, w, h);\r\n\r\n lw = w * 2;\r\n lh = h * 2;\r\n EVE_CoDl_bitmapSize(s_pHalContext, NEAREST, BORDER, BORDER, lw, lh);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_translate(s_pHalContext, (w / 2 + TRANSLATE_XY) * MAX_CIRCLE_UNIT, (w / 2 + TRANSLATE_XY) * MAX_CIRCLE_UNIT);\r\n EVE_CoCmd_rotate(s_pHalContext, rotation_angle * MAX_CIRCLE_UNIT / MAX_ANGLE);\r\n EVE_CoCmd_translate(s_pHalContext, -((int32_t)(w / 2)) * MAX_CIRCLE_UNIT, -((int32_t)(h / 2)) * MAX_CIRCLE_UNIT);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief rotate and translate\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_rotateAndTranslate()\r\n{\r\n int count = MAX_ANGLE;\r\n const uint16_t TRANSLATE_XY = BITMAP_MANDRILL_ROTATE_XY;\r\n static uint16_t rotation_angle = 0;\r\n uint16_t tile1_x = BITMAP_MANDRILL_ROTATE_XY;\r\n uint16_t tile1_y = BITMAP_MANDRILL_ROTATE_XY;\r\n uint16_t tile2_x = (uint16_t)(s_pHalContext->Width / 2);\r\n uint16_t tile2_y = tile1_y;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Bitmap rotate and translate\");\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL, NULL, OPT_RGB565);\r\n\r\n while (count--)\r\n {\r\n /*Display List start*/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n rotation_angle = (rotation_angle + 1) % MAX_ANGLE;\r\n\r\n EVE_CoCmd_text(s_pHalContext, tile1_x + TRANSLATE_XY / 2, tile1_y, BITMAP_TITLE_FONT, 0, \"Rotate by RotateAround\");\r\n EVE_CoCmd_text(s_pHalContext, tile2_x + TRANSLATE_XY / 2, tile2_y, BITMAP_TITLE_FONT, 0, \"Rotate by Rotate and Translate\");\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n\r\n helperRotateAroundOne(BITMAP_LOAD_ADDR, RGB565, tile1_x, tile1_y, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H, rotation_angle);\r\n helperRotateAndTranslateOne(BITMAP_LOAD_ADDR, RGB565, tile2_x, tile2_y, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H, rotation_angle);\r\n\r\n Display_End(s_pHalContext);\r\n EVE_sleep(10);\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Load image from SD card\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_loadImagefromSD()\r\n{\r\n uint32_t result = 0;\r\n uint32_t ptr = 0;\r\n uint32_t w;\r\n uint32_t h;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Load image from SD card\");\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, BITMAP_SD, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_loadImage(s_pHalContext, BITMAP_LOAD_ADDR, OPT_FS | OPT_TRUECOLOR);\r\n\r\n // Now get image properties\r\n EVE_CoCmd_getProps(s_pHalContext, &ptr, &w, &h);\r\n eve_printf_debug(\"Loaded image: ptr: %u, width: %u, height: %u \\n\", ptr, w, h);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - w) / 2 * 16, (s_pHalContext->Height - h) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Load image from flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_loadImagefromFlash()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Load image from Flash\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_flashSource(s_pHalContext, BITMAP_ADDR_FLASH_MANDRILL);\r\n EVE_CoCmd_loadImage(s_pHalContext, BITMAP_LOAD_ADDR, OPT_FLASH | OPT_RGB565);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - BITMAP_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - BITMAP_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n\r\n/**\r\n* @brief Load image in YCBCR\r\n *\r\n * @param None\r\n * @return None\r\n*/\r\nstatic void SAMAPP_Bitmap_loadImage()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Load image and display as YCBCR image\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL, NULL, OPT_YCBCR);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - BITMAP_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - BITMAP_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Load image in L8\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_loadImageMono()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Load image and display as monochromic image\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL, NULL, OPT_MONO);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_blendFunc(s_pHalContext, SRC_ALPHA, ZERO);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - BITMAP_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - BITMAP_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_blendFunc_default(s_pHalContext);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, 0, BITMAP_TITLE_FONT, OPT_CENTERX, \"Display bitmap by jpg decode L8\");\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Load image in full color\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_loadImageFullColor()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Load image full color \");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* decode the jpeg data */\r\n EVE_Util_loadImageFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL, NULL, OPT_TRUECOLOR);\r\n\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width - BITMAP_MANDRILL_W) / 2 * 16), ((s_pHalContext->Height - BITMAP_MANDRILL_H) / 2 * 16));\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, 0, BITMAP_TITLE_FONT, OPT_CENTERX, \"Display bitmap by jpg decode\");\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in YCBCR\r\n *\r\n * For format YCBCR, the image width restriction:\r\n * - 2 pixel aligned\r\n * the image height restriction:\r\n * - 2 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_YCBCR()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: YCBCR format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_YCBCR);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, YCBCR, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in LA1\r\n *\r\n * For format LA1, the image width restriction:\r\n * - 8 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_LA1()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LA1 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_LA1);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, LA1, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in LA2\r\n *\r\n * For format LA2, the image width restriction:\r\n * - 4 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_LA2()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LA2 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_LA2);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, LA2, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in LA4\r\n *\r\n * For format LA4, the image width restriction:\r\n * - 2 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_LA4()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LA4 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_LA4);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, LA4, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in LA8\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_LA8()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LA8 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_LA8);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, LA8, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in RGB6\r\n * \r\n * For format RGB6, the image width restriction:\r\n * - 8 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_RGB6()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: RGB6 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_RGB6);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, RGB6, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in RGB8\r\n *\r\n * For format RGB8, the image width restriction:\r\n * - 2 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_RGB8()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: RGB8 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_MANDRILL_RGB8);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, RGB8, BITMAP_MANDRILL_W, BITMAP_MANDRILL_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in ARGB6\r\n * \r\n * For format ARGB6, the image width restriction:\r\n * - 2 pixel aligned\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_ARGB6()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: ARGB6 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_CASE_ARGB6);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, ARGB6, BITMAP_CASE_W, BITMAP_CASE_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in ARGB8\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_ARGB8()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: ARGB8 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_CASE_ARGB8);\r\n\r\n helperDrawBitmapCentered(s_pHalContext, BITMAP_LOAD_ADDR, ARGB8, BITMAP_CASE_W, BITMAP_CASE_H);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw image in palettedARGB8\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap_PALETTEDARGB8()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: PalettedARGB8 format\");\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR, TEST_DIR BITMAP_CASE_P_ARGB8_LUT);\r\n EVE_Util_loadRawFile(s_pHalContext, BITMAP_LOAD_ADDR + BITMAP_CASE_P_LUT_SZ, TEST_DIR BITMAP_CASE_P_ARGB8_INDEX);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_setBitmap(s_pHalContext, BITMAP_LOAD_ADDR + BITMAP_CASE_P_LUT_SZ, PALETTEDARGB8, BITMAP_CASE_P_W, BITMAP_CASE_P_H);\r\n EVE_CoDl_paletteSource(s_pHalContext, BITMAP_LOAD_ADDR);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2 - BITMAP_CASE_P_W / 2) * 16, (s_pHalContext->Height / 2 - BITMAP_CASE_P_H / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all bitmap demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Bitmap()\r\n{\r\n SAMAPP_Bitmap_getImage();\r\n SAMAPP_Bitmap_dithering();\r\n SAMAPP_Bitmap_ASTCLayoutRAMG();\r\n SAMAPP_Bitmap_ASTCMultiCellRAMG();\r\n SAMAPP_Bitmap_rotate();\r\n SAMAPP_Bitmap_rotateAndTranslate();\r\n SAMAPP_Bitmap_loadImagefromSD();\r\n SAMAPP_Bitmap_loadImagefromFlash();\r\n SAMAPP_Bitmap_loadImage();\r\n SAMAPP_Bitmap_loadImageMono();\r\n SAMAPP_Bitmap_loadImageFullColor();\r\n SAMAPP_Bitmap_YCBCR();\r\n SAMAPP_Bitmap_LA1();\r\n SAMAPP_Bitmap_LA2();\r\n SAMAPP_Bitmap_LA4();\r\n SAMAPP_Bitmap_LA8();\r\n SAMAPP_Bitmap_RGB6();\r\n SAMAPP_Bitmap_RGB8();\r\n SAMAPP_Bitmap_ARGB6();\r\n SAMAPP_Bitmap_ARGB8();\r\n SAMAPP_Bitmap_PALETTEDARGB8();\r\n}\r\n\r\n\r\n"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"sample_id": "sampleapp_extension",
|
|
22
|
+
"relative_path": "SampleApp/Extension/Src/Extension.c",
|
|
23
|
+
"ext": ".c",
|
|
24
|
+
"content": "/**\r\n * @file Extension.c\r\n * @brief Sample usage of extension\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2025\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2025] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Extension.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define EXT_REGION_SCISSOR_W 240\r\n#define EXT_REGION_SCISSOR_H 320\r\n#define EXT_REGION_SCISSOR_X 150\r\n#define EXT_REGION_SCISSOR_Y 0\r\n#define EXT_REGION_ENDREGION1_X 0\r\n#define EXT_REGION_ENDREGION1_Y 90\r\n#define EXT_REGION_ENDREGION2_X 0\r\n#define EXT_REGION_ENDREGION2_Y 50\r\n#define EXT_REGION_ENDREGION3_X 0\r\n#define EXT_REGION_ENDREGION3_Y 10\r\n#define EXT_REGION_ENDREGION1_W 0\r\n#define EXT_REGION_ENDREGION1_H 80\r\n#define EXT_REGION_ENDREGION2_W 0\r\n#define EXT_REGION_ENDREGION2_H 170\r\n#define EXT_REGION_ENDREGION3_W 0\r\n#define EXT_REGION_ENDREGION3_H 300\r\n#define EXT_LINE_X1 0\r\n#define EXT_LINE_Y1 0\r\n#define EXT_LINE_X2 512\r\n#define EXT_LINE_Y2 320\r\n#define EXT_TOUCHOFFSET_WIN_NUM 2\r\n#define EXT_TOUCHOFFSET_WIN0_X 100\r\n#define EXT_TOUCHOFFSET_WIN0_Y 100\r\n#define EXT_TOUCHOFFSET_WIN1_X 800\r\n#define EXT_TOUCHOFFSET_WIN1_Y 400\r\n#define EXT_TOUCHOFFSET_WIN_W 512\r\n#define EXT_TOUCHOFFSET_WIN_H 512\r\n#define EXT_TOUCHOFFSET_BTN_NUM 4\r\n#define EXT_TOUCHOFFSET_BTN_W 220\r\n#define EXT_TOUCHOFFSET_BTN_H 220\r\n#define EXT_TOUCHOFFSET_BTN_FONT 32\r\n#define EXT_TOUCHOFFSET_BTN_X_OFF 24\r\n#define EXT_TOUCHOFFSET_BTN_Y_OFF 24\r\n#define EXT_TOUCHOFFSET_BTN_X_STEP 244\r\n#define EXT_TOUCHOFFSET_BTN_Y_STEP 244\r\n#define EXT_TOUCHOFFSET_FRAMES 1000\r\n#define EXT_TOUCHOFFSET_SLEEP_MS 6\r\n#define EXT_SNAP_BTN_W 100\r\n#define EXT_SNAP_BTN_H 80\r\n#define EXT_SNAP_BTN_FONT 29\r\n#define EXT_SNAP_TITLE_FONT 31\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\n\r\nstatic void SAMAPP_Extension();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_FSSNAPSHOT) != 0)\r\n {\r\n eve_printf_debug(\"load patch failed\\n\");\r\n return 1;\r\n }\r\n else\r\n eve_printf_debug(\"eve_loadpatch OK\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of Extension\",\r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Extension();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\nstatic void SAMAPP_Extension_Region()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: EVE_CMD_REGION and EVE_CMD_ENDREGION from base package\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 0 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext, EXT_REGION_SCISSOR_W, EXT_REGION_SCISSOR_H);\r\n EVE_CoDl_scissorXY(s_pHalContext, EXT_REGION_SCISSOR_X, EXT_REGION_SCISSOR_Y);\r\n\r\n EVE_CMD_REGION(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0); // red\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 255, 165, 0); // orange\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n EVE_CMD_REGION(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 255); // blue\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 80, 80, 200); // medium blue\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n EVE_CMD_REGION(s_pHalContext);\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 250, 80, 200); // bright pink\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n EVE_CMD_ENDREGION(s_pHalContext, EXT_REGION_ENDREGION1_X, EXT_REGION_ENDREGION1_Y, EXT_REGION_ENDREGION1_W, EXT_REGION_ENDREGION1_H);\r\n EVE_CMD_ENDREGION(s_pHalContext, EXT_REGION_ENDREGION2_X, EXT_REGION_ENDREGION2_Y, EXT_REGION_ENDREGION2_W, EXT_REGION_ENDREGION2_H);\r\n EVE_CMD_ENDREGION(s_pHalContext, EXT_REGION_ENDREGION3_X, EXT_REGION_ENDREGION3_Y, EXT_REGION_ENDREGION3_W, EXT_REGION_ENDREGION3_H);\r\n\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 16 * EXT_LINE_X1, 16 * EXT_LINE_Y1);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 16 * EXT_LINE_X2, 16 * EXT_LINE_Y2);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n\r\n/**\r\n * @brief Demonstrates the use of EVE_CMD_TOUCHOFFSET and EVE_CMD_ENDTOUCHOFFSET.\r\n *\r\n * Draws two subwindows with interactive buttons, using touch offset commands.\r\n * Handles button highlighting and frame rendering.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Extension_Touchoffset()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: EVE_CMD_TOUCHOFFSET and EVE_CMD_ENDTOUCHOFFSET from base package\");\r\n uint32_t counter = EXT_TOUCHOFFSET_FRAMES, frame = 0;\r\n uint8_t i, j;\r\n uint16_t win[EXT_TOUCHOFFSET_WIN_NUM][2] = { { EXT_TOUCHOFFSET_WIN0_X, EXT_TOUCHOFFSET_WIN0_Y }, { EXT_TOUCHOFFSET_WIN1_X, EXT_TOUCHOFFSET_WIN1_Y } }; // subwindow location\r\n uint32_t render_addr[EXT_TOUCHOFFSET_WIN_NUM] = { DDR_BITMAPS_STARTADDR, DDR_BITMAPS_STARTADDR1 }; // rendertarget address\r\n uint16_t x, y; // button location\r\n uint32_t tag = 0xFF;\r\n uint32_t prev_tag[2] = { 0 };\r\n char buttonChList[2][4][2] = { { \"a\", \"b\", \"c\", \"d\"}, { \"e\", \"f\", \"g\", \"h\"} }; // button label text\r\n bool highlighted[2][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // by default, no highlight\r\n\r\n while(frame < counter)\r\n {\r\n for (i = 0; i < EXT_TOUCHOFFSET_WIN_NUM; i++)\r\n {\r\n EVE_CMD_TOUCHOFFSET(s_pHalContext, win[i][0], win[i][1]);\r\n EVE_CoCmd_renderTarget(s_pHalContext, render_addr[i], RGB6, EXT_TOUCHOFFSET_WIN_W, EXT_TOUCHOFFSET_WIN_H);\r\n Display_Start(s_pHalContext, (uint8_t[]) { 100, 0, 30 }, (uint8_t[]) { 255, 255, 255 }, 0xFF, 4);\r\n for (j = 0; j < EXT_TOUCHOFFSET_BTN_NUM; j++)\r\n {\r\n x = EXT_TOUCHOFFSET_BTN_X_OFF + (j % 2) * EXT_TOUCHOFFSET_BTN_X_STEP;\r\n y = EXT_TOUCHOFFSET_BTN_Y_OFF + (j / 2) * EXT_TOUCHOFFSET_BTN_Y_STEP;\r\n EVE_CoDl_tag(s_pHalContext, 'a' + i * EXT_TOUCHOFFSET_BTN_NUM + j);\r\n if (highlighted[i][j])\r\n EVE_CoCmd_fgColor(s_pHalContext, 0xd06038);\r\n else\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x3870);\r\n EVE_CoCmd_button(s_pHalContext, x, y, EXT_TOUCHOFFSET_BTN_W, EXT_TOUCHOFFSET_BTN_H, EXT_TOUCHOFFSET_BTN_FONT, OPT_FLAT, buttonChList[i][j]);\r\n }\r\n EVE_CoDl_tag(s_pHalContext, 0);\r\n Display_End(s_pHalContext);\r\n EVE_CoCmd_graphicsFinish(s_pHalContext);\r\n EVE_CMD_ENDTOUCHOFFSET(s_pHalContext);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n EVE_sleep(EXT_TOUCHOFFSET_SLEEP_MS);\r\n tag = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_TAG);\r\n if (prev_tag[i] == 0)\r\n {\r\n if ((tag >= (uint32_t)('a' + i * EXT_TOUCHOFFSET_BTN_NUM)) && (tag < (uint32_t)('a' + (i + 1) * EXT_TOUCHOFFSET_BTN_NUM)))\r\n {\r\n highlighted[i][tag - 'a' - i * EXT_TOUCHOFFSET_BTN_NUM] ^= 1;\r\n }\r\n }\r\n prev_tag[i] = tag;\r\n }\r\n\r\n if (frame % EXT_TOUCHOFFSET_WIN_NUM == 0)\r\n EVE_CoCmd_renderTarget(s_pHalContext, SC0_PTR0_STARTADDR, YCBCR, s_pHalContext->Width, s_pHalContext->Height);\r\n else\r\n EVE_CoCmd_renderTarget(s_pHalContext, SC0_PTR1_STARTADDR, YCBCR, s_pHalContext->Width, s_pHalContext->Height);\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 60, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_number(s_pHalContext, 0, 0, 30, 0, frame);\r\n EVE_CoDl_vertexFormat(s_pHalContext, 0);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n for (i = 0; i < EXT_TOUCHOFFSET_WIN_NUM; i++)\r\n {\r\n EVE_CoCmd_setBitmap(s_pHalContext, render_addr[i], RGB6, EXT_TOUCHOFFSET_WIN_W, EXT_TOUCHOFFSET_WIN_W);\r\n EVE_CoDl_vertex2f(s_pHalContext, win[i][0], win[i][1]);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoCmd_sync(s_pHalContext);\r\n if (frame % EXT_TOUCHOFFSET_WIN_NUM == 0)\r\n EVE_Hal_wr32(s_pHalContext, REG_SO_SOURCE, SC0_PTR0_STARTADDR);\r\n else\r\n EVE_Hal_wr32(s_pHalContext, REG_SO_SOURCE, SC0_PTR1_STARTADDR);\r\n Display_End(s_pHalContext);\r\n\r\n frame++;\r\n }\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n}\r\n\r\n/**\r\n * @brief Demonstrates the use of EVE_CMD_FSSNAPSHOT.\r\n *\r\n * Save snapshot in SD card and display\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Extension_Fssnapshot()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: EVE_CMD_FSSNAPSHOT from fssnapshot extension\");\r\n\r\n\tuint32_t result = 0;\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n int16_t BorderSz = EXT_SNAP_BTN_W;\r\n uint32_t MemZeroSz;\r\n uint32_t tag = 0;\r\n\r\n MemZeroSz = 1L * (s_pHalContext->Width - 2 * BorderSz) * (s_pHalContext->Height - 2 * BorderSz);\r\n /* Sketch L8 format */\r\n /* Send command sketch */\r\n EVE_CoCmd_memZero(s_pHalContext, RAM_G, MemZeroSz);\r\n EVE_CoCmd_sketch(s_pHalContext, BorderSz, BorderSz,\r\n (int16_t)(s_pHalContext->Width - 2 * BorderSz),\r\n (int16_t)(s_pHalContext->Height - 2 * BorderSz), 0, L8); //sketch in L8 format\r\n /* Display the sketch */\r\n while ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && (tag != 's'))\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext,\r\n (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_scissorXY(s_pHalContext, BorderSz, BorderSz);\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n /* default the scissor size */\r\n EVE_CoDl_scissorSize(s_pHalContext, 2048, 2048);\r\n EVE_CoDl_scissorXY(s_pHalContext, 0, 0);\r\n\r\n /* L8 bitmap display */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_setBitmap(s_pHalContext, RAM_G, L8, (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, BorderSz * 16, BorderSz * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n /* Display the button */\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_tag(s_pHalContext, 's');\r\n EVE_CoCmd_button(s_pHalContext, (int16_t)(s_pHalContext->Width - EXT_SNAP_BTN_W), 0, EXT_SNAP_BTN_W, EXT_SNAP_BTN_H, EXT_SNAP_BTN_FONT, 0, \"snapshot\");\r\n Display_End(s_pHalContext);\r\n }\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n /* Update the command buffer pointers - both read and write pointers */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n /* save snapshot */\r\n const char *file = \"SNAP.BMP\";\r\n EVE_CMD_FSSNAPSHOT(s_pHalContext, DDR_BITMAPS_STARTADDR, file, &result);\r\n eve_printf_debug(\"FSSNAPSHOT status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"FSSNAPSHOT failed\\n\");\r\n return;\r\n }\r\n\r\n\t/* Display the snapshot image */\r\n Draw_Text(s_pHalContext, \"Display saved screen\");\r\n EVE_CoCmd_fsRead(s_pHalContext, RAM_G, file, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, RAM_G + 128, RGB8, s_pHalContext->Width, s_pHalContext->Height); // Skip the 128-byte header before reading the pixel data\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, 0, EXT_SNAP_TITLE_FONT, OPT_CENTERX, \"This is the saved screen\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all extension demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Extension()\r\n{\r\n SAMAPP_Extension_Region();\r\n SAMAPP_Extension_Touchoffset();\r\n}\r\n\r\n\r\n"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"sample_id": "sampleapp_flash",
|
|
28
|
+
"relative_path": "SampleApp/Flash/Src/Flash.c",
|
|
29
|
+
"ext": ".c",
|
|
30
|
+
"content": "/**\r\n * @file Flash.c\r\n * @brief Sample usage of flash\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Flash.h\"\r\n#include \"FileTransfer.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define FLASH_DELAY_MS 1000\r\n#define FLASH_TITLE_FONT 31\r\n#define FLASH_TITLE_Y_INC 60\r\n#define FLASH_MSG_NUM 50\r\n#define FLASH_MSG_LEN 50\r\n#define FLASH_MSG_OFFSET_X 20\r\n#define FLASH_STATUS_NONE 4\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Flash();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_NAND) != 0)\r\n {\r\n eve_printf_debug(\"load patch failed\\n\");\r\n return 1;\r\n }\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n //EVE_Calibrate(s_pHalContext);\r\n //Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of flash\", \r\n \"\",\r\n \"\"\r\n };\r\n //WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Flash();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\nstatic char *flashMessage[FLASH_MSG_NUM];\r\nstatic int messageIndex = 0;\r\n\r\n// helper to append messages\r\nstatic void helperAppendMessage(char *s, int num)\r\n{\r\n flashMessage[messageIndex] = (char*)malloc(num);\r\n if (!flashMessage[messageIndex]) {\r\n eve_printf(\"Malloc failed\");\r\n return;\r\n }\r\n\r\n memcpy(flashMessage[messageIndex], s, num);\r\n \r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n\r\n int y = 0;\r\n int x = FLASH_MSG_OFFSET_X;\r\n for (int i = 0; i <= messageIndex; i++)\r\n {\r\n EVE_CoCmd_text(s_pHalContext, x, y, FLASH_TITLE_FONT, 0, flashMessage[i]);\r\n y += FLASH_TITLE_Y_INC;\r\n }\r\n Display_End(s_pHalContext);\r\n\r\n messageIndex++;\r\n EVE_sleep(FLASH_DELAY_MS);\r\n}\r\n\r\n// helper to clear message\r\nstatic void helperClearMessage()\r\n{\r\n for (int i = 0; i < messageIndex; i++)\r\n {\r\n free(flashMessage[i]);\r\n }\r\n messageIndex = 0;\r\n}\r\n\r\n// helper to get flash state\r\nstatic void helperGetFlashState(char *msg, int len, uint32_t state)\r\n{\r\n uint32_t status = 0;\r\n const char *flash_status[4] = { \"INIT\", \"DETACHED\", \"BASIC\", \"FULL\" };\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_FLASH_STATUS, &status);\r\n if (state < FLASH_STATUS_NONE)\r\n {\r\n if (status != state)\r\n {\r\n eve_sprintf(msg, len, \"Flash is not able to change to %s\\n\", flash_status[state]);\r\n helperAppendMessage(msg, len);\r\n }\r\n else\r\n {\r\n eve_sprintf(msg, len, \"Flash is changed to %s\\n\", flash_status[state]);\r\n helperAppendMessage(msg, len);\r\n }\r\n }\r\n eve_sprintf(msg, len, \"Flash State: %s (%d)\\n\", flash_status[status], status);\r\n helperAppendMessage(msg, len);\r\n EVE_sleep(FLASH_DELAY_MS);\r\n}\r\n /**\r\n * @brief API to demonstrate flash states\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Flash_state()\r\n{\r\n char msg[FLASH_MSG_LEN];\r\n int msgLen = FLASH_MSG_LEN;\r\n uint32_t status = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Flash states\");\r\n\r\n eve_printf_debug(\"\\nFLASH STATES\\n\");\r\n helperGetFlashState(msg, msgLen, FLASH_STATUS_NONE);\r\n\r\n eve_sprintf(msg, msgLen, \"CMD_FLASHDETACH\");\r\n helperAppendMessage(msg, msgLen);\r\n EVE_CoCmd_flashDetach(s_pHalContext);\r\n\r\n helperGetFlashState(msg, msgLen, FLASH_STATUS_DETACHED);\r\n\r\n eve_sprintf(msg, msgLen, \"CMD_FLASHATTACH\");\r\n helperAppendMessage(msg, msgLen);\r\n EVE_CoCmd_flashAttach(s_pHalContext);\r\n\r\n helperGetFlashState(msg, msgLen, FLASH_STATUS_BASIC);\r\n\r\n eve_sprintf(msg, msgLen, \"CMD_FLASHFAST\");\r\n helperAppendMessage(msg, msgLen);\r\n EVE_CoCmd_flashFast(s_pHalContext, 0);\r\n\r\n helperGetFlashState(msg, msgLen, FLASH_STATUS_FULL);\r\n\r\n eve_sprintf(msg, msgLen, \"Check Flash Size\");\r\n helperAppendMessage(msg, msgLen);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_FLASH_SIZE, &status);\r\n eve_sprintf(msg, msgLen, \"Flash size : %d MBytes\", status);\r\n helperAppendMessage(msg, msgLen);\r\n\r\n helperClearMessage();\r\n EVE_sleep(FLASH_DELAY_MS);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate flash programming\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Flash_program()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Flash program\");\r\n\r\n // write flash\r\n uint32_t addr_flash = 0;\r\n Write_To_Flash_With_Progressbar(s_pHalContext, TEST_DIR \"/Flash/EveFlash.bin\", &addr_flash, false);\r\n eve_printf_debug(\"flash image programed at 0x%lx\\n\", addr_flash);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate flash programming from EVE connected SD card\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nvoid SAMAPP_Flash_program_from_EVE_SD()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Flash program from EVE connected SD card\");\r\n\r\n uint32_t addr_flash = 0;\r\n Write_To_Flash_With_Progressbar(s_pHalContext, \"EveFlash.bin\", &addr_flash, true);\r\n eve_printf_debug(\"flash image programed at 0x%lx\\n\", addr_flash);\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all flash demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Flash() {\r\n SAMAPP_Flash_state();\r\n //SAMAPP_Flash_program();\r\n SAMAPP_Flash_program_from_EVE_SD();\r\n}\r\n\r\n\r\n"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"sample_id": "sampleapp_font",
|
|
34
|
+
"relative_path": "SampleApp/Font/Src/Font.c",
|
|
35
|
+
"ext": ".c",
|
|
36
|
+
"content": "/**\r\n * @file Font.c\r\n * @brief Sample usage of font\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Font.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define FONT_LOAD_ADDR RAM_G\r\n#define FONT_LINE_X 50\r\n#define FONT_LINE_Y 100\r\n#define FONT_LINE_Y_INC 20\r\n#define FONT_TITLE_X 20\r\n#define FONT_TITLE_Y 20\r\n#define FONT_TITLE_FONT 30\r\n#define FONT_TITLE_LEN 12\r\n#define FONT_TEXT_Y 80\r\n#define FONT_TEXT_Y_INC 40\r\n#define FONT_JPG_TBL_ADDR RAM_G\r\n#define FONT_SET_FONT 7\r\n\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Font();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of fonts\",\r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Font();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n/**\r\n * @brief Inbuilt font example for proportional text\r\n * only font handle 16 - 25 can be printed by cell\r\n * This function is solely for displaying fonts in a legacy format and is not intended for regular use\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_romFonts()\r\n{\r\n int32_t j;\r\n int32_t hoffset;\r\n int32_t voffset;\r\n int32_t stringlen1;\r\n int32_t stringlen2;\r\n int32_t stringlen3;\r\n uint32_t FontTableAddressBase = s_pHalContext->DDR_RamSize - 256; // Pseudo-ROM font table\r\n uint32_t FontTableAddress;\r\n const uint8_t Display_string1[] = \"!\\\"#$%&'()*+,-./0123456789:;<=>?\";\r\n const uint8_t Display_string2[] = \"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_\";\r\n const uint8_t Display_string3[] = \"`abcdefghijklmnopqrstuvwxyz{|} \";\r\n EVE_Gpu_Fonts fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: ROM fonts 16 to 25\");\r\n\r\n stringlen1 = sizeof(Display_string1) - 1;\r\n stringlen2 = sizeof(Display_string2) - 1;\r\n stringlen3 = sizeof(Display_string3) - 1;\r\n\r\n for (int romFont = 16; romFont < 26; romFont++)\r\n {\r\n if (romFont == 17 || romFont == 19)\r\n continue;\r\n /* Read the font address from 0xFFFFC location */\r\n FontTableAddress = EVE_Hal_rd32(s_pHalContext, FontTableAddressBase + 4 * romFont);\r\n eve_printf_debug(\"ROM Font address read from 0x%lx is %x \\n\", FontTableAddressBase + 4 * romFont, FontTableAddress);\r\n /* Read the font table from hardware */\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FontTableAddress, EVE_GPU_FONT_TABLE_SIZE);\r\n eve_printf_debug(\"Inbuilt font structure idx %d fmt 0x%x flags 0x%x hight 0x%x line stride 0x%x width 0x%x Fontaddr 0x%x \\n\", romFont,\r\n fontstruct.FontBitmapFormat, fontstruct.FontFlags, fontstruct.FontHeightInPixels,\r\n fontstruct.FontLineStride, fontstruct.FontWidthInPixels,\r\n fontstruct.PointerToFontGraphicsData);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n hoffset = FONT_LINE_X;\r\n voffset = FONT_LINE_Y;\r\n char str[FONT_TITLE_LEN];\r\n snprintf(str, FONT_TITLE_LEN, \"ROM FONT %d\", romFont);\r\n EVE_CoCmd_text(s_pHalContext, hoffset, voffset, romFont, 0, str);\r\n /* Display string */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n voffset += FONT_LINE_Y;\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, romFont);\r\n for (j = 0; j < stringlen1; j++)\r\n {\r\n EVE_CoDl_cell(s_pHalContext, Display_string1[j]);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += fontstruct.FontWidth[Display_string1[j]];\r\n }\r\n hoffset = FONT_LINE_X;\r\n voffset += fontstruct.FontHeightInPixels + FONT_LINE_Y_INC;\r\n for (j = 0; j < stringlen2; j++)\r\n {\r\n EVE_CoDl_cell(s_pHalContext, Display_string2[j]);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += fontstruct.FontWidth[Display_string2[j]];\r\n }\r\n hoffset = FONT_LINE_X;\r\n voffset += fontstruct.FontHeightInPixels + FONT_LINE_Y_INC;\r\n for (j = 0; j < stringlen3; j++)\r\n {\r\n EVE_CoDl_cell(s_pHalContext, Display_string3[j]);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += fontstruct.FontWidth[Display_string3[j]];\r\n }\r\n\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n }\r\n}\r\n\r\n// helper to draw font charaters\r\nstatic void helperDrawFontCharacters(uint32_t font_addr, char *str)\r\n{\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), FONT_TITLE_Y, FONT_TITLE_FONT, OPT_CENTER, str);\r\n EVE_CoCmd_setFont(s_pHalContext, FONT_SET_FONT, font_addr, FONT_START_CHAR);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), FONT_TEXT_Y, FONT_SET_FONT, OPT_CENTER,\r\n \"The quick brown fox jumps\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), FONT_TEXT_Y + FONT_TEXT_Y_INC, FONT_SET_FONT, OPT_CENTER,\r\n \"over the lazy dog.\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), FONT_TEXT_Y + 2 * FONT_TEXT_Y_INC, FONT_SET_FONT, OPT_CENTER,\r\n \"1234567890\");\r\n EVE_CoCmd_resetFonts(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom font display from a JPEG file\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_fromJPEG()\r\n{\r\n EVE_Gpu_Fonts fontstruct;\r\n Draw_Text(s_pHalContext, \"Example for: Custom font from a JPEG file\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of setfont. Setfont function draws */\r\n /* custom configured fonts on screen. Download the font table and raw */\r\n /* font data in L1/L4/L8 format and display text */\r\n /*************************************************************************/\r\n memset(fontstruct.FontWidth, FONT_JPG_WIDTH, EVE_GPU_NUMCHAR_PERFONT);\r\n fontstruct.FontBitmapFormat = FONT_JPG_FORMAT;\r\n fontstruct.FontFlags = FONT_JPG_FLAGS;\r\n fontstruct.FontLineStride = FONT_JPG_LINESTRIDE;\r\n fontstruct.FontWidthInPixels = FONT_JPG_WIDTHINPIX;\r\n fontstruct.FontHeightInPixels = FONT_JPG_HEIGHTINPIX;\r\n fontstruct.PointerToFontGraphicsData = FONT_JPG_TBL_ADDR + FONT_JPG_DATA;\r\n EVE_Hal_wrMem(s_pHalContext, FONT_JPG_TBL_ADDR, (int8_t *)&fontstruct, EVE_GPU_FONT_TABLE_SIZE);\r\n\r\n /* Characters from 32 to 128 are present and each character is 16*16 dimention */\r\n /******************* Decode jpg output into location 1024 and output color format as MONO *********************/\r\n if (!EVE_Util_loadImageFile(s_pHalContext, FONT_JPG_TBL_ADDR + FONT_JPG_DATA, TEST_DIR FONT_JPG, NULL, OPT_MONO))\r\n {\r\n eve_printf_debug(\"Failed to load image file: %s\\n\", FONT_JPG);\r\n return;\r\n }\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from JPEG - Legacy format L8\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom font display from a converted font file\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_fromConvertedTTF()\r\n{\r\n EVE_Gpu_Fonts fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Custom font from a converted font file\");\r\n if (!EVE_Util_loadRawFile(s_pHalContext, RAM_G, TEST_DIR ROBOTO_L4_RAW))\r\n {\r\n eve_printf_debug(\"Failed to load raw font file: %s\\n\", ROBOTO_L4_RAW);\r\n return;\r\n }\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, EVE_GPU_FONT_TABLE_SIZE);\r\n eve_printf_debug(\"font structure fmt 0x%x flags 0x%x hight 0x%x line stride 0x%x width 0x%x Fontaddr 0x%x \\n\",\r\n fontstruct.FontBitmapFormat, fontstruct.FontFlags, fontstruct.FontHeightInPixels,\r\n fontstruct.FontLineStride, fontstruct.FontWidthInPixels,\r\n fontstruct.PointerToFontGraphicsData);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from raw file - Legacy\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom font display from a converted font file in flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_fromConvertedTTF_flash()\r\n{\r\n EVE_Gpu_Fonts fontstruct;\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Cannot switch flash full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Custom font from a converted font file in flash\");\r\n EVE_CoCmd_flashSource(s_pHalContext, FONT_FLASH_ROBOTO_L4_RELOC);\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, OPT_FLASH);\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, EVE_GPU_FONT_TABLE_SIZE);\r\n eve_printf_debug(\"font structure fmt 0x%x flags 0x%x hight 0x%x line stride 0x%x width 0x%x Fontaddr 0x%x \\n\",\r\n fontstruct.FontBitmapFormat, fontstruct.FontFlags, fontstruct.FontHeightInPixels,\r\n fontstruct.FontLineStride, fontstruct.FontWidthInPixels,\r\n fontstruct.PointerToFontGraphicsData);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from flash - Legacy\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom font display from a converted font file in SD card\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_fromConvertedTTF_SD()\r\n{\r\n EVE_Gpu_Fonts fontstruct;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Custom font from a converted font file in SD card\");\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, FONT_SD, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, OPT_FS);\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, EVE_GPU_FONT_TABLE_SIZE);\r\n eve_printf_debug(\"font structure fmt 0x%x flags 0x%x hight 0x%x line stride 0x%x width 0x%x Fontaddr 0x%x \\n\",\r\n fontstruct.FontBitmapFormat, fontstruct.FontFlags, fontstruct.FontHeightInPixels,\r\n fontstruct.FontLineStride, fontstruct.FontWidthInPixels,\r\n fontstruct.PointerToFontGraphicsData);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from SD card - Legacy\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom font display from a converted font file from CMDB\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_fromConvertedTTF_CMDB()\r\n{\r\n EVE_Gpu_Fonts fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Custom font from a converted font file from CMDB\");\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, 0);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR ROBOTO_L4_RELOC, NULL);\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, EVE_GPU_FONT_TABLE_SIZE);\r\n eve_printf_debug(\"font structure fmt 0x%x flags 0x%x hight 0x%x line stride 0x%x width 0x%x Fontaddr 0x%x \\n\",\r\n fontstruct.FontBitmapFormat, fontstruct.FontFlags, fontstruct.FontHeightInPixels,\r\n fontstruct.FontLineStride, fontstruct.FontWidthInPixels,\r\n fontstruct.PointerToFontGraphicsData);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from command buffer - Legacy\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom extened font display from a converted font file\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_extendedFormat()\r\n{\r\n EVE_Gpu_FontsExt fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: extended font (extended format 1)\");\r\n if (!EVE_Util_loadRawFile(s_pHalContext, FONT_LOAD_ADDR, TEST_DIR ROBOTO_L1_RAW))\r\n {\r\n eve_printf_debug(\"Failed to load raw font file L1: %s\\n\", ROBOTO_L1_RAW);\r\n return;\r\n }\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, sizeof(EVE_Gpu_FontsExt));\r\n eve_printf_debug(\"signature 0x%lx size %ld fmt %d flags 0x%x layout_width %ld layout_height %ld pixel_width %ld pixel_height %ld num_of_chars %ld\\n\",\r\n fontstruct.signature, fontstruct.size, fontstruct.format, fontstruct.flags,\r\n fontstruct.layout_width, fontstruct.layout_height, fontstruct.pixel_width, fontstruct.pixel_height,\r\n fontstruct.number_of_characters);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from raw file - Extended format 1\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Load xfont to RAM_G\r\n *\r\n * @param isReindex\r\n * @return None\r\n */\r\nstatic void helperLoadXfont(uint8_t isReindex)\r\n{\r\n const char *str_noindex = u8\"面朝大海,春暖花开\";\r\n const char *str_reindex = u8\"\\u49c3\\u197e\\u0b88\\u1fd8\\u528c\\u1886\\u18f7\\u3512\\u1161\";\r\n const char *str = str_noindex;\r\n uint32_t addr;\r\n\r\n if (isReindex)\r\n {\r\n str = str_reindex;\r\n addr = FONT_FLASH_NOTO_L1_RELOC_ORDINAL;\r\n }\r\n else\r\n {\r\n str = str_noindex;\r\n addr = FONT_FLASH_NOTO_L2_RELOC;\r\n }\r\n\r\n //Load xfont file into graphics RAM\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Cannot switch flash full mode\");\r\n return;\r\n }\r\n EVE_CoCmd_flashSource(s_pHalContext, addr);\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, OPT_FLASH);\r\n EVE_CoCmd_setFont(s_pHalContext, FONT_SET_FONT, FONT_LOAD_ADDR, 0);\r\n if (isReindex)\r\n {\r\n EVE_CoCmd_text(s_pHalContext, FONT_TITLE_X, FONT_TITLE_Y, FONT_TITLE_FONT, 0,\r\n \"Display unicode string use re-index font data\");\r\n }\r\n else\r\n {\r\n EVE_CoCmd_text(s_pHalContext, FONT_TITLE_X, FONT_TITLE_Y, FONT_TITLE_FONT, 0,\r\n \"Display unicode string use the UTF code point\");\r\n }\r\n EVE_CoCmd_text(s_pHalContext, FONT_TITLE_X, FONT_TEXT_Y, FONT_SET_FONT, 0, str);\r\n EVE_CoCmd_resetFonts(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief An example for code point ordinal/UTF-8\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_indexer()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Code point ordinal/UTF-8\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n helperLoadXfont(0);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n // clear screen\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n helperLoadXfont(1);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\nstatic EVE_FontsExt2_chblk *get_FontsExt2_glyph_addr(uint32_t xf, uint32_t cp)\r\n{\r\n uint32_t *page = &((uint32_t *)(XF2_OPTR(xf)))[cp / 128];\r\n uint32_t *cd = (uint32_t *)(EVE_Hal_rd32(s_pHalContext, (uint32_t)page) + 4 * (cp % 128));\r\n return((EVE_FontsExt2_chblk *)EVE_Hal_rd32(s_pHalContext, (uint32_t)cd));\r\n}\r\n\r\n/**\r\n * @brief Inbuilt font example for proportional text (continue)\r\n * font handle 26 - 34 can be printed by bitmap\r\n * This function is solely for displaying fonts in a extended format 2 and is not intended for regular use\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_romFontsExt2()\r\n{\r\n int32_t j;\r\n int32_t hoffset;\r\n int32_t voffset;\r\n int32_t stringlen1;\r\n int32_t stringlen2;\r\n int32_t stringlen3;\r\n uint32_t FontTableAddressBase = s_pHalContext->DDR_RamSize - 256; // Pseudo-ROM font table\r\n uint32_t FontTableAddress;\r\n const uint8_t Display_string1[] = \"!\\\"#$%&'()*+,-./0123456789:;<=>?\";\r\n const uint8_t Display_string2[] = \"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_\";\r\n const uint8_t Display_string3[] = \"`abcdefghijklmnopqrstuvwxyz{|} \";\r\n EVE_Gpu_FontsExt2 fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: ROM fonts 26 to 34\");\r\n /* only font handle 16 - 26 can be printed by cell */\r\n\r\n stringlen1 = sizeof(Display_string1) - 1;\r\n stringlen2 = sizeof(Display_string2) - 1;\r\n stringlen3 = sizeof(Display_string3) - 1;\r\n\r\n for (int romFont = 26; romFont <= 34; romFont++)\r\n {\r\n FontTableAddress = EVE_Hal_rd32(s_pHalContext, FontTableAddressBase + 4 * romFont);\r\n eve_printf_debug(\"ROM Font address read from 0x%lx is %x \\n\", FontTableAddressBase + 4 * romFont, FontTableAddress);\r\n /* Read the font table from hardware */\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FontTableAddress, sizeof(EVE_Gpu_FontsExt2));\r\n eve_printf_debug(\"Inbuilt font %d signature 0x%lx size %ld fmt %d flags 0x%x layout_width %ld layout_height %ld pixel_width %ld pixel_height %ld num_of_chars %ld\\n\", romFont,\r\n fontstruct.signature, fontstruct.size, fontstruct.format, fontstruct.flags,\r\n fontstruct.layout_width, fontstruct.layout_height, fontstruct.pixel_width, fontstruct.pixel_height,\r\n fontstruct.number_of_characters);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n hoffset = FONT_LINE_X;\r\n voffset = FONT_LINE_Y;\r\n char str[FONT_TITLE_LEN];\r\n snprintf(str, FONT_TITLE_LEN, \"ROM FONT %d\", romFont);\r\n EVE_CoCmd_text(s_pHalContext, hoffset, voffset, romFont, 0, str);\r\n /* Display string */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n voffset += FONT_LINE_Y;\r\n\r\n //EVE_CoDl_bitmapHandle(s_pHalContext, romFont);\r\n for (j = 0; j < stringlen1; j++)\r\n {\r\n EVE_FontsExt2_chblk *pChblk = get_FontsExt2_glyph_addr(FontTableAddress, Display_string1[j]);\r\n EVE_FontsExt2_chblk chblk;\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&chblk, (uint32_t)pChblk, sizeof(EVE_FontsExt2_chblk));\r\n EVE_CoCmd_setBitmap(s_pHalContext, chblk.glyph, fontstruct.format, fontstruct.pixel_width, fontstruct.pixel_height);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += chblk.width;\r\n }\r\n hoffset = 50;\r\n voffset += fontstruct.pixel_height + FONT_LINE_Y_INC;\r\n for (j = 0; j < stringlen2; j++)\r\n {\r\n EVE_FontsExt2_chblk *pChblk = get_FontsExt2_glyph_addr(FontTableAddress, Display_string2[j]); \r\n EVE_FontsExt2_chblk chblk;\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&chblk, (uint32_t)pChblk, sizeof(EVE_FontsExt2_chblk));\r\n EVE_CoCmd_setBitmap(s_pHalContext, chblk.glyph, fontstruct.format, fontstruct.pixel_width, fontstruct.pixel_height);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += chblk.width;\r\n }\r\n hoffset = 50;\r\n voffset += fontstruct.pixel_height + FONT_LINE_Y_INC;\r\n for (j = 0; j < stringlen3; j++)\r\n {\r\n EVE_FontsExt2_chblk *pChblk = get_FontsExt2_glyph_addr(FontTableAddress, Display_string3[j]);\r\n EVE_FontsExt2_chblk chblk;\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&chblk, (uint32_t)pChblk, sizeof(EVE_FontsExt2_chblk));\r\n EVE_CoCmd_setBitmap(s_pHalContext, chblk.glyph, fontstruct.format, fontstruct.pixel_width, fontstruct.pixel_height);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += chblk.width;\r\n }\r\n\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n }\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate custom extened font display from a converted font file\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_extendedFormat2()\r\n{\r\n EVE_Gpu_FontsExt2 fontstruct;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: extened font (extended format 2)\");\r\n if (!EVE_Util_loadRawFile(s_pHalContext, FONT_LOAD_ADDR, TEST_DIR ROBOTO_L2_RAW))\r\n {\r\n eve_printf_debug(\"Failed to load raw font file L2: %s\\n\", ROBOTO_L2_RAW);\r\n return;\r\n }\r\n\r\n EVE_Hal_rdMem(s_pHalContext, (uint8_t *)&fontstruct, FONT_LOAD_ADDR, sizeof(EVE_Gpu_FontsExt2));\r\n eve_printf_debug(\"signature 0x%lx size %ld fmt %d flags 0x%x layout_width %ld layout_height %ld pixel_width %ld pixel_height %ld num_of_chars %ld\\n\",\r\n fontstruct.signature, fontstruct.size, fontstruct.format, fontstruct.flags,\r\n fontstruct.layout_width, fontstruct.layout_height, fontstruct.pixel_width, fontstruct.pixel_height,\r\n fontstruct.number_of_characters);\r\n\r\n helperDrawFontCharacters(FONT_LOAD_ADDR, \"Set Font from raw file - Extended format 2\");\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate unicode font from flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_extendedFormat2_flash()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Cannot switch flash full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: extened font from flash\");\r\n\r\n // Copy font to ramg\r\n EVE_CoCmd_flashSource(s_pHalContext, FONT_FLASH_NOTO_L2_RELOC);\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, OPT_FLASH);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setFont(s_pHalContext, FONT_SET_FONT, FONT_LOAD_ADDR, 0);\r\n EVE_CoCmd_text(s_pHalContext, 0, FONT_LINE_Y, FONT_SET_FONT, 0, u8\"碧洁特的全球公司总部位于亚太地区的中心新加坡。\");\r\n EVE_CoCmd_text(s_pHalContext, 0, 2 * FONT_LINE_Y, FONT_SET_FONT, 0, u8\"公司在格拉斯哥、新加坡、台北(台湾)和胡志明(越南)设有研发机构,\");\r\n EVE_CoCmd_text(s_pHalContext, 0, 3 * FONT_LINE_Y, FONT_SET_FONT, 0, u8\"并在格拉斯哥、台北、蒂加德(美国俄勒冈州)和上海(中国)设有区域销售和技术支持机构。\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_RESETFONTS\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font_resetFont()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Cannot switch flash full mode\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Font reset\");\r\n EVE_CoCmd_resetFonts(s_pHalContext);\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, FONT_FLASH_ROBOTO_L4_RELOC);\r\n EVE_CoCmd_loadAsset(s_pHalContext, FONT_LOAD_ADDR, OPT_FLASH);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n uint32_t x = s_pHalContext->Width / 2;\r\n uint32_t y = s_pHalContext->Height / 2;\r\n EVE_CoCmd_setFont(s_pHalContext, FONT_TITLE_FONT, FONT_LOAD_ADDR, FONT_START_CHAR);\r\n EVE_CoCmd_text(s_pHalContext, x, y, FONT_TITLE_FONT, OPT_CENTER,\r\n \"Use custom font with bitmap handle 30 from SAMAPP_Font_fromConvertedTTF_flash():\");\r\n EVE_CoCmd_text(s_pHalContext, x, y + FONT_TEXT_Y_INC, FONT_TITLE_FONT, OPT_CENTER,\r\n \"The quick brown fox jumps over the lazy dog\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_resetFonts(s_pHalContext);\r\n EVE_CoCmd_text(s_pHalContext, x, y, FONT_TITLE_FONT, OPT_CENTER, \"Call CMD_RESETFONTS and use font 30:\");\r\n EVE_CoCmd_text(s_pHalContext, x, y + FONT_TEXT_Y_INC, FONT_TITLE_FONT, OPT_CENTER,\r\n \"The quick brown fox jumps over the lazy dog\");\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all font demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Font()\r\n{\r\n SAMAPP_Font_romFonts();\r\n SAMAPP_Font_fromJPEG();\r\n SAMAPP_Font_fromConvertedTTF();\r\n SAMAPP_Font_fromConvertedTTF_flash();\r\n SAMAPP_Font_fromConvertedTTF_SD();\r\n SAMAPP_Font_fromConvertedTTF_CMDB();\r\n SAMAPP_Font_extendedFormat();\r\n SAMAPP_Font_indexer();\r\n SAMAPP_Font_romFontsExt2();\r\n SAMAPP_Font_extendedFormat2();\r\n SAMAPP_Font_extendedFormat2_flash();\r\n SAMAPP_Font_resetFont();\r\n}\r\n\r\n\r\n"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"sample_id": "sampleapp_lvdsrx",
|
|
40
|
+
"relative_path": "SampleApp/Lvdsrx/Src/Lvdsrx.c",
|
|
41
|
+
"ext": ".c",
|
|
42
|
+
"content": "/**\r\n * @file Lvdsrx.c\r\n * @brief Sample usage of LVDSRX\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2025\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2025] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Lvdsrx.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define LVDSRX_W 1920\r\n#define LVDSRX_H 1080\r\n#define LVDSRX_TITLE_Y 100\r\n#define LVDSRX_TITLE_FONT 31\r\n#define LVDSRX_LOOP 2000\r\n#define LVDSRX_W_L 800\r\n#define LVDSRX_H_L 600\r\n\r\ntypedef enum\r\n{\r\n LVDSRX_DISCONNECT = 0, /**< 0 */\r\n LVDSRX_CONNECTING, /**< 1 */\r\n LVDSRX_CONNECTED, /**< 2 */\r\n} Lvdsrx_conn;\r\nstatic uint8_t LVDS_connected = LVDSRX_DISCONNECT;\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_LvdsRx();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n {\r\n eve_printf_debug(\"load patch failed\\n\");\r\n return 1;\r\n }\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of LVDSRX\", \r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_LvdsRx();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n// helper function to check LVDSRX connection\r\nstatic uint8_t helperCheckLvdsConn(uint8_t ch)\r\n{\r\n uint32_t reg_val;\r\n uint32_t lock = 0;\r\n if (ch == 2) // two channel\r\n lock = (CHn_DLL_LOCKED << 25) | (CHn_DLL_LOCKED << 24);\r\n else if (ch == 1) // one channel\r\n lock = (CHn_DLL_LOCKED << 24);\r\n else\r\n {\r\n eve_printf_debug(\"channel set wrong, only accept 1 or 2.\\n\");\r\n return LVDSRX_DISCONNECT;\r\n }\r\n\r\n reg_val = (EVE_Hal_rd32(s_pHalContext, REG_LVDSRX_STAT) & lock);\r\n\r\n if (reg_val != lock)\r\n {\r\n if (LVDS_connected == LVDSRX_CONNECTED) // lost connection\r\n {\r\n eve_printf_debug(\"LVDS lost connection, stop it\\n\");\r\n reg_val = EVE_Hal_rd32(s_pHalContext, REG_LVDSRX_CTRL);\r\n reg_val &= ~((CHn_PWDN_B_ON << 8) | CHn_PWDN_B_ON);\r\n EVE_Hal_wr32(s_pHalContext, REG_LVDSRX_CTRL, reg_val);\r\n LVDS_connected = LVDSRX_DISCONNECT;\r\n }\r\n else if (LVDS_connected == LVDSRX_DISCONNECT)\r\n {\r\n eve_printf_debug(\"LVDS restart\\n\");\r\n reg_val = EVE_Hal_rd32(s_pHalContext, REG_LVDSRX_CTRL);\r\n reg_val |= ((CHn_PWDN_B_ON << 8) | CHn_PWDN_B_ON);\r\n EVE_Hal_wr32(s_pHalContext, REG_LVDSRX_CTRL, reg_val);\r\n LVDS_connected = LVDSRX_CONNECTING;\r\n }\r\n else\r\n {\r\n // no action\r\n }\r\n }\r\n else\r\n {\r\n if (LVDS_connected == LVDSRX_CONNECTING)\r\n {\r\n eve_printf_debug(\"LVDS re-sync\\n\");\r\n LVDS_connected = LVDSRX_CONNECTED;\r\n }\r\n else\r\n {\r\n // no action\r\n }\r\n }\r\n return LVDS_connected;\r\n\r\n}\r\n\r\n/**\r\n * @brief Use LVDSRX without swapchain\r\n * \r\n * In this case, LVDSRX will render using a single address, but this is not recommended as there is no synchronization guarantee. \r\n * It is intended only for testing the basic functionality of LVDSRX.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_LvdsRx_withoutSC()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LVDSRX without Swapchain\");\r\n Display_Config(s_pHalContext, YCBCR, MODE_LVDSRX);\r\n LVDS_connected = LVDSRX_CONNECTING;\r\n\r\n uint32_t counter = LVDSRX_LOOP;\r\n while (counter > 0)\r\n {\r\n if (helperCheckLvdsConn(2) != LVDSRX_CONNECTED)\r\n continue;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, DDR_FRAMEBUFFER_STARTADDR, RGB8, LVDSRX_W, LVDSRX_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, LVDSRX_TITLE_Y, LVDSRX_TITLE_FONT, OPT_CENTERX, \"LVDSRX without Swapchain\");\r\n Display_End(s_pHalContext);\r\n counter--;\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Use LVDSRX with swapchain\r\n * \r\n * In this case, LVDSRX will render using a swapchain. To prevent race conditions, please follow this process:\r\n * - Wait for the valid bit in REG_SC2_STATUS to be set, indicating a valid frame\r\n * - Retrieve the address of the valid frame from REG_SC2_ADDR\r\n * - Render the bitmap\r\n * - Clear REG_SC2_STATUS to recycle the swapchain buffer\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_LvdsRx_withSC()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LVDSRX with Swapchain\");\r\n Display_Config(s_pHalContext, YCBCR, MODE_LVDSRX_SC);\r\n LVDS_connected = LVDSRX_CONNECTING;\r\n\r\n uint32_t counter = LVDSRX_LOOP;\r\n uint32_t lvdsrx_data_addr;\r\n\r\n while (counter > 0)\r\n {\r\n if (helperCheckLvdsConn(2) != LVDSRX_CONNECTED)\r\n continue;\r\n\r\n EVE_CoCmd_waitCond(s_pHalContext, REG_SC2_STATUS, EQUAL, 0x1, 0x1);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_SC2_ADDR, &lvdsrx_data_addr);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, lvdsrx_data_addr, RGB8, LVDSRX_W, LVDSRX_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, LVDSRX_TITLE_Y, LVDSRX_TITLE_FONT, OPT_CENTERX, \"LVDSRX with Swapchain\");\r\n Display_End(s_pHalContext);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_SC2_STATUS, 0); // clear status\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n counter--;\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Use LVDSRX with lower resolution\r\n * \r\n * In this case, LVDSRX is configured for an 800*600 resolution using a single channel, RGB565 format\r\n * LVDSRX will directly use swapchain 2 instead of manually updating the bitmap address\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_LvdsRx_lower_resolution()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: LVDSRX with lower resolution\");\r\n Display_Config(s_pHalContext, YCBCR, MODE_LVDSRX_LOW_RESOLUTION);\r\n LVDS_connected = LVDSRX_CONNECTING;\r\n\r\n uint32_t counter = LVDSRX_LOOP;\r\n\r\n while (counter > 0)\r\n {\r\n if (helperCheckLvdsConn(1) != LVDSRX_CONNECTED)\r\n continue;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, SWAPCHAIN_2, RGB565, LVDSRX_W_L, LVDSRX_H_L);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 16 * (s_pHalContext->Width - LVDSRX_W_L) / 2, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, LVDSRX_TITLE_Y, LVDSRX_TITLE_FONT, OPT_CENTERX, \"LVDSRX with Lower resolution\");\r\n Display_End(s_pHalContext);\r\n counter--;\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\nvoid EVE_CMD_LVDSSETUP(EVE_HalContext *phost, uint16_t p1, uint16_t p2)\r\n{\r\n EVE_Cmd_startFunc(phost);\r\n EVE_Cmd_wr32(phost, 0xffffff9f);\r\n EVE_Cmd_wr32(phost, (p1 & 0xffff) | ((uint32_t)p2 << 16));\r\n EVE_Cmd_endFunc(phost);\r\n}\r\n\r\nvoid EVE_CMD_LVDSCONN(EVE_HalContext *phost, uint32_t p1)\r\n{\r\n EVE_Cmd_startFunc(phost);\r\n EVE_Cmd_wr32(phost, 0xffffffa0);\r\n EVE_Cmd_wr32(phost, p1);\r\n EVE_Cmd_endFunc(phost);\r\n}\r\n\r\nuint32_t EVE_LIB_LVDSConn(EVE_HalContext *phost)\r\n{\r\n uint32_t wp;\r\n\r\n EVE_CMD_LVDSCONN(phost, 0);\r\n /* Wait for the result */\r\n if (!EVE_Cmd_waitFlush(phost))\r\n return 0;\r\n wp = EVE_Hal_rd32(phost, REG_CMD_WRITE) & EVE_CMD_FIFO_MASK;\r\n return EVE_Hal_rd32(phost, RAM_CMD + ((0x4000 - 4) & (wp - 4)));\r\n}\r\n\r\nvoid EVE_CMD_LVDSSTOP(EVE_HalContext *phost)\r\n{\r\n EVE_Cmd_startFunc(phost);\r\n EVE_Cmd_wr32(phost, 0xffffffa1);\r\n EVE_Cmd_endFunc(phost);\r\n}\r\n\r\nvoid EVE_CMD_LVDSSTART(EVE_HalContext *phost)\r\n{\r\n EVE_Cmd_startFunc(phost);\r\n EVE_Cmd_wr32(phost, 0xffffffa2);\r\n EVE_Cmd_endFunc(phost);\r\n}\r\n\r\nstatic void test()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: test\");\r\n Display_Config(s_pHalContext, YCBCR, MODE_LVDSRX_LOW_RESOLUTION);\r\n EVE_CMD_LVDSSTART(s_pHalContext);\r\n uint32_t counter = LVDSRX_LOOP * 10;\r\n uint32_t lvds_connected = 1;\r\n\r\n while (counter > 0)\r\n {\r\n if (EVE_LIB_LVDSConn(s_pHalContext) == 0)\r\n {\r\n if (lvds_connected == 2)\r\n {\r\n printf(\"LVDS sync lost stopped\");\r\n EVE_CMD_LVDSSTOP(s_pHalContext);\r\n lvds_connected = 0; \r\n }\r\n else if (lvds_connected == 0)\r\n { // Enable LVDS\r\n\t\t\t\tprintf(\"LVDS re-start\");\r\n EVE_CMD_LVDSSTART(s_pHalContext);\r\n\t\t\t\tlvds_connected = 1;\r\n\t\t\t}\r\n\t\t} \r\n\t\telse\r\n\t\t{ \r\n\t\t\tif(lvds_connected == 1)\r\n\t\t\t{ // Sync established\r\n printf(\"LVDS re-synced\");\r\n\t\t\t\tlvds_connected = 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(lvds_connected == 2) \r\n\t\t{ // Receive data from LVDS\r\n }\r\n if (lvds_connected != 2)\r\n continue;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, SWAPCHAIN_2, RGB565, LVDSRX_W_L, LVDSRX_H_L);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 16 * (s_pHalContext->Width - LVDSRX_W_L) / 2, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, LVDSRX_TITLE_Y, LVDSRX_TITLE_FONT, OPT_CENTERX, \"LVDSRX with Lower resolution\");\r\n Display_End(s_pHalContext);\r\n counter--;\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n\r\n/**\r\n * @brief Main entry to run all LVDSRX demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_LvdsRx()\r\n{\r\n //SAMAPP_LvdsRx_withoutSC();\r\n //SAMAPP_LvdsRx_withSC();\r\n SAMAPP_LvdsRx_lower_resolution();\r\n test();\r\n}\r\n"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"sample_id": "sampleapp_primitives",
|
|
46
|
+
"relative_path": "SampleApp/Primitives/Src/Primitives.c",
|
|
47
|
+
"ext": ".c",
|
|
48
|
+
"content": "/**\r\n * @file Primitives.c\r\n * @brief Sample usage of primitives drawing\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Primitives.h\"\r\n#include \"Maths.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 3000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define PRIM_POINT_SIZE 50\r\n#define PRIM_LINE_W 5\r\n#define PRIM_LINE_H 50\r\n#define PRIM_RECT_W 50\r\n#define PRIM_RECT_H 100\r\n#define PRIM_BITMAP_LOAD RAM_G\r\n#define PRIM_BITMAP_LOC -50\r\n#define PRIM_BARGRAPH_ARRAY_SIZE 256\r\n#define PRIM_BARGRAPH_W 256\r\n#define PRIM_BARGRAPH_H 256\r\n#define PRIM_STRIP_X1 16\r\n#define PRIM_STRIP_Y1 16\r\n#define PRIM_STRIP_X2 300\r\n#define PRIM_SCISSOR_X 100\r\n#define PRIM_SCISSOR_Y 200\r\n#define PRIM_SCISSOR_W 400\r\n#define PRIM_SCISSOR_H 400\r\n#define PRIM_CUBE_SIZE 200\r\n#define PRIM_LOOP 100\r\n#define PRIM_BALL_SIZE 100\r\n#define PRIM_BALL_EDGE 50\r\n#define PRIM_BALL_SPEED_X 10\r\n#define PRIM_BALL_SPEED_Y 8\r\n#define PRIM_BALL_SHADOW_X 20\r\n#define PRIM_BALL_SHADOW_Y 10\r\n#define PRIM_BALL_POINT_NUM 6\r\n#define PRIM_BALL_LINE_NUM 8\r\n#define PRIM_BALL_SOUND 0x50\r\n#define PRIM_BALL_VOL 100\r\n#define PRIM_DELAY_MS 10\r\n#define PRIM_TEXT_X 200\r\n#define PRIM_TEXT_Y 200\r\n#define PRIM_TEXT_INC 20\r\n#define PRIM_TITLE_FONT 30\r\n#define PRIM_CAL_X 20\r\n#define PRIM_CAL_Y 20\r\n#define PRIM_MAP_LINE_W1 20\r\n#define PRIM_MAP_LINE_W2 15\r\n#define PRIM_MAP_LINE_X1 -10\r\n#define PRIM_MAP_LINE_X2 -1\r\n#define PRIM_MAP_LINE_X3 (s_pHalContext->Width / 2)\r\n#define PRIM_MAP_LINE_Y1 -1\r\n#define PRIM_MAP_LINE_Y2 (s_pHalContext->Height / 2)\r\n#define PRIM_TITLE_X 240\r\n#define PRIM_TITLE_Y 90\r\n#define PRIM_REGION_X 50\r\n#define PRIM_REGION_W 500\r\n#define PRIM_REGION_H 500\r\n#define PRIM_REGION_TEXT_W 5\r\n#define PRIM_REGION_SCISSOR_W 50\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Primitives();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of primitives graphics\", \r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Primitives();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n/**\r\n * @brief helper function linear interpolation\r\n *\r\n * @param t deltaTime\r\n * @param a transform position\r\n * @param b target position\r\n * @return float\r\n */\r\nstatic float helperLerp(float t, float a, float b)\r\n{\r\n return (1 - t) * a + t * b;\r\n}\r\n\r\n/**\r\n * @brief helper function Smooth linear interpolation\r\n *\r\n * @param t deltaTime\r\n * @param a transform position\r\n * @param b target position\r\n * @return float\r\n */\r\nstatic float helperSmoothLerp(float t, float a, float b)\r\n{\r\n float lt = 3 * t * t - 2 * t * t * t;\r\n return helperLerp(lt, a, b);\r\n}\r\n\r\n/**\r\n * @brief display few points at various offsets with various colors\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_points()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Points\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Construct DL of points */\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_colorRgb(s_pHalContext, 128, 0, 0);\r\n EVE_CoDl_pointSize(s_pHalContext, (PRIM_POINT_SIZE / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 5) * 16, (s_pHalContext->Height / 2) * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 128, 0);\r\n EVE_CoDl_pointSize(s_pHalContext, PRIM_POINT_SIZE * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 2 / 5) * 16, (s_pHalContext->Height / 2) * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 128);\r\n EVE_CoDl_pointSize(s_pHalContext, (PRIM_POINT_SIZE * 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 3 / 5) * 16, (s_pHalContext->Height / 2) * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 128, 128, 0);\r\n EVE_CoDl_pointSize(s_pHalContext, (PRIM_POINT_SIZE * 3) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 4 / 5) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display Lines on screen\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_lines()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Lines\");\r\n\r\n int16_t LineHeight = PRIM_LINE_H;\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n EVE_CoDl_colorRgb(s_pHalContext, 128, 0, 0);\r\n EVE_CoDl_lineWidth(s_pHalContext, PRIM_LINE_W * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 4) * 16, ((s_pHalContext->Height - LineHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 4) * 16, ((s_pHalContext->Height + LineHeight) / 2) * 16);\r\n\r\n LineHeight = PRIM_LINE_H * 4;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 128, 0);\r\n EVE_CoDl_lineWidth(s_pHalContext, (PRIM_LINE_W * 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 2 / 4) * 16, ((s_pHalContext->Height - LineHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 2 / 4) * 16, ((s_pHalContext->Height + LineHeight) / 2) * 16);\r\n\r\n LineHeight = PRIM_LINE_H * 10;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 128);\r\n EVE_CoDl_lineWidth(s_pHalContext, (PRIM_LINE_W * 4) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 3 / 4) * 16, ((s_pHalContext->Height - LineHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 3 / 4) * 16, ((s_pHalContext->Height + LineHeight) / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display rectangles on screen\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_rectangles()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Rectangles\");\r\n\r\n int16_t RectWidth;\r\n int16_t RectHeight;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n RectWidth = PRIM_RECT_W;\r\n RectHeight = PRIM_RECT_H;\r\n EVE_CoDl_colorRgb(s_pHalContext, 128, 0, 0);\r\n EVE_CoDl_lineWidth(s_pHalContext, PRIM_LINE_W * 16); //LINE_WIDTH is used for corner curvature\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width / 4) - (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height - RectHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width / 4) + (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height + RectHeight) / 2) * 16);\r\n\r\n RectWidth = PRIM_RECT_W * 2;\r\n RectHeight = PRIM_RECT_H * 2;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 128, 0);\r\n EVE_CoDl_lineWidth(s_pHalContext, (PRIM_LINE_W * 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width * 2 / 4) - (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height - RectHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width * 2 / 4) + (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height + RectHeight) / 2) * 16);\r\n\r\n RectWidth = PRIM_RECT_W * 4;\r\n RectHeight = PRIM_RECT_H * 4;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 128);\r\n EVE_CoDl_lineWidth(s_pHalContext, (PRIM_LINE_W * 8) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width * 3 / 4) - (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height - RectHeight) / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width * 3 / 4) + (RectWidth / 2)) * 16,\r\n ((s_pHalContext->Height + RectHeight) / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display image at different locations with various colors, -ve offsets, alpha blend\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_bitmap()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Display image\");\r\n\r\n uint16_t x, y;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_Util_loadImageFile(s_pHalContext, PRIM_BITMAP_LOAD, TEST_DIR PRIM_BITMAP, NULL, OPT_RGB565);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS); // start drawing bitmaps\r\n x = ((s_pHalContext->Width / 4) - (PRIM_BITMAP_W / 2));\r\n y = ((s_pHalContext->Height / 2) - (PRIM_BITMAP_H / 2));\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 64, 64); // red\r\n x = ((s_pHalContext->Width * 2 / 4) - (PRIM_BITMAP_W / 2));\r\n y = ((s_pHalContext->Height / 2) - (PRIM_BITMAP_H / 2));\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 64, 180, 64); // green\r\n x += (PRIM_BITMAP_W / 2);\r\n y += (PRIM_BITMAP_H / 2);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 64); // transparent yellow\r\n EVE_CoDl_colorA(s_pHalContext, 150);\r\n x += (PRIM_BITMAP_W / 2);\r\n y += (PRIM_BITMAP_H / 2);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_BITMAP_LOC * 16, PRIM_BITMAP_LOC * 16); //for -ve coordinates use vertex2f instruction\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display a Bar Graph\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_barGraph()\r\n{\r\n /* Write the data into RAM_G */\r\n uint8_t Y_Array[PRIM_BARGRAPH_ARRAY_SIZE];\r\n uint32_t numchunks = 0;\r\n int32_t String_size;\r\n uint32_t hoffset = 0;\r\n uint32_t voffset = 0;\r\n uint32_t widthaligh;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Display a Bar Graph\");\r\n\r\n hoffset = s_pHalContext->Width / 4;\r\n voffset = (s_pHalContext->Height - PRIM_BARGRAPH_H) / 2; //centre of the screen\r\n\r\n // Draw 1/4 of screen width, and zoom to 2 times larger\r\n widthaligh = ALIGN_TWO_POWER_N(s_pHalContext->Width / 2, PRIM_BARGRAPH_ARRAY_SIZE);\r\n numchunks = widthaligh / PRIM_BARGRAPH_ARRAY_SIZE;\r\n String_size = PRIM_BARGRAPH_ARRAY_SIZE;\r\n for (uint32_t j = 0; j < numchunks; j++)\r\n {\r\n for (int i = 0; i < PRIM_BARGRAPH_ARRAY_SIZE; i++)\r\n {\r\n Y_Array[i] = random(128) + 64; //within range\r\n }\r\n EVE_Hal_wrMem(s_pHalContext, PRIM_BITMAP_LOAD + j * PRIM_BARGRAPH_ARRAY_SIZE, &Y_Array[0],\r\n String_size);\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 128, 0, 0 }, 0, 4);\r\n EVE_CoDl_bitmapSource(s_pHalContext, PRIM_BITMAP_LOAD);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, BARGRAPH, PRIM_BARGRAPH_W, 1);\r\n EVE_CoDl_bitmapSize(s_pHalContext, NEAREST, BORDER, BORDER, PRIM_BARGRAPH_W, PRIM_BARGRAPH_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n /* Display text 8x8 at hoffset, voffset location */\r\n for (uint32_t i = 0; i < numchunks; i++)\r\n {\r\n EVE_CoDl_cell(s_pHalContext, i);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n hoffset += PRIM_BARGRAPH_ARRAY_SIZE;\r\n }\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n /* drawing of sine wave with rising amplitude */\r\n String_size = PRIM_BARGRAPH_ARRAY_SIZE;\r\n for (uint32_t j = 0; j < numchunks; j++)\r\n {\r\n for (int i = 0; i < PRIM_BARGRAPH_ARRAY_SIZE; i++)\r\n {\r\n int32_t tmpval;\r\n int16_t tmpidx;\r\n tmpidx = (int16_t)(i + j * PRIM_BARGRAPH_ARRAY_SIZE);\r\n tmpval = 128 + ((tmpidx / 4) * Math_Qsin(65536 * tmpidx / 48) / 65536); //within range\r\n\r\n Y_Array[i] = tmpval & 0xff;\r\n }\r\n EVE_Hal_wrMem(s_pHalContext, PRIM_BITMAP_LOAD + j * PRIM_BARGRAPH_ARRAY_SIZE, Y_Array, String_size);\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_bitmapSource(s_pHalContext, PRIM_BITMAP_LOAD);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, BARGRAPH, PRIM_BARGRAPH_W, 1);\r\n EVE_CoDl_bitmapSize(s_pHalContext, NEAREST, BORDER, BORDER, PRIM_BARGRAPH_W, PRIM_BARGRAPH_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n\r\n /* Display bargraph at hoffset, voffset location */\r\n voffset = (s_pHalContext->Height - PRIM_BARGRAPH_H) / 2; //centre of the screen\r\n hoffset = s_pHalContext->Width / 4;\r\n for (uint32_t i = 0; i < numchunks; i++)\r\n {\r\n EVE_CoDl_colorRgb(s_pHalContext, 0xff, 0, 0);\r\n EVE_CoDl_cell(s_pHalContext, i);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, (voffset + 4) * 16);\r\n hoffset += PRIM_BARGRAPH_ARRAY_SIZE;\r\n }\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display Linestrips\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_lineStrips()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Linestrips\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 168, 64 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, LINE_STRIP);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_STRIP_X1 * 16, PRIM_STRIP_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 2 / 3) * 16, (s_pHalContext->Height * 2 / 3) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - PRIM_STRIP_X2) * 16, (s_pHalContext->Height - PRIM_STRIP_Y1) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display Edgestrips\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_edgeStrips()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Edgestrips\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 168, 64 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, EDGE_STRIP_R);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_STRIP_X1 * 16, PRIM_STRIP_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 2 / 3) * 16, (s_pHalContext->Height * 2 / 3) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - PRIM_STRIP_X2) * 16, (s_pHalContext->Height - PRIM_STRIP_Y1) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Scissor sample\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_scissor()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Scissor\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorXY(s_pHalContext, PRIM_SCISSOR_X, PRIM_SCISSOR_Y); // Scissor rectangle top left\r\n EVE_CoDl_scissorSize(s_pHalContext, PRIM_SCISSOR_W, PRIM_SCISSOR_H); // Scissor rectangle is 400 x 400 pixels\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 255, 255, 0); // Clear to yellow\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Stencil sample\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_stencil()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Stencil\");\r\n\r\n int16_t PointSize = PRIM_POINT_SIZE * 4;\r\n int16_t DispBtwPoints = PRIM_POINT_SIZE * 5;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_stencilOp(s_pHalContext, INCR, INCR);\r\n EVE_CoDl_pointSize(s_pHalContext, PointSize * 16);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 128);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width - DispBtwPoints) / 2) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, ((s_pHalContext->Width + DispBtwPoints) / 2) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_stencilFunc(s_pHalContext, EQUAL, 2, 255);\r\n EVE_CoDl_colorRgb(s_pHalContext, 128, 0, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display Polygons\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_polygon()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Polygons\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 0, 0 }, 0, 4);\r\n EVE_CoDl_stencilOp(s_pHalContext, INCR, INCR);\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 0); //mask all the colors\r\n EVE_CoDl_begin(s_pHalContext, EDGE_STRIP_L);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2) * 16, (s_pHalContext->Height / 4) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 4 / 5) * 16, (s_pHalContext->Height * 4 / 5) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 4) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2) * 16, (s_pHalContext->Height / 4) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1); //enable all the colors\r\n EVE_CoDl_stencilFunc(s_pHalContext, EQUAL, 1, 255);\r\n EVE_CoDl_begin(s_pHalContext, EDGE_STRIP_L);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, s_pHalContext->Width * 16, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, s_pHalContext->Width * 16, s_pHalContext->Height * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* Draw lines at the borders to make sure anti aliazing is also done */\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 0, 255);\r\n EVE_CoDl_lineWidth(s_pHalContext, 2 * 16);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2) * 16, (s_pHalContext->Height / 4) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 4 / 5) * 16, (s_pHalContext->Height * 4 / 5) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width * 4 / 5) * 16, (s_pHalContext->Height * 4 / 5) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 4) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 4) * 16, (s_pHalContext->Height / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2) * 16, (s_pHalContext->Height / 4) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Display a cube\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_cube()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: cube\");\r\n\r\n uint32_t points[6 * 5][2], x, y, i, z;\r\n int16_t xoffset, yoffset, CubeEdgeSz;\r\n\r\n // color vertices\r\n uint8_t colors[6][3] = { 255,0,0,\r\n 255,128,0,\r\n 255,255,0,\r\n 0,255,0,\r\n 0,0,255,\r\n 128,0,255\r\n };\r\n\r\n // Cube dimention is of 200*200*200\r\n CubeEdgeSz = PRIM_CUBE_SIZE;\r\n xoffset = (s_pHalContext->Width / 2 - CubeEdgeSz); \r\n yoffset = ((s_pHalContext->Height - CubeEdgeSz) / 2);\r\n x = (xoffset + (CubeEdgeSz / 2)); // xoff+w/2\r\n y = (yoffset - (CubeEdgeSz / 2)); // yoff-h/2\r\n\r\n //yz plane (back)\r\n points[0][0] = x;\r\n points[0][1] = y;\r\n points[1][0] = x;\r\n points[1][1] = y + CubeEdgeSz;\r\n points[2][0] = x + CubeEdgeSz;\r\n points[2][1] = y + CubeEdgeSz;\r\n points[3][0] = x + CubeEdgeSz;\r\n points[3][1] = y;\r\n points[4][0] = x;\r\n points[4][1] = y;\r\n\r\n //yz plane (left)\r\n points[5][0] = xoffset;\r\n points[5][1] = yoffset;\r\n points[6][0] = x;\r\n points[6][1] = y;\r\n points[7][0] = x;\r\n points[7][1] = y + CubeEdgeSz;\r\n points[8][0] = xoffset;\r\n points[8][1] = yoffset + CubeEdgeSz;\r\n points[9][0] = xoffset;\r\n points[9][1] = yoffset;\r\n\r\n //xz plane(top)\r\n points[10][0] = xoffset;\r\n points[10][1] = yoffset;\r\n points[11][0] = xoffset + CubeEdgeSz;\r\n points[11][1] = yoffset;\r\n points[12][0] = x + CubeEdgeSz;\r\n points[12][1] = y;\r\n points[13][0] = x;\r\n points[13][1] = y;\r\n points[14][0] = xoffset;\r\n points[14][1] = yoffset;\r\n\r\n //xz plane(bottom)\r\n points[15][0] = xoffset;\r\n points[15][1] = yoffset + CubeEdgeSz;\r\n points[16][0] = xoffset + CubeEdgeSz;\r\n points[16][1] = yoffset + CubeEdgeSz;\r\n points[17][0] = x + CubeEdgeSz;\r\n points[17][1] = y + CubeEdgeSz;\r\n points[18][0] = x;\r\n points[18][1] = y + CubeEdgeSz;\r\n points[19][0] = xoffset;\r\n points[19][1] = yoffset + CubeEdgeSz;\r\n\r\n //yz plane (right)\r\n points[20][0] = xoffset + CubeEdgeSz;\r\n points[20][1] = yoffset + CubeEdgeSz;\r\n points[21][0] = x + CubeEdgeSz;\r\n points[21][1] = y + CubeEdgeSz;\r\n points[22][0] = x + CubeEdgeSz;\r\n points[22][1] = y;\r\n points[23][0] = xoffset + CubeEdgeSz;\r\n points[23][1] = yoffset;\r\n points[24][0] = xoffset + CubeEdgeSz;\r\n points[24][1] = yoffset + CubeEdgeSz;\r\n\r\n // xy plane(front)\r\n points[25][0] = xoffset;\r\n points[25][1] = yoffset;\r\n points[26][0] = xoffset + CubeEdgeSz;\r\n points[26][1] = yoffset;\r\n points[27][0] = xoffset + CubeEdgeSz;\r\n points[27][1] = yoffset + CubeEdgeSz;\r\n points[28][0] = xoffset;\r\n points[28][1] = yoffset + CubeEdgeSz;\r\n points[29][0] = xoffset;\r\n points[29][1] = yoffset;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n\r\n // Draw a cube\r\n EVE_CoDl_stencilOp(s_pHalContext, INCR, INCR);\r\n EVE_CoDl_colorA(s_pHalContext, 192);\r\n for (z = 0; z < 6; z++)\r\n {\r\n EVE_CoDl_clear(s_pHalContext, 0, 1, 1);//clear stencil buffer\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 0);//mask all the colors and draw one surface\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 0, 255);//stencil function to increment all the values\r\n EVE_CoDl_begin(s_pHalContext, EDGE_STRIP_L);\r\n for (i = 0; i < 5; i++)\r\n {\r\n EVE_CoDl_vertex2f_4(s_pHalContext, points[z * 5 + i][0] * 16, points[z * 5 + i][1] * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n /* set the color and draw a strip */\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1);\r\n EVE_CoDl_stencilFunc(s_pHalContext, EQUAL, 1, 255);\r\n EVE_CoDl_colorRgb(s_pHalContext, colors[z][0], colors[z][1], colors[z][2]);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, xoffset * 16, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xoffset + CubeEdgeSz * 2) * 16, (yoffset + CubeEdgeSz * 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n }\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief draw points followed by lines to create 3d ball kind of effect\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_ballStencil()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Display a ball\");\r\n\r\n int32_t xball = (s_pHalContext->Width / 2);\r\n int32_t yball = (s_pHalContext->Height / 2);\r\n int32_t rball = PRIM_BALL_SIZE;\r\n int32_t asize;\r\n int32_t aradius;\r\n int32_t gridsize = PRIM_BALL_SIZE / 2;\r\n int32_t asmooth;\r\n int32_t loopflag = PRIM_LOOP;\r\n int32_t displ = PRIM_BALL_EDGE;\r\n int32_t dispr = (s_pHalContext->Width - displ);\r\n int32_t dispa = PRIM_BALL_EDGE;\r\n int32_t dispb = (s_pHalContext->Height - dispa);\r\n int32_t xflag = 1;\r\n int32_t yflag = 1;\r\n\r\n dispr -= ((dispr - displ) % gridsize);\r\n dispb -= ((dispb - dispa) % gridsize);\r\n /* write the play sound */\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_SOUND, PRIM_BALL_SOUND);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_SOUND, PRIM_BALL_VOL);\r\n while (loopflag-- )\r\n {\r\n if (((xball + rball + PRIM_BALL_SPEED_X) >= dispr) || ((xball - rball - PRIM_BALL_SPEED_X) <= displ))\r\n {\r\n xflag ^= 1;\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAY, 1);\r\n }\r\n if (((yball + rball + PRIM_BALL_SPEED_Y) >= dispb) || ((yball - rball - PRIM_BALL_SPEED_Y) <= dispa))\r\n {\r\n yflag ^= 1;\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAY, 1);\r\n }\r\n if (xflag)\r\n {\r\n xball += PRIM_BALL_SPEED_X;\r\n }\r\n else\r\n {\r\n xball -= PRIM_BALL_SPEED_X;\r\n }\r\n if (yflag)\r\n {\r\n yball += PRIM_BALL_SPEED_Y;\r\n }\r\n else\r\n {\r\n yball -= PRIM_BALL_SPEED_Y;\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 128, 128, 0 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n /* draw grid */\r\n EVE_CoDl_lineWidth(s_pHalContext, 2 * 16);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n for (int i = 0; i <= ((dispr - displ) / gridsize); i++)\r\n {\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (displ + i * gridsize) * 16, dispa * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (displ + i * gridsize) * 16, dispb * 16);\r\n }\r\n for (int i = 0; i <= ((dispb - dispa) / gridsize); i++)\r\n {\r\n EVE_CoDl_vertex2f_4(s_pHalContext, displ * 16, (dispa + i * gridsize) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, dispr * 16, (dispa + i * gridsize) * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 0); //mask all the colors\r\n EVE_CoDl_pointSize(s_pHalContext, rball * 16);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, xball * 16, yball * 16);\r\n EVE_CoDl_stencilOp(s_pHalContext, INCR, ZERO);\r\n EVE_CoDl_stencilFunc(s_pHalContext, GEQUAL, 1, 255);\r\n /* one side points */\r\n\r\n for (int i = 1; i <= PRIM_BALL_POINT_NUM; i++)\r\n {\r\n asize = i * rball * 2 / (PRIM_BALL_POINT_NUM + 1);\r\n asmooth = (int16_t) helperSmoothLerp(((float) (1.0 * asize / (2 * rball))), 0,\r\n (float) (2 * rball));\r\n\r\n if (asmooth > rball)\r\n {\r\n //change the offset to -ve\r\n int32_t tempsmooth;\r\n tempsmooth = asmooth - rball;\r\n aradius = (rball * rball + tempsmooth * tempsmooth) / (2 * tempsmooth);\r\n EVE_CoDl_pointSize(s_pHalContext, aradius * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xball - aradius + tempsmooth) * 16, yball * 16);\r\n }\r\n else\r\n {\r\n int32_t tempsmooth;\r\n tempsmooth = rball - asmooth;\r\n aradius = (rball * rball + tempsmooth * tempsmooth) / (2 * tempsmooth);\r\n EVE_CoDl_pointSize(s_pHalContext, aradius * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xball + aradius - tempsmooth) * 16, yball * 16);\r\n }\r\n }\r\n\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n /* draw lines - line should be at least radius diameter */\r\n for (int i = 1; i <= PRIM_BALL_LINE_NUM; i++)\r\n {\r\n asize = (i * rball * 2 / PRIM_BALL_LINE_NUM);\r\n asmooth = (int16_t) helperSmoothLerp(((float) (1.0 * asize / (2 * rball))), 0,\r\n (float) (2 * rball));\r\n EVE_CoDl_lineWidth(s_pHalContext, asmooth * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xball - rball) * 16, (yball - rball) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xball + rball) * 16, (yball - rball) * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1); // enable all the colors\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 1, 255);\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, KEEP);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_pointSize(s_pHalContext, rball * 16);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0); //shadow\r\n EVE_CoDl_colorA(s_pHalContext, 160);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xball + PRIM_BALL_SHADOW_X) * 16, (yball + PRIM_BALL_SHADOW_Y) * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, xball * 16, yball * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0);\r\n EVE_CoDl_stencilFunc(s_pHalContext, GEQUAL, 1, 1);\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, KEEP);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, xball * 16, yball * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n EVE_sleep(10);\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Additive blending of points\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_additiveBlendPoints()\r\n{\r\n int32_t hoffset;\r\n int32_t hoffsetdiff;\r\n int32_t voffset;\r\n int32_t flagloop = PRIM_LOOP / 10;\r\n int32_t hdiff;\r\n int32_t vdiff;\r\n int32_t PointSz;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Additive blending of points\");\r\n\r\n#define MSVC_PI (3.141592653)\r\n PointSz = s_pHalContext->Width / 100;\r\n hoffsetdiff = s_pHalContext->Width / 160;\r\n while (flagloop--)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 20, 91, 20 }, 0, 4);\r\n EVE_CoDl_blendFunc(s_pHalContext, SRC_ALPHA, DST_ALPHA); //input is source alpha and destination is whole color\r\n EVE_CoDl_pointSize(s_pHalContext, PointSz * 16);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n\r\n /* First 100 random values */\r\n for (int i = 0; i < 100; i++)\r\n {\r\n hoffset = random(s_pHalContext->Width);\r\n voffset = random(s_pHalContext->Height);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n }\r\n\r\n /* next 800 are sine values of two cycles */\r\n for (int i = 0; i < 160; i++)\r\n {\r\n /* i is x offset, y is sinwave */\r\n hoffset = i * hoffsetdiff;\r\n\r\n voffset = (s_pHalContext->Height / 2)\r\n + ((int32_t) (s_pHalContext->Height / 2)\r\n * Math_Qsin((uint16_t) (65536 * i / (s_pHalContext->Width / 6)) / 65536));\r\n\r\n EVE_CoDl_vertex2f_4(s_pHalContext, hoffset * 16, voffset * 16);\r\n for (int j = 0; j < 4; j++)\r\n {\r\n hdiff = random(PointSz * 10) - (PointSz * 5);\r\n vdiff = random(PointSz * 10) - (PointSz * 5);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (hoffset + hdiff) * 16, (voffset + vdiff) * 16);\r\n }\r\n }\r\n\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n EVE_sleep(PRIM_DELAY_MS);\r\n\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief usage of additive blending - draw 3 Gs\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_additiveBlendText()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Additive blending\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, PRIM_TEXT_X, PRIM_TEXT_Y, 33, 0, \"Bridgetek\");\r\n EVE_CoDl_colorA(s_pHalContext, 128);\r\n EVE_CoCmd_text(s_pHalContext, PRIM_TEXT_X + PRIM_TEXT_INC, PRIM_TEXT_X + PRIM_TEXT_INC, 33, 0, \"Bridgetek\");\r\n EVE_CoDl_colorA(s_pHalContext, 64);\r\n EVE_CoCmd_text(s_pHalContext, PRIM_TEXT_X + 2 * PRIM_TEXT_INC, PRIM_TEXT_X + 2 * PRIM_TEXT_INC, 33, 0, \"Bridgetek\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate for CMD_CALIBRATESUB\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_calibratesub()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: CMD_CALIBRATESUB\");\r\n\r\n uint16_t clb_x = PRIM_CAL_X;\r\n uint16_t clb_y = PRIM_CAL_Y;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_Util_loadImageFile(s_pHalContext, PRIM_BITMAP_LOAD, TEST_DIR PRIM_BITMAP_CAL, NULL, OPT_TRUECOLOR);\r\n //Start drawing bitmap\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 255);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, clb_y + s_pHalContext->Height / 2, PRIM_TITLE_FONT, OPT_CENTER,\r\n \"Please touch on screen\");\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, 0xb90007);\r\n EVE_CoCmd_calibrateSub(s_pHalContext, clb_x, clb_y, (uint16_t)(s_pHalContext->Width / 2), (uint16_t)(s_pHalContext->Height / 2), 0);\r\n\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_TESTCARD\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_testcard()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: CMD_TESTCARD\");\r\n\r\n EVE_CoCmd_testCard(s_pHalContext);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Simple graph\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_simpleMap()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: A simple map\");\r\n EVE_CoCmd_dlStart(s_pHalContext);\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 236, 232, 224); //light gray #1\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1); //#2\r\n EVE_CoDl_colorRgb(s_pHalContext, 170, 157, 136); //medium gray #3\r\n EVE_CoDl_lineWidth(s_pHalContext, PRIM_MAP_LINE_W1 * 16); //#4\r\n EVE_CoDl_call(s_pHalContext, 37); //draw the streets //#5\r\n EVE_CoDl_colorRgb(s_pHalContext, 250, 250, 250); //white //#6\r\n EVE_CoDl_lineWidth(s_pHalContext, PRIM_MAP_LINE_W2 * 16); //#7\r\n EVE_CoDl_call(s_pHalContext, 37); //draw the streets //#8\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0); //#9\r\n EVE_CoCmd_text(s_pHalContext, PRIM_TITLE_X, PRIM_TITLE_Y, PRIM_TITLE_FONT, 0, \"Main street\");\r\n EVE_CoDl_display(s_pHalContext);\r\n\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X1 * 16, PRIM_MAP_LINE_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 1 / 20 * 16, PRIM_MAP_LINE_Y2 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 3 / 10 * 16, PRIM_MAP_LINE_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 7 / 20 * 16, PRIM_MAP_LINE_Y2 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 6 / 10 * 16, PRIM_MAP_LINE_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 13 / 20 * 16, PRIM_MAP_LINE_Y2 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 8 / 10 * 16, PRIM_MAP_LINE_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 17 / 20 * 16, PRIM_MAP_LINE_Y2 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 9 / 10 * 16, PRIM_MAP_LINE_Y1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 19 / 20 * 16, PRIM_MAP_LINE_Y2 * 16);\r\n\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X2 * 16, PRIM_MAP_LINE_Y2 * 2 / 10 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 16, PRIM_MAP_LINE_Y2 * 1 / 10 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X2 * 16, PRIM_MAP_LINE_Y2 * 6 / 10 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 16, PRIM_MAP_LINE_Y2 * 5 / 10 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X2 * 16, PRIM_MAP_LINE_Y2 * 10 / 10 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, PRIM_MAP_LINE_X3 * 16, PRIM_MAP_LINE_Y2 * 9 / 10 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_return(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate the use of region commands\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives_region()\r\n{\r\n#define ENABLE_REGION 1\r\n Draw_Text(s_pHalContext, \"Example for: region\");\r\n int32_t y;\r\n char string[10];\r\n uint16_t yoffset = 100;\r\n uint32_t m, p, q;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 55, 0 }, (uint8_t[]) { 200, 200, 200 }, 0, 4);\r\n for (uint8_t i = 0; i < 37; i++)\r\n {\r\n y = (int32_t)(s_pHalContext->Height * i / 64);\r\n if (i % 4 == 0)\r\n {\r\n string[0] = '\\0';\r\n Gpu_Hal_Dec2Ascii(string, sizeof(string), (int32_t) i);\r\n EVE_CoCmd_text(s_pHalContext, PRIM_REGION_X, y, PRIM_TITLE_FONT, OPT_CENTERY | OPT_RIGHTX, string);\r\n string[0] = '\\0';\r\n Gpu_Hal_Dec2Ascii(string, sizeof(string), y);\r\n EVE_CoCmd_text(s_pHalContext, PRIM_REGION_W - PRIM_REGION_X, y, PRIM_TITLE_FONT, OPT_CENTERY, string);\r\n EVE_CoDl_lineWidth(s_pHalContext, 16);\r\n }\r\n else\r\n EVE_CoDl_lineWidth(s_pHalContext, 8);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (PRIM_REGION_X + PRIM_REGION_TEXT_W) * 16, y * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (PRIM_REGION_W - PRIM_REGION_X + PRIM_REGION_TEXT_W) * 16, y * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n }\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CMD_DL, &m);\r\n\r\n EVE_CoDl_scissorSize(s_pHalContext, PRIM_REGION_SCISSOR_W, PRIM_REGION_H);\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 0, 128, 128);\r\n EVE_CoDl_scissorXY(s_pHalContext, PRIM_REGION_X * 3, yoffset);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CMD_DL, &p);\r\n\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoDl_clearColorRgb(s_pHalContext, 255, 165, 0);\r\n EVE_CoDl_scissorXY(s_pHalContext, PRIM_REGION_X * 5, yoffset);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n\r\n#if ENABLE_REGION\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CMD_DL, &q);\r\n EVE_CoCmd_memWrite(s_pHalContext, RAM_DL + p, 4);\r\n EVE_CoDl_region(s_pHalContext, 8, 4, q/4); // 8 * 1200 / 64 = 150, (8+4) * 1200 / 64 = 225, so region is from y:150 to y:225\r\n#endif\r\n\r\n EVE_CoDl_scissorXY(s_pHalContext, PRIM_REGION_X * 7, yoffset);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all primitive demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Primitives()\r\n{\r\n SAMAPP_Primitives_points();\r\n SAMAPP_Primitives_lines();\r\n SAMAPP_Primitives_rectangles();\r\n SAMAPP_Primitives_bitmap();\r\n SAMAPP_Primitives_barGraph();\r\n SAMAPP_Primitives_lineStrips();\r\n SAMAPP_Primitives_edgeStrips();\r\n SAMAPP_Primitives_scissor();\r\n SAMAPP_Primitives_stencil();\r\n SAMAPP_Primitives_polygon();\r\n SAMAPP_Primitives_cube();\r\n SAMAPP_Primitives_ballStencil();\r\n SAMAPP_Primitives_additiveBlendPoints();\r\n SAMAPP_Primitives_additiveBlendText();\r\n SAMAPP_Primitives_calibratesub();\r\n SAMAPP_Primitives_testcard();\r\n SAMAPP_Primitives_simpleMap();\r\n SAMAPP_Primitives_region();\r\n}\r\n\r\n\r\n"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"sample_id": "sampleapp_touch",
|
|
52
|
+
"relative_path": "SampleApp/Touch/Src/Touch.c",
|
|
53
|
+
"ext": ".c",
|
|
54
|
+
"content": "/**\r\n * @file Touch.c\r\n * @brief Sample usage of touching\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Touch.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define TOUCH_BITMAP_LOAD RAM_G\r\n#define TOUCH_LOOP 1500\r\n#define TOUCH_DELAY_MS 5\r\n#define TOUCH_TITLE_FONT 31\r\n#define TOUCH_TITLE_Y 50\r\n#define TOUCH_TITLE_Y_INC 50\r\n#define TOUCH_RECT_X 200\r\n#define TOUCH_RECT_Y 100\r\n#define TOUCH_RECT_W 100\r\n#define TOUCH_RECT_H (s_pHalContext->Height / 2)\r\n#define TOUCH_MRECT_H 5\r\n#define TOUCH_RECT_INC 1\r\n#define TOUCH_CIRCLE_R 100\r\n#define TOUCH_CIRCLE_X 650\r\n#define TOUCH_CIRCLE_Y 200\r\n#define TOUCH_CIRCLE_R_INC 80\r\n#define TOUCH_CIRCLE_TOUCH_R 50\r\n#define TOUCH_CIRCLE_TOUCH_X 600\r\n#define TOUCH_CIRCLE_TOUCH_Y 200\r\n#define TOUCH_CIRCLE_COL_NO 10\r\n#define TOUCH_CIRCLE_ROW_NO 10\r\n#define TOUCH_POINT_SZ 100\r\n#define TOUCH_MVPOINT_X 180\r\n#define TOUCH_MVPOINT_Y 20\r\n#define TOUCH_MVPOINT_SZ 50\r\n#define TOUCH_TRACKER_TAG_R 100\r\n#define TOUCH_TRACKER_TAG_G 101\r\n#define TOUCH_TRACKER_TAG_B 102\r\n#define TOUCH_TRACKER_TAG_A 103\r\n#define TOUCH_TRACKER_DIAL_W (s_pHalContext->Width / 10)\r\n#define TOUCH_TRACKER_DIAL_EDGE 20\r\n#define TOUCH_TRACKER_RECT_W (s_pHalContext->Width / 3)\r\n#define TOUCH_TRACKER_RECT_H (s_pHalContext->Height / 2)\r\n#define TOUCH_OBJ_DIAL_TAG 10\r\n#define TOUCH_OBJ_H_TAG 11\r\n#define TOUCH_OBJ_V_TAG 12\r\n#define TOUCH_OBJ_DIAL_R (s_pHalContext->Width / 8)\r\n#define TOUCH_OBJ_SLIDE_EDGE 100\r\n#define TOUCH_OBJ_SLIDE_W 20\r\n#define TOUCH_OBJ_H_TEXT_Y (s_pHalContext->Height - TOUCH_TITLE_Y_INC)\r\n#define TOUCH_OBJ_V_TEXT_X (s_pHalContext->Width - 150)\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Touch();\r\nstatic int32_t Volume;\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n {\r\n eve_printf_debug(\"load patch failed\\n\");\r\n return 1;\r\n }\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n#ifdef VM820B10A\r\n EVE_Hal_wr32(s_pHalContext, REG_TOUCH_CONFIG, 0x414);\r\n#endif\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of touch\", \r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Touch();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n/**\r\n * @brief touch test\r\n *\r\n * @param Sq Square positions\r\n * @param TouchXY TouchXY value\r\n * @param TouchNo Touch number order\r\n * @return None\r\n */\r\nstatic void helperDrawTouchPt(SAMAPP_Squares *Sq, int32_t TouchXY, uint8_t TouchNo)\r\n{\r\n if (TouchXY != 0x80008000)\r\n {\r\n Sq->x = TouchXY >> 16;\r\n Sq->y = (TouchXY & 0xffff);\r\n Volume = (TouchNo + 1) * 255 / NO_OF_TOUCH;\r\n }\r\n else\r\n {\r\n Sq->x = OFFSCREEN;\r\n Sq->y = OFFSCREEN;\r\n }\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 0);\r\n EVE_CoCmd_setBitmap(s_pHalContext, TOUCH_BITMAP_LOAD, YCBCR, TOUCH_BITMAP_W, TOUCH_BITMAP_H);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (Sq->x - TOUCH_BITMAP_W / 2) * 16, (Sq->y - TOUCH_BITMAP_H / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Calculate small rectangle and positions\r\n *\r\n * @param context BouncingSquares context\r\n * @param Arrayno Rectangle id\r\n * @return None\r\n */\r\nstatic void helperRectangleCalc(SAMAPP_BouncingSquares *context, uint8_t Arrayno)\r\n{\r\n if (context->RectTouched[Arrayno] == 1)\r\n {\r\n //the limits for the smaller rectangles forward and backward movement is set here\r\n if (context->My[Arrayno] <= 0)\r\n context->Decrease[Arrayno] = 0; //increase\r\n else if (context->My[Arrayno] + 10 * TOUCH_RECT_INC >= context->Ty[Arrayno])\r\n context->Decrease[Arrayno] = 1; //decrease\r\n\r\n // the smaller rectangles are moved accordingly according to the flags set above in this function call\r\n if (context->Decrease[Arrayno] == 1)\r\n context->My[Arrayno] -= TOUCH_RECT_INC; //the smaller rectangles are moved upwards\r\n else if (context->Decrease[Arrayno] == 0) // increase\r\n context->My[Arrayno] += 2 * TOUCH_RECT_INC; //the smaller rectangles are moved downwards slightly faster\r\n }\r\n}\r\n\r\n/**\r\n * @brief Check user touches\r\n *\r\n * @param context BouncingSquares context\r\n * @param val Multi touch value\r\n * @return None\r\n */\r\nstatic void helperCheckTouch(SAMAPP_BouncingSquares *context, int32_t val)\r\n{\r\n int8_t Arrayno = -1;\r\n\r\n if (val != 0x80008000)\r\n {\r\n uint16_t Tx = (val >> 16) & 0xffff;\r\n\r\n // Check which rectangle is being touched according to the coordinates\r\n if (Tx >= TOUCH_RECT_X && Tx <= (TOUCH_RECT_X + TOUCH_RECT_W))\r\n Arrayno = 0;\r\n if (Tx >= (2 * TOUCH_RECT_X) && Tx <= (2 * TOUCH_RECT_X + TOUCH_RECT_W))\r\n Arrayno = 1;\r\n if (Tx >= (3 * TOUCH_RECT_X) && Tx <= (3 * TOUCH_RECT_X + TOUCH_RECT_W))\r\n Arrayno = 2;\r\n if (Tx >= (4 * TOUCH_RECT_X) && Tx <= (4 * TOUCH_RECT_X + TOUCH_RECT_W))\r\n Arrayno = 3;\r\n if (Tx >= (5 * TOUCH_RECT_X) && Tx <= (5 * TOUCH_RECT_X + TOUCH_RECT_W))\r\n Arrayno = 4;\r\n\r\n if (Arrayno != -1)\r\n {\r\n context->RectTouched[Arrayno] = 1; // rectangle touched\r\n\r\n //store the touch point's Y-coordinate\r\n context->Ty[Arrayno] = (val & 0xffff);\r\n\r\n //Limit the height of the larger rectangle to reserve space for the smaller one\r\n if (context->Ty[Arrayno] <= TOUCH_RECT_Y)\r\n context->Ty[Arrayno] = TOUCH_RECT_Y;\r\n }\r\n }\r\n\r\n //According to the bigger rectangle values move the smaller rectangles\r\n for (int i = 0; i < NO_OF_RECTS; i++)\r\n {\r\n helperRectangleCalc(context, (uint8_t)i);\r\n }\r\n}\r\n\r\n/**\r\n * @brief Draw BouncingSquares\r\n *\r\n * @param BRx\r\n * @param BRy\r\n * @param MovingRy\r\n * @param SqNumber\r\n * @return None\r\n */\r\nstatic void helperDrawBouncingSquares(SAMAPP_BouncingSquares *context, int16_t *RectX)\r\n{\r\n int8_t R1 = 0;\r\n int8_t G1 = 0;\r\n int8_t B1 = 0;\r\n int8_t R2 = 0;\r\n int8_t G2 = 0;\r\n int8_t B2 = 0;\r\n\r\n for (int i = 0; i < NO_OF_RECTS; i++)\r\n {\r\n //different colours are set for the different rectangles\r\n if (i == 0)\r\n {\r\n R1 = 63;\r\n G1 = 72;\r\n B1 = 204;\r\n R2 = 0;\r\n G2 = 255;\r\n B2 = 255;\r\n }\r\n\r\n if (i == 1)\r\n {\r\n R1 = 255;\r\n G1 = 255;\r\n B1 = 0;\r\n R2 = 246;\r\n G2 = 89;\r\n B2 = 12;\r\n }\r\n\r\n if (i == 2)\r\n {\r\n R1 = 255;\r\n G1 = 0;\r\n B1 = 0;\r\n R2 = 200;\r\n G2 = 28;\r\n B2 = 36;\r\n }\r\n\r\n if (i == 3)\r\n {\r\n R1 = 131;\r\n G1 = 171;\r\n B1 = 9;\r\n R2 = 8;\r\n G2 = 100;\r\n B2 = 50;\r\n }\r\n\r\n if (i == 4)\r\n {\r\n R1 = 90;\r\n G1 = 40;\r\n B1 = 120;\r\n R2 = 177;\r\n G2 = 156;\r\n B2 = 217;\r\n }\r\n\r\n // Draw the rectanles here\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_lineWidth(s_pHalContext, TOUCH_MRECT_H * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, R1, G1, B1);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, RectX[i] * 16, (context->Ty[i]) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (RectX[i] + TOUCH_RECT_W) * 16, TOUCH_RECT_H * 16);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, R2, G2, B2);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, RectX[i] * 16, (context->My[i]) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (RectX[i] + TOUCH_RECT_W) * 16, (context->My[i] + TOUCH_MRECT_H) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n }\r\n}\r\n\r\n/**\r\n * @brief Draw plots\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void helperDrawPlotXY()\r\n{\r\n uint8_t i = 0;\r\n uint16_t PlotHt = 0;\r\n uint16_t PlotWth = 0;\r\n uint16_t X = 0;\r\n uint16_t Y = 0;\r\n\r\n PlotHt = (uint16_t)(s_pHalContext->Height / TOUCH_CIRCLE_ROW_NO);\r\n PlotWth = (uint16_t)(s_pHalContext->Width / TOUCH_CIRCLE_COL_NO);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 36, 54, 125);\r\n EVE_CoDl_begin(s_pHalContext, LINES);\r\n /* Horizontal Lines */\r\n for (i = 0; i < TOUCH_CIRCLE_ROW_NO; i++)\r\n {\r\n Y = (i + 1) * PlotHt;\r\n EVE_CoDl_lineWidth(s_pHalContext, 1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, Y * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, s_pHalContext->Width * 16, Y * 16);\r\n }\r\n /* Vertical Lines */\r\n for (i = 0; i < TOUCH_CIRCLE_COL_NO; i++)\r\n {\r\n X = (i + 1) * PlotWth;\r\n EVE_CoDl_lineWidth(s_pHalContext, 1 * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, X * 16, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, X * 16, s_pHalContext->Height * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief check which circle has been touched based on the coordinates\r\n *\r\n * @param context BouncingSquares context\r\n * @param val Touch value\r\n * @param TouchNum Touch number\r\n * @param i Circle number\r\n * @return None\r\n */\r\nstatic void helperCheckCircleTouchCood(SAMAPP_BouncingCircles *context, int32_t val, uint8_t TouchNum,\r\n uint8_t i)\r\n{\r\n float CX = (float)(val >> 16);\r\n float CY = (float)(val & 0xffff);\r\n\r\n if (val == 0x80008000)\r\n {\r\n context->TN[i] = 0xFF;\r\n return;\r\n }\r\n\r\n if (context->TN[i] != TouchNum \r\n && (CX > (context->CX[i] - TOUCH_CIRCLE_TOUCH_R)) && (CX < (context->CX[i] + TOUCH_CIRCLE_TOUCH_R)) \r\n && (CY > (context->CY[i] - TOUCH_CIRCLE_TOUCH_R)) && (CY < context->CY[i] + TOUCH_CIRCLE_TOUCH_R))\r\n {\r\n // small circle is touched, save the information\r\n context->CX[i] = CX;\r\n context->CY[i] = CY;\r\n context->TN[i] = TouchNum;\r\n }\r\n\r\n // update coordinate\r\n if (context->TN[i] == TouchNum)\r\n {\r\n context->CX[i] = CX;\r\n context->CY[i] = CY;\r\n }\r\n}\r\n\r\n/**\r\n * @brief calculate the radius of each circle according to the touch\r\n *\r\n * @param context BouncingSquares context\r\n * @param Val Circle number\r\n * @return None\r\n */\r\nstatic void helperCirclePlot(SAMAPP_BouncingCircles *context, uint8_t Val)\r\n{\r\n uint32_t Xsq;\r\n uint32_t Ysq;\r\n Xsq = (uint32_t)((uint16_t)context->CX[Val] - (s_pHalContext->Width / 2)) * ((uint16_t)context->CX[Val] - (s_pHalContext->Width / 2));\r\n Ysq = (uint32_t)((uint16_t)context->CY[Val] - (s_pHalContext->Height / 2)) * ((uint16_t)context->CY[Val] - (s_pHalContext->Height / 2));\r\n context->R[Val] = (float)(Xsq + Ysq);\r\n context->R[Val] = (float)sqrt(context->R[Val]);\r\n}\r\n\r\n/**\r\n * @brief Beginning BouncingCircle section\r\n *\r\n * @param C Point size\r\n * @return None\r\n */\r\nstatic void helperDrawConcentricCircles(float C)\r\n{\r\n EVE_CoDl_stencilFunc(s_pHalContext, NEVER, 0x00, 0x00);\r\n EVE_CoDl_stencilOp(s_pHalContext, INCR, INCR);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_pointSize(s_pHalContext, (uint16_t )((C - 5) * 16)); //inner circle\r\n EVE_CoDl_vertex2f_4(s_pHalContext, TOUCH_CIRCLE_X * 16, TOUCH_CIRCLE_Y * 16);\r\n\r\n EVE_CoDl_stencilFunc(s_pHalContext, NOTEQUAL, 0x01, 0x01);\r\n EVE_CoDl_pointSize(s_pHalContext, (uint16_t )((C) * 16)); //outer circle\r\n EVE_CoDl_vertex2f_4(s_pHalContext, TOUCH_CIRCLE_X * 16, TOUCH_CIRCLE_Y * 16);\r\n\r\n EVE_CoDl_stencilFunc(s_pHalContext, EQUAL, 0x01, 0x01);\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, KEEP);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0);\r\n EVE_CoDl_pointSize(s_pHalContext, (uint16_t )((C) * 16));\r\n EVE_CoDl_vertex2f_4(s_pHalContext, TOUCH_CIRCLE_X * 16, TOUCH_CIRCLE_Y * 16);\r\n\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 0x01, 0x01);\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, KEEP);\r\n\r\n EVE_CoDl_end(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Draw touch points\r\n *\r\n * @param CX Point X\r\n * @param CY Point Y\r\n * @param i Point number\r\n * @return None\r\n */\r\nstatic void helperDrawTouchPoints(int16_t CX, int16_t CY, uint8_t i)\r\n{\r\n /* Draw the five white circles for the Touch areas with their rescpective numbers*/\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_pointSize(s_pHalContext, TOUCH_CIRCLE_TOUCH_R * 16);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 0);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, CX * 16, CY * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 155, 155, 0);\r\n EVE_CoCmd_number(s_pHalContext, CX, CY, TOUCH_TITLE_FONT, OPT_CENTERX | OPT_CENTERY, i);\r\n}\r\n\r\n/**\r\n * @brief Beginning BouncingPoints section\r\n *\r\n * @param pBInst Blob instance\r\n * @param TouchXY Touch value\r\n * @return None\r\n */\r\nstatic void helperBlobColor(SAMAPP_BlobsInst *pBInst, int32_t TouchXY)\r\n{\r\n uint8_t j = 0;\r\n // if there is touch store the values\r\n if (TouchXY != 0x80008000)\r\n {\r\n pBInst->blobs[pBInst->CurrIdx].x = (TouchXY >> 16) & 0xffff;\r\n pBInst->blobs[pBInst->CurrIdx].y = (TouchXY & 0xffff);\r\n }\r\n else\r\n {\r\n pBInst->blobs[pBInst->CurrIdx].x = OFFSCREEN;\r\n pBInst->blobs[pBInst->CurrIdx].y = OFFSCREEN;\r\n }\r\n\r\n //calculate the current index\r\n pBInst->CurrIdx = (pBInst->CurrIdx + 1) & (NBLOBS - 1);\r\n\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_colorRgb(s_pHalContext, 60, 166, 117);\r\n for (uint8_t i = 0; i < NBLOBS; i++)\r\n {\r\n // Blobs fade away and swell as they age\r\n EVE_CoDl_colorA(s_pHalContext, i << 1);\r\n EVE_CoDl_pointSize(s_pHalContext, TOUCH_POINT_SZ + (i << 3));\r\n\r\n // Random color for each blob, keyed from (blob_i + i)\r\n j = (pBInst->CurrIdx + i) & (NBLOBS - 1);\r\n\r\n // Draw it!\r\n if (pBInst->blobs[j].x != OFFSCREEN)\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (pBInst->blobs[j].x) * 16, (pBInst->blobs[j].y) * 16);\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Beginning MovingPoints section\r\n *\r\n * @param k Touch number\r\n * @param i Point number\r\n * @return None\r\n */\r\nstatic void helperColorSelection(int16_t k, int16_t i)\r\n{\r\n if (k == 0)\r\n {\r\n if (i & 1)\r\n EVE_CoDl_colorRgb(s_pHalContext, 116, 27, 124); //purple\r\n else\r\n EVE_CoDl_colorRgb(s_pHalContext, 248, 134, 173); //pink\r\n }\r\n if (k == 1)\r\n {\r\n if (i & 1)\r\n EVE_CoDl_colorRgb(s_pHalContext, 232, 35, 25); //red\r\n else\r\n EVE_CoDl_colorRgb(s_pHalContext, 240, 135, 132); //light red\r\n }\r\n if (k == 2)\r\n {\r\n if (i & 1)\r\n EVE_CoDl_colorRgb(s_pHalContext, 248, 130, 58); //orange\r\n else\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 253, 85); //yellow\r\n }\r\n if (k == 3)\r\n {\r\n if (i & 1)\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 35, 245); //blue\r\n else\r\n EVE_CoDl_colorRgb(s_pHalContext, 115, 251, 253); //light blue\r\n }\r\n if (k == 4)\r\n {\r\n if (i & 1)\r\n EVE_CoDl_colorRgb(s_pHalContext, 55, 126, 71); //green\r\n else\r\n EVE_CoDl_colorRgb(s_pHalContext, 161, 251, 142); //light green\r\n }\r\n}\r\n\r\n/**\r\n * @brief Linear function\r\n *\r\n * @param p1\r\n * @param p2\r\n * @param t\r\n * @param rate\r\n * @return int16_t\r\n */\r\nstatic int16_t helperLinear(float p1, float p2, uint16_t t, uint16_t rate)\r\n{\r\n float st = (float)t / rate;\r\n return (int16_t)(p1 + (st * (p2 - p1)));\r\n}\r\n\r\n/**\r\n * @brief Calculate offset movements\r\n *\r\n * @param context MovingPpoints context\r\n * @return None\r\n */\r\nstatic void helperPointsCalc(SAMAPP_MovingPoints* context)\r\n{\r\n uint8_t touchNo = 0;\r\n uint16_t tempDeltaX;\r\n uint16_t tempDeltaY;\r\n\r\n /* For total number of points calculate the offsets of movement */\r\n for (int16_t k = 0; k < NO_OF_POINTS * NO_OF_TOUCH; k++)\r\n {\r\n touchNo = k / NO_OF_POINTS;\r\n if (context->t[k] > NO_OF_POINTS)\r\n {\r\n context->t[k] = 0;\r\n context->X[k] = (context->val[touchNo] >> 16) & 0xffff;\r\n context->Y[k] = (context->val[touchNo] & 0xffff);\r\n }\r\n if (context->X[k] != 0x8000)\r\n {\r\n tempDeltaX = helperLinear(context->X[k], context->StopX[touchNo], context->t[k], NO_OF_POINTS);\r\n tempDeltaY = helperLinear(context->Y[k], context->StopY, context->t[k], NO_OF_POINTS);\r\n helperColorSelection(touchNo, k);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, tempDeltaX * 16L, tempDeltaY * 16L);\r\n }\r\n context->t[k]++;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * @brief touch test with music play\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_touchToPlaySong()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Touch test\\n\\n\\nPlease touch on screen (1-5 fingers)\");\r\n uint32_t val[5];\r\n\r\n SAMAPP_Squares SqCall;\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, TOUCH_BITMAP_LOAD, TEST_DIR TOUCH_BITMAP);\r\n /*Audio*/\r\n EVE_Util_loadRawFile(s_pHalContext, TOUCH_BITMAP_LOAD + TOUCH_BITMAP_W * TOUCH_BITMAP_H * 2, TEST_DIR TOUCH_AUDIO);\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_FREQ, TOUCH_AUDIO_FREQ);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_START, TOUCH_BITMAP_LOAD + TOUCH_BITMAP_W * TOUCH_BITMAP_H * 2);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_FORMAT, TOUCH_AUDIO_FORMAT);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LENGTH, TOUCH_AUDIO_LENGTH);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 1);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_PLAY, 1);\r\n\r\n for (int j = 0; j < TOUCH_LOOP; j++)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), TOUCH_TITLE_Y, TOUCH_TITLE_FONT, OPT_CENTER,\r\n \"Touch to play song\"); //text info\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH0_XY, &val[0]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHA_XY, &val[1]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHB_XY, &val[2]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHC_XY, &val[3]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH4_XY, &val[4]);\r\n\r\n for (int8_t i = 0; i < NO_OF_TOUCH; i++)\r\n {\r\n helperDrawTouchPt(&SqCall, (int32_t)val[i], i);\r\n }\r\n if ((val[0] == 0x80008000) && (val[1] == 0x80008000) && (val[2] == 0x80008000)\r\n && (val[3] == 0x80008000) && (val[4] == 0x80008000))\r\n Volume = 0;\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, (uint8_t)Volume);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, (uint8_t)Volume);\r\n Display_End(s_pHalContext);\r\n }\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LENGTH, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_PLAY, 1);\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n#endif\r\n}\r\n\r\n/**\r\n * @brief touch test with bouncing squares\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_BouncingSquares()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n int16_t RectX[NO_OF_RECTS];\r\n int32_t Touchval[NO_OF_RECTS];\r\n\r\n SAMAPP_BouncingSquares context;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Draw Bouncing squares\\n\\n\\nPlease touch on screen (1-5 fingers)\");\r\n\r\n //Calculate the X vertices where the five rectangles have to be placed\r\n for (int i = 1; i < NO_OF_RECTS; i++)\r\n {\r\n RectX[0] = TOUCH_RECT_X;\r\n RectX[i] = RectX[i - 1] + 2 * TOUCH_RECT_W;\r\n }\r\n\r\n for (int i = 0; i < NO_OF_RECTS; i++)\r\n {\r\n context.Ty[i] = 0;\r\n context.My[i] = 0;\r\n context.RectTouched[i] = 0;\r\n context.Decrease[i] = 0;\r\n }\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n for (int k = 0; k < TOUCH_LOOP; k++)\r\n {\r\n /* first touch*/\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH0_XY, &Touchval[0]);\r\n /* second touch*/\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHA_XY, &Touchval[1]);\r\n /* third touch*/\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHB_XY, &Touchval[2]);\r\n /* fourth touch*/\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHC_XY, &Touchval[3]);\r\n /* fifth touch*/\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH4_XY, &Touchval[4]);\r\n\r\n //Check which rectangle is being touched using the coordinates and move the respective smaller rectangle\r\n for (int8_t i = 0; i < NO_OF_TOUCH; i++)\r\n {\r\n helperCheckTouch(&context, Touchval[i]);\r\n }\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n helperDrawBouncingSquares(&context, RectX);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(TOUCH_DELAY_MS);\r\n }\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n#endif\r\n}\r\n/* End BouncingSquares section */\r\n\r\n/**\r\n * @brief touch test with bouncing Circles\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_BouncingCircles()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n int32_t Touchval[NO_OF_CIRCLE];\r\n SAMAPP_BouncingCircles context;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Draw Bouncing Circles\\n\\n\\nPlease touch on screen (1-5 fingers)\");\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n /* calculate the intital radius of the circles before the touch happens*/\r\n for (int8_t i = 0; i < NO_OF_CIRCLE; i++)\r\n {\r\n context.R[i] = (float)(TOUCH_CIRCLE_R + i * TOUCH_CIRCLE_R_INC);\r\n context.CX[i] = (float)(TOUCH_CIRCLE_TOUCH_X - i * TOUCH_CIRCLE_TOUCH_R * 2);\r\n context.CY[i] = TOUCH_CIRCLE_TOUCH_Y;\r\n }\r\n\r\n for (int32_t k = 0; k < TOUCH_LOOP; k++)\r\n {\r\n /* values of the five touches are stored here */\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH0_XY, &Touchval[0]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHA_XY, &Touchval[1]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHB_XY, &Touchval[2]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHC_XY, &Touchval[3]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH4_XY, &Touchval[4]);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* The plot is drawn here */\r\n helperDrawPlotXY();\r\n\r\n /* check which circle has been touched based on the coordinates and store coordinate of the circle touched*/\r\n for (int8_t i = 0; i < NO_OF_CIRCLE; i++)\r\n {\r\n for (int8_t j = 0; j < NO_OF_TOUCH; j++)\r\n {\r\n helperCheckCircleTouchCood(&context, Touchval[j], j, i);\r\n }\r\n }\r\n /* calculate the radius of each circle according to the touch of each individual circle */\r\n for (int8_t i = 0; i < NO_OF_CIRCLE; i++)\r\n {\r\n helperCirclePlot(&context, i);\r\n }\r\n /* with the calculated radius draw the circles as well as the Touch points */\r\n for (int8_t i = 0; i < (NO_OF_CIRCLE); i++)\r\n {\r\n helperDrawConcentricCircles(context.R[i]);\r\n helperDrawTouchPoints((int16_t) context.CX[i], (int16_t) context.CY[i], i + 1);\r\n }\r\n\r\n Display_End(s_pHalContext);\r\n }\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n#endif // capacity EVE\r\n}\r\n/* End BouncingCircle section */\r\n\r\n/**\r\n * @brief touch test with Bouncing points\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_BouncingPoints()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n int32_t Touchval[NO_OF_TOUCH];\r\n SAMAPP_BlobsInst gBlobsInst[NO_OF_TOUCH];\r\n SAMAPP_BlobsInst* pBInst;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Draw Bouncing points\\n\\n\\nPlease touch on screen (1-5 fingers)\");\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n pBInst = &gBlobsInst[0];\r\n\r\n //set all coordinates to OFFSCREEN position\r\n for (uint8_t j = 0; j < NO_OF_TOUCH; j++)\r\n {\r\n for (uint8_t i = 0; i < NBLOBS; i++)\r\n {\r\n pBInst->blobs[i].x = OFFSCREEN;\r\n pBInst->blobs[i].y = OFFSCREEN;\r\n }\r\n pBInst->CurrIdx = 0;\r\n pBInst++;\r\n }\r\n\r\n for (uint16_t k = 0; k < TOUCH_LOOP; k++)\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH0_XY, &Touchval[0]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHA_XY, &Touchval[1]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHB_XY, &Touchval[2]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHC_XY, &Touchval[3]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH4_XY, &Touchval[4]);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 43, 73, 59 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_blendFunc(s_pHalContext, SRC_ALPHA, ONE);\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 0);\r\n\r\n // draw blobs according to the number of touches\r\n for (uint16_t j = 0; j < NO_OF_TOUCH; j++)\r\n {\r\n helperBlobColor(&gBlobsInst[j], Touchval[j]);\r\n }\r\n Display_End(s_pHalContext);\r\n }\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n#endif // capacity EVE\r\n}\r\n/* End BouncingPoints section */\r\n\r\n/**\r\n * @brief touch test with moving points\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_MovingPoints()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n SAMAPP_MovingPoints context;\r\n Draw_Text(s_pHalContext, \"Example for: Draw Moving points\\n\\n\\nPlease touch on screen (1-5 fingers)\");\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n /* Initialize all coordinates */\r\n for (uint16_t j = 0; j < NO_OF_TOUCH; j++)\r\n {\r\n for (uint16_t i = 0; i < NO_OF_POINTS; i++)\r\n {\r\n context.t[i + j * NO_OF_POINTS] = (uint8_t) i;\r\n context.X[i + j * NO_OF_POINTS] = OFFSCREEN;\r\n context.Y[i + j * NO_OF_POINTS] = OFFSCREEN;\r\n }\r\n }\r\n\r\n /* define the loction moving points stop */\r\n context.StopY = TOUCH_MVPOINT_Y;\r\n for (uint16_t i = 0; i < NO_OF_TOUCH; i++)\r\n {\r\n context.StopX[i] = TOUCH_MVPOINT_X + i * TOUCH_MVPOINT_SZ;\r\n }\r\n\r\n for (uint16_t k = 0; k < TOUCH_LOOP; k++)\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH0_XY, &context.val[0]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHA_XY, &context.val[1]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHB_XY, &context.val[2]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCHC_XY, &context.val[3]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_CTOUCH_TOUCH4_XY, &context.val[4]);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_pointSize(s_pHalContext, TOUCH_MVPOINT_SZ * 16);\r\n EVE_CoDl_colorA(s_pHalContext, 120);\r\n helperPointsCalc(&context);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(TOUCH_DELAY_MS);\r\n }\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n#endif // capacity EVE\r\n}\r\n\r\n/**\r\n * @brief Touch test with multiple objects that can be tracked individually\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_multiTracker()\r\n{\r\n#if defined(EVE_SUPPORT_CAPACITIVE)\r\n uint32_t trackers[NO_OF_TRACKER];\r\n uint32_t delayLoop = TOUCH_LOOP;\r\n uint32_t trackerVal;\r\n uint8_t tagval;\r\n uint8_t RDialTag = TOUCH_TRACKER_TAG_R;\r\n uint8_t GDialTag = TOUCH_TRACKER_TAG_G;\r\n uint8_t BDialTag = TOUCH_TRACKER_TAG_B;\r\n uint8_t ADialTag = TOUCH_TRACKER_TAG_A;\r\n uint8_t DialR = TOUCH_TRACKER_DIAL_W;\r\n uint8_t rectRed = 0;\r\n uint8_t rectGreen = 0;\r\n uint8_t rectBlue = 0;\r\n uint8_t rectAlpha = 255;\r\n\r\n uint16_t RDialX = DialR + TOUCH_TRACKER_DIAL_EDGE;\r\n uint16_t RDialY = DialR + 5 * TOUCH_TRACKER_DIAL_EDGE;\r\n uint16_t GDialX = DialR + TOUCH_TRACKER_DIAL_EDGE;\r\n uint16_t GDialY = (uint16_t)(s_pHalContext->Height - 5* TOUCH_TRACKER_DIAL_EDGE - DialR);\r\n uint16_t BDialX = (uint16_t)(s_pHalContext->Width - TOUCH_TRACKER_DIAL_EDGE - DialR);\r\n uint16_t BDialY = DialR + 5 * TOUCH_TRACKER_DIAL_EDGE;\r\n uint16_t ADialX = (uint16_t)(s_pHalContext->Width - TOUCH_TRACKER_DIAL_EDGE - DialR);\r\n uint16_t ADialY = (uint16_t)(s_pHalContext->Height - 5 * TOUCH_TRACKER_DIAL_EDGE - DialR);\r\n uint16_t rectWidth = TOUCH_TRACKER_RECT_W;\r\n uint16_t rectHeight = TOUCH_TRACKER_RECT_H;\r\n uint16_t rectX = (uint16_t) (s_pHalContext->Width / 2 - rectWidth / 2);\r\n uint16_t rectY = (uint16_t) (s_pHalContext->Height / 2 - rectHeight / 2);\r\n uint16_t RDialTrackVal = 0;\r\n uint16_t GDialTrackVal = 0;\r\n uint16_t BDialTrackVal = 0;\r\n uint16_t ADialTrackVal = 65535;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Multi touch on a single tracked object\\n\\n\\nPlease touch on screen (1-4 fingers)\");\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_EXTENDED);\r\n EVE_CoCmd_track(s_pHalContext, RDialX, RDialY, 1, 1, RDialTag);\r\n EVE_CoCmd_track(s_pHalContext, GDialX, GDialY, 1, 1, GDialTag);\r\n EVE_CoCmd_track(s_pHalContext, BDialX, BDialY, 1, 1, BDialTag);\r\n EVE_CoCmd_track(s_pHalContext, ADialX, ADialY, 1, 1, ADialTag);\r\n while (delayLoop != 0)\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER, &trackers[0]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER_1, &trackers[1]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER_2, &trackers[2]);\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER_3, &trackers[3]);\r\n\r\n for (uint8_t i = 0; i < NO_OF_TRACKER; i++)\r\n {\r\n tagval = (trackers[i] & 0xff);\r\n trackerVal = (trackers[i] >> 16) & 0xffff;\r\n if (tagval == RDialTag)\r\n {\r\n rectRed = (uint8_t) (trackerVal * 255 / 65536);\r\n RDialTrackVal = (uint16_t) trackerVal;\r\n }\r\n else if (tagval == GDialTag)\r\n {\r\n rectGreen = (uint8_t) (trackerVal * 255 / 65536);\r\n GDialTrackVal = (uint16_t) trackerVal;\r\n }\r\n else if (tagval == BDialTag)\r\n {\r\n rectBlue = (uint8_t) (trackerVal * 255 / 65536);\r\n BDialTrackVal = (uint16_t) trackerVal;\r\n }\r\n else if (tagval == ADialTag)\r\n {\r\n rectAlpha = (uint8_t) (trackerVal * 255 / 65536);\r\n ADialTrackVal = (uint16_t) trackerVal;\r\n }\r\n }\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n EVE_CoDl_tagMask(s_pHalContext, 1);\r\n EVE_CoDl_tag(s_pHalContext, RDialTag);\r\n EVE_CoCmd_dial(s_pHalContext, RDialX, RDialY, DialR, 0, RDialTrackVal);\r\n EVE_CoDl_tag(s_pHalContext, GDialTag);\r\n EVE_CoCmd_dial(s_pHalContext, GDialX, GDialY, DialR, 0, GDialTrackVal);\r\n EVE_CoDl_tag(s_pHalContext, BDialTag);\r\n EVE_CoCmd_dial(s_pHalContext, BDialX, BDialY, DialR, 0, BDialTrackVal);\r\n EVE_CoDl_tag(s_pHalContext, ADialTag);\r\n EVE_CoCmd_dial(s_pHalContext, ADialX, ADialY, DialR, 0, ADialTrackVal);\r\n EVE_CoDl_tagMask(s_pHalContext, 0);\r\n\r\n EVE_CoCmd_text(s_pHalContext, RDialX, RDialY, TOUCH_TITLE_FONT, OPT_CENTER, \"Red\");//text info\r\n EVE_CoCmd_text(s_pHalContext, GDialX, GDialY, TOUCH_TITLE_FONT, OPT_CENTER, \"Green\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, BDialX, BDialY, TOUCH_TITLE_FONT, OPT_CENTER, \"Blue\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, ADialX, ADialY, TOUCH_TITLE_FONT, OPT_CENTER, \"Alpha\"); //text info\r\n\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_colorRgb(s_pHalContext, rectRed, rectGreen, rectBlue);\r\n EVE_CoDl_colorA(s_pHalContext, rectAlpha);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, rectX * 16, rectY * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (rectX + rectWidth) * 16, (rectY + rectHeight) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n\r\n delayLoop--;\r\n }\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_CTOUCH_EXTENDED, CTOUCH_MODE_COMPATIBILITY);\r\n#endif\r\n}\r\n\r\n/**\r\n * @brief explain the usage of touch engine of EVE\r\n * \r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_touchInfo()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Touch raw, touch screen, touch tag\\n\\n\\nPlease touch on screen\");\r\n\r\n int32_t LoopFlag = TOUCH_LOOP;\r\n int32_t wbutton;\r\n int32_t hbutton;\r\n char StringArray[100];\r\n uint32_t touchVal;\r\n uint16_t xvalue;\r\n uint16_t yvalue;\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of touch function. Display info */\r\n /* touch raw, touch screen, touch tag, raw adc and resistance values */\r\n /*************************************************************************/\r\n wbutton = s_pHalContext->Width / 8;\r\n hbutton = s_pHalContext->Height / 8;\r\n while (LoopFlag--)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0, 0, 0 }, 0xff, 4);\r\n EVE_CoDl_tagMask(s_pHalContext, 0);\r\n /* Draw informative text */\r\n StringArray[0] = '\\0';\r\n strcat_s(StringArray, sizeof(StringArray), \"Touch Raw XY (\");\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_RAW_XY, &touchVal);\r\n yvalue = (uint16_t)(touchVal & 0xffff);\r\n xvalue = (uint16_t)((touchVal >> 16) & 0xffff);\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), (uint32_t)xvalue);\r\n strcat_s(StringArray, sizeof(StringArray), \",\");\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), (uint32_t)yvalue);\r\n strcat_s(StringArray, sizeof(StringArray), \")\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t) (s_pHalContext->Width / 2), TOUCH_TITLE_Y, TOUCH_TITLE_FONT, OPT_CENTER,\r\n StringArray);\r\n\r\n StringArray[0] = '\\0';\r\n strcat_s(StringArray, sizeof(StringArray), \"Touch Screen XY (\");\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_SCREEN_XY, &touchVal);\r\n yvalue = (int16_t)(touchVal & 0xffff);\r\n xvalue = (int16_t)((touchVal >> 16) & 0xffff);\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), (int32_t)xvalue);\r\n strcat_s(StringArray, sizeof(StringArray), \",\");\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), (int32_t)yvalue);\r\n strcat_s(StringArray, sizeof(StringArray), \")\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), TOUCH_TITLE_Y + TOUCH_TITLE_Y_INC, TOUCH_TITLE_FONT, OPT_CENTER,\r\n StringArray);\r\n\r\n StringArray[0] = '\\0';\r\n strcat_s(StringArray, sizeof(StringArray), \"Touch TAG (\");\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &touchVal);\r\n Gpu_Hal_Dec2Ascii(StringArray, sizeof(StringArray), touchVal);\r\n strcat_s(StringArray, sizeof(StringArray), \")\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), TOUCH_TITLE_Y + 2 * TOUCH_TITLE_Y_INC, TOUCH_TITLE_FONT, OPT_CENTER,\r\n StringArray);\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x008000);\r\n EVE_CoDl_tagMask(s_pHalContext, 1);\r\n EVE_CoDl_tag(s_pHalContext, 12);\r\n EVE_CoCmd_button(s_pHalContext, (int16_t) ((s_pHalContext->Width / 4) - (wbutton / 2)),\r\n (int16_t) ((s_pHalContext->Height * 2 / 4) - (hbutton / 2)), (int16_t) wbutton,\r\n (int16_t)hbutton, TOUCH_TITLE_FONT, OPT_FLAT, \"Tag12\");\r\n EVE_CoDl_tag(s_pHalContext, 13);\r\n EVE_CoCmd_button(s_pHalContext, (int16_t) ((s_pHalContext->Width * 3 / 4) - (wbutton / 2)),\r\n (int16_t) ((s_pHalContext->Height * 3 / 4) - (hbutton / 2)), (int16_t) wbutton,\r\n (int16_t)hbutton, TOUCH_TITLE_FONT, OPT_FLAT, \"Tag13\");\r\n\r\n Display_End(s_pHalContext);\r\n EVE_sleep(TOUCH_DELAY_MS);\r\n }\r\n}\r\n\r\n/**\r\n * @brief Sample app api to demonstrate track widget funtionality\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch_objectTrack()\r\n{\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of track function. Track function */\r\n /* tracks the pen touch on any specific object. Track function supports */\r\n /* rotary and horizontal/vertical tracks. Rotary is given by rotation */\r\n /* angle and horizontal/vertucal track is offset position. */\r\n /*************************************************************************/\r\n int32_t LoopFlag = TOUCH_LOOP;\r\n uint32_t TrackRegisterVal = 0;\r\n uint16_t angleval = 0;\r\n uint16_t slideval = 0;\r\n uint16_t scrollval = 0;\r\n\r\n /* Set the tracker for 3 bojects */\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Rotary and horizontal/vertical tracks\\n\\n\\nPlease touch on screen\");\r\n\r\n EVE_CoCmd_track(s_pHalContext, (int16_t)(s_pHalContext->Width / 2),\r\n (int16_t)(s_pHalContext->Height / 2), 1, 1, TOUCH_OBJ_DIAL_TAG);\r\n EVE_CoCmd_track(s_pHalContext, TOUCH_OBJ_SLIDE_EDGE, (int16_t)(s_pHalContext->Height - TOUCH_OBJ_SLIDE_EDGE),\r\n (int16_t)(s_pHalContext->Width - 2 * TOUCH_OBJ_SLIDE_EDGE), TOUCH_OBJ_SLIDE_W, TOUCH_OBJ_H_TAG);\r\n EVE_CoCmd_track(s_pHalContext, (int16_t)(s_pHalContext->Width - TOUCH_OBJ_SLIDE_EDGE), TOUCH_OBJ_SLIDE_EDGE,\r\n TOUCH_OBJ_SLIDE_W, (int16_t)(s_pHalContext->Height - 2 * TOUCH_OBJ_SLIDE_EDGE), TOUCH_OBJ_V_TAG);\r\n /* Wait till coprocessor completes the operation */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n /* update the background color continuously for the color change in any of the trackers */\r\n while (LoopFlag--)\r\n {\r\n uint8_t tagval = 0;\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TRACKER, &TrackRegisterVal);\r\n tagval = TrackRegisterVal & 0xff;\r\n\r\n if (TOUCH_OBJ_DIAL_TAG == tagval)\r\n {\r\n angleval = TrackRegisterVal >> 16;\r\n }\r\n else if (TOUCH_OBJ_H_TAG == tagval)\r\n {\r\n slideval = TrackRegisterVal >> 16;\r\n }\r\n else if (TOUCH_OBJ_V_TAG == tagval)\r\n {\r\n // scroll bar size is 2/10 of height\r\n scrollval = TrackRegisterVal >> 16;\r\n if ((scrollval + 65535 / 10) > (9 * 65535 / 10))\r\n {\r\n scrollval = (8 * 65535 / 10);\r\n }\r\n else if (scrollval < (1 * 65535 / 10))\r\n {\r\n scrollval = 0;\r\n }\r\n else\r\n {\r\n scrollval -= (1 * 65535 / 10);\r\n }\r\n }\r\n\r\n /* Display a rotary dial, horizontal slider and vertical scroll */\r\n\r\n int32_t tmpval0;\r\n int32_t tmpval1;\r\n int32_t tmpval2;\r\n uint8_t angval;\r\n uint8_t sldval;\r\n uint8_t scrlval;\r\n\r\n tmpval0 = (int32_t) angleval * 255 / 65536;\r\n tmpval1 = (int32_t) slideval * 255 / 65536;\r\n tmpval2 = (int32_t) scrollval * 255 / 65536;\r\n angval = tmpval0 & 0xff;\r\n sldval = tmpval1 & 0xff;\r\n scrlval = tmpval2 & 0xff;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { angval, sldval, scrlval }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n\r\n /* Draw dial with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x00ff00);\r\n EVE_CoCmd_bgColor(s_pHalContext, 0x800000);\r\n EVE_CoDl_tag(s_pHalContext, TOUCH_OBJ_DIAL_TAG);\r\n EVE_CoCmd_dial(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t)(s_pHalContext->Height / 2), (int16_t)TOUCH_OBJ_DIAL_R, 0, angleval);\r\n\r\n /* Draw slider with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x00a000);\r\n EVE_CoCmd_bgColor(s_pHalContext, 0x800000);\r\n EVE_CoDl_tag(s_pHalContext, TOUCH_OBJ_H_TAG);\r\n EVE_CoCmd_slider(s_pHalContext, TOUCH_OBJ_SLIDE_EDGE, (int16_t)(s_pHalContext->Height - TOUCH_OBJ_SLIDE_EDGE),\r\n (int16_t)(s_pHalContext->Width - 2 * TOUCH_OBJ_SLIDE_EDGE), TOUCH_OBJ_SLIDE_W, 0, slideval, 65535);\r\n\r\n /* Draw scroll with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x00a000);\r\n EVE_CoCmd_bgColor(s_pHalContext, 0x000080);\r\n EVE_CoDl_tag(s_pHalContext, TOUCH_OBJ_V_TAG);\r\n EVE_CoCmd_scrollbar(s_pHalContext, (int16_t)(s_pHalContext->Width - TOUCH_OBJ_SLIDE_EDGE), TOUCH_OBJ_SLIDE_EDGE, \r\n TOUCH_OBJ_SLIDE_W, (int16_t)(s_pHalContext->Height - 2 * TOUCH_OBJ_SLIDE_EDGE), 0, scrollval, (uint16_t)(65535 * 2 / 10), 65535);\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, TAG_MASK(0));\r\n EVE_CoDl_colorRgb(s_pHalContext, 0xff, 0xff, 0xff);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t)((s_pHalContext->Height / 2) + TOUCH_OBJ_DIAL_R + TOUCH_TITLE_Y_INC), TOUCH_TITLE_FONT,\r\n OPT_CENTER, \"Rotary track\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), TOUCH_OBJ_H_TEXT_Y, TOUCH_TITLE_FONT, OPT_CENTER, \"Horizontal track\");\r\n EVE_CoCmd_text(s_pHalContext, TOUCH_OBJ_V_TEXT_X, TOUCH_TITLE_Y_INC, TOUCH_TITLE_FONT, OPT_CENTER, \"Vertical track\");\r\n\r\n Display_End(s_pHalContext);\r\n\r\n EVE_sleep(TOUCH_DELAY_MS);\r\n }\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all touch demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Touch()\r\n{\r\n SAMAPP_Touch_touchToPlaySong();\r\n SAMAPP_Touch_BouncingSquares();\r\n SAMAPP_Touch_BouncingCircles();\r\n SAMAPP_Touch_BouncingPoints();\r\n SAMAPP_Touch_MovingPoints();\r\n SAMAPP_Touch_multiTracker();\r\n SAMAPP_Touch_touchInfo();\r\n SAMAPP_Touch_objectTrack();\r\n}\r\n\r\n\r\n"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"sample_id": "sampleapp_utility",
|
|
58
|
+
"relative_path": "SampleApp/Utility/Src/Utility.c",
|
|
59
|
+
"ext": ".c",
|
|
60
|
+
"content": "/**\r\n * @file Utility.c\r\n * @brief Sample usage of some useful command\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Utility.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define UTIL_DELAY_MS 10\r\n#define UTIL_LOAD_ADDR DDR_BITMAPS_STARTADDR\r\n#define UTIL_TITLE_FONT 31\r\n#define UTIL_TITLE_X 10\r\n#define UTIL_TITLE_Y 50\r\n#define UTIL_TITLE_Y_INC 50\r\n#define UTIL_TEXT_LEN 100\r\n#define UTIL_NO_OF_CALLLIST 5\r\n#define UTIL_CALLLIST_ADDR RAM_G\r\n#define UTIL_CALLLIST_ANGLE 60\r\n#define UTIL_COPYLIST_X 500\r\n#define UTIL_COPYLIST_Y 500\r\n#define UTIL_APPEND_CMD_LEN 16\r\n#define UTIL_APPEND_TEXT_Y_INC 300\r\n#define UTIL_BULK_CIRCLE_NUM 100\r\n#define UTIL_BULK_LOOP 600\r\n#define UTIL_BULK_PREC 4\r\n#define UTIL_MEDIAFIFO_ADDR RAM_G\r\n#define UTIL_MEDIAFIFO_SZ (20 * 1024)\r\n#define UTIL_FILLW_X1 100\r\n#define UTIL_FILLW_Y1 200\r\n#define UTIL_FILLW_X2 400\r\n#define UTIL_FILLW_Y2 600\r\n#define UTIL_FILLW_W1 100\r\n#define UTIL_FILLW_W2 2\r\n#define UTIL_FILLW_W3 300\r\n#define UTIL_FILLW_H1 300\r\n#define UTIL_FILLW_H2 200\r\n#define UTIL_ROTATE_MODE 8\r\n#define UTIL_NUM_TEXT_X1 (s_pHalContext->Width / 2 - 200)\r\n#define UTIL_NUM_TEXT_X2 (s_pHalContext->Width / 2 + 100)\r\n#define UTIL_SKIPCOND_BTN_TAG 1\r\n#define UTIL_SKIPCOND_EXIT_TAG 2\r\n#define UTIL_INT_PIC_TAG 1\r\n#define UTIL_LOAD_ADDR1 DDR_BITMAPS_STARTADDR1\r\n#define UTIL_ZORDER_X1 50\r\n#define UTIL_ZORDER_X2 500\r\n#define UTIL_ZORDER_Y 100\r\n#define UTIL_BTN_X1 50\r\n#define UTIL_BTN_X2 s_pHalContext->Width / 2\r\n#define UTIL_BTN_Y s_pHalContext->Height / 6\r\n#define UTIL_BTN_W 500\r\n#define UTIL_BTN_H 50\r\n#define UTIL_BTN_FONT 29\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Utility();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of utilites of EVE\", \r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Utility();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n/**\r\n * @brief Flush a command to REG_CMDB_WRITE\r\n *\r\n * @param command Command value\r\n * @return None\r\n */\r\nstatic void helperCMDBWrite(uint32_t command)\r\n{\r\n EVE_Hal_wr32(s_pHalContext, REG_CMDB_WRITE, command);\r\n}\r\n\r\n/**\r\n * @brief Flush a string to REG_CMDB_WRITE\r\n *\r\n * @param str string to write\r\n * @return None\r\n */\r\nstatic void helperCMDBWriteString(uint8_t* str)\r\n{\r\n int textLen = strlen(str);\r\n int padding = textLen % 4;\r\n /* Copy the command instruction into buffer */\r\n uint32_t v = 0;\r\n for (int i = 0; i < textLen/4; i++) \r\n {\r\n v = str[i*4 + 0] << 0 |\r\n str[i*4 + 1] << 8 |\r\n str[i*4 + 2] << 16|\r\n str[i*4 + 3] << 24 ;\r\n EVE_Hal_wr32(s_pHalContext, REG_CMDB_WRITE, v);\r\n }\r\n\r\n if (padding)\r\n {\r\n v = 0;\r\n for (int i = 0; i < (4 - padding); i++) \r\n {\r\n v |= str[textLen / 4*4 + i] << i * 8;\r\n }\r\n EVE_Hal_wr32(s_pHalContext, REG_CMDB_WRITE, v);\r\n }\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_WAIT\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_wait()\r\n{\r\n const uint32_t delayUs = 1000000;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Waiting/Sleeping\");\r\n Draw_TextColor(s_pHalContext, \"EVE is waiting for 1 second...\", (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n\r\n uint32_t sms = EVE_millis();\r\n eve_printf_debug(\"Time start= %u\\n\", sms);\r\n EVE_CoCmd_wait(s_pHalContext, delayUs);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n uint32_t ems = EVE_millis();\r\n eve_printf_debug(\"Time end= %u\\n\", ems);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate for CMD_CALLLIST, CMD_NEWLIST, CMD_ENDLIST, CMD_RETURN\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_callList()\r\n{\r\n uint32_t endPtr = UTIL_CALLLIST_ADDR + 4;\r\n uint32_t endPtrArr[UTIL_NO_OF_CALLLIST];\r\n const uint16_t x = (s_pHalContext->Width - UTIL_JPG_FLOWER_W) / 2;\r\n const uint16_t y = (s_pHalContext->Height - UTIL_JPG_FLOWER_H) / 2;\r\n char str[UTIL_TEXT_LEN];\r\n\r\n Draw_Text(s_pHalContext, \"Example for: CMD_CALLLIST, CMD_NEWLIST, CMD_ENDLIST and CMD_RETURN\");\r\n\r\n Draw_TextColor(s_pHalContext, \"Constructing 5 lists ...\", (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n for (int i = 0; i < UTIL_NO_OF_CALLLIST; i++)\r\n {\r\n endPtrArr[i] = endPtr;\r\n\r\n EVE_CoCmd_newList(s_pHalContext, endPtr);\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, RGB565, UTIL_JPG_FLOWER_W, UTIL_JPG_FLOWER_H);\r\n\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_rotateAround(s_pHalContext, UTIL_JPG_FLOWER_W / 2, UTIL_JPG_FLOWER_H / 2, i * UTIL_CALLLIST_ANGLE * 65536 / 360, 65536 * 1);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x) * 16, (y) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n\r\n snprintf(str, UTIL_TEXT_LEN, \"Displaying list number %u\", i);\r\n EVE_CoCmd_text(s_pHalContext, x, UTIL_TITLE_Y, UTIL_TITLE_FONT, 0, str);\r\n EVE_CoCmd_endList(s_pHalContext);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n uint32_t endAddr;\r\n EVE_CoCmd_getPtr(s_pHalContext, &endAddr); //cmd_getPtr will be always 128 bytes align\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n eve_printf_debug(\"Compiled list %u at %u, size: %u Bytes\\n\", i, endPtr, endAddr - endPtr);\r\n endPtr = endAddr;\r\n }\r\n Draw_TextColor(s_pHalContext, \"Constructed 5 lists\", (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n\r\n EVE_Util_loadImageFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_JPG_FLOWER, NULL, 0);\r\n for (int i = 0; i < UTIL_NO_OF_CALLLIST; i++)\r\n {\r\n snprintf(str, UTIL_TEXT_LEN, \"Calling List number %u\", i);\r\n Draw_TextColor(s_pHalContext, str, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 125, 125, 125 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_callList(s_pHalContext, endPtrArr[i]);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n //check whether there is a CMD_RETURN at the end of list\r\n if (i == 0)\r\n {\r\n uint32_t cmd = 0;\r\n EVE_CoCmd_regRead(s_pHalContext, UTIL_CALLLIST_ADDR + endPtrArr[i] + 108, &cmd); // 108 is the length of the command list from CMD_NEWLIST to CMD_ENDLIST\r\n eve_printf_debug(\"Return: 0x%08x\\n\", cmd);\r\n\r\n if (cmd == CMD_RETURN)\r\n {\r\n Draw_TextColor(s_pHalContext, \"CMD_RETURN is appended into the list\", (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n SAMAPP_DELAY;\r\n }\r\n }\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate for command list in RAM_G with alignment\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_callListWithAlignment()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Construct a command list in RAM_G to show a button\");\r\n\r\n //Construct a command list in RAM_G to show a button\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 0 * 4, SAVE_CONTEXT());\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 1 * 4, CLEAR_COLOR_RGB(255, 255, 255));\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 2 * 4, CLEAR(1, 1, 1));\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 3 * 4, CMD_BUTTON);\r\n\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 4 * 4, 160 << 16 | 160); //y | x coordinate of button\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 5 * 4, 200 << 16 | 324); //h | w\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 6 * 4, 0 << 16 | 31); //options | Font handle\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 7 * 4, 'T' << 24 | 'S' << 16 | 'E' << 8 | 'T');\r\n\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 8 * 4, '\\0' << 24 | '\\0' << 16 | '\\0' << 8 | '\\0');\r\n\r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 8 * 4, RESTORE_CONTEXT()); //Assume 3 bytes padding bytes for alignment \r\n EVE_Hal_wr32(s_pHalContext, UTIL_LOAD_ADDR + 9 * 4, CMD_RETURN); //return to the command buffer\r\n\r\n //Call cmd_list with data in RAM_G\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_callList(s_pHalContext, UTIL_LOAD_ADDR);\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate copying a display list\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_copyList()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Copy a display list to RAM_G\");\r\n\r\n /* Create a display list and copy to RAM_G */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 100, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_COPYLIST_X, UTIL_COPYLIST_Y, UTIL_TITLE_FONT, OPT_CENTER, \"This is a cached display list\");\r\n EVE_CoCmd_copyList(s_pHalContext, UTIL_CALLLIST_ADDR);\r\n\r\n /* Display a new display list */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 100 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_COPYLIST_X, UTIL_COPYLIST_Y, UTIL_TITLE_FONT, OPT_CENTER, \"Displaying a new display list\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n /* Display cached display list */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_callList(s_pHalContext, UTIL_CALLLIST_ADDR);\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate the use of append commands\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_appendCommand()\r\n{\r\n uint32_t AppendCmds[16];\r\n int16_t xoffset;\r\n int16_t yoffset;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Appending DL command\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of coprocessor append command - to append any*/\r\n /* mcu specific graphics commands to coprocessor generated graphics commands */\r\n /*************************************************************************/\r\n\r\n /* Bitmap construction by MCU */\r\n /* Construct the bitmap data to be copied in the temp buffer then by using\r\n coprocessor append command copy it into graphics processor DL memory */\r\n xoffset = (int16_t)((s_pHalContext->Width - UTIL_JPG_MANDRILL_W) / 4);\r\n yoffset = (int16_t)((s_pHalContext->Height / 3) - UTIL_JPG_MANDRILL_H / 2);\r\n\r\n EVE_CoCmd_dlStart(s_pHalContext);\r\n AppendCmds[0] = CLEAR_COLOR_RGB(255, 0, 0);\r\n AppendCmds[1] = CLEAR(1, 1, 1);\r\n AppendCmds[2] = COLOR_RGB(255, 255, 255);\r\n AppendCmds[3] = BEGIN(BITMAPS);\r\n AppendCmds[4] = BITMAP_SOURCE(UTIL_LOAD_ADDR);\r\n AppendCmds[5] = BITMAP_SOURCEH(UTIL_LOAD_ADDR >> 24);\r\n AppendCmds[6] = BITMAP_LAYOUT(RGB565, 2 * UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n AppendCmds[7] = BITMAP_SIZE(BILINEAR, BORDER, BORDER, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n AppendCmds[8] = VERTEX2F(xoffset * 16, yoffset * 16);\r\n AppendCmds[9] = END();\r\n\r\n /* Download the bitmap data*/\r\n EVE_Util_loadImageFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_JPG_MANDRILL, NULL, OPT_RGB565);\r\n\r\n /* Download the DL data constructed by the MCU to ram */\r\n EVE_Hal_wrMem(s_pHalContext, UTIL_LOAD_ADDR + UTIL_JPG_MANDRILL_W * UTIL_JPG_MANDRILL_H * 2, (uint8_t *)AppendCmds, 9 * 4);\r\n\r\n /* Call the append api for copying the above generated data into graphics processor DL commands */\r\n EVE_CoCmd_append(s_pHalContext, UTIL_LOAD_ADDR + UTIL_JPG_MANDRILL_W * UTIL_JPG_MANDRILL_H * 2, 9 * 4);\r\n /* Display the text information */\r\n yoffset += UTIL_APPEND_TEXT_Y_INC;\r\n EVE_CoCmd_text(s_pHalContext, xoffset, yoffset, UTIL_TITLE_FONT, 0, \"Display bitmap by Append\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief write bulk of data to CMDB\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_bulkTransfer()\r\n{\r\n SAMAPP_Circle circles[UTIL_BULK_CIRCLE_NUM];\r\n uint32_t xoffset = (s_pHalContext->Width - UTIL_JPG_MANDRILL_W) / 2;\r\n uint32_t yoffset = (s_pHalContext->Height - UTIL_JPG_MANDRILL_H) / 2;\r\n int count = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Bulk transfer\");\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n for (int i = 0; i < UTIL_BULK_CIRCLE_NUM; i++)\r\n {\r\n circles[i].visible = 0;\r\n circles[i].opacity = 0;\r\n circles[i].radius = 0;\r\n circles[i].step = 0;\r\n circles[i].x = 0;\r\n circles[i].y = 0;\r\n circles[i].color.b = 0;\r\n circles[i].color.g = 0;\r\n circles[i].color.r = 0;\r\n }\r\n\r\n EVE_Util_loadImageFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_JPG_MANDRILL, NULL, OPT_RGB565);\r\n\r\n while (count++ < UTIL_BULK_LOOP)\r\n {\r\n /*Display List start*/\r\n helperCMDBWrite(CMD_DLSTART);\r\n helperCMDBWrite(CLEAR_COLOR_RGB(0, 0, 0));\r\n helperCMDBWrite(CLEAR(1, 1, 1));\r\n helperCMDBWrite(VERTEX_FORMAT(2));\r\n // draw circles\r\n for (int i = 0; i < UTIL_BULK_CIRCLE_NUM; i++)\r\n {\r\n int visible = rand() % 3;\r\n int x = rand() % s_pHalContext->Width;\r\n int y = rand() % s_pHalContext->Height;\r\n int radius = rand() % 20;\r\n int r = rand() % 255;\r\n int g = rand() % 255;\r\n int b = rand() % 255;\r\n int step = rand() % 100 / 20 + 1;\r\n\r\n if (visible != 1)\r\n {\r\n visible = 0;\r\n }\r\n\r\n if (circles[i].visible == 0 && visible == 1)\r\n {\r\n circles[i].visible = 1;\r\n circles[i].x = x;\r\n circles[i].y = y;\r\n circles[i].radius = radius * 5;\r\n circles[i].color.r = r;\r\n circles[i].color.g = g;\r\n circles[i].color.b = b;\r\n circles[i].opacity = 0;\r\n circles[i].step = step;\r\n }\r\n else if (circles[i].opacity >= 255)\r\n {\r\n circles[i].step = -circles[i].step;\r\n }\r\n else if (circles[i].opacity <= 0)\r\n {\r\n circles[i].visible = 0;\r\n }\r\n circles[i].opacity += circles[i].step;\r\n\r\n if (circles[i].visible)\r\n {\r\n helperCMDBWrite(COLOR_A(circles[i].opacity));\r\n helperCMDBWrite(COLOR_RGB(circles[i].color.r, circles[i].color.g, circles[i].color.b));\r\n\r\n helperCMDBWrite(BEGIN(POINTS));\r\n helperCMDBWrite(POINT_SIZE(circles[i].radius * UTIL_BULK_PREC));\r\n helperCMDBWrite(VERTEX2F(circles[i].x * UTIL_BULK_PREC, circles[i].y * UTIL_BULK_PREC));\r\n helperCMDBWrite(END());\r\n }\r\n }\r\n // reset coloring\r\n helperCMDBWrite(COLOR_A(255));\r\n helperCMDBWrite(COLOR_RGB(255, 255, 255));\r\n\r\n // draw image\r\n helperCMDBWrite(BITMAP_HANDLE(2));\r\n helperCMDBWrite(BEGIN(BITMAPS));\r\n helperCMDBWrite(BITMAP_SOURCE(UTIL_LOAD_ADDR));\r\n helperCMDBWrite(BITMAP_SOURCEH(UTIL_LOAD_ADDR >> 24));\r\n helperCMDBWrite(BITMAP_LAYOUT(RGB565, UTIL_JPG_MANDRILL_W * 2, UTIL_JPG_MANDRILL_H));\r\n helperCMDBWrite(BITMAP_LAYOUT_H((UTIL_JPG_MANDRILL_W * 2) >> 10, UTIL_JPG_MANDRILL_H >> 9));\r\n helperCMDBWrite(BITMAP_SIZE(BILINEAR, BORDER, BORDER, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H));\r\n helperCMDBWrite(BITMAP_SIZE_H(UTIL_JPG_MANDRILL_W >> 9, UTIL_JPG_MANDRILL_H >> 9));\r\n helperCMDBWrite(VERTEX2F(xoffset * UTIL_BULK_PREC, yoffset * UTIL_BULK_PREC));\r\n helperCMDBWrite(END());\r\n\r\n // Draw the text in top of screen\r\n uint32_t x = s_pHalContext->Width / 2;\r\n uint32_t y = UTIL_TITLE_Y;\r\n helperCMDBWrite(CMD_TEXT);\r\n helperCMDBWrite(((y << 16) | (x & 0xffff)));\r\n helperCMDBWrite(((OPT_CENTER << 16) | (UTIL_TITLE_FONT & 0xffff)));\r\n helperCMDBWriteString(\"Bulk transfer demostration\");\r\n\r\n y += UTIL_TITLE_Y_INC;\r\n helperCMDBWrite(CMD_TEXT);\r\n helperCMDBWrite(((y << 16) | (x & 0xffff)));\r\n helperCMDBWrite(((OPT_CENTER << 16) | (UTIL_TITLE_FONT & 0xffff)));\r\n helperCMDBWriteString(\"Commands are transferd into REG_CMDB_WRITE instead of RAM_CMD\");\r\n helperCMDBWrite(VERTEX_FORMAT(4));\r\n\r\n helperCMDBWrite(DISPLAY()); //send command display - to end display commands\r\n helperCMDBWrite(CMD_SWAP); // draw the new screen\r\n\r\n // Flush all the command\r\n EVE_Cmd_waitFlush(s_pHalContext); // Wait until EVE is free\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate display bitmap by inflate data from flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_cmdInflateFromFlash()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: CMD_INFLATE with OPT_FLASH\");\r\n\r\n FlashHelper_SwitchState(s_pHalContext, FLASH_STATUS_FULL); // full mode\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, UTIL_ADDR_FLASH_MANDRILL);\r\n EVE_CoCmd_inflate(s_pHalContext, UTIL_LOAD_ADDR, OPT_FLASH);\r\n\r\n /* Display inflated image */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, YCBCR, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - UTIL_JPG_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - UTIL_JPG_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* Display the text information */\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, UTIL_TITLE_Y, UTIL_TITLE_FONT, OPT_CENTER, \"Display bitmap by inflate (OPT_FLASH)\");\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate display bitmap by inflate data from media fifo\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_CmdInflateFromFifo()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: CMD_INFLATE with data from media fifo\");\r\n\r\n /* Clear the memory - any previous bitmap data */\r\n EVE_CoCmd_memSet(s_pHalContext, UTIL_LOAD_ADDR, 255L, 1L * UTIL_JPG_MANDRILL_W * 2 * UTIL_JPG_MANDRILL_H);\r\n /* Load data to mediafifo */\r\n EVE_MediaFifo_set(s_pHalContext, UTIL_MEDIAFIFO_ADDR, UTIL_MEDIAFIFO_SZ);\r\n EVE_CoCmd_inflate(s_pHalContext, UTIL_LOAD_ADDR, OPT_MEDIAFIFO);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR UTIL_JPG_MANDRILL_INFLATE, NULL);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, YCBCR, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - UTIL_JPG_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - UTIL_JPG_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* Display the text information */\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, UTIL_TITLE_Y, UTIL_TITLE_FONT, OPT_CENTER, \"Display bitmap by inflate from media fifo\");\r\n Display_End(s_pHalContext);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate the usage of inflate command - compression done via zlib\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_CmdInflateFromCommand()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: CMD_INFLATE with data from command fifo\");\r\n\r\n /**********************************************************************************/\r\n /* Below code demonstrates the usage of inflate function */\r\n /**********************************************************************************/\r\n /* Clear the memory - any previous bitmap data */\r\n EVE_CoCmd_memSet(s_pHalContext, UTIL_LOAD_ADDR, 255L, 1L * UTIL_JPG_MANDRILL_W * 2 * UTIL_JPG_MANDRILL_H);\r\n /* inflate the data read from binary file */\r\n EVE_Util_loadInflateFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_JPG_MANDRILL_INFLATE);\r\n\r\n /* Set the display list for graphics processor */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, YCBCR, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width - UTIL_JPG_MANDRILL_W) / 2 * 16, (s_pHalContext->Height - UTIL_JPG_MANDRILL_H) / 2 * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* Display the text information */\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, UTIL_TITLE_Y, UTIL_TITLE_FONT, OPT_CENTER, \"Display bitmap by inflate from command fifo\");\r\n Display_End(s_pHalContext);\r\n\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate Coprocessor fault and recover\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_coprocessorFaultRecover()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Coprocessor fault and recover\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n //Fault case: enable interlace option\r\n EVE_Util_loadImageFile(s_pHalContext, RAM_G, TEST_DIR UTIL_PNG_UNSUPPORT, NULL, 0);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2 - UTIL_PNG_FAILED_W / 2) * 16,\r\n (s_pHalContext->Height / 2 - UTIL_PNG_FAILED_H / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(100);\r\n\r\n EVE_Util_coprocessorFaultRecover(s_pHalContext);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n //Fault case: change bit depth into 7\r\n EVE_Util_loadImageFile(s_pHalContext, RAM_G, TEST_DIR UTIL_PNG_CORRUPT, NULL, 0);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (s_pHalContext->Width / 2 - UTIL_PNG_FAILED_W / 2) * 16,\r\n (s_pHalContext->Height / 2 - UTIL_PNG_FAILED_H / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n\r\n EVE_Util_coprocessorFaultRecover(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_FILLWIDTH\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_fillWidth()\r\n{\r\n int16_t x;\r\n int16_t y;\r\n int16_t fill_w;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: CMD_FILLWIDTH\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n fill_w = UTIL_FILLW_W1;\r\n EVE_CoCmd_fillWidth(s_pHalContext, fill_w);\r\n\r\n x = UTIL_FILLW_X1;\r\n y = UTIL_FILLW_Y1;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 0);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x + fill_w) * 16, (y + UTIL_FILLW_H1) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, x, y, UTIL_TITLE_FONT, OPT_FILL, \"This test doesn't fit on one line\");\r\n\r\n x = UTIL_FILLW_X2;\r\n y = UTIL_FILLW_Y1;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 0);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x - fill_w / 2) * 16, (y - UTIL_FILLW_H1 / 2) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x + fill_w / 2) * 16, (y + UTIL_FILLW_H1 / 2) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, x, y, UTIL_TITLE_FONT, OPT_FILL | OPT_CENTER, \"This test doesn't fit on one line\");\r\n\r\n x = UTIL_FILLW_X1;\r\n y = UTIL_FILLW_Y2;\r\n fill_w = UTIL_FILLW_W2;\r\n EVE_CoCmd_fillWidth(s_pHalContext, fill_w);\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 0);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x + UTIL_FILLW_W1) * 16, (y + UTIL_FILLW_H1) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, x, y, UTIL_TITLE_FONT, OPT_FILL, \"line one line two with fill\");\r\n\r\n x = UTIL_FILLW_X2;\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 0);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, x * 16, y * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (x + UTIL_FILLW_W1) * 16, (y + UTIL_FILLW_H1) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoCmd_text(s_pHalContext, x, y, UTIL_TITLE_FONT, 0, \"line one \\nline two \\nwithout fill\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n // Cover the cmd_button \r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n y = UTIL_FILLW_Y1;\r\n fill_w = UTIL_FILLW_W3;\r\n EVE_CoCmd_fillWidth(s_pHalContext, fill_w);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_FILLW_X1, y, fill_w, UTIL_FILLW_H2, UTIL_TITLE_FONT, OPT_FILL, \"This test doesn't fit on one line\");\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate OTP_FORMAT\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_printType() //must call after SAMAPP_ExtendedFormat_Font\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: OPT_FORMAT\");\r\n uint8_t c = 51;\r\n uint32_t a = 0x12a000;\r\n int16_t mV = 1947;\r\n int32_t t = 680;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y, UTIL_TITLE_FONT, 0, \"%\");\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 1, UTIL_TITLE_FONT, 0, \"%%\");\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 2, UTIL_TITLE_FONT, 0, \"%d%%%\");\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 3, UTIL_TITLE_FONT, OPT_FORMAT, \"%d * %d = %d\", 100, 200, 20000);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 4, UTIL_TITLE_FONT, OPT_FORMAT, \"%3d%% complete\", c); /*result: 51 % complete */\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 5, UTIL_TITLE_FONT, OPT_FORMAT, \"base address %06x\", a); /*result: base address 12a000 */\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 6, UTIL_TITLE_FONT, OPT_FORMAT, \"%+5.3d mV\", mV); /*result: + 1947 mV */\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 7, UTIL_TITLE_FONT, OPT_FORMAT, \"Temp. %d.%.1d degrees\", t / 10,\r\n t % 10); /*result: Temp. 68.0 degrees */\r\n\r\n EVE_Hal_wrMem(s_pHalContext, RAM_G + 4, \"Hello \", 8); //address and length should be aline to 4\r\n EVE_CoCmd_text(s_pHalContext, UTIL_TITLE_X, UTIL_TITLE_Y + UTIL_TITLE_Y_INC * 8, UTIL_TITLE_FONT, OPT_FORMAT, \"%s %d times\", RAM_G + 4, 5); /*result: Hello 5 times */\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Change screen orientation from landscape to portrait mode.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_screenRotate()\r\n{\r\n uint8_t text[UTIL_TEXT_LEN];\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Change screen orientation from landscape to portrait mode\");\r\n\r\n for (uint32_t rotateMode = 0; rotateMode < UTIL_ROTATE_MODE; rotateMode++)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setRotate(s_pHalContext, rotateMode);\r\n switch (rotateMode)\r\n {\r\n case 0:\r\n case 1:\r\n case 4:\r\n case 5:\r\n snprintf(text, UTIL_TEXT_LEN, \"Landscape Mode, rotate value= %d\", rotateMode);\r\n break;\r\n default:\r\n snprintf(text, UTIL_TEXT_LEN, \"Portrait Mode\\nRotate value= %d\", rotateMode);\r\n\r\n break;\r\n }\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), UTIL_TITLE_Y, UTIL_TITLE_FONT, OPT_CENTER, text);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n }\r\n\r\n //reset the rotation angle\r\n EVE_CoCmd_setRotate(s_pHalContext, 0);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate number base\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_numberBases()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Number base\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t) (s_pHalContext->Width / 2), UTIL_TITLE_Y, UTIL_TITLE_FONT, OPT_CENTER,\r\n \"Built-in bases conversion\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), UTIL_TITLE_Y + UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, OPT_CENTER,\r\n \"bases from 2 to 32:\");\r\n\r\n EVE_CoCmd_text(s_pHalContext, UTIL_NUM_TEXT_X1, UTIL_TITLE_Y + 3 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0,\r\n \"Binary(2):\");\r\n EVE_CoCmd_setBase(s_pHalContext, 2);\r\n EVE_CoCmd_number(s_pHalContext, UTIL_NUM_TEXT_X2, UTIL_TITLE_Y + 3 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, 1000);\r\n\r\n EVE_CoCmd_text(s_pHalContext, UTIL_NUM_TEXT_X1, UTIL_TITLE_Y + 5 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0,\r\n \"Octal(8):\");\r\n EVE_CoCmd_setBase(s_pHalContext, 8);\r\n EVE_CoCmd_number(s_pHalContext, UTIL_NUM_TEXT_X2, UTIL_TITLE_Y + 5 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, 1000);\r\n\r\n EVE_CoCmd_text(s_pHalContext, UTIL_NUM_TEXT_X1, UTIL_TITLE_Y + 7 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0,\r\n \"Decimal(10):\");\r\n EVE_CoCmd_setBase(s_pHalContext, 10);\r\n EVE_CoCmd_number(s_pHalContext, UTIL_NUM_TEXT_X2, UTIL_TITLE_Y + 7 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, 1000);\r\n\r\n EVE_CoCmd_text(s_pHalContext, UTIL_NUM_TEXT_X1, UTIL_TITLE_Y + 9 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0,\r\n \"Hex(16):\");\r\n EVE_CoCmd_setBase(s_pHalContext, 16);\r\n EVE_CoCmd_number(s_pHalContext, UTIL_NUM_TEXT_X2, UTIL_TITLE_Y + 9 * UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, 1000);\r\n\r\n //Revert the base back to decimal because numeric base is part of the global context.\r\n EVE_CoCmd_setBase(s_pHalContext, 10);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief CRC check\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_crcCheck()\r\n{\r\n const uint32_t memWrite = 0x66666666; // 66 = 'f'\r\n const uint32_t memSizeTest = 1024; // bytes\r\n const uint32_t crcExpected = 0x17D32620;\r\n uint32_t memcrcRet = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Check Crc32 for 1024 bytes on RAM_G\");\r\n\r\n EVE_CoCmd_memSet(s_pHalContext, RAM_G, memWrite, memSizeTest);\r\n EVE_Cmd_waitFlush(s_pHalContext);/*reset cmd index*/\r\n\r\n EVE_CoCmd_memCrc(s_pHalContext, RAM_G, memSizeTest, &memcrcRet);\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n eve_printf_debug(\"current CRC number [0,1023) is 0x%x \\r\\n\", memcrcRet);\r\n if (memcrcRet == crcExpected)\r\n {\r\n eve_printf_debug(\"Crc return value is as expected\\n\");\r\n Draw_TextColor(s_pHalContext, \"Crc value is as expected\", (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 });\r\n }\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_SKIPCOND\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_skipcond()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Construct a command list with CMD_SKIPCOND\");\r\n uint32_t tag = 0;\r\n bool pressed = 0;\r\n bool exit = 0;\r\n uint8_t txtPause[2][UTIL_TEXT_LEN] = { \"PRESS TO CHANGE COLOR\", \"PRESSED\" };\r\n\r\n do\r\n {\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag);\r\n //only change the button when a release happened\r\n if ((tag & 0xFFFFFF) == UTIL_SKIPCOND_BTN_TAG)\r\n {\r\n pressed = 1;\r\n }\r\n else if ((tag & 0xFFFFFF) == UTIL_SKIPCOND_EXIT_TAG)\r\n {\r\n exit = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n }\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n\r\n /*** Show a button ***/\r\n EVE_CoCmd_skipCond(s_pHalContext, REG_TOUCH_TAG, NOTEQUAL, 0x1, 0xFFFFFF, 4 + 24); // colorRgb 4 bytes, CMD_SKIPCOND 24 bytes, so skip to the second colorRgb command if not equal to 1\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0); // red\r\n EVE_CoCmd_skipCond(s_pHalContext, 0, ALWAYS, 0x0, 0x0, 4); // unconditional branch\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 255, 0); // green\r\n EVE_CoDl_tag(s_pHalContext, UTIL_SKIPCOND_BTN_TAG);\r\n EVE_CoCmd_button(s_pHalContext, 160, 160, 600, 200, UTIL_TITLE_FONT, 0, txtPause[pressed]);\r\n /*** Show exit button ***/\r\n EVE_CoDl_tag(s_pHalContext, UTIL_SKIPCOND_EXIT_TAG);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 255, 255); // white\r\n EVE_CoCmd_button(s_pHalContext, 160, 460, 300, 200, UTIL_TITLE_FONT, 0, \"EXIT\");\r\n /*** Done button ***/\r\n Display_End(s_pHalContext);\r\n\r\n EVE_sleep(UTIL_DELAY_MS);\r\n } while (!exit);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_WAITCOND\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_waitcond()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Construct a command list with CMD_WAITCOND\");\r\n\r\n Draw_Text(s_pHalContext, \"Now you will hear the music \");\r\n EVE_CoCmd_loadWav(s_pHalContext, UTIL_LOAD_ADDR, 0);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR UTIL_WAV, NULL);\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LOOP, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, 155);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, 155);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_PLAY, 1);\r\n // wait until the music play end\r\n EVE_CoCmd_waitCond(s_pHalContext, REG_PLAYBACK_PLAY, EQUAL, 0x0, 0x1);\r\n Draw_Text(s_pHalContext, \"Music play done.\");\r\n\r\n //The file is done, mute the audio.\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_LENGTH, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_PLAYBACK_PLAY, 1);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate interrupt usage\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_interrupt()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Interrupt driven rendering\");\r\n\r\n uint32_t int_flags = 0;\r\n\r\n /* Copy the display list */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 2);\r\n /* Send command screen saver */\r\n EVE_CoDl_tagMask(s_pHalContext, 1);\r\n EVE_CoDl_tag(s_pHalContext, UTIL_INT_PIC_TAG);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_Util_loadImageFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_JPG_MANDRILL, NULL, OPT_RGB565);\r\n EVE_CoDl_macro(s_pHalContext, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_tagMask(s_pHalContext, 0);\r\n /* Display the text */\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height / 2), UTIL_TITLE_FONT, OPT_CENTER, \"Touch the picture to exit ...\");\r\n EVE_CoDl_display(s_pHalContext);\r\n EVE_CoCmd_screenSaver(s_pHalContext); //screen saver command will continuously update the macro0 with vertex2f command\r\n\r\n EVE_CoCmd_regRead(s_pHalContext, REG_INT_FLAGS, &int_flags); // clear flags\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_INT_MASK, 1 << INT_TAG); // set int mask\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_INT_EN, 1); // enable int\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n while ((!EVE_Hal_getInterrupt(s_pHalContext)) \r\n || ((EVE_Hal_rd32(s_pHalContext, REG_INT_FLAGS) & (1 << INT_TAG)) != (1 << INT_TAG)) \r\n || (EVE_Hal_rd32(s_pHalContext, REG_TOUCH_TAG) != UTIL_INT_PIC_TAG))\r\n ;\r\n\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n EVE_CoDl_vertexFormat(s_pHalContext, 4);\r\n Draw_Text(s_pHalContext, \"Tag touched interrupt detected\");\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate zorder usage for RGB8 format\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_zorder_RGB()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: simple zorder exercise for RGB format\");\r\n uint8_t z = 0xAA;\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_RAW_MANDRILL); // normal bitmap\r\n EVE_Util_loadRawFile(s_pHalContext, UTIL_LOAD_ADDR1, TEST_DIR UTIL_RAW_ZORDER_RGB8); //z-ordered bitmap with zorder = 0xaa\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 20, 0, 30 }, (uint8_t[]) { 255, 255, 255 }, 0, 0);\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 0);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_ZORDER_X1, UTIL_ZORDER_Y + UTIL_JPG_MANDRILL_H + UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, \"normal bitmap\");\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, RGB8, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f(s_pHalContext, UTIL_ZORDER_X1, UTIL_ZORDER_Y);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 1);\r\n EVE_CoDl_bitmapZorder(s_pHalContext, z); // after set bitmap handler\r\n EVE_CoCmd_text(s_pHalContext, UTIL_ZORDER_X2, UTIL_ZORDER_Y + UTIL_JPG_MANDRILL_H + UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, \"z-ordered bitmap\");\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR1, RGB8, UTIL_JPG_MANDRILL_W, UTIL_JPG_MANDRILL_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f(s_pHalContext, UTIL_ZORDER_X2, UTIL_ZORDER_Y);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate zorder usage for ASTC format\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_zorder_ASTC()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: simple zorder exercise for ASTC format\");\r\n uint8_t z = 0xAA;\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, UTIL_LOAD_ADDR, TEST_DIR UTIL_RAW_CASE); // normal bitmap\r\n EVE_Util_loadRawFile(s_pHalContext, UTIL_LOAD_ADDR1, TEST_DIR UTIL_RAW_ZORDER_ASTC); // z-ordered bitmap\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 20, 0, 30 }, (uint8_t[]) { 255, 255, 255 }, 0, 0);\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 0);\r\n EVE_CoCmd_text(s_pHalContext, UTIL_ZORDER_X1, UTIL_ZORDER_Y + UTIL_BITMAP_CASE_H + UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, \"normal bitmap\");\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR, COMPRESSED_RGBA_ASTC_8x8_KHR, UTIL_BITMAP_CASE_W, UTIL_BITMAP_CASE_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f(s_pHalContext, UTIL_ZORDER_X1, UTIL_ZORDER_Y);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 1);\r\n EVE_CoDl_bitmapZorder(s_pHalContext, z); // after set bitmap handler\r\n EVE_CoCmd_text(s_pHalContext, UTIL_ZORDER_X2, UTIL_ZORDER_Y + UTIL_BITMAP_CASE_H + UTIL_TITLE_Y_INC, UTIL_TITLE_FONT, 0, \"z-ordered bitmap\");\r\n EVE_CoCmd_setBitmap(s_pHalContext, UTIL_LOAD_ADDR1, COMPRESSED_RGBA_ASTC_8x8_KHR, UTIL_BITMAP_CASE_W, UTIL_BITMAP_CASE_H);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, GLFORMAT, 447 * 16, UTIL_BITMAP_CASE_H / 8); // The value 447 is the z-order width, as obtained from the z-order conversion\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f(s_pHalContext, UTIL_ZORDER_X2, UTIL_ZORDER_Y);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate SAVE_CONTEXT / RESTORE_CONTEXT, CMD_SAVECONTEXT / CMD_RESTORECONTEXT\r\n * \r\n * In this sample code\r\n * - COLOR_RGB is part of the graphics state, so it can be saved and restored using SAVE_CONTEXT / RESTORE_CONTEXT and CMD_SAVECONTEXT / CMD_RESTORECONTEXT\r\n * - CMD_FGCOLOR cannot be saved or restored using SAVE_CONTEXT / RESTORE_CONTEXT, but it can be handled by CMD_SAVECONTEXT / CMD_RESTORECONTEXT\r\n * - CMD_SETFONT cannot be saved or restored by either SAVE_CONTEXT / RESTORE_CONTEXT or CMD_SAVECONTEXT / CMD_RESTORECONTEXT.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility_context()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"Cannot switch flash full mode\");\r\n return;\r\n }\r\n\r\n Draw_Text(s_pHalContext, \"Example for: SAVE_CONTEXT and RESTORE_CONTEXT, CMD_SAVECONTEXT and CMD_RESTORECONTEXT\");\r\n\r\n\t// Copy font to ramg\r\n EVE_CoCmd_flashSource(s_pHalContext, FONT_FLASH_NOTO_L2_RELOC);\r\n EVE_CoCmd_loadAsset(s_pHalContext, UTIL_LOAD_ADDR, OPT_FLASH);\r\n\r\n\tDisplay_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 3);\r\n /********************** SAVE_CONTEXT and RESTORE_CONTEXT *****************************/\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X1, UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"before SAVE_CONTEXT\");\r\n\r\n EVE_CoDl_saveContext(s_pHalContext);\r\n EVE_CoCmd_fgColor(s_pHalContext, 0xd06038);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0);\r\n EVE_CoCmd_setFont(s_pHalContext, UTIL_BTN_FONT, UTIL_LOAD_ADDR, 0);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X1, 2 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after SAVE_CONTEXT\");\r\n\r\n EVE_CoDl_restoreContext(s_pHalContext);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X1, 3 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after RESTORE_CONTEXT\");\r\n\r\n\tEVE_CoCmd_resetFonts(s_pHalContext);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X1, 4 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after CMD_RESETFONT\");\r\n EVE_CoCmd_fgColor(s_pHalContext, 0x3870);\r\n\t/********************** CMD_SAVECONTEXT and CMD_RESTORECONTEXT *****************************/\r\n\tEVE_CoCmd_button(s_pHalContext, UTIL_BTN_X2, UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"before CMD_SAVECONTEXT\");\r\n\r\n EVE_CoCmd_saveContext(s_pHalContext);\r\n EVE_CoCmd_fgColor(s_pHalContext, 0xd06038);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0);\r\n EVE_CoCmd_setFont(s_pHalContext, UTIL_BTN_FONT, UTIL_LOAD_ADDR, 0);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X2, 2 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after CMD_SAVECONTEXT\");\r\n\r\n EVE_CoCmd_restoreContext(s_pHalContext);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X2, 3 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after CMD_RESTORECONTEXT\");\r\n\r\n EVE_CoCmd_resetFonts(s_pHalContext);\r\n EVE_CoCmd_button(s_pHalContext, UTIL_BTN_X2, 4 * UTIL_BTN_Y, UTIL_BTN_W, UTIL_BTN_H, UTIL_BTN_FONT, 0, \"after CMD_RESETFONT\");\r\n\r\n\tDisplay_End(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all utility demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Utility()\r\n{\r\n SAMAPP_Utility_wait();\r\n SAMAPP_Utility_callList();\r\n SAMAPP_Utility_callListWithAlignment();\r\n SAMAPP_Utility_copyList();\r\n SAMAPP_Utility_appendCommand();\r\n SAMAPP_Utility_bulkTransfer();\r\n SAMAPP_Utility_cmdInflateFromFlash();\r\n SAMAPP_Utility_CmdInflateFromFifo();\r\n SAMAPP_Utility_CmdInflateFromCommand();\r\n SAMAPP_Utility_coprocessorFaultRecover();\r\n SAMAPP_Utility_fillWidth();\r\n SAMAPP_Utility_printType();\r\n SAMAPP_Utility_screenRotate();\r\n SAMAPP_Utility_numberBases();\r\n SAMAPP_Utility_crcCheck();\r\n SAMAPP_Utility_skipcond();\r\n SAMAPP_Utility_waitcond();\r\n SAMAPP_Utility_interrupt();\r\n SAMAPP_Utility_zorder_RGB();\r\n SAMAPP_Utility_zorder_ASTC();\r\n SAMAPP_Utility_context();\r\n}\r\n\r\n\r\n"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"sample_id": "sampleapp_video",
|
|
64
|
+
"relative_path": "SampleApp/Video/Src/Video.c",
|
|
65
|
+
"ext": ".c",
|
|
66
|
+
"content": "/**\r\n * @file Video.c\r\n * @brief Sample usage of video display\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Video.h\"\r\n#include \"FlashHelper.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define VIDEO_DELAY_MS 10\r\n#define VIDEO_TITLE_FONT 31\r\n#define VIDEO_VOL 155\r\n#define VIDEO_LOAD_ADDR RAM_G\r\n#define VIDEO_BTN_W 400\r\n#define VIDEO_BTN_H 120\r\n#define VIDEO_BTN_TAG 1\r\n#define VIDEO_BTN_Y_INC 50\r\n#define VIDEO_MEDIAFIFO_ADDR DDR_BITMAPS_STARTADDR\r\n#define VIDEO_MEDIAFIFO_SZ 500 * 1024\r\n#define VIDEO_LOGO_X 100\r\n#define VIDEO_LOGO_Y 100\r\n#define VIDEO_VIDEO_X 400\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Video();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_VIDEO);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of video\", \r\n \"\",\r\n \"\"\r\n };\r\n //WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Video();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n// Helper to set playback volume\r\nstatic void helperSetVolume(EVE_HalContext *phost, uint8_t left, uint8_t right)\r\n{\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_L_PB, left);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_VOL_R_PB, right);\r\n}\r\n\r\n/**\r\n * @brief Test AVI video playback full screen from flash\r\n * \r\n * @note When using CMD_PLAYVIDEO/EVE_CoCmd_playVideo for video playback, SwapChain1(SC1) with double buffers is used by default. \\n\r\n * For configuration details, refer to 'Display_Config()' in Common.c.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromFlashFullScreen()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Video display from Flash - full screen\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n EVE_CoCmd_flashSource(s_pHalContext, VIDEO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FULLSCREEN | OPT_FLASH | OPT_SOUND);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\nstatic void SAMAPP_Video_fromFlashContinue()\r\n{\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H + VIDEO_BTN_Y_INC;\r\n bool stop = false;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Continuous Flash video playback with stop button\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n \r\n while (!stop)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, \"STOP VIDEO\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, VIDEO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FLASH | OPT_SOUND | OPT_YCBCR | OPT_OVERLAY);\r\n\r\n while (EVE_Cmd_space(s_pHalContext) != EVE_CMD_FIFO_SPACE)\r\n {\r\n uint32_t touch = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_SCREEN_XY);\r\n uint32_t touch_x = touch >> 16;\r\n uint32_t touch_y = touch & 0xFFFF;\r\n if ((touch_x > btnX) && (touch_x < (btnX + btnW)) && (touch_y > btnY) && (touch_y < (btnY + btnH)))\r\n {\r\n stop = true;\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, -1);\r\n break;\r\n }\r\n }\r\n \r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n if (stop == true)\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, 1);\r\n }\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate Video display frame by frame from Flash\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameFromFlash()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource = RAM_G + 4;\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Video display frame by frame from Flash\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, VIDEO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_FLASH);\r\n do\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource, completionPtr);\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n } while (EVE_Hal_rd32(s_pHalContext, completionPtr) != 0);\r\n}\r\n\r\n/**\r\n * @brief Video playback frame by frame with pause/resume button\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameFlashPauseResume()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource = RAM_G + 4;\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H - btnH - VIDEO_BTN_Y_INC;\r\n static bool isPause = 0;\r\n const uint32_t btnPauseTag = VIDEO_BTN_TAG;\r\n static bool pressed = 0;\r\n uint8_t txtPause[2][20] = { \"PAUSE\", \"RESUME\" };\r\n uint32_t tag = 0;\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Video playback frame by frame with pause/resume button\");\r\n\r\n EVE_CoCmd_flashSource(s_pHalContext, VIDEO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_FLASH);\r\n do\r\n {\r\n //only change the button when a release happened\r\n if ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && ((tag & 0xFFFFFF) == btnPauseTag))\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n isPause = !isPause;\r\n }\r\n }\r\n\r\n if (!isPause)\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource, completionPtr);\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n // video\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /*** Show a button ***/\r\n EVE_CoDl_tag(s_pHalContext, btnPauseTag);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, txtPause[isPause]);\r\n /*** Done button ***/\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n } while (EVE_Hal_rd32(s_pHalContext, completionPtr) != 0);\r\n}\r\n\r\n/**\r\n * @brief API used to demonstrate looping frame-by-frame Flash video playback with a stop button.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameFlashLoop()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource = RAM_G + 4;\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H + VIDEO_BTN_Y_INC;\r\n bool stop = false;\r\n const uint32_t btnStopTag = VIDEO_BTN_TAG;\r\n uint32_t tag = 0;\r\n\r\n if (!FlashHelper_SwitchFullMode(s_pHalContext))\r\n {\r\n eve_printf(\"SwitchFullMode failed\");\r\n return;\r\n }\r\n Draw_Text(s_pHalContext, \"Example for: Looping frame by frame Flash video playback with a stop button\");\r\n\r\n while (!stop)\r\n {\r\n EVE_CoCmd_flashSource(s_pHalContext, VIDEO_ADDR_FLASH_FLOWER);\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_FLASH);\r\n do\r\n {\r\n if ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && ((tag & 0xFFFFFF) == btnStopTag))\r\n {\r\n stop = true;\r\n break;\r\n }\r\n\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource, completionPtr);\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /*** Show a button ***/\r\n EVE_CoDl_tag(s_pHalContext, btnStopTag);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, \"STOP VIDEO\");\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n } while (EVE_Hal_rd32(s_pHalContext, completionPtr) != 0);\r\n }\r\n}\r\n\r\n/**\r\n * @brief AVI video playback directly from file\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromFileDirect()\r\n{\r\n#if defined(DISPLAY_RESOLUTION_WUXGA)\r\n Draw_Text(s_pHalContext, \"Example for: Video display direct from file\");\r\n Display_Config(s_pHalContext, YCBCR, MODE_DIRECTVIDEO);\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_DIRECT | OPT_SOUND | OPT_YCBCR);\r\n /* the video size must be the same as the screen resolution */\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1920, NULL);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_VIDEO);\r\n EVE_Util_clearScreen(s_pHalContext);\r\n#endif\r\n}\r\n\r\n/**\r\n * @brief AVI video playback from SD card\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromSD()\r\n{\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video display from SD card\");\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FS | OPT_SOUND | OPT_YCBCR);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief AVI video playback from SD card with pause/resume button\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromSDPauseResume()\r\n{\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H + VIDEO_BTN_Y_INC;\r\n static bool isPause = 0;\r\n static bool pressed = 0;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video display from SD card with pause/resume button\");\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n /*** Show a button ***/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, \"Pause/Resume\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FS | OPT_SOUND | OPT_YCBCR | OPT_OVERLAY | OPT_NODL);\r\n while (EVE_Cmd_space(s_pHalContext) != EVE_CMD_FIFO_SPACE)\r\n {\r\n uint32_t touch = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_SCREEN_XY);\r\n uint32_t touch_x = touch >> 16;\r\n uint32_t touch_y = touch & 0xFFFF;\r\n //only change the button when a release happened\r\n if ((touch_x > btnX) && (touch_x < (btnX + btnW)) && (touch_y > btnY) && (touch_y < (btnY + btnH)))\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n isPause = !isPause;\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, isPause ? 0 : 1);\r\n }\r\n }\r\n }\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, 1); // restore default value\r\n}\r\n\r\n/**\r\n * @brief AVI video playback from SD card with background\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromSDbackground()\r\n{\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video display from SD card with background\");\r\n\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_JPG, &result);\r\n eve_printf_debug(\"file read status 0x%lx \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_loadImage(s_pHalContext, VIDEO_LOAD_ADDR, OPT_FS | OPT_TRUECOLOR);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%lx \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FS | OPT_SOUND | OPT_YCBCR | OPT_OVERLAY);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Video playback from SD card frame by frame with pause/resume button\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameSDPauseResume()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource = RAM_G + 4;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - VIDEO_BTN_W / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H - VIDEO_BTN_H - VIDEO_BTN_Y_INC;\r\n static bool isPause = 0;\r\n const uint32_t btnPauseTag = VIDEO_BTN_TAG;\r\n static bool pressed = 0;\r\n uint8_t txtPause[2][20] = { \"PAUSE\", \"RESUME\" };\r\n uint32_t tag = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video playback from SD card, frame by frame with pause/resume button\");\r\n\r\n uint32_t result = 0;\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_FS);\r\n do\r\n {\r\n //only change the button when a release happened\r\n if ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && ((tag & 0xFFFFFF) == btnPauseTag))\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n isPause = !isPause;\r\n }\r\n }\r\n\r\n if (!isPause)\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource, completionPtr);\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n // video\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /*** Show a button ***/\r\n EVE_CoDl_tag(s_pHalContext, btnPauseTag);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, VIDEO_BTN_W, VIDEO_BTN_H, VIDEO_TITLE_FONT, 0, txtPause[isPause]);\r\n /*** Done button ***/\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n } while (EVE_Hal_rd32(s_pHalContext, completionPtr) != 0);\r\n}\r\n\r\n/**\r\n * @brief Video playback from an SD card, frame by frame, with double-buffer swapping\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameSDBufferSwap()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource1 = DDR_BITMAPS_STARTADDR1;\r\n const uint32_t videoSource2 = DDR_BITMAPS_STARTADDR2;\r\n uint32_t frame = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video playback from SD card, frame by frame, with double-buffer swapping\");\r\n\r\n uint32_t result = 0;\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD attach failed\\n\");\r\n return;\r\n }\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_FS);\r\n do\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n if (frame % 2 == 0)\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource1, completionPtr);\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 1);\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource1, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n }\r\n else\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource2, completionPtr);\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 2);\r\n EVE_CoCmd_setBitmap(s_pHalContext, videoSource2, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n }\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n frame++;\r\n } while (EVE_Hal_rd32(s_pHalContext, completionPtr) != 0);\r\n}\r\n\r\n/**\r\n * @brief Test AVI video playback via REG_CMDB_WRITE/REG_CMDB_SPACE\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromCMDB()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Video display via command buffer\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_SOUND);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1024, NULL);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief AVI video playback via CMD buffer\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromCMDBwithLogoBeside()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Video display via command buffer with LOGO\");\r\n\r\n /* construct the DL and display */\r\n EVE_Util_loadImageFile(s_pHalContext, VIDEO_LOAD_ADDR, TEST_DIR VIDEO_PNG_LOGO, NULL, OPT_TRUECOLOR);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 1);\r\n EVE_CoCmd_setBitmap(s_pHalContext, VIDEO_LOAD_ADDR, ARGB8, VIDEO_PNG_LOGO_W, VIDEO_PNG_LOGO_H);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, VIDEO_LOGO_X * 16, VIDEO_LOGO_Y * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n EVE_CoDl_bitmapHandle(s_pHalContext, 0);\r\n EVE_CoDl_vertexTranslateX(s_pHalContext, VIDEO_VIDEO_X * 16);\r\n EVE_CoDl_vertexTranslateY(s_pHalContext, VIDEO_LOGO_Y * 16);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_OVERLAY | OPT_SOUND);\r\n EVE_Util_loadCmdFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1024, NULL);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Test AVI video playback via MediaFiFo and full screen\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromMediafifoFullscreen()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Video display via Media FIFO full screen\");\r\n\r\n /* start video playback, load the data into media fifo */\r\n EVE_MediaFifo_set(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, VIDEO_MEDIAFIFO_SZ); //address of the media fifo buffer\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_MEDIAFIFO | OPT_SOUND | OPT_FULLSCREEN);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1024, NULL);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Test AVI video playback via MediaFiFo and OPT_COMPLETEREG\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromMediafifowithCompletereg()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Video display via Media FIFO with OPT_COMPLETEREG\");\r\n\r\n /* start video playback, load the data into media fifo */\r\n EVE_MediaFifo_set(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, VIDEO_MEDIAFIFO_SZ);\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n uint32_t complete = 0;\r\n EVE_CoCmd_regRead(s_pHalContext, REG_OBJECT_COMPLETE, &complete);\r\n eve_printf_debug(\"REG_OBJECT_COMPLETE %ld\\n\", complete);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_MEDIAFIFO | OPT_SOUND | OPT_COMPLETEREG);\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1024, NULL);\r\n EVE_Hal_wr32(s_pHalContext, REG_OBJECT_COMPLETE, 1);\r\n eve_printf_debug(\"write 1 to REG_OBJECT_COMPLETE\\n\");\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Test AVI video playback via MediaFiFo and OPT_COMPLETEREG with fail condition\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromMediafifowithCompleteregFailcase()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Video display via Media FIFO with OPT_COMPLETEREG failcase\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n uint32_t complete = 0;\r\n EVE_CoCmd_regRead(s_pHalContext, REG_OBJECT_COMPLETE, &complete);\r\n eve_printf_debug(\"REG_OBJECT_COMPLETE %ld\\n\", complete);\r\n\r\n EVE_Util_loadRawFile(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, TEST_DIR VIDEO_FLOWERS_1024);\r\n EVE_CoCmd_mediaFifo(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, VIDEO_MEDIAFIFO_SZ); // set a mediafifo larger than data\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_READ, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_WRITE, 1024 * 400); // only pass part of video data to mediafifo\r\n\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_MEDIAFIFO | OPT_SOUND | OPT_COMPLETEREG);\r\n while (EVE_Hal_rd32(s_pHalContext, REG_MEDIAFIFO_READ) < 1024 * 400)\r\n ;\r\n\r\n EVE_Hal_wr32(s_pHalContext, REG_OBJECT_COMPLETE, 1);\r\n eve_printf_debug(\"write 1 to REG_OBJECT_COMPLETE\\n\");\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n if (s_pHalContext->CmdFault)\r\n {\r\n EVE_Util_coprocessorFaultRecover(s_pHalContext);\r\n }\r\n\r\n Draw_Text(s_pHalContext, \"Quit video play with partial data passed.\");\r\n EVE_Hal_wr32(s_pHalContext, REG_OBJECT_COMPLETE, 0);\r\n}\r\n\r\n/**\r\n * @brief video playback via frame by frame from Mediafifo\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_frameByFrameMediafifo()\r\n{\r\n const uint32_t completionPtr = RAM_G;\r\n const uint32_t videoSource = RAM_G + 4;\r\n uint32_t transfered = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video display frame by frame from Mediafifo\");\r\n\r\n /* start video playback, load the data into media fifo */\r\n EVE_MediaFifo_set(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, VIDEO_MEDIAFIFO_SZ); //address of the media fifo buffer\r\n\r\n EVE_CoCmd_videoStart(s_pHalContext, OPT_MEDIAFIFO); //initialize AVI video decode\r\n EVE_Util_loadMediaFile(s_pHalContext, TEST_DIR VIDEO_FLOWERS_1024, &transfered);\r\n do\r\n {\r\n EVE_CoCmd_videoFrame(s_pHalContext, videoSource, completionPtr);\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_setBitmap(s_pHalContext, 4, RGB565, VIDEO_FLOWERS_1024_W, VIDEO_FLOWERS_1024_H);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(VIDEO_DELAY_MS);\r\n if (s_pHalContext->LoadFileRemaining > 0)\r\n EVE_Util_loadMediaFile(s_pHalContext, NULL, &transfered);\r\n } while ((EVE_Hal_rd32(s_pHalContext, completionPtr) != 0) && (EVE_MediaFifo_space(s_pHalContext) != VIDEO_MEDIAFIFO_SZ - 4)); //loop till end of the file\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_MediaFifo_close(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API demonstrating looping video playback from Mediafifo with stop button.\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video_fromMediafifoLoop()\r\n{\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = VIDEO_FLOWERS_1024_W / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H + VIDEO_BTN_Y_INC;\r\n bool stop = false;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Looping Mediafifo video playback with stop button\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n EVE_Util_loadRawFile(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, TEST_DIR VIDEO_FLOWERS_1024);\r\n EVE_CoCmd_mediaFifo(s_pHalContext, VIDEO_MEDIAFIFO_ADDR, 5000 * 1024); // set a mediafifo larger than data\r\n while (!stop)\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, \"STOP VIDEO\");\r\n\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_READ, 0);\r\n EVE_CoCmd_regWrite(s_pHalContext, REG_MEDIAFIFO_WRITE, 5000 * 1024);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_MEDIAFIFO | OPT_SOUND | OPT_OVERLAY);\r\n\r\n while (EVE_Cmd_space(s_pHalContext) != EVE_CMD_FIFO_SPACE)\r\n {\r\n uint32_t touch = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_SCREEN_XY);\r\n uint32_t touch_x = touch >> 16;\r\n uint32_t touch_y = touch & 0xFFFF;\r\n if ((touch_x > btnX) && (touch_x < (btnX + btnW)) && (touch_y > btnY) && (touch_y < (btnY + btnH)))\r\n {\r\n stop = true;\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, -1);\r\n break;\r\n }\r\n }\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n if (stop == true)\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, 1); // restore default value\r\n }\r\n}\r\n\r\nstatic void test()\r\n{\r\n uint32_t btnW = VIDEO_BTN_W;\r\n uint32_t btnH = VIDEO_BTN_H;\r\n uint32_t btnX = 1920 / 2 - btnW / 2;\r\n uint32_t btnY = VIDEO_FLOWERS_1024_H + VIDEO_BTN_Y_INC;\r\n //static bool isPause = 0;\r\n static bool pressed = 0;\r\n uint32_t result = 0;\r\n\r\n Draw_Text(s_pHalContext, \"Example for: Video display from SD card with stop button\");\r\n\r\n //EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n //eve_printf_debug(\"SD attach status 0x%x \\n\", result);\r\n //if (result != 0)\r\n //{\r\n // eve_printf_debug(\"SD attach failed\\n\");\r\n // return;\r\n //}\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%x \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n /*** Show a button ***/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0, 0, 0 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_button(s_pHalContext, btnX, btnY, btnW, btnH, VIDEO_TITLE_FONT, 0, \"stop\");\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FS | OPT_YCBCR | OPT_OVERLAY);\r\n while (EVE_Cmd_space(s_pHalContext) != EVE_CMD_FIFO_SPACE)\r\n {\r\n uint32_t touch = EVE_Hal_rd32(s_pHalContext, REG_TOUCH_SCREEN_XY);\r\n uint32_t touch_x = touch >> 16;\r\n uint32_t touch_y = touch & 0xFFFF;\r\n //only change the button when a release happened\r\n if ((touch_x > btnX) && (touch_x < (btnX + btnW)) && (touch_y > btnY) && (touch_y < (btnY + btnH)))\r\n {\r\n pressed = 1;\r\n }\r\n else\r\n {\r\n if (pressed)\r\n {\r\n pressed = 0;\r\n //isPause = !isPause;\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, -1);\r\n }\r\n }\r\n }\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_sleep(10);\r\n EVE_Hal_wr32(s_pHalContext, REG_PLAY_CONTROL, 1); // restore default value\r\n}\r\n\r\nstatic void test1()\r\n{\r\n uint32_t result = 0;\r\n Draw_Text(s_pHalContext, \"Example for: test\");\r\n\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_JPG, &result);\r\n eve_printf_debug(\"file read status 0x%lx \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n#if 1\r\n result = 0;\r\n //EVE_CoCmd_getPtr(s_pHalContext, &result);\r\n //printf(\">>>image ptr 0x%x\\n\", result);\r\n EVE_CoCmd_loadImage(s_pHalContext, 0, OPT_FS | OPT_YCBCR);\r\n //EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n //EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n#endif\r\n#if 1\r\n EVE_CoCmd_fsSource(s_pHalContext, VIDEO_AVI, &result);\r\n eve_printf_debug(\"file read status 0x%lx \\n\", result);\r\n if (result != 0)\r\n {\r\n eve_printf_debug(\"SD read failed\\n\");\r\n return;\r\n }\r\n\r\n helperSetVolume(s_pHalContext, VIDEO_VOL, VIDEO_VOL);\r\n eve_printf_debug(\"Video playback starts.\\n\");\r\n result = 0;\r\n EVE_CoCmd_getPtr(s_pHalContext, &result);\r\n printf(\">>>video ptr 0x%x\\n\", result);\r\n EVE_CoCmd_playVideo(s_pHalContext, OPT_FS | OPT_SOUND | OPT_TRUECOLOR | OPT_OVERLAY);\r\n\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n#else\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n#endif\r\n EVE_CoCmd_setBitmap(s_pHalContext, 0, YCBCR, 1920, 1200);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, 0, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n Display_End(s_pHalContext);\r\n EVE_sleep(5000);\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all video demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Video()\r\n{\r\n\t#if 0\r\n int count = 0;\r\n uint32_t result = 0;\r\n EVE_CoCmd_sdAttach(s_pHalContext, OPT_4BIT | OPT_IS_SD, &result);\r\n\r\n while (1)\r\n {\r\n printf(\"\\ntest: %d\\n\", count++);\r\n test1();\r\n }\r\n\t#endif\r\n SAMAPP_Video_fromFlashFullScreen();\r\n SAMAPP_Video_frameByFrameFromFlash();\r\n SAMAPP_Video_frameByFrameFlashPauseResume();\r\n SAMAPP_Video_frameByFrameFlashLoop();\r\n SAMAPP_Video_fromFileDirect();\r\n SAMAPP_Video_fromSD();\r\n SAMAPP_Video_fromSDPauseResume();\r\n SAMAPP_Video_fromSDbackground();\r\n SAMAPP_Video_frameByFrameSDPauseResume();\r\n SAMAPP_Video_frameByFrameSDBufferSwap();\r\n SAMAPP_Video_fromCMDB();\r\n SAMAPP_Video_fromCMDBwithLogoBeside();\r\n SAMAPP_Video_fromMediafifoFullscreen();\r\n SAMAPP_Video_fromMediafifowithCompletereg();\r\n SAMAPP_Video_fromMediafifowithCompleteregFailcase();\r\n SAMAPP_Video_frameByFrameMediafifo();\r\n SAMAPP_Video_fromMediafifoLoop();\r\n}"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"sample_id": "sampleapp_widget",
|
|
70
|
+
"relative_path": "SampleApp/Widget/Src/Widget.c",
|
|
71
|
+
"ext": ".c",
|
|
72
|
+
"content": "/**\r\n * @file Widget.c\r\n * @brief Sample usage of some widgets\r\n *\r\n * @author Bridgetek\r\n *\r\n * @date 2024\r\n * \r\n * MIT License\r\n *\r\n * Copyright (c) [2024] [Bridgetek Pte Ltd (BRTChip)]\r\n * \r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\n#include \"Widget.h\"\r\n#include \"EvePatch.h\"\r\n\r\n#define SAMAPP_DELAY_MS 2000\r\n#define SAMAPP_DELAY EVE_sleep(SAMAPP_DELAY_MS)\r\n#define WIDGET_LOAD_ADDR RAM_G\r\n#define WIDGET_TITLE_FONT_LARGE 33\r\n#define WIDGET_TITLE_FONT 31\r\n#define WIDGET_TITLE_FONT_SMALL 29\r\n#define WIDGET_TITLE_Y_INC 25\r\n#define WIDGET_LOOP 600\r\n#define WIDGET_DELAY_MS 10\r\n#define WIDGET_X_INC1 10\r\n#define WIDGET_X_INC2 20\r\n#define WIDGET_Y_INC1 5\r\n#define WIDGET_Y_INC2 40\r\n#define WIDGET_LINE_W 10\r\n#define WIDGET_COLOR_GREEN 0xBFD1C4\r\n#define WIDGET_COLOR_RED 0xB95756\r\n#define WIDGET_COLOR_PINK 0xED78C1\r\n#define WIDGET_COLOR_GREY 0x919191\r\n#define WIDGET_COLOR_ORANGE 0xFEC37D\r\n#define WIDGET_COLOR_BLUE 0x2E43B5\r\n#define WIDGET_COLOR_PURPLE 0x8C2AED\r\n#define WIDGET_COLOR_WHITE 0xFFFFFF\r\n#define WIDGET_COLOR_YELLOW 0xFFFD55\r\n#define WIDGET_GRAD_W 100\r\n#define WIDGET_CG_X 100\r\n#define WIDGET_CG_Y 100\r\n#define WIDGET_BTN_W 80\r\n#define WIDGET_BTN_H 80\r\n#define WIDGET_BTN_Y_INC 5\r\n#define WIDGET_ARC_COLOR_NUM 10\r\n#define WIDGET_ARC_R 30\r\n#define WIDGET_ARC_W 8\r\n#define WIDGET_GLOW_W 400\r\n#define WIDGET_GLOW_H 250\r\n\r\nstatic EVE_HalContext s_halContext;\r\nstatic EVE_HalContext* s_pHalContext;\r\nstatic void SAMAPP_Widget();\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n s_pHalContext = &s_halContext;\r\n Gpu_Init(s_pHalContext);\r\n Display_Config(s_pHalContext, YCBCR, MODE_PICTURE);\r\n\r\n if (EVE_Load_Patch(s_pHalContext, PATCH_BASE) != 0)\r\n eve_printf_debug(\"load patch failed\\n\");\r\n else\r\n eve_printf_debug(\"load patch ok\\n\");\r\n\r\n // read and store calibration setting\r\n#if GET_CALIBRATION == 1\r\n EVE_Calibrate(s_pHalContext);\r\n Calibration_Save(s_pHalContext);\r\n#endif\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n\r\n char *info[] =\r\n { \"EVE Sample Application\",\r\n \"This sample demonstrates the use of basic widgets\", \r\n \"\",\r\n \"\"\r\n };\r\n WelcomeScreen(s_pHalContext, info);\r\n\r\n SAMAPP_Widget();\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n Gpu_Release(s_pHalContext);\r\n return 0;\r\n}\r\n\r\n/**\r\n * @brief Show logo\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_logo()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Showing logo\");\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n\r\n EVE_CoCmd_logo(s_pHalContext);\r\n\r\n EVE_CoDl_display(s_pHalContext);\r\n EVE_Cmd_waitLogo(s_pHalContext);\r\n\r\n eve_printf_debug(\"Logo animation has finished playing.\\n\");\r\n\r\n SAMAPP_DELAY;\r\n EVE_Util_clearScreen(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief demonstrate clock widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_clock()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: clock widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of clock function. Clocks can be */\r\n /* constructed using flat or 3d effect. Clock background and foreground */\r\n /* colors can be set by gbcolor and colorrgb. Clock can be constructed */\r\n /* with multiple options such as no background, no needles, no pointer. */\r\n /*************************************************************************/\r\n int16_t xOffset;\r\n int16_t yOffset;\r\n uint16_t radius;\r\n int16_t xDistBtwClocks;\r\n\r\n xDistBtwClocks = (int16_t) (s_pHalContext->Width / 5);\r\n radius = xDistBtwClocks / 2 - (int16_t) (s_pHalContext->Width / 64);\r\n\r\n /* Download the bitmap data for lena faced clock */\r\n EVE_Util_loadRawFile(s_pHalContext, WIDGET_LOAD_ADDR, TEST_DIR WIDGET_BITMAP);\r\n\r\n /* Draw clock with blue as background and rad as needle color */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* flat effect and default color background */\r\n xOffset = xDistBtwClocks / 2;\r\n yOffset = radius + WIDGET_Y_INC1;\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_FLAT, 10, 10, 5, 10); // 10:10:05\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + radius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"Flat effect\"); //text info\r\n\r\n /* no seconds needle */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_PURPLE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_NOSECS, 10, 10, 5, 10); // 10:10:05\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + radius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No Secs\"); //text info\r\n\r\n /* no background color */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_NOBACK, 10, 10, 5, 10); // 10:10:05\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + radius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No BG\"); //text info\r\n\r\n /* No ticks */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_PINK);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_NOTICKS, 10, 10, 5, 10); // 10:10:05\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + radius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No Ticks\"); //text info\r\n\r\n /* No hands */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_NOHANDS, 10, 10, 5, 10); // 10:10:05\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + radius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No Hands\"); //text info\r\n yOffset += radius + 2 * WIDGET_TITLE_Y_INC;\r\n\r\n /* Bigger clock */\r\n radius = (int16_t)(s_pHalContext->Height - (WIDGET_Y_INC1 + 2 * radius + 2 * WIDGET_TITLE_Y_INC)); //calculate radius based on remaining height\r\n radius = (radius - 2 * WIDGET_Y_INC1) / 2;\r\n xOffset = radius + WIDGET_X_INC1;\r\n yOffset += radius + WIDGET_Y_INC1;\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, 0, 10, 10, 5, 10); // 10:10:05\r\n\r\n xOffset += 2 * radius + WIDGET_X_INC1;\r\n /* Lena clock with no background and no ticks */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 1);\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_lineWidth(s_pHalContext, WIDGET_LINE_W * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xOffset - radius + WIDGET_LINE_W) * 16, (yOffset - radius + WIDGET_LINE_W) * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xOffset + radius - WIDGET_LINE_W) * 16, (yOffset + radius - WIDGET_LINE_W) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1);\r\n EVE_CoDl_blendFunc(s_pHalContext, DST_ALPHA, ONE_MINUS_DST_ALPHA);\r\n /* Lena bitmap - scale proportionately wrt output resolution */\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_scale(s_pHalContext, 65536 * 2 * radius / WIDGET_BITMAP_W, 65536 * 2 * radius / WIDGET_BITMAP_H);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapSource(s_pHalContext, WIDGET_LOAD_ADDR);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, WIDGET_BITMAP_FORMAT, 3 * WIDGET_BITMAP_W, WIDGET_BITMAP_H);\r\n EVE_CoDl_bitmapSize(s_pHalContext, BILINEAR, BORDER, BORDER, 2 * radius, 2 * radius);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xOffset - radius) * 16, (yOffset - radius) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n // reset to default value\r\n EVE_CoDl_blendFunc_default(s_pHalContext);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoCmd_clock(s_pHalContext, xOffset, yOffset, radius, OPT_NOTICKS | OPT_NOBACK, 10, 10, 5, 10); // 10:10:05\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate a gauge widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_gauge()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: gauge widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of gauge function. Gauge can be */\r\n /* constructed using flat or 3d effect. Gauge background and foreground */\r\n /* colors can be set by gbcolor and colorrgb. Gauge can be constructed */\r\n /* with multiple options such as no background, no minors/majors and */\r\n /* no pointer. */\r\n /*************************************************************************/\r\n int16_t xOffset;\r\n int16_t yOffset;\r\n int16_t cRadius;\r\n int16_t xDistBtwClocks;\r\n\r\n xDistBtwClocks = (int16_t) (s_pHalContext->Width / 5);\r\n cRadius = xDistBtwClocks / 2 - (int16_t) (s_pHalContext->Width / 64);\r\n\r\n /* Download the bitmap data */\r\n EVE_Util_loadRawFile(s_pHalContext, WIDGET_LOAD_ADDR, TEST_DIR WIDGET_BITMAP);\r\n\r\n /* Draw gauge with blue as background and read as needle color */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* flat effect and default color background */\r\n xOffset = xDistBtwClocks / 2;\r\n yOffset = cRadius + WIDGET_Y_INC1;\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_FLAT, 5, 4, 45, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + cRadius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"Flat effect\"); //text info\r\n\r\n /* 3d effect */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_PURPLE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, 0, 5, 1, 60, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + cRadius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"3d effect\"); //text info\r\n\r\n /* no background color */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_NOBACK, 1, 6, 90, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + cRadius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No BG\"); //text info\r\n\r\n /* No ticks */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_PINK);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_NOTICKS, 5, 4, 20, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + cRadius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No Ticks\"); //text info\r\n\r\n /* No hands */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += xDistBtwClocks;\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_NOPOINTER, 5, 4, 55, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + cRadius + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTER, \"No Hands\"); //text info\r\n yOffset += cRadius + 2 * WIDGET_TITLE_Y_INC;\r\n\r\n /* Bigger gauge */\r\n cRadius = (int16_t)(s_pHalContext->Height - (WIDGET_Y_INC1 + 2 * cRadius + 2 * WIDGET_TITLE_Y_INC)); //calculate radius based on remaining height\r\n cRadius = (cRadius - 2 * WIDGET_Y_INC1) / 2;\r\n xOffset = cRadius + WIDGET_X_INC1;\r\n yOffset += cRadius + WIDGET_Y_INC1;\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_NOTICKS | OPT_NOBACK, 5, 4, 30, 100);\r\n\r\n xOffset += 2 * cRadius + WIDGET_X_INC1;\r\n /* Lena gauge with no background and no ticks */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 1);\r\n EVE_CoDl_begin(s_pHalContext, POINTS);\r\n EVE_CoDl_pointSize(s_pHalContext, cRadius * 16);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, xOffset * 16, yOffset * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1);\r\n EVE_CoDl_blendFunc(s_pHalContext, DST_ALPHA, ONE_MINUS_DST_ALPHA);\r\n /* Lena bitmap - scale proportionately wrt output resolution */\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_scale(s_pHalContext, 65536 * 2 * cRadius / WIDGET_BITMAP_W, 65536 * 2 * cRadius / WIDGET_BITMAP_H);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapSource(s_pHalContext, WIDGET_LOAD_ADDR);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, WIDGET_BITMAP_FORMAT, 3 * WIDGET_BITMAP_W, WIDGET_BITMAP_H);\r\n EVE_CoDl_bitmapSize(s_pHalContext, BILINEAR, BORDER, BORDER, 2 * cRadius, 2 * cRadius);\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (xOffset - cRadius) * 16, (yOffset - cRadius) * 16);\r\n EVE_CoDl_end(s_pHalContext);\r\n // reset to default value\r\n EVE_CoDl_blendFunc_default(s_pHalContext);\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoCmd_gauge(s_pHalContext, xOffset, yOffset, cRadius, OPT_NOTICKS | OPT_NOBACK, 5, 4, 30,\r\n 100);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate gradient widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_gradient()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: gradient widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of gradient function. Gradient func */\r\n /* can be used to construct three effects - horizontal, vertical and */\r\n /* diagonal effects. */\r\n /*************************************************************************/\r\n int16_t wScissor;\r\n int16_t hScissor;\r\n int16_t xOffset;\r\n int16_t yOffset;\r\n\r\n xOffset = WIDGET_X_INC2;\r\n yOffset = WIDGET_Y_INC2;\r\n hScissor = (int16_t)((s_pHalContext->Height - 3 * yOffset) / 2);\r\n wScissor = (int16_t)((s_pHalContext->Width - 4 * xOffset) / 3);\r\n\r\n /* Draw gradient */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n /* Horizontal gradient effect */\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_GREY, (xOffset + wScissor), yOffset, WIDGET_COLOR_YELLOW);\r\n\r\n /* Vertical gradient effect */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_RED, xOffset, (yOffset + hScissor), WIDGET_COLOR_GREEN);\r\n\r\n /* diagonal gradient effect */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_PINK, (xOffset + wScissor), (yOffset + hScissor), WIDGET_COLOR_WHITE);\r\n\r\n EVE_CoDl_scissorXY(s_pHalContext, 0, 0); //set to default values\r\n EVE_CoDl_scissorSize(s_pHalContext, 2048, 2048);\r\n // text info\r\n xOffset = WIDGET_X_INC2;\r\n yOffset = WIDGET_Y_INC2 + hScissor + WIDGET_TITLE_Y_INC;\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"Horizontal grad\");\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"Vertical grad\");\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"Diagonal grad\");\r\n\r\n /* Diagonal gradient with text info */\r\n xOffset = WIDGET_X_INC2;\r\n yOffset += WIDGET_Y_INC2;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, WIDGET_Y_INC2);\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, (yOffset + hScissor / 2 - WIDGET_Y_INC2 / 2)); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, (yOffset + hScissor / 2 - WIDGET_Y_INC2 / 2), WIDGET_COLOR_GREY,\r\n (xOffset + wScissor), (yOffset + hScissor / 2 + WIDGET_Y_INC2 / 2), WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_text(s_pHalContext, (xOffset + wScissor / 2), (yOffset + hScissor / 2), WIDGET_TITLE_FONT,\r\n OPT_CENTER, \"Gradient Gradient Gradient\"); //text info\r\n\r\n /* Draw horizontal, vertical and diagonal */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_GREY, (xOffset + wScissor), yOffset, WIDGET_COLOR_YELLOW);\r\n wScissor -= WIDGET_GRAD_W;\r\n hScissor -= WIDGET_GRAD_W;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n xOffset += WIDGET_GRAD_W / 2;\r\n yOffset += WIDGET_GRAD_W / 2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_PINK, xOffset, (yOffset + hScissor), WIDGET_COLOR_WHITE);\r\n wScissor -= WIDGET_GRAD_W;\r\n hScissor -= WIDGET_GRAD_W;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n xOffset += WIDGET_GRAD_W / 2;\r\n yOffset += WIDGET_GRAD_W / 2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradient(s_pHalContext, xOffset, yOffset, WIDGET_COLOR_GREY, (xOffset + wScissor), (yOffset + hScissor), WIDGET_COLOR_PURPLE);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_GRADIENTA with transparency\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_gradientA()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: gradient widget with transparency\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of gradient function. Gradient func */\r\n /* can be used to construct three effects - horizontal, vertical and */\r\n /* diagonal effects. */\r\n /*************************************************************************/\r\n /*GradientA */\r\n int16_t wScissor;\r\n int16_t hScissor;\r\n int16_t xOffset;\r\n int16_t yOffset;\r\n\r\n xOffset = WIDGET_X_INC2;\r\n yOffset = WIDGET_Y_INC2;\r\n hScissor = (int16_t)((s_pHalContext->Height - 3 * yOffset) / 2);\r\n wScissor = (int16_t)((s_pHalContext->Width - 4 * xOffset) / 3);\r\n /* Draw gradient */\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n /* Horizontal gradient effect */\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Horizontal gradient\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor * 3 / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Horizontal gradient\"); //text info\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_GREY, (xOffset + wScissor), yOffset,\r\n 0xFF000000 | WIDGET_COLOR_YELLOW);\r\n /* Vertical gradient effect */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Vertical gradient\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor * 3 / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Vertical gradient\"); //text info\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_RED, xOffset, (yOffset + hScissor),\r\n 0xFF000000 | WIDGET_COLOR_GREEN);\r\n /* diagonal gradient effect */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Diagonal gradient\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + hScissor * 3 / 4, WIDGET_TITLE_FONT, 0, \"GradientA: Diagonal gradient\"); //text info\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_PINK, (xOffset + wScissor),\r\n (yOffset + hScissor), 0xFF000000 | WIDGET_COLOR_WHITE);\r\n /* Diagonal gradient with text info */\r\n xOffset = WIDGET_X_INC2;\r\n yOffset += hScissor + WIDGET_Y_INC2;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, WIDGET_Y_INC2);\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, (yOffset + hScissor / 2 - WIDGET_Y_INC2 / 2)); //clip the display\r\n EVE_CoCmd_text(s_pHalContext, (xOffset + wScissor / 2), (yOffset + hScissor / 2), WIDGET_TITLE_FONT,\r\n OPT_CENTER, \"GradientA GradientA GradientA\"); //text info\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, (yOffset + hScissor / 2 - WIDGET_Y_INC2 / 2), 0x00000000 | WIDGET_COLOR_GREY,\r\n (xOffset + wScissor), (yOffset + hScissor / 2 + WIDGET_Y_INC2 / 2), 0xFF000000 | WIDGET_COLOR_BLUE);\r\n\r\n /* Draw horizontal, vertical and diagonal with alpha */\r\n xOffset += wScissor + WIDGET_X_INC2;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + hScissor / 4), WIDGET_TITLE_FONT, 0, \"GradientA GradientA\"); //text info\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + hScissor * 3 / 4), WIDGET_TITLE_FONT, 0, \"GradientA GradientA\"); //text info\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_GREY, (xOffset + wScissor), yOffset,\r\n 0xFF000000 | WIDGET_COLOR_YELLOW);\r\n wScissor -= WIDGET_GRAD_W;\r\n hScissor -= WIDGET_GRAD_W;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n xOffset += WIDGET_GRAD_W / 2;\r\n yOffset += WIDGET_GRAD_W / 2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_PINK, xOffset, (yOffset + hScissor),\r\n 0xFF000000 | WIDGET_COLOR_WHITE);\r\n wScissor -= WIDGET_GRAD_W;\r\n hScissor -= WIDGET_GRAD_W;\r\n EVE_CoDl_scissorSize(s_pHalContext, wScissor, hScissor);\r\n xOffset += WIDGET_GRAD_W / 2;\r\n yOffset += WIDGET_GRAD_W / 2;\r\n EVE_CoDl_scissorXY(s_pHalContext, xOffset, yOffset); //clip the display\r\n EVE_CoCmd_gradientA(s_pHalContext, xOffset, yOffset, 0x80000000 | WIDGET_COLOR_GREY, (xOffset + wScissor),\r\n (yOffset + hScissor), 0xFF000000 | WIDGET_COLOR_PURPLE);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate CMD_CGRADIENT\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_cgradient()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: circular gradient widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of cgradient function. The cgradient */\r\n /* command draws a rectangle containing a circular gradient, smoothly */\r\n /* blending between one color in the center and another at the corner or */\r\n /* edge. */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 77, 77, 77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_cgradient(s_pHalContext, CORNER_ZERO, WIDGET_CG_X, WIDGET_CG_Y, s_pHalContext->Width / 6, s_pHalContext->Width / 6,\r\n WIDGET_COLOR_RED, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_text(s_pHalContext, WIDGET_CG_X, WIDGET_CG_X + s_pHalContext->Width / 6 + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"CORNER_ZERO\");\r\n EVE_CoCmd_cgradient(s_pHalContext, EDGE_ZERO, s_pHalContext->Width / 2, WIDGET_CG_Y, s_pHalContext->Width / 6, s_pHalContext->Width / 6,\r\n WIDGET_COLOR_RED, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, WIDGET_CG_X + s_pHalContext->Width / 6 + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"EDGE_ZERO\");\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief Key interactive\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_keysInteractive()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Key interactive\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of keys function. keys function */\r\n /* draws buttons with characters given as input parameters. Keys support */\r\n /* Flat and 3D effects, draw at (x,y) coordinates or center of the display*/\r\n /* , inbuilt or custom fonts can be used for key display */\r\n /*************************************************************************/\r\n int32_t loopflag = WIDGET_LOOP;\r\n uint16_t TextFont = WIDGET_TITLE_FONT_LARGE;\r\n int16_t ButtonW = WIDGET_BTN_W;\r\n int16_t ButtonH = WIDGET_BTN_H;\r\n int16_t yBtnDst = WIDGET_BTN_Y_INC;\r\n int16_t yOffset;\r\n#define SAMAPP_COPRO_WIDGET_KEYS_INTERACTIVE_TEXTSIZE (512)\r\n char DispText[SAMAPP_COPRO_WIDGET_KEYS_INTERACTIVE_TEXTSIZE];\r\n char CurrChar = '|';\r\n uint32_t CurrTag = 0;\r\n uint32_t PrevTag = 0;\r\n uint8_t Pendown = 1;\r\n int32_t CurrTextIdx = 0;\r\n\r\n while (loopflag--)\r\n {\r\n /* Check the user input and then add the characters into array */\r\n EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &CurrTag);\r\n\r\n CurrChar = (char)CurrTag;\r\n if (0 == CurrTag)\r\n {\r\n CurrChar = '|';\r\n }\r\n\r\n /* check whether pwndown has happened */\r\n if (!CurrTag && PrevTag && 1 == Pendown && 0 != PrevTag)\r\n {\r\n CurrTextIdx++;\r\n /* clear all the charaters */\r\n if (CurrTextIdx > 24)\r\n {\r\n CurrTextIdx = 0;\r\n }\r\n }\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw text entered by user */\r\n /* make sure the array is a string */\r\n DispText[CurrTextIdx] = CurrChar;\r\n DispText[CurrTextIdx + 1] = '\\0';\r\n\r\n EVE_CoDl_tagMask(s_pHalContext, 0);\r\n yOffset = WIDGET_Y_INC2 + WIDGET_TITLE_Y_INC;\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_Y_INC2 + WIDGET_TITLE_Y_INC, TextFont,\r\n OPT_CENTER, DispText); //text info\r\n EVE_CoDl_tagMask(s_pHalContext, 1);\r\n\r\n yOffset += WIDGET_Y_INC2;\r\n /* Construct a simple keyboard - note that the tags associated with the keys are the character values given in the arguments */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont,\r\n (OPT_CENTER | (uint16_t)CurrTag), \"qwertyuiop\");\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont,\r\n (OPT_CENTER | (uint16_t)CurrTag), \"asdfghjkl\");\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont,\r\n (OPT_CENTER | (uint16_t)CurrTag), \"zxcvbnm\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoDl_tag(s_pHalContext, ' ');\r\n if (' ' == CurrTag)\r\n {\r\n EVE_CoCmd_button(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont,\r\n OPT_FLAT, \" \"); //mandatory to give '\\0' at the end to make sure coprocessor understands the string end\r\n }\r\n else\r\n {\r\n EVE_CoCmd_button(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont, 0,\r\n \" \"); //mandatory to give '\\0' at the end to make sure coprocessor understands the string end\r\n }\r\n yOffset = ButtonW + WIDGET_TITLE_Y_INC;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont,\r\n (0 | (uint16_t)CurrTag), \"789\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont,\r\n (0 | (uint16_t)CurrTag), \"456\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont,\r\n (0 | (uint16_t)CurrTag), \"123\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont,\r\n (0 | (uint16_t)CurrTag), \"0.\"); //hilight button 0\r\n Display_End(s_pHalContext);\r\n EVE_sleep(WIDGET_DELAY_MS);\r\n PrevTag = CurrTag;\r\n }\r\n}\r\n\r\n/**\r\n * @brief keys widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_keys()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Keys widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of keys function. keys function */\r\n /* draws buttons with characters given as input parameters. Keys support */\r\n /* Flat and 3D effects, draw at (x,y) coordinates or center of the display*/\r\n /* , inbuilt or custom fonts can be used for key display */\r\n /*************************************************************************/\r\n uint16_t TextFont = WIDGET_TITLE_FONT_LARGE;\r\n int16_t ButtonW = WIDGET_BTN_W;\r\n int16_t ButtonH = WIDGET_BTN_H;\r\n int16_t yBtnDst = WIDGET_BTN_Y_INC;\r\n int16_t yOffset;\r\n int16_t xOffset;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_lineWidth(s_pHalContext, 1 * 16);\r\n /* Draw keys with flat effect */\r\n xOffset = WIDGET_X_INC1;\r\n yOffset = WIDGET_Y_INC1 + ButtonH + WIDGET_TITLE_Y_INC;\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_keys(s_pHalContext, xOffset, WIDGET_Y_INC1, 4 * ButtonW, ButtonH, TextFont, OPT_FLAT, \"ABCD\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"Flat effect\"); //text info\r\n /* Draw keys with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n xOffset += 4 * ButtonW + WIDGET_X_INC2;\r\n EVE_CoCmd_keys(s_pHalContext, xOffset, WIDGET_Y_INC1, 4 * ButtonW, ButtonH, TextFont, 0, \"ABCD\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"3D effect\"); //text info\r\n /* Draw keys with center option */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n xOffset += 4 * ButtonW + WIDGET_X_INC2;\r\n EVE_CoCmd_keys(s_pHalContext, xOffset, WIDGET_Y_INC1, 4 * ButtonW, ButtonH, TextFont, OPT_CENTER, \"ABCD\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset, WIDGET_TITLE_FONT, OPT_CENTERY, \"Option Center\"); //text info\r\n\r\n yOffset += WIDGET_Y_INC2;\r\n /* Construct a simple keyboard - note that the tags associated with the keys are the character values given in the arguments */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont, OPT_CENTER,\r\n \"qwertyuiop\");\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont, OPT_CENTER,\r\n \"asdfghjkl\");\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 0, yOffset, 10 * ButtonW, ButtonH, TextFont,\r\n (OPT_CENTER | 'z'), \"zxcvbnm\"); //highlight button z\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_button(s_pHalContext, yBtnDst, yOffset, 10 * ButtonW, ButtonH, TextFont, 0, \" \"); //mandatory to give '\\0' at the end to make sure coprocessor understands the string end\r\n yOffset = WIDGET_Y_INC1 + ButtonH + WIDGET_TITLE_Y_INC + WIDGET_Y_INC2;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont, 0, \"789\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont, 0, \"456\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont, 0, \"123\");\r\n yOffset += ButtonH + yBtnDst;\r\n EVE_CoDl_colorA(s_pHalContext, 255);\r\n EVE_CoCmd_keys(s_pHalContext, 11 * ButtonW, yOffset, 3 * ButtonW, ButtonH, TextFont, (0 | '0'),\r\n \"0.\"); //highlight button 0\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate progress bar widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_progressbar()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Progress bar widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of progress function. Progress func */\r\n /* draws process bar with fgcolor for the % completion and bgcolor for */\r\n /* % remaining. Progress bar supports flat and 3d effets */\r\n /*************************************************************************/\r\n int16_t xOffset = WIDGET_X_INC2;\r\n int16_t yOffset = WIDGET_Y_INC2;\r\n int16_t yDist = (int16_t)(s_pHalContext->Height / 10);\r\n int16_t h = (int16_t)(s_pHalContext->Height / 24);\r\n int16_t w = (int16_t)(s_pHalContext->Width / 8);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw progress bar with flat effect */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, OPT_FLAT, 50, 100); //note that h/2 will be added on both sides of the progress bar\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"Flat effect\"); //text info\r\n\r\n /* Draw progress bar with 3d effect */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoCmd_progress(s_pHalContext, xOffset + 2 * w, yOffset, w, h, 0, 75, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset + 2 * w, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"3D effect\"); //text info\r\n\r\n /* Draw progress bar with 3d effect and string on top */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n yOffset += 2 * yDist;\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, 0, 19660, 65535);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoCmd_text(s_pHalContext, xOffset + w / 2, yOffset + h / 2, WIDGET_TITLE_FONT, OPT_CENTER, \"30 %\"); //text info\r\n\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n yOffset += yDist;\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, 0, 10, 100);\r\n\r\n EVE_CoCmd_progress(s_pHalContext, xOffset + 2 * w, yOffset, h, w, 0, 40, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset + 2 * w + h, yOffset, WIDGET_TITLE_FONT, 0, \"40 % TopBottom\"); //text info\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n yOffset += yDist;\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, 0, 40, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n yOffset += yDist;\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, 0, 70, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n yOffset += yDist;\r\n EVE_CoCmd_progress(s_pHalContext, xOffset, yOffset, w, h, 0, 90, 100);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate scroll widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_scroll()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: scroll widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of scroll function. Scroll function */\r\n /* draws scroll bar with fgcolor for inner color and current location and*/\r\n /* can be given by val parameter */\r\n /*************************************************************************/\r\n int16_t xOffset = WIDGET_X_INC2;\r\n int16_t yOffset = WIDGET_Y_INC2;\r\n int16_t xDist = (int16_t)(s_pHalContext->Width / 12);\r\n int16_t yDist = (int16_t)(s_pHalContext->Height / 10);\r\n int16_t w = (int16_t)(s_pHalContext->Width / 3);\r\n int16_t h = (int16_t)(s_pHalContext->Height / 50);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw scroll bar with flat effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w / 2, h, OPT_FLAT, 20, 30, 100); //note that h/2 size will be added on both sides of the progress bar\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"Flat effect\"); //text info\r\n\r\n /* Draw scroll bar with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n xOffset += w / 2 + WIDGET_X_INC2;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w / 2, h, 0, 20, 30, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"3D effect\"); //text info\r\n\r\n /* Draw horizontal scroll bars */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n xOffset = WIDGET_X_INC2;\r\n yOffset += 2 * yDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w, h, 0, 10, 20, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n yOffset += yDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w, h, 0, 30, 20, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n yOffset += yDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w, h, 0, 50, 20, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n yOffset += yDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, w, h, 0, 70, 20, 100);\r\n\r\n xOffset = s_pHalContext->Width / 2;\r\n yOffset = WIDGET_Y_INC2;\r\n /* draw vertical scroll bars */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, h, w, 0, 10, 10, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n xOffset += xDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, h, w, 0, 30, 20, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += xDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, h, w, 0, 50, 30, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n xOffset += xDist;\r\n EVE_CoCmd_scrollbar(s_pHalContext, xOffset, yOffset, h, w, 0, 70, 30, 100);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate slider widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_slider()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Slider widget\");\r\n \r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of slider function. Slider function */\r\n /* draws slider bar with fgcolor for inner color and bgcolor for the knob*/\r\n /* , contains input parameter for position of the knob */\r\n /*************************************************************************/\r\n int16_t xOffset = WIDGET_X_INC2;\r\n int16_t yOffset = WIDGET_Y_INC2;\r\n int16_t xDist = (int16_t)(s_pHalContext->Width / 12);\r\n int16_t yDist = (int16_t)(s_pHalContext->Height / 10);\r\n int16_t w = (int16_t)(s_pHalContext->Width / 3);\r\n int16_t h = (int16_t)(s_pHalContext->Height / 50);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw scroll bar with flat effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w / 2, h, OPT_FLAT, 30, 100); //note that h/2 size will be added on both sides of the progress bar\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"Flat effect\"); //text info\r\n\r\n /* Draw scroll bar with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n xOffset += w / 2 + WIDGET_X_INC2;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w / 2, h, 0, 50, 100);\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + h + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, 0, \"3D effect\"); //text info\r\n\r\n /* Draw horizontal slider bars */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n xOffset = WIDGET_X_INC2;\r\n yOffset += 2 * yDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w, h, 0, 10, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n yOffset += yDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w, h, 0, 30, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREY);\r\n yOffset += yDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w, h, 0, 50, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n yOffset += yDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, w, h, 0, 70, 100);\r\n\r\n xOffset = s_pHalContext->Width / 2;\r\n yOffset = WIDGET_Y_INC2;\r\n /* draw vertical slider bars */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, h, w, 0, 10, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n xOffset += xDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, h, w, 0, 30, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += xDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, h, w, 0, 50, 100);\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n xOffset += xDist;\r\n EVE_CoCmd_slider(s_pHalContext, xOffset, yOffset, h, w, 0, 70, 100);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate dial widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_dial()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Dial widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of dial function. Dial function */\r\n /* draws rounded bar with fgcolor for knob color and colorrgb for pointer*/\r\n /* , contains input parameter for angle of the pointer */\r\n /*************************************************************************/\r\n uint16_t r = (int16_t)(s_pHalContext->Width / 15);\r\n int16_t xOffset = WIDGET_X_INC2 + r;\r\n int16_t yOffset = (int16_t)(s_pHalContext->Height / 4);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw dial with flat effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, OPT_FLAT, (uint16_t) (0.2 * 65535)); //20%\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Flat effect\"); //text info\r\n\r\n /* Draw dial with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += 3 * r;\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, 0, (uint16_t)(0.45 * 65535)); //45%\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"3D effect\"); //text info\r\n\r\n /* Draw increasing dials horizontally */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n xOffset = WIDGET_X_INC2 + r;\r\n yOffset = (int16_t)(s_pHalContext->Height * 3 / 4);\r\n r = r / 2;\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, 0, (uint16_t)(0.30 * 65535));\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"30 %\"); //text info\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREY);\r\n xOffset += 3 * r;\r\n r = r * 3 / 2;\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, 0, (uint16_t) (0.45 * 65535));\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"45 %\"); //text info\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n xOffset += 3 * r;\r\n r = r * 3 / 2;\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, 0, (uint16_t) (0.60 * 65535));\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"60 %\"); //text info\r\n\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n xOffset += 3 * r;\r\n r = r * 3 / 2;\r\n EVE_CoCmd_dial(s_pHalContext, xOffset, yOffset, r, 0, (uint16_t) (0.75 * 65535));\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + r + WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"75 %\"); //text info\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate toggle widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_toggle()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Toggle widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of toggle function. Toggle function */\r\n /* draws line with inside knob to choose between left and right. Toggle */\r\n /* inside color can be changed by bgcolor and knob color by fgcolor. Left*/\r\n /* right texts can be written and the color of the text can be changed by*/\r\n /* colorrgb graphics function */\r\n /*************************************************************************/\r\n int16_t w = (int16_t)(s_pHalContext->Width / 15);\r\n int16_t xOffset = WIDGET_X_INC2 + w;\r\n int16_t yOffset = WIDGET_Y_INC2;\r\n int16_t yDist = (int16_t)(s_pHalContext->Height / 10);\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* Draw toggle with flat effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, OPT_FLAT, (uint16_t)(0.5 * 65535),\r\n \"no\\xffyes\"); //circle radius will be extended on both the horizontal sides\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + yDist, WIDGET_TITLE_FONT, 0, \"Flat effect\"); //text info\r\n\r\n /* Draw toggle bar with 3d effect */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n xOffset += 4 * w;\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, 0, 1 * 65535, \"stop\\xffrun\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, yOffset + yDist, WIDGET_TITLE_FONT, 0, \"3D effect\"); //text info\r\n\r\n /* Draw horizontal toggle bars */\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_PURPLE);\r\n xOffset = WIDGET_X_INC2 + w;\r\n yOffset += 2 * yDist;\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, 0, 0 * 65535, \"-ve\\xff+ve\");\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n yOffset += yDist;\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, 0, (uint16_t)(0.25 * 65535), \"zero\\xffone\");\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n yOffset += yDist;\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, 0, (uint16_t)(0.5 * 65535), \"exit\\xffinit\");\r\n\r\n EVE_CoCmd_bgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_WHITE);\r\n yOffset += yDist;\r\n EVE_CoCmd_toggle(s_pHalContext, xOffset, yOffset, w, WIDGET_TITLE_FONT, 0, (uint16_t)(0.75 * 65535), \"off\\xffon\");\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief demonstrate a spinner widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_spinner()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: Spinner widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of spinner function. Spinner func */\r\n /* will wait untill stop command is sent from the mcu. Spinner has option*/\r\n /* for displaying points in circle fashion or in a line fashion. */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 64, 64, 64 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Spinner circle\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), 4 * WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Please Wait ...\");\r\n EVE_CoCmd_spinner(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t) (s_pHalContext->Height / 2), 0, 1); //style 0 and scale 0\r\n\r\n /* Wait till coprocessor completes the operation */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n /* spinner with style 1 and scale 1 */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 64, 64, 64 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Spinner line\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), 4 * WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Please Wait ...\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_spinner(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t) (s_pHalContext->Height / 2), 1, 1); //style 1 and scale 1\r\n\r\n /* Wait till coprocessor completes the operation */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 64, 64, 64 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Spinner clockhand\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), 4 * WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Please Wait ...\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_spinner(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t) (s_pHalContext->Height / 2), 2, 1); //style 2 scale 1\r\n\r\n /* Wait till coprocessor completes the operation */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n Display_Start(s_pHalContext, (uint8_t[]) { 64, 64, 64 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Spinner two dots\");\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), 4 * WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER, \"Please Wait ...\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_spinner(s_pHalContext, (int16_t) (s_pHalContext->Width / 2),\r\n (int16_t) (s_pHalContext->Height / 2), 3, 1); //style 3 scale 0\r\n\r\n /* Wait till coprocessor completes the operation */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n /* Update the command buffer pointers - both read and write pointers */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate text widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_text()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: text widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of text function. Text function */\r\n /* draws text with either in built or externally configured text. Text */\r\n /* color can be changed by colorrgb and text function supports display of*/\r\n /* texts on left, right, top, bottom and center respectively */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0x00, 0x00, 0x00 }, 0, 4);\r\n /* Draw text at 0,0 location */\r\n EVE_CoCmd_text(s_pHalContext, 0, 0, WIDGET_TITLE_FONT, 0, \"Bridgetek!\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, 0, WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT_SMALL, 0, \"Text31 at 0,0\"); //text info\r\n\r\n /* text with centerx */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height / 8), WIDGET_TITLE_FONT, OPT_CENTERX, \"Bridgetek!\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Text31 centerX\"); //text info\r\n\r\n /* text with centery */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 5), (int16_t)(s_pHalContext->Height * 2 / 8), WIDGET_TITLE_FONT, OPT_CENTERY, \"Bridgetek!\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 5), (int16_t)(s_pHalContext->Height * 2 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Text31 centerY\"); //text info\r\n\r\n /* text with center */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height * 3 / 8), WIDGET_TITLE_FONT, OPT_CENTER, \"Bridgetek!\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height * 3 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Text31 center\"); //text info\r\n\r\n /* text with rightx */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_PURPLE);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)s_pHalContext->Width, (int16_t)(s_pHalContext->Height * 4 / 8), WIDGET_TITLE_FONT, OPT_RIGHTX, \"Bridgetek!\");\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width - 150), (int16_t)(s_pHalContext->Height * 4 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Text31 rightX\"); //text info\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate number widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_number()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: number widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of number function. Number function */\r\n /* draws text with only 32bit decimal number, signed or unsigned can also*/\r\n /* be specified as input parameter. Options like centerx, centery, center*/\r\n /* and rightx are supported */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 0x00, 0x00, 0x00 }, 0, 4);\r\n /* Draw number at 0,0 location */\r\n EVE_CoCmd_number(s_pHalContext, 0, 0, WIDGET_TITLE_FONT, 0, 1234);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, 0, WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT_SMALL, 0, \"Number31 at 0,0\"); //text info\r\n\r\n /* number with centerx */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_number(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height / 8), WIDGET_TITLE_FONT, OPT_CENTERX | OPT_SIGNED, -1234);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Number31 centerX\"); //text info\r\n\r\n /* number with centery */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_GREEN);\r\n EVE_CoCmd_number(s_pHalContext, (int16_t)(s_pHalContext->Width / 5), (int16_t)(s_pHalContext->Height * 2 / 8), WIDGET_TITLE_FONT, OPT_CENTERY, 1234);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 5), (int16_t)(s_pHalContext->Height * 2 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Number31 centerY\"); //text info\r\n\r\n /* number with center */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_ORANGE);\r\n EVE_CoCmd_number(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height * 3 / 8), WIDGET_TITLE_FONT, OPT_CENTER | OPT_SIGNED, -1234);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), (int16_t)(s_pHalContext->Height * 3 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Number31 center\"); //text info\r\n\r\n /* number with rightx */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_PURPLE);\r\n EVE_CoCmd_number(s_pHalContext, (int16_t)s_pHalContext->Width, (int16_t)(s_pHalContext->Height * 4 / 8), WIDGET_TITLE_FONT, OPT_RIGHTX, 1234);\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width - 200), (int16_t)(s_pHalContext->Height * 4 / 8 + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT_SMALL, 0, \"Number31 rightX\"); //text info\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate button functionality\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_button()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: button functionality\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of button function. Buttons can be */\r\n /* constructed using flat or 3d effect. Button color can be changed by */\r\n /* fgcolor command and text color is set by COLOR_RGB graphics command */\r\n /*************************************************************************/\r\n int16_t xOffset = WIDGET_X_INC2;\r\n int16_t yOffset = WIDGET_Y_INC2;\r\n int16_t xDist = (int16_t)(s_pHalContext->Width / 6);\r\n int16_t yDist = (int16_t)(s_pHalContext->Height / 8);\r\n int16_t w = WIDGET_BTN_W;\r\n int16_t h = WIDGET_BTN_W;\r\n\r\n /* Construct a buttons with \"ONE/TWO/THREE\" text and default background */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n /* flat effect and default color background */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n yOffset = (int16_t) (s_pHalContext->Height / 2 - 2 * yDist);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, OPT_FLAT, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, OPT_FLAT, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, OPT_FLAT, \"ABC\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + h + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTERY, \"Flat effect\"); //text info\r\n\r\n /* 3D effect */\r\n xOffset += xDist;\r\n yOffset = (int16_t)(s_pHalContext->Height / 2 - 2 * yDist);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + h + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTERY, \"3D Effect\"); //text info\r\n\r\n /* 3d effect with background color */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n xOffset += xDist;\r\n yOffset = (int16_t)(s_pHalContext->Height / 2 - 2 * yDist);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREEN);\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_PINK);\r\n yOffset += yDist;\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + h + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTERY, \"3D Color\"); //text info\r\n\r\n /* 3d effect with gradient color */\r\n EVE_CoCmd_fgColor(s_pHalContext, WIDGET_COLOR_GREY);\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_RED);\r\n xOffset += xDist;\r\n yOffset = (int16_t)(s_pHalContext->Height / 2 - 2 * yDist);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_YELLOW);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n yOffset += yDist;\r\n EVE_CoCmd_gradColor(s_pHalContext, WIDGET_COLOR_BLUE);\r\n EVE_CoCmd_button(s_pHalContext, xOffset, yOffset, w, h, WIDGET_TITLE_FONT, 0, \"ABC\");\r\n EVE_CoCmd_text(s_pHalContext, xOffset, (yOffset + h + WIDGET_TITLE_Y_INC), WIDGET_TITLE_FONT, OPT_CENTERY, \"3D Gradient\"); //text info\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate screen saver widget - playing of bitmap via macro0\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_screensaver()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: screen saver with an image\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of screensaver function. Screen */\r\n /* saver modifies macro0 with the vertex2f command. */\r\n /* MCU can display any static display list at the background with the */\r\n /* changing bitmap */\r\n /*************************************************************************/\r\n /* Download the bitmap data */\r\n EVE_Util_loadRawFile(s_pHalContext, WIDGET_LOAD_ADDR, TEST_DIR WIDGET_BITMAP);\r\n\r\n /* Copy the display list */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 2);\r\n /* lena bitmap */\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_scale(s_pHalContext, 3 * 65536, 3 * 65536); //scale the bitmap 3 times on both sides\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n /* Send command screen saver */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapSource(s_pHalContext, WIDGET_LOAD_ADDR);\r\n EVE_CoDl_bitmapLayout(s_pHalContext, WIDGET_BITMAP_FORMAT, 3 * WIDGET_BITMAP_W, WIDGET_BITMAP_H);\r\n EVE_CoDl_bitmapSize(s_pHalContext, BILINEAR, BORDER, BORDER, WIDGET_BITMAP_W * 3, WIDGET_BITMAP_H * 3);\r\n EVE_CoDl_macro(s_pHalContext, 0);\r\n EVE_CoDl_end(s_pHalContext);\r\n /* Display the text */\r\n EVE_CoCmd_loadIdentity(s_pHalContext);\r\n EVE_CoCmd_setMatrix(s_pHalContext);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t) (s_pHalContext->Width / 2), (int16_t) (s_pHalContext->Height / 2), WIDGET_TITLE_FONT, OPT_CENTER, \"Screen Saver ...\");\r\n EVE_CoDl_display(s_pHalContext);\r\n EVE_CoCmd_screenSaver(s_pHalContext); //screen saver command will continuously update the macro0 with vertex2f command\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_sleep(5000);\r\n\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n /* Update the command buffer pointers - both read and write pointers */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n EVE_CoDl_vertexFormat(s_pHalContext, 4);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate sketch widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_sketch()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: sketch widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of sketch function. Sketch function */\r\n /* draws line for pen movement. Skecth supports L1 and L8 output formats */\r\n /* Sketch draws till stop command is executed. */\r\n /*************************************************************************/\r\n int16_t BorderSz = WIDGET_BTN_W;\r\n uint32_t MemZeroSz;\r\n int8_t line_width;\r\n uint32_t tag = 0;\r\n /* Send command sketch */\r\n\r\n MemZeroSz = 1L * (s_pHalContext->Width - 2 * BorderSz) * (s_pHalContext->Height - 2 * BorderSz);\r\n /* Sketch L8 format */\r\n /* Send command sketch */\r\n EVE_CoCmd_memZero(s_pHalContext, RAM_G, MemZeroSz);\r\n EVE_CoCmd_sketch(s_pHalContext, BorderSz, BorderSz,\r\n (int16_t)(s_pHalContext->Width - 2 * BorderSz),\r\n (int16_t)(s_pHalContext->Height - 2 * BorderSz), 0, L8); //sketch in L8 format\r\n /* Display the sketch */\r\n while ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && (tag != 'K'))\r\n {\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext,\r\n (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_scissorXY(s_pHalContext, BorderSz, BorderSz);\r\n EVE_CoDl_clearColorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n\r\n /* default the scissor size */\r\n EVE_CoDl_scissorSize(s_pHalContext, 2048, 2048);\r\n EVE_CoDl_scissorXY(s_pHalContext, 0, 0);\r\n /* L8 bitmap display */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapSource(s_pHalContext, RAM_G);\r\n EVE_CoDl_bitmapLayout(s_pHalContext,\r\n L8, (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_bitmapSize(s_pHalContext,\r\n BILINEAR, BORDER, BORDER, (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_RED);\r\n line_width = 3;\r\n while (line_width >= 0)\r\n {\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (BorderSz + line_width) * 16, (BorderSz + line_width) * 16);\r\n line_width = line_width - 1;\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n /* Display the text */\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER,\r\n \"Sketch L8\");\r\n EVE_CoDl_tag(s_pHalContext, 'K');\r\n EVE_CoCmd_button(s_pHalContext, (int16_t)(s_pHalContext->Width - WIDGET_BTN_W), 0, WIDGET_BTN_W, WIDGET_BTN_H, WIDGET_TITLE_FONT_SMALL, 0, \"EXIT\");\r\n Display_End(s_pHalContext);\r\n }\r\n\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n /* Update the command buffer pointers - both read and write pointers */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n\r\n EVE_Util_clearScreen(s_pHalContext);\r\n SAMAPP_DELAY;\r\n\r\n EVE_CoCmd_memZero(s_pHalContext, RAM_G, MemZeroSz);\r\n EVE_CoCmd_sketch(s_pHalContext, BorderSz, BorderSz,\r\n (int16_t)(s_pHalContext->Width - 2 * BorderSz),\r\n (int16_t)(s_pHalContext->Height - 2 * BorderSz), RAM_G, L1); //sketch in L1 format\r\n while ((EVE_CoCmd_regRead(s_pHalContext, REG_TOUCH_TAG, &tag)) && (tag != 'S'))\r\n {\r\n /* Display the sketch */\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0x77, 0x77, 0x77 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n EVE_CoDl_scissorSize(s_pHalContext,\r\n (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_scissorXY(s_pHalContext, BorderSz, BorderSz);\r\n EVE_CoDl_clearColorRgb_ex(s_pHalContext, WIDGET_COLOR_WHITE);\r\n EVE_CoDl_clear(s_pHalContext, 1, 1, 1);\r\n\r\n /* default the scissor size */\r\n EVE_CoDl_scissorSize(s_pHalContext, 2048, 2048);\r\n EVE_CoDl_scissorXY(s_pHalContext, 0, 0);\r\n\r\n /* L1 bitmap display */\r\n EVE_CoDl_begin(s_pHalContext, BITMAPS);\r\n EVE_CoDl_bitmapSource(s_pHalContext, RAM_G);\r\n EVE_CoDl_bitmapLayout(s_pHalContext,\r\n L1, (s_pHalContext->Width - 2 * BorderSz) / 8, (s_pHalContext->Height - 2 * BorderSz));\r\n EVE_CoDl_bitmapSize(s_pHalContext,\r\n BILINEAR, BORDER, BORDER, (s_pHalContext->Width - 2 * BorderSz), (s_pHalContext->Height - 2 * BorderSz));\r\n\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n line_width = 3;\r\n while (line_width >= 0)\r\n {\r\n EVE_CoDl_vertex2f_4(s_pHalContext, (BorderSz + line_width) * 16, (BorderSz + line_width) * 16);\r\n line_width = line_width - 1;\r\n }\r\n EVE_CoDl_end(s_pHalContext);\r\n /* Display the text */\r\n EVE_CoDl_colorRgb(s_pHalContext, 0xff, 0xff, 0xff);\r\n EVE_CoCmd_text(s_pHalContext, (int16_t)(s_pHalContext->Width / 2), WIDGET_TITLE_Y_INC, WIDGET_TITLE_FONT, OPT_CENTER,\r\n \"Sketch L1\");\r\n EVE_CoDl_tag(s_pHalContext, 'S');\r\n EVE_CoCmd_button(s_pHalContext, (int16_t)(s_pHalContext->Width - WIDGET_BTN_W), 0, WIDGET_BTN_W, WIDGET_BTN_H, WIDGET_TITLE_FONT_SMALL, 0, \"EXIT\");\r\n Display_End(s_pHalContext);\r\n }\r\n\r\n /* Send the stop command */\r\n EVE_CoCmd_stop(s_pHalContext);\r\n /* Update the command buffer pointers - both read and write pointers */\r\n EVE_Cmd_waitFlush(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate sketch widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_arc()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: arc widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of arc function. The arc command */\r\n /* draws a circular arc. The end caps of the arc are rounded. */\r\n /* If the angles specify a complete circle, a disc is drawn. */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 255, 255, 255 }, (uint8_t[]) { 255, 255, 255 }, 0, 4);\r\n uint32_t rgb[WIDGET_ARC_COLOR_NUM] = { 0x00E6194B, 0x003CB44B, 0x00FFFF19, 0x000082C8, 0x00F58230, 0x00911EB4, 0x0046F0F0, 0x00F032E6, 0x00D2F53C, 0x00FABED4 };\r\n uint16_t i, r0, r1, a0, a1;\r\n\r\n for (i = 1; i < WIDGET_ARC_COLOR_NUM; i++)\r\n {\r\n r0 = WIDGET_ARC_R * i;\r\n r1 = r0 + WIDGET_ARC_W;\r\n a0 = (i * 0x1933) & 0xffff;\r\n a1 = (a0 + (i * 0x3933)) & 0xffff;\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, rgb[i - 1]);\r\n EVE_CoCmd_arc(s_pHalContext, s_pHalContext->Width / 2, s_pHalContext->Height / 2, r0, r1, a0, a1);\r\n }\r\n\r\n EVE_CoDl_colorRgb_ex(s_pHalContext, rgb[WIDGET_ARC_COLOR_NUM - 1]);\r\n EVE_CoCmd_arc(s_pHalContext, s_pHalContext->Width / 2, s_pHalContext->Height / 2,\r\n WIDGET_ARC_COLOR_NUM * WIDGET_ARC_R, WIDGET_ARC_COLOR_NUM * WIDGET_ARC_R + 5 * WIDGET_ARC_W, 0, 0xffff);\r\n\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n/**\r\n * @brief API to demonstrate glow widget\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget_glow()\r\n{\r\n Draw_Text(s_pHalContext, \"Example for: glow widget\");\r\n\r\n /*************************************************************************/\r\n /* Below code demonstrates the usage of glow function. The glow command */\r\n /* draws an additive glow effect centered in a rectangle, using the */\r\n /* current color. */\r\n /*************************************************************************/\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0xDD, 0XDD, 0xDD }, (uint8_t[]) { 0xFF, 0xC0, 0x80 }, 0, 4);\r\n EVE_CoCmd_text(s_pHalContext, s_pHalContext->Width / 2, s_pHalContext->Height / 2, WIDGET_TITLE_FONT_LARGE, OPT_CENTER, \"glow widget\");\r\n EVE_CoDl_colorRgb(s_pHalContext, 0x60, 48, 30);\r\n EVE_CoCmd_glow(s_pHalContext, s_pHalContext->Width / 2 - WIDGET_GLOW_W / 2, s_pHalContext->Height / 2 - WIDGET_GLOW_H / 2, WIDGET_GLOW_W, WIDGET_GLOW_H);\r\n Display_End(s_pHalContext);\r\n SAMAPP_DELAY;\r\n}\r\n\r\n#define TX0 240 /* top center */\r\n#define TY0 50\r\n#define TX1 120 /* bottom left */\r\n#define TY1 200\r\n#define TX2 360 /* bottom right */\r\n#define TY2 200\r\n\r\n#define OUTLINE_WIDTH 16 /* 1 pixel = 16 units in 1/16 precision */\r\n\r\nvoid draw_red_triangle()\r\n{\r\n Display_Start(s_pHalContext, (uint8_t[]) { 0xDD, 0XDD, 0xDD }, (uint8_t[]) { 0xFF, 0xC0, 0x80 }, 0, 4);\r\n\r\n EVE_CoDl_colorMask(s_pHalContext, 0, 0, 0, 0); /* disable color writes */\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, INVERT); /* toggle stencil on pass */\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 0, 255);\r\n\r\n\r\n EVE_CoDl_begin(s_pHalContext, EDGE_STRIP_B);\r\n EVE_CoDl_vertex2f(s_pHalContext, TX0 * 16, TY0 * 16); /* top */\r\n EVE_CoDl_vertex2f(s_pHalContext, TX1 * 16, TY1 * 16); /* bottom-left */\r\n EVE_CoDl_vertex2f(s_pHalContext, TX2 * 16, TY2 * 16); /* bottom-right */\r\n EVE_CoDl_vertex2f(s_pHalContext, TX0 * 16, TY0 * 16); \r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* --- Step 2: fill red where stencil == 1 (inside triangle) --- */\r\n EVE_CoDl_colorMask(s_pHalContext, 1, 1, 1, 1);\r\n EVE_CoDl_stencilFunc(s_pHalContext, EQUAL, 1, 255);\r\n EVE_CoDl_stencilOp(s_pHalContext, KEEP, KEEP);\r\n EVE_CoDl_colorRgb(s_pHalContext, 255, 0, 0); /* red */\r\n EVE_CoDl_begin(s_pHalContext, RECTS);\r\n EVE_CoDl_vertex2f(s_pHalContext, 0, 0);\r\n EVE_CoDl_vertex2f(s_pHalContext, 480 * 16, 272 * 16); /* full screen */\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n /* --- Step 3: black outline --- */\r\n EVE_CoDl_stencilFunc(s_pHalContext, ALWAYS, 0, 255);\r\n EVE_CoDl_colorRgb(s_pHalContext, 0, 0, 0);\r\n EVE_CoDl_lineWidth(s_pHalContext, 16);\r\n EVE_CoDl_begin(s_pHalContext, LINE_STRIP);\r\n EVE_CoDl_vertex2f(s_pHalContext, TX0 * 16, TY0 * 16);\r\n EVE_CoDl_vertex2f(s_pHalContext, TX1 * 16, TY1 * 16);\r\n EVE_CoDl_vertex2f(s_pHalContext, TX2 * 16, TY2 * 16);\r\n EVE_CoDl_vertex2f(s_pHalContext, TX0 * 16, TY0 * 16); /* close */\r\n EVE_CoDl_end(s_pHalContext);\r\n\r\n Display_End(s_pHalContext);\r\n}\r\n\r\n/**\r\n * @brief Main entry to run all widget demos\r\n *\r\n * @param None\r\n * @return None\r\n */\r\nstatic void SAMAPP_Widget()\r\n{\r\n draw_red_triangle();\r\n SAMAPP_Widget_logo();\r\n SAMAPP_Widget_clock();\r\n SAMAPP_Widget_gauge();\r\n SAMAPP_Widget_gradient();\r\n SAMAPP_Widget_gradientA();\r\n SAMAPP_Widget_cgradient();\r\n SAMAPP_Widget_keysInteractive();\r\n SAMAPP_Widget_keys();\r\n SAMAPP_Widget_progressbar();\r\n SAMAPP_Widget_scroll();\r\n SAMAPP_Widget_slider();\r\n SAMAPP_Widget_dial();\r\n SAMAPP_Widget_toggle();\r\n SAMAPP_Widget_spinner();\r\n SAMAPP_Widget_text();\r\n SAMAPP_Widget_number();\r\n SAMAPP_Widget_button();\r\n SAMAPP_Widget_screensaver();\r\n SAMAPP_Widget_sketch();\r\n SAMAPP_Widget_arc();\r\n SAMAPP_Widget_glow();\r\n}\r\n\r\n\r\n"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"relative_path": "README.md",
|
|
76
|
+
"ext": ".md",
|
|
77
|
+
"content": "\r\n\r\n# EveApps-BT82X\r\n**EveApps-BT82X** is a collection of sample applications created as reference materials for Bridgetek’s 5th-generation graphics controller, the **BT82X**.\r\n\r\nThe samples are implemented in ANSI C with full source code provided. They are primarily instructional, focusing on demonstrating individual display lists and commands.\r\n\r\nAll applications share common resources located in the *“common”* folder.\r\n\r\nEach sample includes a *“project”* subfolder that contains the required files for building the application with **Microsoft Visual Studio 2019**.\r\n\r\nUsers should be familiar with the BT82X programming guide and datasheet before using these examples.\r\n\r\n\r\n## Folder introduction\r\n```\r\n📂 EveApps\r\n ├───common \r\n │ ├───application | Application's common functions\r\n │ ├───eve_flash | Blob binary for flash programming\r\n │ └───eve_hal | Hardware abstraction layer to bridge different platforms\r\n │ \r\n ├───SampleApp\r\n │ ├───Animation | Sample usage of animation \r\n | ├───Audio | Sample usage of audio functionality \r\n │ ├───Bitmap | Sample usage of bitmap \r\n | ├───Extension | Sample usage of extension\r\n │ ├───Flash | Sample usage of flash \r\n │ ├───Font | Sample usage of font\r\n | ├───Lvdsrx | Sample usage of LVDSRX\r\n │ ├───Primitives | Sample usage of drawing primitives\r\n │ ├───Touch | Sample usage of touch functionality\r\n │ ├───Utility | Sample usage of helper utilities\r\n │ ├───Video | Sample usage of video playback\r\n │ ├───Widget | Sample for default widgets\r\n```\r\n\r\nNote:\r\n- Definitions for EVE registers, commands, and instructions can be found in common/eve_hal/EVE_GpuDef.h and common/eve_hal/EVE_CoCmd.h.\r\n- The flash blob used for accessing the EVE-connected NOR flash chip is located in common/eve_flash.\r\n- By default, NAND flash settings are defined in common/eve_hal/EVE_Config.h.\r\n\r\n## Hardware dependency \r\nStarting from version 1.3.0_RC1, EveApps-BT82X supports VM820C, VM820B15A, and VM820B10A. You may refer to the details at www.brtchip.com\r\n\r\n## Build instructions\r\n\r\n### Configurations\r\n<table>\r\n <thead>\r\n <tr>\r\n <th>EVE_APPS_PLATFORM</th>\r\n <th>EVE_APPS_GRAPHICS</th>\r\n <th>EVE_APPS_DISPLAY</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <tr>\r\n <td rowspan=\"3\">\r\n EVE_PLATFORM_FT4222<br>\r\n EVE_PLATFORM_MPSSE<br>\r\n EVE_PLATFORM_RP2040<br>\r\n MM2040EV\r\n </td>\r\n <td>EVE_GRAPHICS_BT820</td>\r\n <td><b>EVE_DISPLAY_WUXGA(1920x1200 LCD)</b><br>\r\n EVE_DISPLAY_FHD(1920x1080 LCD)<br>\r\n EVE_DISPLAY_WXGA(1280x800 LCD)<br></td>\r\n </tr>\r\n <tr>\r\n <td>VM820B15A</td>\r\n <td><b>EVE_DISPLAY_FHD</b></td>\r\n </tr>\r\n <tr>\r\n <td>VM820B10A</td>\r\n <td><b>EVE_DISPLAY_WXGA</b></td>\r\n </tr>\r\n </tbody>\r\n</table>\r\n\r\nBold text indicates the default LCD setting. For details on the compilation switch settings above, refer to common/eve_hal/EVE_Config.h.\r\n\r\n### FT4222 and MPSSE\r\n#### Way 1: Open SampleApp_MSVC.sln\r\n\r\nGo to property\r\n\r\n\r\n\r\nChange settings (EVE_PLATFORM_FT4222 / EVE_PLATFORM_MPSSE)\r\n\r\n\r\n\r\npress F5 to build and run\r\n\r\n#### Way 2: Use Cmake: (Need Cmake 3.19 installed)\r\n```sh\r\n# Launch the appropriate Developer Command Prompt for VS\r\n# For 64-bit build, open:\r\n# x64 Native Tools Command Prompt for VS\r\ncall \"[path to VS]\\VC\\Auxiliary\\Build\\vcvars64.bat\" # for 64-bit\r\n# For 32-bit build, open:\r\n# x86 Native Tools Command Prompt for VS\r\ncall \"[path to VS]\\VC\\Auxiliary\\Build\\vcvars32.bat\" # for 32-bit\r\n\r\ncd [path to EveApps]\r\nmkdir build\r\ncd build\r\ncmake -G \"NMake Makefiles\" -DEVE_APPS_PLATFORM=EVE_PLATFORM_FT4222 -DEVE_APPS_GRAPHICS=[EVE graphics] -DEVE_APPS_DISPLAY=[EVE display] -DEVE_APPS_SPI=[EVE SPI] -DCMAKE_BUILD_TYPE=Debug ..\r\nnmake SampleApp_[Project Name]\r\n\r\n# EVE_APPS_PLATFORM can be one of : EVE_PLATFORM_FT4222 or EVE_PLATFORM_MPSSE\r\n# [EVE graphics] Refer to the configuration table above\r\n# [EVE display] Refer to the configuration table above\r\n# [EVE SPI] can be one of : EVE_SPI_QUAD, EVE_SPI_DUAL, EVE_SPI_SINGLE (FT4222 can support Quad/Dual/Single, MPSSE supports single only)\r\n# [Project Name] is the folder name of a subfolder inside SampleApp , one example is SampleApp_Widget\r\n# The output binary [Project Name].exe can be found in build\\[Project Name]\r\n\r\nOne example is :\r\ncmake -G \"NMake Makefiles\" -DEVE_APPS_PLATFORM=EVE_PLATFORM_FT4222 -DEVE_APPS_GRAPHICS=EVE_GRAPHICS_BT820 -DEVE_APPS_DISPLAY=EVE_DISPLAY_WUXGA -DCMAKE_BUILD_TYPE=Debug ..\r\n```\r\n\r\nexample: \r\n\r\n\r\n\r\n\r\n### Raspberry Pi Pico\r\n\r\nRequires the Pico toolchain https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads to be installed.\r\n\r\nPico-SDK version 2.2.0 is required\r\n```sh\r\n$ git clone https://github.com/raspberrypi/pico-sdk.git --branch master\r\n$ git submodule update --init\r\n```\r\n\r\n\r\nThe following steps will build for Raspberry Pi Pico.\r\n\r\n 1. Install cmake 3.19.x, Visual Studio 2019 community (must select C++), GNU Arm Embedded Toolchain for window.\r\n 2. Launch the *Developer Command Prompt for VS*\r\n```sh\r\nset PICO_SDK_PATH=[path to pico-sdk]\r\nset PICO_TOOLCHAIN_PATH=[path to GNU Arm Embedded Toolchain\\\\bin]\r\ncd EveApps\r\nmkdir build\r\ncd build\r\ncmake -G \"NMake Makefiles\" -DEVE_APPS_PLATFORM=EVE_PLATFORM_RP2040 -DEVE_APPS_GRAPHICS=[EVE graphics] -DEVE_APPS_DISPLAY=[EVE display] -DEVE_APPS_SPI=[EVE SPI] -DCMAKE_BUILD_TYPE=Debug ..\r\nnmake [Project name]\r\n\r\n# EVE_APPS_PLATFORM can be one of : EVE_PLATFORM_RP2040 or MM2040EV\r\n# [EVE graphics] Refer to the configuration table above\r\n# [EVE display] Refer to the configuration table above\r\n# [EVE SPI] must : EVE_SPI_SINGLE (PR2040 supports single only)\r\n# [Project Name] is the folder name of a subfolder inside SampleApp , one example is SampleApp_Widget\r\n# The output binary [Project Name].uf2 can be found in build\\SampleApp\\[Project]\r\n```\r\n\r\nExample: \r\n```\r\n$ cmake.exe -G \"NMake Makefiles\" -DEVE_APPS_GRAPHICS=EVE_GRAPHICS_BT820 -DEVE_APPS_PLATFORM=MM2040EV -DEVE_APPS_DISPLAY=EVE_DISPLAY_WUXGA -DEVE_APPS_SPI=EVE_SPI_SINGLE -DCMAKE_BUILD_TYPE=Debug ..\r\n$ nmake \r\n```\r\n\r\n#### Connections\r\n\r\n| RP2040 | EVE | UART | SD |\r\n| --- | --- | --- | --- |\r\n| GP0 (TX) | | RX (debug) | |\r\n| GP1 (RX) | | TX (optional) | |\r\n| GP2 (SPI0 SCK) | SCK | | |\r\n| GP3 (SPI0 MOSI) | MOSI | | |\r\n| GP4 (SPI0 MISO) | MISO | | |\r\n| GP5 (GPIO) | CS | | |\r\n| GP6 (GPIO) | INT | | |\r\n| GP7 (GPIO) | PWD | | |\r\n| 5V | 5V | | |\r\n| GND | GND | | |\r\n"
|
|
78
|
+
}
|
|
79
|
+
]
|