[ell-i-developers] Re: PWM working for TIM2

  • From: Ivan Raul <supra.material@xxxxxxxxx>
  • To: ell-i-developers@xxxxxxxxxxxxx
  • Date: Fri, 31 Jan 2014 15:29:40 +0200

Dear Pekka.

I'm having a little problem with the designated initializers, I mean:

#ifdef __cplusplus
# define D32(p, r, v) { v }
#else
# ifndef offsetof
#  define offsetof(st, m) ((uint32_t)(&((st *)0)->m))
# endif
# define D32(p, r, v) [offsetof(p, r)/sizeof(uint32_t)] = { v }
#endif

As they are not supported in C++, my initial idea was to simply insert the
missing registers in between to simply use D32 homogeneously.

Do you know of any other alternative for the designated initializers in C++?

Thank you in advance for your reply

With Warm Regards, Ivan Raul


On Fri, Jan 31, 2014 at 12:05 PM, Ivan Raul <supra.material@xxxxxxxxx>wrote:

> And you're completely right. A very important mental note written today :)
>
> Thank you very much
>
> I'll keep you posted
>
> With Warm Regards, Ivan Raul
>
>
> On Fri, Jan 31, 2014 at 11:45 AM, Pekka Nikander <pekka.nikander@xxxxxx>wrote:
>
>> > What would be your initial guess about it, why it is not considering
>> > __GPIO ## port ## _PIN0_MODE
>> > to be  a constant, even when they are declared as static const.
>>
>> Looking at your code, the expression is essentially defined as
>>
>> static const uint32_t __GPIO ## port ## _PIN ## pin ## _MODE =
>> GPIO_MODER_MODER0_ ## mode << (pin * 2);
>>
>> Now, while that is a compile-time constant, IIRC it is not a constant
>> expression by C89/C99 or even C11 rules:
>>
>>
>> http://bytes.com/topic/c/answers/663536-c99-does-const-int-x-5-make-x-constant-expression
>>
>> http://stackoverflow.com/questions/12343027/const-keyword-and-constant-expressions-in-c99-and-c11
>>
>> Most probably the easiest way is to rename ellduino_gpio.c to
>> ellduino_gpio.cpp and try again.  IIRC C++11 should compile it just fine,
>> but I may be wrong.
>>
>> --Pekka
>>
>>
>>
>

Other related posts: