olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
4.91k stars 1.02k forks source link

UC1611s The first line displays a vertical coordinate of 8, which on an LCD display is equivalent to a downward translation of the screen coordinate by 8 #2448

Closed Fan-Yi-Ming closed 1 month ago

Fan-Yi-Ming commented 1 month ago

I rewrote the driver part of my LCD monitor as recommended in the manual, and it seemed to work fine, but miraculously, it seemed to shift down by 8 pixels overall. My monitor is 240160, which prevents me from printing a line of 58 strings at (0,0), but I can print a 5*8 string at (0,160). My code is below.

/==================================================================================================main.c===============/ u8g2_Setup_uc1611_240x160_fym(&u8g2, U8G2_MIRROR_VERTICAL, u8x8_byte_4wire_hw_spi, u8x8_gpio_and_delay); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); u8g2_ClearBuffer(&u8g2);

u8g2_SetFont(&u8g2, u8g2_font_5x8_tr);

u8g2_DrawStr(&u8g2, 0, 0, "000"); u8g2_DrawStr(&u8g2, 0, 8, "008"); u8g2_DrawStr(&u8g2, 0, 16, "016");

u8g2_DrawStr(&u8g2, 0, 144, "144"); u8g2_DrawStr(&u8g2, 0, 152, "152"); u8g2_DrawStr(&u8g2, 0, 160, "160");

u8g2_SendBuffer(&u8g2); /============================================================================================================================/

/=================================================================================================u8g2_d_setup.c===================/ / fym自定义的函数/ void u8g2_Setup_uc1611_240x160_fym(u8g2_t u8g2, const u8g2_cb_t rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) { uint8_t tile_buf_height; uint8_t buf; u8g2_SetupDisplay(u8g2, u8x8_d_uc1611_240x160_fym, u8x8_cad_001, byte_cb, gpio_and_delay_cb); buf = u8g2_m_30_20_f(&tile_buf_height); u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); } /============================================================================================================================*/

/===============================================================================================u8g2_d_memory.c================/ / fym自定义的函数/ uint8_t u8g2_m_30_20_f(uint8_t page_cnt) {

ifdef U8G2_USE_DYNAMIC_ALLOC

*page_cnt = 20; return 0;

else

static uint8_t buf[4800]; *page_cnt = 20; return buf;

endif

} /============================================================================================================================/

/============================================================================================u8x8_d_uc1611.c===================/ / fym自定义的函数/ static const u8x8_display_info_t u8x8_uc1611s_240x160_fym_display_info = { / chip_enable_level = / 0, / chip_disable_level = / 1,

/* post_chip_enable_wait_ns = */ 10, /* uc1611 datasheet, page 60, actually 0 */
/* pre_chip_disable_wait_ns = */ 10, /* uc1611 datasheet, page 60, actually 0 */
/* reset_pulse_width_ms = */ 1,
/* post_reset_wait_ms = */ 10,  /* uc1611 datasheet, page 67 */
/* sda_setup_time_ns = */ 10,   /* uc1611 datasheet, page 64, actually 0 */
/* sck_pulse_width_ns = */ 60,  /* half of cycle time  */
/* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be  1000000000/sck_pulse_width_ns */
/* spi_mode = */ 3,             /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 30,   /* uc1611 datasheet, page 60 */
/* write_pulse_width_ns = */ 80, /* uc1611 datasheet, page 60 */
/* tile_width = */ 30,           /* width of 30*8=240 pixel */
/* tile_height = */ 20,
/* default_x_offset = */ 0,
/* flipmode_x_offset = */ 0,
/* pixel_width = */ 240,
/* pixel_height = */ 160};

static const uint8_t u8x8_d_uc1611s_240x160_fym_init_seq[] = {

U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */

U8X8_C(0x0EB),         /* Set LCD Bias Ratio */
U8X8_CA(0x081, 0x072), /* Set Vbias */

U8X8_CA(0x0F4, 0x000), /* Set Window Program Starting Column Address */
U8X8_CA(0x0F6, 0x0EF), /* Set Window Program Ending Column Address */

U8X8_CA(0x0F5, 0x000), /* Set Window Program Starting Row Address */
U8X8_CA(0x0F7, 0x04F), /* Set Window Program Ending Row Address */

U8X8_C(0x0D1), /* Display Pattern0 1-bit per 1-pixel */

U8X8_END_TRANSFER(), /* disable chip */
U8X8_END()           /* end of sequence */

};

uint8_t u8x8_d_uc1611_240x160_fym(u8x8_t u8x8, uint8_t msg, uint8_t arg_int, void arg_ptr) { / call common procedure first and handle messages there / if (u8x8_d_uc1611_common(u8x8, msg, arg_int, arg_ptr) == 0) { / msg not handled, then try here / switch (msg) { case U8X8_MSG_DISPLAY_SETUP_MEMORY: u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1611s_240x160_fym_display_info); break; case U8X8_MSG_DISPLAY_INIT: u8x8_d_helper_display_init(u8x8); u8x8_cad_SendSequence(u8x8, u8x8_d_uc1611s_240x160_fym_init_seq); break; case U8X8_MSG_DISPLAY_SET_POWER_SAVE: if (arg_int == 0) u8x8_cad_SendSequence(u8x8, u8x8_d_uc1611s_powersave0_seq); else u8x8_cad_SendSequence(u8x8, u8x8_d_uc1611s_powersave1_seq); break; case U8X8_MSG_DISPLAY_SET_FLIP_MODE: if (arg_int == 0) { u8x8_cad_SendSequence(u8x8, u8x8_d_uc1611s_flip0_seq); u8x8->x_offset = u8x8->display_info->default_x_offset; } else { u8x8_cad_SendSequence(u8x8, u8x8_d_uc1611s_flip1_seq); u8x8->x_offset = u8x8->display_info->flipmode_x_offset; } break; default: return 0; / msg unknown / } } return 1; } /============================================================================================================================/

/=================================================================================================interface 微信图片_20240524130436 ===================/ uint8_t u8x8_byte_4wire_hw_spi(u8x8_t u8x8, uint8_t msg, uint8_t arg_int, void arg_ptr) { uint8_t data; switch (msg) { case U8X8_MSG_BYTE_SEND: data = (uint8_t )arg_ptr; while (arg_int > 0) { spi_hard_swapbyte((uint8_t)*data); data++; arg_int--; } break;

case U8X8_MSG_BYTE_INIT:
    break;

case U8X8_MSG_BYTE_SET_DC:
    uc1611s_w_cd(arg_int);
    break;

case U8X8_MSG_BYTE_START_TRANSFER:
    uc1611s_w_cs(0);
    break;

case U8X8_MSG_BYTE_END_TRANSFER:
    uc1611s_w_cs(1);
    break;

default:
    return 0;
}
return 1;

}

uint8_t u8x8_gpio_and_delay(u8x8_t u8x8, uint8_t msg, uint8_t arg_int, void arg_ptr) { switch (msg) { case U8X8_MSG_GPIO_AND_DELAY_INIT: uc1611s_init(); break;

case U8X8_MSG_DELAY_MILLI:
    delay_ms(arg_int);
    break;

default:
    u8x8_SetGPIOResult(u8x8, 1);
    break;
}
return 1;

} /============================================================================================================================/

olikraus commented 1 month ago

Looks ok to me. Please note, that the reference position for any text is the lower left corner of the string: https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontposbottom

Fan-Yi-Ming commented 1 month ago

Thank you very much. That's what I missed