From 8775caf20ce7c0a776b9f66c5b287b077c8afcee Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 4 Sep 2022 18:25:23 +0200 Subject: driver for lcd: ili9806e and gt911 --- fw/fe310/eos/soc/Makefile | 2 +- fw/fe310/eos/soc/spi9bit.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ fw/fe310/eos/soc/spi9bit.h | 4 ++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 fw/fe310/eos/soc/spi9bit.c create mode 100644 fw/fe310/eos/soc/spi9bit.h (limited to 'fw/fe310/eos/soc') diff --git a/fw/fe310/eos/soc/Makefile b/fw/fe310/eos/soc/Makefile index 1404c81..f5f072a 100644 --- a/fw/fe310/eos/soc/Makefile +++ b/fw/fe310/eos/soc/Makefile @@ -1,7 +1,7 @@ include ../../common.mk CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -obj = trap_entry.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o +obj = trap_entry.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o spi9bit.o lib = ../../libeos-soc.a diff --git a/fw/fe310/eos/soc/spi9bit.c b/fw/fe310/eos/soc/spi9bit.c new file mode 100644 index 0000000..712dc81 --- /dev/null +++ b/fw/fe310/eos/soc/spi9bit.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include "encoding.h" +#include "platform.h" + +#include "eos.h" + +#include "spi9bit.h" + +#define BIT_GET ((GPIO_REG(GPIO_INPUT_VAL) & (1 << IOF_SPI1_MISO)) >> IOF_SPI1_MISO) +#define BIT_PUT(b) { if (b) GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI); else GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << IOF_SPI1_MOSI); } + +#define SCK_UP { GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_SCK); } +#define SCK_DN { GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << IOF_SPI1_SCK); } + +static inline void _sleep(int n) { + volatile int x = n; + + while(x) x--; +} + +/* sck frequency for r/w operations is 0.8Mhz */ +void eos_spi9bit_read(uint8_t *data) { + int i; + + *data = 0; + for (i=0; i<8; i++) { + _sleep(10); + *data = *data << 1; + *data |= BIT_GET; + SCK_UP; + _sleep(10); + SCK_DN; + } +} + +void eos_spi9bit_write(uint8_t dc, uint8_t data) { + int i; + + BIT_PUT(dc); + _sleep(10); + SCK_UP; + for (i=0; i<8; i++) { + _sleep(10); + SCK_DN; + BIT_PUT(data & 0x80); + _sleep(10); + SCK_UP; + data = data << 1; + } + _sleep(10); + SCK_DN; + BIT_PUT(0); +} diff --git a/fw/fe310/eos/soc/spi9bit.h b/fw/fe310/eos/soc/spi9bit.h new file mode 100644 index 0000000..dd3c254 --- /dev/null +++ b/fw/fe310/eos/soc/spi9bit.h @@ -0,0 +1,4 @@ +#include + +void eos_spi9bit_read(uint8_t *data); +void eos_spi9bit_write(uint8_t dc, uint8_t data); -- cgit v1.2.3