Mandelbrot set viewer for the ARM Mbed platform

Dependencies:   mbed DmTftLibrary

Mbed Mandelbrot Viewer

Touch-based mandelbrot set viewer for the ARM Mbed platform. Designed with the NXP LPC1768 and the DisplayModule DM-TFT28-116. It should be easy to adapt for any DisplayModule product, especially if it has an I2C touch controller.

On screen options allow the user to switch between 256*(2^n) maxiters up to 4096, and three rendering kernels using floats, integers, and integers in ARMv7 ASM.

Committer:
ofrasier
Date:
Fri Dec 07 01:00:54 2018 +0000
Revision:
3:835c035b8b1c
Parent:
1:a1d80c69e1f0
Combined ADD-LSL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ofrasier 1:a1d80c69e1f0 1 // Oscar Frasier, CS 335, Fall 2018
ofrasier 1:a1d80c69e1f0 2 // Interactive mandelbrot set, ARM platform
ofrasier 1:a1d80c69e1f0 3
ofrasier 1:a1d80c69e1f0 4 // Copyright notice for drivers: DmTpFt6x06.h/cpp DmTftIli9341.h/cpp
ofrasier 1:a1d80c69e1f0 5 /**********************************************************************************************
ofrasier 1:a1d80c69e1f0 6 Copyright (c) 2014 DisplayModule. All rights reserved.
ofrasier 1:a1d80c69e1f0 7
ofrasier 1:a1d80c69e1f0 8 Redistribution and use of this source code, part of this source code or any compiled binary
ofrasier 1:a1d80c69e1f0 9 based on this source code is permitted as long as the above copyright notice and following
ofrasier 1:a1d80c69e1f0 10 disclaimer is retained.
ofrasier 1:a1d80c69e1f0 11
ofrasier 1:a1d80c69e1f0 12 DISCLAIMER:
ofrasier 1:a1d80c69e1f0 13 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES
ofrasier 1:a1d80c69e1f0 14 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
ofrasier 1:a1d80c69e1f0 15 ********************************************************************************************/
ofrasier 1:a1d80c69e1f0 16
ofrasier 1:a1d80c69e1f0 17 #include <vector>
ofrasier 1:a1d80c69e1f0 18 #include "DmTpFt6x06.h"
ofrasier 1:a1d80c69e1f0 19 #include "DmTftIli9341.h"
ofrasier 1:a1d80c69e1f0 20 #include "ui.h"
ofrasier 1:a1d80c69e1f0 21 #include "kernels.h"
ofrasier 1:a1d80c69e1f0 22 #include "buttonhandlers.h"
ofrasier 1:a1d80c69e1f0 23
ofrasier 1:a1d80c69e1f0 24 // Globals are bad. Here's one:
ofrasier 1:a1d80c69e1f0 25 Mandelbrot *brot;
ofrasier 1:a1d80c69e1f0 26
ofrasier 1:a1d80c69e1f0 27 int main(int argc, char** argv)
ofrasier 1:a1d80c69e1f0 28 {
ofrasier 1:a1d80c69e1f0 29 DmTftIli9341 *screen = new DmTftIli9341(p26, p25, p5, p6, p7);
ofrasier 1:a1d80c69e1f0 30 screen->init();
ofrasier 1:a1d80c69e1f0 31
ofrasier 1:a1d80c69e1f0 32 I2C touchI2c = I2C(p28, p27);
ofrasier 1:a1d80c69e1f0 33 DmTpFt6x06 *touch = new DmTpFt6x06(DmTpFt6x06::DM_TFT28_116, touchI2c, false);
ofrasier 1:a1d80c69e1f0 34 touch->init();
ofrasier 1:a1d80c69e1f0 35
ofrasier 1:a1d80c69e1f0 36 // User Interface
ofrasier 1:a1d80c69e1f0 37 brot = new Mandelbrot(0, 80, 240, 240, drawASM);
ofrasier 1:a1d80c69e1f0 38 Label maxItersLabel = Label(0, 16, "MaxIters:");
ofrasier 1:a1d80c69e1f0 39 Label kernelLabel = Label(0, 48, "Kernel:");
ofrasier 1:a1d80c69e1f0 40 Button maxItersButton = Button(80, 0, 64, 40, "256", changeMaxIters);
ofrasier 1:a1d80c69e1f0 41 Button kernelButton = Button(80, 40, 64, 39, "ASM", changeKernel);
ofrasier 1:a1d80c69e1f0 42 Button drawButton = Button(144, 0, 48, 40, "Draw", reDraw);
ofrasier 1:a1d80c69e1f0 43 Button resetButton = Button(144, 40, 48, 39, "Reset", resetView);
ofrasier 1:a1d80c69e1f0 44 Button zoomOutButton = Button(192, 0, 48, 79, "Back", zoomOut);
ofrasier 1:a1d80c69e1f0 45
ofrasier 1:a1d80c69e1f0 46 std::vector<UIElement*> elements;
ofrasier 1:a1d80c69e1f0 47 elements.insert(elements.end(), &maxItersLabel);
ofrasier 1:a1d80c69e1f0 48 elements.insert(elements.end(), &kernelLabel);
ofrasier 1:a1d80c69e1f0 49 elements.insert(elements.end(), &maxItersButton);
ofrasier 1:a1d80c69e1f0 50 elements.insert(elements.end(), &kernelButton);
ofrasier 1:a1d80c69e1f0 51 elements.insert(elements.end(), &drawButton);
ofrasier 1:a1d80c69e1f0 52 elements.insert(elements.end(), &resetButton);
ofrasier 1:a1d80c69e1f0 53 elements.insert(elements.end(), &zoomOutButton);
ofrasier 1:a1d80c69e1f0 54 elements.insert(elements.end(), brot);
ofrasier 1:a1d80c69e1f0 55
ofrasier 1:a1d80c69e1f0 56 for (int i = 0; i < elements.size(); ++i) {
ofrasier 1:a1d80c69e1f0 57 elements[i]->draw(screen);
ofrasier 1:a1d80c69e1f0 58 }
ofrasier 1:a1d80c69e1f0 59
ofrasier 1:a1d80c69e1f0 60 // Polling touchscreen
ofrasier 1:a1d80c69e1f0 61 uint16_t cursorX;
ofrasier 1:a1d80c69e1f0 62 uint16_t cursorY;
ofrasier 1:a1d80c69e1f0 63 bool touching;
ofrasier 1:a1d80c69e1f0 64 bool wasTouching;
ofrasier 1:a1d80c69e1f0 65 while (1) {
ofrasier 1:a1d80c69e1f0 66 touch->readTouchData(cursorX, cursorY, touching);
ofrasier 1:a1d80c69e1f0 67 if (touching) {
ofrasier 1:a1d80c69e1f0 68 if (!wasTouching) {
ofrasier 1:a1d80c69e1f0 69 for (int i = 0; i < elements.size(); ++i) {
ofrasier 1:a1d80c69e1f0 70 if (cursorX > elements[i]->x &&
ofrasier 1:a1d80c69e1f0 71 cursorX < (elements[i]->x + elements[i]->width) &&
ofrasier 1:a1d80c69e1f0 72 cursorY > elements[i]->y &&
ofrasier 1:a1d80c69e1f0 73 cursorY < (elements[i]->y + elements[i]->height)) {
ofrasier 1:a1d80c69e1f0 74 // Is within bounding box of element
ofrasier 1:a1d80c69e1f0 75 elements[i]->onClick(screen, cursorX, cursorY);
ofrasier 1:a1d80c69e1f0 76 }
ofrasier 1:a1d80c69e1f0 77 }
ofrasier 1:a1d80c69e1f0 78 wasTouching = true;
ofrasier 1:a1d80c69e1f0 79 }
ofrasier 1:a1d80c69e1f0 80 } else if (wasTouching) {
ofrasier 1:a1d80c69e1f0 81 wasTouching = false;
ofrasier 1:a1d80c69e1f0 82 }
ofrasier 1:a1d80c69e1f0 83 wait(0.04);
ofrasier 1:a1d80c69e1f0 84 }
ofrasier 1:a1d80c69e1f0 85 /*
ofrasier 1:a1d80c69e1f0 86 Unreachable:
ofrasier 1:a1d80c69e1f0 87 delete screen;
ofrasier 1:a1d80c69e1f0 88 delete brot;
ofrasier 1:a1d80c69e1f0 89 delete touch;
ofrasier 1:a1d80c69e1f0 90 */
ofrasier 1:a1d80c69e1f0 91 }