stm32f429 Discovery FMC Drive atom 4.3 inch lcd

Source: Internet
Author: User
Tags id3

I have a piece of stm32f429 discovery Board, for some reason need to use 8080 interface lcd, and the block Development Board comes with the LCD interface using LTDC drive, so on the right atom here bought a 4.3 inch capacitive touch screen, driver IC for the NT35510.
In order to quickly build a software engineering, I use the STM32CUBEMX tool to generate code templates, and write the LCD.C and nt35510.c two files, the code is as follows:

Lcd.c

typedef struct _LCD_DRV{UINT32_T (*checkid) (void), void (*init) (void), void (*setpixel) (uint16_t color, uint16_t x, Uint16_t y), void (*fillrect) (uint16_t color, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1), Void (*bitmap) (uint16_t C Olor[], uint16_t x0, uint16_t y0, uint16_t width, uint16_t height), void (*clear) (uint16_t color); int (*ioctrl) (uint32_t cm D, uint32_t param); uint16_t (*getpixel) (uint16_t x, uint16_t y);} Lcd_drv_t;const lcd_drv_t* lcd_module[] = {&nt35510_module,&st7789v_module,/*any other LCD Module*/};const LCD _drv_t *lcd_drv = 0;void lcd_gpio_cfg (void) {/* Since the FMC GPIO is automatically configured by CUBEMX, only reset pins are set here */Gpio_inittypedef Gpio_ Initstruct; Gpio_initstruct.pin = gpio_pin_0; Gpio_initstruct.mode = gpio_mode_output_pp; Gpio_initstruct.pull = Gpio_pullup; Gpio_initstruct.speed = Gpio_speed_fast; Hal_gpio_init (Gpioa, &gpio_initstruct);} void Lcd_fmc_cfg (void) {/* because STM32 CUBEMX has automatically generated code for the relevant FMC configuration, there is no need for additional settings */}void lcd_reset (void) {Hal_gpio_writepin (Gpioa , Gpio_pin_0, Gpio_pin_set);d elAy_ms (100); Hal_gpio_writepin (Gpioa, Gpio_pin_0, Gpio_pin_reset);d Elay_ms (100); Hal_gpio_writepin (Gpioa, Gpio_pin_0, Gpio_pin_set);d Elay_ms (100);} uint8_t lcd_checkid (void) {uint32_t Id;int i;for (i = 0; i < (sizeof (Lcd_module)/sizeof (Lcd_module[0])) (i++) {id = lcd_ Module[i]->checkid (); if (0! = ID) {printf ("Found ID:%x\r\n", id); lcd_drv = Lcd_module[i];return 1;}} return 0;} void Lcd_init (void) {lcd_gpio_cfg (); Lcd_fmc_cfg (); Lcd_reset (); if (Lcd_checkid ()) {Lcd_drv->init ();}} void Lcd_drawpixel (uint16_t color, uint16_t x, uint16_t y) {if (lcd_drv) lcd_drv->setpixel (color, x, y);} void Lcd_fillrect (uint16_t color, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {if (lcd_drv) Lcd_drv->fillrect ( Color, x0, y0, x1, y1);} void Lcd_drawbitmap (uint16_t color[], uint16_t x0, uint16_t y0, uint16_t width, uint16_t height) {if (lcd_drv) lcd_drv-> Bitmap (color, x0, y0, width, height);} void Lcd_clear (uint16_t color) {if (lcd_drv) lcd_drv->clear (color);}

It is important to note that if you are using a template of the right atom or a template of your own, you need to implement LCD_GPIO_CFG () and lcd_fmc_cfg () two functions, since stm32cubemx in the configuration of GPIO and FMC, the corresponding code has been generated automatically, So this is empty. In addition, my hardware is connected to the Lcd_rsfmc_a0, so Lcd_data's address is 0x6c000002, please modify it for your own hardware.

void Nt35510_writereg (uint16_t lcd_reg, uint16_t lcd_regvalue) {lcd_wr_reg (Lcd_reg);   Lcd_wr_data (Lcd_regvalue);}  uint16_t Nt35510_readreg (uint16_t lcd_reg) {lcd_wr_reg (Lcd_reg);//write the register sequence to be read Delay_us (5); return Lcd_rd_data ();//returns the Read value}//Begins writing gramvoid nt35510_writeram_prepare (void) {Lcd_wr_reg (0x2c00);} void nt35510_ Displayon (void) {Lcd_wr_reg (0x2900);//Open Display} void Nt35510_displayoff (void) {Lcd_wr_reg (0x2800);//close display} void nt35510_s  Etwindow (uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1) {nt35510_writereg (0x2a00, x0 >> 8);  Nt35510_writereg (0X2A01, x0 & 0XFF);   Nt35510_writereg (0X2A02, X1 >> 8);   Nt35510_writereg (0X2A03, X1 & 0XFF);   Nt35510_writereg (0x2b00, y0 >> 8);  Nt35510_writereg (0X2B01, y0 & 0XFF);   Nt35510_writereg (0x2b02, y1 >> 8);  Nt35510_writereg (0x2b03, Y1 & 0XFF); } void Nt35510_drawpixel (uint16_t color, uint16_t x, uint16_t y) {Nt35510_setwindow (x, y, x, y);//Set cursor position NT35510_WRITERAM_ Prepare ();//start writing gramlcd_wr_data (color); }//clear screen function void Nt35510_clear (uint16_t color) {uint32_t i; Nt35510_setwindow (0, 0, Width-1, Height-1);      Nt35510_writeram_prepare ();  for (i = 0; i < Width * Height; i++) {lcd_wr_data (color);}} uint32_t nt35510_checkid (void) {uint8_t id1, id2, id3;id1 = Nt35510_readreg (0xda00);//should be 0x00id2 = Nt35510_readreg  (0xdb00);//should be 0x80id3 = Nt35510_readreg (0XDC00);//should is 0x00 printf ("Read id:%x,%x,%x\r\n", Id1, Id2, ID3); if ((id1 = = 0x00) && (Id2 = = 0x80) && (ID3 = = 0x00)) return 0x35510;elsereturn 0;} void Nt35510_init (void) {Delay_ms (50);  Nt35510_writereg (0x0000,0x0001);d Elay_ms (50); Nt35510_writereg (0xf000,0x55); Nt35510_writereg (0XF001,0XAA); Nt35510_writereg (0xf002,0x52); Nt35510_writereg (0xf003,0x08);        Nt35510_writereg (0XF004,0X01); ......} void Nt35510_fillrect (uint16_t color, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {uint32_t i;uint16_t wi DTH, height;width = X1-x0+1;height = y1-y0+1; Nt35510_setwindow (x0, y0, x1, y1); NT35510_writeram_prepare (); for (i = 0; I < width * height; i++) {lcd_wr_data (color); }}//bitmap display function, bitmap each pixel size is 16bit, high byte in front low byte after void Nt35510_drawbitmap (uint16_t color[], uint16_t x0, uint16_t y0, uint16_t width, uint16_t height) {uint32_t i;uint16_t x1, y1;x1 = x0 + width-1;y1 = y0 + height-1; Nt35510_setwindow (x0, y0, x1, y1); Nt35510_writeram_prepare (); for (i = 0; I < width * height; i++) {lcd_wr_data (color[i]);}}    int Nt35510_ioctrl (uint32_t cmd, uint32_t param) {switch (cmd) {case lcd_cmd_sleep_in:break;    Case Lcd_cmd_sleep_out:break;    Case Lcd_cmd_set_dir:break;    Default:break; }return 0;} Const lcd_drv_t Nt35510_module = {nt35510_checkid,nt35510_init,nt35510_drawpixel,nt35510_fillrect,nt35510_ Drawbitmap,nt35510_clear,nt35510_ioctrl};

Project source code Please see attachment: Click to open the link

The experimental film is as follows:




stm32f429 Discovery FMC Drive atom 4.3 inch lcd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.