I have seen several explanations about this topic. But i can't seem to fit any solution for my code. I have read: Passing a 2D array to a C++ function https://www.techiedelight.com/pass-2d-array-function-parameter/
and so on.
But i don't know how to make any of the solutions work for me. My problem is following:
First of all im working with LED driver LP5030. Im trying to write some drivers like giving it an array of colors and then blink etc.
I have an array of colors like this:
static uint8_t colors[][3] = {
{ 0x00, 0xFF, 0x00 }, /* Red */
{ 0xFF, 0x00, 0x00 }, /* Green */
{ 0x00, 0x00, 0xFF }, /* Blue */
{ 0xFF, 0xFF, 0xFF }, /* White */
{ 0xFF, 0xFF, 0x00 }, /* Yellow */
{ 0x00, 0xFF, 0xFF }, /* Purple */
{ 0xFF, 0x00, 0xFF }, /* Cyan */
{ 0x79, 0xF4, 0x20 }, /* Orange */
};
And i have a following code which just changes colors in this array after every 1000ms. It works.
for(int i = 0; i < colors_size; i++)
{
set_LP5030_bank_colors(&I2C1Handle, SLAVE_ADDR, colors[i]);
DelayMs(1000);
}
I have defined set_LP5030_bank_colors as:
void set_LP5030_bank_colors(I2C_Handle_t *pI2CHandle, uint8_t SlaveAddr, uint8_t *colors)
Where *colors should be 1 dimensional array like this: {0x00, 0xFF, 0x00}
(one row of two dimensional array)
Now i would like to use all of this in a function because i would like to make fade function for example. My fade function should take whole array in instead of one line because i need to use it further.
I would like to use function inside a function like this (i left fade code out to make it simpler):
void fade_LP5030(I2C_Handle_t *pI2CHandle, uint8_t SlaveAddr, uint8_t **colors)
{
uint32_t colors_size = 8;
for(int i = 0; i < colors_size; i++)
{
set_LP5030_bank_colors(pI2CHandle, SlaveAddr, (uint8_t*)colors[i]);
DelayMs(10);
}
}
And i use it like this in main function:
fade_LP5030(&I2C1Handle, SLAVE_ADDR, colors);
It gives me error:
warning: passing argument 3 of 'fade_LP5030' from incompatible pointer type [-Wincompatible-pointer-types]
210 | fade_LP5030(&I2C1Handle, SLAVE_ADDR, colors);
| ^~~~~~
| |
| uint8_t (*)[3] {aka unsigned char (*)[3]}
And when i write my main function like this:
fade_LP5030(&I2C1Handle, SLAVE_ADDR, (uint8_t**)colors);
I get no errors but it seems im violating some memory location. Can you give me advice why this way it doesn't work?