最近在 Teensy 3.2 上使用 ILI9341 的液晶屏,在编译的时候会出现两个错误导致无法完成编译。
1.关于 _NOP 的错误。经过搜索,在 https://github.com/olikraus/ucglib/issues/65 找到有人解决过这样的问题。原帖写的是:
Ucglib.cpp, line 786 – change the
…defined(__arm__)… to …defined(__NOT_arm__)…
Ucglib.cpp, line 833, add the following:
#ifndef __NOP
#define __NOP __asm__ __volatile__("NOP");
#endif
有可能是因为版本的差别,我在Ucglib.cpp 中修改如下:
Line783:
#if defined(__PIC32MX) || defined(__NOT_arm__) || defined(ESP8266) || defined(ARDUINO_ARCH_ESP8266) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_ESP32)
Line 830:
#ifndef __NOP
#define __NOP __asm__ __volatile__("NOP");
#endif
之后即可解决这个问题。
2. u8g_data_port 的错误。修改方法是将 Ucglib.cpp
#if defined(__PIC32MX) || defined(__arm__) || defined(ESP8266) || defined(ARDUINO_ARCH_ESP8266) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_ESP32)
/* CHIPKIT PIC32 */
static volatile uint32_t *u8g_data_port[9];
static uint32_t u8g_data_mask[9];
#else
中的 static volatile uint32_t *u8g_data_port[9]; 修改为 static volatile uint8_t *u8g_data_port[9]; 。 这样有可能降低 UcgLib 的通用性,但是编译没问题。
代码中按照下面两种接线和定义都是能够工作正常的
Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
推荐 HWSPI,速度快很多。