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

  • From: Pekka Nikander <pekka.nikander@xxxxxx>
  • To: ell-i-developers@xxxxxxxxxxxxx
  • Date: Thu, 30 Jan 2014 02:08:43 +0200

>> That is, I'd like to use a macro like
>> 
>> DEFINE_GPIO_PIN_INIT(B, 2, INPUT, ..., AF2);
>> 
>> One line for each pin.
>> 
>> Perhaps we could generate static const values out of the macro, and then 
>> combine them?  Something like
>> 
>>   ...
>>   static const __GPIOB_PIN2_AF = GPIO_AFRx_AFRx3_AF2;
>>   ...
>>   const SystemInitRecordArrayData32NoAddress ... {
>>         ...
>>          D32(GPIO_TypeDef, AF[0],
>>                 __GPIOB_PIN0_AF |
>>                 __GPIOB_PIN1_AF |
>>                 ...
>> 
>> What do you think?  Would that work?  Could you perhaps try it, Ivan?  Or 
>> should I?

> I think the second option looks quite reasonable. I will give it a try 
> tomorrow. It is the first time I will start writing something a little more 
> extensive for the system!! :-)

Good.  I would place the macro definitions in arduelli_gpio.h, the lines per 
pin in ellduino_gpio.h, and then the actual code that generates initialisation 
records in ellduino_gpio.c.  And then add stuff to ellduino.c to force linker 
to include the records.

I would also have two macros, so that the source looks like this:

ellduino_gpio.h:

...
DEFINE_GPIO_PIN_INIT(B, 1, ...
DEFINE_GPIO_PIN_INIT(B, 2, INPUT, ..., AF2);
DEFINE_GPIO_PIN_INIT(B, 3, ...
...

each of these expanding to a set of static const variables.

ellduino_gpio.c:

DEFINE_GPIO_PORT_INIT(A);
...

each of these xpanding into a const SystemInit stuff.

--Pekka


Other related posts: