david1982
-
Posts
29 -
Joined
-
Last visited
Content Type
Forums
Store
Downloads
Blogs
Posts posted by david1982
-
-
I think that what I am doing ..
and sorry yes both displays use the same controller.
I have set the following in my ugfxconf..
#define GDISP_TOTAL_DISPLAYS 2
#define GDISP_TOTAL_CONTROLLERS 1
#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
My board int looks like..
static inline void init_board(GDisplay *g) {
(void) g;
//Set up the pins..
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);//cs 2
palSetPadMode(SPI_PORT, CS_PAD, PAL_MODE_OUTPUT_PUSHPULL);//cs 1
palSetPadMode(SPI_PORT, SCK_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(SPI_PORT, MISO_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(SPI_PORT, MOSI_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(RESET_PORT, RESET_PAD, PAL_MODE_OUTPUT_PUSHPULL );
palSetPadMode(DNC_PORT, DNC_PAD, PAL_MODE_OUTPUT_PUSHPULL);
switch(g->controllerdisplay)
{
case 0:
//Set pins.
palSetPad(CS_PORT, CS_PAD);
palSetPad(RESET_PORT, RESET_PAD);
palClearPad(DNC_PORT, DNC_PAD);
break;
//Start SPI1 with our config.
spiStart(SPI_DRIVER, &spi_cfg);
spiSelectI(SPI_DRIVER); /* Slave Select assertion. */
case 1:
//Set pins.
palSetPad(GPIOB, 0);
palSetPad(RESET_PORT, RESET_PAD);
palClearPad(DNC_PORT, DNC_PAD);
//Start SPI1 with our config.
spiStart(SPI_DRIVER, &spi_cfg2);
spiSelectI(SPI_DRIVER);
break;
}
}But when I draw to each display only the second display works..
I am switching between displays like so..
coord_t displayA,displayB;
displayA = 0;
displayB = 1;
gdispSetDisplay(gdispGetDisplay(displayA));
///Do some drawing This does not show
gdispSetDisplay(gdispGetDisplay(displayB));
///Do some drawing This does show -
Hello all,
Can some one please just help me with my multiple display set-up.
I understand the basics of using the multiple displays from the examples but how do I set-up my board file as the only difference between the two displays is the chip select (SPI).
Thanks.
-
Hello,
Just having some trouble displaying a custom font can someone please test it for me?
-
Hello all,
I have a working spi SD card setup using gfile.
What I want to do is have a file on the SD card with some settings (numbers) and have my code read the file and then have the setting number applied to an int.
How would I best go about this?
Thank you.
-
I have fixed the error by enabling
#define GFILE_NEED_STRINGS TRUE
#define GFILE_NEED_PRINTG TRUE
in the gfxconf file.
-
Hello,
I am trying to use the stdio with ugfx as I need sprintf.
I have updated my stdio file to fix the compile errors but now I get this error went I use sprintf
undefined reference to `snprintg'
How could I resolve this?
Thank you.
-
I got it all working.
Thank you very much.
-
Hello,
I have got my sd card working under chibios (I can read and write).
Now how do I display an bmp file that is on that sd card?
I have the basics for displaying images down just don't know how to open image from the sd card.
I will be grateful for any help.
Thank you.
-
Is it safe to assume that the fsmc is working?
Where should I start to look to fix it.
Thank you
-
Hello,
Just trying to get my SSD1289 display working and all I am getting is a screen full of multi colored pixels what would be the cause of this??
Here is my board file.
/*
#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
// For a multiple display configuration we would put all this in a structure and then
// set g->board to that structure.
/* Using FSMC A19 (PE3) as DC */
#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* DC = 0 */
#define GDISP_RAM (*((volatile uint16_t *) 0x60100000)) /* DC = 1 */
#define GDISP_DMA_STREAM STM32_DMA2_STREAM6
#define SET_RST palSetPad(GPIOD, 3);
#define CLR_RST palClearPad(GPIOD, 3);
static inline void init_board(GDisplay *g) {
// As we are not using multiple displays we set g->board to NULL as we don't use it.
g->board = 0;
switch(g->controllerdisplay) {
case 0: // Set up for Display 0
#if defined(STM32F4XX) || defined(STM32F2XX)
/* STM32F4 FSMC init */
rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
#if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, 0, 0))
gfxExit();
dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
#endif
#else
#error "FSMC not implemented for this device"
#endif
/* Group pins */
IOBus busD = {GPIOD, (1 << 0) | (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) |
(1 << 9) | (1 << 10) | (1 << 14) | (1 << 15), 0};
IOBus busE = {GPIOE, (1 << 3) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) |
(1 << 13) | (1 << 14) | (1 << 15), 0};
/* FSMC is an alternate function 12 (AF12) */
palSetBusMode(&busD, PAL_MODE_ALTERNATE(12));
palSetBusMode(&busE, PAL_MODE_ALTERNATE(12));
/* FSMC timing register configuration */
FSMC_Bank1->BTCR[0 + 1] = (FSMC_BTR1_ADDSET_1 | FSMC_BTR1_ADDSET_3) \
| (FSMC_BTR1_DATAST_1 | FSMC_BTR1_DATAST_3) \
| (FSMC_BTR1_BUSTURN_1 | FSMC_BTR1_BUSTURN_3) ;
// FSMC_Bank1->BTCR[0 + 1] = (FSMC_BTR1_ADDSET_3 | FSMC_BTR1_ADDSET_0) \
// | (FSMC_BTR1_DATAST_3 | FSMC_BTR1_DATAST_0) \
// | FSMC_BTR1_BUSTURN_0;
/* Bank1 NOR/PSRAM control register configuration
* Write enable, memory databus width set to 16 bit, memory bank enable */
// FSMC_Bank1->BTCR[0] = FSMC_BCR1_WREN | FSMC_BCR1_MWID_0 | FSMC_BCR1_MBKEN;
break;
}
}
static inline void post_init_board(GDisplay *g) {
(void) g;
}
static inline void setpin_reset(GDisplay *g, bool_t state) {
(void) g;
if (state) {
CLR_RST;
} else {
SET_RST;
}
}
static inline void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
}
static inline void acquire_bus(GDisplay *g) {
(void) g;
}
static inline void release_bus(GDisplay *g) {
(void) g;
}
static inline void write_index(GDisplay *g, uint16_t index) {
(void) g;
GDISP_REG = index;
}
static inline void write_data(GDisplay *g, uint16_t data) {
(void) g;
GDISP_RAM = data;
}
static inline void setreadmode(GDisplay *g) {
(void) g;
}
static inline void setwritemode(GDisplay *g) {
(void) g;
}
static inline uint16_t read_data(GDisplay *g) {
(void) g;
return GDISP_RAM;
}
#if defined(GDISP_USE_DMA)
static inline void dma_with_noinc(GDisplay *g, color_t *buffer, int area) {
(void) g;
dmaStreamSetPeripheral(GDISP_DMA_STREAM, buffer);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
for (; area > 0; area -= 65535) {
dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area > 65535 ? 65535 : area);
dmaStreamEnable(GDISP_DMA_STREAM);
dmaWaitCompletion(GDISP_DMA_STREAM);
}
}
static inline void dma_with_inc(GDisplay *g, color_t *buffer, int area) {
(void) g;
dmaStreamSetPeripheral(GDISP_DMA_STREAM, buffer);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PINC | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
for (; area > 0; area -= 65535) {
dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area > 65535 ? 65535 : area);
dmaStreamEnable(GDISP_DMA_STREAM);
dmaWaitCompletion(GDISP_DMA_STREAM);
}
}
#endif
#endif /* _GDISP_LLD_BOARD_H */ -
Hello,
I have just got hold of a tft1p4705 TFT with an D51E5TA7601 driver ic I was just wondering if any one has played with one of there before?
Thank you.
Here is a link to the driver ic datasheet.
https://drive.google.com/file/d/0B_B2fQCYwJRiNnpzcWxqeldoZHM/view?usp=sharing
-
Hello,
I have been trying to get a large number (50+) font working for use with a temperature sensor but I am having some problems.
I have userfonts working but only at a font size of 5 as soon as I try to go for the larger sizes the userfont will not work.
I have also filtered for just numbers to reduce the size in case that was the problem but no luck.
Is there a limit on the font size that I can use?
The font I am currently trying to use is DejaVuSansMono.
Any help would be great.
-
Very nice !! :shock:
Thank you!
-
Wow that is a big difference.
Thanks for cleaning up the code I to can run SPI_BaudRatePrescaler_2 now.
My setup is also running about the same speed as your ugfx setup.
Thank you.
-
Great glad it helped ..
Speed up is next for me also please let me know how you go.
-
The problem was just bad setup on my end looking at examples I came up with the following board file.
Hope it helps.
#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
//**** ILI9341 on SPI1. TESTED on STM32F1 AND STM32F4.
// Pin & SPI setup
// SPI1
#define SPI_DRIVER (&SPID1)
#define SPI_PORT GPIOA
#define SCK_PAD 5 //PA5
#define MISO_PAD 6 //PA6
#define MOSI_PAD 7 //PA7
#define CS_PORT GPIOA
#define RESET_PORT GPIOA
#define DNC_PORT GPIOA
#define CS_PAD 4 // PA4 -- 0 = chip selected
#define RESET_PAD 1 // PA1 -- 0 = reset
#define DNC_PAD 0 // PA0 -- control=0, data=1 -- DNC or D/C
// SPI setup ajust " SPI_BaudRatePrescaler_X" to set SPI speed.
// Peripherial Clock 42MHz SPI2 SPI3
// Peripherial Clock 84MHz SPI1 SPI1 SPI2/3
#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) // 42 MHz 21 MHZ
#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) // 21 MHz 10.5 MHz
#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) // 10.5 MHz 5.25 MHz
#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) // 5.25 MHz 2.626 MHz
#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) // 2.626 MHz 1.3125 MHz
#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) // 1.3125 MHz 656.25 KHz
#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) // 656.25 KHz 328.125 KHz
#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) // 328.125 KHz 164.06 KHz
static SPIConfig spi_cfg = {
NULL,
CS_PORT,
CS_PAD,
SPI_BaudRatePrescaler_4 //AJUST SPEED HERE..
};
static inline void init_board(GDisplay *g) {
(void) g;
//g->board = 0;
//Set up the pins..
palSetPadMode(SPI_PORT, SCK_PAD, PAL_MODE_ALTERNATE(5));
palSetPadMode(SPI_PORT, MOSI_PAD, PAL_MODE_ALTERNATE(5));
palSetPadMode(SPI_PORT, MISO_PAD, PAL_MODE_ALTERNATE(5));
palSetPadMode(RESET_PORT, RESET_PAD, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(CS_PORT, CS_PAD, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(DNC_PORT, DNC_PAD, PAL_MODE_OUTPUT_PUSHPULL);
//Set pins.
palSetPad(CS_PORT, CS_PAD);
palSetPad(RESET_PORT, RESET_PAD);
palClearPad(DNC_PORT, DNC_PAD);
//Start SPI1 with our config.
spiStart(SPI_DRIVER, &spi_cfg);
}
static inline void post_init_board(GDisplay *g) {
(void) g;
}
static inline void setpin_reset(GDisplay *g, bool_t state) {
(void) g;
palWritePad(RESET_PORT, RESET_PAD, !state);
}
static inline void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
(void) percent;
}
static inline void acquire_bus(GDisplay *g) {
(void) g;
spiSelect(SPI_DRIVER);
}
static inline void release_bus(GDisplay *g) {
(void) g;
spiUnselect(SPI_DRIVER);
}
static inline void write_index(GDisplay *g, uint8_t index) {
static uint8_t sindex;
(void) g;
palClearPad(DNC_PORT, DNC_PAD);
sindex = index;
spiSend(SPI_DRIVER, 1, &sindex);
}
static inline void write_data(GDisplay *g, uint8_t data) {
static uint8_t sdata;
(void) g;
palSetPad(DNC_PORT, DNC_PAD);
sdata = data;
spiSend(SPI_DRIVER, 1, &sdata);
}
static inline void setreadmode(GDisplay *g) {
(void) g;
}
static inline void setwritemode(GDisplay *g) {
(void) g;
}
static inline uint16_t read_data(GDisplay *g) {
(void) g;
return 0;
}
#endif /* _GDISP_LLD_BOARD_H */ -
Well I have been playing around and I am now trying to get an image to display the normal way..
I am using the romfs and I have my romfs_files.h sorted with a bmp image converted via file2c (bf.h)
My code runs fine but no image displays (I toggle an LED in the while and the code does not jam up)
#include "gfx.h"
static gdispImage myImage;
int main(void) {
halInit();
chSysInit();
coord_t swidth, sheight;
gfxInit();
gdispSetOrientation(GDISP_ROTATE_90);
swidth = gdispGetWidth();
sheight = gdispGetHeight();
gdispImageOpenGFile(&myImage, "bf.h");
gdispImageDraw(&myImage, 20, 20, swidth, sheight, 10, 10);
gdispImageClose(&myImage);
while(TRUE) {
gfxSleepMilliseconds(500);
}
}
#ifndef _GFXCONF_H
#define _GFXCONF_H
/* The operating system to use. One of these must be defined - preferably in your Makefile */
#define GFX_USE_OS_CHIBIOS TRUE
//#define GFX_USE_OS_WIN32 FALSE
//#define GFX_USE_OS_LINUX FALSE
//#define GFX_USE_OS_OSX FALSE
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GFILE TRUE
/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_NEED_CONTROL TRUE
#define GDISP_NEED_STARTUP_LOGO FALSE
#define GDISP_NEED_CIRCLE FALSE
#define GDISP_NEED_MULTITHREAD FALSE
#define GDISP_NEED_IMAGE TRUE
#define GDISP_NEED_IMAGE_BMP TRUE
#define GDISP_NEED_IMAGE_BMP_1 FALSE
#define GDISP_NEED_IMAGE_BMP_4 FALSE
#define GDISP_NEED_IMAGE_BMP_4_RLE FALSE
#define GDISP_NEED_IMAGE_BMP_8 FALSE
#define GDISP_NEED_IMAGE_BMP_8_RLE FALSE
#define GDISP_NEED_IMAGE_BMP_16 FALSE
#define GDISP_NEED_IMAGE_BMP_24 FALSE
#define GDISP_NEED_IMAGE_BMP_32 FALSE
#define GDISP_NEED_IMAGE_PNG FALSE
#define GDISP_NEED_IMAGE_NATIVE FALSE
/* GDISP - fonts to include */
#define GDISP_INCLUDE_USER_FONTS FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 FALSE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS10 FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS12 FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS16 FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS24 TRUE
#define GDISP_INCLUDE_FONT_DEJAVUSANS32 TRUE
#define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12 FALSE
#define GDISP_INCLUDE_FONT_FIXED_10x20 FALSE
#define GDISP_INCLUDE_FONT_FIXED_7x14 FALSE
#define GDISP_INCLUDE_FONT_FIXED_5x8 FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS16_AA FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS24_AA FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANS32_AA FALSE
#define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12_AA FALSE
/*gfile */
#define GFILE_NEED_ROMFS TRUE
#define GFILE_NEED_NATIVEFS FALSE
#define GFILE_NEED_CHBIOSFS FALSE
/*GWIN*/
#define GWIN_NEED_IMAGE FALSE
#define GWIN_NEED_CONTAINER FALSE
#define GWIN_NEED_WIDGET FALSE
#endif /* _GFXCONF_H */ -
Hello.
I am trying to use Image Box but I get "unknown type name 'GHandle'" when trying to build.
I assume that i have not enabled something in my ugfxconf file.
What could it be?
I have rom file system working with my image converted to a h file also .
Thank you.
-
Thank you inmarket.
I have it all working now
-
Still on good..
I have slowed down the SPI and I have redone the board file.
I also looked at the Chinese files that came with the LCD and there where some write_data differences so I corrected them in my gdisp_lld_ILI9341.c file but still nothing on the LCD.
I have connected my oscilloscope and I am defiantly getting pulses on MOSI and CS also RST.
The backlight is also differently on.
The attachment is what I got with the LCD and below are my files.
Could some one with more experience and knowledge than I please have a look.
Thank You.
board_ILI9341.h
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
/**
* @file boards/addons/gdisp/board_SSD1306_spi.h
* @brief GDISP Graphic Driver subsystem board interface for the SSD1306 display.
*
* @note This file contains a mix of hardware specific and operating system specific
* code. You will need to change it for your CPU and/or operating system.
*/
#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
// Pin & SPI setup
#define SPI_DRIVER (&SPID2)
#define SPI_PORT GPIOB
#define SCK_PAD 13
#define MISO_PAD 14
#define MOSI_PAD 15
#define CS_PORT GPIOB
#define RESET_PORT GPIOB
#define DNC_PORT GPIOB
#define CS_PAD 12 // 0 = chip selected
#define RESET_PAD 10 // 0 = reset
#define DNC_PAD 11 // control=0, data=1
static SPIConfig spi_cfg = {
NULL,
CS_PORT,
CS_PAD,
(SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA)
};
static inline void init_board(GDisplay *g) {
(void) g;
//g->board = 0;
palSetPadMode(SPI_PORT, SCK_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(SPI_PORT, MOSI_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(SPI_PORT, MISO_PAD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(RESET_PORT, RESET_PAD, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(CS_PORT, CS_PAD, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(DNC_PORT, DNC_PAD, PAL_MODE_OUTPUT_PUSHPULL);
palSetPad(CS_PORT, CS_PAD);
palSetPad(RESET_PORT, RESET_PAD);
palClearPad(DNC_PORT, DNC_PAD);
spiStart(&SPID2, &spi_cfg);
}
static inline void post_init_board(GDisplay *g) {
(void) g;
}
static inline void setpin_reset(GDisplay *g, bool_t state) {
(void) g;
palWritePad(RESET_PORT, RESET_PAD, !state);
}
static inline void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
(void) percent;
}
static inline void acquire_bus(GDisplay *g) {
(void) g;
spiAcquireBus(SPI_DRIVER);
}
static inline void release_bus(GDisplay *g) {
(void) g;
spiReleaseBus(SPI_DRIVER);
}
static inline void write_index(GDisplay *g, uint16_t index) {
(void) g;
spiSelect(SPI_DRIVER);
static uint8_t txbuf[2] = {0};
txbuf[0] = 0x70 | 0x00 | 0x00;
spiSend(SPI_DRIVER, 1, txbuf);
//txbuf[0] = index & 0xFF;
txbuf[0] = (index >> 8);
txbuf[1] = (index & 0xFF);
spiSend(SPI_DRIVER, 2, txbuf);
spiUnselect(SPI_DRIVER);
}
static inline void write_data(GDisplay *g, uint16_t data) {
(void) g;
spiSelect(SPI_DRIVER);
static uint8_t txbuf[2] = {0};
txbuf[0] = 0x70 | 0x00 | 0x02;
spiSend(SPI_DRIVER, 1, txbuf);
txbuf[0] = (data >> 8);
txbuf[1] = (data & 0xFF);
spiSend(SPI_DRIVER, 2, txbuf);
spiUnselect(SPI_DRIVER);
}
static inline void setreadmode(GDisplay *g) {
(void) g;
}
static inline void setwritemode(GDisplay *g) {
(void) g;
}
static inline uint16_t read_data(GDisplay *g) {
(void) g;
spiStart(SPI_DRIVER, &spi_cfg);
spiSelect(SPI_DRIVER);
static uint8_t txbuf[1] = {0};
txbuf[0] = 0x70 | 0x01 | 0x02;
spiSend(SPI_DRIVER, 1, txbuf);
static uint8_t rxbuf[3] = {0};
spiReceive(SPI_DRIVER, 3, rxbuf);
spiUnselect(SPI_DRIVER);
spiStart(SPI_DRIVER, &spi_cfg);
static uint16_t value = 0;
value = rxbuf[1] << 8 | rxbuf[2];
return value;
}
#endif /* _GDISP_LLD_BOARD_H */gdisp_lld_ILI9341.c
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#include "gfx.h"
#if GFX_USE_GDISP
#if defined(GDISP_SCREEN_HEIGHT)
#warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
#undef GISP_SCREEN_HEIGHT
#endif
#if defined(GDISP_SCREEN_WIDTH)
#warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
#undef GDISP_SCREEN_WIDTH
#endif
#define GDISP_DRIVER_VMT GDISPVMT_ILI9341
#include "drivers/gdisp/ILI9341/gdisp_lld_config.h"
#include "src/gdisp/gdisp_driver.h"
#include "board_ILI9341.h"
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
#ifndef GDISP_SCREEN_HEIGHT
#define GDISP_SCREEN_HEIGHT 320
#endif
#ifndef GDISP_SCREEN_WIDTH
#define GDISP_SCREEN_WIDTH 240
#endif
#ifndef GDISP_INITIAL_CONTRAST
#define GDISP_INITIAL_CONTRAST 50
#endif
#ifndef GDISP_INITIAL_BACKLIGHT
#define GDISP_INITIAL_BACKLIGHT 100
#endif
#include "drivers/gdisp/ILI9341/ILI9341.h"
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
// Some common routines and macros
#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
#define write_data16(g, data) { write_data(g, data >> 8); write_data(g, (uint8_t)data); }
#define delay(us) gfxSleepMicroseconds(us)
#define delayms(ms) gfxSleepMilliseconds(ms)
static void set_viewport(GDisplay *g) {
write_index(g, 0x2A);
write_data(g, (g->p.x >> 8));
write_data(g, (uint8_t) g->p.x);
write_data(g, (g->p.x + g->p.cx - 1) >> 8);
write_data(g, (uint8_t) (g->p.x + g->p.cx - 1));
write_index(g, 0x2B);
write_data(g, (g->p.y >> 8));
write_data(g, (uint8_t) g->p.y);
write_data(g, (g->p.y + g->p.cy - 1) >> 8);
write_data(g, (uint8_t) (g->p.y + g->p.cy - 1));
}
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
// No private area for this controller
g->priv = 0;
// Initialise the board interface
g-> board = 0;
init_board(g);
// Hardware reset
setpin_reset(g, TRUE);
gfxSleepMilliseconds(20);
setpin_reset(g, FALSE);
gfxSleepMilliseconds(20);
// Get the bus for the following initialisation commands
acquire_bus(g);
write_index(g, 0x01); //software reset
gfxSleepMilliseconds(5);
write_index(g, 0x28);
// display off
//---------------------------------------------------------
// magic?
write_index(g, 0xCF);
write_data(g, 0x00);
write_data(g, 0xC1);
write_data(g, 0x30);
write_index(g, 0xED);
write_data(g, 0x64);
write_data(g, 0x03);
write_data(g, 0x12);
write_data(g, 0x81);
write_index(g, 0xE8);
write_data(g, 0x85);
write_data(g, 0x00);
write_data(g, 0x78);
write_index(g, 0xCB);
write_data(g, 0x39);
write_data(g, 0x2C);
write_data(g, 0x00);
write_data(g, 0x34);
write_data(g, 0x02);
write_index(g, 0xF7);
write_data(g, 0x20);
write_index(g, 0xEA);
write_data(g, 0x00);
write_data(g, 0x00);
//------------power control------------------------------
write_index(g, 0xC0); //power control
write_data(g, 0x23);
write_index(g, 0xC1); //power control
write_data(g, 0x10);
//--------------VCOM
write_index(g, 0xC5); //vcom control
write_data(g, 0x3e);//35
write_data(g, 0x28);//3E
write_index(g, 0xC7); //vcom control
write_data(g, 0x86); // 0x94
//------------memory access control------------------------
write_index(g, 0x36);
// memory access control
write_data(g, 0x48); //0048 my,mx,mv,ml,BGR,mh,0.0
write_index(g, 0x3A); // pixel format set
write_data(g, 0x55);//16bit /pixel
//----------------- frame rate------------------------------
write_index(g, 0xB1);
// frame rate
write_data(g, 0x00);
write_data(g, 0x18); //70
//----------------Gamma---------------------------------
write_index(g, 0xF2); // 3Gamma Function Disable
write_data(g, 0x00);
write_index(g, 0x26);
write_data(g, 0x01); // gamma set 4 gamma curve 01/02/04/08
write_index(g, 0xE0); //positive gamma correction
write_data(g, 0x0F);
write_data(g, 0x31);
write_data(g, 0x2B);
write_data(g, 0x0C);
write_data(g, 0x0E);
write_data(g, 0x08);
write_data(g, 0x4E);
write_data(g, 0xF1);
write_data(g, 0x37);
write_data(g, 0x07);
write_data(g, 0x10);
write_data(g, 0x03);
write_data(g, 0x0E);
write_data(g, 0x09);
write_data(g, 0x00);
write_index(g, 0xE1); //negamma correction
write_data(g, 0x00);
write_data(g, 0x0E);
write_data(g, 0x14);
write_data(g, 0x03);
write_data(g, 0x11);
write_data(g, 0x07);
write_data(g, 0x31);
write_data(g, 0xC1);
write_data(g, 0x48);
write_data(g, 0x08);
write_data(g, 0x0F);
write_data(g, 0x0C);
write_data(g, 0x31);
write_data(g, 0x36);
write_data(g, 0x0F);
//--------------ddram ---------------------
write_index(g, 0x2A);
// column set
// size = 239
write_data(g, 0x00);
write_data(g, 0x00);
write_data(g, 0x00);
write_data(g, 0xEF);
write_index(g, 0x2B);
// page address set
// size = 319
write_data(g, 0x00);
write_data(g, 0x00);
write_data(g, 0x01);
write_data(g, 0x3F);
// write_index(g, 0x34);
//write_index(g, 0x35);
// tearing effect off
// tearing effect on
// write_index(g, 0xb4); // display inversion
// write_data(g, 0x00);
write_index(g, 0xb7); //entry mode set
write_data(g, 0x07);
//-----------------display---------------------
write_index(g, 0xB6);
// display function control
write_data(g, 0x08);
write_data(g, 0x82);
write_data(g, 0x27);
write_index(g, 0x11); //sleep out
gfxSleepMilliseconds(100);
write_index(g, 0x29); // display on
write_index(g, 0x2c);
// Finish Init
post_init_board(g);
// Release the bus
release_bus(g);
/* Turn on the back-light */
set_backlight(g, GDISP_INITIAL_BACKLIGHT);
/* Initialise the GDISP structure */
g->g.Width = GDISP_SCREEN_WIDTH;
g->g.Height = GDISP_SCREEN_HEIGHT;
g->g.Orientation = GDISP_ROTATE_0;
g->g.Powermode = powerOn;
g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
g->g.Contrast = GDISP_INITIAL_CONTRAST;
return TRUE;
}
#if GDISP_HARDWARE_STREAM_WRITE
LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
acquire_bus(g);
set_viewport(g);
write_index(g, 0x2C);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data16(g, gdispColor2Native(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
}
#endif
#if GDISP_HARDWARE_STREAM_READ
LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
acquire_bus(g);
set_viewport(g);
write_index(g, 0x2E);
setreadmode(g);
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
uint16_t data;
data = read_data(g);
return gdispNative2Color(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);
release_bus(g);
}
#endif
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
LLDSPEC void gdisp_lld_control(GDisplay *g) {
switch(g->p.x) {
case GDISP_CONTROL_POWER:
if (g->g.Powermode == (powermode_t)g->p.ptr)
return;
switch((powermode_t)g->p.ptr) {
case powerOff:
case powerSleep:
case powerDeepSleep:
acquire_bus(g);
write_reg(g, 0x0010, 0x0001); /* enter sleep mode */
release_bus(g);
break;
case powerOn:
acquire_bus(g);
write_reg(g, 0x0010, 0x0000); /* leave sleep mode */
release_bus(g);
break;
default:
return;
}
g->g.Powermode = (powermode_t)g->p.ptr;
return;
case GDISP_CONTROL_ORIENTATION:
if (g->g.Orientation == (orientation_t)g->p.ptr)
return;
switch((orientation_t)g->p.ptr) {
case GDISP_ROTATE_0:
acquire_bus(g);
write_reg(g, 0x36, 0x48); /* X and Y axes non-inverted */
release_bus(g);
g->g.Height = GDISP_SCREEN_HEIGHT;
g->g.Width = GDISP_SCREEN_WIDTH;
break;
case GDISP_ROTATE_90:
acquire_bus(g);
write_reg(g, 0x36, 0xE8); /* Invert X and Y axes */
release_bus(g);
g->g.Height = GDISP_SCREEN_WIDTH;
g->g.Width = GDISP_SCREEN_HEIGHT;
break;
case GDISP_ROTATE_180:
acquire_bus(g);
write_reg(g, 0x36, 0x88); /* X and Y axes non-inverted */
release_bus(g);
g->g.Height = GDISP_SCREEN_HEIGHT;
g->g.Width = GDISP_SCREEN_WIDTH;
break;
case GDISP_ROTATE_270:
acquire_bus(g);
write_reg(g, 0x36, 0x28); /* Invert X and Y axes */
release_bus(g);
g->g.Height = GDISP_SCREEN_WIDTH;
g->g.Width = GDISP_SCREEN_HEIGHT;
break;
default:
return;
}
g->g.Orientation = (orientation_t)g->p.ptr;
return;
case GDISP_CONTROL_BACKLIGHT:
if ((unsigned)g->p.ptr > 100)
g->p.ptr = (void *)100;
set_backlight(g, (unsigned)g->p.ptr);
g->g.Backlight = (unsigned)g->p.ptr;
return;
//case GDISP_CONTROL_CONTRAST:
default:
return;
}
}
#endif
#endif /* GFX_USE_GDISP */ -
Hello All.
I have started to play with a new LCD ILI9341 SPI on my stm32f103.
I just cannot seam to get it to work I have connected to the correct pins as per the ILI9341 example in extras ..
Is there some thing else I should be doing when using the SPI?
My board_ILI9341.h
#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
#define LCD_PORT GPIOB
#define LCD_MOSI 15
#define LCD_MISO 14
#define LCD_SCK 13
#define LCD_CS 12
#define LCD_DC 11
#define LCD_RES 10
#define LCD_DC_CMD palClearPad(LCD_PORT, LCD_DC)
#define LCD_DC_DATA palSetPad(LCD_PORT, LCD_DC)
#define LCD_SCK_SET palSetPad(LCD_PORT, LCD_SCK)
#define LCD_SCK_RES palClearPad(LCD_PORT, LCD_SCK)
#define LCD_CS_RES palSetPad(LCD_PORT, LCD_CS)
#define LCD_CS_SET palClearPad(LCD_PORT, LCD_CS)
/**
* SPI configuration structure.
* Speed 12 MHz, CPHA=0, CPOL=0, 8bits frames, MSb transmitted first.
* Soft slave select.
*/
static const SPIConfig spi2cfg = {
NULL,
LCD_PORT,
LCD_CS,
(SPI_CR1_MSTR | SPI_CR1_SPE | SPI_CR1_SSM | SPI_CR1_SSI)
};
static void send_data(uint16_t data);
/**
* @brief Initialise the board for the display.
*
* @param[in] g The GDisplay structure
*
* @note Set the g->board member to whatever is appropriate. For multiple
* displays this might be a pointer to the appropriate register set.
*
* @notapi
*/
static inline void init_board(GDisplay *g) {
// As we are not using multiple displays we set g->board to NULL as we don't use it.
g->board = 0;
palSetPadMode(LCD_PORT, LCD_CS, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(LCD_PORT, LCD_DC, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(LCD_PORT, LCD_RES, PAL_MODE_OUTPUT_PUSHPULL);
spiStart(&SPID2, &spi2cfg);
spiSelectI(&SPID2);
}
/**
* @brief After the initialisation.
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline void post_init_board(GDisplay *g) {
(void) g;
}
/**
* @brief Set or clear the lcd reset pin.
*
* @param[in] g The GDisplay structure
* @param[in] state TRUE = lcd in reset, FALSE = normal operation
*
* @notapi
*/
static inline void setpin_reset(GDisplay *g, bool_t state) {
(void) g;
if (state = TRUE) {
palClearPad(LCD_PORT, LCD_RES);
} else {
palSetPad(LCD_PORT, LCD_RES);
}
}
/**
* @brief Set the lcd back-light level.
*
* @param[in] g The GDisplay structure
* @param[in] percent 0 to 100%
*
* @notapi
*/
static inline void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
(void) percent;
}
/**
* @brief Take exclusive control of the bus
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline void acquire_bus(GDisplay *g) {
(void) g;
}
/**
* @brief Release exclusive control of the bus
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline void release_bus(GDisplay *g) {
(void) g;
}
/**
* @brief Send data to the lcd.
*
* @param[in] data The data to send
*
* @notapi
*/
static inline void send_data(uint16_t data) {
// http://forum.easyelectronics.ru/viewtopic.php?p=262122#p262122
while (!(SPI2->SR & SPI_SR_TXE)); // ��� ����� �� �������� ��������� - � ������ �� SPI_DR
SPI2->DR = data; // ��������� � SPI_DR ��� �������
}
/**
* @brief Send data to the index register.
*
* @param[in] g The GDisplay structure
* @param[in] index The index register to set
*
* @notapi
*/
static inline void write_index(GDisplay *g, uint16_t index) {
(void) g;
while (SPI2->SR & SPI_SR_BSY);
LCD_CS_RES;
LCD_DC_CMD; // ��������� ������� � ����� ������
LCD_CS_SET;
send_data(index);
while (SPI2->SR & SPI_SR_BSY); // ���� ���� ���������� (==1) -- ������ SPI �����
/* ������ ���� �������� ��������� �������� ������� ��������� � ���������� �����
* ����� ������ ��� �������� �������� � ��������.
*/
LCD_DC_DATA; // ��������� ������� � ����� ������
}
/**
* @brief Send data to the lcd with DC control.
*
* @param[in] g The GDisplay structure
* @param[in] data The data to send
*
* @notapi
*/
static inline void write_data(GDisplay *g, uint16_t data) {
(void) g;
send_data(data);
}
/**
* @brief Set the bus in read mode
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline void setreadmode(GDisplay *g) {
(void) g;
}
/**
* @brief Set the bus back into write mode
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline void setwritemode(GDisplay *g) {
(void) g;
}
/**
* @brief Read data from the lcd.
* @return The data from the lcd
*
* @param[in] g The GDisplay structure
*
* @notapi
*/
static inline uint16_t read_data(GDisplay *g) {
(void) g;
return 0;
}
#endif /* _GDISP_LLD_BOARD_H */My main.c
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#include "board_ILI9341.h"
int main(void) {
coord_t width, height;
halInit();
chSysInit();
gfxInit();
// Get the screen size
width = gdispGetWidth();
height = gdispGetHeight();
// Code Here
gdispFillArc(width/2, height/2, width/4, -10, -45, White);
gdispDrawCircle(width/2+width/8, height/2-height/8, 13, Green);
gdispFillCircle (width/2+width/8, height/2-height/8, 10, Red);
gdispDrawArc(width/2+width/8, height/2-height/8, 20, 25, 115, Gray);
gdispFillEllipse (width-width/6, height-height/6, width/8, height/16, Blue);
gdispDrawEllipse (width-width/6, height-height/6, width/16, height/8, Yellow);
while(TRUE) {
gfxSleepMilliseconds(500);
}
} -
Yes the backlight is working.
White screen with no noise.
So I tested the pins with a scope and pressed reset on each pin test.
DB08 8 /NOTHING
DB09 9 /NOTHING
DB10 10 /NOTHING
DB11 11 /NOTHING
DB12 12 /NOTHING
DB13 13 /NOTHING
DB14 14 /NOTHING
DB15 15 /NOTHING
DB00 0 /NOTHING
DB01 1 /NOTHING
DB02 2 /NOTHING
DB03 3 /NOTHING
DB04 4 /NOTHING
DB05 5 /NOTHING
DB06 6 /NOTHING
DB07 7 /NOTHING
CS 8 /3 PULSE'S ON RESET
RS 9 /NOTHING
WR 10 /3 BURST'S OF PULSE'S
RD 11 /NOTHING
Thanks
-
Ok,
That compiled with no errors but still no good..
What should my pin configuration be in my board.h file for such a setup?
-
Ok I tryed your borad_ILI9325.h and now i get these errors
'busC' undeclared (first use in this function) board_ILI9325.h
'busB' undeclared (first use in this function) board_ILI9325.h
'index' undeclared (first use in this function) board_ILI9325.h
a label can only be part of a statement and a declaration is not a statement board_ILI9325.h line 31
expected expression before 'IOBus' board_ILI9325.h line 32
Just a little help with multiple displays..
in Support
Posted
Yes you where right inmarket..
I have it working now, you don’t do anything with the spi in int board but you do all spi work in acquire bus.
Below is my board file for 2 ILI9341 displays running on a STM32F1 via spi.
It my help others as an example.