This commit is contained in:
kraus 2018-10-28 21:40:55 +01:00
parent 2d85d77f07
commit 9164db6e76
6 changed files with 26 additions and 15 deletions

View File

@ -63,6 +63,9 @@ class U8G2 : public Print
u8x8_t *getU8x8(void) { return u8g2_GetU8x8(&u8g2); }
u8g2_t *getU8g2(void) { return &u8g2; }
uint32_t getBusClock(void) { return u8g2_GetU8x8(&u8g2)->bus_clock; }
void setBusClock(uint32_t clock_speed) { u8g2_GetU8x8(&u8g2)->bus_clock = clock_speed; }
void setI2CAddress(uint8_t adr) { u8g2_SetI2CAddress(&u8g2, adr); }

View File

@ -556,6 +556,7 @@ extern "C" uint8_t u8x8_byte_arduino_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t a
break;
case U8X8_MSG_BYTE_INIT:
u8x8->bus_clock = u8x8->display_info->sck_clock_hz;
/* disable chipselect */
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
@ -608,7 +609,7 @@ extern "C" uint8_t u8x8_byte_arduino_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t a
}
#if ARDUINO >= 10600
SPI.beginTransaction(SPISettings(u8x8->display_info->sck_clock_hz, MSBFIRST, internal_spi_mode));
SPI.beginTransaction(SPISettings(u8x8->bus_clock, MSBFIRST, internal_spi_mode));
#else
SPI.begin();
@ -674,6 +675,7 @@ extern "C" uint8_t u8x8_byte_arduino_2nd_hw_spi(U8X8_UNUSED u8x8_t *u8x8, U8X8_U
break;
case U8X8_MSG_BYTE_INIT:
u8x8->bus_clock = u8x8->display_info->sck_clock_hz;
/* disable chipselect */
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
/* no wait required here */
@ -704,7 +706,7 @@ extern "C" uint8_t u8x8_byte_arduino_2nd_hw_spi(U8X8_UNUSED u8x8_t *u8x8, U8X8_U
}
#if ARDUINO >= 10600
SPI1.beginTransaction(SPISettings(u8x8->display_info->sck_clock_hz, MSBFIRST, internal_spi_mode));
SPI1.beginTransaction(SPISettings(u8x8->bus_clock, MSBFIRST, internal_spi_mode));
#else
SPI1.begin();
@ -975,6 +977,7 @@ extern "C" uint8_t u8x8_byte_arduino_hw_i2c(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSE
Wire.write((uint8_t *)arg_ptr, (int)arg_int);
break;
case U8X8_MSG_BYTE_INIT:
u8x8->bus_clock = u8x8->display_info->i2c_bus_clock_100kHz * 100000UL;
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP8266) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_ESP32)
/* for ESP8266/ESP32, Wire.begin has two more arguments: clock and data */
if ( u8x8->pins[U8X8_PIN_I2C_CLOCK] != U8X8_PIN_NONE && u8x8->pins[U8X8_PIN_I2C_DATA] != U8X8_PIN_NONE )
@ -996,10 +999,7 @@ extern "C" uint8_t u8x8_byte_arduino_hw_i2c(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSE
#if ARDUINO >= 10600
/* not sure when the setClock function was introduced, but it is there since 1.6.0 */
/* if there is any error with Wire.setClock() just remove this function call */
if ( u8x8->display_info->i2c_bus_clock_100kHz >= 4 )
{
Wire.setClock(400000L);
}
Wire.setClock(u8x8->bus_clock);
#endif
Wire.beginTransmission(u8x8_GetI2CAddress(u8x8)>>1);
break;
@ -1022,6 +1022,7 @@ extern "C" uint8_t u8x8_byte_arduino_2nd_hw_i2c(U8X8_UNUSED u8x8_t *u8x8, U8X8_U
Wire1.write((uint8_t *)arg_ptr, (int)arg_int);
break;
case U8X8_MSG_BYTE_INIT:
u8x8->bus_clock = u8x8->display_info->i2c_bus_clock_100kHz * 100000UL;
Wire1.begin();
break;
case U8X8_MSG_BYTE_SET_DC:
@ -1030,10 +1031,7 @@ extern "C" uint8_t u8x8_byte_arduino_2nd_hw_i2c(U8X8_UNUSED u8x8_t *u8x8, U8X8_U
#if ARDUINO >= 10600
/* not sure when the setClock function was introduced, but it is there since 1.6.0 */
/* if there is any error with Wire.setClock() just remove this function call */
if ( u8x8->display_info->i2c_bus_clock_100kHz >= 4 )
{
Wire1.setClock(400000L);
}
Wire1.setClock(u8x8->bus_clock);
#endif
Wire1.beginTransmission(u8x8_GetI2CAddress(u8x8)>>1);
break;

View File

@ -156,9 +156,12 @@ class U8X8 : public Print
public:
uint8_t tx, ty;
U8X8(void) { home(); }
U8X8(void) { home(); }
u8x8_t *getU8x8(void) { return &u8x8; }
uint32_t getBusClock(void) { return u8x8.bus_clock; }
void setBusClock(uint32_t clock_speed) { u8x8.bus_clock = clock_speed; }
void setI2CAddress(uint8_t adr) { u8x8_SetI2CAddress(&u8x8, adr); }
uint8_t getCols(void) { return u8x8_GetCols(&u8x8); }

View File

@ -321,6 +321,7 @@ struct u8x8_struct
u8x8_msg_cb cad_cb;
u8x8_msg_cb byte_cb;
u8x8_msg_cb gpio_and_delay_cb;
uint32_t bus_clock; /* can be used by the byte function to store the clock speed of the bus */
const uint8_t *font;
uint16_t encoding; /* encoding result for utf8 decoder in next_cb */
uint8_t x_offset; /* copied from info struct, can be modified in flip mode */

View File

@ -240,7 +240,14 @@
28 Oct 2018, Arduino 1.8.4, 8 Bit Mode
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno 8MHz Clip=34.0 Box=88.4 @=4.5 Pix=8.2 issue 364, clip window
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno Clip=34.0 Box=88.4 @=4.5 Pix=8.2 issue 364, clip window
U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C Uno Clip=28.4 Box=39.2 @=10.0 Pix=14.9 I2C default
U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C Uno Clip=32.9 Box=48.3 @=10.5 Pix=16.1 I2C default, u8g2.setBusClock(600000UL)
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno Clip=33.9 Box=88.2 @=4.5 Pix=8.2 SPI default speed
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno Clip=32.8 Box=80.6 @=4.5 Pix=8.2 SPI default speed u8g2.setBusClock(6000000UL);
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno Clip=33.9 Box=88.2 @=4.5 Pix=8.2 SPI default speed u8g2.setBusClock(9000000UL);
*/

View File

@ -131,7 +131,7 @@
//U8G2_KS0108_ERM19264_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low!
//U8G2_ST7920_192X32_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_192X32_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0
//U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0
//U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
//U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);
@ -231,14 +231,13 @@ void setup(void) {
void draw(const char *s)
{
delay(1500);
u8g2.firstPage();
do {
u8g2.drawStr(2,15,"PowerSaveTest");
u8g2.drawStr(2,30,s);
u8g2.drawFrame(0,0,u8g2.getDisplayWidth(),u8g2.getDisplayHeight() );
} while ( u8g2.nextPage() );
delay(1500);
delay(2000);
}
void loop(void) {