//#DOC Main, program entry and main loop
#include "main.h"
#include <otSerial.h>
#include <otTimer.h>
#include <otPrintfLite.h>
#include <otILI9341.h>
#include <otPlot.h>
#include <otMath.h>
#include <otMalloc.h>

otILI9341   tft;
otPlot      plot;
F32         * data;

void setup()
{
    UartEnableSignals(UART0);
    UartSetBaud(UART0, 115200);
   
    setStdout(UART0); // printf output is now directed on UART0
   
    tft.init();
    tft.setRotation(otILI9341::IR_270);
    tft.clear();
    tft.setTextColor(RGB565_YELLOW, RGB565_BLACK);
    tft.setTextSize(3);
    
    plot.init(0, 0, 320, 240, &tft);
    plot.setRange(-100, 100);
    
    data = (F32 *) _malloc(sizeof(F32) * 320);
}

void loop()
{
    for(int a = 10; a < 90; a += 5)
        for(int m = 20; m < 90; m++)
        {
            for(int i = 0; i < 320; i++)
                data[i] = sin(M_PI / m * i) * a;
            plot.setData(data);
            plot.plot();
        }
}