Skip to content

Commit dd01f0c

Browse files
committed
Merge branch 'master' of [email protected]:btx000/Kenduino-core.git
2 parents 4ff6c1f + 5d48319 commit dd01f0c

File tree

12 files changed

+870
-1
lines changed

12 files changed

+870
-1
lines changed

cores/arduino/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ int main( void )
1515
pll_init();
1616
plic_init();
1717
uarths_init();
18+
gpio_init();
19+
sysctl_set_power_mode(SYSCTL_POWER_BANK6,SYSCTL_POWER_V18);
20+
sysctl_set_power_mode(SYSCTL_POWER_BANK7,SYSCTL_POWER_V18);
1821
setup();
1922

2023
do {

libraries/SPI/src/SPI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class SPIClass
6767

6868
void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
6969

70+
// special
71+
spi_id_t busId(){ return _spiNum; }
72+
7073
};
7174

7275
extern SPIClass SPI;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <Sipeed_ST7789.h>
2+
3+
SPIClass spi_(SPI0);
4+
Sipeed_ST7789 lcd(320, 240, spi_);
5+
6+
void setup()
7+
{
8+
lcd.begin(15000000, COLOR_BLACK);
9+
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
10+
lcd.drawCircle(100, 100, 40, COLOR_WHITE);
11+
lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE);
12+
}
13+
14+
void loop()
15+
{
16+
17+
}
18+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
Sipeed_ST7789 KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
begin KEYWORD2
15+
drawPixel KEYWORD2
16+
writePixel KEYWORD2
17+
writeFillRect KEYWORD2
18+
writeFastVLine KEYWORD2
19+
writeFastHLine KEYWORD2
20+
drawFastVLine KEYWORD2
21+
drawFastHLine KEYWORD2
22+
fillRect KEYWORD2
23+
fillScreen KEYWORD2
24+
drawRect KEYWORD2
25+
setRotation KEYWORD2
26+
invertDisplay KEYWORD2
27+
28+
#######################################
29+
# Constants (LITERAL1)
30+
#######################################
31+
32+
COLOR_BLACK LITERAL1
33+
COLOR_NAVY LITERAL1
34+
COLOR_DARKGREEN LITERAL1
35+
COLOR_DARKCYAN LITERAL1
36+
COLOR_MAROON LITERAL1
37+
COLOR_PURPLE LITERAL1
38+
COLOR_OLIVE LITERAL1
39+
COLOR_LIGHTGREY LITERAL1
40+
COLOR_DARKGREY LITERAL1
41+
COLOR_BLUE LITERAL1
42+
COLOR_GREEN LITERAL1
43+
COLOR_CYAN LITERAL1
44+
COLOR_RED LITERAL1
45+
COLOR_MAGENTA LITERAL1
46+
COLOR_YELLOW LITERAL1
47+
COLOR_WHITE LITERAL1
48+
COLOR_ORANGE LITERAL1
49+
COLOR_GREENYELLOW LITERAL1
50+
COLOR_PINK LITERAL1
51+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Sipeed_ST7789
2+
version=1.0
3+
author=Neucrack
4+
maintainer=Neucrack<[email protected]>
5+
sentence=LCD display st7789 driver
6+
paragraph=LCD display st7789 driver
7+
category=Display
8+
url=
9+
architectures=k210
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
#include "Sipeed_ST7789.h"
3+
#include "lcd.h"
4+
#include "sysctl.h"
5+
#include "utils.h"
6+
7+
Sipeed_ST7789::Sipeed_ST7789(uint16_t w, uint16_t h, SPIClass& spi, int8_t dc_pin, int8_t rst_pin, uint8_t dma_ch )
8+
:Adafruit_GFX(w,h),
9+
_spi(spi), _dcxPin(dc_pin), _rstPin(rst_pin),
10+
_dmaCh(dma_ch)
11+
{
12+
configASSERT(_spi.busId()==SPI0);
13+
}
14+
15+
Sipeed_ST7789::~Sipeed_ST7789(void)
16+
{
17+
18+
}
19+
20+
boolean Sipeed_ST7789::begin( uint32_t freq, uint16_t color )
21+
{
22+
uint8_t spiNum = _spi.busId();
23+
if( (spi_id_t)spiNum == SPI0)
24+
{
25+
fpioa_set_function(SIPEED_ST7789_SS_PIN , (fpioa_function_t)(FUNC_SPI0_SS0 + SIPEED_ST7789_SS));
26+
fpioa_set_function(SIPEED_ST7789_SCLK_PIN, (fpioa_function_t)FUNC_SPI0_SCLK);
27+
}
28+
else if((spi_id_t)spiNum == SPI1)
29+
{
30+
fpioa_set_function(SIPEED_ST7789_SS_PIN , (fpioa_function_t)(FUNC_SPI1_SS0 + SIPEED_ST7789_SS));
31+
fpioa_set_function(SIPEED_ST7789_SCLK_PIN, (fpioa_function_t)FUNC_SPI1_SCLK);
32+
}
33+
sysctl_set_spi0_dvp_data(1);
34+
_freq = freq;
35+
lcd_init(spiNum, SIPEED_ST7789_SS, SIPEED_ST7789_RST_GPIONUM, SIPEED_ST7789_DCX_GPIONUM, _freq, _rstPin, _dcxPin, _dmaCh);
36+
lcd_clear(color);
37+
return true;
38+
}
39+
40+
41+
void Sipeed_ST7789::drawPixel(int16_t x, int16_t y, uint16_t color)
42+
{
43+
lcd_draw_point(x, y, color);
44+
}
45+
void Sipeed_ST7789::writePixel(int16_t x, int16_t y, uint16_t color)
46+
{
47+
lcd_draw_point(x, y, color);
48+
}
49+
50+
void Sipeed_ST7789::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
51+
{
52+
lcd_fill_rectangle(x, y , x+w-1, y+h-1, color);
53+
}
54+
55+
void Sipeed_ST7789::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
56+
{
57+
lcd_fill_rectangle(x, y, x, y+h-1, color);
58+
}
59+
60+
void Sipeed_ST7789::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
61+
{
62+
lcd_fill_rectangle(x, y, x+w-1, y, color);
63+
}
64+
65+
void Sipeed_ST7789::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
66+
{
67+
lcd_fill_rectangle(x, y, x, y+h-1, color);
68+
}
69+
70+
void Sipeed_ST7789::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
71+
{
72+
lcd_fill_rectangle(x, y, x+w-1, y, color);
73+
}
74+
75+
void Sipeed_ST7789::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
76+
{
77+
lcd_fill_rectangle(x, y , x+w-1, y+h-1, color);
78+
}
79+
80+
void Sipeed_ST7789::fillScreen(uint16_t color)
81+
{
82+
lcd_clear(color);
83+
}
84+
85+
void Sipeed_ST7789::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
86+
{
87+
lcd_draw_rectangle(x, y, x+w-1, y+h-1, 1, color);
88+
}
89+
90+
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth)
91+
{
92+
lcd_draw_rectangle(x, y, x+w-1, y+h-1, lineWidth, color);
93+
}
94+
95+
96+
97+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef _SIPEED_ST7789_H
2+
#define _SIPEED_ST7789_H
3+
4+
5+
#include <SPI.h>
6+
#include <Adafruit_GFX.h>
7+
8+
9+
#if (defined(BOARD_SIPEED_MAIX_GO) || defined(BOARD_SIPEED_MAIX_ONE_DOCK) )
10+
#define SIPEED_ST7789_RST_PIN 37
11+
#define SIPEED_ST7789_DCX_PIN 38
12+
#define SIPEED_ST7789_SS_PIN 36
13+
#define SIPEED_ST7789_SCLK_PIN 39
14+
#else
15+
#define SIPEED_ST7789_RST_PIN 37
16+
#define SIPEED_ST7789_DCX_PIN 38
17+
#define SIPEED_ST7789_SS_PIN 36
18+
#define SIPEED_ST7789_SCLK_PIN 39
19+
#endif
20+
21+
// default peripheral
22+
#define SIPEED_ST7789_RST_GPIONUM 6
23+
#define SIPEED_ST7789_DCX_GPIONUM 7
24+
#define SIPEED_ST7789_SS 3
25+
26+
27+
#define COLOR_BLACK 0x0000
28+
#define COLOR_NAVY 0x000F
29+
#define COLOR_DARKGREEN 0x03E0
30+
#define COLOR_DARKCYAN 0x03EF
31+
#define COLOR_MAROON 0x7800
32+
#define COLOR_PURPLE 0x780F
33+
#define COLOR_OLIVE 0x7BE0
34+
#define COLOR_LIGHTGREY 0xC618
35+
#define COLOR_DARKGREY 0x7BEF
36+
#define COLOR_BLUE 0x001F
37+
#define COLOR_GREEN 0x07E0
38+
#define COLOR_CYAN 0x07FF
39+
#define COLOR_RED 0xF800
40+
#define COLOR_MAGENTA 0xF81F
41+
#define COLOR_YELLOW 0xFFE0
42+
#define COLOR_WHITE 0xFFFF
43+
#define COLOR_ORANGE 0xFD20
44+
#define COLOR_GREENYELLOW 0xAFE5
45+
#define COLOR_PINK 0xF81F
46+
47+
48+
class Sipeed_ST7789 : public Adafruit_GFX{
49+
public:
50+
/**
51+
* @param rst_pin -1: not use reset pin
52+
*/
53+
Sipeed_ST7789(uint16_t w, uint16_t h, SPIClass& spi, int8_t dc_pin = SIPEED_ST7789_DCX_PIN, int8_t rst_pin = SIPEED_ST7789_RST_PIN , uint8_t dma_ch = 3);
54+
55+
~Sipeed_ST7789(void);
56+
57+
boolean begin( uint32_t freq = 15000000, uint16_t color = 0xffff );
58+
// void display(void);
59+
// void clearDisplay(uint16_t color);
60+
// void invertDisplay(boolean i);
61+
// void dim(boolean dim);
62+
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
63+
virtual void writePixel(int16_t x, int16_t y, uint16_t color);
64+
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
65+
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
66+
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
67+
68+
virtual void
69+
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
70+
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
71+
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
72+
fillScreen(uint16_t color),
73+
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
74+
75+
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth);
76+
77+
//TODO: direction
78+
// virtual void setRotation(uint8_t r);
79+
// virtual void invertDisplay(boolean i);
80+
81+
private:
82+
SPIClass& _spi;
83+
int8_t _dcxPin;
84+
int8_t _rstPin;
85+
uint8_t _dmaCh;
86+
uint32_t _freq;
87+
88+
89+
90+
};
91+
92+
#endif
93+

0 commit comments

Comments
 (0)