kopia lustrzana https://github.com/pimoroni/pimoroni-pico
UC8151: Refactor to uc8151_legacy.
rodzic
a6458d2321
commit
646bd1a9b0
|
@ -27,7 +27,7 @@ add_subdirectory(rgbled)
|
|||
add_subdirectory(icp10125)
|
||||
add_subdirectory(scd4x)
|
||||
add_subdirectory(hub75)
|
||||
add_subdirectory(uc8151)
|
||||
add_subdirectory(uc8151_legacy)
|
||||
add_subdirectory(pwm)
|
||||
add_subdirectory(servo)
|
||||
add_subdirectory(encoder)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
include(uc8151.cmake)
|
|
@ -0,0 +1 @@
|
|||
include(uc8151_legacy.cmake)
|
|
@ -1,4 +1,4 @@
|
|||
set(DRIVER_NAME uc8151)
|
||||
set(DRIVER_NAME uc8151_legacy)
|
||||
add_library(${DRIVER_NAME} INTERFACE)
|
||||
|
||||
target_sources(${DRIVER_NAME} INTERFACE
|
|
@ -1,4 +1,4 @@
|
|||
#include "uc8151.hpp"
|
||||
#include "uc8151_legacy.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
|
@ -48,23 +48,23 @@ namespace pimoroni {
|
|||
TSSET = 0xe5
|
||||
};
|
||||
|
||||
bool UC8151::is_busy() {
|
||||
bool UC8151_Legacy::is_busy() {
|
||||
return !gpio_get(BUSY);
|
||||
}
|
||||
|
||||
void UC8151::busy_wait() {
|
||||
void UC8151_Legacy::busy_wait() {
|
||||
while(is_busy()) {
|
||||
tight_loop_contents();
|
||||
}
|
||||
}
|
||||
|
||||
void UC8151::reset() {
|
||||
void UC8151_Legacy::reset() {
|
||||
gpio_put(RESET, 0); sleep_ms(10);
|
||||
gpio_put(RESET, 1); sleep_ms(10);
|
||||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::default_luts() {
|
||||
void UC8151_Legacy::default_luts() {
|
||||
command(LUT_VCOM, {
|
||||
0x00, 0x64, 0x64, 0x37, 0x00, 0x01,
|
||||
0x00, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
||||
|
@ -119,7 +119,7 @@ namespace pimoroni {
|
|||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::medium_luts() {
|
||||
void UC8151_Legacy::medium_luts() {
|
||||
|
||||
command(LUT_VCOM, {
|
||||
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
||||
|
@ -175,7 +175,7 @@ namespace pimoroni {
|
|||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::fast_luts() {
|
||||
void UC8151_Legacy::fast_luts() {
|
||||
// 0x3c, 0x00, 0x2b, 0x2b, 0x24, 0x1a, ????
|
||||
command(LUT_VCOM, {
|
||||
0x00, 0x04, 0x04, 0x07, 0x00, 0x01,
|
||||
|
@ -235,7 +235,7 @@ namespace pimoroni {
|
|||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::turbo_luts() {
|
||||
void UC8151_Legacy::turbo_luts() {
|
||||
// 0x3c, 0x00, 0x2b, 0x2b, 0x24, 0x1a, ????
|
||||
command(LUT_VCOM, {
|
||||
0x00, 0x01, 0x01, 0x02, 0x00, 0x01,
|
||||
|
@ -295,7 +295,7 @@ namespace pimoroni {
|
|||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::init() {
|
||||
void UC8151_Legacy::init() {
|
||||
// configure spi interface and pins
|
||||
spi_init(spi, 12'000'000);
|
||||
|
||||
|
@ -320,7 +320,7 @@ namespace pimoroni {
|
|||
setup();
|
||||
};
|
||||
|
||||
void UC8151::setup(uint8_t speed) {
|
||||
void UC8151_Legacy::setup(uint8_t speed) {
|
||||
reset();
|
||||
|
||||
_update_speed = speed;
|
||||
|
@ -389,11 +389,11 @@ namespace pimoroni {
|
|||
busy_wait();
|
||||
}
|
||||
|
||||
void UC8151::power_off() {
|
||||
void UC8151_Legacy::power_off() {
|
||||
command(POF);
|
||||
}
|
||||
|
||||
void UC8151::read(uint8_t reg, size_t len, uint8_t *data) {
|
||||
void UC8151_Legacy::read(uint8_t reg, size_t len, uint8_t *data) {
|
||||
gpio_put(CS, 0);
|
||||
|
||||
gpio_put(DC, 0); // command mode
|
||||
|
@ -421,7 +421,7 @@ namespace pimoroni {
|
|||
gpio_put(CS, 1);
|
||||
}
|
||||
|
||||
void UC8151::command(uint8_t reg, size_t len, const uint8_t *data) {
|
||||
void UC8151_Legacy::command(uint8_t reg, size_t len, const uint8_t *data) {
|
||||
gpio_put(CS, 0);
|
||||
|
||||
gpio_put(DC, 0); // command mode
|
||||
|
@ -435,18 +435,18 @@ namespace pimoroni {
|
|||
gpio_put(CS, 1);
|
||||
}
|
||||
|
||||
void UC8151::data(size_t len, const uint8_t *data) {
|
||||
void UC8151_Legacy::data(size_t len, const uint8_t *data) {
|
||||
gpio_put(CS, 0);
|
||||
gpio_put(DC, 1); // data mode
|
||||
spi_write_blocking(spi, (const uint8_t*)data, len);
|
||||
gpio_put(CS, 1);
|
||||
}
|
||||
|
||||
void UC8151::command(uint8_t reg, std::initializer_list<uint8_t> values) {
|
||||
void UC8151_Legacy::command(uint8_t reg, std::initializer_list<uint8_t> values) {
|
||||
command(reg, values.size(), (uint8_t *)values.begin());
|
||||
}
|
||||
|
||||
void UC8151::pixel(int x, int y, int v) {
|
||||
void UC8151_Legacy::pixel(int x, int y, int v) {
|
||||
// bounds check
|
||||
if(x < 0 || y < 0 || x >= width || y >= height) return;
|
||||
|
||||
|
@ -461,24 +461,24 @@ namespace pimoroni {
|
|||
*p |= b; // set bit value
|
||||
}
|
||||
|
||||
uint8_t* UC8151::get_frame_buffer() {
|
||||
uint8_t* UC8151_Legacy::get_frame_buffer() {
|
||||
return frame_buffer;
|
||||
}
|
||||
|
||||
void UC8151::invert(bool inv) {
|
||||
void UC8151_Legacy::invert(bool inv) {
|
||||
inverted = inv;
|
||||
command(CDI, {(uint8_t)(inverted ? 0b01'01'1100 : 0b01'00'1100)}); // vcom and data interval
|
||||
}
|
||||
|
||||
void UC8151::update_speed(uint8_t speed) {
|
||||
void UC8151_Legacy::update_speed(uint8_t speed) {
|
||||
setup(speed);
|
||||
}
|
||||
|
||||
uint8_t UC8151::update_speed() {
|
||||
uint8_t UC8151_Legacy::update_speed() {
|
||||
return _update_speed;
|
||||
}
|
||||
|
||||
uint32_t UC8151::update_time() {
|
||||
uint32_t UC8151_Legacy::update_time() {
|
||||
switch(_update_speed) {
|
||||
case 0:
|
||||
return 4500;
|
||||
|
@ -493,7 +493,7 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
void UC8151::partial_update(int x, int y, int w, int h, bool blocking) {
|
||||
void UC8151_Legacy::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
|
||||
if(blocking) {
|
||||
|
@ -539,7 +539,7 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
void UC8151::update(bool blocking) {
|
||||
void UC8151_Legacy::update(bool blocking) {
|
||||
if(blocking) {
|
||||
busy_wait();
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
void UC8151::off() {
|
||||
void UC8151_Legacy::off() {
|
||||
busy_wait();
|
||||
command(POF); // turn off
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
class UC8151 {
|
||||
class UC8151_Legacy {
|
||||
enum PSR_FLAGS {
|
||||
RES_96x230 = 0b00000000,
|
||||
RES_96x252 = 0b01000000,
|
||||
|
@ -149,15 +149,15 @@ namespace pimoroni {
|
|||
uint8_t _update_speed = 0;
|
||||
|
||||
public:
|
||||
UC8151(uint16_t width, uint16_t height) :
|
||||
UC8151_Legacy(uint16_t width, uint16_t height) :
|
||||
width(width), height(height), frame_buffer(new uint8_t[width * height / 8]) {
|
||||
}
|
||||
|
||||
UC8151(uint16_t width, uint16_t height, uint8_t *frame_buffer) :
|
||||
UC8151_Legacy(uint16_t width, uint16_t height, uint8_t *frame_buffer) :
|
||||
width(width), height(height), frame_buffer(frame_buffer) {
|
||||
}
|
||||
|
||||
UC8151(uint16_t width, uint16_t height,
|
||||
UC8151_Legacy(uint16_t width, uint16_t height,
|
||||
spi_inst_t *spi,
|
||||
uint CS, uint DC, uint SCK, uint MOSI,
|
||||
uint BUSY = PIN_UNUSED, uint RESET = PIN_UNUSED) :
|
||||
|
@ -166,7 +166,7 @@ namespace pimoroni {
|
|||
spi(spi),
|
||||
CS(CS), DC(DC), SCK(SCK), MOSI(MOSI), BUSY(BUSY), RESET(RESET) {}
|
||||
|
||||
UC8151(uint16_t width, uint16_t height,
|
||||
UC8151_Legacy(uint16_t width, uint16_t height,
|
||||
uint8_t *frame_buffer,
|
||||
spi_inst_t *spi,
|
||||
uint CS, uint DC, uint SCK, uint MOSI,
|
|
@ -8,4 +8,4 @@ target_sources(${LIB_NAME} INTERFACE
|
|||
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${LIB_NAME} INTERFACE bitmap_fonts hershey_fonts pico_stdlib hardware_pwm uc8151)
|
||||
target_link_libraries(${LIB_NAME} INTERFACE bitmap_fonts hershey_fonts pico_stdlib hardware_pwm uc8151_legacy)
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace pimoroni {
|
|||
gpio_set_function(LED, GPIO_FUNC_PWM);
|
||||
led(0);
|
||||
|
||||
uc8151.init();
|
||||
uc8151_legacy.init();
|
||||
|
||||
// TODO: set default image?
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ namespace pimoroni {
|
|||
void Badger2040::clear() {
|
||||
const uint32_t column_len = 128 / 8;
|
||||
const uint32_t buf_len = column_len * 296;
|
||||
uint8_t* buf = uc8151.get_frame_buffer();
|
||||
uint8_t* buf = uc8151_legacy.get_frame_buffer();
|
||||
|
||||
if (_pen == 0) {
|
||||
memset(buf, 0xff, buf_len);
|
||||
|
@ -145,12 +145,12 @@ namespace pimoroni {
|
|||
|
||||
void Badger2040::pixel(int32_t x, int32_t y) {
|
||||
if(_thickness == 1) {
|
||||
uc8151.pixel(x, y, _dither_value(x, y, _pen));
|
||||
uc8151_legacy.pixel(x, y, _dither_value(x, y, _pen));
|
||||
}else{
|
||||
uint8_t ht = _thickness / 2;
|
||||
for(int sy = 0; sy < _thickness; sy++) {
|
||||
for(int sx = 0; sx < _thickness; sx++) {
|
||||
uc8151.pixel(x + sx - ht, y + sy - ht, _dither_value(x + sx - ht, y + sy - ht, _pen));
|
||||
uc8151_legacy.pixel(x + sx - ht, y + sy - ht, _dither_value(x + sx - ht, y + sy - ht, _pen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ namespace pimoroni {
|
|||
|
||||
// Display an image that fills the screen (296*128)
|
||||
void Badger2040::image(const uint8_t* data) {
|
||||
uint8_t* ptr = uc8151.get_frame_buffer();
|
||||
uint8_t* ptr = uc8151_legacy.get_frame_buffer();
|
||||
|
||||
for (uint32_t x = 0; x < 296; ++x) {
|
||||
// extract bitmask for this pixel
|
||||
|
@ -205,7 +205,7 @@ namespace pimoroni {
|
|||
uint32_t bm = 0b10000000 >> ((x + sx) & 0b111);
|
||||
|
||||
// draw the pixel
|
||||
uc8151.pixel(dx + x, dy + y, data[o] & bm);
|
||||
uc8151_legacy.pixel(dx + x, dy + y, data[o] & bm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ namespace pimoroni {
|
|||
|
||||
if (h >= 8) {
|
||||
// Directly write to the frame buffer when clearing a large area
|
||||
uint8_t* buf = uc8151.get_frame_buffer();
|
||||
uint8_t* buf = uc8151_legacy.get_frame_buffer();
|
||||
|
||||
for(int cx = x; cx < x + w; cx++) {
|
||||
uint8_t* buf_ptr = &buf[cx * 16 + y / 8];
|
||||
|
@ -253,7 +253,7 @@ namespace pimoroni {
|
|||
else {
|
||||
for(int cx = x; cx < x + w; cx++) {
|
||||
for(int cy = y; cy < y + h; cy++) {
|
||||
uc8151.pixel(cx, cy, _dither_value(cx, cy, _pen));
|
||||
uc8151_legacy.pixel(cx, cy, _dither_value(cx, cy, _pen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,11 +283,11 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
void Badger2040::debug_command(uint8_t reg, size_t len, const uint8_t *data) {
|
||||
uc8151.command(reg, len, data);
|
||||
uc8151_legacy.command(reg, len, data);
|
||||
}
|
||||
|
||||
void Badger2040::dump_otp(uint8_t *data) {
|
||||
uc8151.read(0xa2, 0xFFF, data);
|
||||
uc8151_legacy.read(0xa2, 0xFFF, data);
|
||||
}
|
||||
|
||||
void Badger2040::update_button_states() {
|
||||
|
@ -301,31 +301,31 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
bool Badger2040::is_busy() {
|
||||
return uc8151.is_busy();
|
||||
return uc8151_legacy.is_busy();
|
||||
}
|
||||
|
||||
void Badger2040::power_off() {
|
||||
uc8151.power_off();
|
||||
uc8151_legacy.power_off();
|
||||
}
|
||||
|
||||
void Badger2040::invert(bool invert) {
|
||||
uc8151.invert(invert);
|
||||
uc8151_legacy.invert(invert);
|
||||
}
|
||||
|
||||
void Badger2040::update_speed(uint8_t speed) {
|
||||
uc8151.update_speed(speed);
|
||||
uc8151_legacy.update_speed(speed);
|
||||
}
|
||||
|
||||
uint32_t Badger2040::update_time() {
|
||||
return uc8151.update_time();
|
||||
return uc8151_legacy.update_time();
|
||||
}
|
||||
|
||||
void Badger2040::partial_update(int x, int y, int w, int h, bool blocking) {
|
||||
uc8151.partial_update(x, y, w, h, blocking);
|
||||
uc8151_legacy.partial_update(x, y, w, h, blocking);
|
||||
}
|
||||
|
||||
void Badger2040::update(bool blocking) {
|
||||
uc8151.update(blocking);
|
||||
uc8151_legacy.update(blocking);
|
||||
}
|
||||
|
||||
const hershey::font_glyph_t* Badger2040::glyph_data(unsigned char c) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "drivers/uc8151/uc8151.hpp"
|
||||
#include "drivers/uc8151_legacy/uc8151_legacy.hpp"
|
||||
|
||||
#include "libraries/hershey_fonts/hershey_fonts.hpp"
|
||||
#include "libraries/bitmap_fonts/bitmap_fonts.hpp"
|
||||
|
@ -14,7 +14,7 @@ namespace pimoroni {
|
|||
|
||||
class Badger2040 {
|
||||
protected:
|
||||
UC8151 uc8151;
|
||||
UC8151_Legacy uc8151_legacy;
|
||||
const hershey::font_t *_font = &hershey::futural;
|
||||
const bitmap::font_t *_bitmap_font = nullptr;
|
||||
uint8_t _pen = 0;
|
||||
|
@ -25,11 +25,11 @@ namespace pimoroni {
|
|||
|
||||
public:
|
||||
Badger2040()
|
||||
: uc8151(296, 128, spi0, CS, DC, CLK, MOSI, BUSY, RESET) {
|
||||
: uc8151_legacy(296, 128, spi0, CS, DC, CLK, MOSI, BUSY, RESET) {
|
||||
};
|
||||
// Constructor for Python-managed buffer
|
||||
Badger2040(uint8_t *framebuffer)
|
||||
: uc8151(296, 128, framebuffer, spi0, CS, DC, CLK, MOSI, BUSY, RESET) {
|
||||
: uc8151_legacy(296, 128, framebuffer, spi0, CS, DC, CLK, MOSI, BUSY, RESET) {
|
||||
};
|
||||
void init();
|
||||
void update(bool blocking=false);
|
||||
|
|
|
@ -7,13 +7,13 @@ target_sources(usermod_${MOD_NAME} INTERFACE
|
|||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/badgerinit.S
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/badger2040/badger2040.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8151/uc8151.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8151_legacy/uc8151_legacy.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/badger2040/
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8151/
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8151_legacy/
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
|
|
Ładowanie…
Reference in New Issue