olikraus / u8g2

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

New display st7571 128x128 with 3 wire SPI #2460

Open bnv12345 opened 2 weeks ago

bnv12345 commented 2 weeks ago

Hello. I bought this display from the Chinese.

1 2 3

Added a couple of lines of code to the file - u8x8_d_st7571.c

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) );                                          // Set Column Address (MSB) 
  u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));                                         // Set Column Address (LSB) 
  u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));                // Set Page Address

  u8x8_cad_SendCmd(u8x8, 0x0E8);                                                    // Set Display Data Length (DDL) command - 11101000 
  u8x8_cad_SendCmd(u8x8, 0x080);                                                    // Display Data Length (bytes) - 128

  do
  {
    c = ((u8x8_tile_t *)arg_ptr)->cnt;
    ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
    /* SendData can not handle more than 255 bytes */
/*
    if ( c > 31 )
    {
      u8x8_cad_SendData(u8x8, 31*8, ptr); 
      ptr+=31*8;
      c -= 31;
    }
*/

    u8x8_cad_SendData(u8x8, c*8, ptr);  
    arg_int--;
  } while( arg_int > 0 );

  u8x8_cad_EndTransfer(u8x8);
  break;

I added these two lines: u8x8_cad_SendCmd(u8x8, 0x0E8); // Set Display Data Length (DDL) command - 11101000 u8x8_cad_SendCmd(u8x8, 0x080); // Display Data Length (bytes) - 128

Everything worked great IMG_20240617_181638 Can you add a constructor under this display? I think it should look like this: U8G2_ST7571_128X128_F_3W_HW_SPI u8g2(U8G2_R0, / cs=/ 10, / reset=/ 8);

olikraus commented 1 week ago

Which constructor did you use as a starting point?

bnv12345 commented 1 week ago

U8G2_ST7571_128X128_F_4W_HW_SPI

olikraus commented 1 week ago

Hmm.. looks difficult. The E8 command changes the data length in 3-wire mode. However, the 3-wire mode is just the same as the 4-wire mode, except that the data transfer is prefixed by the E8 command. The argument to the E8 must not be constant (as in your example) but instead it should be calculated based on the current values c and arg_int (otherwise it will not work in u8x8 mode).

Additionally as you pointed out, it should be called 3W_SPI, but actually the 3W SPI protocol is very much different. I think I need to look more deeper into this.

bnv12345 commented 1 week ago

Yes, I didn’t even think about the u8x8 mode.

olikraus commented 1 week ago

Note to myself: We need a new 3W CAD procedure and a new interface for the code generator, the above command should be sent in the CAD procedure.