|
| 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 | + |
0 commit comments