|
| 1 | + |
| 2 | +#include <lvgl.h> |
| 3 | +#include <LovyanGFX.hpp> |
| 4 | + |
| 5 | +class LGFX : public lgfx::LGFX_Device |
| 6 | +{ |
| 7 | +lgfx::Panel_ILI9341 _panel_instance; |
| 8 | +lgfx::Bus_SPI _bus_instance; // SPI bus instance // SPIバスのインスタンス |
| 9 | +lgfx::Light_PWM _light_instance; |
| 10 | +lgfx::Touch_XPT2046 _touch_instance; |
| 11 | + |
| 12 | +public: |
| 13 | + LGFX(void) |
| 14 | + { |
| 15 | + { // バス制御の設定を行います。 |
| 16 | + auto cfg = _bus_instance.config(); // Gets the structure for bus configuration. // バス設定用の構造体を取得します。 |
| 17 | + cfg.spi_host = HSPI_HOST; // Select the SPI to use // 使用するSPIを選択 (VSPI_HOST or HSPI_HOST) |
| 18 | + cfg.spi_mode = 0; // Set SPI communication mode (0 ~ 3) // SPI通信モードを設定 (0 ~ 3) |
| 19 | + cfg.freq_write = 55000000; // SPI clock at the time of transmission (up to 80MHz, rounded to the value obtained by dividing 80MHz by an integer) // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます) |
| 20 | + cfg.freq_read = 20000000; // SPI clock when receiving // 受信時のSPIクロック |
| 21 | + cfg.spi_3wire = false; // Set true when receiving with MOSI pin // 受信をMOSIピンで行う場合はtrueを設定 |
| 22 | + cfg.use_lock = true; // Set to true when using transaction lock // トランザクションロックを使用する場合はtrueを設定 |
| 23 | + cfg.dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable) // 使用するDMAチャンネルを設定 (0=DMA不使用) |
| 24 | + cfg.pin_sclk = 14; // Set SPI SCLK pin number // SPIのSCLKピン番号を設定 |
| 25 | + cfg.pin_mosi = 13; // Set SPI MOSI pin number // SPIのMOSIピン番号を設定 |
| 26 | + cfg.pin_miso = 12; // Set SPI MISO pin number (-1 = disable) // SPIのMISOピン番号を設定 (-1 = disable) |
| 27 | + cfg.pin_dc = 2; // Set SPI D / C pin number (-1 = disable) // SPIのD/Cピン番号を設定 (-1 = disable) |
| 28 | + |
| 29 | + _bus_instance.config(cfg); // The set value is reflected on the bus. // 設定値をバスに反映します。 |
| 30 | + _panel_instance.setBus(&_bus_instance); // Set the bus on the panel. // バスをパネルにセットします。 |
| 31 | + } |
| 32 | + |
| 33 | + { // Set the display panel control.//表示パネル制御の設定を行います。 |
| 34 | + auto cfg = _panel_instance.config(); // Gets the structure for display panel settings.// 表示パネル設定用の構造体を取得します。 |
| 35 | + cfg.pin_cs = 15; // Pin number to which CS is connected (-1 = disable) // CSが接続されているピン番号 (-1 = disable) |
| 36 | + cfg.pin_rst = -1; // Pin number to which RST is connected (-1 = disable) // RSTが接続されているピン番号 (-1 = disable) |
| 37 | + cfg.pin_busy = -1; // Pin number to which BUSY is connected (-1 = disable) // BUSYが接続されているピン番号 (-1 = disable) |
| 38 | + cfg.memory_width = 240; // Maximum width supported by driver IC // ドライバICがサポートしている最大の幅 |
| 39 | + cfg.memory_height = 320; // Maximum height supported by driver IC // ドライバICがサポートしている最大の高さ |
| 40 | + cfg.panel_width = 240; // Actually displayable width // 実際に表示可能な幅 |
| 41 | + cfg.panel_height = 320; // Actually displayable height // 実際に表示可能な高さ |
| 42 | + cfg.offset_x = 0; // Amount of X-direction offset of the panel // パネルのX方向オフセット量 |
| 43 | + cfg.offset_y = 0; // Amount of Y-direction offset of the panel // パネルのY方向オフセット量 |
| 44 | + cfg.offset_rotation = 0; // Offset of values in the direction of rotation 0 ~ 7 (4 ~ 7 are upside down) // 回転方向の値のオフセット 0~7 (4~7は上下反転) |
| 45 | + cfg.dummy_read_pixel = 8; // Number of dummy read bits before pixel reading // ピクセル読出し前のダミーリードのビット数 |
| 46 | + cfg.dummy_read_bits = 1; // Number of bits of dummy read before reading data other than pixels // ピクセル以外のデータ読出し前のダミーリードのビット数 |
| 47 | + cfg.readable = true; // Set to true if data can be read // データ読出しが可能な場合 trueに設定 |
| 48 | + cfg.invert = false; // Set to true if the light and darkness of the panel is reversed // パネルの明暗が反転してしまう場合 trueに設定 |
| 49 | + cfg.rgb_order = false; // Set to true if the red and blue of the panel are swapped // パネルの赤と青が入れ替わってしまう場合 trueに設定 |
| 50 | + cfg.dlen_16bit = false; // Set to true for panels that send data length in 16-bit units // データ長を16bit単位で送信するパネルの場合 trueに設定 |
| 51 | + cfg.bus_shared = true; // If the bus is shared with the SD card, set to true (bus control is performed with drawJpgFile etc.) // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います) |
| 52 | + |
| 53 | + _panel_instance.config(cfg); |
| 54 | + } |
| 55 | + |
| 56 | + { // Set the backlight control. (Delete if not needed // バックライト制御の設定を行います。(必要なければ削除) |
| 57 | + auto cfg = _light_instance.config(); // Gets the structure for the backlight setting. // バックライト設定用の構造体を取得します。 |
| 58 | + |
| 59 | + cfg.pin_bl = 21; // Pin number to which the backlight is connected // バックライトが接続されているピン番号 |
| 60 | + cfg.invert = false; // True if you want to invert the brightness of the backlight // バックライトの輝度を反転させる場合 true |
| 61 | + cfg.freq = 44100; // Backlight PWM frequency // バックライトのPWM周波数 |
| 62 | + cfg.pwm_channel = 7; // PWM channel number to use // 使用するPWMのチャンネル番号 |
| 63 | + |
| 64 | + _light_instance.config(cfg); |
| 65 | + _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. // バックライトをパネルにセットします。 |
| 66 | + } |
| 67 | + |
| 68 | + { // Set the touch screen control. (Delete if not needed) // タッチスクリーン制御の設定を行います。(必要なければ削除) |
| 69 | + auto cfg = _touch_instance.config(); |
| 70 | + cfg.x_min = 0; // Minimum X value (raw value) obtained from touch screen // タッチスクリーンから得られる最小のX値(生の値) |
| 71 | + cfg.x_max = 239; // Maximum X value (raw value) obtained from the touch screen // タッチスクリーンから得られる最大のX値(生の値) |
| 72 | + cfg.y_min = 0; // Minimum Y value (raw value) obtained from touch screen // タッチスクリーンから得られる最小のY値(生の値) |
| 73 | + cfg.y_max = 319; // Maximum Y value (raw value) obtained from the touch screen // タッチスクリーンから得られる最大のY値(生の値) |
| 74 | + cfg.pin_int = 36; // Pin number to which INT is connected // INTが接続されているピン番号 |
| 75 | + cfg.bus_shared = true; // Set to true if you are using the same bus as the screen // 画面と共通のバスを使用している場合 trueを設定 |
| 76 | + cfg.offset_rotation = 0;// Adjustment when the display and touch orientation do not match Set with a value from 0 to 7 // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定 |
| 77 | + cfg.spi_host = VSPI_HOST;// Select the SPI to use (HSPI_HOST or VSPI_HOST) // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST) |
| 78 | + cfg.freq = 2500000; // Set SPI clock // SPIクロックを設定 |
| 79 | + cfg.pin_sclk = 25; // Pin number to which SCLK is connected // SCLKが接続されているピン番号 |
| 80 | + cfg.pin_mosi = 32; // Pin number to which MOSI is connected // MOSIが接続されているピン番号 |
| 81 | + cfg.pin_miso = 39; // Pin number to which MISO is connected // MISOが接続されているピン番号 |
| 82 | + cfg.pin_cs = 33; // Pin number to which CS is connected // CSが接続されているピン番号 |
| 83 | + |
| 84 | + _touch_instance.config(cfg); |
| 85 | + _panel_instance.setTouch(&_touch_instance); // Set the touch screen on the panel. // タッチスクリーンをパネルにセットします。 |
| 86 | + } |
| 87 | + setPanel(&_panel_instance); // Set the panel to be used. // 使用するパネルをセットします。 |
| 88 | + } |
| 89 | +}; |
| 90 | + |
| 91 | + |
| 92 | +/*Change to your screen resolution*/ |
| 93 | +static const uint32_t screenWidth = 320; |
| 94 | +static const uint32_t screenHeight = 240; |
| 95 | +static lv_disp_draw_buf_t draw_buf; |
| 96 | +static lv_color_t buf[ screenWidth * 10 ]; |
| 97 | + |
0 commit comments