Skip to content

Commit

Permalink
Added support for Digispark PRO
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Dec 3, 2017
1 parent ddf8ede commit 6b035c8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 42 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ configurable through API.
* Attiny85, Attiny45 (Refer to [Damellis attiny package](https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json))
* Atmega328p, Atmega168
* Atmega2560
* Digispark (check [examples compatibility list](examples/Digispark_compatibility.txt))
* Digispark, including PRO version (check [examples compatibility list](examples/Digispark_compatibility.txt))
* ESP8266 (check [examples compatibility list](examples/ESP8266_compatibility.txt))
* ESP32 (unofficial, only compilation checked)

Expand All @@ -72,7 +72,7 @@ Ssd1306 library requires at least c++11 and c99 (by default Digispark package mi

## Adding new interface

If you need to add new not supported interface for the library, just implement
If you need to add support for new interface to the library, just implement
interface specific functions and assign them to function pointers:

```cpp
Expand Down Expand Up @@ -106,6 +106,7 @@ initialization function for you LCD:

```cpp
#include "lcd/lcd_common.h"
#include "intf/ssd1306_interface.h"

void myDisplayInit()
{
Expand Down Expand Up @@ -139,6 +140,10 @@ If you found any problem or have any idea, please, report to Issues section.

## License

The library is free. If this project helps you, you can give me a cup of coffee.
[![Donate via Paypal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/lexus2k)


Copyright (C) 2016-2017 Alexey Dynda

This file is part of SSD1306 Library.
Expand Down
4 changes: 2 additions & 2 deletions examples/Digispark_compatibility.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== Digispark compatibility list ===

arkanoid [ - ] Not compatible (compile using Damellis attiny package instead of Digispark: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json)
arkanoid [ * ] Compatible only with Digispark PRO. For Digispark based on Attiny compile using Damellis attiny package instead of Digispark: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
buffers_demo [ OK ]
draw_bitmap [ OK ]
draw_text [ OK ]
Expand All @@ -9,5 +9,5 @@ menu_demo [ OK ]
move_sprite [ OK ]
pcd8544_spi [ OK ]
sprite_pool [ OK ]
ssd1306_demo [ - ] Too big for Digispark Attiny version. Can be compiled, but doesn't fit.
ssd1306_demo [ * ] Too big for Digispark Attiny85 version (6KiB is not enough). Digispark PRO is OK.

12 changes: 6 additions & 6 deletions examples/arkanoid/arkanoid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const uint8_t SPEED_SHIFT = 2;

uint8_t platformPos; // platform position
bool updateStatusPanel; // Set to true if status panel update is required
int platformWidth;
const int platformWidth = INITIAL_PLATFORM_WIDTH;
int ballx;
int bally;
int8_t vSpeed;
Expand Down Expand Up @@ -258,8 +258,8 @@ void startLevel()
hSpeed = INITIAL_H_SPEED;
vSpeed = INITIAL_V_SPEED;
platformPos = random(0, (RIGHT_EDGE - LEFT_EDGE - 1 - platformWidth));
ballx = (platformPos+(platformWidth>>1)) << SPEED_SHIFT;
bally = (SCREEN_HEIGHT - PLATFORM_HEIGHT) << SPEED_SHIFT;
ballx = ( platformPos + ( platformWidth >> 1 ) ) << SPEED_SHIFT;
bally = ( SCREEN_HEIGHT - PLATFORM_HEIGHT ) << SPEED_SHIFT;
for(uint8_t i=0; i<MAX_GAME_OBJECTS; i++)
{
objects[i].type = 0;
Expand All @@ -271,10 +271,9 @@ void startLevel()
void resetGame()
{
score = 0;
platformWidth = INITIAL_PLATFORM_WIDTH;
// platformWidth = INITIAL_PLATFORM_WIDTH;
platformPower = 0;
hearts = 2;
delay(40);
drawIntro();
delay(3000);
startLevel();
Expand Down Expand Up @@ -545,7 +544,8 @@ bool moveObjects()
void movePlatform()
{
#ifdef USE_Z_KEYPAD
uint8_t buttonCode = getPressedButton(A0);
// Use A0 ADC input (channel 0)
uint8_t buttonCode = getPressedButton(0);
if (buttonCode == BUTTON_RIGHT)
#else
if (digitalRead(RIGHT_BTN) != LOW)
Expand Down
8 changes: 6 additions & 2 deletions src/i2c/ssd1306_i2c_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ extern "C" {
/** The macro is defined when i2c Wire library is available */
#define SSD1306_WIRE_SUPPORTED
/** The macro is defined when Wire library speed can be configured */
#define SSD1306_WIRE_CLOCK_CONFIGURABLE
#if defined(ESP8266) || defined(ESP32) || defined(ESP31B)
#if defined(ARDUINO_AVR_DIGISPARKPRO)
/* Wire.setClock() is not supported by Digispark PRO */
#else
#define SSD1306_WIRE_CLOCK_CONFIGURABLE
#endif
#if defined(ESP8266) || defined(ESP32) || defined(ESP31B) || defined(ARDUINO_AVR_DIGISPARKPRO)
/* SW implementation of i2c isn't supported on ESP platforms */
#else
/** The macro is defined when software i2c implementation is available */
Expand Down
44 changes: 21 additions & 23 deletions src/i2c/ssd1306_i2c_embedded.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,29 @@ void ssd1306_i2cStop_Embedded(void)
*/
void ssd1306_i2cSendByte_Embedded(uint8_t data)
{
uint8_t i;
for(i=8; i>0; i--)
// for(i=0; i<8; i++)
uint8_t i;
for(i=8; i>0; i--)
{
if(data & 0x80)
// if((data << i) & 0x80)
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_sda)
else
DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_sda);
data<<=1;
ssd1306_delay(I2C_RISE_TIME); // Fall time is the same as rise time

DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);

DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
if(data & 0x80)
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_sda)
else
DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_sda);
data<<=1;
ssd1306_delay(I2C_RISE_TIME); // Fall time is the same as rise time

DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);

DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
}
// generating confirmation impulse
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_sda);
ssd1306_delay(I2C_RISE_TIME); // Fall time is the same as rise time
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
// generating confirmation impulse
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_sda);
ssd1306_delay(I2C_RISE_TIME); // Fall time is the same as rise time
DIGITAL_WRITE_HIGH(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
DIGITAL_WRITE_LOW(DDR_REG, PORT_REG, s_scl);
ssd1306_delay(I2C_HALF_CLOCK);
}

void ssd1306_i2cInit_Embedded(int8_t scl, int8_t sda, uint8_t sa)
Expand Down
2 changes: 1 addition & 1 deletion src/lcd/ssd1306_128x32.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void ssd1306_setBlock(uint8_t x, uint8_t y, uint8_t w)
ssd1306_sendByte(x + w - 1);
ssd1306_sendByte(SSD1306_PAGEADDR);
ssd1306_sendByte(y);
ssd1306_sendByte((ssd1306_displayHeight() >> 3) - 1);
ssd1306_sendByte((s_displayHeight >> 3) - 1);
ssd1306_endTransmission();
}

Expand Down
2 changes: 1 addition & 1 deletion src/lcd/ssd1306_128x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void ssd1306_setBlock(uint8_t x, uint8_t y, uint8_t w)
ssd1306_sendByte(w ? (x + w - 1) : (s_displayWidth - 1));
ssd1306_sendByte(SSD1306_PAGEADDR);
ssd1306_sendByte(y);
ssd1306_sendByte((ssd1306_displayHeight() >> 3) - 1);
ssd1306_sendByte((s_displayHeight >> 3) - 1);
ssd1306_endTransmission();
}

Expand Down
9 changes: 4 additions & 5 deletions src/ssd1306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,20 @@ void ssd1306_drawSpriteEx(uint8_t x, uint8_t y, uint8_t w, const uint8_t *sprite

void ssd1306_drawSprite(SPRITE *sprite)
{
uint8_t posy = sprite->y >> 3;
uint8_t offsety = sprite->y & 0x7;
if (posy < (s_displayHeight >> 3))
if (sprite->y < s_displayHeight)
{
ssd1306_setRamBlock(sprite->x, posy, sprite->w);
ssd1306_setRamBlock(sprite->x, sprite->y >> 3, sprite->w);
ssd1306_dataStart();
for (uint8_t i=0; i < sprite->w; i++)
{
ssd1306_sendByte( s_invertByte^(pgm_read_byte( &sprite->data[i] ) << offsety) );
}
ssd1306_endTransmission();
}
if (offsety && (posy + 1 < (s_displayHeight >> 3)))
if (offsety && (sprite->y + 8 < s_displayHeight))
{
ssd1306_setRamBlock(sprite->x, posy + 1, sprite->w);
ssd1306_setRamBlock(sprite->x, (sprite->y >> 3) + 1, sprite->w);
ssd1306_dataStart();
for (uint8_t i=0; i < sprite->w; i++)
{
Expand Down
2 changes: 2 additions & 0 deletions tools/avrparse.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-nm.exe" --size-sort -C -r %1 >elfdump.txt
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-objdump.exe" -C -d %1 >elfdisasm.txt

0 comments on commit 6b035c8

Please sign in to comment.