@@ -777,3 +777,147 @@ static void tft_controller_init(void) {
777777}
778778
779779#endif
780+
781+ #ifdef DISPLAY_CONTROLLER_ST7735
782+
783+ #define ST_CMD_DELAY 0x80 // special signifier for command lists
784+
785+ // ST77XX common commands (shared with ST7789)
786+ #define ST77XX_NOP 0x00
787+ #define ST77XX_SWRESET 0x01
788+ #define ST77XX_RDDID 0x04
789+ #define ST77XX_RDDST 0x09
790+
791+ #define ST77XX_SLPIN 0x10
792+ #define ST77XX_SLPOUT 0x11
793+ #define ST77XX_PTLON 0x12
794+ #define ST77XX_NORON 0x13
795+
796+ #define ST77XX_INVOFF 0x20
797+ #define ST77XX_INVON 0x21
798+ #define ST77XX_DISPOFF 0x28
799+ #define ST77XX_DISPON 0x29
800+ #define ST77XX_CASET 0x2A
801+ #define ST77XX_RASET 0x2B
802+ #define ST77XX_RAMWR 0x2C
803+ #define ST77XX_RAMRD 0x2E
804+
805+ #define ST77XX_PTLAR 0x30
806+ #define ST77XX_TEOFF 0x34
807+ #define ST77XX_TEON 0x35
808+ #define ST77XX_MADCTL 0x36
809+ #define ST77XX_VSCSAD 0x37
810+ #define ST77XX_COLMOD 0x3A
811+
812+ #define ST77XX_MADCTL_MY 0x80
813+ #define ST77XX_MADCTL_MX 0x40
814+ #define ST77XX_MADCTL_MV 0x20
815+ #define ST77XX_MADCTL_ML 0x10
816+ #define ST77XX_MADCTL_RGB 0x00
817+
818+ #define ST77XX_RDID1 0xDA
819+ #define ST77XX_RDID2 0xDB
820+ #define ST77XX_RDID3 0xDC
821+ #define ST77XX_RDID4 0xDD
822+
823+ // ST7735-specific commands
824+ #define ST7735_FRMCTR1 0xB1
825+ #define ST7735_FRMCTR2 0xB2
826+ #define ST7735_FRMCTR3 0xB3
827+ #define ST7735_INVCTR 0xB4
828+ #define ST7735_PWCTR1 0xC0
829+ #define ST7735_PWCTR2 0xC1
830+ #define ST7735_PWCTR3 0xC2
831+ #define ST7735_PWCTR4 0xC3
832+ #define ST7735_PWCTR5 0xC4
833+ #define ST7735_VMCTR1 0xC5
834+ #define ST7735_GMCTRP1 0xE0
835+ #define ST7735_GMCTRN1 0xE1
836+ #define ST7735_MADCTL_BGR 0x08
837+
838+ // Some ready-made 16-bit ('565') color settings:
839+ #define ST77XX_BLACK 0x0000
840+ #define ST77XX_WHITE 0xFFFF
841+ #define ST77XX_RED 0xF800
842+ #define ST77XX_GREEN 0x07E0
843+ #define ST77XX_BLUE 0x001F
844+ #define ST77XX_CYAN 0x07FF
845+ #define ST77XX_MAGENTA 0xF81F
846+ #define ST77XX_YELLOW 0xFFE0
847+ #define ST77XX_ORANGE 0xFC00
848+
849+ static void tft_controller_init (void ) {
850+ // Init commands for ST7735 mini 160x80 screens
851+ // Based on Adafruit INITR_MINI160x80 sequence
852+ uint8_t cmdinit_st7735 [] = {
853+ #if !defined (DISPLAY_PIN_RST ) || (DISPLAY_PIN_RST < 0 )
854+ // Software reset if rst pin not available
855+ ST77XX_SWRESET , ST_CMD_DELAY , 150 ,
856+ #endif
857+ // Out of sleep mode, w/delay 255 = 500ms
858+ ST77XX_SLPOUT , ST_CMD_DELAY , 255 ,
859+ // Frame rate control - normal mode (3 args)
860+ ST7735_FRMCTR1 , 3 , 0x01 , 0x2C , 0x2D ,
861+ // Frame rate control - idle mode (3 args)
862+ ST7735_FRMCTR2 , 3 , 0x01 , 0x2C , 0x2D ,
863+ // Frame rate control - partial mode (6 args)
864+ ST7735_FRMCTR3 , 6 , 0x01 , 0x2C , 0x2D , 0x01 , 0x2C , 0x2D ,
865+ // Display inversion control (1 arg)
866+ ST7735_INVCTR , 1 , 0x07 ,
867+ // Power control 1 (3 args)
868+ ST7735_PWCTR1 , 3 , 0xA2 , 0x02 , 0x84 ,
869+ // Power control 2 (1 arg)
870+ ST7735_PWCTR2 , 1 , 0xC5 ,
871+ // Power control 3 - normal mode (2 args)
872+ ST7735_PWCTR3 , 2 , 0x0A , 0x00 ,
873+ // Power control 4 - idle mode (2 args)
874+ ST7735_PWCTR4 , 2 , 0x8A , 0x2A ,
875+ // Power control 5 - partial mode (2 args)
876+ ST7735_PWCTR5 , 2 , 0x8A , 0xEE ,
877+ // VCOM control (1 arg)
878+ ST7735_VMCTR1 , 1 , 0x0E ,
879+ // Inversion off (required for Heltec T096)
880+ ST77XX_INVOFF , 0 ,
881+ // Set color mode, 1 arg: 16-bit color (0x05 for ST7735)
882+ ST77XX_COLMOD , 1 + ST_CMD_DELAY , 0x05 , 10 ,
883+ // Mem access ctrl, 1 arg: row/col addr, color order
884+ ST77XX_MADCTL , 1 , DISPLAY_MADCTL ,
885+ // Column addr set, 4 args: XSTART/XEND (132 wide framebuffer)
886+ ST77XX_CASET , 4 , 0x00 , 0x00 , 0x00 , 0x83 ,
887+ // Row addr set, 4 args: YSTART/YEND (162 tall framebuffer)
888+ ST77XX_RASET , 4 , 0x00 , 0x00 , 0x00 , 0xA1 ,
889+ // Positive gamma correction (16 args)
890+ ST7735_GMCTRP1 , 16 ,
891+ 0x02 , 0x1C , 0x07 , 0x12 , 0x37 , 0x32 , 0x29 , 0x2D ,
892+ 0x29 , 0x25 , 0x2B , 0x39 , 0x00 , 0x01 , 0x03 , 0x10 ,
893+ // Negative gamma correction (16 args)
894+ ST7735_GMCTRN1 , 16 ,
895+ 0x03 , 0x1D , 0x07 , 0x06 , 0x2E , 0x2C , 0x29 , 0x2D ,
896+ 0x2E , 0x2E , 0x37 , 0x3F , 0x00 , 0x00 , 0x02 , 0x10 ,
897+ // Normal display on, w/delay 10ms
898+ ST77XX_NORON , ST_CMD_DELAY , 10 ,
899+ // Main screen turn on, w/delay 100ms
900+ ST77XX_DISPON , ST_CMD_DELAY , 100
901+ };
902+
903+ size_t count = 0 ;
904+ while (count < sizeof (cmdinit_st7735 )) {
905+ uint8_t const cmd = cmdinit_st7735 [count ++ ];
906+ uint8_t const cmd_arg = cmdinit_st7735 [count ++ ];
907+ uint8_t const has_delay = cmd_arg & ST_CMD_DELAY ;
908+ uint8_t const narg = cmd_arg & ~ST_CMD_DELAY ;
909+
910+ tft_cmd (cmd , cmdinit_st7735 + count , narg );
911+ count += narg ;
912+
913+ if (has_delay ) {
914+ uint16_t delay = (uint16_t ) cmdinit_st7735 [count ++ ];
915+ if (delay == 255 ) {
916+ delay = 500 ; // If 255, delay for 500 ms
917+ }
918+ NRFX_DELAY_MS (delay );
919+ }
920+ }
921+ }
922+
923+ #endif
0 commit comments