Is there a way to set data based on PIN macros.

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to make a device that can have dual USB descriptors. All the USB data needs to be done prior to run time. I do use a bootloader (not sure that helps) but can not think of how this could be done aside from making all data dynamic. I'm not sure that can easily be done.

Last Edited: Fri. Mar 27, 2020 - 10:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What has pin macros got to do with dual usb descriptors or dynamic data for that matter? Tell us what you want to achieve in 25 words or less. Then we can talk about implementation details.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using a switch to change from one descriptor to another. If pinb.3 is Low use usb descriptor A if high use B.  Which is made before usb insert.

 

I think I'm jut going to load up my h files and use one macro for the switch and a bunch if if statements checking it.

 

#define _X_()  (PINB & 0x04)==0

Endpoint_Read_Control_Stream_LE(&reportBuffer, sizeof((_X_())?JOYSTICK_EPSIZEX:JOYSTICK_EPSIZE));               

etc..

 

Last Edited: Sat. Mar 28, 2020 - 12:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure what the macro adds here - especially with the name _X_ as that obscures the meaning rather than explains it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
Using a switch to change from one descriptor to another. If pinb.3 is Low use usb descriptor A if high use B.  Which is made before usb insert.

 

presumably, a "descriptor" is just a data structure?

 

So isn't it as simple as just

 

typedef struct
{
    	// whatever
	:
	:
} descriptor_t;

descriptor_t this_descriptor = { /* whatever this is */ };
descriptor_t that_descriptor = { /* whatever that is */ };

descriptor_t * p_descriptor_to_use;

if( whatever_condition )
{
	p_descriptor_to_use = &this_descriptor ;
}
else
{
	p_descriptor_to_use = &that_descriptor ;
}

 

EDIT

 

Yes, you could use a conditional expression (ternary operator) there if you want.

 

EDIT 2

 

And you don't have to go via a pointer = you could just have 1 structure, and set it appropriately in the conditional blocks

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sat. Mar 28, 2020 - 10:22 AM