From: Robin Krens Date: Mon, 16 Sep 2019 09:46:16 +0000 (+0700) Subject: st7735s: signs of life X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=a45e9d29077fac0f124a02ad75f6a7dd60218b06;p=cortex-from-scratch st7735s: signs of life --- diff --git a/Makefile b/Makefile index 3eb5eed..630c2be 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ _OBJ = ivt.o systick.o sysinfo.o term.o main.o clock.o rtc.o OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ)) DDIR = obj/drivers -_DRIVERS = uart.o tm1637.o led.o tsensor.o at24c.o mk450_joystick.o +_DRIVERS = uart.o tm1637.o led.o tsensor.o at24c.o mk450_joystick.o st7735s.o DRIVERS = $(patsubst %, $(DDIR)/%,$(_DRIVERS)) LDIR = obj/lib diff --git a/drivers/st7735s.c b/drivers/st7735s.c new file mode 100644 index 0000000..bf6c763 --- /dev/null +++ b/drivers/st7735s.c @@ -0,0 +1,65 @@ +/* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL + * + * $LOG$ + * 2019/9/14 - ROBIN KRENS + * Initial version + * + * $DESCRIPTION$ + * + * $USAGE$ + * + * */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +void tft_command(); +void tft_init() { + + /* Peripherial init */ + rsetbit(RCC_APB1ENR, 14); // enable SPI2 + rsetbit(RCC_APB2ENR, 3); // enable GPIOB + + /* The PINS used are respective PB12, PB13 and PB15 + * NSS (or CS): alternative function pusp-pull + * NSS Output is (always high) enabled with this setting + * SCK Master: alternate function push-pull + * MOSI (or DI): alternate function push-pull */ + rwrite(GPIOB_CRH, 0xA4AA4444); + + /* Chip select: software enabled */ + rsetbit(SPI2_CR1, 9); + rsetbit(SPI2_CR1, 8); + + // LOW and first edge: standard settings + + rsetbit(SPI2_CR1, 15); // one-wire mode + rsetbit(SPI2_CR1, 14); // start with transfer + rsetbit(SPI2_CR1, 4); // FPLCK div 8 + rsetbit(SPI2_CR1, 2); // master selection + rsetbit(SPI2_CR1, 6); // enable SPI + + tft_command(); + +} + + +void tft_command() { + + /* 9-bit hack */ + uint8_t cmd = 0x0A; + + rwrite(SPI2_DR, cmd); + while (!rchkbit(SPI2_SR, 1)); + rclrbit(SPI2_CR1, 14); // receive +} diff --git a/include/drivers/st7735s.h b/include/drivers/st7735s.h new file mode 100644 index 0000000..d345c10 --- /dev/null +++ b/include/drivers/st7735s.h @@ -0,0 +1,7 @@ +#ifndef __ST7735S_H +#define __ST7735S_H + +extern void tft_init(); + +#endif + diff --git a/include/sys/mmap.h b/include/sys/mmap.h index 4275bc7..4af5c35 100644 --- a/include/sys/mmap.h +++ b/include/sys/mmap.h @@ -73,6 +73,7 @@ #define GPIOA_CRL MEM_ADDR(0x40010800) // for ADC1 #define GPIOA_ODR MEM_ADDR(0x4001080C) #define GPIOB_CRL MEM_ADDR(0x40010C00) // low register (!) for I2C1 +#define GPIOB_CRH MEM_ADDR(0x40010C04) // high register for SPI2 #define GPIOB_BSRR MEM_ADDR(0x40010C10) #define GPIOB_ODR MEM_ADDR(0x40010C0C) #define GPIOB_IDR MEM_ADDR(0x40010C08) @@ -85,7 +86,7 @@ #define AFIO_EVCR MEM_ADDR(0x40010000) -/* I2C REGISTER */ +/* I2C REGISTERS */ #define I2C_CR1 MEM_ADDR(0x40005400) #define I2C_CR2 MEM_ADDR(0x40005404) #define I2C_DR MEM_ADDR(0x40005410) @@ -94,6 +95,14 @@ #define I2C_CCR MEM_ADDR(0x4000541C) #define I2C_TRISE MEM_ADDR(0x40005420) +/* SPI2 REGISTERS */ +#define SPI2_CR1 MEM_ADDR(0x40003800) +#define SPI2_CR2 MEM_ADDR(0x40003804) +#define SPI2_SR MEM_ADDR(0x40003808) +#define SPI2_DR MEM_ADDR(0x4000380C) +#define SPI2_CFGR MEM_ADDR(0x4000381C) +#define SPI2_PR MEM_ADDR(0x40003820) + /* EXTERNAL INTERRUPTS */ #define EXTI_IMR MEM_ADDR(0x40010400) #define EXTI_RTSR MEM_ADDR(0x40010408) diff --git a/main.c b/main.c index bcbf6f1..8de2880 100644 --- a/main.c +++ b/main.c @@ -26,7 +26,8 @@ //#include //#include //#include -#include +//#include +#include void main() { @@ -78,6 +79,9 @@ void main() /* ADC Joystick module */ // mk450_init(); + /* TFT screen */ + tft_init(); + /* Start up terminal */ terminal();