Get whole thing working based on display buffer

This commit is contained in:
Archie Hilton 2024-06-29 00:10:30 +01:00
parent 1f859949b7
commit d5ac1b340a
5 changed files with 1774 additions and 25 deletions

2
.ccls Normal file
View File

@ -0,0 +1,2 @@
%compile_commands.json
--sysroot=/usr/arm-none-eabi/

1
grep Normal file
View File

@ -0,0 +1 @@
ccls: Unknown command line argument 'main.cc'. Try: 'ccls --help'

1711
profile.log Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,11 @@
#include "hardware/gpio.h" #include "hardware/gpio.h"
#include "hardware/i2c.h" #include "hardware/i2c.h"
#include "pico/error.h"
#include <pico/stdlib.h> #include <pico/stdlib.h>
#include <pico/stdio.h> #include <pico/stdio.h>
#include <cstdio> #include <stdio.h>
#include <string.h>
#define ADDR 0x3c #define ADDR 0x3c
@ -21,7 +21,7 @@ int main(void) {
gpio_set_dir(25, GPIO_OUT); gpio_set_dir(25, GPIO_OUT);
i2c_init(i2c0, 115200); i2c_init(i2c0, 400000);
gpio_init(0); gpio_init(0);
gpio_init(1); gpio_init(1);
gpio_set_function(0, GPIO_FUNC_I2C); gpio_set_function(0, GPIO_FUNC_I2C);
@ -38,8 +38,12 @@ int main(void) {
gpio_put(25, true); gpio_put(25, true);
busy_wait_ms(failure ? 50 : 500); busy_wait_ms(failure ? 50 : 500);
*/ */
disp.test(); disp.fill(0);
busy_wait_ms(10); disp.flush();
busy_wait_ms(500);
disp.fill(0xFF);
disp.flush();
busy_wait_ms(500);
} }
return 0; return 0;
@ -47,6 +51,7 @@ int main(void) {
static void write_cmd(uint8_t cmd) { static void write_cmd(uint8_t cmd) {
uint8_t buf[2] = {0x80, cmd}; uint8_t buf[2] = {0x80, cmd};
if (i2c_write_timeout_us(i2c0, ADDR, buf, 2, false, 1000000) < 0) { if (i2c_write_timeout_us(i2c0, ADDR, buf, 2, false, 1000000) < 0) {
failure = true; failure = true;
printf("TX fail\n"); printf("TX fail\n");
@ -55,19 +60,9 @@ static void write_cmd(uint8_t cmd) {
} }
} }
static void write_data(uint8_t *data, size_t len) {
if (i2c_write_timeout_us(i2c0, ADDR, data, len, false, 1000000) < 0) {
failure = true;
printf("data fail\n");
} else {
printf("data succ\n");
}
}
ssd1306::ssd1306() { ssd1306::ssd1306() {
write_cmd(SET_DISP | 0x00); // Off write_cmd(SET_DISP | 0x00); // Off
//
write_cmd(SET_MUX_RATIO); // The height write_cmd(SET_MUX_RATIO); // The height
write_cmd(63); // The height write_cmd(63); // The height
@ -90,7 +85,7 @@ ssd1306::ssd1306() {
write_cmd(0x80); write_cmd(0x80);
write_cmd(SET_PRECHARGE); write_cmd(SET_PRECHARGE);
write_cmd(0xF1); write_cmd(0x22);
write_cmd(SET_CHARGE_PUMP); write_cmd(SET_CHARGE_PUMP);
write_cmd(0x14); write_cmd(0x14);
@ -99,19 +94,48 @@ ssd1306::ssd1306() {
write_cmd(SET_DISP | 0x01); write_cmd(SET_DISP | 0x01);
set_coordinates(0, 127, 0, 7);
write_cmd(SET_MEM_ADDR); write_cmd(SET_MEM_ADDR);
write_cmd(0x00); // Horizontal write_cmd(0x00); // Horizontal
write_cmd(SET_COL_ADDR); for(size_t i = 0; i < (128*8); i++) {
write_cmd(0); uint8_t test_buf[] = {0x40, 0x00};
write_cmd(127); i2c_write_timeout_us(i2c0, ADDR, test_buf, 2, false, 10000000);
write_cmd(SET_PAGE_ADDR); }
write_cmd(0);
write_cmd(0x63);
} }
void ssd1306::test() { void ssd1306::test() {
static bool flip = true; static bool flip = true;
uint8_t buf[2] = {0x40, 0xFF}; fill(flip?0xFF:0x00);
write_data(buf, 2); flip = !flip;
flush();
}
void ssd1306::fill(uint8_t val) {
for(size_t i = 1; i < sizeof(m_display_buffer); i++) {
m_display_buffer[i] = val;
}
}
void ssd1306::set_coordinates(uint8_t start_x, uint8_t end_x, uint8_t start_y, uint8_t end_y){
write_cmd(SET_COL_ADDR);
write_cmd(start_x);
write_cmd(end_x);
write_cmd(SET_PAGE_ADDR);
write_cmd(start_y);
write_cmd(end_y);
}
void ssd1306::flush() {
set_coordinates(0, 127, 0, 7);
write_cmd(SET_MEM_ADDR);
write_cmd(0x00); // Horizontal
if (i2c_write_timeout_us(i2c0, ADDR, m_display_buffer, sizeof(m_display_buffer), false, 1000000) < 0) {
failure = true;
printf("data fail\n");
} else {
printf("data succ\n");
}
} }

View File

@ -21,11 +21,22 @@
#define SET_VCOM_DESEL (0xDB) #define SET_VCOM_DESEL (0xDB)
#define SET_CHARGE_PUMP (0x8D) #define SET_CHARGE_PUMP (0x8D)
#define WIDTH 128
#define HEIGHT 64
class ssd1306 { class ssd1306 {
private:
uint8_t m_display_buffer[WIDTH*(HEIGHT/8)+1] = {0x40};
public: public:
ssd1306(); ssd1306();
void poweron(); void poweron();
void test(); void test();
void fill(uint8_t val);
void flush();
void set_coordinates(uint8_t start_x, uint8_t end_x, uint8_t start_y, uint8_t end_y);
}; };