kopia lustrzana https://github.com/pimoroni/pimoroni-pico
driver working for PG1Bit mode
rodzic
0e5e7feb7d
commit
d03c00383a
|
@ -141,19 +141,14 @@ namespace pimoroni {
|
|||
void ST7567::update(PicoGraphics *graphics) {
|
||||
|
||||
uint8_t *fb = (uint8_t *)graphics->frame_buffer;
|
||||
uint8_t page_buffer[128];
|
||||
uint8_t page_buffer[PAGESIZE];
|
||||
uint8_t page_byte_selector;
|
||||
uint8_t page_bit_selector;
|
||||
// clear page buffer
|
||||
for (int i=0 ; i < 128 ; i++){
|
||||
page_buffer[i] = 0;
|
||||
}
|
||||
for (uint8_t page=0; page < 8 ; page++){ //select page
|
||||
|
||||
for (uint16_t pixel_index=0 ; pixel_index < (128 * 8) ; pixel_index++){
|
||||
page_byte_selector = ((pixel_index % 128)) ;
|
||||
for (uint16_t pixel_index=0 ; pixel_index < (PAGESIZE * 8) ; pixel_index++){ //cycle through a page worth of bits from the fb
|
||||
page_byte_selector = ((pixel_index % 128));
|
||||
page_bit_selector = (pixel_index / 128);
|
||||
|
||||
// printf ("fb byte %d fb bit %d set to %d\n", page_byte_selector, page_bit_selector, *fb & (1 << (pixel_index % 8)));
|
||||
|
||||
|
||||
if (*fb & (0b10000000 >> (pixel_index % 8))){ // check selected pixel is present
|
||||
|
@ -162,58 +157,26 @@ namespace pimoroni {
|
|||
else{
|
||||
page_buffer[page_byte_selector] &= ~( 1 << page_bit_selector);
|
||||
}
|
||||
|
||||
|
||||
if ((pixel_index % 8) >= 7 ){ //increment fb pointer at end of byte
|
||||
|
||||
|
||||
fb++;
|
||||
|
||||
|
||||
if ((pixel_index % 8) >= 7 ){ //increment fb pointer at end of byte
|
||||
fb++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(graphics->pen_type == PicoGraphics::PEN_1BIT) {
|
||||
command(reg::ENTER_RMWMODE);
|
||||
for (uint8_t page=0; page < 8 ; page++){
|
||||
|
||||
command(reg::SETPAGESTART | page);
|
||||
command(reg::SETCOLL);
|
||||
command(reg::SETCOLH);
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(cs, 0);
|
||||
spi_write_blocking(spi, &page_buffer[0], PAGESIZE );
|
||||
fb += (PAGESIZE);
|
||||
gpio_put(cs, 1);
|
||||
gpio_put(dc, 0); // Back to command mode
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*else {
|
||||
command(reg::ENTER_RMWMODE);
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(cs, 0);
|
||||
|
||||
graphics->frame_convert(PicoGraphics::PEN_1BIT, [this](void *data, size_t length) {
|
||||
if (length > 0) {
|
||||
for (uint8_t page=0; page < 8 ; page++){
|
||||
|
||||
command(reg::SETPAGESTART | page);
|
||||
command(reg::SETCOLL);
|
||||
command(reg::SETCOLH);
|
||||
gpio_put(dc, 1); // data mode
|
||||
gpio_put(cs, 0);
|
||||
spi_write_blocking(spi, fb, PAGESIZE / 8);
|
||||
fb += PAGESIZE / 8;
|
||||
gpio_put(cs, 1);
|
||||
}
|
||||
};
|
||||
*/
|
||||
}
|
||||
gpio_put(cs, 1);
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace pimoroni {
|
|||
uint bl;
|
||||
uint reset_pin=21;
|
||||
|
||||
uint32_t spi_baud = 500000;
|
||||
uint32_t spi_baud = 10000000; //10Mhz
|
||||
|
||||
uint8_t offset_cols = 0;
|
||||
uint8_t offset_rows = 0;
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
using namespace pimoroni;
|
||||
|
||||
ST7567 st7567(128, 64, get_spi_pins(BG_SPI_FRONT));
|
||||
PicoGraphics_PenRGB332 graphics(st7567.width, st7567.height, nullptr);
|
||||
ST7567 st7567(128, 64, {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 16, SPI_BG_FRONT_PWM});
|
||||
PicoGraphics_Pen1Bit graphics(st7567.width, st7567.height, nullptr);
|
||||
|
||||
|
||||
|
||||
|
@ -55,21 +55,21 @@ int main() {
|
|||
};
|
||||
|
||||
std::vector<pt> shapes;
|
||||
for(int i = 0; i < 100; i++) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
pt shape;
|
||||
shape.x = rand() % graphics.bounds.w;
|
||||
shape.y = rand() % graphics.bounds.h;
|
||||
shape.r = (rand() % 10) + 3;
|
||||
shape.dx = float(rand() % 255) / 64.0f;
|
||||
shape.dy = float(rand() % 255) / 64.0f;
|
||||
shape.pen = graphics.create_pen(rand() % 255, rand() % 255, rand() % 255);
|
||||
shape.pen = rand() % 14;
|
||||
shapes.push_back(shape);
|
||||
}
|
||||
|
||||
Point text_location(0, 0);
|
||||
|
||||
Pen BG = graphics.create_pen(120, 40, 60);
|
||||
Pen WHITE = graphics.create_pen(255, 255, 255);
|
||||
//Pen BG = graphics.create_pen(120, 40, 60);
|
||||
//Pen WHITE = graphics.create_pen(255, 255, 255);
|
||||
|
||||
while(true) {
|
||||
if(button_a.raw()) text_location.x -= 1;
|
||||
|
@ -78,7 +78,7 @@ int main() {
|
|||
if(button_x.raw()) text_location.y -= 1;
|
||||
if(button_y.raw()) text_location.y += 1;
|
||||
|
||||
graphics.set_pen(BG);
|
||||
graphics.set_pen(0);
|
||||
graphics.clear();
|
||||
|
||||
for(auto &shape : shapes) {
|
||||
|
@ -106,19 +106,15 @@ int main() {
|
|||
|
||||
}
|
||||
|
||||
// Since HSV takes a float from 0.0 to 1.0 indicating hue,
|
||||
// then we can divide millis by the number of milliseconds
|
||||
// we want a full colour cycle to take. 5000 = 5 sec.
|
||||
uint8_t r = 0, g = 0, b = 0;
|
||||
from_hsv((float)millis() / 5000.0f, 1.0f, 0.5f + sinf(millis() / 100.0f / 3.14159f) * 0.5f, r, g, b);
|
||||
|
||||
|
||||
|
||||
graphics.set_pen(WHITE);
|
||||
graphics.set_pen(15);
|
||||
graphics.text("Hello World", text_location, 320);
|
||||
|
||||
// update screen
|
||||
st7567.update(&graphics);
|
||||
sleep_ms(1000/15);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Ładowanie…
Reference in New Issue