Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- * @info https://community.ugfx.org/topic/430-errors-with-ugfx-and-chibios-on-stm32f7-discovery/#comment-3157
- * @info https://community.ugfx.org/topic/324-stm32f429-disc/
- * @info
- ******************************************************************************
- */
- #include "stm32f4xx.h"
- #include "stm32f429i_discovery.h"
- #include "gfx.h"
- #include "stm32f4xx_hal.h"
- #include <stdlib.h>
- #include "init.h"
- #include "math.h"
- void mandelbrot(float x1, float y1, float x2, float y2);
- static GListener gl;
- static GHandle ghButton1, ghButton2, gh, ghContainerPage0;
- static GGraphObject g;
- // A set of data points that will be displayed in the graph
- static const point data[5] = {
- { -40, -40 },
- { 70, 40 },
- { 140, 60 },
- { 210, 60 },
- { 280, 200 }
- };
- // A graph styling
- static GGraphStyle GraphStyle1 = {
- { GGRAPH_POINT_DOT, 0, Blue }, // Point
- { GGRAPH_LINE_NONE, 2, Gray }, // Line
- { GGRAPH_LINE_SOLID, 0, Black }, // X axis
- { GGRAPH_LINE_SOLID, 0, Black }, // Y axis
- { GGRAPH_LINE_DASH, 5, Gray, 50 }, // X grid
- { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // Y grid
- GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // Flags
- };
- // Another graph styling
- static const GGraphStyle GraphStyle2 = {
- { GGRAPH_POINT_SQUARE, 5, Red }, // Point
- { GGRAPH_LINE_DOT, 2, Pink }, // Line
- { GGRAPH_LINE_SOLID, 0, Black }, // X axis
- { GGRAPH_LINE_SOLID, 0, Black }, // Y axis
- { GGRAPH_LINE_DASH, 5, Gray, 50 }, // X grid
- { GGRAPH_LINE_DOT, 7, Yellow, 50 }, // Y grid
- GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS // Flags
- };
- static void createWidgets(void) {
- GWidgetInit wi;
- // Apply some default values for GWIN
- gwinWidgetClearInit(&wi);
- wi.g.show = FALSE;
- wi.g.x = 0;
- wi.g.y = 0;
- wi.g.width = 240;
- wi.g.height = 320;
- wi.g.parent = 0;
- wi.text = "Container";
- wi.customDraw = 0;
- ghContainerPage0 = gwinContainerCreate(0, &wi, 0);
- wi.g.show = TRUE;
- // Apply the button parameters
- wi.g.width = 90;
- wi.g.height = 30;
- wi.g.y = 10;
- wi.g.x = 10;
- wi.text = "Toggle LED3";
- // Create the actual button
- ghButton1 = gwinButtonCreate(NULL, &wi);
- // Apply the button parameters
- wi.g.width = 90;
- wi.g.height = 30;
- wi.g.y = 10;
- wi.g.x = 110;
- wi.text = "Toggle LED4";
- // Create the actual button
- ghButton2 = gwinButtonCreate(NULL, &wi);
- }
- systemticks_t gfxSystemTicks(void)
- {
- return HAL_GetTick();
- }
- systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
- {
- return ms;
- }
- int main(void) {
- GEvent* pe;
- HAL_Init();
- SystemClock_Config();
- BSP_LED_Init(LED3);
- BSP_LED_Init(LED4);
- // Initialize the display
- gfxInit();
- // Set the widget defaults
- gwinSetDefaultFont(gdispOpenFont("UI2"));
- gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
- gdispClear(White);
- // create the widget
- createWidgets();
- GWindowInit wii;
- wii.show = TRUE;
- wii.x = 10;
- wii.y = 50;
- wii.width = 150;
- wii.height = 150;
- gh = gwinGraphCreate(&g, &wii);
- gwinGraphSetOrigin(gh, (gwinGetWidth(gh)/2), (gwinGetHeight(gh)/2));
- gwinGraphSetStyle(gh, &GraphStyle1);
- gwinGraphDrawAxis(gh);
- gwinGraphDrawPoint(gh, 10, 10);
- gwinGraphDrawPoint(gh, 20, 20);
- gwinGraphDrawPoint(gh, 30, 30);
- // We want to listen for widget events
- geventListenerInit(&gl);
- gwinAttachListener(&gl);
- while(1) {
- // Get an Event
- pe = geventEventWait(&gl, TIME_INFINITE);
- switch(pe->type) {
- case GEVENT_GWIN_BUTTON:
- if (((GEventGWinButton*)pe)->gwin == ghButton1) {
- // Our button has been pressed
- BSP_LED_Toggle(LED3);
- }
- if (((GEventGWinButton*)pe)->gwin == ghButton2) {
- // Our button has been pressed
- BSP_LED_Toggle(LED4);
- }
- break;
- default:
- break;
- }
- }
- return 0;
- }
- /*
- int main(void)
- {
- float cx, cy;
- float zoom = 1.0f;
- HAL_Init();
- SystemClock_Config();
- gfxInit();
- // where to zoom in
- cx = -0.086f;
- cy = 0.85f;
- while(TRUE) {
- mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy);
- zoom *= 0.7f;
- if(zoom <= 0.00001f)
- zoom = 1.0f;
- }
- }
- void mandelbrot(float x1, float y1, float x2, float y2) {
- unsigned int i,j, width, height;
- uint16_t iter;
- color_t color;
- float fwidth, fheight;
- float sy = y2 - y1;
- float sx = x2 - x1;
- const int MAX = 512;
- width = (unsigned int)gdispGetWidth();
- height = (unsigned int)gdispGetHeight();
- fwidth = width;
- fheight = height;
- for(i = 0; i < width; i++) {
- for(j = 0; j < height; j++) {
- float cy = j * sy / fheight + y1;
- float cx = i * sx / fwidth + x1;
- float x=0.0f, y=0.0f, xx=0.0f, yy=0.0f;
- for(iter=0; iter <= MAX && xx+yy<4.0f; iter++) {
- xx = x*x;
- yy = y*y;
- y = 2.0f*x*y + cy;
- x = xx - yy + cx;
- }
- //color = ((iter << 8) | (iter&0xFF));
- color = RGB2COLOR(iter<<7, iter<<4, iter);
- gdispDrawPixel(i, j, color);
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement