Revert changes to badger2040 library

pull/903/head
kennedn 2024-02-19 16:40:13 +00:00
rodzic c5a7c59510
commit b5f67b0426
1 zmienionych plików z 234 dodań i 260 usunięć

Wyświetl plik

@ -1,11 +1,11 @@
#include "badger2040.hpp"
#include <math.h>
#include <string.h> #include <string.h>
#include <math.h>
#include "hardware/pwm.h" #include "hardware/pwm.h"
#include "hardware/watchdog.h" #include "hardware/watchdog.h"
#include "badger2040.hpp"
namespace pimoroni { namespace pimoroni {
void Badger2040::init() { void Badger2040::init() {
@ -89,7 +89,8 @@ uint8_t _dither_value(int32_t x, int32_t y, uint8_t p) {
0, 8, 2, 10, 0, 8, 2, 10,
12, 4, 14, 6, 12, 4, 14, 6,
3, 11, 1, 9, 3, 11, 1, 9,
15, 7, 13, 5}; 15, 7, 13, 5
};
if (p == 0) { if (p == 0) {
return 1; return 1;
@ -121,6 +122,7 @@ uint8_t _dither_column_value(int32_t x, uint8_t p) {
return val; return val;
} }
void Badger2040::clear() { void Badger2040::clear() {
const uint32_t column_len = 128 / 8; const uint32_t column_len = 128 / 8;
const uint32_t buf_len = column_len * 296; const uint32_t buf_len = column_len * 296;
@ -128,9 +130,11 @@ void Badger2040::clear() {
if (_pen == 0) { if (_pen == 0) {
memset(buf, 0xff, buf_len); memset(buf, 0xff, buf_len);
} else if (_pen == 15) { }
else if (_pen == 15) {
memset(buf, 0, buf_len); memset(buf, 0, buf_len);
} else { }
else {
for(uint32_t x = 0; x < 296; x++) { for(uint32_t x = 0; x < 296; x++) {
uint8_t val = _dither_column_value(x, _pen); uint8_t val = _dither_column_value(x, _pen);
memset(buf, val, column_len); 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) { void Badger2040::image(const uint8_t *data, int w, int h, int x, int y) {
if (x == 0 && y == 0 && w == 296 && h == 128) { if (x == 0 && y == 0 && w == 296 && h == 128) {
image(data); image(data);
} else { }
else {
image(data, w, 0, 0, w, h, x, y); 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 &= last_mask;
*buf_ptr |= (val & (~last_mask)); *buf_ptr |= (val & (~last_mask));
} }
} else { }
else {
for(int cx = x; cx < x + w; cx++) { for(int cx = x; cx < x + w; cx++) {
for(int cy = y; cy < y + h; cy++) { for(int cy = y; cy < y + h; cy++) {
uc8151_legacy.pixel(cx, cy, _dither_value(cx, cy, _pen)); 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) { 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; int32_t x = x1, y = y1, dx, dy, incx, incy, balance;
if (x2 >= x1) { if(x2 >= x1) {dx = x2 - x1; incx = 1;} else {dx = x1 - x2; incx = -1;}
dx = x2 - x1; if(y2 >= y1) {dy = y2 - y1; incy = 1;} else {dy = y1 - y2; incy = -1;}
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) { if(dx >= dy) {
dy <<= 1; dy <<= 1; balance = dy - dx; dx <<= 1;
balance = dy - dx;
dx <<= 1;
while(x != x2) { while(x != x2) {
pixel(x, y); pixel(x, y);
if (balance >= 0) { if (balance >= 0) {y += incy; balance -= dx;}
y += incy; balance += dy; x += incx;
balance -= dx;
}
balance += dy;
x += incx;
} }
} else { } else {
dx <<= 1; dx <<= 1; balance = dx - dy; dy <<= 1;
balance = dx - dy;
dy <<= 1;
while(y != y2) { while(y != y2) {
pixel(x, y); pixel(x, y);
if (balance >= 0) { if(balance >= 0) {x += incx; balance -= dy;}
x += incx; balance += dx; y += incy;
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) { int32_t Badger2040::glyph(unsigned char c, int32_t x, int32_t y, float s, float a) {
if (_bitmap_font) { if (_bitmap_font) {
bitmap::character( bitmap::character(_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
for(auto px = 0; px < w; px++) { for(auto px = 0; px < w; px++) {
for(auto py = 0; py < h; py++) { for(auto py = 0; py < h; py++) {
pixel(x + px, y + py); pixel(x + px, y + py);
} }
} }
}, }, c, x, y, std::max(1.0f, s));
c, x, y, std::max(1.0f, s));
return 0; return 0;
} else { } else {
return hershey::glyph( return hershey::glyph(_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
line(x1, y1, x2, 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) { void Badger2040::text(std::string message, int32_t x, int32_t y, float s, float a, uint8_t letter_spacing) {
if (_bitmap_font) { if (_bitmap_font) {
bitmap::text( bitmap::text(_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
_bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) {
for(auto px = 0; px < w; px++) { for(auto px = 0; px < w; px++) {
for(auto py = 0; py < h; py++) { for(auto py = 0; py < h; py++) {
pixel(x + px, y + 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 { } else {
hershey::text( hershey::text(_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
line(x1, y1, x2, 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(); tight_loop_contents();
} }
} }
} // namespace pimoroni }