Custom LedMatrix problem displaying text

I have built a custom LED matrix consisting of 5 modules, each with an 8x8 LED grid, resulting in a total resolution of 8x40 (height x width). I wrote a test script that displays squares on the matrix. This test confirms that the physical positions of the modules and the pixel mapping are accurate.

light:
  - platform: neopixelbus
    id: led_matrix_light
    type: GRB
    variant: WS2811
    pin: GPIO4
    num_leds: 320 
    name: "NeoPixel Light"
    color_correct: [20%, 20%, 20%]

display:
  - platform: addressable_light
    id: led_matrix_display
    addressable_light_id: led_matrix_light
    width: 40 
    height: 8 
    pixel_mapper: |-
      if (x / 8 % 2 == 0) {
        return x * 8 + y;
      }
      return (x + 1) * 8 - y - 1;
    rotation: 0°
    update_interval: 16ms
    lambda: |-
          // Draw a pattern for 40x8 matrix
          Color red = Color(0xFF0000);
          Color green = Color(0x00FF00);
          Color blue = Color(0x0000FF);
          it.rectangle(0, 0, 40, 8, red);  // Full outer rectangle
          it.rectangle(4, 1, 32, 6, green); // Inner rectangle
          it.rectangle(8, 2, 24, 4, blue);  // Smaller inner rectangle
          it.rectangle(12, 3, 16, 2, red);   // Smallest inner rectangle

font:
  - file: "fonts/PixelOperatorMono8.ttf"
    id: my_font
    size: 8

When I modified the code to display text instead of squares, something unexpected happened. The test was to display the text “aaaaa” across the matrix. However, I noticed that the first, third, and fifth “a” were flipped vertically, while the second and fourth “a” displayed correctly.

Can you believe it? It seems like there’s an issue with how the text is being mapped or rendered on the matrix.

lambda: |-
      it.fill(Color(0x000000));
      it.print(0, 0, id(my_font), Color(0xFFFFFF), TextAlign::TOP_LEFT, "aaaaa");

Then you have options of turning them physically or finding correct pixel_mapper.

Thank you for taking the time to respond. I agree that the issue lies with the pixel mapper. However, the real value lies in finding the solution. Physically rotating the matrix doesn’t make sense, as the “a” is flipped vertically, like in a mirror, rather than being rotated.

I had the same issue with waveshare ESP32-S3 matrix display.
The codes I could find had the wrong pixel mapper.

I used this on my 8x8 displays:

    pixel_mapper: |-
      return (x ) + (y*8);