kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Revert changes to badger2040 library
rodzic
c5a7c59510
commit
b5f67b0426
|
@ -1,11 +1,11 @@
|
|||
#include "badger2040.hpp"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "hardware/pwm.h"
|
||||
#include "hardware/watchdog.h"
|
||||
|
||||
#include "badger2040.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
void Badger2040::init() {
|
||||
|
@ -89,7 +89,8 @@ uint8_t _dither_value(int32_t x, int32_t y, uint8_t p) {
|
|||
0, 8, 2, 10,
|
||||
12, 4, 14, 6,
|
||||
3, 11, 1, 9,
|
||||
15, 7, 13, 5};
|
||||
15, 7, 13, 5
|
||||
};
|
||||
|
||||
if (p == 0) {
|
||||
return 1;
|
||||
|
@ -121,6 +122,7 @@ uint8_t _dither_column_value(int32_t x, uint8_t p) {
|
|||
return val;
|
||||
}
|
||||
|
||||
|
||||
void Badger2040::clear() {
|
||||
const uint32_t column_len = 128 / 8;
|
||||
const uint32_t buf_len = column_len * 296;
|
||||
|
@ -128,9 +130,11 @@ void Badger2040::clear() {
|
|||
|
||||
if (_pen == 0) {
|
||||
memset(buf, 0xff, buf_len);
|
||||
} else if (_pen == 15) {
|
||||
}
|
||||
else if (_pen == 15) {
|
||||
memset(buf, 0, buf_len);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for(uint32_t x = 0; x < 296; x++) {
|
||||
uint8_t val = _dither_column_value(x, _pen);
|
||||
memset(buf, val, column_len);
|
||||
|
@ -185,7 +189,8 @@ void Badger2040::image(const uint8_t* data) {
|
|||
void Badger2040::image(const uint8_t *data, int w, int h, int x, int y) {
|
||||
if (x == 0 && y == 0 && w == 296 && h == 128) {
|
||||
image(data);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
image(data, w, 0, 0, w, h, x, y);
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +249,8 @@ void Badger2040::rectangle(int32_t x, int32_t y, int32_t w, int32_t h) {
|
|||
*buf_ptr &= last_mask;
|
||||
*buf_ptr |= (val & (~last_mask));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for(int cx = x; cx < x + w; cx++) {
|
||||
for(int cy = y; cy < y + h; cy++) {
|
||||
uc8151_legacy.pixel(cx, cy, _dither_value(cx, cy, _pen));
|
||||
|
@ -256,46 +262,22 @@ void Badger2040::rectangle(int32_t x, int32_t y, int32_t w, int32_t h) {
|
|||
void Badger2040::line(int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
|
||||
int32_t x = x1, y = y1, dx, dy, incx, incy, balance;
|
||||
|
||||
if (x2 >= x1) {
|
||||
dx = x2 - x1;
|
||||
incx = 1;
|
||||
} else {
|
||||
dx = x1 - x2;
|
||||
incx = -1;
|
||||
}
|
||||
if (y2 >= y1) {
|
||||
dy = y2 - y1;
|
||||
incy = 1;
|
||||
} else {
|
||||
dy = y1 - y2;
|
||||
incy = -1;
|
||||
}
|
||||
if(x2 >= x1) {dx = x2 - x1; incx = 1;} else {dx = x1 - x2; incx = -1;}
|
||||
if(y2 >= y1) {dy = y2 - y1; incy = 1;} else {dy = y1 - y2; incy = -1;}
|
||||
|
||||
if(dx >= dy) {
|
||||
dy <<= 1;
|
||||
balance = dy - dx;
|
||||
dx <<= 1;
|
||||
dy <<= 1; balance = dy - dx; dx <<= 1;
|
||||
while(x != x2) {
|
||||
pixel(x, y);
|
||||
if (balance >= 0) {
|
||||
y += incy;
|
||||
balance -= dx;
|
||||
}
|
||||
balance += dy;
|
||||
x += incx;
|
||||
if (balance >= 0) {y += incy; balance -= dx;}
|
||||
balance += dy; x += incx;
|
||||
}
|
||||
} else {
|
||||
dx <<= 1;
|
||||
balance = dx - dy;
|
||||
dy <<= 1;
|
||||
dx <<= 1; balance = dx - dy; dy <<= 1;
|
||||
while(y != y2) {
|
||||
pixel(x, y);
|
||||
if (balance >= 0) {
|
||||
x += incx;
|
||||
balance -= dy;
|
||||
}
|
||||
balance += dx;
|
||||
y += incy;
|
||||
if(balance >= 0) {x += incx; balance -= dy;}
|
||||
balance += dx; y += incy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -352,42 +334,34 @@ const hershey::font_glyph_t* Badger2040::glyph_data(unsigned char c) {
|
|||
|
||||
int32_t Badger2040::glyph(unsigned char c, int32_t x, int32_t y, float s, float a) {
|
||||
if (_bitmap_font) {
|
||||
bitmap::character(
|
||||
_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||
bitmap::character(_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||
for(auto px = 0; px < w; px++) {
|
||||
for(auto py = 0; py < h; py++) {
|
||||
pixel(x + px, y + py);
|
||||
}
|
||||
}
|
||||
},
|
||||
c, x, y, std::max(1.0f, s));
|
||||
}, c, x, y, std::max(1.0f, s));
|
||||
return 0;
|
||||
} else {
|
||||
return hershey::glyph(
|
||||
_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
|
||||
return hershey::glyph(_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
|
||||
line(x1, y1, x2, y2);
|
||||
},
|
||||
c, x, y, s, a);
|
||||
}, c, x, y, s, a);
|
||||
}
|
||||
}
|
||||
|
||||
void Badger2040::text(std::string message, int32_t x, int32_t y, float s, float a, uint8_t letter_spacing) {
|
||||
if (_bitmap_font) {
|
||||
bitmap::text(
|
||||
_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||
bitmap::text(_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||
for(auto px = 0; px < w; px++) {
|
||||
for(auto py = 0; py < h; py++) {
|
||||
pixel(x + px, y + py);
|
||||
}
|
||||
}
|
||||
},
|
||||
message, x, y, 296 - x, std::max(1.0f, s), letter_spacing);
|
||||
}, message, x, y, 296 - x, std::max(1.0f, s), letter_spacing);
|
||||
} else {
|
||||
hershey::text(
|
||||
_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
|
||||
hershey::text(_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
|
||||
line(x1, y1, x2, y2);
|
||||
},
|
||||
message, x, y, s, a);
|
||||
}, message, x, y, s, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,4 +429,4 @@ void Badger2040::wait_for_press() {
|
|||
tight_loop_contents();
|
||||
}
|
||||
}
|
||||
} // namespace pimoroni
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue