Some cleanup, clang-format
This commit is contained in:
parent
f9fe03db61
commit
e2bc0d6514
3 changed files with 52 additions and 56 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
PicoDVI display(320, 240, VREG_VOLTAGE_1_20, dvi_timing_640x480p_60hz, pimoroni_demo_hdmi_cfg);
|
||||
|
||||
#define PAUSE 2000 // Delay (millisecondss) between examples
|
||||
#define PAUSE 2000 // Delay (milliseconds) between examples
|
||||
uint8_t rotate = 0; // Current screen orientation (0-3)
|
||||
|
||||
#if !defined(CORNER_RADIUS)
|
||||
|
|
@ -15,14 +15,12 @@ uint8_t rotate = 0; // Current screen orientation (0-3)
|
|||
void setup() {
|
||||
Serial.begin(115200);
|
||||
//while(!Serial);
|
||||
Serial.println("A");
|
||||
display.begin();
|
||||
Serial.println("B");
|
||||
bool status = display.begin();
|
||||
Serial.println(status);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void loop() {
|
||||
Serial.println("C");
|
||||
dvi.drawLine(random(320), random(240), random(320), random(240), random(65536));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,48 +1,47 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "PicoDVI.h"
|
||||
#include "pico/multicore.h"
|
||||
|
||||
PicoDVI::PicoDVI(uint16_t w, uint16_t h, vreg_voltage v, const struct dvi_timing &t, const struct dvi_serialiser_cfg &c) : GFXcanvas16(w, h) {
|
||||
framebuf = getBuffer();
|
||||
framebuf_width = w;
|
||||
framebuf_height = h;
|
||||
timing = &t;
|
||||
voltage = v;
|
||||
cfg = &c;
|
||||
}
|
||||
|
||||
PicoDVI::~PicoDVI(void) {
|
||||
// if (framebuf) free(framebuf);
|
||||
}
|
||||
|
||||
static struct dvi_inst *dviptr = NULL;
|
||||
static uint16_t *fb = NULL;
|
||||
static uint16_t fbw = 0, fbh = 0;
|
||||
static volatile bool waiting = true;
|
||||
// Some elements of the PicoDVI object must be accessed in interrupts or
|
||||
// outside the class context, so a pointer to the active PicoDVI object is
|
||||
// kept. This does mean only one instance can be active, but that's the
|
||||
// typical use case anyway so we should be OK.
|
||||
static PicoDVI *dviptr = NULL;
|
||||
static volatile bool wait_begin = true;
|
||||
|
||||
// This runs at startup on core 1
|
||||
void setup1() {
|
||||
while(waiting); // Wait for begin() to do its thing
|
||||
dvi_register_irqs_this_core(dviptr, DMA_IRQ_0);
|
||||
dvi_start(dviptr);
|
||||
dvi_scanbuf_main_16bpp(dviptr);
|
||||
__builtin_unreachable();
|
||||
while (wait_begin)
|
||||
; // Wait for PicoDVI::begin() to do its thing
|
||||
dviptr->_setup();
|
||||
}
|
||||
|
||||
void core1_scanline_callback() {
|
||||
// Discard any scanline pointers passed back
|
||||
uint16_t *bufptr;
|
||||
while (queue_try_remove_u32(&dviptr->q_colour_free, &bufptr));
|
||||
// Note first two scanlines are pushed before DVI start
|
||||
static uint scanline = 2;
|
||||
bufptr = &fb[fbw * scanline];
|
||||
queue_add_blocking_u32(&dviptr->q_colour_valid, &bufptr);
|
||||
scanline = (scanline + 1) % fbh;
|
||||
void PicoDVI::_setup(void) {
|
||||
dvi_register_irqs_this_core(&dvi0, DMA_IRQ_0);
|
||||
dvi_start(&dvi0);
|
||||
dvi_scanbuf_main_16bpp(&dvi0);
|
||||
}
|
||||
|
||||
static void core1_scanline_callback() { dviptr->_scanline_callback(); }
|
||||
|
||||
void PicoDVI::_scanline_callback(void) {
|
||||
// Discard any scanline pointers passed back
|
||||
uint16_t *bufptr;
|
||||
while (queue_try_remove_u32(&dvi0.q_colour_free, &bufptr))
|
||||
;
|
||||
// Note first two scanlines are pushed before DVI start
|
||||
static uint scanline = 2;
|
||||
bufptr = &getBuffer()[WIDTH * scanline];
|
||||
queue_add_blocking_u32(&dvi0.q_colour_valid, &bufptr);
|
||||
scanline = (scanline + 1) % HEIGHT;
|
||||
}
|
||||
|
||||
PicoDVI::PicoDVI(uint16_t w, uint16_t h, vreg_voltage v,
|
||||
const struct dvi_timing &t, const struct dvi_serialiser_cfg &c)
|
||||
: GFXcanvas16(w, h), timing(&t), voltage(v), cfg(&c) {}
|
||||
|
||||
PicoDVI::~PicoDVI(void) { dviptr = NULL; }
|
||||
|
||||
bool PicoDVI::begin(void) {
|
||||
// if ((framebuf = (uint16_t *)calloc(framebuf_width * framebuf_height, sizeof(uint16_t)))) {
|
||||
if (1) {
|
||||
if (getBuffer()) { // Canvas alloc'd OK?
|
||||
vreg_set_voltage(voltage);
|
||||
sleep_ms(10);
|
||||
#ifdef RUN_FROM_CRYSTAL
|
||||
|
|
@ -57,19 +56,15 @@ bool PicoDVI::begin(void) {
|
|||
dvi0.scanline_callback = core1_scanline_callback;
|
||||
dvi_init(&dvi0, next_striped_spin_lock_num(), next_striped_spin_lock_num());
|
||||
|
||||
uint16_t *bufptr = framebuf;
|
||||
uint16_t *bufptr = getBuffer();
|
||||
queue_add_blocking_u32(&dvi0.q_colour_valid, &bufptr);
|
||||
bufptr += framebuf_width;
|
||||
bufptr += WIDTH;
|
||||
queue_add_blocking_u32(&dvi0.q_colour_valid, &bufptr);
|
||||
|
||||
dviptr = &dvi0;
|
||||
fb = framebuf;
|
||||
fbw = framebuf_width;
|
||||
fbh = framebuf_height;
|
||||
waiting = false; // Set core 1 free
|
||||
dviptr = this;
|
||||
wait_begin = false; // Set core 1 free
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "pico/stdlib.h" // In Pico SDK
|
||||
#include "../software/include/common_dvi_pin_configs.h"
|
||||
#include "hardware/vreg.h" // In Pico SDK
|
||||
#include "libdvi/dvi.h"
|
||||
#include "../software/include/common_dvi_pin_configs.h"
|
||||
#include "pico/stdlib.h" // In Pico SDK
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
class PicoDVI : public GFXcanvas16 {
|
||||
public:
|
||||
PicoDVI(uint16_t w, uint16_t h, vreg_voltage v, const struct dvi_timing &t, const struct dvi_serialiser_cfg &c);
|
||||
PicoDVI(uint16_t w, uint16_t h, vreg_voltage v, const struct dvi_timing &t,
|
||||
const struct dvi_serialiser_cfg &c);
|
||||
~PicoDVI(void);
|
||||
bool begin(void);
|
||||
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t *framebuf = NULL;
|
||||
uint16_t framebuf_width;
|
||||
uint16_t framebuf_height;
|
||||
// These functions are necessary to lib but can't be private/protected.
|
||||
// DO NOT CALL these functions in user code! Pretend they're not here.
|
||||
void _setup(void);
|
||||
void _scanline_callback(void);
|
||||
|
||||
protected:
|
||||
struct dvi_inst dvi0;
|
||||
const struct dvi_timing *timing;
|
||||
vreg_voltage voltage;
|
||||
|
|
|
|||
Loading…
Reference in a new issue