Page 2 of 6
Re: LCD Driver
Posted: Wed Jan 04, 2012 12:37 pm
by Badger
I've successfully used FSMC to control a SSD1289 LCD. I thought about writing an FSMC driver for chibios, but it was really simple to get going:
Code: Select all
#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
#define LCD_RAM (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */
void ssd1289_fsmc_init(void) {
rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
int FSMC_Bank = 0;
/* timing structure */
/* from datasheet:
address setup: 0ns
address hold: 0ns
Data setup: 5ns
Data hold: 5ns
Data access: 250ns
output hold: 100ns
*/
FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_1 | FSMC_BTR1_DATAST_1;
/* Bank1 NOR/SRAM control register configuration */
FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
}
static __inline void LCD_WriteReg(uint8_t LCD_Reg,uint16_t LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_REG = LCD_Reg;
/* Write 16-bit Reg */
LCD_RAM = LCD_RegValue;
}
static __inline uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = LCD_Reg;
/* Read 16-bit Reg */
return (LCD_RAM);
}
Re: LCD Driver
Posted: Wed Jan 04, 2012 1:42 pm
by mobyfab
Awesome, that will definately save me some time

Which FSMC pins did you use? (for RS, WR, RD, and CS)
Thanks a ton Badger!
Re: LCD Driver
Posted: Wed Jan 04, 2012 1:58 pm
by Badger
LCD_RS - PD11
LCD_WR - PD5
LCD_RD - PD4
LCD_CS - PD7
Glad to help!
Re: LCD Driver
Posted: Wed Jan 04, 2012 2:08 pm
by Badger
mobyfab, maybe you might be interested in helping me write an LCD driver for chibios? Abstracting the various low level stuff for different displays should be fairly easy, then having some decent high level drawing routines would be great. At the moment I've just implemented some basic fonts, line drawing etc. I'll tidy up the rest of the code and post it later.
Giovanni, is this something that could be of use to chibios? The interface (FSMC, SPI etc) could be abstracted for different MCU, and the LCD driver abstracted for different display types, but with common graphics functions.
Re: LCD Driver
Posted: Wed Jan 04, 2012 3:08 pm
by mobyfab
That's definately something I can help with, I have to write a full GUI for my project anyways.
So far I have written the following functions in my library: (everything works)
Code: Select all
void SSD1963_Init (void);
void SSD1963_WriteCommand(uint16_t commandToWrite);
void SSD1963_WriteData(uint16_t dataToWrite);
void SSD1963_SetArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey);
void SSD1963_FillArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey, uint16_t color);
void SSD1963_ClearScreen(uint16_t color);
void SSD1963_SetPixel(int x, int y, uint16_t color);
void SSD1963_Demo(void);
void SSD1963_drawString(uint16_t x, uint16_t y, const char *c, uint16_t color, uint8_t size);
void SSD1963_drawChar(uint16_t x, uint16_t y, const char c, uint16_t color, uint8_t size) ;
void SSD1963_drawBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const unsigned char *bmp);
float SSD1963_FPS(void);
This can easily be abstracted to work on other LCD controllers.
Re: LCD Driver
Posted: Wed Jan 04, 2012 3:22 pm
by Giovanni
Badger wrote:Giovanni, is this something that could be of use to chibios? The interface (FSMC, SPI etc) could be abstracted for different MCU, and the LCD driver abstracted for different display types, but with common graphics functions.
It would be a very valuable component of course but an huge effort IMO.
BTW, being a separate subsystem I would not require copyright assignment for such a large effort if handled separately from the OS, potentially it could be handled as a stand-alone project and have a separate yet linked life.
Giovanni
Re: LCD Driver
Posted: Wed Jan 04, 2012 11:22 pm
by Badger
I've created a Git Hub repository to store the driver:
https://github.com/trsaunders/Chibios-LCD-DriverThere are some basic instructions in the readme. Currently it is very basic, it will fill the screen, and draw some fonts.
mobyfab, it should be fairly obvious how to implement a new display; copy ssd1289_lld.* and change as required.
If you want to add any code then submit a pull request or I can add you on github.
Re: LCD Driver
Posted: Thu Jan 05, 2012 10:19 am
by mobyfab
It looks good, however it is missing the LCD panel abstraction.
Currently your LCD values are hard coded, a better way would be to use a "panel.h" file with a list of LCD panels and their properties.
That way we can use multiple panels with multiple controllers.
Re: LCD Driver
Posted: Thu Jan 05, 2012 10:53 am
by Badger
Good point on abstracting the panel, although I don't know what panel my
board has! How were you thinking we could abstract the panel? define the screen sizes in panel.h? The initialisation code I have in ssd1289_lld.c mostly comes from the source code package that came with the board, but I think it is specific to the driver chip rather than the screen with the exception of screen size.
Re: LCD Driver
Posted: Thu Jan 05, 2012 11:06 am
by Giovanni
May be, rather than abstract the panel you should abstract the frame buffer and the basic operations. A complex portable graphic framework can then be built on top of the abstraction.
Each LCD or VGA or whatever would then have a "driver" including the physical communication, much like X does.
Giovanni