diff --git a/csrc/u8x8_d_st7567.c b/csrc/u8x8_d_st7567.c index a13ac153..2bd637d9 100644 --- a/csrc/u8x8_d_st7567.c +++ b/csrc/u8x8_d_st7567.c @@ -1510,3 +1510,147 @@ uint8_t u8x8_d_st7567_lw12832(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * return 1; } + + +/*=====================================================*/ +/* + 96x65 + https://github.com/olikraus/u8g2/issues/2332 +*/ + +static const u8x8_display_info_t u8x8_st7567_96x65_display_info = +{ + /* chip_enable_level = */ 0, + /* chip_disable_level = */ 1, + + /* post_chip_enable_wait_ns = */ 150, /* */ + /* pre_chip_disable_wait_ns = */ 50, /* */ + /* reset_pulse_width_ms = */ 1, + /* post_reset_wait_ms = */ 1, + /* sda_setup_time_ns = */ 50, /* */ + /* sck_pulse_width_ns = */ 120, /* */ + /* sck_clock_hz = */ 4000000UL, /* */ + /* spi_mode = */ 0, /* active high, rising edge */ + /* i2c_bus_clock_100kHz = */ 4, + /* data_setup_time_ns = */ 40, /* */ + /* write_pulse_width_ns = */ 80, /* */ + /* tile_width = */ 12, /* width of 12*8=96 pixel */ + /* tile_height = */ 9, + /* default_x_offset = */ 0, + /* flipmode_x_offset = */ 0, + /* pixel_width = */ 96, + /* pixel_height = */ 65 +}; + +static const uint8_t u8x8_st7567_96x65_init_seq[] = { + + U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ + + U8X8_C(0x0e2), /* soft reset */ + U8X8_C(0x0ae), /* display off */ + U8X8_C(0x040), /* set display start line to 0 */ + + U8X8_C(0x0a1), /* ADC set to reverse */ + U8X8_C(0x0c0), /* common output mode */ + // Flipmode + //U8X8_C(0x0a0), /* ADC set to reverse */ + //U8X8_C(0x0c8), /* common output mode */ + + U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */ + U8X8_C(0x0a3), /* LCD bias 1/7 */ + /* power on sequence from paxinstruments */ + U8X8_C(0x028|4), /* all power control circuits on */ + U8X8_DLY(50), + U8X8_C(0x028|6), /* all power control circuits on */ + U8X8_DLY(50), + U8X8_C(0x028|7), /* all power control circuits on */ + U8X8_DLY(50), + + U8X8_C(0x023), /* v0 voltage resistor ratio */ + U8X8_CA(0x081, 42>>2), /* set contrast, contrast value*/ + + U8X8_C(0x0ae), /* display off */ + U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */ + + U8X8_END_TRANSFER(), /* disable chip */ + U8X8_END() /* end of sequence */ +}; + +/* JLX12864 display */ +uint8_t u8x8_d_st7567_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + uint8_t x, c; + uint8_t *ptr; + switch(msg) + { + case U8X8_MSG_DISPLAY_SETUP_MEMORY: + u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_96x65_display_info); + break; + case U8X8_MSG_DISPLAY_INIT: + u8x8_d_helper_display_init(u8x8); + u8x8_cad_SendSequence(u8x8, u8x8_st7567_96x65_init_seq); + break; + case U8X8_MSG_DISPLAY_SET_POWER_SAVE: + if ( arg_int == 0 ) + u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq); + else + u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq); + break; + case U8X8_MSG_DISPLAY_SET_FLIP_MODE: + if ( arg_int == 0 ) + { + u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq); + u8x8->x_offset = u8x8->display_info->default_x_offset; + } + else + { + u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq); + u8x8->x_offset = u8x8->display_info->flipmode_x_offset; + } + break; +#ifdef U8X8_WITH_SET_CONTRAST + case U8X8_MSG_DISPLAY_SET_CONTRAST: + u8x8_cad_StartTransfer(u8x8); + u8x8_cad_SendCmd(u8x8, 0x081 ); + u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */ + u8x8_cad_EndTransfer(u8x8); + break; +#endif + case U8X8_MSG_DISPLAY_DRAW_TILE: + u8x8_cad_StartTransfer(u8x8); + + x = ((u8x8_tile_t *)arg_ptr)->x_pos; + x *= 8; + x += u8x8->x_offset; + u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); + u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); + u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); + + c = ((u8x8_tile_t *)arg_ptr)->cnt; + c *= 8; + ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; + /* + The following if condition checks the hardware limits of the st7567 + controller: It is not allowed to write beyond the display limits. + This is in fact an issue within flip mode. + */ + if ( c + x > 132u ) + { + c = 132u; + c -= x; + } + do + { + u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */ + arg_int--; + } while( arg_int > 0 ); + + u8x8_cad_EndTransfer(u8x8); + break; + default: + return 0; + } + return 1; +} + + diff --git a/sys/sdl/question_2333/Makefile b/sys/sdl/question_2333/Makefile new file mode 100644 index 00000000..5030fe50 --- /dev/null +++ b/sys/sdl/question_2333/Makefile @@ -0,0 +1,12 @@ +CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags` + +SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) $(shell ls ../../bitmap/common/*.c ) $(shell ls *.c ) + +OBJ = $(SRC:.c=.o) + +u8g2_sdl: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl2-config --libs` -o u8g2_sdl + +clean: + -rm $(OBJ) u8g2_sdl + diff --git a/sys/sdl/question_2333/main.c b/sys/sdl/question_2333/main.c new file mode 100644 index 00000000..72027cb8 --- /dev/null +++ b/sys/sdl/question_2333/main.c @@ -0,0 +1,246 @@ + +#include "u8g2.h" +#include +#include +#include +#include "mui.h" +#include "mui_u8g2.h" + + +/*=================================================*/ +/* global variables */ + +u8g2_t u8g2; +mui_t ui; + +uint8_t num_value = 0; +uint8_t bar_value = 0; +uint8_t TestModeRadioChoice = 0; +long LastTime; + + +uint16_t menu_get_cnt(void *data) { + return 7; /* number of menu entries */ +} + +uint16_t menu_get_cnt2(void *data) { + return 5; /* number of menu entries */ +} + +const char *menu_get_str(void *data, uint16_t index) { + static const char *menu[] = { + MUI_11 "Device 1", + MUI_11 "Device 2", + MUI_11 "Device 3", + MUI_11 "Device 4", + MUI_11 "Device 5", + MUI_11 "Device 6" + }; + return menu[index]; +} + +const char *menuAC_get_str(void *data, uint16_t index) { + static const char *menu[] = { + MUI_21 "Test", + MUI_22 "Battery", + MUI_23 "Timer", + MUI_24 "Activation", + MUI_1 "Back..", + }; + return menu[index]; +} + +uint16_t selection = 0, selection2 = 0; + +uint8_t mui_hrule(mui_t *ui, uint8_t msg) { + if (msg == MUIF_MSG_DRAW) { + u8g2_DrawHLine(&u8g2, 0, mui_get_y(ui), 128); + //Serial.println("drawHLine " + String(selection + 1)); + + //Serial.println(String(selection2)); + + selection2 = 0; + } + return 0; +} + +uint8_t mui_draw_current_device(mui_t *ui, uint8_t msg) { + if (msg == MUIF_MSG_DRAW) { + //u8g2_SetCursor(mui_get_x(ui ), mui_get_y(ui)); + u8g2_DrawStr(&u8g2, mui_get_x(ui ), mui_get_y(ui ), "Device: ??"); + + //u8g2.print("Device: " + String(selection + 1)); + + } + return 0; +} + +//forced exit +uint8_t mui_go_main_menu(mui_t *ui, uint8_t msg) { + if (msg == MUIF_MSG_FORM_START) { + mui_SendSelectWithExecuteOnSelectFieldSearch(ui); + + //Serial.println("mui_go_main_menu"); + } + return 0; +} + +muif_t muif_list[] = { + MUIF_U8G2_FONT_STYLE(0, u8g2_font_6x12_t_cyrillic), /* regular font */ + MUIF_U8G2_FONT_STYLE(1, u8g2_font_6x12_t_cyrillic), /* bold font */ + + MUIF_VARIABLE("TM",&TestModeRadioChoice,mui_u8g2_u8_chkbox_wm_pi), + + MUIF_RO("HR", mui_hrule), + MUIF_U8G2_LABEL(), + MUIF_RO("GP", mui_u8g2_goto_data), + MUIF_BUTTON("GC", mui_u8g2_goto_form_w1_pi), + + MUIF_U8G2_U16_LIST("ID", &selection, NULL, menu_get_str, menu_get_cnt, mui_u8g2_u16_list_goto_w1_pi), + + MUIF_U8G2_U16_LIST("AC", &selection2, NULL, menuAC_get_str, menu_get_cnt2, mui_u8g2_u16_list_goto_w1_pi), + + MUIF_RO("DD", mui_draw_current_device), + + MUIF_RO("GG", mui_go_main_menu), + + /* a button for the menu... */ + MUIF_EXECUTE_ON_SELECT_BUTTON("ST", mui_u8g2_btn_exit_wm_fi) + //MUIF_BUTTON("ST", mui_u8g2_btn_exit_wm_fi) +}; + +fds_t fds_data[] = + + MUI_FORM(1) + MUI_STYLE(1) + MUI_LABEL(5, 10, "Choose:") + MUI_XY("HR", 0,11) + + MUI_XYA("ID", 5, 24, 0) + MUI_XYA("ID", 5, 36, 1) + MUI_XYA("ID", 5, 48, 2) + MUI_XYA("ID", 5, 60, 3) + + + MUI_FORM(11) + MUI_STYLE(1) + MUI_XY("HR", 0,11) + MUI_XY("DD", 5, 10) + + MUI_XYA("AC", 5, 24, 0) + MUI_XYA("AC", 5, 36, 1) + MUI_XYA("AC", 5, 48, 2) + MUI_XYA("AC", 5, 60, 3) + + MUI_FORM(25) + MUI_STYLE(1) + MUI_XYT("ST", 5, 24, "Exit") + MUI_AUX("GG") +; + +int screenshot_n = 0; + +void do_screenshot(void) +{ + char s[4096]; + u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga"); + sprintf( s, + "convert -border 4 -bordercolor 'rgb(255,190,40)'" + " -fill 'rgb(255,170,0)' -opaque white" + " -filter point -resize 200%%" + " screenshot.tga pic%04d.png", screenshot_n); + system(s); + screenshot_n++; + /* + gif animation: + convert -delay 40 -loop 0 pic*.png animation.gif + */ +} + +void clearFormPositionCache( mui_t *mui, uint8_t form_id ) +{ + uint8_t i; + for( i = 0; i < MUI_MENU_CACHE_CNT; i++ ) + if ( mui->menu_form_id[i] == form_id ) + mui->menu_form_cursor_focus_position[i] = 0; +} + +int main(void) +{ + int x, y; + int k; + + + u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); + u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); + u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); + + u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */ + + u8g2_SetFont(&u8g2, u8g2_font_6x10_tr); + u8g2_SetFontMode(&u8g2, 1); + mui_Init(&ui, &u8g2, fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t)); + mui_GotoForm(&ui, 1, 0); + + + x = 4; // use as height for the box + y = 0; + + for(;;) + { + u8g2_SetFontRefHeightExtendedText(&u8g2); + u8g2_FirstPage(&u8g2); + do + { + mui_Draw(&ui); + } while( u8g2_NextPage(&u8g2) ); + do_screenshot(); + + // printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui)); + + do + { + k = u8g_sdl_get_key(); + } while( k < 0 ); + + if ( k == 273 ) y -= 1; + if ( k == 274 ) y += 1; + if ( k == 276 ) x -= 1; + if ( k == 275 ) x += 1; + + /* + if ( k == 'e' ) y -= 1; + if ( k == 'x' ) y += 1; + if ( k == 's' ) x -= 1; + if ( k == 'd' ) x += 1; + */ + + if ( k == 'q' ) break; + + if ( k == 'n' ) + { + mui_NextField(&ui); + } + if ( k == 'p' ) + { + mui_PrevField(&ui); + } + if ( k == 's' ) + { + clearFormPositionCache( &ui, 11 ); + mui_SendSelect(&ui); + } + + if ( k == 't' ) + { + puts("screenshot"); + do_screenshot(); + } + + if ( x < 0 ) + x = 0; + + } + return 0; +} + diff --git a/tools/codebuild/codebuild.c b/tools/codebuild/codebuild.c index d002a801..07353064 100644 --- a/tools/codebuild/codebuild.c +++ b/tools/codebuild/codebuild.c @@ -1519,6 +1519,23 @@ struct controller controller_list[] = } }, + { + "st7567", 12, 9, "u8g2_ll_hvline_vertical_top_lsb", "u8x8_cad_001", "", COM_4WSPI|COM_3WSPI|COM_6800|COM_8080, + "", /* is_generate_u8g2_class= */ 1, + { + { "96x65" }, + { NULL } + } + }, + { + "st7567", 12, 9, "u8g2_ll_hvline_vertical_top_lsb", "u8x8_cad_ssd13xx_fast_i2c", "i2c", COM_I2C, + "", /* is_generate_u8g2_class= */ 1, + { + { "96x65" }, + { NULL } + } + }, + { "st7567", 16, 4, "u8g2_ll_hvline_vertical_top_lsb", "u8x8_cad_001", "", COM_4WSPI|COM_3WSPI|COM_6800|COM_8080, "", /* is_generate_u8g2_class= */ 1,