-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from pimoroni/experimental/8bitfb
ST7789 / PicoGraphics rewrite - Support for 4-bit, 8-bit and 16-bit framebuffers and more.
- Loading branch information
Showing
249 changed files
with
10,799 additions
and
7,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include(pimoroni_i2c.cmake) | ||
include(pimoroni_bus.cmake) |
6 changes: 3 additions & 3 deletions
6
libraries/breakout_roundlcd/CMakeLists.txt → common/pimoroni_bus.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
set(LIB_NAME breakout_roundlcd) | ||
set(LIB_NAME pimoroni_bus) | ||
add_library(${LIB_NAME} INTERFACE) | ||
|
||
target_sources(${LIB_NAME} INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}.cpp | ||
) | ||
|
||
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib st7789 pico_graphics) | ||
target_link_libraries(${LIB_NAME} INTERFACE pico_stdlib hardware_spi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "pimoroni_bus.hpp" | ||
|
||
namespace pimoroni { | ||
SPIPins get_spi_pins(BG_SPI_SLOT slot) { | ||
switch(slot) { | ||
case PICO_EXPLORER_ONBOARD: | ||
return {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, SPI_DEFAULT_DC, PIN_UNUSED}; | ||
case BG_SPI_FRONT: | ||
return {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, SPI_DEFAULT_DC, SPI_BG_FRONT_PWM}; | ||
case BG_SPI_BACK: | ||
return {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_BACK_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, SPI_DEFAULT_DC, SPI_BG_BACK_PWM}; | ||
} | ||
return {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, SPI_DEFAULT_DC, SPI_BG_FRONT_PWM}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "pimoroni_common.hpp" | ||
#include "hardware/gpio.h" | ||
#include "hardware/spi.h" | ||
|
||
namespace pimoroni { | ||
struct SPIPins { | ||
spi_inst_t *spi; | ||
uint cs; | ||
uint sck; | ||
uint mosi; | ||
uint miso; | ||
uint dc; | ||
uint bl; | ||
}; | ||
|
||
struct ParallelPins { | ||
uint cs; | ||
uint dc; | ||
uint wr_sck; | ||
uint rd_sck; | ||
uint d0; | ||
uint bl; | ||
}; | ||
|
||
SPIPins get_spi_pins(BG_SPI_SLOT slot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
add_subdirectory(analog) | ||
add_subdirectory(analogmux) | ||
add_subdirectory(esp32spi) | ||
add_subdirectory(ioexpander) | ||
add_subdirectory(ltp305) | ||
add_subdirectory(ltr559) | ||
add_subdirectory(pmw3901) | ||
add_subdirectory(sgp30) | ||
add_subdirectory(st7735) | ||
add_subdirectory(st7789) | ||
add_subdirectory(msa301) | ||
add_subdirectory(rv3028) | ||
add_subdirectory(trackball) | ||
add_subdirectory(vl53l1x) | ||
add_subdirectory(is31fl3731) | ||
add_subdirectory(fatfs) | ||
add_subdirectory(sdcard) | ||
add_subdirectory(as7262) | ||
add_subdirectory(bh1745) | ||
add_subdirectory(bme68x) | ||
add_subdirectory(bmp280) | ||
add_subdirectory(bme280) | ||
add_subdirectory(button) | ||
add_subdirectory(pid) | ||
add_subdirectory(plasma) | ||
add_subdirectory(rgbled) | ||
add_subdirectory(icp10125) | ||
add_subdirectory(scd4x) | ||
add_subdirectory(hub75) | ||
add_subdirectory(uc8151) | ||
add_subdirectory(pwm) | ||
add_subdirectory(servo) | ||
add_subdirectory(encoder) | ||
add_subdirectory(motor) | ||
add_subdirectory(vl53l5cx) | ||
add_subdirectory(pcf85063a) | ||
add_subdirectory(pms5003) | ||
add_subdirectory(analog) | ||
add_subdirectory(analogmux) | ||
add_subdirectory(esp32spi) | ||
add_subdirectory(ioexpander) | ||
add_subdirectory(ltp305) | ||
add_subdirectory(ltr559) | ||
add_subdirectory(pmw3901) | ||
add_subdirectory(sgp30) | ||
add_subdirectory(st7735) | ||
add_subdirectory(st7789) | ||
add_subdirectory(msa301) | ||
add_subdirectory(rv3028) | ||
add_subdirectory(trackball) | ||
add_subdirectory(vl53l1x) | ||
add_subdirectory(is31fl3731) | ||
add_subdirectory(fatfs) | ||
add_subdirectory(sdcard) | ||
add_subdirectory(as7262) | ||
add_subdirectory(bh1745) | ||
add_subdirectory(bme68x) | ||
add_subdirectory(bmp280) | ||
add_subdirectory(bme280) | ||
add_subdirectory(button) | ||
add_subdirectory(pid) | ||
add_subdirectory(plasma) | ||
add_subdirectory(rgbled) | ||
add_subdirectory(icp10125) | ||
add_subdirectory(scd4x) | ||
add_subdirectory(hub75) | ||
add_subdirectory(uc8151) | ||
add_subdirectory(pwm) | ||
add_subdirectory(servo) | ||
add_subdirectory(encoder) | ||
add_subdirectory(motor) | ||
add_subdirectory(vl53l5cx) | ||
add_subdirectory(pcf85063a) | ||
add_subdirectory(pms5003) | ||
add_subdirectory(sh1107) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(${CMAKE_CURRENT_LIST_DIR}/sh1107.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ST7789 Display Driver for Pimoroni LCDs <!-- omit in toc --> | ||
|
||
The ST7789 driver supports both Parallel and Serial (SPI) ST7789 displays and is intended for use with: | ||
|
||
* Pico Display | ||
* Pico Display 2.0 | ||
* Tufty 2040 | ||
* Pico Explorer | ||
* 240x240 Round & Square SPI LCD Breakouts | ||
|
||
## Setup | ||
|
||
Construct an instance of the ST7789 driver with either Parallel or SPI pins. | ||
|
||
Parallel: | ||
|
||
```c++ | ||
ST7789 st7789(WIDTH, HEIGHT, ROTATE_0, { | ||
Tufty2040::LCD_CS, // Chip-Select | ||
Tufty2040::LCD_DC, // Data-Command | ||
Tufty2040::LCD_WR, // Write | ||
Tufty2040::LCD_RD, // Read | ||
Tufty2040::LCD_D0, // Data 0 (start of a bank of 8 pins) | ||
Tufty2040::BACKLIGHT // Backlight | ||
}); | ||
``` | ||
SPI: | ||
```c++ | ||
ST7789 st7789(WIDTH, HEIGHT, ROTATE_0, false, { | ||
PIMORONI_SPI_DEFAULT_INSTANCE, // SPI instance | ||
SPI_BG_FRONT_CS, // Chip-select | ||
SPI_DEFAULT_SCK, // SPI Clock | ||
SPI_DEFAULT_MOSI, // SPI Out | ||
PIN_UNUSED, // SPI In | ||
SPI_DEFAULT_DC, // SPI Data/Command | ||
PIN_UNUSED // Backlight | ||
}); | ||
``` | ||
|
||
## Reference | ||
|
||
### Update | ||
|
||
ST7789's `update` accepts an instance of `PicoGraphics` in any colour mode: | ||
|
||
```c++ | ||
st7789.update(&graphics); | ||
``` | ||
|
||
### Set Backlight | ||
|
||
If a backlight pin has been configured, you can set the backlight from 0 to 255: | ||
|
||
```c++ | ||
st7789.set_backlight(128) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(DRIVER_NAME sh1107) | ||
add_library(${DRIVER_NAME} INTERFACE) | ||
|
||
target_sources(${DRIVER_NAME} INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp) | ||
|
||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
target_include_directories(sh1107 INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib pimoroni_i2c pico_graphics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "sh1107.hpp" | ||
|
||
#include <cstdlib> | ||
#include <math.h> | ||
#include <string.h> | ||
|
||
namespace pimoroni { | ||
|
||
void SH1107::update(PicoGraphics *graphics) { | ||
if(graphics->pen_type == PicoGraphics::PEN_1BIT) { // Display buffer is screen native | ||
|
||
uint8_t *p = (uint8_t *)graphics->frame_buffer; | ||
uint framebuffer_size = PicoGraphics_Pen1Bit::buffer_size(width, height); | ||
uint page_size = framebuffer_size / 16; | ||
|
||
uint8_t temp[framebuffer_size] = {0}; | ||
uint8_t *ptemp = temp; | ||
|
||
for(int y = 0; y < height; y++) { | ||
for(int x = 0; x < width; x++) { | ||
uint bo = 7 - (x & 0b111); | ||
uint8_t color = p[(x / 8) + (y * width / 8)] & (1U << bo); | ||
if(color) { | ||
temp[x + (y / 8 ) * width] |= 1 << (y % 8); | ||
}else{ | ||
temp[x + (y / 8 ) * width] &= ~(1 << (y % 8)); | ||
} | ||
} | ||
} | ||
|
||
uint8_t buf[page_size + 1]; | ||
|
||
for(int i = 0; i < 16; i++) { | ||
i2c.reg_write_uint8(0x3c, 0, 0xb0 + i); | ||
i2c.reg_write_uint8(0x3c, 0, 0x00); | ||
i2c.reg_write_uint8(0x3c, 0, 0x10); | ||
|
||
memcpy(buf + 1, ptemp, page_size); | ||
buf[0] = 0x40; | ||
|
||
i2c.write_blocking(0x3c, buf, page_size + 1, false); | ||
|
||
ptemp += page_size; | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.