palWriteGroup() macro
Posted: Sun Jun 24, 2012 9:18 pm
Morning folks,
Maybe a little stupid, the following question, but I don't get it...
I try to replace the following working code with some ChibiOS stuff to keep it plattfrom independend:
d is a uint16_t.
I thought that the best way is using the palWriteGroup() macro.
I am just very confused about the offset the macro takes as an argument. Shouldn't this work?
Here are the defines of the different LCD macros:
~ Tectu
Maybe a little stupid, the following question, but I don't get it...
I try to replace the following working code with some ChibiOS stuff to keep it plattfrom independend:
Code: Select all
LCD_DATA_PORT_1->BSRR = ((((~d >> 12 & 0xF) << 16) | (d >> 12 & 0xF)) << LCD_DATA_PORT_1_BASE);
LCD_DATA_PORT_2->BSRR = ((((~d >> 8 & 0xF) << 16) | (d >> 8 & 0xF)) << LCD_DATA_PORT_2_BASE);
LCD_DATA_PORT_3->BSRR = ((((~d >> 4 & 0xF) << 16) | (d >> 4 & 0xF)) << LCD_DATA_PORT_3_BASE);
LCD_DATA_PORT_4->BSRR = ((((~d >> 0 & 0xF) << 16) | (d >> 0 & 0xF)) << LCD_DATA_PORT_4_BASE);
d is a uint16_t.
I thought that the best way is using the palWriteGroup() macro.
I am just very confused about the offset the macro takes as an argument. Shouldn't this work?
Code: Select all
#define MASK(a) (15 << a)
palWriteGroup(LCD_DATA_PORT_1, MASK(LCD_DATA_PORT_1_BASE), LCD_DATA_PORT_1_BASE, d >> 12 & 0xF);
palWriteGroup(LCD_DATA_PORT_2, MASK(LCD_DATA_PORT_2_BASE), LCD_DATA_PORT_2_BASE, d >> 8 & 0xF);
palWriteGroup(LCD_DATA_PORT_3, MASK(LCD_DATA_PORT_3_BASE), LCD_DATA_PORT_3_BASE, d >> 4 & 0xF);
palWriteGroup(LCD_DATA_PORT_4, MASK(LCD_DATA_PORT_4_BASE), LCD_DATA_PORT_4_BASE, d >> 0 & 0xF);
Here are the defines of the different LCD macros:
Code: Select all
#define LCD_DATA_PORT_1 GPIOE
#define LCD_DATA_PORT_2 GPIOE
#define LCD_DATA_PORT_3 GPIOE
#define LCD_DATA_PORT_4 GPIOE
#define LCD_DATA_PORT_1_BASE 12
#define LCD_DATA_PORT_2_BASE 8
#define LCD_DATA_PORT_3_BASE 4
#define LCD_DATA_PORT_4_BASE 0
~ Tectu