Added line and rect drawing
This commit is contained in:
parent
e073e6c750
commit
d8180ba10a
38
st7735.c
38
st7735.c
|
@ -44,6 +44,12 @@ static inline void st7735_write_data(uint8_t data) {
|
||||||
spi_set_cs();
|
spi_set_cs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void st7735_write_color(uint16_t color) {
|
||||||
|
spi_write(color >> 8);
|
||||||
|
spi_write(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void st7735_reset() {
|
static inline void st7735_reset() {
|
||||||
spi_unset_cs();
|
spi_unset_cs();
|
||||||
st7735_set_rst();
|
st7735_set_rst();
|
||||||
|
@ -228,7 +234,7 @@ void st7735_set_addr_win(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void st7735_draw_pixel(int16_t x, int16_t y, uint16_t color) {
|
void st7735_draw_pixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
if((x < 0) || (x >= st7735_width) || (y < 0) || (y >= st7735_height)){
|
if(x < 0 || x >= st7735_width || y < 0 || y >= st7735_height){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,8 +243,34 @@ void st7735_draw_pixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
st7735_set_rs();
|
st7735_set_rs();
|
||||||
spi_unset_cs();
|
spi_unset_cs();
|
||||||
|
|
||||||
spi_write(color >> 8);
|
st7735_write_color(color);
|
||||||
spi_write(color);
|
|
||||||
|
spi_set_cs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void st7735_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
|
||||||
|
if(x >= st7735_width || y >= st7735_height) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((x + w - 1) >= st7735_width) {
|
||||||
|
w = st7735_width - x;
|
||||||
|
}
|
||||||
|
if((y + h - 1) >= st7735_height) {
|
||||||
|
h = st7735_height - y;
|
||||||
|
}
|
||||||
|
|
||||||
|
st7735_set_addr_win(x, y, x + w - 1, y + h - 1);
|
||||||
|
|
||||||
|
st7735_set_rs();
|
||||||
|
spi_unset_cs();
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < h; i++) {
|
||||||
|
for(uint8_t j = 0; j < w; j++) {
|
||||||
|
st7735_write_color(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
spi_set_cs();
|
spi_set_cs();
|
||||||
}
|
}
|
||||||
|
|
16
st7735.h
16
st7735.h
|
@ -88,6 +88,22 @@ enum ST7735_ORIENTATION {
|
||||||
};
|
};
|
||||||
|
|
||||||
void st7735_init(void);
|
void st7735_init(void);
|
||||||
|
|
||||||
void st7735_set_orientation(enum ST7735_ORIENTATION orientation);
|
void st7735_set_orientation(enum ST7735_ORIENTATION orientation);
|
||||||
|
|
||||||
|
void st7735_draw_pixel(int16_t x, int16_t y, uint16_t color);
|
||||||
|
void st7735_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||||
|
|
||||||
|
static inline void st7735_draw_fast_vline(int16_t x, int16_t y, int16_t h, uint16_t color) {
|
||||||
|
st7735_fill_rect(x, y, 1, h, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void st7735_draw_fast_hline(int16_t x, int16_t y, int16_t w, uint16_t color) {
|
||||||
|
st7735_fill_rect(x, y, w, 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint16_t st7735_color(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue