2015-02-06 15:14:16 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2015-02-06 15:14:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GDISP_LLD_BOARD_H
|
|
|
|
#define _GDISP_LLD_BOARD_H
|
|
|
|
|
|
|
|
#include "board_uext.h"
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
// The various methods of driving the SPI interface
|
|
|
|
#define SPI_METHOD_PIO 1
|
|
|
|
#define SPI_METHOD_AT91 2
|
|
|
|
#define SPI_METHOD_CHIBIOS 3 // ChibiOS SPI for AT91SAM7 requires patch 7675 or higher to work correctly
|
|
|
|
|
|
|
|
// The various methods of driving the PIO interface
|
|
|
|
#define PIO_METHOD_AT91 1
|
|
|
|
#define PIO_METHOD_CHIBIOS 2 // ChibiOS PIO for the AT91SAM7 requires patch 7669 or higher to work correctly
|
|
|
|
|
|
|
|
// What methods are we using in this file
|
|
|
|
#define SPI_METHOD SPI_METHOD_AT91
|
|
|
|
#define PIO_METHOD PIO_METHOD_AT91
|
|
|
|
|
|
|
|
// If using SPI_METHOD_CHIBIOS or SPI_METHOD_AT91 then this must be defined for your CPU
|
|
|
|
#define SPI_CONFIG_REGISTER 0x00000801 // For AT91SAM7: 8bit, CPOL=1, NCPHA = 0, ClockPhase=0, SCLK = 48Mhz/8 = 6MHz
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
2015-02-06 15:14:16 +00:00
|
|
|
#define PORT_RESET UEXT_PORT_PIN5
|
|
|
|
#define PIN_RESET UEXT_PORTPIN_PIN5
|
|
|
|
#define PORT_DC UEXT_PORT_PIN6
|
|
|
|
#define PIN_DC UEXT_PORTPIN_PIN6
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
#if PIO_METHOD == PIO_METHOD_AT91
|
2015-02-06 15:14:16 +00:00
|
|
|
#define PinIsOutput(port,pin) ((port)->PIO_OER = 1 << (pin), (port)->PIO_PER = 1 << (pin), (port)->PIO_MDDR = 1 << (pin), (port)->PIO_PPUDR = 1 << (pin))
|
|
|
|
#define PinSet(port,pin) (port)->PIO_SODR = 1 << (pin)
|
|
|
|
#define PinClear(port,pin) (port)->PIO_CODR = 1 << (pin)
|
2015-02-07 11:58:24 +00:00
|
|
|
#elif PIO_METHOD == PIO_METHOD_CHIBIOS
|
2015-02-06 15:14:16 +00:00
|
|
|
#define PinIsOutput(port,pin) palSetPadMode((port), (pin), PAL_MODE_OUTPUT_PUSHPULL)
|
|
|
|
#define PinSet(port,pin) palSetPad((port), (pin))
|
|
|
|
#define PinClear(port,pin) palClearPad((port), (pin))
|
2015-02-07 11:58:24 +00:00
|
|
|
#else
|
|
|
|
#error "TLS8204 board file: Unsupported PIO method"
|
2015-02-06 15:14:16 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
#if SPI_METHOD == SPI_METHOD_PIO
|
|
|
|
|
|
|
|
static void spi_delay(volatile unsigned long a) { while (a!=0) a--; }
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static void spi_write(gU8 data) {
|
|
|
|
gU8 bit;
|
2015-02-07 11:58:24 +00:00
|
|
|
|
|
|
|
for(bit = 0x80; bit; bit >>= 1) {
|
|
|
|
if(data & bit)
|
|
|
|
PinSet(UEXT_SPI_MOSI_PORT, UEXT_SPI_MOSI_PORTPIN);
|
|
|
|
else
|
|
|
|
PinClear(UEXT_SPI_MOSI_PORT, UEXT_SPI_MOSI_PORTPIN);
|
2015-02-07 12:25:00 +00:00
|
|
|
spi_delay(1);
|
2015-02-07 11:58:24 +00:00
|
|
|
PinClear(UEXT_SPI_SCK_PORT, UEXT_SPI_SCK_PORTPIN);
|
2015-02-07 12:25:00 +00:00
|
|
|
spi_delay(1);
|
2015-02-07 11:58:24 +00:00
|
|
|
PinSet(UEXT_SPI_SCK_PORT, UEXT_SPI_SCK_PORTPIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPI_INIT() { \
|
|
|
|
PinIsOutput (UEXT_SPI_MOSI_PORT, UEXT_SPI_MOSI_PORTPIN); \
|
|
|
|
PinSet (UEXT_SPI_MOSI_PORT, UEXT_SPI_MOSI_PORTPIN); \
|
|
|
|
PinIsOutput (UEXT_SPI_SCK_PORT, UEXT_SPI_SCK_PORTPIN); \
|
|
|
|
PinSet (UEXT_SPI_SCK_PORT, UEXT_SPI_SCK_PORTPIN); \
|
|
|
|
PinIsOutput (UEXT_SPI_CS_PORT, UEXT_SPI_CS_PORTPIN); \
|
|
|
|
PinSet (UEXT_SPI_CS_PORT, UEXT_SPI_CS_PORTPIN); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPI_GETBUS() PinClear(UEXT_SPI_CS_PORT, UEXT_SPI_CS_PORTPIN)
|
|
|
|
#define SPI_RELEASEBUS() PinSet(UEXT_SPI_CS_PORT, UEXT_SPI_CS_PORTPIN)
|
|
|
|
#define SPI_WAITCOMPLETE()
|
|
|
|
#define SPI_WRITEBYTE(data) spi_write(data)
|
|
|
|
#define SPI_WRITEBYTES(pdata, len) while(len--) spi_write(*pdata++)
|
|
|
|
|
|
|
|
#elif SPI_METHOD == SPI_METHOD_AT91
|
|
|
|
|
|
|
|
#if UEXT_SPI_SCK_PORTPIN == 22
|
|
|
|
// Assume it is on SPI1
|
|
|
|
#define UEXT_SPI_DEV AT91C_BASE_SPI1
|
|
|
|
#define UEXT_SPI_ID AT91C_ID_SPI1
|
|
|
|
#define UEXT_SPI_PORT AT91C_BASE_PIOA
|
|
|
|
#define UEXT_SPI_PERIPH PIO_BSR
|
|
|
|
#else
|
|
|
|
// Assume it is on SPI0
|
|
|
|
#define UEXT_SPI_DEV AT91C_BASE_SPI0
|
|
|
|
#define UEXT_SPI_ID AT91C_ID_SPI0
|
|
|
|
#define UEXT_SPI_PORT AT91C_BASE_PIOA
|
|
|
|
#define UEXT_SPI_PERIPH PIO_ASR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SPI_INIT() { \
|
|
|
|
UEXT_SPI_PORT->PIO_MDDR = (1<<UEXT_SPI_CS_PORTPIN) | (1<<UEXT_SPI_SCK_PORTPIN) | (1<<UEXT_SPI_MOSI_PORTPIN) | (1<<UEXT_SPI_MISO_PORTPIN); \
|
|
|
|
UEXT_SPI_PORT->PIO_PPUER = 1<<UEXT_SPI_MISO_PORTPIN; \
|
|
|
|
UEXT_SPI_PORT->PIO_PDR = (1<<UEXT_SPI_CS_PORTPIN) | (1<<UEXT_SPI_SCK_PORTPIN) | (1<<UEXT_SPI_MOSI_PORTPIN) | (1<<UEXT_SPI_MISO_PORTPIN); \
|
|
|
|
UEXT_SPI_PORT->UEXT_SPI_PERIPH = (1<<UEXT_SPI_CS_PORTPIN) | (1<<UEXT_SPI_SCK_PORTPIN) | (1<<UEXT_SPI_MOSI_PORTPIN) | (1<<UEXT_SPI_MISO_PORTPIN); \
|
2015-02-07 12:25:00 +00:00
|
|
|
AT91C_BASE_PMC->PMC_PCER = 1 << UEXT_SPI_ID; \
|
2015-02-07 11:58:24 +00:00
|
|
|
UEXT_SPI_DEV->SPI_CR = 0x81; \
|
|
|
|
UEXT_SPI_DEV->SPI_CR = 0x81; \
|
|
|
|
UEXT_SPI_DEV->SPI_CR = 0x01; \
|
|
|
|
UEXT_SPI_DEV->SPI_MR = 0x000E0011; \
|
|
|
|
UEXT_SPI_DEV->SPI_CSR[0] = SPI_CONFIG_REGISTER; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPI_WAITCOMPLETE() while(!(UEXT_SPI_DEV->SPI_SR & AT91C_SPI_TXEMPTY))
|
|
|
|
#define SPI_GETBUS()
|
|
|
|
#define SPI_RELEASEBUS()
|
|
|
|
#define SPI_WRITEBYTE(data) { \
|
|
|
|
while(!(UEXT_SPI_DEV->SPI_SR & AT91C_SPI_TDRE)); \
|
|
|
|
UEXT_SPI_DEV->SPI_TDR = data; \
|
|
|
|
}
|
|
|
|
#define SPI_WRITEBYTES(pdata, len) while(len--) SPI_WRITEBYTE(*pdata++)
|
|
|
|
|
|
|
|
#elif SPI_METHOD == SPI_METHOD_CHIBIOS
|
|
|
|
|
2015-02-06 15:14:16 +00:00
|
|
|
static const SPIConfig spiconfig = {
|
|
|
|
0,
|
|
|
|
/* HW dependent part.*/
|
|
|
|
UEXT_SPI_CS_PORT,
|
|
|
|
UEXT_SPI_CS_PORTPIN,
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_CONFIG_REGISTER
|
2015-02-06 15:14:16 +00:00
|
|
|
};
|
2015-02-07 11:58:24 +00:00
|
|
|
|
|
|
|
#define SPI_INIT()
|
|
|
|
|
|
|
|
#define SPI_GETBUS() { \
|
|
|
|
spiStart(UEXT_SPI, &spiconfig); \
|
|
|
|
spiSelect(UEXT_SPI); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPI_RELEASEBUS() { \
|
|
|
|
spiUnselect(UEXT_SPI); \
|
|
|
|
spiStop(UEXT_SPI); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPI_WAITCOMPLETE()
|
|
|
|
#define SPI_WRITEBYTE(data) spiSend(UEXT_SPI, 1, &data)
|
|
|
|
#define SPI_WRITEBYTES(pdata, len) spiSend(UEXT_SPI, len, pdata)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "TLS8204 board file: Unsupported SPI method"
|
2015-02-06 15:14:16 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void init_board(GDisplay *g) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
|
|
|
|
PinIsOutput (PORT_DC, PIN_DC);
|
|
|
|
PinIsOutput (PORT_RESET, PIN_RESET);
|
|
|
|
PinSet (PORT_RESET, PIN_RESET);
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_INIT();
|
2015-02-06 15:14:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void post_init_board(GDisplay *g) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
static GFXINLINE void setpin_reset(GDisplay *g, gBool state) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
(void) state;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
PinClear(PORT_RESET, PIN_RESET);
|
|
|
|
else
|
|
|
|
PinSet(PORT_RESET, PIN_RESET);
|
|
|
|
}
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static GFXINLINE void set_backlight(GDisplay *g, gU8 percent) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
(void) percent;
|
|
|
|
}
|
|
|
|
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void acquire_bus(GDisplay *g) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_GETBUS();
|
2015-02-06 15:14:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 08:24:49 +00:00
|
|
|
static GFXINLINE void release_bus(GDisplay *g) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_WAITCOMPLETE();
|
|
|
|
SPI_RELEASEBUS();
|
2015-02-06 15:14:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static GFXINLINE void write_cmd(GDisplay *g, gU8 cmd) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
|
|
|
|
// Command mode please
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_WAITCOMPLETE();
|
2015-02-06 15:14:16 +00:00
|
|
|
PinClear(PORT_DC, PIN_DC);
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_WRITEBYTE(cmd);
|
2015-02-06 15:14:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static GFXINLINE void write_data(GDisplay *g, gU8* data, gU16 length) {
|
2015-02-06 15:14:16 +00:00
|
|
|
(void) g;
|
|
|
|
|
|
|
|
// Data mode please
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_WAITCOMPLETE();
|
2015-02-06 15:14:16 +00:00
|
|
|
PinSet(PORT_DC, PIN_DC);
|
|
|
|
|
2015-02-07 11:58:24 +00:00
|
|
|
SPI_WRITEBYTES(data, length);
|
2015-02-06 15:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _GDISP_LLD_BOARD_H */
|