Skip to content

Commit 7edf32f

Browse files
committed
Merge branch 'master' of [email protected]:btx000/Kenduino-core.git
2 parents c1e1773 + b4c8531 commit 7edf32f

File tree

8 files changed

+153
-43
lines changed

8 files changed

+153
-43
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "cores/arduino/kendryte-standalone-sdk"]
22
path = cores/arduino/kendryte-standalone-sdk
33
url = https://github.com/sipeed/kendryte-standalone-sdk
4+
[submodule "libraries/Adafruit-GFX-Library"]
5+
path = libraries/Adafruit-GFX-Library
6+
url = https://github.com/adafruit/Adafruit-GFX-Library

libraries/Adafruit-GFX-Library

Submodule Adafruit-GFX-Library added at 253e30d

libraries/SPI/examples/basic/basic.ino

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#include "SPI.h"
22

33
SPIClass spi0(SPI0);
4-
#ifdef K210
5-
#error "11111111"
6-
#else
7-
#error "222222"
8-
#endif
94

105
void setup()
116
{

libraries/SPI/src/SPI.cpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,67 +145,77 @@ void sipeed_spi_deinit(spi_device_num_t spi_num)
145145
sysctl_clock_disable( sysctl_clock_t(SYSCTL_CLOCK_SPI0 + spi_num));
146146
}
147147

148+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
149+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148150

149151

150152
typedef struct{
151153
int8_t pin;
152154
bool used;
153155
} spi_ss_t;
154156

155-
static spi_ss_t g_ss_table[4]={
156-
{.pin = -1, .used = false},
157-
{.pin = -1, .used = false},
158-
{.pin = -1, .used = false},
159-
{.pin = -1, .used = false}
157+
static spi_ss_t g_ss_table[2][4]={
158+
{//SPI0
159+
{.pin = -1, .used = false},
160+
{.pin = -1, .used = false},
161+
{.pin = -1, .used = false},
162+
{.pin = -1, .used = false}
163+
},
164+
{//SPI1
165+
{.pin = -1, .used = false},
166+
{.pin = -1, .used = false},
167+
{.pin = -1, .used = false},
168+
{.pin = -1, .used = false}
169+
}
160170
};
161171

162-
int8_t getSsByPin(int8_t pin)
172+
int8_t getSsByPin(uint8_t spi, int8_t pin)
163173
{
164174
uint8_t i;
165175

166176
if(pin<0)
167177
return -1;
168178
for(i=0; i<4; ++i)
169179
{
170-
if(g_ss_table[i].used && g_ss_table[i].pin == pin)
180+
if(g_ss_table[spi][i].used && g_ss_table[spi][i].pin == pin)
171181
return i;
172182
}
173183
return -1;
174184
}
175185

176-
int8_t getSsNumLast()
186+
int8_t getSsNumLast(uint8_t spi)
177187
{
178188
uint8_t i=0, count=0;
179189
for(i=0; i<4; ++i)
180190
{
181-
if(!g_ss_table[i].used)
191+
if(!g_ss_table[spi][i].used)
182192
++count;
183193
}
184194
return count;
185195
}
186196

187-
bool checkSs(int8_t ss)
197+
bool checkSs(uint8_t spi, int8_t ss)
188198
{
189199
int8_t ssPeriph;
190200
if( ss < 0) // not use ss
191201
return true;
192-
ssPeriph = getSsByPin(ss);
202+
ssPeriph = getSsByPin(spi, ss);
193203
if(ssPeriph >= 0)
194204
return true;
195-
if(getSsNumLast() > 0)
205+
if(getSsNumLast(spi) > 0)
196206
return true;
197207
return false;
198208
}
199209

200-
int8_t setSs(int8_t pin)
210+
int8_t setSs(uint8_t spi, int8_t pin)
201211
{
202212
uint8_t i=0;
203213
for(i=0; i<4; ++i)
204214
{
205-
if(!g_ss_table[i].used)
215+
if(!g_ss_table[spi][i].used)
206216
{
207-
g_ss_table[i].used = true;
208-
g_ss_table[i].pin = pin;
217+
g_ss_table[spi][i].used = true;
218+
g_ss_table[spi][i].pin = pin;
209219
return i;
210220
}
211221
}
@@ -217,9 +227,9 @@ int8_t setSs(int8_t pin)
217227
* @param mosi must >= 0
218228
* @param ss -1: not use hardware ss
219229
*/
220-
bool checkPinParam(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
230+
bool checkPinParam(uint8_t spi, int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
221231
{
222-
if(!checkSs(ss))
232+
if(!checkSs(spi, ss))
223233
return false;
224234
//TODO:
225235
return true;
@@ -275,7 +285,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
275285
mosi = _mosi;
276286
ss = _ss;
277287
}
278-
configASSERT(checkPinParam(sck, miso, mosi, ss));
288+
configASSERT(checkPinParam(_spiNum, sck, miso, mosi, ss));
279289

280290
if(_spiNum == SPI_SOFT)
281291
{
@@ -288,7 +298,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
288298
fpioa_set_function(sck, FUNC_SPI0_SCLK);
289299
if( ss >= 0)
290300
{
291-
fpioa_function_t a = (fpioa_function_t)(FUNC_SPI0_SS0+setSs(ss));
301+
fpioa_function_t a = (fpioa_function_t)(FUNC_SPI0_SS0+setSs(_spiNum, ss));
292302
fpioa_set_function(ss, a);
293303
}
294304
fpioa_set_function(mosi, FUNC_SPI0_D0);
@@ -300,7 +310,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
300310
fpioa_set_function(sck, FUNC_SPI1_SCLK);
301311
if( ss >= 0)
302312
{
303-
fpioa_set_function(ss, (fpioa_function_t)(FUNC_SPI1_SS0+setSs(ss)));
313+
fpioa_set_function(ss, (fpioa_function_t)(FUNC_SPI1_SS0+setSs(_spiNum, ss)));
304314
}
305315
fpioa_set_function(mosi, FUNC_SPI1_D0);
306316
if(miso>=0)
@@ -310,7 +320,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
310320
_miso = miso;
311321
_sck = sck;
312322
_ss = ss;
313-
_ssPeriph = getSsByPin(ss);
323+
_ssPeriph = getSsByPin(_spiNum, ss);
314324
if(_ssPeriph<0)
315325
_ssPeriph = 0; // default to cs0 TODO: optimize?
316326
spi_init(spi_device_num_t(_spiNum), spi_work_mode_t(_dataMode), SPI_FF_STANDARD, 8, 0);
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
11
#include <Sipeed_ST7789.h>
22

3-
SPIClass spi_(SPI0);
3+
SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
44
Sipeed_ST7789 lcd(320, 240, spi_);
55

6-
void setup()
6+
7+
void func()
78
{
8-
lcd.begin(15000000, COLOR_BLACK);
9+
lcd.fillScreen(COLOR_RED);
910
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
10-
lcd.drawCircle(100, 100, 40, COLOR_WHITE);
11+
lcd.fillCircle(100, 100, 40, COLOR_WHITE);
1112
lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE);
13+
lcd.setTextSize(2);
14+
lcd.setTextColor(COLOR_WHITE);
15+
lcd.setCursor(100,30);
16+
lcd.println("hello Sipeed Maix");
1217
}
1318

14-
void loop()
19+
void func2()
1520
{
21+
lcd.fillScreen(COLOR_RED);
22+
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
23+
lcd.fillCircle(180, 50, 40, COLOR_WHITE);
24+
lcd.fillTriangle(10, 300, 200, 300, 200, 150, COLOR_WHITE);
25+
lcd.setTextSize(2);
26+
lcd.setTextColor(COLOR_WHITE);
27+
lcd.setCursor(1,100);
28+
lcd.println("hello Sipeed Maix");
29+
}
1630

31+
void setup()
32+
{
33+
lcd.begin(15000000, COLOR_RED);
1734
}
1835

36+
void loop()
37+
{
38+
lcd.setRotation(0);
39+
func();
40+
delay(3000);
41+
lcd.invertDisplay(true);
42+
func();
43+
delay(3000);
44+
lcd.setRotation(1);
45+
func2();
46+
delay(3000);
47+
lcd.setRotation(2);
48+
func();
49+
delay(3000);
50+
lcd.setRotation(3);
51+
func2();
52+
delay(3000);
53+
}

libraries/Sipeed_ST7789/src/Sipeed_ST7789.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
Sipeed_ST7789::Sipeed_ST7789(uint16_t w, uint16_t h, SPIClass& spi, int8_t dc_pin, int8_t rst_pin, uint8_t dma_ch )
88
:Adafruit_GFX(w,h),
99
_spi(spi), _dcxPin(dc_pin), _rstPin(rst_pin),
10-
_dmaCh(dma_ch)
10+
_dmaCh(dma_ch),
11+
_screenDir(DIR_YX_RLDU)
1112
{
1213
configASSERT(_spi.busId()==SPI0);
1314
}
@@ -33,6 +34,7 @@ boolean Sipeed_ST7789::begin( uint32_t freq, uint16_t color )
3334
sysctl_set_spi0_dvp_data(1);
3435
_freq = freq;
3536
lcd_init(spiNum, SIPEED_ST7789_SS, SIPEED_ST7789_RST_GPIONUM, SIPEED_ST7789_DCX_GPIONUM, _freq, _rstPin, _dcxPin, _dmaCh);
37+
lcd_set_direction((lcd_dir_t)_screenDir);
3638
lcd_clear(color);
3739
return true;
3840
}
@@ -87,11 +89,78 @@ void Sipeed_ST7789::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_
8789
lcd_draw_rectangle(x, y, x+w-1, y+h-1, 1, color);
8890
}
8991

90-
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth)
92+
void Sipeed_ST7789::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth)
9193
{
9294
lcd_draw_rectangle(x, y, x+w-1, y+h-1, lineWidth, color);
9395
}
9496

9597

98+
uint16_t getValueByRotation(uint8_t rotation)
99+
{
100+
uint16_t v = DIR_YX_RLDU;
101+
switch(rotation) {
102+
case 0:
103+
v = DIR_YX_RLDU;
104+
break;
105+
case 1:
106+
v = DIR_XY_RLUD;
107+
break;
108+
case 2:
109+
v = DIR_YX_LRUD;
110+
break;
111+
case 3:
112+
v = DIR_XY_LRDU;
113+
break;
114+
}
115+
return v;
116+
}
117+
118+
/**************************************************************************/
119+
/*!
120+
@brief Set rotation setting for display
121+
@param x 0 thru 3 corresponding to 4 cardinal rotations
122+
*/
123+
/**************************************************************************/
124+
void Sipeed_ST7789::setRotation(uint8_t x) {
125+
rotation = (x & 3);
126+
configASSERT(rotation >= 0 && rotation <= 3);
127+
128+
switch(rotation) {
129+
case 0:
130+
case 2:
131+
_width = WIDTH;
132+
_height = HEIGHT;
133+
break;
134+
case 1:
135+
case 3:
136+
_width = HEIGHT;
137+
_height = WIDTH;
138+
break;
139+
}
140+
_screenDir = getValueByRotation(rotation);
141+
lcd_set_direction((lcd_dir_t)_screenDir);
142+
}
143+
144+
void Sipeed_ST7789::invertDisplay(boolean invert) {
145+
uint16_t _screenDir = getValueByRotation(rotation);
146+
if( invert )
147+
{
148+
switch(rotation) {
149+
case 0:
150+
_screenDir = DIR_YX_RLUD;
151+
break;
152+
case 1:
153+
_screenDir = DIR_XY_LRUD;
154+
break;
155+
case 2:
156+
_screenDir = DIR_YX_LRDU;
157+
break;
158+
case 3:
159+
_screenDir = DIR_XY_RLDU;
160+
break;
161+
}
162+
}
163+
lcd_set_direction((lcd_dir_t)_screenDir);
164+
}
96165

97166

libraries/Sipeed_ST7789/src/Sipeed_ST7789.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ class Sipeed_ST7789 : public Adafruit_GFX{
5555
~Sipeed_ST7789(void);
5656

5757
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);
58+
6259
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
6360
virtual void writePixel(int16_t x, int16_t y, uint16_t color);
6461
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
@@ -74,17 +71,16 @@ class Sipeed_ST7789 : public Adafruit_GFX{
7471

7572
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth);
7673

77-
//TODO: direction
78-
// virtual void setRotation(uint8_t r);
79-
// virtual void invertDisplay(boolean i);
74+
virtual void setRotation(uint8_t r);
75+
virtual void invertDisplay(boolean invert);
8076

8177
private:
8278
SPIClass& _spi;
8379
int8_t _dcxPin;
8480
int8_t _rstPin;
8581
uint8_t _dmaCh;
8682
uint32_t _freq;
87-
83+
uint16_t _screenDir;
8884

8985

9086
};

libraries/Sipeed_ST7789/src/lcd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ typedef enum _lcd_dir
6161
DIR_XY_LRDU = 0xC0,
6262
DIR_YX_LRDU = 0xE0,
6363
DIR_XY_MASK = 0x20,
64-
DIR_MASK = 0xE0,
64+
DIR_RL_MASK = 0x40,
65+
DIR_UD_MASK = 0x80
6566
} lcd_dir_t;
6667

6768
typedef struct _lcd_ctl

0 commit comments

Comments
 (0)