Exemple #1
0
/**
 * @brief  Displays a keypad on touchscreen
 * @param  none
 * @retval none
 */
void Make_Touch_Pad(void) {

    int t_y = 7;
    int t_y1;
    int ft = 2;
    int t_x = 4;
    int lines = 7;
    int column = 20;

    int pitch;
    int ys; //terminal is organised in lines 1..30/15, depending on
    //selcted font -> to calculate pixelpostion, decrement line and multiplay with font height
    int yh;
    int xw;
    int xs;
    int x;
    int y;

    TFT_Init();

    TFT_cursor_off();
    TFT_graphic_cls();
    TFT_touch_area_clear();

    //_-------------------------------------------------
    //---- 2. Define the small blue terminal window ----
    //--------------------------------------------------
    TFT_set_font_color(YELLOW); // define terminal colors

    t_y = 3;
    ft = 2;
    t_x = 4;
    lines = 7;
    column = 20;
    TFT_set_window(ft, t_x, t_y, column, lines); // define the font (8x16), origin
    //(5x8=40,7x16=112), width (20 character) and height (7 lines)
    // note: origin is defined as column no.7 and line no.10 (not dots)
    TFT_terminal_on(); // Terminal on        

    // ----------------------------------------------
    //---- 3. Define a keypad with numbers 0..9 ----
    //---------------------------------------------
    TFT_touch_area_font_color(YELLOW, BLACK); // define color for touch font
    TFT_touch_area_font(SWISS30B); // set font for touch area
    TFT_touch_area_frame(20, 0); //set border no. 20
    TFT_touch_area_color(WHITE, BLACK, BLUE, WHITE, BLACK, YELLOW); //set border colors normal and for selection
    // using a constant for (touch)size and (touch)pitch makes it 
    //more easy to move the whole key group later
    // XPIXEL=320 and YPIXEL=240 
    pitch = 2;
    t_y1 = 5; // startline for button
    ys = (t_y1 - 1) * ft * 8; //terminal is organised in lines 1..30/15, depending on
    //selcted font -> to calculate pixelpostion, decrement line and multiplay with font height
    yh = (YPIXEL - ys - 3 * pitch) / NUMBER_BUTTON_VERTICAL; // 4 button vertical
    xw = yh; // width same as hight
    xs = XPIXEL - (NUMBER_BUTTON_HORIZONTAL * xw + 2 * pitch); // 7 button in line
    x = xs; // xs is left start of button
    y = ys;
    TFT_touch_area(x, y, x + xw, y + yh, '1', 0, "1"); // define a touchkey with number "1". 
    x += pitch + xw; //while release, touchmacro no. 20 will be executed
    TFT_touch_area(x, y, x + xw, y + yh, '2', 0, "2");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '3', 0, "3");
    x += pitch + xw; // empty place
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, 'r', 0, "r");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, 'd', 0, "d");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, 's', 0, "st");
    // -- start 2nd row of buttons	 
    x = xs;
    y += pitch + yh;
    TFT_touch_area(x, y, x + xw, y + yh, '4', 0, "4");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '5', 0, "5");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '6', 0, "6");
    x += pitch + xw; // empty place
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '+', 0, "+");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '-', 0, "-");

    // -- start 3rd row of buttons	 	 
    x = xs;
    y += pitch + yh;
    TFT_touch_area(x, y, x + xw, y + yh, '7', 0, "7");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '8', 0, "8");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '9', 0, "9");
    x += pitch + xw; // empty place
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '*', 0, "*");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '/', 0, "/");
    // -- start 4th row of button
    x = xs;
    y += pitch + yh;
    //TFT_touch_area( x,y,x+xw,y+yh, 0,0, "=" );
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, '0', 0, "0");
    x += pitch + xw;
    //TFT_touch_area( x, y, x+xw, y+yh, 0, 0, "" );
    x += pitch + xw; // empty place
    //x+=pitch+xw;
    //TFT_touch_area( x, y, x+xw, y+yh, '=', 0, "=" );
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, 'e', 0, "e");
    x += pitch + xw;
    TFT_touch_area(x, y, x + xw, y + yh, 'c', 0, "c");

    return;

}
Exemple #2
0
int main(void) {
	RCC_ClocksTypeDef RCC_Clocks;
	
	/* default value with 440 Hz delta fi and Amplitude 1.0V*/
	d_phi = D_PHI_440HZ;
	b = AMPLITUDE_B_HIGH;
	
    initCEP_Board();
	initTimer_Dac();	
		
	msecs = 0;
	
	
	RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
	
	TFT_cursor_off();
	
	//Mark buffer as empty
	buf1.isEmpty = 1;
	buf2.isEmpty = 1;
	
	bgbuf  = &buf1;
	isrbuf = &buf1;
   
	TFT_cls();
	TFT_puts("CEP4");
	TFT_gotoxy(1, 2);
	TFT_puts("Besnik & Burim Mulici");
	TFT_gotoxy(1,5);
	TFT_puts("msecs: ");
	TFT_gotoxy(1,6);
	TFT_puts("Interrupts: ");	
	TFT_gotoxy(1,7);
	TFT_puts("delta_P: ");
	TFT_gotoxy(1,8);
	TFT_puts("Frequenz:  440");
	TFT_gotoxy(1,9);
	TFT_puts("Form:    Sinus");	

	
    while (1) {
		
		read_buttons();
	
		//slow down display output
		if(msecCountVar <= msecCounter) {						 
			msecCountVar++;
		} else {
			msecCountVar = 0;
		}
		
		//Display output
		if((output ==1) && (msecCountVar == msecCounter)){		
			ITM->PORT[11].u32 = 0;
			
			TFT_gotoxy(1,5);
			TFT_puts("msecs: ");
			sprintf(msecbuf, "%d" , msecs);
			TFT_puts(msecbuf);	
			
			TFT_gotoxy(1,6);
			TFT_puts("Interrupts: ");
			sprintf(interruptbuf, "%d", interruptCounter);
			TFT_puts(interruptbuf);
			
			TFT_gotoxy(1,7);
			TFT_puts("delta_P: ");
			sprintf(d_phi_buf, "%d", d_phi);
			TFT_puts(d_phi_buf);
			
			ITM->PORT[11].u32 = 1;
		}
		
		//Buffer empty? If yes fill it and Wait-LED off, else Wait-LED on
		if(bgbuf->isEmpty){										
			
			resetLED(WAITING);
			ITM->PORT[12].u32 = 0;
			fill_Buf(bgbuf);
			ITM->PORT[12].u32 = 1;
						
			if(bgbuf == &buf1) { bgbuf = &buf2;} 
			else{ bgbuf = &buf1;}
			
		} else {
			setLED(WAITING);
		}			       
    }
}
Exemple #3
0
void labor6(void) {
    run = 1;
    syncword_address =0;
    spi_address = 0;
    pwmVal = 0;
    HMP3Decoder mp3dec;
    bytesLeft = 0;
    bytesTilSyncWord = 0;
    decodeRetVal = 0;
    errorCounter = 0;
    idx_ISR = 0;
    mainBuf_empty = 1;
    interrupt_Counter = 0;
    mseczaehlvar = 0;

    RCC_ClocksTypeDef RCC_Clocks;
    msec = 0;
    int i = 0;

    //Amplitude 1.0V (b_big)
    amplitude = b_big;

    spi_setup();
    setup_TIM8_DAC_PWM();
    mp3dec = MP3InitDecoder();

    //SysTick end of count event each 10ms
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

    TFT_cursor_off();

    buf1.isEmpty = 1;
    buf2.isEmpty = 1;

    mp3OutBuffer = &buf1;		//start with buf1
    irsInBuffer = &buf1;

    TFT_cls();
    TFT_gotoxy(1,1);
    TFT_puts("Frequenz:   5000");

    while(B1 != 0 && B2 != 0) {}

    do {
        //Check Buttons
        read_buttons();
        //ausgabe
        print_display();

        //wenn der mainBuf leer ist, muss der durch readSPI mit mp3-daten gefuellt werden
        if (mainBuf_empty) {

            do {

                //Shift bytes to the beginning
                /**
                * Bsp:  mainBufSize = 10
                * 			readBytes = 7 --> bytesLeft = 3
                * 			for(){
                * 				mainBuffer[0] = mainBuffer[(10-3)+0]	idx[0] = idx[7]
                * 				mainBuffer[1] = mainBuffer[(10-3)+1]	idx[1] = ide[8] ...
                */
                for(i = 0; i < bytesLeft; i++) {															//die ungelesene bytes am anfang stellen
                    mainBuf[i] = mainBuf[(MAINBUF_SIZE - bytesLeft) + i];
                }

                //Reads size-bytes from current_SPI_Address and writes them into the given array ((mainBuffer + nBytesLeft))
                //also nach diesem aufruf, ist der mainBuf voll und spiadresse muss verschoben werden
                spiFlashMemRead(SPI_MEM_WORK, spi_address, (mainBuf + bytesLeft),  MAINBUF_SIZE - bytesLeft);

                //nach sync word in dem mainBuf suchen
                bytesTilSyncWord = MP3FindSyncWord(mainBuf, MAINBUF_SIZE);


                if (bytesTilSyncWord == 0) {	//falls guelltige date gleich am anfang liegen
                    spi_address =  spi_address + (MAINBUF_SIZE - bytesLeft);
                } else if (bytesTilSyncWord < 0) {//fehler, kein sync word gefunden
                    run = 0;
                } else if (bytesTilSyncWord > 0) {//falls skip word an der n-te adresse gefunden wurde, verschiebe ich die spiadresse um n, damit ich beim naechsten durchlauf vom flash nur die guelltige daten lese (also muell ueberspringen)
                    spi_address = (spi_address - bytesLeft )+ bytesTilSyncWord;
                }

                bytesLeft = 0;		//MUSS DAS HIER NICHT AUSSERHALB DER WHILE ?? DAMIT DIE NBYTES NICHT VERLOREN GEHEN
            } while(bytesTilSyncWord != 0 && run);

            mainBuf_empty = 0; //mainBuf ist voll
        }


        if (run) {	//wenn kein fehler

            //wenn der mp3OutBuf voll ist ODER der MainBuf leer ist, dann warten (WAITING-LED) anschalten
            if (!mp3OutBuffer->isEmpty || mainBuf_empty) {
                setLED(WAITING_LED);
            } else {
                resetLED(WAITING_LED);

                bytesLeft = MAINBUF_SIZE;																					//in nBytesLeft steht wieviele daten aus dem MainBuf noch in dem mp3OutBuf uebertragen werden muessen
                ptrMainBuf = mainBuf;																			//mainBufPointer soll auf MainBuff zeigen, obwohl es bei der initialisierung schon gemacht wurde !!

                /**
                	* para1: decoder instance
                	*	para2: buffer aus dem die daten decodet werden sollen
                	* para3: (input) --> anzahl gueltige bytes, die gelesen werden sollen,
                	* 			 (output)--> input - gelesene bytes, also die bytes die noch gelesen werden muessen
                	* para4: der buffer in dem geschrieben werden soll, der pointer wird geupdatet (bis wo der voll geschrieben wurde)
                	*/

                //nach diesem aufruf ist der mp3OutBuf auf jeden fall voll
                decodeRetVal = MP3Decode(mp3dec, &ptrMainBuf, &bytesLeft, mp3OutBuffer->data, 0);		//decodeResult -->(0 means no error, < 0 means error)


                mainBuf_empty = 1;																									//der mainBuf ist nicht komplett voll

                if (decodeRetVal < 0) {
                    errorCounter++;
                } else {
                    errorCounter = 0;
                }

                if (errorCounter > 2) {																							//fehler beim decode aufgetreten
                    run = 0;
                } else {
                    mp3OutBuffer->isEmpty = 0;																			//der mp3OutBuffer wurde voll geschrieben, bereit fuer die ISR
                    if(mp3OutBuffer == &buf1) {																			//buffer ist voll, also wechseln
                        mp3OutBuffer = &buf2;
                    } else if (mp3OutBuffer == &buf2) {
                        mp3OutBuffer = &buf1;
                    }
                }
            }
        }

    } while (run);

    MP3FreeDecoder(mp3dec);

}