Shop Learn P1 Docs P2 Docs Events
LCD Graphics/Text Driver for cheap SPI LCD's with optional Touch screen support - Page 4 — Parallax Forums

LCD Graphics/Text Driver for cheap SPI LCD's with optional Touch screen support

124»

Comments

  • @ManAtWork said:

    I also planned to provide larger fonts. But instead of scaling the 8x8 font up I'd rather use the 32x32 font from the P1 ROM and scale it down.

    >

    That's great. I'm looking forward to test it when it is implemented, it would benefit my UI framework with a better looking font.

  • I just looked at the code. Uaagghh! The fonts use a very strange format of reverse packed bits and the code to extract that into pixels looks weired. I think the reason for this was that the original driver by Cluso placed the font data in cog RAM where there was very little space and it wasn't adressable as single bytes but longword-only. I moved the font data to hub RAM which is byte-adressable and there's a lot more space so we can get rid of that ugly format and store the pixels in their natural order.

    Speed is also no concern because the scaling doesn't have to be done in real time. I would pre-calculate the font in the desired size and then let the driver just copy it from the memory image. This takes a bit more RAM but it shouldn't be a problem unless you need more than, say, 2 or 3 different font sizes at once.

    Will take some time, though to update the code...

  • Ok, I figured it out and re-ordered the bytes in the 6x8 and 8x8 fonts. It now looks like this

      byte %00000000  '\ $41 A   ........
      byte %00011000  '|         ...**...
      byte %00111100  '|         ..****..
      byte %01100110  '|         .**..**.
      byte %01100110  '|         .**..**.
      byte %01111110  '|         .******.
      byte %01100110  '|         .**..**.
      byte %00000000  '/         ........
    

    instead of

      byte %01100110  '\ $41 A   ........
      byte %00111100  '|         ...**...
      byte %00011000  '|         ..****..
      byte %00000000  '|         .**..**.
      byte %00000000  '|         .**..**.
      byte %01100110  '|         .******.
      byte %01111110  '|         .**..**.
      byte %01100110  '/         ........
    

    The driver should now theoretically work with any font size but I still have to implement the actual scaling.

  • I somehow remember there was a trick to use the P1 font as 2 o 4 bit color, that was the reason for the original font order.

    Mike

  • Yeah, success!

    @msrobots said:
    I somehow remember there was a trick to use the P1 font as 2 o 4 bit color, that was the reason for the original font order.

    The P1 had the pixels of an even/odd character pair interleaved for that reason. But that has nothing to do with Roger's packed format where the 6x8 font used one and a half longword in cog RAM per character with the byte order swapped.

  • looks great

  • If anyone want to try, here is the preliminary source code. If it works I'll put it on OBEX/GITHUB.

    Depending on the requirements either LCD_FixedFont.spin2 or LCD_VarSizeFont.spin2 can be included, see Demo for an example. You can change the font at any time by calling lcd.SetFont().

    Generating the 12x16 font out of the 16x16 image takes ~70ms in Spin. I think that could be sped up by a factor of 10 if optimized in PASM but as it's only required once at startup it doesn't really matter.

  • Excellent! Will try soon enough. Thanks

  • @ManAtWork said:
    If anyone want to try, here is the preliminary source code. If it works I'll put it on OBEX/GITHUB.

    Depending on the requirements either LCD_FixedFont.spin2 or LCD_VarSizeFont.spin2 can be included, see Demo for an example. You can change the font at any time by calling lcd.SetFont().

    Generating the 12x16 font out of the 16x16 image takes ~70ms in Spin. I think that could be sped up by a factor of 10 if optimized in PASM but as it's only required once at startup it doesn't really matter.

    Fantastic job! Thank you for the update to the driver. Also thank you for providing a way to set the pins through SetLcdPins and SetTouchPins.

  • Thanks. There may be some cosmetic optimizations to be done. I decided to use a 16x16 image as base for all variable size fonts. The original 16x32 from the P1 ROM would probably be better but would use more memory. Cutting it in half causes aliasing, for example the upper horizontal line of the "E" is thinner than the middle and lower lines. That could be fixed by a more clever anti-aliasing scaling or simply manual pixel painting in the 16x16 source.

  • @ManAtWork Here is a test video of the driver with my framework:

Sign In or Register to comment.