Compare commits
2 Commits
1f859949b7
...
f4a6715134
Author | SHA1 | Date |
---|---|---|
Archie Hilton | f4a6715134 | |
Archie Hilton | d5ac1b340a |
|
@ -0,0 +1 @@
|
|||
ccls: Unknown command line argument 'main.cc'. Try: 'ccls --help'
|
File diff suppressed because it is too large
Load Diff
122
src/main.cc
122
src/main.cc
|
@ -2,16 +2,49 @@
|
|||
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/i2c.h"
|
||||
#include "pico/error.h"
|
||||
#include <pico/stdlib.h>
|
||||
#include <pico/stdio.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ADDR 0x3c
|
||||
|
||||
static bool failure = false;
|
||||
|
||||
#define INVALID_CH (0xff8181ff)
|
||||
|
||||
static uint32_t charset[127] = {
|
||||
INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH,
|
||||
INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH,
|
||||
INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH,
|
||||
INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, INVALID_CH, 0x00000000, // this is space
|
||||
// !, ", #, $, %, &, ', (,
|
||||
0x00bf0000, 0x03000300, 0x5ce85ce8, 0x24ff4a24, 0xc3cc33c3, 0x4834a458, 0x00030000, 0x81423c00,
|
||||
// ), *, +, ,, -, ., /, 0
|
||||
0x3c428100, 0x09060609, 0x00083e08, 0x00408000, 0x08080808, 0x00030300, 0x030c30c0, 0x7E81817E,
|
||||
// 1, 2, 3, 4, 5, 6, 7, 8
|
||||
0x80FF8280, 0x868991E2, 0x76898162, 0xff121418, 0x7189894f, 0x7289897e, 0x0709f101, 0x76898976,
|
||||
// 9, :, ;, <, =, >, ?, @
|
||||
0x7e898946, 0x00666600, 0x00264600, 0x82442810, 0x28282828, 0x10284482, 0x0609b102, INVALID_CH,
|
||||
// A, B, C, D, E, F, G, H
|
||||
0xfe1111fe, 0x768989ff, 0x6681817e, 0x7e8181ff, 0x818989ff, 0x010909ff, 0x7691817e, 0xff0808ff,
|
||||
// I, J, K, L, M, N, O, P
|
||||
0x81ffff81, 0x01ff8141, 0xe31408ff, 0x808080ff, 0xff0606ff, 0xff0804ff, 0x7E81817E, 0x060909ff,
|
||||
// Q, R, S, T, U, V, W, X
|
||||
0xbe41413e, 0xee1111ff, 0x66918966, 0x01ff0101, 0x7f80807f, 0x1fe0e01f, 0xff6060ff, 0xe71818e7,
|
||||
// Y, Z, [, \, ], ^, _, *
|
||||
0x7f90904f, 0x878991e1, 0x818181ff, 0xc0300c03, 0xff818181, 0x0c03030c, 0x80808080, 0x00060600,
|
||||
// a, b, c, d, e, f, g, h
|
||||
0xf0a8a840, 0x609090fe, 0x50888870, 0xfe909060, 0x30a8a870, 0x000212fc, 0x60a48478, 0xe01010fe,
|
||||
// i, j, k, l, m, n, o, p
|
||||
0x00f40000, 0x00748040, 0x885020fe, 0x80807e02, 0xf03030f0, 0xe01010f8, 0x60909060, 0x182424f8,
|
||||
// q, r, s, t, u, v, w, x
|
||||
0xb0484830, 0x000808f0, 0x48a49448, 0x0080907c, 0x70808070, 0x70c0c070, 0x70e0e070, 0x90606090,
|
||||
// y, z, {, |, }, ~, DEL
|
||||
0x7c90904c, 0x90b0d090, 0x81816618, 0x00ff0000, 0x81816618, 0x10081008, INVALID_CH,
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
|
||||
|
@ -21,7 +54,7 @@ int main(void) {
|
|||
gpio_set_dir(25, GPIO_OUT);
|
||||
|
||||
|
||||
i2c_init(i2c0, 115200);
|
||||
i2c_init(i2c0, 400000);
|
||||
gpio_init(0);
|
||||
gpio_init(1);
|
||||
gpio_set_function(0, GPIO_FUNC_I2C);
|
||||
|
@ -31,6 +64,9 @@ int main(void) {
|
|||
|
||||
busy_wait_ms(100);
|
||||
|
||||
disp.fill(0);
|
||||
disp.puts(0, 0, "Hello, World!");
|
||||
disp.flush();
|
||||
while (true) {
|
||||
/*
|
||||
gpio_put(25, false);
|
||||
|
@ -38,8 +74,6 @@ int main(void) {
|
|||
gpio_put(25, true);
|
||||
busy_wait_ms(failure ? 50 : 500);
|
||||
*/
|
||||
disp.test();
|
||||
busy_wait_ms(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -47,6 +81,7 @@ int main(void) {
|
|||
|
||||
static void write_cmd(uint8_t cmd) {
|
||||
uint8_t buf[2] = {0x80, cmd};
|
||||
|
||||
if (i2c_write_timeout_us(i2c0, ADDR, buf, 2, false, 1000000) < 0) {
|
||||
failure = true;
|
||||
printf("TX fail\n");
|
||||
|
@ -55,19 +90,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() {
|
||||
write_cmd(SET_DISP | 0x00); // Off
|
||||
//
|
||||
|
||||
write_cmd(SET_MUX_RATIO); // The height
|
||||
write_cmd(63); // The height
|
||||
|
||||
|
@ -90,7 +115,7 @@ ssd1306::ssd1306() {
|
|||
write_cmd(0x80);
|
||||
|
||||
write_cmd(SET_PRECHARGE);
|
||||
write_cmd(0xF1);
|
||||
write_cmd(0x22);
|
||||
write_cmd(SET_CHARGE_PUMP);
|
||||
write_cmd(0x14);
|
||||
|
||||
|
@ -99,19 +124,64 @@ ssd1306::ssd1306() {
|
|||
|
||||
write_cmd(SET_DISP | 0x01);
|
||||
|
||||
set_coordinates(0, 127, 0, 7);
|
||||
|
||||
write_cmd(SET_MEM_ADDR);
|
||||
write_cmd(0x00); // Horizontal
|
||||
|
||||
write_cmd(SET_COL_ADDR);
|
||||
write_cmd(0);
|
||||
write_cmd(127);
|
||||
write_cmd(SET_PAGE_ADDR);
|
||||
write_cmd(0);
|
||||
write_cmd(0x63);
|
||||
for(size_t i = 0; i < (128*8); i++) {
|
||||
uint8_t test_buf[] = {0x40, 0x00};
|
||||
i2c_write_timeout_us(i2c0, ADDR, test_buf, 2, false, 10000000);
|
||||
}
|
||||
}
|
||||
|
||||
void ssd1306::test() {
|
||||
static bool flip = true;
|
||||
uint8_t buf[2] = {0x40, 0xFF};
|
||||
write_data(buf, 2);
|
||||
memcpy(m_display_buffer+1, &charset['i'-1], 4*16);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void ssd1306::put_char(uint8_t row, uint8_t col, char c) {
|
||||
if (row % 4 != 0) return;
|
||||
|
||||
memcpy(&m_display_buffer[1 + (row + (128*col))], &charset[c-1], 4);
|
||||
}
|
||||
|
||||
void ssd1306::puts(uint8_t row, uint8_t col, const char *str) {
|
||||
// Start index
|
||||
size_t buf_idx = 1+(row + (128*col));
|
||||
|
||||
while(*str != '\0') {
|
||||
memcpy(m_display_buffer+buf_idx, &charset[*str-1], 4);
|
||||
|
||||
buf_idx+=4;
|
||||
str++;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
src/main.hh
15
src/main.hh
|
@ -21,11 +21,26 @@
|
|||
#define SET_VCOM_DESEL (0xDB)
|
||||
#define SET_CHARGE_PUMP (0x8D)
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 64
|
||||
|
||||
class ssd1306 {
|
||||
private:
|
||||
uint8_t m_display_buffer[WIDTH*(HEIGHT/8)+1] = {0x40};
|
||||
public:
|
||||
ssd1306();
|
||||
|
||||
void poweron();
|
||||
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);
|
||||
|
||||
void put_char(uint8_t row, uint8_t col, char c);
|
||||
|
||||
void puts(uint8_t row, uint8_t col, const char* str);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue