Badger2040: Enforce minimum update blocking time.

MichaelBell-battery-improvements
Phil Howard 2022-03-25 10:57:30 +00:00
rodzic f332dcdf2e
commit b1fd8936cf
5 zmienionych plików z 38 dodań i 2 usunięć

Wyświetl plik

@ -323,6 +323,8 @@ namespace pimoroni {
void UC8151::setup(uint8_t speed) {
reset();
_update_speed = speed;
if(speed == 0) {
command(PSR, {
RES_128x296 | LUT_OTP | FORMAT_BW | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE
@ -468,6 +470,25 @@ namespace pimoroni {
setup(speed);
}
uint8_t UC8151::update_speed() {
return _update_speed;
}
uint32_t UC8151::update_time() {
switch(_update_speed) {
case 0:
return 5500;
case 1:
return 2600;
case 2:
return 1000;
case 3:
return 300;
default:
return 5500;
}
}
void UC8151::partial_update(int x, int y, int w, int h, bool blocking) {
// y is given in columns ("banks"), which are groups of 8 horiontal pixels
// x is given in pixels

Wyświetl plik

@ -146,6 +146,8 @@ namespace pimoroni {
bool inverted = false;
uint8_t _update_speed = 0;
public:
UC8151(uint16_t width, uint16_t height) :
width(width), height(height), frame_buffer(new uint8_t[width * height / 8]) {
@ -199,6 +201,8 @@ namespace pimoroni {
void invert(bool invert);
void update_speed(uint8_t speed);
uint8_t update_speed();
uint32_t update_time();
void update(bool blocking = true);
void partial_update(int x, int y, int w, int h, bool blocking = true);
void off();

Wyświetl plik

@ -220,6 +220,10 @@ namespace pimoroni {
uc8151.update_speed(speed);
}
uint32_t Badger2040::update_time() {
return uc8151.update_time();
}
void Badger2040::partial_update(int x, int y, int w, int h, bool blocking) {
uc8151.partial_update(x, y, w, h, blocking);
}

Wyświetl plik

@ -30,6 +30,7 @@ namespace pimoroni {
void update(bool blocking=false);
void partial_update(int x, int y, int w, int h, bool blocking=false);
void update_speed(uint8_t speed);
uint32_t update_time();
void halt();
void sleep();
bool is_busy();

Wyświetl plik

@ -149,9 +149,12 @@ MICROPY_EVENT_POLL_HOOK
#endif
}
absolute_time_t t_end = make_timeout_time_ms(self->badger2040->update_time());
self->badger2040->update(false);
while(self->badger2040->is_busy()) {
// Ensure blocking for the minimum amount of time
// in cases where "is_busy" is unreliable.
while(self->badger2040->is_busy() || absolute_time_diff_us(t_end, get_absolute_time()) > 0) {
#ifdef MICROPY_EVENT_POLL_HOOK
MICROPY_EVENT_POLL_HOOK
#endif
@ -190,9 +193,12 @@ MICROPY_EVENT_POLL_HOOK
#endif
}
absolute_time_t t_end = make_timeout_time_ms(self->badger2040->update_time());
self->badger2040->partial_update(x, y, w, h);
while(self->badger2040->is_busy()) {
// Ensure blocking for the minimum amount of time
// in cases where "is_busy" is unreliable.
while(self->badger2040->is_busy() || absolute_time_diff_us(t_end, get_absolute_time()) > 0) {
#ifdef MICROPY_EVENT_POLL_HOOK
MICROPY_EVENT_POLL_HOOK
#endif