qbancoffee / imac_g3_ivad_board_init

iMac G3 IVAD board initialization with an arduino
GNU Lesser General Public License v3.0
144 stars 14 forks source link

Consider sending EDID in bursts instead of patching Wire library? #11

Open shuuryou opened 2 years ago

shuuryou commented 2 years ago

Hello

To make the sketch work in its current state the Wire library needs to be patched in two locations so its buffer size is 128 instead of 32.

I am curious as to why you decided to go with that approach. Did sending the EDID in bursts not work?

e.g. like this (totally untested pseudocode)

/* somewhere in the global scope */ 
// Default buffer size of unpatched Wire library
#define TWI_BUFSIZE 32

#define EDID_LENGTH 128
// (or like this, GCC is hopefully smart enough to optimize it into a constant)
// int EDID_LENGTH = sizeof(edid) / sizeof(byte);

byte edid_chunk_buf[TWI_BUFSIZE];

/* where the EDID is sent to the controlling PC */
int i;
for (i=0;i<EDID_LENGTH;i++)
{
  if (i!=0&&i%TWI_BUFSIZE==0)
    Wire.write(edid_chunk_buf, TWI_BUFSIZE);

  edid_chunk_buf[i%TWI_BUFSIZE] = edid[i];
}

// next 2 lines not really necessary if EDID_LENGTH is always a multiple of TWI_BUFSIZE
if ((TWI_BUFSIZE-i%TWI_BUFSIZE)!=0)
  Wire.write(edid_chunk_buf, (TWI_BUFSIZE-i%TWI_BUFSIZE));

I am currently (again, after destroying the first one last year) trying stuff with an eMac and building on the foundations you painfully figured out for that heavy monster. But since your iMac sketch is the pretty one I thought I'd file this here.

The real pain with the eMac is finding a HDMI>VGA adapter that will attempt to do the insane refresh rates on lower resolutions. That's a different story though.

qbancoffee commented 2 years ago

Hello,

Yes, I tried sending it in bursts and sometimes it would work but I had many many issues with HDMI to VGA adapters. In the end it was not very reliable so I decided to patch the wire library. I know it isn't the cleanest but until I figure out a more reliable way of doing it, I need something reproducible.

The eMac was my first conversion and it is one I need to revisit. I had to take a break from most of the stuff I was doing with these projects but I'm planning on revisiting the eMac project to make it as doable as the iMac one.

shuuryou commented 2 years ago

I'm ashamed to say that I had the same results as you, unfortunately. :(

I also gave up (for now) and went with this:

#if BUFFER_LENGTH < EMAC_EDID_BIN_LEN
#error Must patch the Wire library to send EDID correctly.
#endif

BUFFER_LENGTH is in Wire.h or TWI.h; I forget which. But it stops the compile if the library isn't patched.

Same issue with HDMI to VGA adapters. I got a used HDF1 Nano GX which won't pass through my EDID but will at least do the insane refresh rates without crapping out.

I have a Sketch for the eMac and a very crude "GUI" ready. I will put it in my emac repo soon. I also brought the iMac G3 VGA thread on forums.macrumors.com back from the dead.

qbancoffee commented 2 years ago

Well, I know there's some general handshaking with the HDMI to VGA that I can't figure out and I think it's erratic because of the limited memory on these devices. I can hard code sending burst EDID and it works on a per converter basis not a good general solution....

I can't wait to see your GUI, it will be a great addition! I have some projects lined up that I need to finish but the emac is definitely one project I really want to revisit.