Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.14 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Ac6
  5.   * @version V1.0
  6.   * @date    01-December-2013
  7.   * @brief   Default main function.
  8.   * @info   https://community.ugfx.org/topic/430-errors-with-ugfx-and-chibios-on-stm32f7-discovery/#comment-3157
  9.   * @info   https://community.ugfx.org/topic/324-stm32f429-disc/
  10.   * @info
  11.   ******************************************************************************
  12. */
  13.  
  14.  
  15. #include "stm32f4xx.h"
  16. #include "stm32f429i_discovery.h"
  17. #include "gfx.h"
  18. #include "stm32f4xx_hal.h"
  19. #include <stdlib.h>
  20. #include "init.h"
  21. #include "math.h"
  22.  
  23. void mandelbrot(float x1, float y1, float x2, float y2);
  24.  
  25. static GListener gl;
  26. static GHandle   ghButton1, ghButton2, gh, ghContainerPage0;
  27. static GGraphObject g;
  28.  
  29. // A set of data points that will be displayed in the graph
  30. static const point data[5] = {
  31.     { -40, -40 },
  32.     { 70, 40 },
  33.     { 140, 60 },
  34.     { 210, 60 },
  35.     { 280, 200 }
  36. };
  37.  
  38. // A graph styling
  39. static GGraphStyle GraphStyle1 = {
  40.     { GGRAPH_POINT_DOT, 0, Blue },          // Point
  41.     { GGRAPH_LINE_NONE, 2, Gray },          // Line
  42.     { GGRAPH_LINE_SOLID, 0, Black },        // X axis
  43.     { GGRAPH_LINE_SOLID, 0, Black },        // Y axis
  44.     { GGRAPH_LINE_DASH, 5, Gray, 50 },      // X grid
  45.     { GGRAPH_LINE_DOT, 7, Yellow, 50 },     // Y grid
  46.     GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS   // Flags
  47. };
  48.  
  49. // Another graph styling
  50. static const GGraphStyle GraphStyle2 = {
  51.     { GGRAPH_POINT_SQUARE, 5, Red },        // Point
  52.     { GGRAPH_LINE_DOT, 2, Pink },           // Line
  53.     { GGRAPH_LINE_SOLID, 0, Black },        // X axis
  54.     { GGRAPH_LINE_SOLID, 0, Black },        // Y axis
  55.     { GGRAPH_LINE_DASH, 5, Gray, 50 },      // X grid
  56.     { GGRAPH_LINE_DOT, 7, Yellow, 50 },     // Y grid
  57.     GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS   // Flags
  58. };
  59.  
  60. static void createWidgets(void) {
  61.     GWidgetInit wi;
  62.  
  63.     // Apply some default values for GWIN
  64.     gwinWidgetClearInit(&wi);
  65.  
  66.     wi.g.show = FALSE;
  67.     wi.g.x = 0;
  68.     wi.g.y = 0;
  69.     wi.g.width = 240;
  70.     wi.g.height = 320;
  71.     wi.g.parent = 0;
  72.     wi.text = "Container";
  73.     wi.customDraw = 0;
  74.     ghContainerPage0 = gwinContainerCreate(0, &wi, 0);
  75.  
  76.     wi.g.show = TRUE;
  77.  
  78.     // Apply the button parameters
  79.     wi.g.width = 90;
  80.     wi.g.height = 30;
  81.     wi.g.y = 10;
  82.     wi.g.x = 10;
  83.     wi.text = "Toggle LED3";
  84.  
  85.     // Create the actual button
  86.     ghButton1 = gwinButtonCreate(NULL, &wi);
  87.  
  88.     // Apply the button parameters
  89.     wi.g.width = 90;
  90.     wi.g.height = 30;
  91.     wi.g.y = 10;
  92.     wi.g.x = 110;
  93.     wi.text = "Toggle LED4";
  94.  
  95.     // Create the actual button
  96.     ghButton2 = gwinButtonCreate(NULL, &wi);
  97.  
  98.  
  99.  
  100. }
  101.  
  102.  
  103.  
  104. systemticks_t gfxSystemTicks(void)
  105. {
  106.     return HAL_GetTick();
  107. }
  108.  
  109. systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
  110. {
  111.     return ms;
  112. }
  113.  
  114.  
  115. int main(void) {
  116.     GEvent* pe;
  117.     HAL_Init();
  118.     SystemClock_Config();
  119.     BSP_LED_Init(LED3);
  120.     BSP_LED_Init(LED4);
  121.     // Initialize the display
  122.     gfxInit();
  123.  
  124.     // Set the widget defaults
  125.     gwinSetDefaultFont(gdispOpenFont("UI2"));
  126.     gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
  127.     gdispClear(White);
  128.  
  129.     // create the widget
  130.     createWidgets();
  131.  
  132.     GWindowInit wii;
  133.  
  134.     wii.show = TRUE;
  135.     wii.x = 10;
  136.     wii.y = 50;
  137.     wii.width = 150;
  138.     wii.height = 150;
  139.     gh = gwinGraphCreate(&g, &wii);
  140.     gwinGraphSetOrigin(gh, (gwinGetWidth(gh)/2), (gwinGetHeight(gh)/2));
  141.     gwinGraphSetStyle(gh, &GraphStyle1);
  142.     gwinGraphDrawAxis(gh);
  143.  
  144.     gwinGraphDrawPoint(gh, 10, 10);
  145.  
  146.     gwinGraphDrawPoint(gh, 20, 20);
  147.  
  148.     gwinGraphDrawPoint(gh, 30, 30);
  149.  
  150.     // We want to listen for widget events
  151.     geventListenerInit(&gl);
  152.     gwinAttachListener(&gl);
  153.  
  154.  
  155.     while(1) {
  156.         // Get an Event
  157.         pe = geventEventWait(&gl, TIME_INFINITE);
  158.  
  159.         switch(pe->type) {
  160.             case GEVENT_GWIN_BUTTON:
  161.                 if (((GEventGWinButton*)pe)->gwin == ghButton1) {
  162.                     // Our button has been pressed
  163.                     BSP_LED_Toggle(LED3);
  164.                 }
  165.                 if (((GEventGWinButton*)pe)->gwin == ghButton2) {
  166.                     // Our button has been pressed
  167.                     BSP_LED_Toggle(LED4);
  168.                 }
  169.                 break;
  170.             default:
  171.                 break;
  172.         }
  173.     }
  174.  
  175.     return 0;
  176. }
  177.  
  178. /*
  179. int main(void)
  180. {
  181.     float cx, cy;
  182.     float zoom = 1.0f;
  183.  
  184.     HAL_Init();
  185.     SystemClock_Config();
  186.  
  187.     gfxInit();
  188.     // where to zoom in
  189.         cx = -0.086f;
  190.         cy = 0.85f;
  191.  
  192.         while(TRUE) {
  193.             mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy);
  194.  
  195.             zoom *= 0.7f;
  196.             if(zoom <= 0.00001f)
  197.                 zoom = 1.0f;
  198.         }
  199. }
  200.  
  201. void mandelbrot(float x1, float y1, float x2, float y2) {
  202.     unsigned int i,j, width, height;
  203.     uint16_t iter;
  204.     color_t color;
  205.     float fwidth, fheight;
  206.  
  207.     float sy = y2 - y1;
  208.     float sx = x2 - x1;
  209.     const int MAX = 512;
  210.  
  211.     width = (unsigned int)gdispGetWidth();
  212.     height = (unsigned int)gdispGetHeight();
  213.     fwidth = width;
  214.     fheight = height;
  215.  
  216.     for(i = 0; i < width; i++) {
  217.         for(j = 0; j < height; j++) {
  218.             float cy = j * sy / fheight + y1;
  219.             float cx = i * sx / fwidth + x1;
  220.             float x=0.0f, y=0.0f, xx=0.0f, yy=0.0f;
  221.             for(iter=0; iter <= MAX && xx+yy<4.0f; iter++) {
  222.                 xx = x*x;
  223.                 yy = y*y;
  224.                 y = 2.0f*x*y + cy;
  225.                 x = xx - yy + cx;
  226.             }
  227.             //color = ((iter << 8) | (iter&0xFF));
  228.             color = RGB2COLOR(iter<<7, iter<<4, iter);
  229.             gdispDrawPixel(i, j, color);
  230.         }
  231.     }
  232. }
  233. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement