mirror of
https://github.com/sipeed/Maixduino.git
synced 2026-03-03 17:14:00 +01:00
Merge branch 'master' of git@github.com:btx000/Kenduino-core.git
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "cores/arduino/kendryte-standalone-sdk"]
|
||||
path = cores/arduino/kendryte-standalone-sdk
|
||||
url = https://github.com/sipeed/kendryte-standalone-sdk
|
||||
[submodule "libraries/Adafruit-GFX-Library"]
|
||||
path = libraries/Adafruit-GFX-Library
|
||||
url = https://github.com/adafruit/Adafruit-GFX-Library
|
||||
|
||||
1
libraries/Adafruit-GFX-Library
Submodule
1
libraries/Adafruit-GFX-Library
Submodule
Submodule libraries/Adafruit-GFX-Library added at 253e30d6eb
@@ -1,11 +1,6 @@
|
||||
#include "SPI.h"
|
||||
|
||||
SPIClass spi0(SPI0);
|
||||
#ifdef K210
|
||||
#error "11111111"
|
||||
#else
|
||||
#error "222222"
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
@@ -145,6 +145,8 @@ void sipeed_spi_deinit(spi_device_num_t spi_num)
|
||||
sysctl_clock_disable( sysctl_clock_t(SYSCTL_CLOCK_SPI0 + spi_num));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
typedef struct{
|
||||
@@ -152,14 +154,22 @@ typedef struct{
|
||||
bool used;
|
||||
} spi_ss_t;
|
||||
|
||||
static spi_ss_t g_ss_table[4]={
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false}
|
||||
static spi_ss_t g_ss_table[2][4]={
|
||||
{//SPI0
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false}
|
||||
},
|
||||
{//SPI1
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false},
|
||||
{.pin = -1, .used = false}
|
||||
}
|
||||
};
|
||||
|
||||
int8_t getSsByPin(int8_t pin)
|
||||
int8_t getSsByPin(uint8_t spi, int8_t pin)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
@@ -167,45 +177,45 @@ int8_t getSsByPin(int8_t pin)
|
||||
return -1;
|
||||
for(i=0; i<4; ++i)
|
||||
{
|
||||
if(g_ss_table[i].used && g_ss_table[i].pin == pin)
|
||||
if(g_ss_table[spi][i].used && g_ss_table[spi][i].pin == pin)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int8_t getSsNumLast()
|
||||
int8_t getSsNumLast(uint8_t spi)
|
||||
{
|
||||
uint8_t i=0, count=0;
|
||||
for(i=0; i<4; ++i)
|
||||
{
|
||||
if(!g_ss_table[i].used)
|
||||
if(!g_ss_table[spi][i].used)
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool checkSs(int8_t ss)
|
||||
bool checkSs(uint8_t spi, int8_t ss)
|
||||
{
|
||||
int8_t ssPeriph;
|
||||
if( ss < 0) // not use ss
|
||||
return true;
|
||||
ssPeriph = getSsByPin(ss);
|
||||
ssPeriph = getSsByPin(spi, ss);
|
||||
if(ssPeriph >= 0)
|
||||
return true;
|
||||
if(getSsNumLast() > 0)
|
||||
if(getSsNumLast(spi) > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int8_t setSs(int8_t pin)
|
||||
int8_t setSs(uint8_t spi, int8_t pin)
|
||||
{
|
||||
uint8_t i=0;
|
||||
for(i=0; i<4; ++i)
|
||||
{
|
||||
if(!g_ss_table[i].used)
|
||||
if(!g_ss_table[spi][i].used)
|
||||
{
|
||||
g_ss_table[i].used = true;
|
||||
g_ss_table[i].pin = pin;
|
||||
g_ss_table[spi][i].used = true;
|
||||
g_ss_table[spi][i].pin = pin;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -217,9 +227,9 @@ int8_t setSs(int8_t pin)
|
||||
* @param mosi must >= 0
|
||||
* @param ss -1: not use hardware ss
|
||||
*/
|
||||
bool checkPinParam(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
bool checkPinParam(uint8_t spi, int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
if(!checkSs(ss))
|
||||
if(!checkSs(spi, ss))
|
||||
return false;
|
||||
//TODO:
|
||||
return true;
|
||||
@@ -275,7 +285,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
mosi = _mosi;
|
||||
ss = _ss;
|
||||
}
|
||||
configASSERT(checkPinParam(sck, miso, mosi, ss));
|
||||
configASSERT(checkPinParam(_spiNum, sck, miso, mosi, ss));
|
||||
|
||||
if(_spiNum == SPI_SOFT)
|
||||
{
|
||||
@@ -288,7 +298,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
fpioa_set_function(sck, FUNC_SPI0_SCLK);
|
||||
if( ss >= 0)
|
||||
{
|
||||
fpioa_function_t a = (fpioa_function_t)(FUNC_SPI0_SS0+setSs(ss));
|
||||
fpioa_function_t a = (fpioa_function_t)(FUNC_SPI0_SS0+setSs(_spiNum, ss));
|
||||
fpioa_set_function(ss, a);
|
||||
}
|
||||
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)
|
||||
fpioa_set_function(sck, FUNC_SPI1_SCLK);
|
||||
if( ss >= 0)
|
||||
{
|
||||
fpioa_set_function(ss, (fpioa_function_t)(FUNC_SPI1_SS0+setSs(ss)));
|
||||
fpioa_set_function(ss, (fpioa_function_t)(FUNC_SPI1_SS0+setSs(_spiNum, ss)));
|
||||
}
|
||||
fpioa_set_function(mosi, FUNC_SPI1_D0);
|
||||
if(miso>=0)
|
||||
@@ -310,7 +320,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
_miso = miso;
|
||||
_sck = sck;
|
||||
_ss = ss;
|
||||
_ssPeriph = getSsByPin(ss);
|
||||
_ssPeriph = getSsByPin(_spiNum, ss);
|
||||
if(_ssPeriph<0)
|
||||
_ssPeriph = 0; // default to cs0 TODO: optimize?
|
||||
spi_init(spi_device_num_t(_spiNum), spi_work_mode_t(_dataMode), SPI_FF_STANDARD, 8, 0);
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
#include <Sipeed_ST7789.h>
|
||||
|
||||
SPIClass spi_(SPI0);
|
||||
SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
|
||||
Sipeed_ST7789 lcd(320, 240, spi_);
|
||||
|
||||
|
||||
void func()
|
||||
{
|
||||
lcd.fillScreen(COLOR_RED);
|
||||
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
|
||||
lcd.fillCircle(100, 100, 40, COLOR_WHITE);
|
||||
lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE);
|
||||
lcd.setTextSize(2);
|
||||
lcd.setTextColor(COLOR_WHITE);
|
||||
lcd.setCursor(100,30);
|
||||
lcd.println("hello Sipeed Maix");
|
||||
}
|
||||
|
||||
void func2()
|
||||
{
|
||||
lcd.fillScreen(COLOR_RED);
|
||||
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
|
||||
lcd.fillCircle(180, 50, 40, COLOR_WHITE);
|
||||
lcd.fillTriangle(10, 300, 200, 300, 200, 150, COLOR_WHITE);
|
||||
lcd.setTextSize(2);
|
||||
lcd.setTextColor(COLOR_WHITE);
|
||||
lcd.setCursor(1,100);
|
||||
lcd.println("hello Sipeed Maix");
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(15000000, COLOR_BLACK);
|
||||
lcd.drawRect(20, 20, 50, 50, COLOR_WHITE);
|
||||
lcd.drawCircle(100, 100, 40, COLOR_WHITE);
|
||||
lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE);
|
||||
lcd.begin(15000000, COLOR_RED);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
lcd.setRotation(0);
|
||||
func();
|
||||
delay(3000);
|
||||
lcd.invertDisplay(true);
|
||||
func();
|
||||
delay(3000);
|
||||
lcd.setRotation(1);
|
||||
func2();
|
||||
delay(3000);
|
||||
lcd.setRotation(2);
|
||||
func();
|
||||
delay(3000);
|
||||
lcd.setRotation(3);
|
||||
func2();
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
Sipeed_ST7789::Sipeed_ST7789(uint16_t w, uint16_t h, SPIClass& spi, int8_t dc_pin, int8_t rst_pin, uint8_t dma_ch )
|
||||
:Adafruit_GFX(w,h),
|
||||
_spi(spi), _dcxPin(dc_pin), _rstPin(rst_pin),
|
||||
_dmaCh(dma_ch)
|
||||
_dmaCh(dma_ch),
|
||||
_screenDir(DIR_YX_RLDU)
|
||||
{
|
||||
configASSERT(_spi.busId()==SPI0);
|
||||
}
|
||||
@@ -33,6 +34,7 @@ boolean Sipeed_ST7789::begin( uint32_t freq, uint16_t color )
|
||||
sysctl_set_spi0_dvp_data(1);
|
||||
_freq = freq;
|
||||
lcd_init(spiNum, SIPEED_ST7789_SS, SIPEED_ST7789_RST_GPIONUM, SIPEED_ST7789_DCX_GPIONUM, _freq, _rstPin, _dcxPin, _dmaCh);
|
||||
lcd_set_direction((lcd_dir_t)_screenDir);
|
||||
lcd_clear(color);
|
||||
return true;
|
||||
}
|
||||
@@ -87,11 +89,78 @@ void Sipeed_ST7789::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_
|
||||
lcd_draw_rectangle(x, y, x+w-1, y+h-1, 1, color);
|
||||
}
|
||||
|
||||
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth)
|
||||
void Sipeed_ST7789::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth)
|
||||
{
|
||||
lcd_draw_rectangle(x, y, x+w-1, y+h-1, lineWidth, color);
|
||||
}
|
||||
|
||||
|
||||
uint16_t getValueByRotation(uint8_t rotation)
|
||||
{
|
||||
uint16_t v = DIR_YX_RLDU;
|
||||
switch(rotation) {
|
||||
case 0:
|
||||
v = DIR_YX_RLDU;
|
||||
break;
|
||||
case 1:
|
||||
v = DIR_XY_RLUD;
|
||||
break;
|
||||
case 2:
|
||||
v = DIR_YX_LRUD;
|
||||
break;
|
||||
case 3:
|
||||
v = DIR_XY_LRDU;
|
||||
break;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set rotation setting for display
|
||||
@param x 0 thru 3 corresponding to 4 cardinal rotations
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Sipeed_ST7789::setRotation(uint8_t x) {
|
||||
rotation = (x & 3);
|
||||
configASSERT(rotation >= 0 && rotation <= 3);
|
||||
|
||||
switch(rotation) {
|
||||
case 0:
|
||||
case 2:
|
||||
_width = WIDTH;
|
||||
_height = HEIGHT;
|
||||
break;
|
||||
case 1:
|
||||
case 3:
|
||||
_width = HEIGHT;
|
||||
_height = WIDTH;
|
||||
break;
|
||||
}
|
||||
_screenDir = getValueByRotation(rotation);
|
||||
lcd_set_direction((lcd_dir_t)_screenDir);
|
||||
}
|
||||
|
||||
void Sipeed_ST7789::invertDisplay(boolean invert) {
|
||||
uint16_t _screenDir = getValueByRotation(rotation);
|
||||
if( invert )
|
||||
{
|
||||
switch(rotation) {
|
||||
case 0:
|
||||
_screenDir = DIR_YX_RLUD;
|
||||
break;
|
||||
case 1:
|
||||
_screenDir = DIR_XY_LRUD;
|
||||
break;
|
||||
case 2:
|
||||
_screenDir = DIR_YX_LRDU;
|
||||
break;
|
||||
case 3:
|
||||
_screenDir = DIR_XY_RLDU;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lcd_set_direction((lcd_dir_t)_screenDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,10 +55,7 @@ public:
|
||||
~Sipeed_ST7789(void);
|
||||
|
||||
boolean begin( uint32_t freq = 15000000, uint16_t color = 0xffff );
|
||||
// void display(void);
|
||||
// void clearDisplay(uint16_t color);
|
||||
// void invertDisplay(boolean i);
|
||||
// void dim(boolean dim);
|
||||
|
||||
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void writePixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
@@ -74,9 +71,8 @@ public:
|
||||
|
||||
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint16_t lineWidth);
|
||||
|
||||
//TODO: direction
|
||||
// virtual void setRotation(uint8_t r);
|
||||
// virtual void invertDisplay(boolean i);
|
||||
virtual void setRotation(uint8_t r);
|
||||
virtual void invertDisplay(boolean invert);
|
||||
|
||||
private:
|
||||
SPIClass& _spi;
|
||||
@@ -84,7 +80,7 @@ private:
|
||||
int8_t _rstPin;
|
||||
uint8_t _dmaCh;
|
||||
uint32_t _freq;
|
||||
|
||||
uint16_t _screenDir;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -61,7 +61,8 @@ typedef enum _lcd_dir
|
||||
DIR_XY_LRDU = 0xC0,
|
||||
DIR_YX_LRDU = 0xE0,
|
||||
DIR_XY_MASK = 0x20,
|
||||
DIR_MASK = 0xE0,
|
||||
DIR_RL_MASK = 0x40,
|
||||
DIR_UD_MASK = 0x80
|
||||
} lcd_dir_t;
|
||||
|
||||
typedef struct _lcd_ctl
|
||||
|
||||
Reference in New Issue
Block a user