简体   繁体   English

是否可以将具有延迟功能的结构数组声明为某些元素

[英]Is it possible to declare array of structures with delays functions as some of the elements

I got an initialization structure for my touchscreen driver from manufacturer. 我从制造商那里获得了触摸屏驱动程序的初始化结构。

struct ChipSetting ssd25xxcfgTable[]={
delay(300),
{2,0x01,0x00,0x00},
delay(100),
{2,0x06,0x19,0x0F},
{2,0x07,0x00,0xE0},
{2,0x08,0x00,0xE1},
{2,0x09,0x00,0xE2},
{2,0x0A,0x00,0xE3},
{2,0x0B,0x00,0xE4},
};

According to me the struct Chipsetting should be : 据我说,芯片设置的结构应该是:

struct Chipsetting
{
   unsigned char reg; // register to be written
   unsigned char len; // length of data
   unsigned char msb; // data
   unsigned char lsb;
};

I want to use the strutcure to program device registers as shown below. 我想使用strutcure对设备寄存器进行编程,如下所示。

for (index = 0; index < sizeof(ssd25xxcfgTable)/sizeof(ssd25xxcfgTable[0]); index++)
{
    //               command                  address of parameter     parameter length
    WriteReg(ssd25xxcfgTable[index].reg, &ssd25xxcfgTable[index].msb, ssd25xxcfgTable[index].len);

}

Is it possible to do so ? 有可能这样做吗? I need the delay functions to be called according to the element order given in the structure. 我需要根据结构中给定的元素顺序调用延迟函数。 According to me, it is not possible, but need to know if there is some workarounds. 据我说,这是不可能的,但是需要知道是否有一些解决方法。 I want to avoid splitting the for loop. 我想避免拆分for循环。 And I feel the above init structure is more readable. 而且我觉得上面的init结构更具可读性。

As I understand your question, it seems you need to actually store delays along with the Chipsetting values, and call them at runtime: 据我了解您的问题,看来您实际上需要将延迟与Chipsetting值一起存储,并在运行时调用它们:

struct ChipsettingWrite {
    int delay;
    struct Chipsetting setting;
};

struct ChipsettingWrite ssd25xxcfgTable[]={
    {300, {2,0x01,0x00,0x00}},
    {100, {2,0x06,0x19,0x0F}},
    {0,   {2,0x07,0x00,0xE0}},
    {0,   {2,0x08,0x00,0xE1}},
    {0,   {2,0x09,0x00,0xE2}},
    {0,   {2,0x0A,0x00,0xE3}},
    {0,   {2,0x0B,0x00,0xE4}},
};

I assume there must exist a function somewhere that writes the values, so you can do something like this: 我认为必须在某个地方存在一个可以写入值的函数,因此您可以执行以下操作:

int NUMBER_OF_SETTINGS = sizeof(ssd25xxcfgTable)/sizeof(ssd25xxcfgTable[0]);
for (int i = 0; i < NUMBER_OF_SETTINGS; i++) {
     if (ssd25xxcfgTable[i].delay > 0) {
          delay(ssd25xxcfgTable[i].delay);
     }
     WriteReg(ssd25xxcfgTable[i].setting.reg, &ssd25xxcfgTable[i].setting.msb, ssd25xxcfgTable[i].setting.len);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM