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
--- /dev/null
+/* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
+ *
+ * $LOG$
+ * 2019/9/14 - ROBIN KRENS
+ * Initial version
+ *
+ * $DESCRIPTION$
+ *
+ * $USAGE$
+ *
+ * */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <sys/mmap.h>
+#include <sys/robsys.h>
+
+#include <lib/regfunc.h>
+#include <lib/string.h>
+#include <lib/tinyprintf.h>
+
+#include <drivers/st7735s.h>
+
+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
+}
--- /dev/null
+#ifndef __ST7735S_H
+#define __ST7735S_H
+
+extern void tft_init();
+
+#endif
+
#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)
#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)
#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)
//#include <drivers/tm1637.h>
//#include <drivers/at24c.h>
//#include <drivers/tsensor.h>
-#include <drivers/mk450_joystick.h>
+//#include <drivers/mk450_joystick.h>
+#include <drivers/st7735s.h>
void main()
{
/* ADC Joystick module */
// mk450_init();
+ /* TFT screen */
+ tft_init();
+
/* Start up terminal */
terminal();