kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Badger2040: Bugfixes, danger LUTs, examples
rodzic
183dd5f8cb
commit
6ff5c39c1b
|
@ -239,6 +239,62 @@ namespace pimoroni {
|
||||||
busy_wait();
|
busy_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UC8151::turbo_luts() {
|
||||||
|
// 0x3c, 0x00, 0x2b, 0x2b, 0x24, 0x1a, ????
|
||||||
|
command(LUT_VCOM, {
|
||||||
|
0x00, 0x02, 0x02, 0x03, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00
|
||||||
|
});
|
||||||
|
|
||||||
|
command(LUT_WW, {
|
||||||
|
0xa8, 0x02, 0x02, 0x03, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
});
|
||||||
|
|
||||||
|
command(LUT_BW, {
|
||||||
|
0xa8, 0x02, 0x02, 0x03, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
});
|
||||||
|
|
||||||
|
command(LUT_WB, {
|
||||||
|
0x54, 0x02, 0x02, 0x03, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
});
|
||||||
|
|
||||||
|
command(LUT_BB, {
|
||||||
|
0x54, 0x02, 0x02, 0x03, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
});
|
||||||
|
|
||||||
|
command(PLL, {
|
||||||
|
HZ_200
|
||||||
|
});
|
||||||
|
|
||||||
|
busy_wait();
|
||||||
|
}
|
||||||
|
|
||||||
void UC8151::init() {
|
void UC8151::init() {
|
||||||
// configure spi interface and pins
|
// configure spi interface and pins
|
||||||
spi_init(spi, 12'000'000);
|
spi_init(spi, 12'000'000);
|
||||||
|
@ -285,6 +341,9 @@ namespace pimoroni {
|
||||||
case 2:
|
case 2:
|
||||||
faster_luts();
|
faster_luts();
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
turbo_luts();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -326,6 +385,10 @@ namespace pimoroni {
|
||||||
busy_wait();
|
busy_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UC8151::power_off() {
|
||||||
|
command(POF);
|
||||||
|
}
|
||||||
|
|
||||||
void UC8151::read(uint8_t reg, size_t len, uint8_t *data) {
|
void UC8151::read(uint8_t reg, size_t len, uint8_t *data) {
|
||||||
gpio_put(CS, 0);
|
gpio_put(CS, 0);
|
||||||
|
|
||||||
|
|
|
@ -182,10 +182,12 @@ namespace pimoroni {
|
||||||
bool is_busy();
|
bool is_busy();
|
||||||
void reset();
|
void reset();
|
||||||
void setup(uint8_t speed=0);
|
void setup(uint8_t speed=0);
|
||||||
|
void power_off();
|
||||||
|
|
||||||
void default_luts();
|
void default_luts();
|
||||||
void fast_luts();
|
void fast_luts();
|
||||||
void faster_luts();
|
void faster_luts();
|
||||||
|
void turbo_luts();
|
||||||
|
|
||||||
void read(uint8_t reg, size_t len, uint8_t *data);
|
void read(uint8_t reg, size_t len, uint8_t *data);
|
||||||
void command(uint8_t reg, size_t len, const uint8_t *data);
|
void command(uint8_t reg, size_t len, const uint8_t *data);
|
||||||
|
|
|
@ -174,6 +174,10 @@ namespace pimoroni {
|
||||||
return uc8151.is_busy();
|
return uc8151.is_busy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Badger2040::power_off() {
|
||||||
|
uc8151.power_off();
|
||||||
|
}
|
||||||
|
|
||||||
void Badger2040::update_speed(uint8_t speed) {
|
void Badger2040::update_speed(uint8_t speed) {
|
||||||
uc8151.update_speed(speed);
|
uc8151.update_speed(speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace pimoroni {
|
||||||
void halt();
|
void halt();
|
||||||
void sleep();
|
void sleep();
|
||||||
bool is_busy();
|
bool is_busy();
|
||||||
|
void power_off();
|
||||||
|
|
||||||
// state
|
// state
|
||||||
void led(uint8_t brightness);
|
void led(uint8_t brightness);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,22 @@
|
||||||
|
import time
|
||||||
|
import badger2040
|
||||||
|
from machine import RTC
|
||||||
|
|
||||||
|
rtc = RTC()
|
||||||
|
screen = badger2040.Badger2040()
|
||||||
|
screen.update_speed(badger2040.UPDATE_TURBO)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
year, month, day, wd, hour, minute, second, _ = rtc.datetime()
|
||||||
|
hms = "{:02} {:02} {:02}".format(hour, minute, second)
|
||||||
|
ymd = "{:04}/{:02}/{:02}".format(year, month, day)
|
||||||
|
|
||||||
|
screen.pen(15)
|
||||||
|
screen.clear()
|
||||||
|
screen.pen(1)
|
||||||
|
screen.thickness(5)
|
||||||
|
screen.text(hms, 0, 0, 2.0)
|
||||||
|
screen.thickness(3)
|
||||||
|
screen.text(ymd, 0, 60, 1.0)
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
|
@ -0,0 +1,109 @@
|
||||||
|
import gc
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import math
|
||||||
|
import machine
|
||||||
|
import badger2040
|
||||||
|
|
||||||
|
page = 0
|
||||||
|
|
||||||
|
examples = [
|
||||||
|
"clock.py",
|
||||||
|
"fonts.py",
|
||||||
|
"clean.py",
|
||||||
|
"interrupt.py",
|
||||||
|
"scanline.py",
|
||||||
|
"lut-test.py",
|
||||||
|
"quictest.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
MAX_PAGE = math.ceil(len(examples) / 3)
|
||||||
|
|
||||||
|
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
|
||||||
|
# Early exit if a button is pressed
|
||||||
|
if button_a.value():
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
screen = badger2040.Badger2040()
|
||||||
|
screen.update_speed(1)
|
||||||
|
|
||||||
|
|
||||||
|
def render():
|
||||||
|
screen.pen(15)
|
||||||
|
screen.clear()
|
||||||
|
screen.pen(0)
|
||||||
|
screen.thickness(2)
|
||||||
|
|
||||||
|
max_icons = min(3, len(examples[(page * 3):]))
|
||||||
|
|
||||||
|
for i in range(max_icons):
|
||||||
|
x = (14 + 80) * i + 14
|
||||||
|
label = examples[i + (page * 3)].replace(".py", "")
|
||||||
|
screen.rectangle(x, 24, 80, 80)
|
||||||
|
screen.text(label, x, 24 + 80 + 10, 0.5)
|
||||||
|
|
||||||
|
for i in range(MAX_PAGE):
|
||||||
|
x = 286
|
||||||
|
y = int((128 / 2) - (MAX_PAGE * 10 / 2) + (i * 10))
|
||||||
|
screen.pen(0)
|
||||||
|
screen.rectangle(x, y, 8, 8)
|
||||||
|
if page != i:
|
||||||
|
screen.pen(15)
|
||||||
|
screen.rectangle(x + 1, y + 1, 6, 6)
|
||||||
|
|
||||||
|
screen.update()
|
||||||
|
|
||||||
|
|
||||||
|
def launch(file):
|
||||||
|
for k in locals().keys():
|
||||||
|
if k not in ("gc", "file"):
|
||||||
|
del locals()[k]
|
||||||
|
gc.collect()
|
||||||
|
__import__(file)
|
||||||
|
|
||||||
|
|
||||||
|
def get_example(index):
|
||||||
|
try:
|
||||||
|
return examples[(page * 3) + index]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def button(pin):
|
||||||
|
global page
|
||||||
|
if pin == button_a:
|
||||||
|
example = get_example(0)
|
||||||
|
if example: launch(example)
|
||||||
|
if pin == button_b:
|
||||||
|
example = get_example(1)
|
||||||
|
if example: launch(example)
|
||||||
|
if pin == button_c:
|
||||||
|
example = get_example(2)
|
||||||
|
if example: launch(example)
|
||||||
|
if pin == button_up:
|
||||||
|
if page > 0:
|
||||||
|
page -= 1
|
||||||
|
render()
|
||||||
|
if pin == button_down:
|
||||||
|
if page < MAX_PAGE - 1:
|
||||||
|
page += 1
|
||||||
|
render()
|
||||||
|
|
||||||
|
|
||||||
|
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
|
|
||||||
|
render()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(1.0)
|
||||||
|
|
|
@ -45,7 +45,7 @@ STATIC const mp_rom_map_elem_t Badger2040_locals_dict_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&Badger2040_line_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&Badger2040_line_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&Badger2040_rectangle_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&Badger2040_rectangle_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_glyph), MP_ROM_PTR(&Badger2040_glyph_obj) },
|
//{ MP_ROM_QSTR(MP_QSTR_glyph), MP_ROM_PTR(&Badger2040_glyph_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&Badger2040_text_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&Badger2040_text_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_command), MP_ROM_PTR(&Badger2040_command_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_command), MP_ROM_PTR(&Badger2040_command_obj) },
|
||||||
|
@ -71,6 +71,7 @@ STATIC const mp_map_elem_t badger2040_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_UPDATE_NORMAL), MP_ROM_INT(0) },
|
{ MP_ROM_QSTR(MP_QSTR_UPDATE_NORMAL), MP_ROM_INT(0) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_UPDATE_FAST), MP_ROM_INT(1) },
|
{ MP_ROM_QSTR(MP_QSTR_UPDATE_FAST), MP_ROM_INT(1) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_UPDATE_TURBO), MP_ROM_INT(2) },
|
{ MP_ROM_QSTR(MP_QSTR_UPDATE_TURBO), MP_ROM_INT(2) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_UPDATE_SUPER_EXTRA_TURBO), MP_ROM_INT(3) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(296) },
|
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(296) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(128) },
|
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(128) },
|
||||||
|
|
|
@ -122,6 +122,8 @@ MICROPY_EVENT_POLL_HOOK
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->badger2040->power_off();
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +163,8 @@ MICROPY_EVENT_POLL_HOOK
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->badger2040->power_off();
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,14 +283,14 @@ mp_obj_t Badger2040_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||||
// image
|
// image
|
||||||
|
|
||||||
mp_obj_t Badger2040_glyph(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
mp_obj_t Badger2040_glyph(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale };
|
enum { ARG_self, ARG_char, ARG_x, ARG_y, ARG_scale, ARG_rotation };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
{ MP_QSTR_char, MP_ARG_REQUIRED | MP_ARG_INT },
|
{ MP_QSTR_char, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||||
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||||
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||||
{ MP_QSTR_scale, MP_ARG_OBJ, {.u_obj = mp_obj_new_float(1.0f)} },
|
{ MP_QSTR_scale, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||||
{ MP_QSTR_rotation, MP_ARG_OBJ, {.u_obj = mp_obj_new_float(0.0f)} }
|
{ MP_QSTR_rotation, MP_ARG_OBJ, {.u_obj = mp_const_none} }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse args.
|
// Parse args.
|
||||||
|
@ -296,10 +300,17 @@ mp_obj_t Badger2040_glyph(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
|
||||||
int c = args[ARG_char].u_int;
|
int c = args[ARG_char].u_int;
|
||||||
int x = args[ARG_x].u_int;
|
int x = args[ARG_x].u_int;
|
||||||
int y = args[ARG_y].u_int;
|
int y = args[ARG_y].u_int;
|
||||||
float scale = mp_obj_get_float(args[ARG_scale].u_obj);
|
float scale = 1.0f;
|
||||||
|
if (args[ARG_scale].u_obj != mp_const_none) {
|
||||||
|
scale = mp_obj_get_float(args[ARG_scale].u_obj);
|
||||||
|
}
|
||||||
|
float rotation = 0.0f;
|
||||||
|
if (args[ARG_rotation].u_obj != mp_const_none) {
|
||||||
|
rotation = mp_obj_get_float(args[ARG_rotation].u_obj);
|
||||||
|
}
|
||||||
|
|
||||||
_Badger2040_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Badger2040_obj_t);
|
_Badger2040_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Badger2040_obj_t);
|
||||||
self->badger2040->glyph(c, x, y, scale);
|
self->badger2040->glyph(c, x, y, scale, rotation);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -311,8 +322,8 @@ mp_obj_t Badger2040_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||||
{ MP_QSTR_message, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_message, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||||
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||||
{ MP_QSTR_scale, MP_ARG_OBJ, {.u_obj = mp_obj_new_float(1.0f)} },
|
{ MP_QSTR_scale, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||||
{ MP_QSTR_rotation, MP_ARG_OBJ, {.u_obj = mp_obj_new_float(0.0f)} }
|
{ MP_QSTR_rotation, MP_ARG_OBJ, {.u_obj = mp_const_none} }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse args.
|
// Parse args.
|
||||||
|
@ -322,8 +333,14 @@ mp_obj_t Badger2040_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||||
std::string message = mp_obj_to_string_r(args[ARG_message].u_obj);
|
std::string message = mp_obj_to_string_r(args[ARG_message].u_obj);
|
||||||
int x = args[ARG_x].u_int;
|
int x = args[ARG_x].u_int;
|
||||||
int y = args[ARG_y].u_int;
|
int y = args[ARG_y].u_int;
|
||||||
float scale = mp_obj_get_float(args[ARG_scale].u_obj);
|
float scale = 1.0f;
|
||||||
float rotation = mp_obj_get_float(args[ARG_rotation].u_obj);
|
if (args[ARG_scale].u_obj != mp_const_none) {
|
||||||
|
scale = mp_obj_get_float(args[ARG_scale].u_obj);
|
||||||
|
}
|
||||||
|
float rotation = 0.0f;
|
||||||
|
if (args[ARG_rotation].u_obj != mp_const_none) {
|
||||||
|
rotation = mp_obj_get_float(args[ARG_rotation].u_obj);
|
||||||
|
}
|
||||||
|
|
||||||
_Badger2040_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Badger2040_obj_t);
|
_Badger2040_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Badger2040_obj_t);
|
||||||
self->badger2040->text(message, x, y, scale, rotation);
|
self->badger2040->text(message, x, y, scale, rotation);
|
||||||
|
|
Ładowanie…
Reference in New Issue