Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am trying to have a Set of Constant string declared as pointers in Flash, I want then to copy the pointer to a struct, I am not sure what is the way to go with this.

I declared my string as static const char pointers:

static const char * GlobalTuningStr     = "Global Tuning";

static const char * KeyboardStr         = "Keyboard";

Also I have the following struct:

struct KeyboardStruct

{

  uint8_t ID;

  const char *name;

  uint8_t ActiveScaleMapping;

  uint8_t RootNote;

  uint8_t Octave;

 

  CYBIT OcatveMappingEnabled;

  uint8_t ScaleSize;

  uint8_t ScaleWidth;

  uint8_t ScaleStepsCounted;

  uint8_t Steps[12];

};

but when I call the MidiController_Keyboard_Start() function, USBUART prints trash.

void MidiController_Keyboard_Start()

{

    Keyboard -> name = KeyboardStr;

    SetActiveMapping( Keyboard, CHROMATIC);

   

    USBUART_PutString(Keyboard -> name);

   

  Keyboard->RootNote = 0;

  Keyboard->Octave = 0;

}

I am not sure how am I supposed to handle Strings in PSoC, any help?

Thanks!

0 Likes
1 Solution
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

You add following line inside of the function MidiController_Keyboard_Start()

    struct KeyboardStruct *Keyboard = &KeyboardContent;

In this case, the LOCAL variable Keyboard is declared and the LOCAL variable is discarded when exiting from the function MidiController_Keyboard_Start() The pointer to the KeyboardContent will not be stored in the GLOBAL variable declared in the header file.

If you want to initialize the GLOBAL variable in the function, just assign the pointer without the type identifier.

    Keyboard = &KeyboardContent;

It is available to declare the struct without the pointer variable.  But I don't recommend this solution because the operator -> must be replaced with the operator . (dot) in all codes.

Regards,

Noriaki

View solution in original post

4 Replies