bitfixer / esp32s3vga

A VGA output driver for the ESP32S3
GNU General Public License v3.0
13 stars 2 forks source link

full example possibly arduino #2

Open davidos81 opened 11 months ago

davidos81 commented 11 months ago

This is incredible ! Well done bitfixer !!

Could you please include this with an arduino example , as it much easier for noobs ( like me ) to experiment with...

Thanks in advance !

BrainBoardz commented 8 months ago

Amazing work on getting VGA working and also getting semaphores working bitfixer. Fun times!

I second the Arduino request if it is doable! It could certainly be very useful as there are boatloads of libraries for Arduino that provide support for SD cards, I2S audio with MP3 and so on. FabGL style libraries essentially. I'm sure that this functionality could also be achieved using the VS Code/ESP IDF method, but this is pretty challenging for us less experienced coders.

One thing I can't find a definition of what GPIO pins are assigned to what color channels in the codebase. I watched the video repeatedly and can determine the 3 bit GPIOs from that, but not the 8 bit mode GPIO assignments. That info would be really helpful if it was included as comments in the code.

davidos81 commented 8 months ago

hi brainboardz!

the pin defines are at the beginning of the VGA.cpp look here...

// default pin values chosen to avoid conflicting with spi, i2c, or serial.

#define VGA_PIN_NUM_HSYNC          12
#define VGA_PIN_NUM_VSYNC          13
#define VGA_PIN_NUM_DE             -1

// note: PCLK pin is not needed for VGA output.
// however, the current version of the esp lcd rgb driver requires this to be set
// to keep this pin unused and available for something else, you need a patched version
// of the driver (for now)
#if PATCHED_LCD_DRIVER
#define VGA_PIN_NUM_PCLK           -1
#else
#define VGA_PIN_NUM_PCLK           21
#endif
************************************************************************************************
THE DEFINES BELOW ARE FOR THE RGB & REMEMBER ITS 8 BIT COLOR RGB 332 
************************************************************************************************
#define VGA_PIN_NUM_DATA0          1
#define VGA_PIN_NUM_DATA1          2
#define VGA_PIN_NUM_DATA2          3
#define VGA_PIN_NUM_DATA3          4
#define VGA_PIN_NUM_DATA4          5
#define VGA_PIN_NUM_DATA5          16
#define VGA_PIN_NUM_DATA6          15
#define VGA_PIN_NUM_DATA7          14
***************************************************************************************************
#define VGA_PIN_NUM_DISP_EN        -1
BrainBoardz commented 8 months ago

Thanks. I did see that. But, I'm not sure if VGA_PIN_NUM_DATA3 is for Red, Green or Blue for example. A schematic would help.

davidos81 commented 8 months ago

i have not tried this library myself , my guess is stand 8bit color is as follows :


RRRGGGBB < 3bits RED , 3bits GREEN , 2bits BLUE
--------
01234567 < pins data0 thru 7

like i said not tried it , but it might also be the reverse order BBGGGRRR
BrainBoardz commented 8 months ago

Thanks! RRRGGGBB makes sense as the Blue channel does require fewer pins for 8 bit modes. I'll give that (and the reverse if necessary) a go.

I'm sure I'm going to have to define and test extra pins for my board with this library as it does not currently allocate for the higher res modes (based on the 8MB Octal PSRAM ESP32 bitluni used and on which my test board is based). There is something to be said for getting VGA working on lower spec ESP32S3's as these are no doubt very common (so this code opens up VGA output to more S3's) and it frees up unused pins for other purposes, but the higher res/color modes are very tempting. I'm not sure if even an Octal RAM equipped S3 can cope with a bunch of other activities going on in conjunction with the higher res/color depth (say 800x600 16 bit) VGA activity without completely trashing frame rates, but I'd like to see what is possible. This library looks well suited to test the limits and maybe get some peripherals involved along the way! I can say it is mind blowing that so much VGA goodness can be squeezed out of an ESP32S3!

davidos81 commented 8 months ago

you can do the same stuff with bitluni's s3vga library , some say its better , I am not sure as I have not tested both (yet) but I do know it works very well (now) out of the box with arduino , something that this library lacks support for.

bitfixer commented 8 months ago

Hi, sorry for the delayed reply. Thanks for checking out the library. I'll post a schematic for the VGA breakout board I made shortly. It does use 2 of the bits for blue, 3 each for red, I'll check on the order I used. The order and bit allocation is pretty much arbitrary, but I was using the adafruit drawing library which had a specific order.

On Mon, Oct 16, 2023 at 3:54 PM davidos81 @.***> wrote:

you can do the same stuff with bitluni's s3vga library , some say its better , I am not sure as I have not tested both (yet) but I do know it works very well (now) out of the box with arduino , something that this library lacks support for.

— Reply to this email directly, view it on GitHub https://github.com/bitfixer/esp32s3vga/issues/2#issuecomment-1765393820, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANYKOPBAOHFVKUQV2T5PK3X7W3LPAVCNFSM6AAAAAA3EYTCCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRVGM4TGOBSGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

davidos81 commented 8 months ago

@bitfixer can you please provide a very simple example for us arduino diehards that don't fully know how to use idf...

cheers!

BrainBoardz commented 8 months ago

Hi bitfixer:

That's great news about posting a schematic. Much appreciated!

BrainBoardz commented 8 months ago

Hi davidos81:

I have been experimenting with bitluni's library. I actually designed a prototype VGA board based on his resistor ladder etc. It was just the VGA element (that uses loads of the ESP32S3 pins and lots of resistors) and a header for the remaining pins to test out other modules. It worked perfectly with bitluni's code right from the get go. I have another dev board on the way that adds an I2S audio output, PS/2 ports and a USB (host) connection. I'm not sure if any or all of these additions will work, but I remain optimistic! The expanded board is due to arrive any day now. The big challenge with bitluni's approach is the very limited number of free pins left over after the full VGA ladder is implemented. I used basically all of the remaining S3 pins and even had to use the TX/RX pins and some strapping pins to eek out every last bit of I/O. I went all-in on that design basically. I am going to be posting my results once I've tested everything.

It is really nice to have bitluni's Arduino code . Can't say I have pushed his library much, but I did manage to get the Adafruit GFX and basic VGA color bar demo working on the Dev board. He has been improving the documentation as well. As far as I can tell bitluni's library is more about showing what the ESP32S3 (NR8/8 specifically) is capable of generating (which is amazing BTW), while bitfixer implemented a more efficient library that supports a wider range of S3 modules, albeit at lower resolutions and color depths.

davidos81 commented 8 months ago

@BrainBoardz your expanded board is really interesting !

Will you be selling populated boards , and uploading schematic any time soon , I (like a few others) would love to experiment with the possibilities it offers..!

cheers

BrainBoardz commented 8 months ago

Hi davidos81:

Absolutely, that is the plan. I will be uploading the schematic to my repository once I have confirmed everything works. Both of my dev boards utilize my ESP32S3 NR8/8 Neuron module, but they I think the approach could be easily adapted to other modules (or an on-the-board S3) assuming that all of the ESP32S3 pins are broken out. I'm a pretty terrible coder, so if I can provide a board that enables way more adept coders to develop extra functionality I'm all for that! I think the ideal would be a FabGL style library for ESP32S3's. With support for I2S, USB joysticks, SD cards and so on. It's early days for that, but I can see the potential for some really fun projects.

bitfixer commented 8 months ago

Hi, I uploaded the schematic for my small VGA breakout board here: http://bitfixer.com/tmp/bitfixer_vga_breakout.pdf

This has separate inputs for 8-bit and 3-bit color, not intended to be used simultaneously. It uses a simple resistor ladder to convert D->A and get analog signals for R,G,B. Also checked and the 8-bit mode is (starting with MSB) BBBGGRRR. Although this is entirely dependent on how you decide to draw things into memory. I'm using a slightly hacked up version of the adafruit graphics library, which uses this layout. I haven't looked much at bitluni's library, but as mentioned it does support higher bit depth and resolution. This code was primarily put together to just be a display for a "retrocomputer" so I was not that concerned with pushing the limits. Mainly I focused on achieving as close to 30FPS as possible with drawing a full image every frame. You could certainly achieve faster frame rates if you don't update the whole frame every cycle but this was conceptually simple to me so that's how I went about it. The real bottleneck is the speed of the SPIRAM. I'll look at including an arduino example. I will say that the last few projects I've had on the ESP32 or S3 started out arduino and for all of them I've ended up having to de-arduinoize them due to limitations in the library. GPIO latency, to name one - accessing or writing to pins is much slower using arduino than idf directly. But depends on your needs.

On Wed, Oct 18, 2023 at 8:05 AM Jeremy Littler @.***> wrote:

Hi davidos81:

Absolutely, that is the plan. I will be uploading the schematic to my repository once I have confirmed everything works. Both of my dev boards utilize my ESP32S3 NR8/8 Neuron module, but they I think the approach could be easily adapted to other modules (or an on-the-board S3) assuming that all of the ESP32S3 pins are broken out. I'm a pretty terrible coder, so if I can provide a board that enables way more adept coders to develop extra functionality I'm all for that! I think the ideal would be a FabGL style library for ESP32S3's. With support for I2S, USB joysticks, SD cards and so on. It's early days for that, but I can see the potential for some really fun projects.

— Reply to this email directly, view it on GitHub https://github.com/bitfixer/esp32s3vga/issues/2#issuecomment-1768663784, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANYKOMAWHNIKET7HSJYZ6DX77V3HAVCNFSM6AAAAAA3EYTCCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRYGY3DGNZYGQ . You are receiving this because you were mentioned.Message ID: @.***>

BrainBoardz commented 8 months ago

Hi bitfixer:

That's great. Thanks for the schematic and clarification on the 8-bit mode. The approach taken makes total sense given the fps and the "retrocomputer" focus. 30fps would indeed be impressive and keeping things to 8 bit does keep the pin count very manageable as well. I'm just starting to dig into the IDF, but will also happily look at using code for that and Arduino code if you deem it to be useable.

I've been looking at 16:9 modes as 4:3 monitors just aren't as common as they once were. On that note, I did some tests with a low cost VGA to HDMI converter from Ali and both 800x600 and my slightly hacked widescreen resolutions worked really well with that hardware. This broadens the number of compatible screens. The converted output was even better than I expected. 16:9 probably isn't appropriate for the vast majority of "retrogames", but I think 16:9 could be useful for some scenarios (data display situations and signage in particular). In terms of 16:9 I've been focusing mostly on 854 X 480 (FWVGA). If it's ok I'd like to see if I can build a prototype based on your schematic to test resolutions out. I may even try adding I2S audio support and perhaps some other peripherals into the mix. After such a long wait for S3 VGA support it's really exciting to see two VGA libraries being developed!

bitfixer commented 8 months ago

Sounds great, I'll try to get an additional schematic up showing the rest of the system - the S3 connected up to VGA as well as USB for the keyboard. It might take me a bit longer to get an arduino example up, but I can certainly provide a full idf example showing a demo using this vga driver as an idf component. Hopefully that helps! Also my mistake earlier about the color allocation for 8-bit VGA, looks like it is actually RRRGGGBB (MSB->LSB).

On Wed, Oct 18, 2023 at 10:43 AM Jeremy Littler @.***> wrote:

Hi bitfixer:

That's great. Thanks for the schematic and clarification on the 8-bit mode. The approach taken makes total sense given the fps and the "retrocomputer" focus. 30fps would indeed be impressive and keeping things to 8 bit does keep the pin count very manageable as well. I'm just starting to dig into the IDF, but will also happily look at using code for that and Arduino code if you deem it to be useable.

I've been looking at 16:9 modes as 4:3 monitors just aren't as common as they once were. On that note, I did some tests with a low cost VGA to HDMI converter from Ali and both 800x600 and my slightly hacked widescreen resolutions worked really well with that hardware. This broadens the number of compatible screens. The converted output was even better than I expected. 16:9 probably isn't appropriate for the vast majority of "retrogames", but I think 16:9 could be useful for some scenarios (data display situations and signage in particular). In terms of 16:9 I've been focusing mostly on 854 X 480 (FWVGA). If it's ok I'd like to see if I can build a prototype based on your schematic to test resolutions out. I may even try adding I2S audio support and perhaps some other peripherals into the mix. After such a long wait for S3 VGA support it's really exciting to see two VGA libraries being developed!

— Reply to this email directly, view it on GitHub https://github.com/bitfixer/esp32s3vga/issues/2#issuecomment-1769036963, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANYKOIWWOV5VQ5R2XQF44LYAAIKZAVCNFSM6AAAAAA3EYTCCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRZGAZTMOJWGM . You are receiving this because you were mentioned.Message ID: @.***>

BrainBoardz commented 8 months ago

Thanks for the clarification on the 8 bit allocation. An idf example would be really useful! On my prototype I allocated GPIO 19 and 20 (D-/D+) for either programming the esp (OTG basically) or as the usb host for a gamepad. My ESP32S3 board does not use UARTs, so I assigned them to one of the 2 PS/2 support channels. I didn't include a mode switch for the 2 USB modes, but I may add that in a board update as I am pretty sure that trying to program the board while also having a gamepad attached is not going to work out well. I also allocated GPIO 45, 46 and 48 to an I2S audio circuit (ended up designing my DAC based on a PCM5102). I was able to verify those pins work using my test VGA board, whether the custom DAC will is TBD. I should know by early next week if this all the peripherals work! If the do I'm going to create a repository for the project and post it. I'll update this thread when I have checked everything out. I'd rather not post anything it until I am completely confident the various components work as I really pushed the envelope on this one.

davidos81 commented 8 months ago

@BrainBoardz brilliant!!

just out of curiosity ... how are you implementing the USB gamepad ? What drivers / program will you use etc ?

I did try the wch ch559 after some great youtube videos using with older esp32 , However my finding were disappointing , Attaching gamepads never worked , mice and keyboard were patchy , some worked then stopped and other not at all.

Then I realized the drivers were out of date by about 5 years , no one on github showed any interest in updating the code - even the original authors never bothered past the inital codebase.No wonder it was so buggy.

I left it as I did have not expertise to write my own driver

So just like you , I am implementing the mouse and keyboard using PS/2 , There are some very good libraries , and they work very well , But , I am stuck with how to implement the gamepad part...

BrainBoardz commented 8 months ago

Hi davidos81:

That port was a last minute addition to the board. The primary reason for adding this USB connector was to test providing power for VGA to HDMI converters. I did think that I might be able to get a gamepad working in ESP32S3 USB Host mode or even using tobozo's soft host USB library (maybe even bitbanging?) or any library I can find. But yes, this was certainly a TBD thing. I wasn't overly focused on a specific library or method as I knew it was possible to get a PS2 controller working over Bluetooth. So that is a fallback for using joysticks. I am probably going to switch this port to power delivery on Rev 2 if the Gamepad thing is a bust, after I have ensured the power draw of the converters can be handled comfortably by my voltage regulator!

I did look at the CH559 as well, but I wasn't confident it would be reliable and the programming it looked daunting. I've used WCH UARTs before and they worked fine, but, I am not a fan of relying on a sole source chip. So many chips go out of production these days. That's actually been a big issue with the DAC, as most of these are now out of production. I was able to find one eventually (the PCM5102), but it was pretty much Max98357's and I needed a line level outputs for the HDMI converter.

Based on your experience, I guess was right about avoiding it . I have actually mulled with the idea of adding a second microcontroller. The idea was to use an STM32 or similar (blue pill style to keep things as simple and inexpensive as possible). A second microcontroller would provide lots of additional IO potentially, but there are extremely limited pins left on the ESP32 to connect to any other microcontroller if you are using bitluni's VGA design. I think it might be possible to get one wire or maybe I2C going though. I had though about SPI and I didn't want to tie SPI up as the SD card is using that and it could be very busy streaming files to the DAC etc.

davidos81 commented 8 months ago

regards the VGA > HDMI , what chip are you using ? or like me , its a cheap aliexpress unit (the ones that sell for about 4-5 US dollars)

another option I had in mind for the USB GAMEPAD was to use RP2040 , this has excellent USB support and is a very cheap microcontroller (and fast ) , you can communicate using uart too . Programming is quite easy as its an ARM based system , with very good documentation.

So the graphics and sound etc are on the ESP32 S3 , other stuff on the RP2040... Mind you , the RP2040 has a very capable IO subsystem called PIO and that too can generate VGA and a whole lot more , fairly easily...!

BrainBoardz commented 8 months ago

I didn't use a chip. I also went the Aliexpress route. It was from WvvMvv (nice name BTW) and cost something around $5.00. I'm sure many others would work, but that is one I bought to test and it works really well. Not fussy about frequencies and the conversion is really clean. It also has audio to HDMI support. Hence my feverish DAC work. No sound is no fun. There is a post on bitluni's VGA project about someone with a VGA to HDMI system that uses an an FPGA, but I these always seem to end up being rather expensive. Makes you wonder if you could not just cut out the VGA connector completely and wire a converter board directly on the board (Hmmm). A module perhaps?

The RP2040 is a really excellent idea. I like it. If memory serves me you have to overclock it to get higher resolutions in VGA, but that PIO element was really a stroke of brilliance on RPF's part. A combined ESP32S3 + Pico2040 would be a really neat package. Maybe offloading Bluetooth/wireless and VGA to the S3 and letting the PI do the rest. The PIO could even be used as the DAC potentially. That would reduce the cost of implementing a DAC considerably. The lack of an SD Card reader on the RP boards could limit storage, but that could be fixable with a shared SPI bus or something.

davidos81 commented 8 months ago

Great minds think alike - your project is very nearly , exactly what I am working on ! So I will share some thoughts ... VGA > HDMI , I didnt bother with an LDO to power that , most of these custom IC have provision for 3v - 5v , and the fact that it gets power from a 5v proves that (It might have its own LDO though ? ) So mine is powered direct from + - 5v USB. It will always be powered on this way , so if you want a standby mode then a simple GPIO on/off switch circuit will be needed.

BLUETOOTH gamepads , like USB HID gamepads , this is a minefield , There are quite a few libs. for the esp32 , I didnt have one to test but most libraries had people complaining about all sorts of issues. So, I simply used the WIIMOTE for testing and worked well on the ESP32 , Cannot remember if the libs will compile on the ESP32S3. I wont be using wireless for gamepads , I will use the SNES style controllers , these are easy to use , use very few pins (most are shared if you have more than 1 controller ) super easy to program and very cheap to buy from aliexpress !

THE AUDIO DAC , I did not want to use one , like you , I needed line level audio from the esp32 fed into the HDMI line in . As i wanted low res sound , 8bit was fine , I used a simple LED driver and audio quality was excellent (from an esp32 ), done the same with esp32 s3 and ... they changed the LED drivers , The LED circuits cannot be driven as fast as the original esp32 and as such a high pitch audible "whining" can be heard - so forget that !

Next came max98357A, low cost and high quality i2s 16bit audio DAC , However... not line level output . I settled for MAX98357A , albeit , output lower volume audio until i found something more suitable... I will look at the PCM5102

BrainBoardz commented 8 months ago

Hi davidos81:

Sorry, I explained that incorrectly. Sounds like we are actually on the same page. I'm feeding 5V directly from the USB-C connection to a USB-A port to feed the HDMI converter. I'm not sure if the USB on a TV could power the whole thing (seems like 500mA is about it for USB on TV's ). It would be nice if the whole package could be run off just a "TV" USB port. A single USB-C power plug connection should have no trouble powering everything the TV approach does not work. The USB-C provided 5V is actually split off to a 5V to 3.3V LDO to power my ESP32S3 module. I'm not sure how much power the converter + VGA board requires, so I am going to be taking a look at that. I suspect TV USB is probably capable enough to power everything. Would be really nice if it did work.

That's too bad about the "whining" on the S3 LED driver. I wasn't even aware that this approach was even possible! Even if it had some quality limitations, not keeping a built in DAC in the S3 was a very unfortunate decision on Espressif's part IMO. As my DAC circuit is very much TBD at the moment (board is on the delivery truck apparently) I guess the jury is out on how good this will work. I did test some Alii modules that use the PCM5102 and the sound quality was impressive. One thing in the PCM5102's favor is that it supports stereo audio on one chip. I know that you can double up MAX's, but that does add to the complexity/cost. I really like stereo sound! A true combo 3 watt + line level output chip would be super useful, but alas everything I read indicated the Max is not good for line level situations. I did wonder if a Max set to the lowest dB output would work ok with an HDMI converter. Did that work for you?

The wiimote idea is intriguing. I also looked at the SNES as an option and had that in mind for future Rev. That is a good direction to go given the better stability of the approach. I'm going to take a much deeper look at that. Sounds like all of the pieces are falling into place for a very useable S3 VGA board!

davidos81 commented 8 months ago

cheers brainboardz,

as our conversation is getting a bit off topic , is there any way we can continue sharing our ideas through other means - unobtrusive email perhaps ?

BrainBoardz commented 8 months ago

hi davidos81:

I was thinking exactly the same thing! Kind of took over the thread. I'm surprised bitfixer hasn't told us to go away (ha ha). There's a contact form on my website and that is linked on my repository page (I won't advertise it here, but I'm sure you can find it with a quick google search) if you want to send me your contact email. I'll reply with mine and we can go from there. On a very positive note, I did a quick check of the new board and the DAC worked perfectly! Also the VGA and USB-C elements (as I had expected they would, but you never know with a new board). The DAC output was as clean as the Aliexpress PCM5102 test board. I'm super happy about that. Going to start with the PS/2 and USB peripherals over the weekend.