| @ -0,0 +1,231 @@ | |||
| /* | |||
| Digital VFO with Rotation Dial | |||
| File: VFOsys2.ino | |||
| Author: JF3HZB / T.UEBO | |||
| Created on July 1, 2023 | |||
| Board manager: esp32 ver. 2.0.9 | |||
| Board: ESP32 Dev Module | |||
| Library: LovyanGFX ver. 1.1.7 | |||
| */ | |||
| #define NAME "VFO System" | |||
| #define VERSION "Ver. 2.00" | |||
| #define ID "by JF3HZB" | |||
| #include "dial.hpp" | |||
| #include "si5351.h" | |||
| #include "driver/pcnt.h" | |||
| LGFX lcd; | |||
| LGFX_Sprite sp; | |||
| LGFX_Sprite sprites[2]; | |||
| bool flip; | |||
| int sprite_height; | |||
| DIAL dial; | |||
| //#define REV_ENCODER | |||
| #define PULSE_INPUT_PIN 16 // Rotaty Encoder A | |||
| #define PULSE_CTRL_PIN 17 // Rotaty Encoder B | |||
| /*------------------------------------------------------- | |||
| Frequency settings | |||
| --------------------------------------------------------*/ | |||
| #define init_frq 7100000 // Initial Frequncy[Hz] | |||
| int32_t offset_frq = 8998500; // Offset Frequency[Hz] | |||
| int32_t car_frq = 8998500; // Carrier Frequncy[Hz] | |||
| #define max_frq 200000000 // Max frequency[Hz] | |||
| #define min_frq 10000 // Min frequency[Hz] | |||
| /*---------------------------------------------------------- | |||
| Adaptive step control parameters | |||
| -----------------------------------------------------------*/ | |||
| #define vth 4 // Velocity threshold for acceleration | |||
| #define Racc 200 // Rate of acceleration | |||
| #define Rdec 100 // Rate of deceleration | |||
| #define freq_step 10 // Min step[Hz] | |||
| #define MAX_Step 5000 // [Hz] | |||
| float L=0.0; | |||
| float inv_Tacc=Racc*1.0e-6; | |||
| float MaxL = sqrt( (MAX_Step - freq_step)/inv_Tacc ); | |||
| int32_t afstp; | |||
| int16_t RE_Count = 0; | |||
| /*---------------------------------------------------------------------------------- | |||
| Control flags | |||
| -----------------------------------------------------------------------------------*/ | |||
| uint8_t f_fchange = 1; // if frequency changed, set this flag to 1 | |||
| uint8_t f_cchange = 1; // if Car frequency and/or "f_carON" changed, set this flag to 1 | |||
| uint8_t f_carON = 1; // ON(1)/OFF(0) Car signal | |||
| int32_t Dial_frq; | |||
| void setup(void) | |||
| { | |||
| //--- Counter setup for Rotary Encoder --------------------- | |||
| pcnt_config_t pcnt_config_A;// structure for A | |||
| pcnt_config_t pcnt_config_B;// structure for B | |||
| // | |||
| pcnt_config_A.pulse_gpio_num = PULSE_INPUT_PIN; | |||
| pcnt_config_A.ctrl_gpio_num = PULSE_CTRL_PIN; | |||
| pcnt_config_A.lctrl_mode = PCNT_MODE_REVERSE; | |||
| pcnt_config_A.hctrl_mode = PCNT_MODE_KEEP; | |||
| pcnt_config_A.channel = PCNT_CHANNEL_0; | |||
| pcnt_config_A.unit = PCNT_UNIT_0; | |||
| pcnt_config_A.pos_mode = PCNT_COUNT_INC; | |||
| pcnt_config_A.neg_mode = PCNT_COUNT_DEC; | |||
| pcnt_config_A.counter_h_lim = 10000; | |||
| pcnt_config_A.counter_l_lim = -10000; | |||
| // | |||
| pcnt_config_B.pulse_gpio_num = PULSE_CTRL_PIN; | |||
| pcnt_config_B.ctrl_gpio_num = PULSE_INPUT_PIN; | |||
| pcnt_config_B.lctrl_mode = PCNT_MODE_KEEP; | |||
| pcnt_config_B.hctrl_mode = PCNT_MODE_REVERSE; | |||
| pcnt_config_B.channel = PCNT_CHANNEL_1; | |||
| pcnt_config_B.unit = PCNT_UNIT_0; | |||
| pcnt_config_B.pos_mode = PCNT_COUNT_INC; | |||
| pcnt_config_B.neg_mode = PCNT_COUNT_DEC; | |||
| pcnt_config_B.counter_h_lim = 10000; | |||
| pcnt_config_B.counter_l_lim = -10000; | |||
| // | |||
| pcnt_unit_config(&pcnt_config_A);//Initialize A | |||
| pcnt_unit_config(&pcnt_config_B);//Initialize B | |||
| pcnt_counter_pause(PCNT_UNIT_0); | |||
| pcnt_counter_clear(PCNT_UNIT_0); | |||
| pcnt_counter_resume(PCNT_UNIT_0); //Start | |||
| LCD_setup(); | |||
| lcd.setTextColor(TFT_CYAN); | |||
| lcd.setFont(&fonts::Font0); | |||
| lcd.setTextSize(1.0f*( lcd.height()/64.0f)); | |||
| lcd.setCursor( 0.5f*(lcd.width()-lcd.textWidth(NAME) ), 0.1f*lcd.height() ); | |||
| lcd.printf( NAME ); | |||
| lcd.setTextSize(1.0f*( lcd.height()/64.0f)); | |||
| lcd.setCursor( 0.5f*(lcd.width()-lcd.textWidth(VERSION) ), 0.4f*lcd.height()); | |||
| lcd.printf(VERSION); | |||
| lcd.setTextSize(1.0f*(lcd.height()/64.0f)); | |||
| lcd.setCursor( 0.5f*(lcd.width()-lcd.textWidth(ID) ), 0.7f*lcd.height()); | |||
| lcd.printf(ID); | |||
| delay(1000); | |||
| si5351_init(); | |||
| Dial_frq = init_frq; | |||
| set_freq(Dial_frq); | |||
| } | |||
| void loop(void) | |||
| { | |||
| // Encoder | |||
| pcnt_get_counter_value(PCNT_UNIT_0, &RE_Count); | |||
| #ifdef REV_ENCODER | |||
| int count=-RE_Count; | |||
| #else if | |||
| int count=RE_Count; | |||
| #endif | |||
| pcnt_counter_clear(PCNT_UNIT_0); | |||
| // Step control | |||
| if(count!=0){ | |||
| afstp=(int32_t)(0.5 + (float)(count)*( (float)freq_step + L*L*inv_Tacc) ); | |||
| if(abs(count)>= vth ) L+=1.0*(float)( abs(count) - vth ); | |||
| if(L>MaxL) L=MaxL; | |||
| }else{ | |||
| L-=(float)Rdec; | |||
| if(L<0) L=0; | |||
| } | |||
| // Update frequency | |||
| if(afstp!=0){ | |||
| int32_t tfrq=Dial_frq; | |||
| tfrq+=afstp; | |||
| tfrq = (tfrq/freq_step)*freq_step; | |||
| if(tfrq>max_frq) tfrq=max_frq; | |||
| if(tfrq<min_frq) tfrq=min_frq; | |||
| Dial_frq=tfrq; | |||
| afstp=0; | |||
| f_fchange = 1; | |||
| } | |||
| // Set frequency to Si5351A | |||
| if(f_fchange==1){ | |||
| f_fchange=0; | |||
| // Lo freq | |||
| set_freq( Dial_frq + offset_frq ); | |||
| } | |||
| if(f_cchange==1){ | |||
| f_cchange=0; | |||
| // Car freq | |||
| set_car_freq(car_frq, f_carON, 0); | |||
| } | |||
| // Display process ------------------------------------------------------------------- | |||
| for (int yoff = 0; yoff < lcd.height(); yoff += sprite_height) | |||
| { | |||
| sprites[flip].clear(BGCol); | |||
| // Draw dial | |||
| dial.draw(Dial_frq, yoff); | |||
| // Draw digital frequency display | |||
| char str[12], strl[24]; | |||
| sprintf(str, "%03d.%03d.%02d", | |||
| Dial_frq/1000000, (Dial_frq%1000000)/1000, (Dial_frq%1000)/10 ); | |||
| int cc=0; | |||
| if(str[0]=='0'){ | |||
| cc++; | |||
| if(str[1]=='0') cc++; | |||
| } | |||
| for(int i=0; i<12; i++){ | |||
| strl[2*i]=str[i+cc]; | |||
| strl[2*i+1]=' '; | |||
| } | |||
| #ifdef MODE0 | |||
| int xdf=0, ydf=0;// position | |||
| int hdf = top_position-2; | |||
| if(hdf>=20) | |||
| { | |||
| sprites[flip].drawRoundRect(xdf, ydf -yoff, lcd.width(), hdf, 5, TFT_WHITE); | |||
| sprites[flip].setFont(&fonts::Font7); | |||
| sprites[flip].setTextSize(0.0022f*lcd.width(), 0.014f*hdf); | |||
| sprites[flip].setTextColor(TFT_ORANGE); | |||
| sprites[flip].setCursor(xdf + 0.05f*lcd.width() + cc*sprites[flip].textWidth("0 "), | |||
| ydf + 0.5f*(hdf - sprites[flip].fontHeight() ) -yoff ); | |||
| sprites[flip].print(strl); | |||
| } | |||
| #endif | |||
| // Add draw functions if you need. | |||
| // Note that the y-coordinate is applied with the offset -yoff added. | |||
| // | |||
| // ex. | |||
| // sprites[flip].setFont(&fonts::Font4); | |||
| // sprites[flip].setTextSize(1.0f); | |||
| // sprites[flip].setTextColor(TFT_WHITE); | |||
| // sprites[flip].setCursor(0, 55 -yoff); // "-yoff" is Required | |||
| // sprites[flip].print("LSB"); | |||
| // | |||
| // | |||
| sprites[flip].pushSprite(&lcd, 0, yoff); | |||
| flip = !flip; | |||
| } | |||
| // End of Display process ------------------------------------------------------------- | |||
| } | |||
| @ -0,0 +1,332 @@ | |||
| /* | |||
| Digital VFO with Rotation Dial | |||
| File: dial.cpp | |||
| Author: JF3HZB / T.UEBO | |||
| Created on July 1, 2023 | |||
| */ | |||
| #include "dial.hpp" | |||
| void LCD_setup(void) | |||
| { | |||
| lcd.init(); | |||
| lcd.setColorDepth(16); | |||
| //if (lcd.width() < lcd.height()) { lcd.setRotation(lcd.getRotation()^1); } | |||
| //lcd.setRotation(1); | |||
| for (int i = 0; i < 2; i++) | |||
| { | |||
| sprites[i].setColorDepth(lcd.getColorDepth()); | |||
| sprites[i].setFont(&fonts::Font2); | |||
| sprites[i].setTextDatum(textdatum_t::top_right); | |||
| } | |||
| int div = 1; | |||
| for (;;) | |||
| { | |||
| sprite_height = (lcd.height() + div - 1) / div; | |||
| bool fail = false; | |||
| for (int i = 0; !fail && i < 2; ++i) | |||
| { | |||
| fail = !sprites[i].createSprite(lcd.width(), sprite_height); | |||
| } | |||
| if (!fail) break; | |||
| for (int i = 0; i < 2; ++i) | |||
| { | |||
| sprites[i].deleteSprite(); | |||
| } | |||
| div++; | |||
| } | |||
| sp.setColorDepth(16); | |||
| //sp.setFont(&fonts::Font6); | |||
| sp.setFont(&fonts::FreeSansBold18pt7b); | |||
| sp.setTextDatum(textdatum_t::middle_center); | |||
| lcd.startWrite(); | |||
| } | |||
| void DIAL::draw(int32_t freq, int yoff) | |||
| { | |||
| int num; | |||
| float numf; | |||
| float zoom_x, zoom_y; | |||
| float angle; | |||
| freq=abs(freq); | |||
| #ifdef MODE0 | |||
| int xc = lcd.width() / 2 + hoff; | |||
| int yc = voff + top_margin + (std::fmax(radiusMain, radiusSub)); | |||
| float aoff = 0; | |||
| #endif | |||
| #ifdef MODE1 | |||
| int xc = voff + top_margin + (std::fmax(radiusMain, radiusSub)); | |||
| int yc = lcd.height() / 2 + hoff; | |||
| float aoff = -90.0f; | |||
| #endif | |||
| #ifdef MODE2 | |||
| int xc = lcd.width() - (voff + top_margin + (std::fmax(radiusMain, radiusSub)) ); | |||
| int yc = lcd.height() / 2 + hoff; | |||
| float aoff = 90.0f; | |||
| #endif | |||
| #ifdef MAIN_UNIT_kHz | |||
| TickResoMain = 10000; | |||
| TickResoSub = 1000; | |||
| #endif | |||
| if(TickResoSub == 10000) TickResoMain = 100000; | |||
| // draw dial Background --------------------------------------------------------- | |||
| #ifdef MODE0 | |||
| sprites[flip].fillRect(0, voff-yoff, lcd.width(), lcd.height()-voff, DialBGCol); | |||
| #endif | |||
| #ifdef MODE1 | |||
| sprites[flip].fillRect(voff, 0-yoff, lcd.width()-voff, lcd.height(), DialBGCol); | |||
| #endif | |||
| #ifdef MODE2 | |||
| sprites[flip].fillRect(0, 0-yoff, lcd.width()-voff, lcd.height(), DialBGCol); | |||
| #endif | |||
| // draw Sub dial ---------------------------------------------------------------- | |||
| #ifdef REV_DIAL | |||
| angle = -resoSub * (float)( freq % (TickResoSub*10) ) / (float)TickResoSub ; | |||
| #else if | |||
| angle = resoSub * (float)( freq % (TickResoSub*10) ) / (float)TickResoSub ; | |||
| #endif | |||
| sp.createSprite(1, 1); | |||
| sp.clear(TickSubCol); | |||
| float pvoff; | |||
| if (tnSub<=0) pvoff = -0.5f; else pvoff = 0.5f; | |||
| for (int i = -100; i < 100; i++) | |||
| { | |||
| float a = angle - (float)i * resoSub; | |||
| if (a > 100 || a < -100) continue; | |||
| zoom_x = (i%5 ? tickWSub : ((i % 10) ? tick5WSub : tick10WSub)); | |||
| zoom_y = (i%5 ? tickLSub : ((i % 10) ? tick5LSub : tick10LSub)); | |||
| sp.setPivot(0, radiusSub / zoom_y + pvoff); | |||
| sp.pushRotateZoomWithAA(&sprites[flip], xc, yc - yoff, a+aoff, zoom_x, zoom_y, 0); | |||
| } | |||
| // draw Sub number ---------------------------------------------------------------- | |||
| zoom_x = font_sizex_sub; | |||
| zoom_y = font_sizey_sub; | |||
| sp.createSprite(60, 28); | |||
| #ifdef MODE0 | |||
| if(tnSub<=0){ | |||
| sp.setTextDatum(textdatum_t::top_center); | |||
| sp.setPivot((float)sp.width() / 2, (radiusSub + tnSub) / zoom_y); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::baseline_center); | |||
| sp.setPivot((float)sp.width() / 2, (radiusSub + tnSub) / zoom_y + (float)sp.height() ); | |||
| } | |||
| #endif | |||
| #ifdef MODE1 | |||
| if(tnSub<=0){ | |||
| sp.setTextDatum(textdatum_t::middle_left); | |||
| sp.setPivot( (radiusSub + tnSub) / zoom_x, (float)sp.height() / 2); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::middle_right); | |||
| sp.setPivot( (radiusSub + tnSub) / zoom_x + (float)sp.width(), (float)sp.height() / 2); | |||
| } | |||
| #endif | |||
| #ifdef MODE2 | |||
| if(tnSub<=0){ | |||
| sp.setTextDatum(textdatum_t::middle_right); | |||
| sp.setPivot( -(radiusSub + tnSub) / zoom_x + (float)sp.width(), (float)sp.height() / 2); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::middle_left); | |||
| sp.setPivot( -(radiusSub + tnSub) / zoom_x , (float)sp.height() / 2); | |||
| } | |||
| #endif | |||
| sp.setTextColor(NumSubCol, TFT_BLACK); | |||
| for (int i = -80; i < 80; i += 10) | |||
| { | |||
| #ifdef REV_DIAL | |||
| float a = angle + (float)i * resoSub; | |||
| #else if | |||
| float a = angle - (float)i * resoSub; | |||
| #endif | |||
| if (a > 100 || a < -100) continue; | |||
| sp.clear(TFT_BLACK); | |||
| num = (freq/(TickResoSub*10)*10 + i + 1000)*(TickResoSub/1000) % (TickResoMain/100); | |||
| #ifdef MODE0 | |||
| if(tnSub<=0) sp.drawNumber( num , sp.width()>>1, 0 ); | |||
| else sp.drawNumber( num , sp.width()>>1, sp.height()-1 ); | |||
| #endif | |||
| #ifdef MODE1 | |||
| if(tnSub<=0) sp.drawNumber( num , 0, sp.height()>>1 ); | |||
| else sp.drawNumber( num , sp.width(), sp.height()>>1 ); | |||
| #endif | |||
| #ifdef MODE2 | |||
| if(tnSub<=0) sp.drawNumber( num , sp.width(), sp.height()>>1 ); | |||
| else sp.drawNumber( num , 0, sp.height()>>1 ); | |||
| #endif | |||
| sp.pushRotateZoomWithAA(&sprites[flip], xc, yc - yoff, a, zoom_x, zoom_y, 0); | |||
| } | |||
| // draw Main dial ----------------------------------------------------------------------- | |||
| #ifdef REV_DIAL | |||
| angle = -resoMain * (float)( freq % (TickResoMain*10) ) / (float)TickResoMain; | |||
| #else if | |||
| angle = resoMain * (float)( freq % (TickResoMain*10) ) / (float)TickResoMain; | |||
| #endif | |||
| sp.createSprite(1, 1); | |||
| sp.clear(TickMainCol); | |||
| if (tnMain<=0) pvoff = -0.5f; else pvoff = 0.5f; | |||
| for (int i = -100; i < 100; i++) | |||
| { | |||
| float a = angle - (float)i * resoMain; | |||
| if (a > 100 || a < -100) continue; | |||
| zoom_x = (i%5 ? tickWMain : ((i % 10) ? tick5WMain : tick10WMain)); | |||
| zoom_y = (i%5 ? tickLMain : ((i % 10) ? tick5LMain : tick10LMain)); | |||
| sp.setPivot(0, radiusMain / zoom_y + pvoff); | |||
| sp.pushRotateZoomWithAA(&sprites[flip], xc, yc - yoff, a+aoff, zoom_x, zoom_y, 0); | |||
| } | |||
| // draw Main number ---------------------------------------------------------------------- | |||
| zoom_x = font_sizex_main; | |||
| zoom_y = font_sizey_main; | |||
| sp.createSprite(85, 28); | |||
| #ifdef MODE0 | |||
| if(tnMain<=0){ | |||
| sp.setTextDatum(textdatum_t::top_center); | |||
| sp.setPivot((float)sp.width() / 2, (radiusMain + tnMain)/zoom_y ); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::baseline_center); | |||
| sp.setPivot((float)sp.width() / 2, (radiusMain + tnMain)/zoom_y + (float)sp.height() ); | |||
| } | |||
| #endif | |||
| #ifdef MODE1 | |||
| if(tnMain<=0){ | |||
| sp.setTextDatum(textdatum_t::middle_left); | |||
| sp.setPivot( (radiusMain + tnMain) / zoom_x , (float)sp.height() / 2); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::middle_right); | |||
| sp.setPivot( (radiusMain + tnMain) / zoom_x + (float)sp.width(), (float)sp.height() / 2); | |||
| } | |||
| #endif | |||
| #ifdef MODE2 | |||
| if(tnMain<=0){ | |||
| sp.setTextDatum(textdatum_t::middle_right); | |||
| sp.setPivot( -(radiusMain + tnMain) / zoom_x + (float)sp.width(), (float)sp.height() / 2); | |||
| }else{ | |||
| sp.setTextDatum(textdatum_t::middle_left); | |||
| sp.setPivot( -(radiusMain + tnMain) / zoom_x , (float)sp.height() / 2); | |||
| } | |||
| #endif | |||
| sp.setTextColor(NumMainCol, TFT_BLACK); | |||
| for (int i = -80; i < 80; i += 10) | |||
| { | |||
| #ifdef REV_DIAL | |||
| float a = angle + (float)i * resoMain; | |||
| #else if | |||
| float a = angle - (float)i * resoMain; | |||
| #endif | |||
| if (a > 100 || a < -100) continue; | |||
| sp.clear(TFT_BLACK); | |||
| #ifdef MAIN_UNIT_kHz | |||
| num = abs(freq)/(100000)*100 + i*10; | |||
| #else if | |||
| numf = ( abs(freq)/(TickResoMain*10) + i*0.1f ) * 1e-5 * TickResoMain; | |||
| #endif | |||
| #ifdef MODE0 | |||
| if(tnMain<=0){ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, sp.width()>>1, 0); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, sp.width()>>1, 0); | |||
| #endif | |||
| }else{ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, sp.width()>>1, sp.height()-1); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, sp.width()>>1, sp.height()-1); | |||
| #endif | |||
| } | |||
| #endif | |||
| #ifdef MODE1 | |||
| if(tnMain<=0){ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, 0, sp.height()>>1); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, 0, sp.height()>>1 ); | |||
| #endif | |||
| }else{ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, sp.width(), sp.height()>>1 ); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, sp.width(), sp.height()>>1 ); | |||
| #endif | |||
| } | |||
| #endif | |||
| #ifdef MODE2 | |||
| if(tnMain<=0){ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, sp.width(), sp.height()>>1 ); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, sp.width(), sp.height()>>1 ); | |||
| #endif | |||
| }else{ | |||
| #ifdef MAIN_UNIT_kHz | |||
| if(num>=0) sp.drawNumber( num, 0, sp.height()>>1 ); | |||
| #else if | |||
| if(numf>=0) sp.drawFloat( fabs(numf), 1, 0, sp.height()>>1 ); | |||
| #endif | |||
| } | |||
| #endif | |||
| sp.pushRotateZoomWithAA(&sprites[flip], xc, yc - yoff, a, zoom_x, zoom_y, 0); | |||
| } | |||
| sp.setTextDatum(textdatum_t::middle_center); | |||
| // draw Pointer -------------------------------------------------------------------------------------------------- | |||
| sp.createSprite(1, 1); | |||
| sp.clear(PointerCol); | |||
| sp.setPivot(0, -0.5f); | |||
| #ifdef MODE0 | |||
| sp.pushRotateZoomWithAA(&sprites[flip], xc, voff-yoff, 0, WidthPointer, LenPointer, 0); | |||
| #endif | |||
| #ifdef MODE1 | |||
| sp.pushRotateZoomWithAA(&sprites[flip], voff, yc-yoff, -90, WidthPointer, LenPointer, 0); | |||
| #endif | |||
| #ifdef MODE2 | |||
| sp.pushRotateZoomWithAA(&sprites[flip], lcd.width()-voff, yc-yoff, 90, WidthPointer, LenPointer, 0); | |||
| #endif | |||
| } | |||
| @ -0,0 +1,85 @@ | |||
| /* | |||
| Digital VFO with Rotation Dial | |||
| File: dial.hpp | |||
| Author: JF3HZB / T.UEBO | |||
| Created on July 1, 2023 | |||
| */ | |||
| #ifndef DIAL_H | |||
| #define DIAL_H | |||
| //#include "prm\ST7789_240x320.hpp" | |||
| //#include "prm\ST7789_240x240.hpp" | |||
| //#include "prm\ST7789_135x240.hpp" | |||
| //#include "prm\ST7735S_128x160.hpp" | |||
| //#include "prm\ST7735S_80x160.hpp" | |||
| #include "prm\ILI9341_240x320.hpp" | |||
| //#include "prm\SSD1331_64x96.hpp" | |||
| extern LGFX lcd; | |||
| extern LGFX_Sprite sp; | |||
| extern LGFX_Sprite sprites[2]; | |||
| extern bool flip; | |||
| extern int sprite_height; | |||
| void LCD_setup(void); | |||
| class DIAL | |||
| { | |||
| private: | |||
| float resoSub; //[deg] | |||
| float resoMain; //[deg] | |||
| int32_t TickResoMain = freq_tick_main; | |||
| int32_t TickResoSub = freq_tick_sub; | |||
| int hoff = center_offset; | |||
| int voff = top_position; | |||
| float radiusMain; | |||
| float radiusSub; | |||
| public: | |||
| float tnMain = -TNCL_main; | |||
| float tnSub = -TNCL_sub; | |||
| float tickPitchMain = tick_pitch_main; | |||
| float tickPitchSub = tick_pitch_sub; | |||
| float tickWSub = tw_sub1; | |||
| float tick5WSub = tw_sub5; | |||
| float tick10WSub = tw_sub10; | |||
| float tickLSub = tl_sub1; | |||
| float tick5LSub = tl_sub5; | |||
| float tick10LSub = tl_sub10; | |||
| float tickWMain = tw_main1; | |||
| float tick5WMain = tw_main5; | |||
| float tick10WMain = tw_main10; | |||
| float tickLMain = tl_main1; | |||
| float tick5LMain = tl_main5; | |||
| float tick10LMain = tl_main10; | |||
| float LenPointer = DP_len; | |||
| float WidthPointer = DP_width; | |||
| DIAL() | |||
| { | |||
| #ifdef MAINDIAL_IS_OUTSIDE | |||
| radiusMain = dial_radius; | |||
| radiusSub = dial_radius - dial_space; | |||
| #else if | |||
| radiusSub = dial_radius; | |||
| radiusMain = dial_radius - dial_space; | |||
| #endif | |||
| resoMain = (180.0f/M_PI)*tickPitchMain/(float)radiusMain; | |||
| resoSub = (180.0f/M_PI)*tickPitchSub/(float)radiusSub; | |||
| } | |||
| void draw(int32_t freq, int yoff); | |||
| }; | |||
| #endif /* DIAL_H */ | |||
| @ -0,0 +1,151 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.70 | |||
| #define font_sizey_main 0.60 | |||
| #define font_sizex_sub 0.75 | |||
| #define font_sizey_sub 0.60 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 60 | |||
| #define top_margin 20 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 280.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 60.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 9.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 10.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 3.0 // Tick width of main(1) | |||
| #define tw_main5 4.0 // Tick width of main(5) | |||
| #define tw_main10 4.5 // Tick width of main(10) | |||
| #define tw_sub1 3.0 // Tick width of sub(1) | |||
| #define tw_sub5 4.0 // Tick width of sub(5) | |||
| #define tw_sub10 4.5 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 5.0 // Tick length of main(1) | |||
| #define tl_main5 14.0 // Tick length of main(5) | |||
| #define tl_main10 18.0 // Tick length of main(10) | |||
| #define tl_sub1 5.0 // Tick length of sub(1) | |||
| #define tl_sub5 14.0 // Tick length of sub(5) | |||
| #define tl_sub10 18.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 22.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 22.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ILI9341 _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 240;//128; // 実際に表示可能な幅 | |||
| cfg.panel_height = 320;//160; // 実際に表示可能な高さ | |||
| cfg.offset_x = 0; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 0; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = false; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| //cfg.memory_width = 128; // ドライバICがサポートしている最大の幅 | |||
| //cfg.memory_height = 160; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* PRM_H */ | |||
| @ -0,0 +1,151 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.4 | |||
| #define font_sizey_main 0.35 | |||
| #define font_sizex_sub 0.4 | |||
| #define font_sizey_sub 0.35 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 0 | |||
| #define top_margin 2 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 150.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 30.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 5.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 5.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 2.0 // Tick width of main(1) | |||
| #define tw_main5 2.5 // Tick width of main(5) | |||
| #define tw_main10 3.0 // Tick width of main(10) | |||
| #define tw_sub1 2.0 // Tick width of sub(1) | |||
| #define tw_sub5 2.5 // Tick width of sub(5) | |||
| #define tw_sub10 3.0 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 2.5 // Tick length of main(1) | |||
| #define tl_main5 8.0 // Tick length of main(5) | |||
| #define tl_main10 10.0 // Tick length of main(10) | |||
| #define tl_sub1 2.5 // Tick length of sub(1) | |||
| #define tl_sub5 8.0 // Tick length of sub(5) | |||
| #define tl_sub10 10.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 13.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 13.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_SSD1331 _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 20000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 96; // 実際に表示可能な幅 | |||
| cfg.panel_height = 64; // 実際に表示可能な高さ | |||
| cfg.offset_x = 0; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 0; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 2; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = false; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = true; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| //cfg.memory_width = 96; // ドライバICがサポートしている最大の幅 | |||
| //cfg.memory_height = 64; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* PRM_H */ | |||
| @ -0,0 +1,152 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.5 | |||
| #define font_sizey_main 0.45 | |||
| #define font_sizex_sub 0.5 | |||
| #define font_sizey_sub 0.45 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 35 | |||
| #define top_margin 10 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 230.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 40.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 6.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 7.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 2.0 // Tick width of main(1) | |||
| #define tw_main5 3.5 // Tick width of main(5) | |||
| #define tw_main10 4.0 // Tick width of main(10) | |||
| #define tw_sub1 2.0 // Tick width of sub(1) | |||
| #define tw_sub5 3.5 // Tick width of sub(5) | |||
| #define tw_sub10 4.0 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 4.0 // Tick length of main(1) | |||
| #define tl_main5 10.0 // Tick length of main(5) | |||
| #define tl_main10 12.0 // Tick length of main(10) | |||
| #define tl_sub1 4.0 // Tick length of sub(1) | |||
| #define tl_sub5 10.0 // Tick length of sub(5) | |||
| #define tl_sub10 12.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 15.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 15.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ST7735S _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 128; // 実際に表示可能な幅 | |||
| cfg.panel_height = 160; // 実際に表示可能な高さ | |||
| cfg.offset_x = 0; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 0; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = false; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = true; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| cfg.memory_width = 128; // ドライバICがサポートしている最大の幅 | |||
| cfg.memory_height = 160; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* LCD_H */ | |||
| @ -0,0 +1,153 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.55 | |||
| #define font_sizey_main 0.5 | |||
| #define font_sizex_sub 0.55 | |||
| #define font_sizey_sub 0.5 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 0 | |||
| #define top_margin 5 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 230.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 35.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 7.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 7.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 2.0 // Tick width of main(1) | |||
| #define tw_main5 3.0 // Tick width of main(5) | |||
| #define tw_main10 4.0 // Tick width of main(10) | |||
| #define tw_sub1 2.0 // Tick width of sub(1) | |||
| #define tw_sub5 3.0 // Tick width of sub(5) | |||
| #define tw_sub10 3.5 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 3.0 // Tick length of main(1) | |||
| #define tl_main5 8.0 // Tick length of main(5) | |||
| #define tl_main10 10.0 // Tick length of main(10) | |||
| #define tl_sub1 3.0 // Tick length of sub(1) | |||
| #define tl_sub5 8.0 // Tick length of sub(5) | |||
| #define tl_sub10 12.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 12.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 15.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ST7735S _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 80; // 実際に表示可能な幅 | |||
| cfg.panel_height = 160; // 実際に表示可能な高さ | |||
| cfg.offset_x = 26; // パネルのX方向オフセット量 | |||
| cfg.offset_y = -1; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| cfg.memory_width = 80; // ドライバICがサポートしている最大の幅 | |||
| cfg.memory_height = 160; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* LCD_H */ | |||
| @ -0,0 +1,152 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.75 | |||
| #define font_sizey_main 0.70 | |||
| #define font_sizex_sub 0.90 | |||
| #define font_sizey_sub 0.70 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 10 | |||
| #define top_margin 10 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 280.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 50.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 10.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 12.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 3.0 // Tick width of main(1) | |||
| #define tw_main5 4.0 // Tick width of main(5) | |||
| #define tw_main10 4.5 // Tick width of main(10) | |||
| #define tw_sub1 3.0 // Tick width of sub(1) | |||
| #define tw_sub5 4.0 // Tick width of sub(5) | |||
| #define tw_sub10 4.5 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 5.0 // Tick length of main(1) | |||
| #define tl_main5 14.0 // Tick length of main(5) | |||
| #define tl_main10 18.0 // Tick length of main(10) | |||
| #define tl_sub1 5.0 // Tick length of sub(1) | |||
| #define tl_sub5 14.0 // Tick length of sub(5) | |||
| #define tl_sub10 18.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 20.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 20.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ST7789 _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 135; // 実際に表示可能な幅 | |||
| cfg.panel_height = 240; // 実際に表示可能な高さ | |||
| cfg.offset_x = 52; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 40; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 1; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| //cfg.memory_width = 240; // ドライバICがサポートしている最大の幅 | |||
| //cfg.memory_height = 320; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* LCD_H */ | |||
| @ -0,0 +1,151 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.75 | |||
| #define font_sizey_main 0.70 | |||
| #define font_sizex_sub 0.90 | |||
| #define font_sizey_sub 0.70 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 60 | |||
| #define top_margin 20 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 280.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 60.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 10.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 12.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 3.0 // Tick width of main(1) | |||
| #define tw_main5 4.0 // Tick width of main(5) | |||
| #define tw_main10 4.5 // Tick width of main(10) | |||
| #define tw_sub1 3.0 // Tick width of sub(1) | |||
| #define tw_sub5 4.0 // Tick width of sub(5) | |||
| #define tw_sub10 4.5 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 5.0 // Tick length of main(1) | |||
| #define tl_main5 14.0 // Tick length of main(5) | |||
| #define tl_main10 18.0 // Tick length of main(10) | |||
| #define tl_sub1 5.0 // Tick length of sub(1) | |||
| #define tl_sub5 14.0 // Tick length of sub(5) | |||
| #define tl_sub10 18.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 22.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 22.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ST7789 _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 240; // 実際に表示可能な幅 | |||
| cfg.panel_height = 240; // 実際に表示可能な高さ | |||
| cfg.offset_x = 0; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 0; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| //cfg.memory_width = 128; // ドライバICがサポートしている最大の幅 | |||
| //cfg.memory_height = 160; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* LCD_H */ | |||
| @ -0,0 +1,150 @@ | |||
| #ifndef PRM_H | |||
| #define PRM_H | |||
| /*---------------------------------------------------------- | |||
| Dial design | |||
| -----------------------------------------------------------*/ | |||
| #define MAINDIAL_IS_OUTSIDE //Comment out this definition and Sub dial is outsaide | |||
| //#define REV_DIAL | |||
| //#define MAIN_UNIT_kHz | |||
| #define MODE0 // MODE0, MODE1, MODE2 | |||
| //ダイアル数字のサイズ -------------------------------------------------------- | |||
| //Font size of numbers | |||
| #define font_sizex_main 0.75 | |||
| #define font_sizey_main 0.70 | |||
| #define font_sizex_sub 0.90 | |||
| #define font_sizey_sub 0.70 | |||
| //メインダイアル1目盛あたりの周波数 ---------------------------------------------------------- | |||
| #define freq_tick_main 10000 // Frequency per tick of Main dial: 10000(10kHz) or 100000(100kHz) | |||
| #define freq_tick_sub 1000 // Frequency per tick of Sub dial: 1000(1kHz) or 10000(10kHz) | |||
| //ダイアル表示位置----------------------------------------------- | |||
| //Position of dial display | |||
| #define center_offset 0 | |||
| #define top_position 60 | |||
| #define top_margin 20 | |||
| //ダイアル半径--------------------------------------------------- | |||
| #define dial_radius 280.0 //Dial radius (if 10000, Linear scale) | |||
| //メイン,サブダイアル間の間隔------------------------------ | |||
| #define dial_space 60.0 // Space bitween Main and Sub dial | |||
| //目盛り間隔--------------------------------------------- | |||
| #define tick_pitch_main 10.0 // Tick pitch of main dial | |||
| #define tick_pitch_sub 12.0 // Tick pitch of sub dial | |||
| //目盛りの太さ---------------------------------------- | |||
| #define tw_main1 3.0 // Tick width of main(1) | |||
| #define tw_main5 4.0 // Tick width of main(5) | |||
| #define tw_main10 4.5 // Tick width of main(10) | |||
| #define tw_sub1 3.0 // Tick width of sub(1) | |||
| #define tw_sub5 4.0 // Tick width of sub(5) | |||
| #define tw_sub10 4.5 // Tick width of sub(10) | |||
| //目盛りの長さ---------------------------------------- | |||
| #define tl_main1 5.0 // Tick length of main(1) | |||
| #define tl_main5 14.0 // Tick length of main(5) | |||
| #define tl_main10 18.0 // Tick length of main(10) | |||
| #define tl_sub1 5.0 // Tick length of sub(1) | |||
| #define tl_sub5 14.0 // Tick length of sub(5) | |||
| #define tl_sub10 18.0 // Tick length of sub(10) | |||
| //目盛り・数字間のスペース------------------------------------------- | |||
| #define TNCL_main 22.0 // Space bitween Number and Tick (Main dial) | |||
| #define TNCL_sub 22.0 // Space bitween Number and Tick (Sub dial) | |||
| // 指針幅,長さ-------------------------- | |||
| #define DP_width 1.0 // Needle width | |||
| #define DP_len 200.0 // Needle length | |||
| #define TickMainCol TFT_CYAN | |||
| #define TickSubCol TFT_GREEN | |||
| #define NumMainCol TFT_WHITE | |||
| #define NumSubCol TFT_GOLD //TFT_ORANGE | |||
| #define PointerCol TFT_RED | |||
| #define BGCol TFT_BLACK //0x80FF80U | |||
| #define DialBGCol BGCol | |||
| #define TFT_BLACK2 0x0020 //opaque black | |||
| #include <LovyanGFX.hpp> | |||
| class LGFX : public lgfx::LGFX_Device | |||
| { | |||
| lgfx::Panel_ST7789 _panel_instance; | |||
| lgfx::Bus_SPI _bus_instance; | |||
| public: | |||
| LGFX(void) | |||
| { | |||
| { // // SPIバスの設定 | |||
| auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。 | |||
| cfg.spi_host = VSPI_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST | |||
| // ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。 | |||
| cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3) | |||
| cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) | |||
| cfg.freq_read = 16000000; // 受信時のSPIクロック | |||
| cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定 | |||
| cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定 | |||
| cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定) | |||
| // ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。 | |||
| cfg.pin_sclk = 18; // SPIのSCLKピン番号を設定 | |||
| cfg.pin_mosi = 23; // SPIのMOSIピン番号を設定 | |||
| cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable) | |||
| cfg.pin_dc = 2; // SPIのD/Cピン番号を設定 (-1 = disable) | |||
| _bus_instance.config(cfg); // 設定値をバスに反映します。 | |||
| _panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。 | |||
| } | |||
| { // 表示パネル制御の設定を行います。 | |||
| auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。 | |||
| cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_rst = 15; // RSTが接続されているピン番号 (-1 = disable) | |||
| cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable) | |||
| // ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。 | |||
| cfg.panel_width = 240; // 実際に表示可能な幅 | |||
| cfg.panel_height = 320; // 実際に表示可能な高さ | |||
| cfg.offset_x = 0; // パネルのX方向オフセット量 | |||
| cfg.offset_y = 0; // パネルのY方向オフセット量 | |||
| cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転) | |||
| cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数 | |||
| cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数 | |||
| cfg.readable = false; // データ読出しが可能な場合 trueに設定 | |||
| cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定 | |||
| cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定 | |||
| cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定, false: 8bit | |||
| cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) | |||
| // 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。 | |||
| //cfg.memory_width = 128; // ドライバICがサポートしている最大の幅 | |||
| //cfg.memory_height = 160; // ドライバICがサポートしている最大の高さ | |||
| _panel_instance.config(cfg); | |||
| } | |||
| setPanel(&_panel_instance); // 使用するパネルをセットします。 | |||
| } | |||
| }; | |||
| #endif /* LCD_H */ | |||
| @ -0,0 +1,445 @@ | |||
| /* | |||
| * File: si5351.cpp | |||
| * Author: JF3HZB / T.UEBO | |||
| * | |||
| * Created on 2020/08/20, 23:07 | |||
| * | |||
| * Get IQ local signal down to 100kHz | |||
| * | |||
| */ | |||
| #include <arduino.h> | |||
| #define SDA 21 | |||
| #define SCL 22 | |||
| #define fxtal (25000000) | |||
| #define pi 3.14159265359 | |||
| #define PH (pi/2) // PH=90deg | |||
| #define df 4 // (Hz) | |||
| #define tw 1 | |||
| uint32_t oMf=-1; | |||
| uint32_t oMc=-1; | |||
| uint32_t oFL=-1; | |||
| void wr_I2C(unsigned char d){ | |||
| int k; | |||
| for(k=0;k<8;k++){ | |||
| if(d & 0x80) digitalWrite(SDA, HIGH); else digitalWrite(SDA, LOW); | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, HIGH); | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, LOW); | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SDA, LOW); | |||
| d <<= 1; | |||
| } | |||
| digitalWrite(SCL, HIGH); | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, LOW); | |||
| } | |||
| void cmd_si5351(unsigned char reg_No, unsigned char d){ | |||
| digitalWrite(SDA, LOW); // start condition | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, LOW); // | |||
| delayMicroseconds(tw); | |||
| wr_I2C(0xC0); | |||
| wr_I2C(reg_No); | |||
| wr_I2C(d); | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, HIGH); // stop condition | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SDA, HIGH); // | |||
| delayMicroseconds(10+tw); | |||
| } | |||
| void cmd_si5351_block(unsigned char reg_No, unsigned char *d){ | |||
| digitalWrite(SDA, LOW); // start condition | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, LOW); // | |||
| delayMicroseconds(tw); | |||
| wr_I2C(0xC0); | |||
| wr_I2C(reg_No); | |||
| int i; | |||
| for (i=0; i<8; i++) { | |||
| wr_I2C(d[i]); | |||
| } | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SCL, HIGH); // stop condition | |||
| delayMicroseconds(tw); | |||
| digitalWrite(SDA, HIGH); // | |||
| delayMicroseconds(10+tw); | |||
| } | |||
| void set_freq(unsigned long freq){ | |||
| // freq [Hz] | |||
| // | |||
| // fvco= fxtal*(a+b/c) ( a:15 -- 90, b:0 -- 1048575, c:1 -- 1048575 ) | |||
| // freq= fvco /(a+b/c) ( a:4, 6--1800, b:0 -- 1048575, c:1 -- 1048575 ) | |||
| // | |||
| // P1= 128*a + floor(128*b/c) - 512 | |||
| // P2= 128*b - c*floor(128*b/c) | |||
| // P3= c | |||
| // | |||
| int k; | |||
| uint32_t M; | |||
| uint32_t R; | |||
| uint32_t FL; | |||
| unsigned long c; | |||
| unsigned long a; | |||
| unsigned long b; | |||
| unsigned long dd; | |||
| unsigned long P1; | |||
| unsigned long P2; | |||
| unsigned long P3; | |||
| unsigned char dat[8]; | |||
| if(freq<1500) freq=1500; else if(freq>280000000) freq=280000000; | |||
| if(freq>=3000000){ //-------------------freq>=3MHz-------------------------------------------------- | |||
| FL=0; | |||
| if(FL!=oFL){ | |||
| cmd_si5351(16,0x4F); // Enable CLK0 (MS0=Integer Mode, Source=PLL_A) | |||
| cmd_si5351(17,0x4F); // Enable CLK1 (MS1=Integer Mode, Source=PLL_A) | |||
| } | |||
| if( freq> 150000000){M=4; R=0;} | |||
| else if(freq>=63000000){M=6; R=0;} | |||
| else if(freq>=27500000){M=14; R=0;} | |||
| else if(freq>=13000000){M=30; R=0;} | |||
| else if(freq>= 6500000){M=62; R=0;} | |||
| else {M=126; R=0;} | |||
| freq*=M; | |||
| freq<<=R; | |||
| c=0xFFFFF; | |||
| a=freq/fxtal; | |||
| b=(long)((float)(freq-a*fxtal)*(float)c/(float)fxtal); | |||
| dd=(128*b)/c; | |||
| P1=128*a+dd-512; | |||
| P2=128*b-c*dd; | |||
| P3=c; | |||
| //Set fvco of PLL_A | |||
| cmd_si5351(26,(P3>>8)&0xFF); //MSNA_P3[15:8] | |||
| cmd_si5351(27,P3&0xFF); //MSNA_P3[7:0] | |||
| cmd_si5351(28,(P1>>16)&0x03); //MSNA_P1[17:16] | |||
| cmd_si5351(29,(P1>>8)&0xFF); //MSNA_P1[15:8] | |||
| cmd_si5351(30,P1&0xFF); //MSNA_P1[7:0] | |||
| cmd_si5351(31,(P3>>12)&0xF0|(P2>>16)&0x0F);//MSNA_P3[19:16], MSNA_P2[19:16] | |||
| cmd_si5351(32,(P2>>8)&0xFF); //MSNA_P2[15:8] | |||
| cmd_si5351(33,P2&0xFF); //MSNA_P2[7:0] | |||
| if( (oMf!=M)||(FL!=oFL) ){ | |||
| // Set MS0, MS1 | |||
| // a=M, b=0, c=1 ---> P1=128*M-512, P2=0, P3=1 | |||
| if(M==4){ | |||
| P1=0; | |||
| cmd_si5351(42,0); //MS0_P3[15:8] | |||
| cmd_si5351(43,1); //MS0_P3[7:0] | |||
| cmd_si5351(44,0b00001100); //0,R0_DIV[2:0],MS0_DIVBY4[1:0],MS0_P1[17:16] | |||
| cmd_si5351(45,0); //MS0_P1[15:8] | |||
| cmd_si5351(46,0); //MS0_P1[7:0] | |||
| cmd_si5351(47,0); //MS0_P3[19:16], MS0_P2[19:16] | |||
| cmd_si5351(48,0); //MS0_P2[15:8] | |||
| cmd_si5351(49,0); //MS0_P2[7:0] | |||
| cmd_si5351(50,0); //MS1_P3[15:8] | |||
| cmd_si5351(51,1); //MS1_P3[7:0] | |||
| cmd_si5351(52,0b00001100); //0,R1_DIV[2:0],MS1_DIVBY4[1:0],MS1_P1[17:16] | |||
| cmd_si5351(53,0); //MS1_P1[15:8] | |||
| cmd_si5351(54,0); //MS1_P1[7:0] | |||
| cmd_si5351(55,0); //MS1_P3[19:16], MS0_P2[19:16] | |||
| cmd_si5351(56,0); //MS1_P2[15:8] | |||
| cmd_si5351(57,0); //MS1_P2[7:0] | |||
| }else{ | |||
| P1=128*M-512; | |||
| cmd_si5351(42,0); //MS0_P3[15:8] | |||
| cmd_si5351(43,1); //MS0_P3[7:0] | |||
| cmd_si5351(44,(R<<4)&0x70|(P1>>16)&0x03);//0,R0_DIV[2:0],MS0_DIVBY4[1:0],MS0_P1[17:16] | |||
| cmd_si5351(45,(P1>>8)&0xFF); //MS0_P1[15:8] | |||
| cmd_si5351(46,P1&0xFF); //MS0_P1[7:0] | |||
| cmd_si5351(47,0); //MS0_P3[19:16], MS0_P2[19:16] | |||
| cmd_si5351(48,0); //MS0_P2[15:8] | |||
| cmd_si5351(49,0); //MS0_P2[7:0] | |||
| cmd_si5351(50,0); //MS1_P3[15:8] | |||
| cmd_si5351(51,1); //MS1_P3[7:0] | |||
| cmd_si5351(52,(R<<4)&0x70|(P1>>16)&0x03);//0,R1_DIV[2:0],MS1_DIVBY4[1:0],MS1_P1[17:16] | |||
| cmd_si5351(53,(P1>>8)&0xFF); //MS1_P1[15:8] | |||
| cmd_si5351(54,P1&0xFF); //MS1_P1[7:0] | |||
| cmd_si5351(55,0); //MS1_P3[19:16], MS0_P2[19:16] | |||
| cmd_si5351(56,0); //MS1_P2[15:8] | |||
| cmd_si5351(57,0); //MS1_P2[7:0] | |||
| } | |||
| cmd_si5351(165,0); | |||
| cmd_si5351(166,M); | |||
| cmd_si5351(177,0x20); // Reset PLLA | |||
| } | |||
| oMf=M; | |||
| }//------------------- End of set freq>=3MHz---------------------------------------------- | |||
| else { //-------------------freq<3MHz----------------------------------------------------- | |||
| long fvco; | |||
| if (freq>=1500000){ FL=1; fvco=freq*300;} | |||
| else if(freq>= 500000){ FL=2; fvco=freq*600;} | |||
| else { FL=3; fvco=freq*1800;} | |||
| R=0; | |||
| if(FL!=oFL){ | |||
| double Td=1e6*PH/(2*pi*df); //convert 90deg to Td(us) | |||
| cmd_si5351(16,0x0F); // Enable CLK0 (MS0=Fractional Mode, Source=PLL_A) | |||
| cmd_si5351(17,0x0F); // Enable CLK1 (MS1=Fractional Mode, Source=PLL_A) | |||
| c=0xFFFFF; | |||
| a=fvco/fxtal; | |||
| b=(long)((double)(fvco-a*fxtal)*(double)c/(double)fxtal); | |||
| dd=(128*b)/c; | |||
| P1=128*a+dd-512; | |||
| P2=128*b-c*dd; | |||
| P3=c; | |||
| //Set fvco of PLL_A | |||
| cmd_si5351(26,(P3>>8)&0xFF); //MSNA_P3[15:8] | |||
| cmd_si5351(27,P3&0xFF); //MSNA_P3[7:0] | |||
| cmd_si5351(28,(P1>>16)&0x03); //MSNA_P1[17:16] | |||
| cmd_si5351(29,(P1>>8)&0xFF); //MSNA_P1[15:8] | |||
| cmd_si5351(30,P1&0xFF); //MSNA_P1[7:0] | |||
| cmd_si5351(31,(P3>>12)&0xF0|(P2>>16)&0x0F);//MSNA_P3[19:16], MSNA_P2[19:16] | |||
| cmd_si5351(32,(P2>>8)&0xFF); //MSNA_P2[15:8] | |||
| cmd_si5351(33,P2&0xFF); //MSNA_P2[7:0] | |||
| //-------------- shift 90 deg -------------------------------- | |||
| c=0xFFFFF; | |||
| a=fvco/(freq-df ); | |||
| b=(long)( (double)(fvco-a*(freq-df))*(double)c/(double)(freq-df) ); | |||
| dd=(128*b)/c; | |||
| P1=128*a+dd-512; | |||
| P2=128*b-c*dd; | |||
| P3=c; | |||
| dat[0]=(P3>>8)&0xFF; | |||
| dat[1]=P3&0xFF; | |||
| dat[2]=(R<<4)&0x70|(P1>>16)&0x03; | |||
| dat[3]=(P1>>8)&0xFF; | |||
| dat[4]=P1&0xFF; | |||
| dat[5]=(P3>>12)&0xF0|(P2>>16)&0x0F; | |||
| dat[6]=(P2>>8)&0xFF; | |||
| dat[7]=P2&0xFF; | |||
| cmd_si5351_block(42,dat); | |||
| cmd_si5351_block(50,dat); | |||
| cmd_si5351(165,0); | |||
| cmd_si5351(166,0); | |||
| cmd_si5351(177,0x20); // Reset PLLA | |||
| a=fvco/( freq ); | |||
| b=(long)( (double)(fvco-a*freq )*(double)c/(double)(freq) ); | |||
| dd=(128*b)/c; | |||
| P1=128*a+dd-512; | |||
| P2=128*b-c*dd; | |||
| P3=c; | |||
| dat[0]=(P3>>8)&0xFF; | |||
| dat[1]=P3&0xFF; | |||
| dat[2]=(R<<4)&0x70|(P1>>16)&0x03; | |||
| dat[3]=(P1>>8)&0xFF; | |||
| dat[4]=P1&0xFF; | |||
| dat[5]=(P3>>12)&0xF0|(P2>>16)&0x0F; | |||
| dat[6]=(P2>>8)&0xFF; | |||
| dat[7]=P2&0xFF; | |||
| cmd_si5351_block(42, dat); | |||
| delayMicroseconds((int)Td); | |||
| cmd_si5351_block(50, dat); | |||
| //------------------------------------------------------ | |||
| } | |||
| a=fvco/fxtal; | |||
| b=(long)((float)(fvco-a*fxtal)*(float)c/(float)fxtal); | |||
| dd=(128*b)/c; | |||
| P1=128*a+dd-512; | |||
| P2=128*b-c*dd; | |||
| P3=c; | |||
| //Set freq of PLL_A | |||
| cmd_si5351(26,(P3>>8)&0xFF); //MSNA_P3[15:8] | |||
| cmd_si5351(27,P3&0xFF); //MSNA_P3[7:0] | |||
| cmd_si5351(28,(P1>>16)&0x03); //MSNA_P1[17:16] | |||
| cmd_si5351(29,(P1>>8)&0xFF); //MSNA_P1[15:8] | |||
| cmd_si5351(30,P1&0xFF); //MSNA_P1[7:0] | |||
| cmd_si5351(31,(P3>>12)&0xF0|(P2>>16)&0x0F);//MSNA_P3[19:16], MSNA_P2[19:16] | |||
| cmd_si5351(32,(P2>>8)&0xFF); //MSNA_P2[15:8] | |||
| cmd_si5351(33,P2&0xFF); //MSNA_P2[7:0] | |||
| } //-------------------------- End of set freq<3MHz--------------------------------------------- | |||
| oFL=FL; | |||
| } | |||
| void set_car_freq(unsigned long freq, unsigned char EN, unsigned char RST){ | |||
| // freq [Hz] | |||
| // | |||
| // fvco= fxtal*(a+b/c) ( a:15 -- 90, b:0 -- 1048575, c:1 -- 1048575 ) | |||
| // freq= fvco /(a+b/c) ( a:4, 6--1800, b:0 -- 1048575, c:1 -- 1048575 ) | |||
| // | |||
| // P1= 128*a + floor(128*b/c) - 512 | |||
| // P2= 128*b - c*floor(128*b/c) | |||
| // P3= c | |||
| // | |||
| int k; | |||
| uint32_t M; | |||
| uint32_t R; | |||
| if(EN==1){ | |||
| cmd_si5351(18,0x6F); | |||
| if(freq<1500) freq=1500; else if(freq>280000000) freq=280000000; | |||
| if( freq> 150000000){M=4; R=0;} | |||
| else if(freq>=63000000){M=6; R=0;} | |||
| else if(freq>=27500000){M=14; R=0;} | |||
| else if(freq>=13000000){M=30; R=0;} | |||
| else if(freq>= 6500000){M=62; R=0;} | |||
| else if(freq>= 3000000){M=126; R=0;} | |||
| else if(freq>= 1500000){M=280; R=0;} | |||
| else if(freq>= 700000){M=600; R=0;} | |||
| else if(freq>= 330000){M=1280; R=0;} | |||
| else if(freq>= 150000){M=1300; R=1;} | |||
| else if(freq>= 67000){M=1500; R=2;} | |||
| else if(freq>= 30300){M=1600; R=3;} | |||
| else if(freq>= 14000){M=1800; R=4;} | |||
| else if(freq>= 7000){M=1800; R=5;} | |||
| else if(freq>= 3500){M=1800; R=6;} | |||
| else{M=1800; R=7;} | |||
| freq*=M; | |||
| freq<<=R; | |||
| unsigned long c=0xFFFFF; | |||
| unsigned long a=freq/fxtal; | |||
| unsigned long b=(long)((float)(freq-a*fxtal)*(float)c/(float)fxtal); | |||
| unsigned long dd=(128*b)/c; | |||
| unsigned long P1=128*a+dd-512; | |||
| unsigned long P2=128*b-c*dd; | |||
| unsigned long P3=c; | |||
| //Set fvco of PLL_B | |||
| cmd_si5351(34,(P3>>8)&0xFF); //MSNB_P3[15:8] | |||
| cmd_si5351(35,P3&0xFF); //MSNB_P3[7:0] | |||
| cmd_si5351(36,(P1>>16)&0x03); //MSNB_P1[17:16] | |||
| cmd_si5351(37,(P1>>8)&0xFF); //MSNB_P1[15:8] | |||
| cmd_si5351(38,P1&0xFF); //MSNB_P1[7:0] | |||
| cmd_si5351(39,(P3>>12)&0xF0|(P2>>16)&0x0F);//MSNB_P3[19:16], MSNB_P2[19:16] | |||
| cmd_si5351(40,(P2>>8)&0xFF); //MSNB_P2[15:8] | |||
| cmd_si5351(41,P2&0xFF); //MSNB_P2[7:0] | |||
| // Set MS2 | |||
| // a=M, b=0, c=1 ---> P1=128*M-512, P2=0, P3=1 | |||
| if(M==4){ | |||
| P1=0; | |||
| cmd_si5351(58,0); //MS2_P3[15:8] | |||
| cmd_si5351(59,1); //MS2_P3[7:0] | |||
| cmd_si5351(60,0b00001100); //0,R0_DIV[2:0],MS2_DIVBY4[1:0],MS2_P1[17:16] | |||
| cmd_si5351(61,0); //MS2_P1[15:8] | |||
| cmd_si5351(62,0); //MS2_P1[7:0] | |||
| cmd_si5351(63,0); //MS2_P3[19:16], MS2_P2[19:16] | |||
| cmd_si5351(64,0); //MS2_P2[15:8] | |||
| cmd_si5351(65,0); //MS2_P2[7:0] | |||
| }else{ | |||
| P1=128*M-512; | |||
| cmd_si5351(58,0); //MS2_P3[15:8] | |||
| cmd_si5351(59,1); //MS2_P3[7:0] | |||
| cmd_si5351(60,(R<<4)&0x70|(P1>>16)&0x03);//0,R0_DIV[2:0],MS2_DIVBY4[1:0],MS2_P1[17:16] | |||
| cmd_si5351(61,(P1>>8)&0xFF); //MS2_P1[15:8] | |||
| cmd_si5351(62,P1&0xFF); //MS2_P1[7:0] | |||
| cmd_si5351(63,0); //MS2_P3[19:16], MS2_P2[19:16] | |||
| cmd_si5351(64,0); //MS2_P2[15:8] | |||
| cmd_si5351(65,0); //MS2_P2[7:0] | |||
| } | |||
| if( (oMc!=M)||(RST==1) ){ | |||
| //cmd_si5351(177,0x80); // Reset PLLB | |||
| } | |||
| oMc=M; | |||
| }else{ | |||
| cmd_si5351(18,0x80); | |||
| } | |||
| } | |||
| void si5351_init(void){ | |||
| pinMode(SDA, OUTPUT); | |||
| pinMode(SCL, OUTPUT); | |||
| digitalWrite(SDA, HIGH); | |||
| digitalWrite(SCL, HIGH); | |||
| delay(10); | |||
| cmd_si5351(183,0b10010010); // CL=8pF | |||
| cmd_si5351(16,0x80); // Disable CLK0 | |||
| cmd_si5351(17,0x80); // Disable CLK1 | |||
| cmd_si5351(18,0x80); // Disable CLK2 | |||
| cmd_si5351(177,0xA0); // Reset PLL_A and B | |||
| cmd_si5351(16,0x4F); // Enable CLK0 (MS0=Integer Mode, Source=PLL_A) | |||
| cmd_si5351(17,0x4F); // Enable CLK1 (MS1=Integer Mode, Source=PLL_A) | |||
| cmd_si5351(18,0x80); // Disable CLK2 (MS2=Integer Mode, Source=PLL_B) | |||
| cmd_si5351(177,0xA0); // Reset PLL_A and B | |||
| delay(10); | |||
| set_freq(10000000); | |||
| cmd_si5351(177,0x20); // Reset PLLA | |||
| delay(10); | |||
| } | |||
| @ -0,0 +1,17 @@ | |||
| /* | |||
| * File: si5351.h | |||
| * Author: JF3HZB / T.UEBO | |||
| * | |||
| * Created on 2019/02/11, 23:07 | |||
| */ | |||
| #ifndef __si5351H___ | |||
| #define __si5351H___ | |||
| void si5351_init(void); | |||
| void set_freq(unsigned long freq); | |||
| void set_car_freq(unsigned long freq, unsigned char EN, unsigned char RST); | |||
| void cmd_si5351_block(unsigned char reg_No, unsigned char *d); | |||
| #endif | |||
| @ -0,0 +1,17 @@ | |||
| "VFOsys2" is the original version of a digital VFO with analog dial display by Tj Lab(JF3HZB), | |||
| which can be compiled on Arduino IDE with Board manager "esp32 ver. 2.0.9" and Library "LovyanGFX ver. 1.1.7". | |||
| Usable display panel: | |||
| ST7735S (128 x 160, 80 x 160), | |||
| ST7789 (135 x 240, 240 x 240, 240 x 320), | |||
| ILI9341 (240 x 320), | |||
| SSD1331 (64 x 96). | |||
| JF3HZB T. Uebo | |||
| Tj Lab | |||
| https://tj-lab.org | |||