Finish st7781 driver.
This commit is contained in:
@@ -130,6 +130,22 @@ device picga0 at spi1 pin RA4 # chip select signal
|
|||||||
options "PICGA_BUS=SPI1CON" # TODO: delete this option
|
options "PICGA_BUS=SPI1CON" # TODO: delete this option
|
||||||
signal "PICGA_CS" pin RA4 # TODO: delete
|
signal "PICGA_CS" pin RA4 # TODO: delete
|
||||||
|
|
||||||
|
# ST7781 TFT display driver
|
||||||
|
device swtft
|
||||||
|
signal "LCD_RST" pin RB10
|
||||||
|
signal "LCD_CS" pin RB0
|
||||||
|
signal "LCD_RD" pin RB2
|
||||||
|
signal "LCD_RS" pin RB8
|
||||||
|
signal "LCD_WR" pin RB4
|
||||||
|
signal "LCD_D0" pin RA14
|
||||||
|
signal "LCD_D1" pin RD3
|
||||||
|
signal "LCD_D2" pin RE8
|
||||||
|
signal "LCD_D3" pin RD0
|
||||||
|
signal "LCD_D4" pin RF0
|
||||||
|
signal "LCD_D5" pin RD1
|
||||||
|
signal "LCD_D6" pin RD2
|
||||||
|
signal "LCD_D7" pin RE9
|
||||||
|
|
||||||
#--------------------------------------------
|
#--------------------------------------------
|
||||||
# Custom RAM disk devices
|
# Custom RAM disk devices
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -67,7 +67,19 @@ static int _col, _row;
|
|||||||
|
|
||||||
#define WR_IDLE() LAT_SET(LCD_WR_PORT) = 1<<LCD_WR_PIN
|
#define WR_IDLE() LAT_SET(LCD_WR_PORT) = 1<<LCD_WR_PIN
|
||||||
#define WR_ACTIVE() LAT_CLR(LCD_WR_PORT) = 1<<LCD_WR_PIN
|
#define WR_ACTIVE() LAT_CLR(LCD_WR_PORT) = 1<<LCD_WR_PIN
|
||||||
#define WR_STROBE() { WR_ACTIVE(); WR_IDLE(); }
|
#define WR_STROBE() { WR_ACTIVE(); ndelay(50); WR_IDLE(); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delay for a given number of nanoseconds.
|
||||||
|
*/
|
||||||
|
void ndelay(unsigned nsec)
|
||||||
|
{
|
||||||
|
/* Four instructions (cycles) per loop. */
|
||||||
|
unsigned nloops = (nsec * (CPU_KHZ/1000)) / 1000 / 4;
|
||||||
|
|
||||||
|
while (nloops-- > 0)
|
||||||
|
asm volatile ("nop");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set direction of data bus as output.
|
* Set direction of data bus as output.
|
||||||
@@ -147,26 +159,12 @@ static void writeByte(unsigned value)
|
|||||||
WR_STROBE();
|
WR_STROBE();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Delay for a given number of nanoseconds.
|
|
||||||
*/
|
|
||||||
void ndelay(unsigned nsec)
|
|
||||||
{
|
|
||||||
/* Four instructions (cycles) per loop. */
|
|
||||||
unsigned nloops = (nsec * (CPU_KHZ/1000)) / 1000 / 4;
|
|
||||||
|
|
||||||
while (nloops-- > 0)
|
|
||||||
asm volatile ("nop");
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned readByte()
|
static unsigned readByte()
|
||||||
{
|
{
|
||||||
unsigned value = 0;
|
unsigned value = 0;
|
||||||
|
|
||||||
/* Pixel read operations require a minimum 400 nS delay
|
|
||||||
* from RD_ACTIVE to polling the input pins. */
|
|
||||||
RD_ACTIVE();
|
RD_ACTIVE();
|
||||||
ndelay(400);
|
ndelay(100);
|
||||||
if (PORT_VAL(LCD_D0_PORT) & (1 << LCD_D0_PIN)) value |= 1;
|
if (PORT_VAL(LCD_D0_PORT) & (1 << LCD_D0_PIN)) value |= 1;
|
||||||
if (PORT_VAL(LCD_D1_PORT) & (1 << LCD_D1_PIN)) value |= 2;
|
if (PORT_VAL(LCD_D1_PORT) & (1 << LCD_D1_PIN)) value |= 2;
|
||||||
if (PORT_VAL(LCD_D2_PORT) & (1 << LCD_D2_PIN)) value |= 4;
|
if (PORT_VAL(LCD_D2_PORT) & (1 << LCD_D2_PIN)) value |= 4;
|
||||||
@@ -192,6 +190,26 @@ static void writeReg(unsigned reg, unsigned value)
|
|||||||
writeByte(value);
|
writeByte(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read device ID code.
|
||||||
|
*/
|
||||||
|
static unsigned readDeviceId()
|
||||||
|
{
|
||||||
|
unsigned value;
|
||||||
|
|
||||||
|
CS_ACTIVE();
|
||||||
|
RS_COMMAND();
|
||||||
|
writeByte(0x00);
|
||||||
|
WR_STROBE(); // Repeat prior byte (0x00)
|
||||||
|
setReadDir(); // Switch data bus as input
|
||||||
|
RS_DATA();
|
||||||
|
value = readByte() << 8;
|
||||||
|
value |= readByte();
|
||||||
|
setWriteDir(); // Restore data bus as output
|
||||||
|
CS_IDLE();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
static void initDisplay()
|
static void initDisplay()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -388,24 +406,24 @@ static void flood(int color, int npixels)
|
|||||||
/* 64 pixels/block. */
|
/* 64 pixels/block. */
|
||||||
blocks = npixels >> 6;
|
blocks = npixels >> 6;
|
||||||
if (hi == lo) {
|
if (hi == lo) {
|
||||||
// High and low bytes are identical. Leave prior data
|
/* High and low bytes are identical. Leave prior data
|
||||||
// on the port(s) and just toggle the write strobe.
|
* on the port(s) and just toggle the write strobe. */
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
// 64 pixels/block / 4 pixels/pass
|
/* 64 pixels/block / 4 pixels/pass. */
|
||||||
for (i = 16; i > 0; i--) {
|
for (i = 16; i > 0; i--) {
|
||||||
// 2 bytes/pixel x 4 pixels
|
/* 2 bytes/pixel x 4 pixels. */
|
||||||
WR_STROBE(); WR_STROBE(); WR_STROBE(); WR_STROBE();
|
WR_STROBE(); WR_STROBE(); WR_STROBE(); WR_STROBE();
|
||||||
WR_STROBE(); WR_STROBE(); WR_STROBE(); WR_STROBE();
|
WR_STROBE(); WR_STROBE(); WR_STROBE(); WR_STROBE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fill any remaining pixels (1 to 64)
|
/* Fill any remaining pixels (1 to 64). */
|
||||||
for (i = npixels & 63; i > 0; i--) {
|
for (i = npixels & 63; i > 0; i--) {
|
||||||
WR_STROBE();
|
WR_STROBE();
|
||||||
WR_STROBE();
|
WR_STROBE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
// 64 pixels/block / 4 pixels/pass
|
/* 64 pixels/block / 4 pixels/pass. */
|
||||||
for (i = 16; i > 0; i--) {
|
for (i = 16; i > 0; i--) {
|
||||||
writeByte(hi); writeByte(lo); writeByte(hi); writeByte(lo);
|
writeByte(hi); writeByte(lo); writeByte(hi); writeByte(lo);
|
||||||
writeByte(hi); writeByte(lo); writeByte(hi); writeByte(lo);
|
writeByte(hi); writeByte(lo); writeByte(hi); writeByte(lo);
|
||||||
@@ -837,26 +855,6 @@ int gpanel_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Read device ID code.
|
|
||||||
*/
|
|
||||||
static unsigned readDeviceId()
|
|
||||||
{
|
|
||||||
unsigned value;
|
|
||||||
|
|
||||||
CS_ACTIVE();
|
|
||||||
RS_COMMAND();
|
|
||||||
writeByte(0x00);
|
|
||||||
WR_STROBE(); // Repeat prior byte (0x00)
|
|
||||||
setReadDir(); // Switch data bus as input
|
|
||||||
RS_DATA();
|
|
||||||
value = readByte() << 8;
|
|
||||||
value |= readByte();
|
|
||||||
setWriteDir(); // Restore data bus as output
|
|
||||||
CS_IDLE();
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test to see if device is present.
|
* Test to see if device is present.
|
||||||
* Return true if found and initialized ok.
|
* Return true if found and initialized ok.
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
|
|||||||
|
|
||||||
# LEDs
|
# LEDs
|
||||||
signal "LED_KERNEL" pin RA0 # kernel activity indicator
|
signal "LED_KERNEL" pin RA0 # kernel activity indicator
|
||||||
signal "LED_DISK" pin RF0 # disk activity indicator
|
signal "LED_DISK" pin RA1 # disk activity indicator
|
||||||
signal "LED_TTY" pin RA1 # tty activity indicator
|
|
||||||
|
|
||||||
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||||
config unix root on sd0a
|
config unix root on sd0a
|
||||||
@@ -46,14 +45,18 @@ options "SD_MHZ=10" # speed 10 MHz
|
|||||||
# General purpose I/O ports
|
# General purpose I/O ports
|
||||||
# Flags define a mask of available pins
|
# Flags define a mask of available pins
|
||||||
# The following pins excluded:
|
# The following pins excluded:
|
||||||
# RF2, RF8 - uart1
|
# RF2, RF8 - uart1
|
||||||
# RG6, RG7, RG8, RD4 - spi2, SD card
|
# RG6, RG7, RG8, RD4 - spi2, SD card
|
||||||
device gpio0 flags 0xc6ff # port A
|
# RA14, RB0, RB2, RB4,
|
||||||
device gpio1 flags 0xffff # port B
|
# RB8, RB10, RD0, RD1,
|
||||||
|
# RD2, RD3, RE8, RE9, RF0 - LCD display
|
||||||
|
#
|
||||||
|
device gpio0 flags 0x86ff # port A
|
||||||
|
device gpio1 flags 0xfaea # port B
|
||||||
device gpio2 flags 0xf01e # port C
|
device gpio2 flags 0xf01e # port C
|
||||||
device gpio3 flags 0xffef # port D
|
device gpio3 flags 0xffe0 # port D
|
||||||
device gpio4 flags 0x03ff # port E
|
device gpio4 flags 0x00ff # port E
|
||||||
device gpio5 flags 0x303b # port F
|
device gpio5 flags 0x303a # port F
|
||||||
device gpio6 flags 0xf20f # port G
|
device gpio6 flags 0xf20f # port G
|
||||||
|
|
||||||
# ADC driver
|
# ADC driver
|
||||||
@@ -61,19 +64,3 @@ device adc
|
|||||||
|
|
||||||
# PWM driver
|
# PWM driver
|
||||||
device pwm
|
device pwm
|
||||||
|
|
||||||
# ST7781 TFT display driver
|
|
||||||
device swtft
|
|
||||||
signal "LCD_RST" pin RB10
|
|
||||||
signal "LCD_CS" pin RB0
|
|
||||||
signal "LCD_RD" pin RB2
|
|
||||||
signal "LCD_RS" pin RB8
|
|
||||||
signal "LCD_WR" pin RB4
|
|
||||||
signal "LCD_D0" pin RA14
|
|
||||||
signal "LCD_D1" pin RD3
|
|
||||||
signal "LCD_D2" pin RE8
|
|
||||||
signal "LCD_D3" pin RD0
|
|
||||||
signal "LCD_D4" pin RF0
|
|
||||||
signal "LCD_D5" pin RD1
|
|
||||||
signal "LCD_D6" pin RD2
|
|
||||||
signal "LCD_D7" pin RE9
|
|
||||||
|
|||||||
82
sys/pic32/wf32/Config-swtft
Normal file
82
sys/pic32/wf32/Config-swtft
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#
|
||||||
|
# chipKIT WF32 board with microSD card on 2.4" LCD TFT display shield
|
||||||
|
#
|
||||||
|
# To build the kernel, use:
|
||||||
|
# cd sys/pic32/wf32
|
||||||
|
# kconfig Config
|
||||||
|
# make clean
|
||||||
|
# make
|
||||||
|
#
|
||||||
|
# Format of this file is described on page:
|
||||||
|
# http://retrobsd.org/wiki/doku.php/doc/kconfig
|
||||||
|
#
|
||||||
|
architecture "pic32"
|
||||||
|
cpu "PIC32MX7" # Processor variant
|
||||||
|
board "WF32" # Board type
|
||||||
|
ldscript "max32/bootloader.ld" # Linker script
|
||||||
|
|
||||||
|
# Standard system options
|
||||||
|
options "CPU_KHZ=80000" # Oscillator frequency of CPU core
|
||||||
|
options "BUS_KHZ=80000" # Frequency of peripheral bus
|
||||||
|
options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
|
||||||
|
|
||||||
|
# LEDs
|
||||||
|
signal "LED_KERNEL" pin RA0 # kernel activity indicator
|
||||||
|
signal "LED_DISK" pin RA1 # disk activity indicator
|
||||||
|
|
||||||
|
# Root filesystem at /dev/sd0a, swap at /dev/sd0b
|
||||||
|
config unix root on sd0a
|
||||||
|
swap on sd0b
|
||||||
|
|
||||||
|
# Serial UART ports
|
||||||
|
device uart1 # Serial-to-USB converter
|
||||||
|
|
||||||
|
# Console options
|
||||||
|
options "CONS_MAJOR=UART_MAJOR" # UART device
|
||||||
|
options "CONS_MINOR=0" # /dev/tty0
|
||||||
|
|
||||||
|
# SPI ports
|
||||||
|
controller spi2 # SD card
|
||||||
|
|
||||||
|
# microSD card
|
||||||
|
device sd0 at spi2 pin RD4 # select pin RD4
|
||||||
|
options "SD_MHZ=10" # speed 10 MHz
|
||||||
|
|
||||||
|
# General purpose I/O ports
|
||||||
|
# Flags define a mask of available pins
|
||||||
|
# The following pins excluded:
|
||||||
|
# RF2, RF8 - uart1
|
||||||
|
# RG6, RG7, RG8, RD4 - spi2, SD card
|
||||||
|
# RA14, RB0, RB2, RB4,
|
||||||
|
# RB8, RB10, RD0, RD1,
|
||||||
|
# RD2, RD3, RE8, RE9, RF0 - LCD display
|
||||||
|
#
|
||||||
|
device gpio0 flags 0x86ff # port A
|
||||||
|
device gpio1 flags 0xfaea # port B
|
||||||
|
device gpio2 flags 0xf01e # port C
|
||||||
|
device gpio3 flags 0xffe0 # port D
|
||||||
|
device gpio4 flags 0x00ff # port E
|
||||||
|
device gpio5 flags 0x303a # port F
|
||||||
|
device gpio6 flags 0xf20f # port G
|
||||||
|
|
||||||
|
# ADC driver
|
||||||
|
device adc
|
||||||
|
|
||||||
|
# PWM driver
|
||||||
|
device pwm
|
||||||
|
|
||||||
|
# ST7781 TFT display driver
|
||||||
|
device swtft
|
||||||
|
signal "LCD_RST" pin RB10
|
||||||
|
signal "LCD_CS" pin RB0
|
||||||
|
signal "LCD_RD" pin RB2
|
||||||
|
signal "LCD_RS" pin RB8
|
||||||
|
signal "LCD_WR" pin RB4
|
||||||
|
signal "LCD_D0" pin RA14
|
||||||
|
signal "LCD_D1" pin RD3
|
||||||
|
signal "LCD_D2" pin RE8
|
||||||
|
signal "LCD_D3" pin RD0
|
||||||
|
signal "LCD_D4" pin RF0
|
||||||
|
signal "LCD_D5" pin RD1
|
||||||
|
signal "LCD_D6" pin RD2
|
||||||
|
signal "LCD_D7" pin RE9
|
||||||
@@ -12,22 +12,7 @@ PARAM += -DGPIO5_ENABLED
|
|||||||
PARAM += -DGPIO6_ENABLED
|
PARAM += -DGPIO6_ENABLED
|
||||||
PARAM += -DADC_ENABLED
|
PARAM += -DADC_ENABLED
|
||||||
PARAM += -DPWM_ENABLED
|
PARAM += -DPWM_ENABLED
|
||||||
PARAM += -DSWTFT_ENABLED
|
PARAM += -DLED_DISK_PORT=TRISA -DLED_DISK_PIN=1
|
||||||
PARAM += -DLCD_D7_PORT=TRISE -DLCD_D7_PIN=9
|
|
||||||
PARAM += -DLCD_D6_PORT=TRISD -DLCD_D6_PIN=2
|
|
||||||
PARAM += -DLCD_D5_PORT=TRISD -DLCD_D5_PIN=1
|
|
||||||
PARAM += -DLCD_D4_PORT=TRISF -DLCD_D4_PIN=0
|
|
||||||
PARAM += -DLCD_D3_PORT=TRISD -DLCD_D3_PIN=0
|
|
||||||
PARAM += -DLCD_D2_PORT=TRISE -DLCD_D2_PIN=8
|
|
||||||
PARAM += -DLCD_D1_PORT=TRISD -DLCD_D1_PIN=3
|
|
||||||
PARAM += -DLCD_D0_PORT=TRISA -DLCD_D0_PIN=14
|
|
||||||
PARAM += -DLCD_WR_PORT=TRISB -DLCD_WR_PIN=4
|
|
||||||
PARAM += -DLCD_RS_PORT=TRISB -DLCD_RS_PIN=8
|
|
||||||
PARAM += -DLCD_RD_PORT=TRISB -DLCD_RD_PIN=2
|
|
||||||
PARAM += -DLCD_CS_PORT=TRISB -DLCD_CS_PIN=0
|
|
||||||
PARAM += -DLCD_RST_PORT=TRISB -DLCD_RST_PIN=10
|
|
||||||
PARAM += -DLED_TTY_PORT=TRISA -DLED_TTY_PIN=1
|
|
||||||
PARAM += -DLED_DISK_PORT=TRISF -DLED_DISK_PIN=0
|
|
||||||
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=0
|
PARAM += -DLED_KERNEL_PORT=TRISA -DLED_KERNEL_PIN=0
|
||||||
PARAM += -DSD_MHZ=10
|
PARAM += -DSD_MHZ=10
|
||||||
PARAM += -DCONS_MINOR=0
|
PARAM += -DCONS_MINOR=0
|
||||||
@@ -80,7 +65,7 @@ OBJS = exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o \
|
|||||||
ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o \
|
ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o \
|
||||||
vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o clock.o cons.o devsw.o \
|
vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o clock.o cons.o devsw.o \
|
||||||
exception.o machdep.o mem.o signal.o swap.o sysctl.o adc.o \
|
exception.o machdep.o mem.o signal.o swap.o sysctl.o adc.o \
|
||||||
gpio.o pwm.o sd.o st7781.o spi.o spi_bus.o uart.o
|
gpio.o pwm.o sd.o spi.o spi_bus.o uart.o
|
||||||
|
|
||||||
CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
|
CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
|
||||||
$S/kernel/exec_script.c $S/kernel/exec_subr.c \
|
$S/kernel/exec_script.c $S/kernel/exec_subr.c \
|
||||||
@@ -106,8 +91,8 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
|
|||||||
$S/pic32/devsw.c $S/pic32/exception.c $S/pic32/machdep.c \
|
$S/pic32/devsw.c $S/pic32/exception.c $S/pic32/machdep.c \
|
||||||
$S/pic32/mem.c $S/pic32/signal.c $S/pic32/swap.c \
|
$S/pic32/mem.c $S/pic32/signal.c $S/pic32/swap.c \
|
||||||
$S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/gpio.c $S/pic32/pwm.c \
|
$S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/gpio.c $S/pic32/pwm.c \
|
||||||
$S/pic32/sd.c $S/pic32/st7781.c $S/pic32/spi.c \
|
$S/pic32/sd.c $S/pic32/spi.c $S/pic32/spi_bus.c $S/pic32/uart.c \
|
||||||
$S/pic32/spi_bus.c $S/pic32/uart.c swapunix.c
|
swapunix.c
|
||||||
|
|
||||||
# load lines for config "xxx" will be emitted as:
|
# load lines for config "xxx" will be emitted as:
|
||||||
# xxx: ${SYSTEM_DEP} swapxxx.o
|
# xxx: ${SYSTEM_DEP} swapxxx.o
|
||||||
@@ -351,9 +336,6 @@ pwm.o: $S/pic32/pwm.c
|
|||||||
sd.o: $S/pic32/sd.c
|
sd.o: $S/pic32/sd.c
|
||||||
${COMPILE_C}
|
${COMPILE_C}
|
||||||
|
|
||||||
st7781.o: $S/pic32/st7781.c
|
|
||||||
${COMPILE_C}
|
|
||||||
|
|
||||||
spi.o: $S/pic32/spi.c
|
spi.o: $S/pic32/spi.c
|
||||||
${COMPILE_C}
|
${COMPILE_C}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user