probonopd / MiniDexed

Dexed FM synthesizer similar to 8x DX7 (TX816/TX802) running on a bare metal Raspberry Pi (without a Linux kernel or operating system)
https://github.com/probonopd/MiniDexed/wiki
1.05k stars 76 forks source link

I2C display support #169

Closed Deftaudio closed 2 years ago

Deftaudio commented 2 years ago

Hi, just wondering, what's the current plan on this? I'm willing to further reduce the size of MiniDexed and just limited with parallel LCD options... In particular, OLED 128x32 would be the best.

luisfcorreia commented 2 years ago

my current C++ skils are basicly non existing

user Interface should have two things detached, display and encoder handling

I tried, without success

probonopd commented 2 years ago

i2c display support would need a volunteer to write it. The proper way would be to get those displays supported in Circle, e.g., by upstreaming them from mt32-pi. Once in Circle, we could think about using them in this project.

Deftaudio commented 2 years ago

I see, thanks!

diyelectromusic commented 2 years ago

For info, I've sent in support for the I2C version of the HD44780 so hopefully that will be in the next Circle release.

I have draft support for SSD1306 based displays too based on the driver in MT32-Pi (you can see it in my own branch of circle), but it looks like that is going to open a bit of a wider discussion on how to do graphical displays that will have to wait until after the next release of Circle. To follow the conversation, see https://github.com/rsta2/circle/discussions/296

But in summary, if I can work out how to build MiniDexed myself with my own version of Circle, I might have a go at building a version using a 128x32 ssd1306, which would be nice... but I'm not sure it would be something releasable more widely at present...

Kevin

probonopd commented 2 years ago

Wow, that's quite exciting @diyelectromusic!

Your HD44780 I2C support is on the develop branch in the Circle repo now

Since MiniDexed is using the develop branch of Circle, we should be good to go! We just need to update the revision of the Circle git submodule. How can MiniDexed make use of it?

But in summary, if I can work out how to build MiniDexed myself with my own version of Circle

Which part do you need help with?

diyelectromusic commented 2 years ago

Well to use the I2C hd44780 just use the same initialisation but with I2C instead. There is a new addon/display/sample/hd44780i2c example that shows how (I haven't looked at how MiniDexed does it yet - I'll have a look and see). The SSD1306 in theory would be similar, but as I say that isn't in Circle yet... :)

Which part do you need help with?

I just need a bit of time to sit down and have a go :)

diyelectromusic commented 2 years ago

So I think you need to first create a CI2CMaster object and then pass this into the new HD44780 constructor something like the following:

define I2C_MASTER_DEVICE (CMachineInfo::Get ()->GetDevice (DeviceI2CMaster))

m_pI2CMaster = new CI2CMaster(I2C_MASTER_DEVICE); m_pLCD = new CHD44780Device (&I2CMaster, I2C_ADDR, CConfig::LCDColumns, CConfig::LCDRows);

That kind of thing in userinterface.cpp I guess?

If the SSD1306 support gets include in the same way, then using that should be the same but with CSD1306Device instead... but as I say, that is probably a little way off yet.

probonopd commented 2 years ago

Running into issues:

userinterface.cpp: In member function 'bool CUserInterface::Initialize()':
userinterface.cpp:57:3: error: 'm_pI2CMaster' was not declared in this scope; did you mean 'CI2CMaster'?
   57 |   m_pI2CMaster = new CI2CMaster(I2C_MASTER_DEVICE);
      |   ^~~~~~~~~~~~
      |   CI2CMaster
userinterface.cpp:28:28: error: 'CMachineInfo' has not been declared
   28 | #define I2C_MASTER_DEVICE (CMachineInfo::Get ()->GetDevice (DeviceI2CMaster))
      |                            ^~~~~~~~~~~~
userinterface.cpp:57:33: note: in expansion of macro 'I2C_MASTER_DEVICE'
   57 |   m_pI2CMaster = new CI2CMaster(I2C_MASTER_DEVICE);
      |                                 ^~~~~~~~~~~~~~~~~
userinterface.cpp:28:61: error: 'DeviceI2CMaster' was not declared in this scope
   28 | #define I2C_MASTER_DEVICE (CMachineInfo::Get ()->GetDevice (DeviceI2CMaster))
      |                                                             ^~~~~~~~~~~~~~~
userinterface.cpp:57:33: note: in expansion of macro 'I2C_MASTER_DEVICE'
   57 |   m_pI2CMaster = new CI2CMaster(I2C_MASTER_DEVICE);
      |                                 ^~~~~~~~~~~~~~~~~
userinterface.cpp:58:33: error: 'I2CMaster' was not declared in this scope; did you mean 'CI2CMaster'?
   58 |   m_pLCD = new CHD44780Device (&I2CMaster, CConfig::LCDI2CAddress, CConfig::LCDColumns, CConfig::LCDRows);
      |                                 ^~~~~~~~~
      |                                 CI2CMaster
make: *** [../circle-stdlib/libs/circle/Rules.mk:144: userinterface.o] Error 1
make: *** Waiting for unfinished jobs....
Error: Process completed with exit code 2.

https://github.com/probonopd/MiniDexed/pull/220

diyelectromusic commented 2 years ago

Oh sorry - that wasn't exact code, I've not got a building MiniDexed setup atm, but it is that kind of thing. To start with you'll need to include <circle/i2cmaster.h> somewhere and also <circle/machineinfo.h> and I don't know what strategy you are using for objects - statically created in other objects or dynamically created, but the essence is: Get an CI2CMaster instance; pass this into the HD44780 instance along with the I2C address followed by columns/rows and ignore all the pin definitions. As I say, take a look at the new sample code in addon/display/sample/hd44780i2c

Sorry I don't have the exact code, as I say I don't have a code environment to try it with yet :)

probonopd commented 2 years ago

m_I2CMaster is being set up in

https://github.com/probonopd/MiniDexed/blob/2199208d340f111dfc3a644737d31464ba4308ae/src/kernel.cpp#L33

diyelectromusic commented 2 years ago

That should do then I think? Can you just pass that into the HD44780 constructor?

Hmm... looks like it isn't preserved when creating the MiniDexed object - it is just used temporarily. Somehow that will have to get into the userinterace initialisation...

probonopd commented 2 years ago

I don't have a code environment to try it with yet :)

I used this trick:

https://github.com/probonopd/MiniDexed/blob/52b8900293b4605b9aba7182d2d72fe9f1eb7235/.github/workflows/build.yml#L26-L27

diyelectromusic commented 2 years ago

It looks like it will need to be added to the interface for CUserInterface and then passed in from kernel.c when m_UI is setup in CMiniDexed...?

probonopd commented 2 years ago

Probably. As you have probably guessed by now, C++ is just not how my brain is wired. Do you think you can get it to work?

diyelectromusic commented 2 years ago

Probably. As you have probably guessed by now, C++ is just not how my brain is wired. Do you think you can get it to work?

It will take me a while to get an environment up and running... but I won't really get a chance to have a proper look right away...

I'll see what I can do :)

probonopd commented 2 years ago

It will take me a while to get an environment up and running...

This is the quickest way imho, 3 minutes max:

https://github.com/probonopd/MiniDexed/wiki/Development#developing-in-the-cloud

diyelectromusic commented 2 years ago

This is the quickest way imho, 3 minutes max: I'm having a go. Is there a Ubuntu package for the aarch64 toolchain? There was for the 32-bit one, I could just apt-get install gcc-arm-none-eabi, but I'm not sure what to look for for aarch64... (it seems odd to have to download a .tgz!?)

probonopd commented 2 years ago

This is the official toolchain provided by ARM. I have never tried anyting else. But let me ask, how did you develop support for i2c in Circle without all of this? ;-)

diyelectromusic commented 2 years ago

Ok, I think the initial support could look something like this: https://github.com/diyelectromusic/MiniDexed/commits/hd44780i2c

This requires the latest develop branch of circle (which I haven't included, as I wasn't quite sure what I was doing with submodules in git!). This seems to work for me for both I2C and non-I2C versions of the HD44780. If LCDI2CAddress is set in the minidexed.ini file (default for my module is 0x27) then it will look for an I2C display. If this is missed out (or set to 0 I guess) then it will look for the non-I2C version.

See what you think. Any queries and I'll get back to you tomorrow now.

Kevin

probonopd commented 2 years ago

Thank you very much @diyelectromusic. I have merged your patch and have updated the documentation accordingly. Right now i2c is not yet the default configuration, but possibly we should make it so.

diyelectromusic commented 2 years ago

That's great! :)

diyelectromusic commented 2 years ago

For what it's worth, if you don't mind messing around with github branches, then it is now possible to build a one-off, unsupported (i.e. it won't be maintained) SSD1306 version of MiniDexed... if ssd1306 support ends up in circle proper, then this might make its way over here too.

To do it, you need the changes to MiniDexed from here: https://github.com/diyelectromusic/MiniDexed/tree/ssd1306

And you need to use the version of Circle (as I say, unmaintained), from here: https://github.com/diyelectromusic/circle/tree/ssd1306

Not ideal, I know, but it shows that it is at least possible! Here it is running with my (full) Clumsy MIDI interface. Now I just need a rotary encoder!

The changes to MiniDexed are not the final versions by any stretch - there are a few ugly hacks in there at the moment, but it is a start.

Kevin

IMG_6200

probonopd commented 2 years ago

W00t! This is scary good! :+1: :+1: :+1:

Especially because this might open the path to displaying the opeartors graphically...

craigyjp commented 2 years ago

That would be great, I know one guy on FB that wants to build 8 of these on pi zeros to utilize individual outputs and putting in a 0.96" display will take up less real estate than a standard 1602 LCD.

probonopd commented 2 years ago

8 RPi Zeros. The guy must be rich and should buy a TX816 :-)

diyelectromusic commented 2 years ago

Especially because this might open the path to displaying the opeartors graphically...

Well this is the sticking point in Circle atm and will need some thought, as the HD44780 interface is definitely a "text interface" and that is what I've used here too. In fact in MiniDexed, it makes lots of use of the control sequences for the menus/etc...

There is some simple graphics work in the st7789 display driver, but it is a very different interface to the HD44780.

So, yes and no. I suspect Circle would have to harmonise on a single graphical/LCD API and then you'd need to update those aspects of MiniDexed too... basically, there is still a lot of work :)