diff --git a/drivers/dv_display/dv_display.cpp b/drivers/dv_display/dv_display.cpp index e2f91ba6..58375669 100644 --- a/drivers/dv_display/dv_display.cpp +++ b/drivers/dv_display/dv_display.cpp @@ -459,10 +459,10 @@ namespace pimoroni { define_sprite_internal(sprite_data_idx, width, height, (uint32_t*)data); } - void DVDisplay::set_sprite(int sprite_num, uint16_t sprite_data_idx, const Point &p) + void DVDisplay::set_sprite(int sprite_num, uint16_t sprite_data_idx, const Point &p, SpriteBlendMode blend_mode) { uint8_t buf[7]; - buf[0] = 1; // BLEND_DEPTH + buf[0] = (uint8_t)blend_mode; buf[1] = sprite_data_idx & 0xff; buf[2] = sprite_data_idx >> 8; buf[3] = p.x & 0xff; diff --git a/drivers/dv_display/dv_display.hpp b/drivers/dv_display/dv_display.hpp index 4759dfd5..9ceea9db 100644 --- a/drivers/dv_display/dv_display.hpp +++ b/drivers/dv_display/dv_display.hpp @@ -25,6 +25,15 @@ namespace pimoroni { MODE_RGB888 = 3, }; + enum SpriteBlendMode : uint8_t { + BLEND_NONE = 0, // Sprite data always written to frame regardless of alpha + BLEND_DEPTH = 1, // Alpha represents depth. Order from back to front is: Sprite A0, Frame A0, Sprite A1, Frame A1 + BLEND_DEPTH2 = 2, // Alpha represents depth. Order from back to front is: Sprite A0, Frame A0, Frame A1, Sprite A1 + // Note that blend modes are only supported in RGB555 mode. + BLEND_BLEND = 3, // Use frame if Sprite A0 or Frame A1, additive blend if Sprite A1 and Frame A0 + BLEND_BLEND2 = 4, // Use frame if Sprite A0, additive blend if Sprite A1 + }; + // I2C pins static constexpr uint I2C_SDA = 6; static constexpr uint I2C_SCL = 7; @@ -150,8 +159,7 @@ namespace pimoroni { // Display/move a sprite to a given position. // Note sprite positions are always display relative (not scrolled) - // TODO: Blend mode - void set_sprite(int sprite_num, uint16_t sprite_data_idx, const Point &p); + void set_sprite(int sprite_num, uint16_t sprite_data_idx, const Point &p, SpriteBlendMode blend_mode = BLEND_DEPTH); void clear_sprite(int sprite_num); // 32 colour palette mode. Note that palette entries range from 0-31, diff --git a/examples/dv_stick/dv_sprite_test.cpp b/examples/dv_stick/dv_sprite_test.cpp index 4a3433a2..8b125a18 100644 --- a/examples/dv_stick/dv_sprite_test.cpp +++ b/examples/dv_stick/dv_sprite_test.cpp @@ -18,7 +18,7 @@ using namespace pimoroni; #define SPRITE_WIDTH 8 #define SPRITE_HEIGHT 8 -#define USE_PALETTE 1 +#define USE_PALETTE 0 #if USE_PALETTE static uint8_t sprite_data_pal[] = { @@ -104,7 +104,7 @@ int main() { while (true) { for (int i = 0; i < 32; ++i) { - display.set_sprite(i, 0, sprite_pos[i]); + display.set_sprite(i, 0, sprite_pos[i], (i < 16) ? DVDisplay::BLEND_BLEND : DVDisplay::BLEND_DEPTH); sprite_pos[i] += sprite_dir[i]; if (sprite_pos[i].x >= DISPLAY_WIDTH || sprite_pos[i].x <= 0) {