//Show char //x:0~63 //y:0~31 //size:select the font 16/12 void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr, uint8_t size, uint8_t mode) { uint8_t temp,t,t1; uint8_t y0=y; chr=chr-' ';//get the offset for(t=0;t<size;t++) { if(size == 12) temp = asc2_1206[chr][t]; //font:1206 else if(size == 16) temp = asc2_1608[chr][t]; //font:1608 else temp = asc2_3208[chr][t]; //font:3208 for(t1=0; t1<8; t1++) { if(temp&0x80)OLED_DrawPoint(x,y,mode); else OLED_DrawPoint(x,y,!mode); temp<<=1; y++; if((y-y0) == size) { y=y0; x++; break; } } } }
//Show image //x:0~63 //y:0~31 void OLED_ShowImg(uint8_t x, uint8_t y, uint8_t chr, uint8_t mode) { uint8_t temp,t,t1; uint8_t y0=y; for(t=0;t<32;t++) { temp = image[chr][t]; for(t1=0; t1<8; t1++) { if(temp&0x80)OLED_DrawPoint(x,y,mode); else OLED_DrawPoint(x,y,!mode); temp<<=1; y++; if((y-y0) == 32) { y=y0; x++; break; } } } }
/** * @brief Show a char withgiven size @param x,y:Position chr:Char size:Char size in y 16,12,8 are selectable mode:Draw(1) or unDraw(0) @retval None */ void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char chr, unsigned char size, unsigned char mode) { unsigned char temp, t, t1, m; unsigned char y0 = y; if (chr == '\n' || chr == '\r') return; chr = chr - ' '; if (size == 8) { m = 5; for (t = 0; t < 5; t++) { temp = oled_asc2_0705[chr][t]; for (t1 = 0; t1 < 8; t1++) { if (temp & 0x01)OLED_DrawPoint(x, y, mode); else OLED_DrawPoint(x, y, !mode); temp >>= 1; y++; if ((y - y0) == size) { y = y0; x++; break; } } } }
void oled_cmps_mode() { uint8_t x, y; y = 15; for(x=23; x<40; ++x) OLED_DrawPoint(x, y, 1); x = 31; for(y=8; y<24; ++y) OLED_DrawPoint(x, y, 1); OLED_Refresh_Gram(); }
//add by ll void update_battery(uint8_t level) { uint8_t i, j; uint16_t length = 0; i = j = 0; for(i=48; i<=60; ++i) OLED_DrawPoint(i, j, 1); i -= 1; for(j=0; j<=3; ++j) OLED_DrawPoint(i, j, 1); j -= 1; for(; i<=63; ++i) OLED_DrawPoint(i, j, 1); i -= 1; for(; j<=6; ++j) OLED_DrawPoint(i, j, 1); j -= 1; for(; i>=60; --i) OLED_DrawPoint(i, j, 1); i += 1; for(; j<=9; ++j) OLED_DrawPoint(i, j, 1); j -= 1; for(; i>=48; --i) OLED_DrawPoint(i, j, 1); i += 1; for(; j>=1; --j) OLED_DrawPoint(i, j, 1); //get the level of battery //length = 49 + (get_battery_value() - 20) / 7; // xprintf("length = %d\r\n",length); for(i=49; i<=length; i++) for(j=0; j<=9; j++) OLED_DrawPoint(i, j, 1); }
/** * @brief Draw a horizonal line @param y(from 0 to 127): Public Y position x1(from 0 to 63): Start of line x2(from 0 to 63): End of line t:Draw(1) or unDraw(0) x1,x2 satisfies x1<x2 @retval None */ void OLED_DrawHorizonalLine(unsigned char y, unsigned char x1, unsigned char x2, unsigned char t) { for (; x1 < x2 + 1; x1++) { OLED_DrawPoint(x1, y, t); } }
/** * @brief Draw a vertical line @param x(from 0 to 127): Public X position y1(from 0 to 63): Start of line y2(from 0 to 63): End of line t:Draw(1) or unDraw(0) y1,y2 satisfies y1<y2 @retval None */ void OLED_DrawVerticalLine(unsigned char x, unsigned char y1, unsigned char y2, unsigned char t) { for (; y1 < y2 + 1; y1++) { OLED_DrawPoint(x, y1, t); } }
//x1,y1,x2,y2 填充区域的对角坐标 //确保x1<=x2;y1<=y2 0<=x1<=127 0<=y1<=63 //dot:0,清空;1,填充 void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot) { u8 x,y; for(x=x1;x<=x2;x++) { for(y=y1;y<=y2;y++)OLED_DrawPoint(x,y,dot); } OLED_Refresh_Gram();//更新显示 }
//x1,y1,x2,y2 //x1<=x2;y1<=y2 0<=x1<=63 0<=y1<=31 //dot:0,clear;1,fill void OLED_Fill(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint8_t dot) { uint8_t x,y; for(x=x1;x<=x2;x++) { for(y=y1;y<=y2;y++)OLED_DrawPoint(x,y,dot); } OLED_Refresh_Gram(); }
void OLED_line (int x1, int y1, int x2, int y2, unsigned char mode) //Draws a line between two points on the display - по Ѕрезенхейму { signed int dy = 0; signed int dx = 0; signed int stepx = 0; signed int stepy = 0; signed int fraction = 0; // if (x1>lcdWidth() || x2>lcdWidth() || y1>lcdHeight() || y2>lcdHeight()) return; dy = y2 - y1; dx = x2 - x1; if (dy < 0) { dy = -dy; stepy = -1; } else stepy = 1; if (dx < 0) { dx = -dx; stepx = -1; } else stepx = 1; dy <<= 1; dx <<= 1; OLED_DrawPoint(x1,y1,mode); if (dx > dy) { fraction = dy - (dx >> 1); while (x1 != x2) { if (fraction >= 0) { y1 += stepy; fraction -= dx; } x1 += stepx; fraction += dy; OLED_DrawPoint(x1,y1,mode); } }
void OLED_Equalizer_128(u8 *data) { int x,y; for (x=0;x<128;x++) { //printf("0x%x\n\r", data[x]); for (y=0;y<=data[x];y++) OLED_DrawPoint(128-x,y,1); } OLED_Refresh_Gram(); }
/****************************************************** Function: void OLED_GT20Photo( u8 x, u8 y, u8 len, u8 wide, u8 *pic, u8 mode) Description:从任意点开始画指点大小的图片 Calls: void OLED_DrawPoint(u8 x,u8 y,u8 t) //任意坐标画点 Input: u8 x,u8 y:起始点。 u8 len:长,x轴方向 u8 wide:宽,y轴方向 u8 *pic:图片数组 u8 mode:字符显示区域为0或1 ******************************************************/ void OLED_GT20Photo( u8 x, u8 y, u8 len, u8 wide, u8 *pic, u8 mode) { u8 x_pos,y_pos,temp; u8 i,j; x_pos = x; y_pos = y; for(j=0; j<len; j++) { for(i=0;i<wide;i++) { if(i%8==0) { temp = *(pic+(i/8)*len+j); } if(temp&0x01) OLED_DrawPoint( x_pos+j,y_pos+i,mode); else OLED_DrawPoint( x_pos+j,y_pos+i,!mode); //某“点”写0,或写1 temp >>=1; } } }
void oled_drawline(int16_t angle) { int16_t x1, y1; static int16_t x2=0, y2=0; float rad = angle * 3.14 / 180; x1 = 31; y1 = 15; OLED_DrawPoint(x2, y2, 0); // DDALine(x1, y1, x2, y2, 0); // dda_line(x1, y1, x2, y2, 0); x2 = (int16_t)(cos(rad) * 15) + x1; y2 = y1 - (int16_t)(sin(rad) * 15); // xprintf("%d, %d, %d\r\n", angle, x2, y2); OLED_DrawPoint(x2, y2, 1); // DDALine(x1, y1, x2, y2, 1); // dda_line(x1, y1, x2, y2, 1); }
///////////////////////////////////////////////////////////////////////////////// //在指定位置显示一个字符,包括部分字符 //x:0~127 //y:0~63 //mode:0,反白显示;1,正常显示 //size:选择字体 16/12 void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t size,uint8_t mode) { uint8_t temp,t,t1; uint8_t y0=y; chr=chr-' ';//得到偏移后的值 // offset position in table for(t=0;t<size;t++) { if(size==12) { temp=oled_asc2_1206[chr][t]; //调用1206字体 } else { temp=oled_asc2_1608[chr][t]; //调用1608字体 } for(t1=0;t1<8;t1++) { if(temp&0x80) { OLED_DrawPoint(x,y,mode); } else { OLED_DrawPoint(x,y,!mode); } temp<<=1; y++; if((y-y0)==size) { y=y0; x++; break; } } } }
//在指定位置显示一个字符,包括部分字符 //x:0~127 //y:0~63 //mode:0,反白显示;1,正常显示 //size:选择字体 16/12 void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 size,u8 mode) { u8 temp,t,t1; u8 y0=y; chr=chr-' ';//得到偏移后的值 for(t=0;t<size;t++) { if(size==12)temp=asc2_1206[chr][t]; //调用1206字体 else temp=asc2_1608[chr][t]; //调用1608字体 for(t1=0;t1<8;t1++) { if(temp&0x80)OLED_DrawPoint(x,y,mode); else OLED_DrawPoint(x,y,!mode); temp<<=1; y++; if((y-y0)==size) { y=y0; x++; break; } } } }
void DDALine(int x0,int y0,int x1,int y1,int color) { int x; float dx, dy, y, k; dx = x1 - x0; dy = y1 - y0; k = dy / dx; y = y0; for (x=x0; x<x1; x++) { OLED_DrawPoint(x, (int)(y+0.5), color); y = y + k; } }
void dda_line(int x0,int y0,int x1,int y1,int color) { float e, dx, dy; dx = x1 - x0; dy = y1 - y0; e = dy - dx/2; while(x0 <= x1) { OLED_DrawPoint(x0, y0, color); if(e > 0) { y0 += 1; e -= dx; } x0 += 1; e += dy; } }
void OLED_drawbitmap(unsigned char x, unsigned char y, const unsigned char bitmap[], unsigned char w,unsigned char h, unsigned char mode) { unsigned char i,j; for ( j = 0; j < h; j++) { for (i = 0; i < w; i++) { //if (*(bitmap + i + (j / 8) * w) & TO_BIT(j%8)) { if ((bitmap[i + (j / 8) * w]) & (0x1 << (j%8))) { OLED_DrawPoint(x + i, y + j, mode); } } } }
int main(void) { short real[N], image[N]; float datacpx[N]; int outLED[N]; int i,j,window; int timeL; print("FFT start\n"); Xil_Out32(OLED_BASE_ADDR,0xff); OLED_Init(); OLED_ShowString(0,0, "Hello FFT!"); OLED_Refresh_Gram(); //srand(time(0)); while(1){ init_timer(timer_ctrl, timer_counter_l, timer_counter_h); start_timer(timer_ctrl); OLED_Clear(); for (i = 0; i < N; i++) outLED[i] = 0; for(window = 0; window<WINDOW; ++window) { //Generate input data for (i = 0; i < N; i++) { #ifdef FIX_POINT real[i] = ((rand()%128-64)/128.0f)*(1<<14); image[i] = 0; #else //datacpx[2*i]=(cos(2 * M_PI * 4 * i / N)); datacpx[2*i]=(rand()%128-64)/128.0f; datacpx[2*i+1] = 0; #endif } timeL = *timer_counter_l; //FFT #ifdef FIX_POINT fix_fft(real, image, POW_N); #else fft(datacpx,N,1); #endif printf("FFT: %d us\n",(*timer_counter_l - timeL)/333); timeL = *timer_counter_l; //Conj for (i = 0; i < N; i++) { #ifdef FIX_POINT //printf("real[%d]= %d image[%d]= %d\n",i,real[i],i,image[i]); int conj_pdt_out =sqrt((real[i]*real[i]) + (image[i]*image[i])); #else int conj_pdt_out =sqrt((datacpx[2*i]*datacpx[2*i]) + (datacpx[2*i+1]*datacpx[2*i+1])); #endif //conj_pdt_out=conj_pdt_out/2; outLED[i]+=conj_pdt_out; } printf("Conj: %d us\n",(*timer_counter_l - timeL)/333); } timeL = *timer_counter_l; //Averaging for(i=0;i<N;++i) { #ifdef FIX_POINT outLED[i]=outLED[i]>>10; #else outLED[i]=outLED[i]/8; #endif } printf("Averaging: %d us\n",(*timer_counter_l - timeL)/333); stop_timer(timer_ctrl); //Display for(i=0;i<N;++i) { //printf("real[%d]= %d image[%d]= %d\n",i,real[i],i,image[i]); for(j=0; j< outLED[i]; ++j) OLED_DrawPoint(i,63-j,1); } OLED_Refresh_Gram(); } return 0; }