2022-03-22 17:12:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include "hardware/spi.h"
|
|
|
|
#include "hardware/gpio.h"
|
2022-06-14 09:57:00 +01:00
|
|
|
#include "common/pimoroni_common.hpp"
|
|
|
|
#include "common/pimoroni_bus.hpp"
|
|
|
|
#include "libraries/pico_graphics/pico_graphics.hpp"
|
2022-03-22 17:12:59 +00:00
|
|
|
|
|
|
|
namespace pimoroni {
|
|
|
|
|
2022-06-14 09:57:00 +01:00
|
|
|
class UC8159 : public DisplayDriver {
|
2022-03-22 17:12:59 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Variables
|
|
|
|
//--------------------------------------------------
|
|
|
|
private:
|
|
|
|
spi_inst_t *spi = PIMORONI_SPI_DEFAULT_INSTANCE;
|
|
|
|
|
|
|
|
// interface pins with our standard defaults where appropriate
|
|
|
|
uint CS = SPI_BG_FRONT_CS;
|
2022-06-29 11:14:02 +01:00
|
|
|
uint DC = 28; // 27;
|
2022-03-22 17:12:59 +00:00
|
|
|
uint SCK = SPI_DEFAULT_SCK;
|
|
|
|
uint MOSI = SPI_DEFAULT_MOSI;
|
2022-06-29 10:32:11 +01:00
|
|
|
uint BUSY = PIN_UNUSED;
|
2022-06-29 11:14:02 +01:00
|
|
|
uint RESET = 27; //25;
|
2022-06-29 10:32:11 +01:00
|
|
|
|
2022-06-29 11:14:02 +01:00
|
|
|
absolute_time_t timeout;
|
2022-03-22 17:12:59 +00:00
|
|
|
|
2022-06-30 15:24:58 +01:00
|
|
|
bool blocking = false;
|
|
|
|
|
2022-03-22 17:12:59 +00:00
|
|
|
public:
|
2022-03-28 17:47:44 +01:00
|
|
|
enum colour : uint8_t {
|
|
|
|
BLACK = 0,
|
|
|
|
WHITE = 1,
|
|
|
|
GREEN = 2,
|
|
|
|
BLUE = 3,
|
|
|
|
RED = 4,
|
|
|
|
YELLOW = 5,
|
|
|
|
ORANGE = 6,
|
|
|
|
CLEAN = 7
|
|
|
|
};
|
|
|
|
|
2022-06-29 10:32:11 +01:00
|
|
|
UC8159(uint16_t width, uint16_t height) : UC8159(width, height, {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 28, PIN_UNUSED}) {};
|
2022-03-22 17:12:59 +00:00
|
|
|
|
2022-06-29 10:32:11 +01:00
|
|
|
UC8159(uint16_t width, uint16_t height, SPIPins pins, uint busy=PIN_UNUSED, uint reset=27) :
|
2022-06-14 09:57:00 +01:00
|
|
|
DisplayDriver(width, height, ROTATE_0),
|
|
|
|
spi(pins.spi),
|
|
|
|
CS(pins.cs), DC(pins.dc), SCK(pins.sck), MOSI(pins.mosi), BUSY(busy), RESET(reset) {
|
|
|
|
init();
|
|
|
|
}
|
2022-03-22 17:12:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Methods
|
|
|
|
//--------------------------------------------------
|
|
|
|
public:
|
2022-06-29 10:32:11 +01:00
|
|
|
void busy_wait(uint minimum_wait_ms=0);
|
2022-03-22 17:12:59 +00:00
|
|
|
void reset();
|
|
|
|
void power_off();
|
2022-06-14 09:57:00 +01:00
|
|
|
|
|
|
|
bool is_busy() override;
|
|
|
|
void update(PicoGraphics *graphics) override;
|
2022-03-22 17:12:59 +00:00
|
|
|
|
2022-06-30 15:24:58 +01:00
|
|
|
void set_blocking(bool blocking);
|
|
|
|
|
2022-06-14 09:57:00 +01:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void setup();
|
2022-03-22 17:12:59 +00:00
|
|
|
void command(uint8_t reg, size_t len, const uint8_t *data);
|
|
|
|
void command(uint8_t reg, std::initializer_list<uint8_t> values);
|
|
|
|
void command(uint8_t reg, const uint8_t data) {command(reg, 0, &data);};
|
|
|
|
void command(uint8_t reg) {command(reg, 0, nullptr);};
|
|
|
|
void data(size_t len, const uint8_t *data);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|