#include "draw.h" ADC_InitTypeDef ADC_InitStructure; //======================================================================== void ChangeBand(uint8_t Band, uint8_t Mode) { TIM_Cmd(TIM2, DISABLE); DrawString(Str_Band[Band], 24, 3, CYAN, RED); if (Mode==2) {DrawString(StringFFT[Band], 23, 224, YELLOW, 0);} if (Band<3) { // DMA OFF, Start ADC ContinuousConvMode DMA_Cmd(DMA1_Channel1, DISABLE); ADC_SoftwareStartConvCmd(ADC1, DISABLE); DMA_ClearFlag(DMA1_FLAG_GL1); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_Init(ADC1, &ADC_InitStructure); ADC_SoftwareStartConvCmd(ADC1, ENABLE); } else { // DMA ON, Start ADC Tim2 if (Band<=10) { ADC_SoftwareStartConvCmd(ADC1, DISABLE); ADC_Cmd(ADC1, DISABLE); DMA_Cmd(DMA1_Channel1, DISABLE); DMA_ClearFlag(DMA1_FLAG_GL1); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_Init(ADC1, &ADC_InitStructure); ADC_Cmd(ADC1, ENABLE); DMA_Cmd(DMA1_Channel1, ENABLE); ADC_DMACmd(ADC1 , ENABLE); } else { // DMA OFF, Start ADC Tim2 ADC_SoftwareStartConvCmd(ADC1, DISABLE); ADC_Cmd(ADC1, DISABLE); DMA_Cmd(DMA1_Channel1, DISABLE); DMA_ClearFlag(DMA1_FLAG_GL1); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_Init(ADC1, &ADC_InitStructure); ADC_Cmd(ADC1, ENABLE); ADC_SoftwareStartConvCmd(ADC1, ENABLE); } } if (Band==15) { Frame(0, 24, 320, 216, LGRID, 0); } TIM2->ARR = TIM2_ADC_Period[Band]; TIM2->PSC = TIM2_ADC_Prescaler[Band]; TIM2->CNT = 0; TIM_Cmd(TIM2, ENABLE); } //======================================================================== void DrawOSD(uint8_t Band, uint8_t Sync, uint8_t Vbat, uint8_t Mode) { LCDclr(16,0,2,24,BLACK); Frame(18, 0, 82, 24, LGRID, RED); // Band Frame(100, 0, 39, 24, LGRID, BLACK); // Sync Frame(139, 0, 101, 24, LGRID, BLUE); // Frequence Frame(240, 0, 80, 24, LGRID, BLUE); // Uin if (Mode==0) {Frame(0, 24, 320, 216, LGRID, 0);} // OSC if (Mode==1) {Frame(0, 24, 320, 184, LGRID, 0); // OSC+miniOSC Frame(0, 208, 320, 32, LGRID, 0);} if (Mode==2) {Frame(0, 24, 320, 184, LGRID, 0);} // FFT if (Mode==3) {Frame(0, 24, 320, 184, LGRID, 0);} // Voltmeter ChangeBand(Band, Mode); DrawSim24x20(107, 2, YELLOW, Sync+2); // DrawString("10.0kHz", 148, 3, WHITE, BLUE); // DrawString("~3.12V", 245, 3, YELLOW, BLUE); DrawPicture16x1(0, 0, 0); // Up BAT DrawPicture16x1(0, 1, 1); DrawPicture16x1(0, 23, 3); // Down BAT DrawBat(Vbat); // level BAT } //=========================================== //--------- DISPLAY 320 x 216 ------------= //=========================================== void Draw320x216(uint16_t *buffer, uint16_t PointSync, uint8_t CursorRED, uint8_t CursorBLUE) { SendCMD(ILI9341_MAC); SendDAT(Orient_Land); SendCMD(ILI9341_PAGE_ADDR); SendDAT(0); SendDAT(1); SendDAT(0x01); SendDAT(0x3E); SendCMD(ILI9341_COLUMN_ADDR); SendDAT(0); SendDAT(32-31); SendDAT(0); SendDAT(212+2); SendCMD(ILI9341_GRAM); GPIO_SetBits(GPIOB, LCD_RS); // data for (uint16_t j = 1; j < 319; j++) { // uint8_t beam_new=45+buffer[j+PointSync]/2; // uint8_t beam_old=45+buffer[j+PointSync-1]/2; uint8_t beam_new=1+(buffer[j+PointSync]*216/256); uint8_t beam_old=1+(buffer[j+PointSync-1]*216/256); uint16_t color = BLACK; if (j==40||j==80||j==120||j==160||j==200||j==240||j==280) {color = GRID;} for (uint8_t i = 1; i < 215; i++) { uint16_t send_color = color; if (i==36||i==72||i==144||i==180) {send_color = GRID;} if (i==108) {send_color = LGRID;} // if (i==CursorRED) {send_color = RED;} // if (i==CursorBLUE) {send_color = BLUE;} if ( beam_new > beam_old ) { if (( i < beam_new )&( i >= beam_old )) {send_color = WHITE;}} else {if (( i >= beam_new )&( i <= beam_old )) {send_color = WHITE;}} SPI_I2S_SendData(SPI1, send_color>>8); SPI_I2S_SendData(SPI1, send_color); } } } //=========================================== //--------- DISPLAY 320 x 184 ------------= //=========================================== void Draw320x184(uint16_t *buffer, uint16_t PointSync, uint8_t CursorRED, uint8_t CursorBLUE) { SendCMD(ILI9341_MAC); SendDAT(Orient_Land); SendCMD(ILI9341_PAGE_ADDR); SendDAT(0); SendDAT(1); SendDAT(0x01); SendDAT(0x3E); SendCMD(ILI9341_COLUMN_ADDR); SendDAT(0); SendDAT(33); SendDAT(0); SendDAT(214); SendCMD(ILI9341_GRAM); GPIO_SetBits(GPIOB, LCD_RS); // data for (uint16_t j = 1; j < 319; j++) { // uint8_t beam_new=16+45+buffer[j+PointSync]/2; // uint8_t beam_old=16+45+buffer[j+PointSync-1]/2; uint8_t beam_new=16+18+(buffer[j+PointSync]*180/256); uint8_t beam_old=16+18+(buffer[j+PointSync-1]*180/256); uint16_t color = BLACK; if (j==40||j==80||j==120||j==160||j==200||j==240||j==280) {color = GRID;} for (uint8_t i = 33; i < 215; i++) { uint16_t send_color = color; if (i==36+16||i==72+16||i==144+16||i==180+16) {send_color = GRID;} if (i==108+16) {send_color = LGRID;} // if (i==CursorRED) {send_color = RED;} // if (i==CursorBLUE) {send_color = BLUE;} if ( beam_new > beam_old ) { if (( i < beam_new )&( i >= beam_old )) {send_color = WHITE;}} else {if (( i >= beam_new )&( i <= beam_old )) {send_color = WHITE;}} SPI_I2S_SendData(SPI1, send_color>>8); SPI_I2S_SendData(SPI1, send_color); } } } //=========================================== //--------- DISPLAY 320 x 32 -------------= //=========================================== void Draw320x32(uint16_t *buffer, uint16_t PointSync, uint8_t Freez) { SendCMD(ILI9341_MAC); SendDAT(Orient_Land); SendCMD(ILI9341_PAGE_ADDR); SendDAT(0); SendDAT(1); SendDAT(0x01); SendDAT(0x3E); SendCMD(ILI9341_COLUMN_ADDR); SendDAT(0); SendDAT(1); SendDAT(0); SendDAT(30); SendCMD(ILI9341_GRAM); GPIO_SetBits(GPIOB, LCD_RS); // data for (uint16_t j = 1; j < 319; j++) { for (uint8_t i = 1; i < 31; i++) { uint16_t send_color = BACKGROUND_32; if (i==16) {send_color = LGRID;} uint8_t beam_new=8+(buffer[j*8])/16; uint8_t beam_old=8+(buffer[(j-1)*8])/16; // uint8_t beam_new=(buffer[j*8])/8; //uint8_t beam_old=(buffer[(j-1)*8])/8; if ( beam_new > beam_old ) { if (( i < beam_new )&( i >= beam_old )) {send_color = GREEN;}} else {if (( i >= beam_new )&( i <= beam_old )) {send_color = GREEN;}} SPI_I2S_SendData(SPI1, send_color>>8); SPI_I2S_SendData(SPI1, send_color); } } } void DrawColumn(uint8_t beam_new, uint8_t beam_old, uint16_t j) { uint16_t color = 0; if (j==40||j==80||j==120||j==160||j==200||j==240||j==280) {color = GRID;} SendCMD(ILI9341_PAGE_ADDR); SendDAT(j>>8); SendDAT(j); SendDAT(j>>8); SendDAT(j); SendCMD(ILI9341_COLUMN_ADDR); SendDAT(0); SendDAT(1); SendDAT(0); SendDAT(214); SendCMD(ILI9341_GRAM); GPIO_SetBits(GPIOB, LCD_RS); // data for (uint8_t i = 1; i < 215; i++) { uint16_t send_color = color; if (i==36||i==72||i==144||i==180) {send_color = GRID;} // if (i==Cursor) {send_color = RED;} if (i==108) {send_color = LGRID;} if ( beam_new > beam_old ) { if ( i < beam_new && i >= beam_old ) {send_color = WHITE;}} else {if ( i >= beam_new && i <= beam_old ) {send_color = WHITE;}} while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); SPI_I2S_SendData(SPI1, send_color>>8); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); SPI_I2S_SendData(SPI1, send_color); } } //=========================================== //--------- DISPLAY 320 x 216 x 256 -------= //=========================================== const uint16_t grad[] = { 0, 0, 0, 0, 8192, 8192, 8192, 8192, 16648, 16648, 16648, 16648, 24840, 24840, 24840, 24840, 33296, 33296, 33296, 33296, 41488, 41488, 41488, 41488, 49944, 49944, 49944, 49944, 58136, 58136, 58136, 58136, 1057, 1057, 1057, 1057, 9249, 9249, 9249, 9249, 17705, 17705, 17705, 17705, 25897, 25897, 25897, 25897, 34353, 34353, 34353, 34353, 42545, 42545, 42545, 42545, 51001, 51001, 51001, 51001, 59193, 59193, 59193, 59193, 2114, 2114, 2114, 2114, 10306, 10306, 10306, 10306, 18762, 18762, 18762, 18762, 26954, 26954, 26954, 26954, 35410, 35410, 35410, 35410, 43602, 43602, 43602, 43602, 52058, 52058, 52058, 52058, 60250, 60250, 60250, 60250, 3171, 3171, 3171, 3171, 11363, 11363, 11363, 11363, 19819, 19819, 19819, 19819, 28011, 28011, 28011, 28011, 36467, 36467, 36467, 36467, 44659, 44659, 44659, 44659, 53115, 53115, 53115, 53115, 61307, 61307, 61307, 61307, 4228, 4228, 4228, 4228, 12420, 12420, 12420, 12420, 20876, 20876, 20876, 20876, 29068, 29068, 29068, 29068, 37524, 37524, 37524, 37524, 45716, 45716, 45716, 45716, 54172, 54172, 54172, 54172, 62364, 62364, 62364, 62364, 5285, 5285, 5285, 5285, 13477, 13477, 13477, 13477, 21933, 21933, 21933, 21933, 30125, 30125, 30125, 30125, 38581, 38581, 38581, 38581, 46773, 46773, 46773, 46773, 55229, 55229, 55229, 55229, 63421, 63421, 63421, 63421, 6342, 6342, 6342, 6342, 14534, 14534, 14534, 14534, 22990, 22990, 22990, 22990, 31182, 31182, 31182, 31182, 39638, 39638, 39638, 39638, 47830, 47830, 47830, 47830, 56286, 56286, 56286, 56286, 64478, 64478, 64478, 64478, 7399, 7399, 7399, 7399, 15591, 15591, 15591, 15591, 24047, 24047, 24047, 24047, 32239, 32239, 32239, 32239, 40695, 40695, 40695, 40695, 48887, 48887, 48887, 48887, 57343, 57343, 57343, 57343, 65535, 65535, 65535, 65535, 65535, }; uint16_t Draw320x216x256(uint16_t *buffer, uint16_t position, uint8_t Cursor, uint8_t KeyStatus) { // draw 256 columns #define plume 256 for (uint16_t column = 0; column < plume; column++) { uint16_t draw_column; uint8_t top; uint8_t bot; if (position > column) {draw_column = position-column;} // 1-0=1 318-0=318 else {draw_column = position+318-column;} // 1+318-1=318 1+318-317=1 uint16_t old_column=draw_column-1; if (old_column==0) {old_column=318;} uint8_t new_buffer=buffer[draw_column]; // <=215 uint8_t old_buffer=buffer[old_column]; if (new_buffer>old_buffer) { top=new_buffer; bot=old_buffer; } else { top=old_buffer; bot=new_buffer; } if(top>=214) {top=213;} if(bot>=214) {bot=213;} SendCMD(ILI9341_MAC); SendDAT(Orient_Land); SendCMD(ILI9341_PAGE_ADDR); SendDAT(draw_column>>8); SendDAT(draw_column); SendDAT(draw_column>>8); SendDAT(draw_column); SendCMD(ILI9341_COLUMN_ADDR); SendDAT(0); SendDAT(bot+1); SendDAT(0); SendDAT(top+1); SendCMD(ILI9341_GRAM); GPIO_SetBits(GPIOB, LCD_RS); // data // uint16_t color=(((plume-column)/8)<<11)|(((plume-column)/8)<<6)|(((plume-column)/8)); uint16_t color=grad[plume-column]; if ((plume-column)<64) { if (draw_column==40||draw_column==80||draw_column==120||draw_column==160||draw_column==200||draw_column==240||draw_column==280) {color = color | 0xE701;} } for (uint8_t i = 0; i < top-bot+1; i++) { unsigned short send_color=color; if ((plume-column)<64) { if (bot+i==34||bot+i==70||bot+i==142||bot+i==178) {send_color = send_color | 0xE701;} } if ((plume-column)<128) { if (bot+i==106) {send_color = send_color | 0x0C43;} } // if (i+bot==0 || (i==top-bot && top==182)) {send_color = 0x0C43;} while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, send_color); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, send_color>>8); } } // draw 256 columns return position; } //----------------------------------------------------------- void DrawUin(uint16_t Uin) { Uin=Uin*5/4; uint8_t DD2= Uin/100; uint8_t DD3=(Uin-DD2*100)/10; uint8_t DD4= Uin-DD2*100-DD3*10; DrawSim16(126-32, 244, 3, YELLOW, BLUE); DrawSim16(DD2+16, 258, 3, YELLOW, BLUE); DrawSim16(DD3+16, 272, 3, YELLOW, BLUE); DrawSim16(DD4+16, 286, 3, YELLOW, BLUE); DrawSim16(86-32, 302, 3, YELLOW, BLUE); Point(271, 16, YELLOW); } //----------------------------------------------------------- void DrawFreq(uint32_t Frequence) { /* Frame(0, 0, 100, 24, LGRID, BLACK); char D0= Frequence/100000; char D1=(Frequence-D0*100000)/10000; char D2=(Frequence-D0*100000-D1*10000)/1000; char D3=(Frequence-D0*100000-D1*10000-D2*1000)/100; char D4=(Frequence-D0*100000-D1*10000-D2*1000-D3*100)/10; char D5= Frequence-D0*100000-D1*10000-D2*1000-D3*100-D4*10; DrawSim16(D0+16, 4+ 0, 3, WHITE, BLACK); DrawSim16(D1+16, 4+14, 3, WHITE, BLACK); DrawSim16(D2+16, 4+28, 3, WHITE, BLACK); DrawSim16(D3+16, 4+42, 3, WHITE, BLACK); DrawSim16(D4+16, 4+56, 3, WHITE, BLACK); DrawSim16(D5+16, 4+70, 3, WHITE, BLACK); */ uint16_t color=WHITE; uint8_t Frequence_point; if(Frequence==0) { color=GRAY; DrawString("-------", 140, 3, GRAY, BLUE);} else { color=WHITE; if (Frequence>=10000000) { Frequence_point=2; DrawString("mHz", 196, 3, color, BLUE); Frequence=Frequence/100000;} else { if (Frequence>=1000000) { Frequence_point=0; DrawString("kHz", 196, 3, color, BLUE); Frequence=Frequence/10000;} else { if (Frequence>=100000) { Frequence_point=3; DrawString("kHz", 196, 3, color, BLUE); Frequence=Frequence/1000;} else { if (Frequence>=10000) { Frequence_point=2; DrawString("kHz", 196, 3, color, BLUE); Frequence=Frequence/100;} else { if (Frequence>=1000) { Frequence_point=0; DrawString(" Hz", 196, 3, color, BLUE); Frequence=Frequence/10;} else { if (Frequence>=100) { Frequence_point=3; DrawString(" Hz", 196, 3, color, BLUE); Frequence=Frequence/1;} else { Frequence_point=3; DrawString(" Hz", 196, 3, color, BLUE); }}}}}} char F1= Frequence/1000; char F2=(Frequence-F1*1000)/100; char F3=(Frequence-F1*1000-F2*100)/10; char F4=(Frequence-F1*1000-F2*100-F3*10); // char F5= Frequence-F1*10000-F2*1000-F3*100-F4*10; if (F1==0 && Frequence_point!=1) {DrawSim16(0, 140, 3, color, BLUE);} else {DrawSim16(F1+16, 140, 3, color, BLUE);} if (F1==0 && F2==0 && (Frequence_point==0||Frequence_point==3)) {DrawSim16(0, 140+14, 3, color, BLUE);} else {DrawSim16(F2+16, 140+14, 3, color, BLUE);} // DrawSim16(F1+16, 140, 3, color, BLUE); // DrawSim16(F2+16, 140+14, 3, color, BLUE); DrawSim16(F3+16, 140+28, 3, color, BLUE); DrawSim16(F4+16, 140+42, 3, color, BLUE); // Frequence_point==0 0000 if (Frequence_point==1) {Point(139+14, 16, color);} // 0.000 if (Frequence_point==2) {Point(139+28, 16, color);} // 00.00 if (Frequence_point==3) {Point(139+42, 16, color);} // 000.0 } }