all complies needs testing against finished unit

This commit is contained in:
Gee Bartlett 2022-09-29 15:48:33 +01:00
parent c48f81bc90
commit 7b5946ef48
4 changed files with 47 additions and 48 deletions

View File

@ -1,4 +1,4 @@
#include "ST7567.hpp"
#include "st7567.hpp"
#include <cstdlib>
#include <math.h>
@ -49,9 +49,9 @@ namespace pimoroni {
};
void ST7567::reset() {
if(RESET == PIN_UNUSED) return;
gpio_put(RESET, 0); sleep_ms(10);
gpio_put(RESET, 1); sleep_ms(10);
if(reset_pin == PIN_UNUSED) return;
gpio_put(reset_pin, 0); sleep_ms(10);
gpio_put(reset_pin, 1); sleep_ms(10);
sleep_ms(100);
}
@ -59,8 +59,8 @@ namespace pimoroni {
void ST7567::init(bool auto_init_sequence) {
spi_init(spi, spi_baud);
gpio_set_function(reset, GPIO_FUNC_SIO);
gpio_set_dir(reset, GPIO_OUT);
gpio_set_function(reset_pin, GPIO_FUNC_SIO);
gpio_set_dir(reset_pin, GPIO_OUT);
gpio_set_function(dc, GPIO_FUNC_SIO);
gpio_set_dir(dc, GPIO_OUT);
@ -124,12 +124,12 @@ namespace pimoroni {
// Native 16-bit framebuffer update
void ST7567::update(PicoGraphics *graphics) {
uint8_t offset;
uint8_t *fb = (uint8_t *)graphics->frame_buffer;
if(graphics->pen_type == PicoGraphics::PEN_1BIT) {
command(reg::ENTER_RWMODE);
command(reg::ENTER_RMWMODE);
for (uint8_t page=0; page < 8 ; page++){
command(reg::SETPAGESTART | page);
command(reg::SETCOLL);
@ -137,32 +137,33 @@ namespace pimoroni {
gpio_put(dc, 1); // data mode
gpio_put(cs, 0);
spi_write_blocking(spi, fb, PAGESIZE / 8);
fb += PAGESIZE / 8;
fb += (PAGESIZE / 8);
gpio_put(cs, 1);
}
} else {
command(reg::ENTER_RWMODE);
} /*else {
command(reg::ENTER_RMWMODE);
gpio_put(dc, 1); // data mode
gpio_put(cs, 0);
graphics->frame_convert(PicoGraphics::PEN_1BIT, [this](void *data, size_t length) {
if (length > 0) {
for (uint8_t page=0; page < 8 ; page++){
offset = page * PAGESIZE;
command(reg::SETPAGESTART | page);
command(reg::SETCOLL);
command(reg::SETCOLH);
gpio_put(dc, 1); // data mode
gpio_put(cs, 0);
spi_write_blocking(spi, (const uint8_t*)data[offset/8], PAGESIZE / 8);
spi_write_blocking(spi, fb, PAGESIZE / 8);
fb += PAGESIZE / 8;
gpio_put(cs, 1);
}
});
};
*/
gpio_put(cs, 1);
}
}
void ST7567::set_backlight(uint8_t brightness) {
@ -172,4 +173,4 @@ namespace pimoroni {
uint16_t value = (uint16_t)(pow((float)(brightness) / 255.0f, gamma) * 65535.0f + 0.5f);
pwm_set_gpio_level(bl, value);
}
}
}

View File

@ -22,19 +22,19 @@ namespace pimoroni {
//--------------------------------------------------
private:
spi_inst_t *spi = spi0;
spi_inst_t *spi = spi0;
uint32_t dma_channel;
// interface pins with our standard defaults where appropriate
uint cs = SPI_BG_FRONT_CS;
uint dc = 20;
uint sck = SPI_DEFAULT_SCK ;
uint mosi = SPI_DEFAULT_MOSI;
uint bl = PIN_UNUSED;
uint reset = PIN_UNUSED;
uint cs;
uint dc;
uint sck;
uint mosi;
uint bl;
uint reset_pin;
uint32_t spi_baud = 30 * 1024 * 1024;
uint32_t spi_baud = 1 * 1024 * 1024;
uint8_t offset_cols = 0;
uint8_t offset_rows = 0;
@ -43,22 +43,19 @@ namespace pimoroni {
// Constructors/Destructor
//--------------------------------------------------
public:
ST7567(uint16_t width, uint16_t height, Rotation rotate) : ST7567(width, height, rotate, {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 20, PIN_UNUSED}) {};
ST7567(uint16_t width, uint16_t height, SPIPins pins, uint busy=26, uint reset=21) :
ST7567(uint16_t width, uint16_t height, SPIPins pins) :
DisplayDriver(width, height, ROTATE_0),
spi(pins.spi),
CS(pins.cs), DC(pins.dc), SCK(pins.sck), MOSI(pins.mosi), BUSY(busy), RESET(reset) {
spi(pins.spi), cs(pins.cs), dc(pins.dc), sck(pins.sck), mosi(pins.mosi), bl(pins.bl) {
init();
}
//--------------------------------------------------
// Methods
//--------------------------------------------------
public:
void update(PicoGraphics *graphics) override;
void set_backlight(uint8_t brightness) override;
void reset();
private:
void init(bool auto_init_sequence = true);

View File

@ -6,7 +6,7 @@ add_executable(
)
# Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7568 pico_graphics)
target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7567 pico_graphics)
# create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME})

View File

@ -1,25 +1,26 @@
#include <string.h>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <string.h>
#include <time.h>
#include <cstdio>
#include "libraries/pico_display_2/pico_display_2.hpp"
#include "drivers/st7789/st7789.hpp"
#include "pico/stdlib.h"
#include "libraries/pico_graphics/pico_graphics.hpp"
#include "rgbled.hpp"
#include "button.hpp"
#include "libraries/gfx_pack/gfx_pack.hpp"
#include "drivers/st7567/st7567.hpp"
#include "drivers/button/button.hpp"
using namespace pimoroni;
ST7789 st7789(320, 240, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
ST7567 st7567(128, 64, get_spi_pins(BG_SPI_FRONT));
PicoGraphics_PenRGB332 graphics(st7567.width, st7567.height, nullptr);
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);
Button button_a(PicoDisplay2::A);
Button button_b(PicoDisplay2::B);
Button button_x(PicoDisplay2::X);
Button button_y(PicoDisplay2::Y);
Button button_a(gfx_pack::A);
Button button_b(gfx_pack::B);
Button button_x(gfx_pack::X);
Button button_y(gfx_pack::Y);
// HSV Conversion expects float inputs in the range of 0.00-1.00 for each channel
// Outputs are rgb in the range 0-255 for each channel
@ -42,7 +43,7 @@ void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
}
int main() {
st7789.set_backlight(255);
st7567.set_backlight(255);
struct pt {
float x;
@ -110,14 +111,14 @@ int main() {
// we want a full colour cycle to take. 5000 = 5 sec.
uint8_t r = 0, g = 0, b = 0;
from_hsv((float)millis() / 5000.0f, 1.0f, 0.5f + sinf(millis() / 100.0f / 3.14159f) * 0.5f, r, g, b);
led.set_rgb(r, g, b);
graphics.set_pen(WHITE);
graphics.text("Hello World", text_location, 320);
// update screen
st7789.update(&graphics);
st7567.update(&graphics);
}
return 0;