-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed_driver.c
134 lines (107 loc) · 3.91 KB
/
oled_driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* oled_driver.c
*
* Created: 29.09.2021 16:46:43
* Author: idamand
*/
#include <avr/pgmspace.h>
//#include "fonts.h"
//we have the fonts in fonts.h
volatile char *ext_ram_oled = (char *)0x1000; // Start address for the OLED
//1200 - 10 bit
//write command to oled
void write_c(uint8_t command){
ext_ram_oled[0] = command; //zero because we use address as control
//printf("command to oled: %4d\r\n", command );
}
//write data to oled
void write_d(uint8_t data_to_write){
volatile char *ext_ram_dummy = (char *)0x1200; // Start address for the OLED
ext_ram_dummy[0] = data_to_write; //one because we use address as control
}
//suggested in p.15 of oled-ly-190
void oled_init() {
printf("initializing data");
// while(1){
write_c(0xae); // display off
// }
write_c(0xa1); //segment remap
write_c(0xda); //common pads hardware: alternative
write_c(0x12);
write_c(0xc8); //common output scan direction:com63~com0
write_c(0xa8); //multiplex ration mode:63
write_c(0x3f);
write_c(0xd5); //display divide ratio/osc. freq. mode
write_c(0x80);
write_c(0x81); //contrast control
write_c(0x50);
write_c(0xd9); //set pre-charge period
write_c(0x21);
write_c(0x20); //Set Memory Addressing Mode
write_c(0x02);
write_c(0xdb); //VCOM deselect level mode
write_c(0x30);
write_c(0xad); //master configuration
write_c(0x00);
write_c(0xa4); //out follows RAM content
write_c(0xa6); //set normal display
write_c(0xaf); // display on
write_c(0xa5); // will light up the screen
}
/*
void test_char_printing(char* in_char){
printf("char selection test running");
printf("in_char: %4d\r\n", in_char );
printf("using font8");
for (int i = 0; i < 8; ++i)
{
printf("byte %4d is: %4d \r\n", i, pgm_read_byte(&(font8[font_index][i])))
}
//print the entire font to test progmem
//but what makes it difficult is that theree exist several possible representation of the numbers in binary
for (int i = 0; i < 8; ++i) //loop all chars
{
for (int i = 0; i < 8; ++i) //columns
{
printf( "%4d", pgm_read_byte(&(font8[font_index][i])) )
}
}
}
void oled_print_char(char* in_char){
uint_16_t ext_ram_size = 0x400;
volatile char *ext_ram = (char *)0x0000 //start adress for the adc
//the char corresponds to the index in the fonts
font_index = in_char; //might be wrong so I move it to new var for easier editing
//loop through second dimension of indexes to write the char
//to begin with we just use font8 (todo: later add functionality for other fonts)
for (int i = 0; i < sizeof(font8[font_index])/sizeof(font8[font_index][0]); ++i) // aka i<8
{
//write the current column of the content to the place the column pointer is
DATA_SELECT_PIN=1; //force the pin connected to D/C# high, so that we atate that what is sent is data.
// if the fonts were sotored in program memory it would be something like:
// row_content_oled = font8[font_index][i];
// but we are using progmem, so it looks like
ext_ram[0] = pgm_read_byte(&(font8[font_index][i])); //should index be zero?
//when writing we should make sure that the data bus is in data mode and not command mode.
//where ext_ram[0] is row_content_oled (uncertain about this one).
//the column pointer is automatically increemented when it is written to
//so we can just jump to the top of the for loop again without that being a problem
}
}
void oled_goto_line(line){
//change the line pointed to
//this is well explained in the instruction set
//command 21h
// or d3h
}
void oled_goto_column(column){
//change the line pointed to
//this is well explained in the instruction set
}
//uncertain what this should do
void oled_reset(){
}
//uncertain what this should do
void oled_home(){
}
*/