Esempio n. 1
0
int main(void){ 
	DisableInterrupts();
	PLL_Init(Bus80MHz);	// bus clock at 80 MHz
	UART_Init();
	ST7735_InitR(INITR_REDTAB);
	ADC0_InitTimerTriggerSeq3_Ch0();
		
	EnableInterrupts();
	
	/*
	UART_OutString("Points: \r\n");
	while(currentIndex < 100);
	for(int i = 0; i < 100; i += 1) {
		UART_OutUDec(data[i]);
		UART_OutString("\r\n");
	}
	*/
	while(1) {
		ST7735_SetCursor(0, 0);
		int32_t currentTemperature = Temperature_Convert(ADC_FIFO_CurrentValue());
		printf("Temperature %5d.%02d\n", currentTemperature / 100, currentTemperature % 100);
		ST7735_PlotClear(32, 159);
		//TODO change color?
		
		for(int i = 0; i < FIFO_SIZE; i += 1) {
			int32_t point = 128 - Temperature_Convert(ADC_FIFO_Get()[i]) * 2 / 100;
			ST7735_DrawPixel(i+1, point+1, ST7735_RED);
			ST7735_DrawPixel(i+1, point, ST7735_RED);
			ST7735_DrawPixel(i, point+1, ST7735_RED);
			ST7735_DrawPixel(i, point, ST7735_RED);
		}
		WaitForInterrupt();
	}
}
Esempio n. 2
0
void DrawCircle(uint32_t x0, uint32_t y0, uint32_t radius, uint32_t color)
{
  int32_t x = radius;
  int32_t y = 0;
  int32_t decisionOver2 = 1 - x;   // Decision criterion divided by 2 evaluated at x=r, y=0

  while( y <= x )
  {
    ST7735_DrawPixel( x + x0,  y + y0, color);// right bottom clock
    ST7735_DrawPixel( y + x0,  x + y0, color);// bottom right clock'
    ST7735_DrawPixel(-x + x0,  y + y0, color);// left bottom clock'
    ST7735_DrawPixel(-y + x0,  x + y0, color);// bottom left clock
    ST7735_DrawPixel(-x + x0, -y + y0, color);// left top clock
    ST7735_DrawPixel(-y + x0, -x + y0, color);// top left clock'
    ST7735_DrawPixel( x + x0, -y + y0, color);// right top clock'
    ST7735_DrawPixel( y + x0, -x + y0, color);// top right clock
    y++;
    if (decisionOver2<=0)
    {
      decisionOver2 += 2 * y + 1;   // Change in decision criterion for y -> y+1
    }
    else
    {
      x--;
      decisionOver2 += 2 * (y - x) + 1;   // Change for y -> y+1, x -> x-1
    }
  }
}
Esempio n. 3
0
//************* ST7735_Circle********************************************
//  Draws one line on the ST7735 color LCD
//  Inputs: (x1,y1) is the start point
//          (radious) is the end point
// x1,y2 is the center position of the circle, radious is the number of pixels
// outwards from the center.
//        color 16-bit color, which can be produced by ST7735_Color565() 
// Output: none
void ST7735_Circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color) {
	{
  int x = radius;
  int y = 0;
  int decisionOver2 = 1 - x;

  while( y <= x )
  {
    ST7735_DrawPixel( x + x0,  y + y0, color);
    ST7735_DrawPixel( y + x0,  x + y0, color);
    ST7735_DrawPixel(-x + x0,  y + y0, color);
    ST7735_DrawPixel(-y + x0,  x + y0, color);
    ST7735_DrawPixel(-x + x0, -y + y0, color);
    ST7735_DrawPixel(-y + x0, -x + y0, color);
    ST7735_DrawPixel( x + x0, -y + y0, color);
    ST7735_DrawPixel( y + x0, -x + y0, color);
    y++;
    if (decisionOver2<=0)
    {
      decisionOver2 += 2 * y + 1;
    }
    else
    {
      x--;
      decisionOver2 += 2 * (y - x) + 1;
    }
  }
}
}
Esempio n. 4
0
int main(void) {
	DisableInterrupts();
	PLL_Init(Bus80MHz);             // bus clock at 50 MHz
  Tach_Init();										// initialize the Tach measureing input capture
	PWM0B_Init(40000, 30000); 			// 1000 Hz
	Buttons_Init();
	ST7735_InitR(INITR_REDTAB);
	SysTick_Init();

	EnableInterrupts();

	int32_t x = 0;
	ST7735_SetCursor(0,0);
	printf("Speed:\nTarget:");
	while(1) {
		ST7735_SetCursor(8, 0);
		int32_t speed = Tach_GetSpeed();
		int32_t speedY = ST7735_TFTHEIGHT - 20 - speed / 4;
		printf("%5d.%01d rps", speed / 10, speed % 10);
		ST7735_SetCursor(8, 1);
		printf("%5d.%01d rps", Target_Speed / 10, Target_Speed % 10);
		
		if(x == 0) ST7735_PlotClear(32, 159);
		/*
		Speed = 200000000/Period; // 0.1 rps
	
	if(PID_delay == 0){
		E = Target_Speed-Speed;   // 0.1 rps
		U += (40*E)/64;  // discrete integral
		if(U < 100) U=100;        // Constrain output
		if(U>39900) U=39900;      // 100 to 39900
		PWM0B_Duty(U);            // output
		PID_delay = 4;
	}
	else {
		PID_delay -= 1;
	}*/
		while(! SysTick_ShouldDraw());
		ST7735_DrawPixel(x+1, speedY+1, ST7735_RED);
		ST7735_DrawPixel(x+1, speedY, ST7735_RED);
		ST7735_DrawPixel(x, speedY+1, ST7735_RED);
		ST7735_DrawPixel(x, speedY, ST7735_RED);
		x = (x + 1) % ST7735_TFTWIDTH;

		
		WaitForInterrupt();
	}
}
Esempio n. 5
0
/**************ST7735_XYplot***************
 Plot an array of (x,y) data
 Inputs:  num    number of data points in the two arrays
          bufX   array of 32-bit fixed-point data, resolution= 0.001
          bufY   array of 32-bit fixed-point data, resolution= 0.001
 Outputs: none
 assumes ST7735_XYplotInit has been previously called
 neglect any points outside the minX maxY minY maxY bounds
*/
void ST7735_XYplot(uint32_t num, int32_t bufX[], int32_t bufY[]){
	/*
	convert all fixed point numbers to pixel locations, bounds check them.
	plot pixel with each point.
	*/
	int16_t xPix[num];
	int16_t yPix[num];
	int i;
	
	for(i=0; i<num; i++){
		//do conversions for each int32_t -> pixel location
		//plot on the screen with ST7735_DrawPixel(int16_t x, int16_t y, uint16_t color);
		if(bufX[i]<gi.xMin || bufX[i] > gi.xMax){
			xPix[i] = -1;
			continue;
		} 
		if(bufY[i]<gi.yMin || bufY[i] > gi.yMax){
			yPix[i] = -1;
			continue;
		} 
		xPix[i] = (((gi.smallDem*1000)/gi.xRange)*bufX[i])/1000 + ST7735_TFTWIDTH/2;
		yPix[i] = (((gi.smallDem*1000)/gi.yRange)*bufY[i])/1000 + ST7735_TFTHEIGHT/2;	
	}
	
	for(i=0; i<num; i++){
		if(xPix[i] != -1 && yPix[i] != -1){
			ST7735_DrawPixel(xPix[i], yPix[i], ST7735_WHITE);
		}
	}
	return;
}
Esempio n. 6
0
//************* ST7735_Line********************************************
//  Draws one line on the ST7735 color LCD
//  Inputs: (x1,y1) is the start point
//          (x2,y2) is the end point
// x1,x2 are horizontal positions, columns from the left edge
//               must be less than 128
//               0 is on the left, 126 is near the right
// y1,y2 are vertical positions, rows from the top edge
//               must be less than 160
//               159 is near the wires, 0 is the side opposite the wires
//        color 16-bit color, which can be produced by ST7735_Color565() 
// Output: none
void ST7735_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
	int slopenum; 
	int slopeden;
	int currentx = x1;
	int currenty = y1;
	int counter = 0;
	slopenum = y2 - y1;
	slopeden = x2 - x1;
	if ( abs(slopeden) > abs(slopenum) ){
		int curCount = 1;
		if (slopeden > 0){
			counter = 1;
		} else {
			counter = -1;
		}
		while (currentx != x2){
			ST7735_DrawPixel(currentx, currenty, color);
			currentx += counter;
			currenty = (y1 * slopeden + counter * curCount * slopenum) / (slopeden); 
			++curCount;
		}
	} else {
		int curCount = 1;
		if (slopenum > 0){
			counter = 1;
		} else {
			counter = -1;
		}
		while (currenty != y2){
			ST7735_DrawPixel(currentx, currenty, color);
			currenty += counter;
			currentx = (x1 * slopenum + counter * curCount * slopeden) / (slopenum);
			++curCount;
		}
	}
}
Esempio n. 7
0
/**************ST7735_XYplot***************
 Plot an array of (x,y) data
 Inputs:  num    number of data points in the two arrays
          bufX   array of 32-bit fixed-point data, resolution= 0.001
          bufY   array of 32-bit fixed-point data, resolution= 0.001
 Outputs: none
 assumes ST7735_XYplotInit has been previously called
 neglect any points outside the minX maxY minY maxY bounds
*/
void ST7735_XYplot(uint32_t num, int32_t bufX[], int32_t bufY[]) {

	int n;
	for(n=0; n < num; n++){
		//For the Kentec
		//LCD_DrawPixel(bufX[n], bufY[n], 0xFFE0);
		//For the SS7735
		//ST7735_XYPoint(bufX[n], bufY[n]);
		int yRange=(MaxYplot-MinYplot);
		int y=MinYplot+bufY[n];
		int xRange=(MaxXplot-MinXplot);
		int x=MinXplot+bufX[n];
		if(bufX[n]<=MaxXplot && bufY[n]<=MinYplot)
		{
			ST7735_DrawPixel(x, y, ST7735_BLUE);
		}
	}
}
Esempio n. 8
0
void ST7735_XYplot(uint32_t count, int32_t bufX[], int32_t bufY[])
{
  for (int i = 0; i < count; ++i) {
    int x = bufX[i];
    int y = bufY[i];
		
		if (x < MinX || MaxX < x || y < MinY || MaxY < y) {
			// Neglect any points outside the minX maxY minY maxY bounds.
			continue;
		}
		// from plotpoints
	// X goes from 0 to 127
  // j goes from 159 to 32
  // y=Ymax maps to j=32
  // y=Ymin maps to j=159
    int hwX = (127 * (x - MinX)) / (MaxX - MinX);  
    int hwY = 32 + (127 * (MaxY - y)) / (MaxY - MinY);
    ST7735_DrawPixel(hwX, hwY, ST7735_MAGENTA);
  }
}
Esempio n. 9
0
void drawLine(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint32_t color){
	int32_t dx;
	int32_t dy;
	int32_t x;
	int32_t y;
	int32_t xend;
	int32_t yend;
	int32_t dxAbs;
	int32_t dyAbs;
	int32_t midApprX;
	int32_t midApprY;

	dx = x2 - x1;
	dy = y2 - y1;

	if (dx < 0) { dxAbs = dx * -1; }
	else { dxAbs = dx; }
	if (dy < 0) { dyAbs = dy * -1; }
	else { dyAbs = dy; }
	midApprX = 2*dyAbs - dxAbs; //multiply by 2 due to integer arithmetic
	midApprY = 2*dxAbs - dyAbs;
	
	//need the larger axis range to be the one spanned across
	if(dyAbs <= dxAbs)
	{
		//need to start from smallest x to increment to higher x
		if(dx >= 0)
		{
			y = y1;
			xend = x2;
			x = x1;
		}
		else
		{
			y = y2;
			x = x2;
			xend = x1;
		}
		ST7735_DrawPixel(x,y,color);
		while(x <= xend)
			{
				x++;
				if(midApprX < 0)
				{
					midApprX += 2*dyAbs;
				}		
				else
				{
					midApprX += 2*(dyAbs - dxAbs);
					if((dy < 0 && dx < 0) ||(dy > 0 && dx > 0)){ y++; }
					else { y--; }
				}
				ST7735_DrawPixel(x,y,color);
			}
	}
	else //The y range is larger
	{
		if(dy >= 0)
		{
			x = x1;
			y = y1;
			yend = y2;
		}
		else
		{
			x = x2;
			y = y2;
			yend = y1;
		}
		ST7735_DrawPixel(x,y,color);
		while(y <= yend)
		{
			y++;
			if(midApprY < 0)
			{
				midApprY += 2*dxAbs;
			}		
			else
			{
				midApprY += 2*(dxAbs - dyAbs);
				if((dy < 0 && dx < 0) ||(dy > 0 && dx > 0)){ x++; }
				else { x--; }
			}
			ST7735_DrawPixel(x,y,color);
		}
	}
}
Esempio n. 10
0
int displayImage(const char* fname) {
    UART_Printf("Openning %s...\r\n", fname);
    FIL file;
    FRESULT res = f_open(&file, fname, FA_READ);
    if(res != FR_OK) {
        UART_Printf("f_open() failed, res = %d\r\n", res);
        return -1;
    }

    UART_Printf("File opened, reading...\r\n");

    unsigned int bytesRead;
    uint8_t header[34];
    res = f_read(&file, header, sizeof(header), &bytesRead);
    if(res != FR_OK) {
        UART_Printf("f_read() failed, res = %d\r\n", res);
        f_close(&file);
        return -2;
    }

    if((header[0] != 0x42) || (header[1] != 0x4D)) {
        UART_Printf("Wrong BMP signature: 0x%02X 0x%02X\r\n", header[0], header[1]);
        f_close(&file);
        return -3;
    }

    uint32_t imageOffset = header[10] | (header[11] << 8) | (header[12] << 16) | (header[13] << 24);
    uint32_t imageWidth = header[18] | (header[19] << 8) | (header[20] << 16) | (header[21] << 24);
    uint32_t imageHeight = header[22] | (header[23] << 8) | (header[24] << 16) | (header[25] << 24);
    uint16_t imagePlanes = header[26] | (header[27] << 8);
    uint16_t imageBitsPerPixel = header[28] | (header[29] << 8);
    uint32_t imageCompression = header[30] | (header[31] << 8) | (header[32] << 16) | (header[33] << 24);

    UART_Printf(
        "--- Image info ---\r\n"
        "Pixels offset: %lu\r\n"
        "WxH: %lux%lu\r\n"
        "Planes: %d\r\n"
        "Bits per pixel: %d\r\n"
        "Compression: %d\r\n"
        "------------------\r\n",
        imageOffset, imageWidth, imageHeight, imagePlanes, imageBitsPerPixel, imageCompression);

    if((imageWidth != ST7735_WIDTH) || (imageHeight != ST7735_HEIGHT)) {
        UART_Printf("Wrong BMP size, %dx%d expected\r\n", ST7735_WIDTH, ST7735_HEIGHT);
        f_close(&file);
        return -4;
    }

    if((imagePlanes != 1) || (imageBitsPerPixel != 24) || (imageCompression != 0)) {
        UART_Printf("Unsupported image format\r\n");
        f_close(&file);
        return -5;
    }

    res = f_lseek(&file, imageOffset);
    if(res != FR_OK) {
        UART_Printf("f_lseek() failed, res = %d\r\n", res);
        f_close(&file);
        return -6;
    }

    // row size is aligned to 4 bytes
    uint8_t imageRow[(ST7735_WIDTH * 3 + 3) & ~3];
    for(uint32_t y = 0; y < imageHeight; y++) {
        uint32_t rowIdx = 0;
        res = f_read(&file, imageRow, sizeof(imageRow), &bytesRead);
        if(res != FR_OK) {
            UART_Printf("f_read() failed, res = %d\r\n", res);
            f_close(&file);
            return -7;
        }

        for(uint32_t x = 0; x < imageWidth; x++) {
            uint8_t b = imageRow[rowIdx++];
            uint8_t g = imageRow[rowIdx++];
            uint8_t r = imageRow[rowIdx++];
            uint16_t color565 = ST7735_COLOR565(r, g, b);
            ST7735_DrawPixel(x, imageHeight - y - 1, color565);
        }
    }

    res = f_close(&file);
    if(res != FR_OK) {
        UART_Printf("f_close() failed, res = %d\r\n", res);
        return -8;
    }

    return 0;
}
Esempio n. 11
0
//------------Character_Draw2------------
// Draw a character onto the screen without black borders
// Input: Character struct to be drawn
// Output: none
void Character_Draw(Character data){
	for(int y=0; y<(*data.bmp).height; y++)
		for(int x=0; x<(*data.bmp).width; x++)
			if((*data.bmp).array[x+y*(*data.bmp).width] != 0x0000)	// check to see if pixel is black
				ST7735_DrawPixel(data.x-frameXCord+x, data.y-frameYCord-y, (*data.bmp).array[x+y*(*data.bmp).width]);
}