Closed Fan-Yi-Ming closed 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
Thank you very much. That's what I missed
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,
static const uint8_t u8x8_d_uc1611s_240x160_fym_init_seq[] = {
};
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
===================/
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;
}
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;
} /============================================================================================================================/