Skip to content

Commit 0067b10

Browse files
AndrewCaponGadgetoid
authored andcommitted
Inky 7.3: Direct pen & PSRAM update.
1 parent b810ffd commit 0067b10

15 files changed

+648
-2
lines changed

drivers/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ add_subdirectory(vl53l5cx)
3939
add_subdirectory(pcf85063a)
4040
add_subdirectory(pms5003)
4141
add_subdirectory(sh1107)
42-
add_subdirectory(st7567)
42+
add_subdirectory(st7567)
43+
add_subdirectory(psram_display)
44+
add_subdirectory(uc8159_inky7)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(psram_display.cmake)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(DRIVER_NAME psram_display)
2+
add_library(${DRIVER_NAME} INTERFACE)
3+
4+
target_sources(${DRIVER_NAME} INTERFACE
5+
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp)
6+
7+
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
8+
9+
# Pull in pico libraries that we need
10+
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_spi)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "psram_display.hpp"
2+
3+
#include <cstdlib>
4+
#include <math.h>
5+
#include <string.h>
6+
7+
namespace pimoroni {
8+
9+
enum reg {
10+
WRITE = 0x02,
11+
READ = 0x03,
12+
RESET_ENABLE = 0x66,
13+
RESET = 0x99
14+
};
15+
16+
void PSRamDisplay::init() {
17+
uint baud = spi_init(spi, 31'250'000);
18+
printf("PSRam connected at %u\n", baud);
19+
gpio_set_function(CS, GPIO_FUNC_SIO);
20+
gpio_set_dir(CS, GPIO_OUT);
21+
gpio_put(CS, 1);
22+
23+
gpio_set_function(SCK, GPIO_FUNC_SPI);
24+
gpio_set_function(MOSI, GPIO_FUNC_SPI);
25+
gpio_set_function(MISO, GPIO_FUNC_SPI);
26+
27+
gpio_put(CS, 0);
28+
uint8_t command_buffer[2] = {RESET_ENABLE, RESET};
29+
spi_write_blocking(spi, command_buffer, 2);
30+
gpio_put(CS, 1);
31+
}
32+
33+
void PSRamDisplay::write(uint32_t address, size_t len, const uint8_t *data)
34+
{
35+
gpio_put(CS, 0);
36+
uint8_t command_buffer[4] = {WRITE, (uint8_t)((address >> 16) & 0xFF), (uint8_t)((address >> 8) & 0xFF), (uint8_t)(address & 0xFF)};
37+
spi_write_blocking(spi, command_buffer, 4);
38+
spi_write_blocking(spi, data, len);
39+
gpio_put(CS, 1);
40+
}
41+
42+
void PSRamDisplay::write(uint32_t address, size_t len, const uint8_t byte)
43+
{
44+
gpio_put(CS, 0);
45+
uint8_t command_buffer[4] = {WRITE, (uint8_t)((address >> 16) & 0xFF), (uint8_t)((address >> 8) & 0xFF), (uint8_t)(address & 0xFF)};
46+
spi_write_blocking(spi, command_buffer, 4);
47+
SpiSetBlocking(byte, len);
48+
gpio_put(CS, 1);
49+
}
50+
51+
52+
void PSRamDisplay::read(uint32_t address, size_t len, uint8_t *data)
53+
{
54+
gpio_put(CS, 0);
55+
uint8_t command_buffer[4] = {READ, (uint8_t)((address >> 16) & 0xFF), (uint8_t)((address >> 8) & 0xFF), (uint8_t)(address & 0xFF)};
56+
spi_write_blocking(spi, command_buffer, 4);
57+
spi_read_blocking(spi, 0, data, len);
58+
gpio_put(CS, 1);
59+
}
60+
61+
void PSRamDisplay::write_pixel(const Point &p, uint8_t colour)
62+
{
63+
write(pointToAddress(p), 1, colour);
64+
}
65+
66+
void PSRamDisplay::write_pixel_span(const Point &p, uint l, uint8_t colour)
67+
{
68+
write(pointToAddress(p), l, colour);
69+
}
70+
71+
void PSRamDisplay::read_pixel_span(const Point &p, uint l, uint8_t *data)
72+
{
73+
read(pointToAddress(p), l, data);
74+
}
75+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#pragma once
2+
3+
#include <cstring>
4+
5+
#include "pico/stdlib.h"
6+
#include "hardware/spi.h"
7+
#include "hardware/gpio.h"
8+
#include "common/pimoroni_common.hpp"
9+
#include "common/pimoroni_bus.hpp"
10+
#include "libraries/pico_graphics/pico_graphics.hpp"
11+
12+
13+
// 8 MB PSRam
14+
15+
namespace pimoroni {
16+
17+
class PSRamDisplay : public IDirectDisplayDriver<uint8_t> {
18+
//--------------------------------------------------
19+
// Variables
20+
//--------------------------------------------------
21+
private:
22+
spi_inst_t *spi = PIMORONI_SPI_DEFAULT_INSTANCE;
23+
24+
// interface pins with our standard defaults where appropriate
25+
uint CS = 3;
26+
uint DC = PIN_UNUSED;
27+
uint SCK = SPI_DEFAULT_SCK;
28+
uint MOSI = SPI_DEFAULT_MOSI;
29+
uint MISO = SPI_DEFAULT_MISO;
30+
31+
uint32_t start_address = 0;
32+
uint16_t width = 0;
33+
uint16_t height = 0;
34+
35+
absolute_time_t timeout;
36+
37+
bool blocking = false;
38+
39+
public:
40+
enum colour : uint8_t {
41+
BLACK = 0,
42+
WHITE = 1,
43+
GREEN = 2,
44+
BLUE = 3,
45+
RED = 4,
46+
YELLOW = 5,
47+
ORANGE = 6,
48+
CLEAN = 7
49+
};
50+
51+
PSRamDisplay(uint16_t width, uint16_t height) : PSRamDisplay(width, height, {PIMORONI_SPI_DEFAULT_INSTANCE, 3, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, PIN_UNUSED, PIN_UNUSED}) {};
52+
53+
PSRamDisplay(uint16_t width, uint16_t height, SPIPins pins) :
54+
spi(pins.spi),
55+
CS(pins.cs), DC(pins.dc), SCK(pins.sck), MOSI(pins.mosi),
56+
width(width), height(height) {
57+
init();
58+
}
59+
60+
61+
//--------------------------------------------------
62+
// Methods
63+
//--------------------------------------------------
64+
public:
65+
void test(void){
66+
67+
char writeBuffer[1024];
68+
char readBuffer[1024];
69+
70+
uint mb = 8;
71+
72+
for(uint k = 0; k < 1024*mb; k++)
73+
{
74+
sprintf(writeBuffer, "%u", k);
75+
76+
write(k*1024, strlen(writeBuffer)+1, (uint8_t *)writeBuffer);
77+
}
78+
79+
bool bSame = true;
80+
for(uint k = 0; k < 1024*mb && bSame; k++)
81+
{
82+
sprintf(writeBuffer, "%u", k);
83+
read(k*1024, strlen(writeBuffer)+1, (uint8_t *)readBuffer);
84+
bSame = strcmp(writeBuffer, readBuffer) ==0;
85+
printf("[%u] %s == %s ? %s\n", k, writeBuffer, readBuffer, bSame ? "Success" : "Failure");
86+
}
87+
}
88+
89+
void write_pixel(const Point &p, uint8_t colour) override;
90+
void write_pixel_span(const Point &p, uint l, uint8_t colour) override;
91+
void read_pixel_span(const Point &p, uint l, uint8_t *data) override;
92+
93+
int __not_in_flash_func(SpiSetBlocking)(const uint16_t uSrc, size_t uLen)
94+
{
95+
invalid_params_if(SPI, 0 > (int)uLen);
96+
// Deliberately overflow FIFO, then clean up afterward, to minimise amount
97+
// of APB polling required per halfword
98+
for (size_t i = 0; i < uLen; ++i) {
99+
while (!spi_is_writable(spi))
100+
tight_loop_contents();
101+
spi_get_hw(spi)->dr = uSrc;
102+
}
103+
104+
while (spi_is_readable(spi))
105+
(void)spi_get_hw(spi)->dr;
106+
while (spi_get_hw(spi)->sr & SPI_SSPSR_BSY_BITS)
107+
tight_loop_contents();
108+
while (spi_is_readable(spi))
109+
(void)spi_get_hw(spi)->dr;
110+
111+
// Don't leave overrun flag set
112+
spi_get_hw(spi)->icr = SPI_SSPICR_RORIC_BITS;
113+
114+
return (int)uLen;
115+
}
116+
117+
private:
118+
void init();
119+
void write(uint32_t address, size_t len, const uint8_t *data);
120+
void write(uint32_t address, size_t len, const uint8_t byte);
121+
void read(uint32_t address, size_t len, uint8_t *data);
122+
123+
uint32_t pointToAddress(const Point &p)
124+
{
125+
return start_address + (p.y * width) + p.x;
126+
}
127+
};
128+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(uc8159_inky7.cmake)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(DRIVER_NAME uc8159_inky7)
2+
add_library(${DRIVER_NAME} INTERFACE)
3+
4+
target_sources(${DRIVER_NAME} INTERFACE
5+
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp)
6+
7+
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
8+
9+
# Pull in pico libraries that we need
10+
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_spi)

0 commit comments

Comments
 (0)