Skip to content

Commit 52f444d

Browse files
committed
Add OLED library - update tiny wire libraries - add support for all PWM channels and PWM on pin 8
1 parent fb93846 commit 52f444d

File tree

60 files changed

+3286
-711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3286
-711
lines changed

hardware/digistump/avr/cores/pro/Arduino.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ int digitalRead(uint8_t);
103103
int analogRead(uint8_t);
104104
void analogReference(uint8_t mode);
105105
void analogWrite(uint8_t, int);
106+
void pwmWrite(uint8_t, int);
107+
void pwmConnect(uint8_t);
108+
void pwmDisconnect(uint8_t);
109+
void pwmReset(void);
110+
106111

107112
unsigned long millis(void);
108113
unsigned long micros(void);
@@ -160,8 +165,8 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
160165
#define TIMER1B 4
161166
#define TIMER1D 5
162167

163-
#define CHANNELA 3; //TIMER1A
164-
#define CHANNELB 4; //TIMER1B
168+
#define CHANNELA 3 //TIMER1A
169+
#define CHANNELB 4 //TIMER1B
165170

166171
#include "pins_arduino.h"
167172

hardware/digistump/avr/cores/pro/Stream_old.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

hardware/digistump/avr/cores/pro/wiring_analog.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ void analogWrite(uint8_t pin, int val)
185185
uint8_t timer = digitalPinToTimer(pin);
186186

187187

188-
/*
189-
if( timer == TIMER0B){
190-
// connect pwm to pin on timer 0, channel B
191-
sbi(TCCR0A, COM0B1);
192-
cbi(TCCR0A, COM0B0);
193-
OCR0B = val; // set pwm duty
194-
} else
195-
*/
196188

189+
if( timer == TIMER0A){
190+
// connect pwm to pin 8 on timer 0, channel A
191+
sbi(TCCR0A, COM0A1);
192+
cbi(TCCR0A, COM0A0);
193+
sbi(TCCR0A, WGM01);
194+
sbi(TCCR0A, WGM00);
195+
OCR0A = val; // set pwm duty
196+
} else
197197

198198
if( timer == TIMER1A){
199199
// connect pwm to pin on timer 1, channel A
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CHANGES
2+
3+
4+
2015-01-10 (nb)
5+
6+
Fixed and improved initialization. New and improved printing of text. Updated texts.
7+
8+
- Fixed initialization commands.
9+
- Implemented ssd1306_init more efficiently.
10+
- New functions ssd1306_send_command_start, ssd1306_send_command_stop.
11+
- Improved ssd1306_setpos, more efficient.
12+
- Reimplemented function ssd1306_char_f6x8 as improved ssd1306_char_font6x8 printing single characters only, added new ssd1306_string_font6x8 for printing strings.
13+
- The font8x16 functions and data moved to another file until properly implemented.
14+
- Added to the Make file ssd1306xled8x16 file.
15+
- Updated testing text displayed on the screen.
16+
17+
18+
2015-01-10 (nb)
19+
20+
Changed default pins for display, now PB0=SCL and PB1=SDA. Source code reformatting, improvements, edited comments.
21+
22+
- Changed default pins for connecting to the display for consistency with the built-in TWI interface, they are now PB0=SCL and PB1=SDA.
23+
- Source code, removed redundant initializations of variables.
24+
- Source code reformatting, edited comments.
25+
26+
27+
2015-01-10 (nb)
28+
29+
Fixed some warnings, variables renamed. The font16x16/Chinese stuff moved to other folders.
30+
31+
- Font variable ssd1306xled_font8X16 renamed to ssd1306xled_font8x16 for consistency. TODO: rename "ssd1306xled_font8x16" file as well.
32+
- Fixed ssd1306_draw_bmp prototype: added "const" to bitmap so it wont't generate warning.
33+
- Files related to font 16x16 (Chinese) moved to different folders: font16x16cn.h.
34+
- Functions and other code related to font 16x16 (Chinese) moved to different folders.
35+
- Source code reformatting, edited comments.
36+
37+
38+
2014-10-26 (gs)
39+
40+
Make project compile on gcc-avr - turn static images to consts, and rename include of font16x16cn.h
41+
42+
43+
2014-08-13 (nb)
44+
45+
More files added to the repository.
46+
47+
48+
2014-08-11 (nb)
49+
50+
Files added to the repository.
51+
52+
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/*
2+
* SSD1306xLED - Drivers for SSD1306 controlled dot matrix OLED/PLED 128x64 displays
3+
*
4+
* @created: 2014-08-12
5+
* @author: Neven Boyanov
6+
*
7+
* Source code available at: https://bitbucket.org/tinusaur/ssd1306xled
8+
*
9+
*/
10+
11+
// ----------------------------------------------------------------------------
12+
13+
#include <stdlib.h>
14+
#include <avr/io.h>
15+
16+
#include <avr/pgmspace.h>
17+
18+
#include "DigisparkOLED.h"
19+
#include "font6x8.h"
20+
#include "font8x16.h"
21+
22+
23+
24+
// ----------------------------------------------------------------------------
25+
26+
// Some code based on "IIC_wtihout_ACK" by http://www.14blog.com/archives/1358
27+
28+
const uint8_t ssd1306_init_sequence [] PROGMEM = { // Initialization Sequence
29+
0xAE, // Display OFF (sleep mode)
30+
0x20, 0b00, // Set Memory Addressing Mode
31+
// 00=Horizontal Addressing Mode; 01=Vertical Addressing Mode;
32+
// 10=Page Addressing Mode (RESET); 11=Invalid
33+
0xB0, // Set Page Start Address for Page Addressing Mode, 0-7
34+
0xC8, // Set COM Output Scan Direction
35+
0x00, // ---set low column address
36+
0x10, // ---set high column address
37+
0x40, // --set start line address
38+
0x81, 0x3F, // Set contrast control register
39+
0xA1, // Set Segment Re-map. A0=address mapped; A1=address 127 mapped.
40+
0xA6, // Set display mode. A6=Normal; A7=Inverse
41+
0xA8, 0x3F, // Set multiplex ratio(1 to 64)
42+
0xA4, // Output RAM to Display
43+
// 0xA4=Output follows RAM content; 0xA5,Output ignores RAM content
44+
0xD3, 0x00, // Set display offset. 00 = no offset
45+
0xD5, // --set display clock divide ratio/oscillator frequency
46+
0xF0, // --set divide ratio
47+
0xD9, 0x22, // Set pre-charge period
48+
0xDA, 0x12, // Set com pins hardware configuration
49+
0xDB, // --set vcomh
50+
0x20, // 0x20,0.77xVcc
51+
0x8D, 0x14, // Set DC-DC enable
52+
0xAF // Display ON in normal mode
53+
54+
};
55+
56+
uint8_t oledFont, oledX, oledY = 0;
57+
58+
// Program: 5248 bytes
59+
60+
SSD1306Device::SSD1306Device(void){}
61+
62+
63+
void SSD1306Device::begin(void)
64+
{
65+
Wire.begin();
66+
67+
for (uint8_t i = 0; i < sizeof (ssd1306_init_sequence); i++) {
68+
ssd1306_send_command(pgm_read_byte(&ssd1306_init_sequence[i]));
69+
}
70+
clear();
71+
}
72+
73+
74+
void SSD1306Device::setFont(uint8_t font)
75+
{
76+
oledFont = font;
77+
}
78+
79+
void SSD1306Device::ssd1306_send_command_start(void) {
80+
Wire.beginTransmission(SSD1306);
81+
Wire.write(0x00); // write command
82+
}
83+
84+
void SSD1306Device::ssd1306_send_command_stop(void) {
85+
Wire.endTransmission();
86+
}
87+
88+
void SSD1306Device::ssd1306_send_data_byte(uint8_t byte)
89+
{
90+
if(Wire.writeAvailable()){
91+
ssd1306_send_data_stop();
92+
ssd1306_send_data_start();
93+
}
94+
Wire.write(byte);
95+
96+
}
97+
98+
void SSD1306Device::ssd1306_send_command(uint8_t command)
99+
{
100+
ssd1306_send_command_start();
101+
Wire.write(command);
102+
ssd1306_send_command_stop();
103+
}
104+
105+
void SSD1306Device::ssd1306_send_data_start(void)
106+
{
107+
Wire.beginTransmission(SSD1306);
108+
Wire.write(0x40); //write data
109+
}
110+
111+
void SSD1306Device::ssd1306_send_data_stop(void)
112+
{
113+
Wire.endTransmission();
114+
}
115+
116+
void SSD1306Device::setCursor(uint8_t x, uint8_t y)
117+
{
118+
ssd1306_send_command_start();
119+
Wire.write(0xb0 + y);
120+
Wire.write(((x & 0xf0) >> 4) | 0x10); // | 0x10
121+
Wire.write((x & 0x0f) | 0x01); // | 0x01
122+
ssd1306_send_command_stop();
123+
oledX = x;
124+
oledY = y;
125+
}
126+
127+
void SSD1306Device::clear(void)
128+
{
129+
fill(0x00);
130+
}
131+
132+
void SSD1306Device::fill(uint8_t fill)
133+
{
134+
uint8_t m,n;
135+
for (m = 0; m < 8; m++)
136+
{
137+
ssd1306_send_command(0xb0 + m); // page0 - page1
138+
ssd1306_send_command(0x00); // low column start address
139+
ssd1306_send_command(0x10); // high column start address
140+
ssd1306_send_data_start();
141+
for (n = 0; n < 128; n++)
142+
{
143+
ssd1306_send_data_byte(fill);
144+
}
145+
ssd1306_send_data_stop();
146+
}
147+
setCursor(0, 0);
148+
}
149+
150+
size_t SSD1306Device::write(byte c) {
151+
uint8_t i = 0;
152+
uint8_t ci = c - 32;
153+
if(c == '\r')
154+
return 1;
155+
if(c == '\n'){
156+
if(oledFont == 0)
157+
setCursor(0, oledY+1);
158+
else
159+
setCursor(0, oledY+2);
160+
return 1;
161+
}
162+
163+
if(oledFont == 0){
164+
if (oledX > 122)
165+
{
166+
oledX = 0;
167+
oledY++;
168+
setCursor(oledX, oledY);
169+
}
170+
171+
ssd1306_send_data_start();
172+
for (i= 0; i < 6; i++)
173+
{
174+
ssd1306_send_data_byte(pgm_read_byte(&ssd1306xled_font6x8[ci * 6 + i]));
175+
}
176+
ssd1306_send_data_stop();
177+
setCursor(oledX+6, oledY);
178+
}
179+
else{
180+
if (oledX > 120)
181+
{
182+
oledX = 0;
183+
oledY++;
184+
setCursor(oledX, oledY);
185+
}
186+
187+
ssd1306_send_data_start();
188+
for (i = 0; i < 8; i++)
189+
{
190+
Wire.write(pgm_read_byte(&ssd1306xled_font8x16[ci * 16 + i]));
191+
}
192+
ssd1306_send_data_stop();
193+
setCursor(oledX, oledY + 1);
194+
ssd1306_send_data_start();
195+
for (i = 0; i < 8; i++)
196+
{
197+
Wire.write(pgm_read_byte(&ssd1306xled_font8x16[ci * 16 + i + 8]));
198+
}
199+
ssd1306_send_data_stop();
200+
setCursor(oledX + 8, oledY - 1);
201+
202+
}
203+
return 1;
204+
}
205+
206+
207+
208+
209+
void SSD1306Device::bitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, const uint8_t bitmap[])
210+
{
211+
uint16_t j = 0;
212+
uint8_t y, x;
213+
if (y1 % 8 == 0) y = y1 / 8;
214+
else y = y1 / 8 + 1;
215+
for (y = y0; y < y1; y++)
216+
{
217+
setCursor(x0,y);
218+
ssd1306_send_data_start();
219+
for (x = x0; x < x1; x++)
220+
{
221+
ssd1306_send_data_byte(pgm_read_byte(&bitmap[j++]));
222+
}
223+
ssd1306_send_data_stop();
224+
}
225+
setCursor(0, 0);
226+
}
227+
228+
229+
SSD1306Device oled;
230+
231+
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)