OLED with SPD0301 driver

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

OLED with SPD0301 driver

Post by patrick schoon »

Hi All

I have purchased some bigger 1,54" I2C OLED displays from Heltec (heltec.cn).
This display uses a SPD0301 driver.

In the Flowcode I2C Oled macro's dispays are used with SSD1306 and SH1106 drivers.
I use these also... and these are working great.

The SPD0301 controler is not supported yet.
Any change this wil come available soon?

Is the OLED macro source available so I can expand it to SPD0301 as well?

Regards,

Patrick

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: OLED with SPD0301 driver

Post by Benj »

Hi Patrick,

Here's the component source for the SSD1306 so you can see how it's done and have a go.

Please shout if you need any help. Very happy to help if needed if you can test out the code.
glcd_SSD1306_I2C.fcfx
(159.58 KiB) Downloaded 247 times
Also if you get it working then let us know and I can add it to the supported devices list.

patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: OLED with SPD0301 driver

Post by patrick schoon »

Hi Ben,

Great, thanks.

Patrick

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

I'd like to check how the 'component' source allocates memory for the buffers for the display..

These are declared as global dram0..7[128] -> but they don't get allocated if a smaller display is defined..

Incidentally - these would be a candidate for a 2d array (see current thread) - which could aid a speed up (Plot and BPlot could be simplified).

I 'removed' the switch for calculating font size (in Print) and replaced with a lookup table (high order nibble width, low order height) which gave a saving of ~200bytes...

Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: OLED with SPD0301 driver

Post by kersing »

Keep in mind the compiler needs to be able to allocate the entire array in continuous memory. That is easier for multiple smaller arrays...
There might be devices where the XC8 compiler can not allocate arrays > 128 bytes.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

That could be - but 8x128 byte buffers are defined, how are these not declared if, for example, I alter the display size to be 128x16 (a trick I've used to allow use on an ATTiny?)

The ws2812 component certainly 'allocates' bigger chunks (3*leds) but may not work on some MCUs?

Really, I'm interested in how to create a component that allocates memory based on some properties , rather than just allocating a buffer that is 'big enough' for the largest size 'display' allowable. (A problem I never managed to solve with the max7219 component I did some time ago). If FC had a 'pointer' type this could be handled using 'new' - though, as is, it requires quite a bit of extra work at present.

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: OLED with SPD0301 driver

Post by Benj »

Hello,

The Ev_GetVarSize macro allows the variables to dynamically allocate the correct size to match the display resolution.

GetVarSize.jpg
GetVarSize.jpg (51.57 KiB) Viewed 7248 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Thanks Benj,

Not quite sure I see how it works - it doesn't look like it does anything? (if (parameter) variable name[0..3] = 'dram' then set a local variable.....) but I'll have a play and see where it leads.

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: OLED with SPD0301 driver

Post by Benj »

Hi Martin,

The Event macros are fairly mysterious and advanced, I'm not sure I understand them all :D .

The event when enabled gets called for every array type global variable in the component and the Elements parameter contains the number of elements in the array. By writing to the parameter it is possible to override the size of the array in the generated C code.

Note I believe this event only works once you export the code as a component, though I could be wrong on this.

The AddVar event is similar but allows variable code generation to be switched off or completely overridden for specific variables allowing for say a long variable to be converted to a unsigned int or byte as necessary to maintain efficiency.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Thanks,
This is an area that would be made much simpler by use of new?

So in this case Initialize would allocate memory:
for pages
dram[page]=new(128).
(Or dram = new(pages*128))


an alternative
Use dram[pages*128]. - are there instances where d1[128] ... Dn[128] would work and d[pages*128] will fail???

I started thinking a dynamic memory component could work (so handle allocation, freeing and access routines)) - are there compilers that don't support new?

If using an integer as a ' pointer' how would you select the size (8,16,32 bit) needed - could this be pulled from the mcu definition (ram size ??)

Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: OLED with SPD0301 driver

Post by kersing »

New is not part of C. In plain C you use things like malloc/free, however these rely on a library that provides memory management which is not present in small controllers. (That memory management library would be required for new/delete as well)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Hi,

Yes, been playing with c++ a lot lately.. I did a linked list example for Arduino using malloc a while ago..

Any ideas how many compilers would not support malloc/calloc? - GCC for avr it seems to work. Maybe xc8 it doesn't?

Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: OLED with SPD0301 driver

Post by kersing »

Malloc/free are part of a library. Having them available is a luxury, not a given in my experience. Memory management functions use memory themselves in runtime overhead (ram use for the administration) and code overhead (flash). So small platforms usually don’t offer them.
Check https://microchipdeveloper.com/faq:15 for xc8 information.

Does gcc provide it for all AVR chips or just the more capable (arm) cores?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Certainly works on 328p - there is some overhead (two bytes size I think but mcu dependent (32bit?)) per allocation - we only do one (or a few - this would be acceptable) freeing memory is less likely to occur in an embedded environment.
Here's the demo I did: https://matrixtsl.com/mmforums/viewtopi ... lit=Linked

Not sure what the malloc overhead would be for eeprom usage - but pretty lightweight at a guess.

In this instance, it would be easy enough to have buf[n*128] and calculate an address - but again is this going to cause a problem ( works on AVR (ram permitting)) but maybe problems under other tool chains? I was trying to ascertain how to modify the library to allocate the required space (perhaps a peek at the ws2812 component would help) as a single buffer..

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: OLED with SPD0301 driver

Post by Benj »

WS2812 is a bit more complex as its a multi dimension array. So this time we use the Ev_AddVar event macro and override the code generation.

WS2812.jpg
WS2812.jpg (51.7 KiB) Viewed 7121 times
The code check to see if the variable to add is called RGB. If it is then we take the first characters from the code generation minus the last 12 characters.

"MX_GLOBAL MX_UINT8 FCV_06621_LED_WS2811__RGB[32768][3];\n"

would become

"MX_GLOBAL MX_UINT8 FCV_06621_LED_WS2811__RGB"

Then add to that "[" + LED_Count + "][3];\n"

So for a LED_Count of 9 we end up with this.

"MX_GLOBAL MX_UINT8 FCV_06621_LED_WS2811__RGB[9][3];\n"

The Return 1 allows the variable to be added to the C code, returning 0 would remove the variable from the C code.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Thanks Ben,

There's a lot going on behind the scenes.... A lot to learn!

Another (related) question - I used a global variable in some C - this worked AOK in a standalone program, but was name mangled (the global not the C) in a component, giving compilation errors. I just moved it to FC (where it belonged) - but what is the correct way to handle this situation?

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: OLED with SPD0301 driver

Post by Benj »

Hi Martin,

A couple of options here.

The easy option is to stop Flowcode from adding all the various stuff to the variable name using the AddVar event to clean up the variable name, and this will let your keep your original variable name. The downside to this being if 1) the component can be used more than once in a project or 2) the user happens to be using that variable name in their project.

Another way to do it is via a property or definition maybe including the component instance number to keep things unique, this is a bit more involved but I can probably throw together an example for you if your interested.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: OLED with SPD0301 driver

Post by mnf »

Thanks Ben,

I'll have a play - but away at present (flu vaccination training :-( )

It's a fairly quick hit to try - I'll try going to a 'single' buffer (either dram[7][128] or dram[7*128]) - and see what sort of speed up it gets for plot and bplot - which are key routines getting called for each pixel in the 'altered' area.

Martin

Post Reply