Page 2 of 2
Re: Interface abstraction
Posted: Sat Jun 23, 2012 4:52 pm
by Tectu
I try to find a good way for configuring the GPIO interfaces.
We currently have the problem, that the most developmend boards to do not have a full, free port. On my board, for example, the LCD is interfaces from PORTE 0 to PORTE 15.
This allows to just do: palWritePort(GPIOE, data); where data is of type uint16_t.
But since the most users need some way to split the data lines, we need to find a way to make it easy to configure, and not neccessary to edit the actual drivers sourcecode.
I thought about just splitting it into two 8-bit lanes like this:
Code: Select all
#define LCD_DATA_PORT_1 GPIOB
#define LCD_DATA_PORT_2 GPIOC
#define LCD_DATA_PORT_1_BASE 0
#define LCD_DATA_PORT_2_BASE 8
This would use GPIOB[0:7] for the DB0 to DB7 of the LCD, and GPIOC[8:15] for DB8 to DB15 of the LCD.
The main problem here is that we still need 8 continous pins on one free port. So we would have to be able to also provide 4+12 lanes, or 4+4+4 etc.
How do make this easy to configure for the user?
Abhishek thought about writing a small generator program/script which will automaticly generate the lld write and read functions depending on the config file of the user.
Does anybody else have another idea?
~ Tectu
Re: Interface abstraction
Posted: Sat Jun 23, 2012 8:36 pm
by Giovanni
The PAL driver can handle a thing called "bus", use an externally defined bus.
Giovanni
Re: Interface abstraction
Posted: Sun Jun 24, 2012 2:43 pm
by Tectu
okay guys, I over worked the GPIO thing now:
I made a new static inline function inside the ssd1289 driver source, called lld_lcdWriteGPIO(uint16_t d). This function does nothing beside write the 16-bit value to the LCD's data interface, depending on the pin config. Basiclly, I split the 16-bits up to 4x 4-bits. Now you don't need a continious 16-bit, or two 8-bit ports, but four different 4-bit ports.
Every function which does have to write to the data port of the LCD such as lld_lcdWriteIndex(), lld_lcdWriteData() and lld_lcdWriteStream() do now use that function.
The configuration looks like this:
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
And the function itself:
Code: Select all
static __inline lld_lcdWriteGPIO(uint16_t d) {
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);
}
It dosen't use the PAL driver of ChibiOS to keep everything quick.
~ Tectu
Re: Interface abstraction
Posted: Sun Jun 24, 2012 4:02 pm
by mabl
Hi Tectu,
just my 2c: Shouldn't the driver be generic and independent from the target architecture? And most macros in the PAL STM32 HAL are defines anyway - so I'm not sure how much you gain by this move.

Re: Interface abstraction
Posted: Sun Jun 24, 2012 4:11 pm
by Abhishek
I took a look at the HAL source code for the STM32 and found out that palWriteBus does the exact same thing.
This code can be pretty much easily ported to it, we simply set offset to required value and it'll work...
We can change our code accordingly.
Abhishek
Re: Interface abstraction
Posted: Mon Jun 25, 2012 9:58 am
by Tectu
I am still trying to find a good way to make a very easy to configure, but very flexible GPIO interface configuration at the same time.
Giovanni came up with the idea, to let the "user" of the library write the functions.
This sounds like a very good idea to me, since that would just be two functions:
Code: Select all
__inline void lld_lcdWriteGPIO(uint16_t data);
__inline uint16_t lld_lcdReadGPIO(void);
This would be put into the main.c or somewhere else of the project file.
In my case this would be:
Code: Select all
__inline void lld_lcdWriteGPIO(uint16_t data) {
palWritePort(LCD_DATA_PORT, data);
}
__inline uint16_t lcdReadGPIO(void) {
palReadPort(LCD_DATA_PORT);
}
For someone with needs 4x 4-bit groups, this would be a possible solution (just write):
Code: Select all
__inline void lld_lcdWriteGPIO(uint16_t d) {
palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 0);
palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 4);
palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 8);
palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 12);
}
What do you think about this?
~ Tectu
Re: Interface abstraction
Posted: Mon Jun 25, 2012 10:02 am
by Badger
that's about as good as we're going to get without complex configuration structs, so I vote we go with that.
Re: Interface abstraction
Posted: Mon Jun 25, 2012 10:08 am
by Tectu
Badger wrote:that's about as good as we're going to get without complex configuration structs, so I vote we go with that.
I fully agree with you. I edited everything as needed in the repo and edit the wiki now.
Re: Interface abstraction
Posted: Mon Jun 25, 2012 1:46 pm
by Abhishek
All right then, so be it.
I'll make the changes soon
Abhishek
Re: Interface abstraction
Posted: Mon Jun 25, 2012 1:58 pm
by Tectu
Abhishek wrote:I'll make the changes soon
Thanks in advance.
~ Tectu