Skip to content

Commit

Permalink
Feat&Bug: Plot sin(t) with dynaimic graph
Browse files Browse the repository at this point in the history
Bug found: TouchGFX freezes when there are incoming audio from USB
  • Loading branch information
qqq89513 committed Jan 3, 2021
1 parent f5b9ad5 commit fec4bb2
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 364 deletions.
617 changes: 309 additions & 308 deletions .cproject

Large diffs are not rendered by default.

54 changes: 51 additions & 3 deletions TouchGFX/equalizer.touchgfx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
}
],
"Name": "btn_test",
"X": 215,
"Y": 111,
"X": 0,
"Y": 222,
"Width": 50,
"Height": 50,
"Visible": true,
Expand All @@ -51,12 +51,60 @@
"Clickable": false,
"Fadeable": false,
"Moveable": false
},
{
"Type": "DynamicGraph",
"DataSeed": 1759792312,
"NumberOfValues": 100,
"MaxY": 2.0,
"MinY": -2.0,
"Precision": "0.1",
"UseCustomVisibleDataPointRange": false,
"FirstIndex": 0,
"LastIndex": 99,
"MapDataPointIndexToCustomValue": false,
"XAxisOffset": 0.0,
"XAxisScale": 1.0,
"InsertRandomValues": true,
"Alpha": 255,
"LabelSizeTop": 0,
"LabelSizeBottom": 0,
"LabelSizeLeft": 0,
"LabelSizeRight": 0,
"PaddingTop": 0,
"PaddingBottom": 0,
"PaddingLeft": 0,
"PaddingRight": 0,
"GraphType": "GraphScroll",
"GraphDrawers": [
{
"Type": "LineDrawer",
"LineWidth": 2,
"Color": {
"Red": 41,
"Green": 255,
"Blue": 207
},
"Alpha": 255
}
],
"Name": "graph_t",
"X": 80,
"Y": 16,
"Width": 320,
"Height": 240,
"Visible": true,
"LockPosition": false,
"Draggable": false,
"Clickable": false,
"Fadeable": false,
"Moveable": false
}
],
"Interactions": [],
"Name": "screen",
"OverrideDefaultBufferSize": false,
"CanvasBufferSize": 0
"CanvasBufferSize": 7200
}
],
"CustomContainerDefinitions": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <gui/screen_screen/screenPresenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/containers/buttons/Buttons.hpp>
#include <touchgfx/widgets/graph/GraphScroll.hpp>
#include <touchgfx/widgets/graph/GraphElements.hpp>
#include <touchgfx/widgets/canvas/PainterRGB565.hpp>

class screenViewBase : public touchgfx::View<screenPresenter>
{
Expand All @@ -27,9 +30,17 @@ class screenViewBase : public touchgfx::View<screenPresenter>
*/
touchgfx::Box __background;
touchgfx::BoxWithBorderButtonStyle< touchgfx::ClickButtonTrigger > btn_test;
touchgfx::GraphScroll<100> graph_t;
touchgfx::GraphElementLine graph_tLine1;
touchgfx::PainterRGB565 graph_tLine1Painter;

private:

/*
* Canvas Buffer Size
*/
static const uint16_t CANVAS_BUFFER_SIZE = 7200;
uint8_t canvasBuffer[CANVAS_BUFFER_SIZE];
};

#endif // SCREENVIEWBASE_HPP
118 changes: 117 additions & 1 deletion TouchGFX/generated/gui_generated/src/screen_screen/screenViewBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,132 @@
screenViewBase::screenViewBase()
{

touchgfx::CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);

__background.setPosition(0, 0, 480, 272);
__background.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));

btn_test.setBoxWithBorderPosition(0, 0, 50, 50);
btn_test.setBorderSize(5);
btn_test.setBoxWithBorderColors(touchgfx::Color::getColorFrom24BitRGB(0, 102, 153), touchgfx::Color::getColorFrom24BitRGB(0, 153, 204), touchgfx::Color::getColorFrom24BitRGB(0, 51, 102), touchgfx::Color::getColorFrom24BitRGB(51, 102, 153));
btn_test.setPosition(215, 111, 50, 50);
btn_test.setPosition(0, 222, 50, 50);

graph_t.setScale(10);
graph_t.setPosition(80, 16, 320, 240);
graph_t.setGraphAreaMargin(0, 0, 0, 0);
graph_t.setGraphAreaPadding(0, 0, 0, 0);
graph_t.setGraphRangeY(-2, 2);

graph_tLine1.setScale(10);
graph_tLine1Painter.setColor(touchgfx::Color::getColorFrom24BitRGB(41, 255, 207));
graph_tLine1.setPainter(graph_tLine1Painter);
graph_tLine1.setLineWidth(2);
graph_t.addGraphElement(graph_tLine1);

graph_t.addDataPoint(-0.417215583610724f);
graph_t.addDataPoint(-0.461838269209249f);
graph_t.addDataPoint(-0.288148744417035f);
graph_t.addDataPoint(0.0941737216314843f);
graph_t.addDataPoint(0.618864207415873f);
graph_t.addDataPoint(1.17820616174399f);
graph_t.addDataPoint(1.64857709749906f);
graph_t.addDataPoint(1.92018448607729f);
graph_t.addDataPoint(1.92373272833795f);
graph_t.addDataPoint(1.6475005875711f);
graph_t.addDataPoint(1.14064362572498f);
graph_t.addDataPoint(0.501895726138028f);
graph_t.addDataPoint(-0.143593109967374f);
graph_t.addDataPoint(-0.673652747151312f);
graph_t.addDataPoint(-0.997574316951929f);
graph_t.addDataPoint(-1.07676142754346f);
graph_t.addDataPoint(-0.932556946363063f);
graph_t.addDataPoint(-0.639393510302043f);
graph_t.addDataPoint(-0.305010288759501f);
graph_t.addDataPoint(-0.0426407488116348f);
graph_t.addDataPoint(0.0579612033867787f);
graph_t.addDataPoint(-0.0464866312869641f);
graph_t.addDataPoint(-0.341454133340161f);
graph_t.addDataPoint(-0.757716209125886f);
graph_t.addDataPoint(-1.18818210698272f);
graph_t.addDataPoint(-1.51432131186617f);
graph_t.addDataPoint(-1.63570765409345f);
graph_t.addDataPoint(-1.49542759077121f);
graph_t.addDataPoint(-1.09509854503038f);
graph_t.addDataPoint(-0.495777807687519f);
graph_t.addDataPoint(0.195513084333107f);
graph_t.addDataPoint(0.850407775353221f);
graph_t.addDataPoint(1.34899344715719f);
graph_t.addDataPoint(1.6075582355748f);
graph_t.addDataPoint(1.59755732881529f);
graph_t.addDataPoint(1.35121598656455f);
graph_t.addDataPoint(0.952452588493452f);
graph_t.addDataPoint(0.515391334168578f);
graph_t.addDataPoint(0.155763266201633f);
graph_t.addDataPoint(-0.0377765911482054f);
graph_t.addDataPoint(-0.0253791851155916f);
graph_t.addDataPoint(0.174542536589409f);
graph_t.addDataPoint(0.490434946799339f);
graph_t.addDataPoint(0.816023604312622f);
graph_t.addDataPoint(1.03748652361727f);
graph_t.addDataPoint(1.06268145826048f);
graph_t.addDataPoint(0.845217243642808f);
graph_t.addDataPoint(0.397415741176133f);
graph_t.addDataPoint(-0.211073920442741f);
graph_t.addDataPoint(-0.868733451190036f);
graph_t.addDataPoint(-1.44798556614644f);
graph_t.addDataPoint(-1.83509620530993f);
graph_t.addDataPoint(-1.95690074704041f);
graph_t.addDataPoint(-1.79785576725351f);
graph_t.addDataPoint(-1.40327524355519f);
graph_t.addDataPoint(-0.867982029525072f);
graph_t.addDataPoint(-0.313163013484652f);
graph_t.addDataPoint(0.142908005406286f);
graph_t.addDataPoint(0.413127737548098f);
graph_t.addDataPoint(0.461910158061324f);
graph_t.addDataPoint(0.312680370410439f);
graph_t.addDataPoint(0.0407293437416533f);
graph_t.addDataPoint(-0.246765176423281f);
graph_t.addDataPoint(-0.438597574466765f);
graph_t.addDataPoint(-0.448388839408267f);
graph_t.addDataPoint(-0.237306323189566f);
graph_t.addDataPoint(0.174976141857669f);
graph_t.addDataPoint(0.713818949016399f);
graph_t.addDataPoint(1.26684274761975f);
graph_t.addDataPoint(1.71066335291999f);
graph_t.addDataPoint(1.9406215271875f);
graph_t.addDataPoint(1.8962475800054f);
graph_t.addDataPoint(1.57623269502379f);
graph_t.addDataPoint(1.03923457991543f);
graph_t.addDataPoint(0.390301171592758f);
graph_t.addDataPoint(-0.243795176331669f);
graph_t.addDataPoint(-0.744315954395583f);
graph_t.addDataPoint(-1.02817205415244f);
graph_t.addDataPoint(-1.06669421540372f);
graph_t.addDataPoint(-0.891024341274597f);
graph_t.addDataPoint(-0.582873393726609f);
graph_t.addDataPoint(-0.252972859890495f);
graph_t.addDataPoint(-0.0125569464171407f);
graph_t.addDataPoint(0.055085656021106f);
graph_t.addDataPoint(-0.0840222712813379f);
graph_t.addDataPoint(-0.405533396141337f);
graph_t.addDataPoint(-0.832349743740966f);
graph_t.addDataPoint(-1.25343446477635f);
graph_t.addDataPoint(-1.55125809886457f);
graph_t.addDataPoint(-1.63114931815102f);
graph_t.addDataPoint(-1.44534101842361f);
graph_t.addDataPoint(-1.00578983725128f);
graph_t.addDataPoint(-0.382585923437876f);
graph_t.addDataPoint(0.311711780294708f);
graph_t.addDataPoint(0.94803809714466f);
graph_t.addDataPoint(1.41078984954275f);
graph_t.addDataPoint(1.62452727885217f);
graph_t.addDataPoint(1.57093487085471f);
graph_t.addDataPoint(1.2919498389466f);
graph_t.addDataPoint(0.878345441005528f);

add(__background);
add(btn_test);
add(graph_t);
}

void screenViewBase::setupScreen()
Expand Down
3 changes: 3 additions & 0 deletions TouchGFX/gui/include/gui/screen_screen/screenView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class screenView : public screenViewBase
virtual ~screenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
void handleTickEvent();

protected:
int tick_cnt;
};

#endif // SCREENVIEW_HPP
14 changes: 11 additions & 3 deletions TouchGFX/gui/src/screen_screen/screenView.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#include <gui/screen_screen/screenView.hpp>
#include "math.h"

screenView::screenView()
{

tick_cnt = 0;
}

void screenView::setupScreen()
{
screenViewBase::setupScreen();
screenViewBase::setupScreen();
}

void screenView::tearDownScreen()
{
screenViewBase::tearDownScreen();
screenViewBase::tearDownScreen();
}

void screenView::handleTickEvent(){
tick_cnt++;
if(tick_cnt%3 == 0){
graph_t.addDataPoint(sinf(tick_cnt*0.1));
}
}
25 changes: 1 addition & 24 deletions TouchGFX/target/generated/TouchGFXGeneratedHAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,9 @@ void TouchGFXGeneratedHAL::initialize()
HAL::initialize();

registerEventListener(*(Application::getInstance()));
registerTaskDelayFunction(&OSWrappers::taskDelay);
setFrameRefreshStrategy(HAL::REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL);
enableLCDControllerInterrupt();
enableInterrupts();
setFrameBufferStartAddresses((void*)0xC0000000, (void*)0, (void*)0);
/*
* Set whether the DMA transfers are locked to the TFT update cycle. If
* locked, DMA transfer will not begin until the TFT controller has finished
* updating the display. If not locked, DMA transfers will begin as soon as
* possible. Default is true (DMA is locked with TFT).
*/
lockDMAToFrontPorch(true);
setFrameBufferStartAddresses((void*)0xC0000000, (void*)0xC003FC00, (void*)0);
}

void TouchGFXGeneratedHAL::configureInterrupts()
Expand Down Expand Up @@ -101,20 +92,6 @@ bool TouchGFXGeneratedHAL::blockCopy(void* RESTRICT dest, const void* RESTRICT s
return HAL::blockCopy(dest, src, numBytes);
}

uint16_t TouchGFXGeneratedHAL::getTFTCurrentLine()
{
// This function only requires an implementation if single buffering
// on LTDC display is being used (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).

// The CPSR register (bits 15:0) specify current line of TFT controller.
uint16_t curr = (uint16_t)(LTDC->CPSR & 0xffff);
uint16_t backPorchY = (uint16_t)(LTDC->BPCR & 0x7FF) + 1;

// The semantics of the getTFTCurrentLine() function is to return a value
// in the range of 0-totalheight. If we are still in back porch area, return 0.
return (curr < backPorchY) ? 0 : (curr - backPorchY);
}

extern "C"
{
void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
Expand Down
23 changes: 0 additions & 23 deletions TouchGFX/target/generated/TouchGFXGeneratedHAL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,6 @@ class TouchGFXGeneratedHAL : public touchgfx::HAL
*/
virtual void setTFTFrameBuffer(uint16_t* adr);

/**
* @fn virtual uint16_t TouchGFXGeneratedHAL::getTFTCurrentLine()
*
* @brief Get the current line (Y) of the TFT controller
*
* This function is used to obtain the progress of the TFT controller. More
* specifically, the line (or Y-value) currently being transferred.
*
* Note: The value must be adjusted to account for vertical back porch before
* returning, such that the value is always within the range of 0 &lt;= value &lt;
* actual display height in pixels
*
* It is used for the REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL frame refresh
* strategy in order to synchronize frame buffer drawing with TFT controller
* progress. If this strategy is used, the concrete HAL subclass must provide an
* override of this function that returns correct line value. If this strategy is
* not used, then the getTFTCurrentLine function is never called and can be
* disregarded.
*
* @return In this default implementation, 0xFFFF is returned to signify "not implemented".
*/
virtual uint16_t getTFTCurrentLine();

};
#endif // TouchGFXGeneratedHAL_HPP

Expand Down
6 changes: 4 additions & 2 deletions equalizer.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ ProjectManager.StackSize=0x3000
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_CRC_Init-CRC-false-HAL-true,4-MX_DMA2D_Init-DMA2D-false-HAL-true,5-MX_FMC_Init-FMC-false-HAL-true,6-MX_I2C1_Init-I2C1-false-HAL-true,7-MX_I2C3_Init-I2C3-false-HAL-true,8-MX_LTDC_Init-LTDC-false-HAL-true,9-MX_QUADSPI_Init-QUADSPI-false-HAL-true,10-MX_SAI2_Init-SAI2-false-HAL-true,11-MX_SDMMC1_SD_Init-SDMMC1-false-HAL-true,12-MX_SPDIFRX_Init-SPDIFRX-false-HAL-true,13-MX_SPI2_Init-SPI2-false-HAL-true,14-MX_TIM1_Init-TIM1-false-HAL-true,15-MX_TIM2_Init-TIM2-false-HAL-true,16-MX_TIM3_Init-TIM3-false-HAL-true,17-MX_TIM5_Init-TIM5-false-HAL-true,18-MX_TIM8_Init-TIM8-false-HAL-true,19-MX_TIM12_Init-TIM12-false-HAL-true,20-MX_USART1_UART_Init-USART1-false-HAL-true,21-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_CRC_Init-CRC-false-HAL-true,4-MX_DMA2D_Init-DMA2D-false-HAL-true,5-MX_FMC_Init-FMC-false-HAL-true,6-MX_I2C1_Init-I2C1-false-HAL-true,7-MX_I2C3_Init-I2C3-false-HAL-true,8-MX_LTDC_Init-LTDC-false-HAL-true,9-MX_QUADSPI_Init-QUADSPI-false-HAL-true,10-MX_SAI2_Init-SAI2-false-HAL-true,11-MX_SDMMC1_SD_Init-SDMMC1-false-HAL-true,12-MX_SPDIFRX_Init-SPDIFRX-false-HAL-true,13-MX_SPI2_Init-SPI2-false-HAL-true,14-MX_TIM1_Init-TIM1-false-HAL-true,15-MX_TIM2_Init-TIM2-false-HAL-true,16-MX_TIM3_Init-TIM3-false-HAL-true,17-MX_TIM5_Init-TIM5-false-HAL-true,18-MX_TIM8_Init-TIM8-false-HAL-true,19-MX_TIM12_Init-TIM12-false-HAL-true,20-MX_USART1_UART_Init-USART1-false-HAL-true,21-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,22-MX_TouchGFX_Init-STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0-false-HAL-false,23-MX_TouchGFX_Process-STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
RCC.AHBFreq_Value=200000000
RCC.APB1CLKDivider=RCC_HCLK_DIV4
RCC.APB1Freq_Value=50000000
Expand Down Expand Up @@ -1254,8 +1254,10 @@ SPI2.Mode=SPI_MODE_MASTER
SPI2.VirtualType=VM_MASTER
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.ApplicationCcGraphicsJjApplication=TouchGFXOoGenerator
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.GraphicsJjApplication_Checked=true
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.IPParameters=ApplicationCcGraphicsJjApplication,tgfx_custom_height,tgfx_location,tgfx_address1,tgfx_display_interface,tgfx_vsync,tgfx_hardware_accelerator
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.IPParameters=ApplicationCcGraphicsJjApplication,tgfx_custom_height,tgfx_location,tgfx_address1,tgfx_display_interface,tgfx_vsync,tgfx_hardware_accelerator,tgfx_buffering_strategy,tgfx_address2
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_address1=0xC0000000
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_address2=0xC003FC00
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_buffering_strategy=Double
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_custom_height=272
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_display_interface=disp_ltdc
STMicroelectronics.X-CUBE-TOUCHGFX.4.15.0.tgfx_hardware_accelerator=dma_2d
Expand Down

0 comments on commit fec4bb2

Please sign in to comment.