Skip to content

Commit

Permalink
Base ESP8266 Support
Browse files Browse the repository at this point in the history
Started over with a fresh fork of the DMD2 library, since I'd borked
things up so badly with the old one, developing in my own branch.
  • Loading branch information
h4rm0n1c committed Jul 16, 2015
1 parent d152e16 commit e5af70e
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 5 deletions.
14 changes: 14 additions & 0 deletions DMD2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
typedef intptr_t port_reg_t;

SPIDMD::SPIDMD(byte panelsWide, byte panelsHigh)
#ifdef ESP8266
: BaseDMD(panelsWide, panelsHigh, 0, 16, 12, 15)
#else
: BaseDMD(panelsWide, panelsHigh, 9, 6, 7, 8)
#endif
{
}

Expand All @@ -41,6 +45,8 @@ void SPIDMD::beginNoTimer()
SPI.setDataMode(SPI_MODE0); // CPOL=0, CPHA=0
#ifdef __AVR__
SPI.setClockDivider(SPI_CLOCK_DIV4); // 4MHz clock. 8MHz (DIV2 not DIV4) is possible if you have short cables. Longer cables may need DIV8/DIV16.
#elif defined(ESP8266)
SPI.setFrequency(4000000); // ESP can run at 80mhz or 160mhz, setting frequency directly is easier, set to 4MHz.
#else
SPI.setClockDivider(20); // 4.2MHz on Due. Same comment as above applies (lower numbers = less divider = faster speeds.)
#endif
Expand Down Expand Up @@ -96,6 +102,9 @@ void BaseDMD::scanDisplay()
analogWrite(pin_noe, brightness);
}

#ifdef ESP8266
// No SoftDMD for ESP8266 for now
#else
SoftDMD::SoftDMD(byte panelsWide, byte panelsHigh)
: BaseDMD(panelsWide, panelsHigh, 9, 6, 7, 8),
pin_clk(13),
Expand Down Expand Up @@ -152,6 +161,7 @@ void SoftDMD::writeSPIData(volatile uint8_t *rows[4], const int rowsize)
softSPITransfer(*(rows[0]++), port_r_data, mask_r_data, port_clk, mask_clk);
}
}
#endif

BaseDMD::BaseDMD(byte panelsWide, byte panelsHigh, byte pin_noe, byte pin_a, byte pin_b, byte pin_sck)
:
Expand All @@ -161,7 +171,11 @@ BaseDMD::BaseDMD(byte panelsWide, byte panelsHigh, byte pin_noe, byte pin_a, byt
pin_a(pin_a),
pin_b(pin_b),
pin_sck(pin_sck),
#ifdef ESP8266
default_pins(pin_noe == 0 && pin_a == 16 && pin_b == 12 && pin_sck == 15),
#else
default_pins(pin_noe == 9 && pin_a == 6 && pin_b == 7 && pin_sck == 8),
#endif
pin_other_cs(-1),
brightness(255)
{
Expand Down
8 changes: 6 additions & 2 deletions DMD2.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class DMDFrame

void drawString(int x, int y, const char *bChars, DMDGraphicsMode mode=GRAPHICS_ON, const uint8_t *font = NULL);
void drawString(int x, int y, const String &str, DMDGraphicsMode mode=GRAPHICS_ON, const uint8_t *font = NULL);
#ifdef __AVR__
#if defined(__AVR__) || defined(ESP8266)
void drawString_P(int x, int y, const char *flashStr, DMDGraphicsMode mode=GRAPHICS_ON, const uint8_t *font = NULL);
inline void drawString(int x, int y, const __FlashStringHelper *flashStr, DMDGraphicsMode mode=GRAPHICS_ON, const uint8_t *font = NULL) {
return drawString_P(x,y,(const char*)flashStr, mode, font);
Expand All @@ -152,7 +152,7 @@ class DMDFrame
int charWidth(const char letter, const uint8_t *font = NULL);

//Find the width of a string (width of all characters plus 1 pixel "kerning" between each character)
#ifdef __AVR__
#if defined(__AVR__) || defined(ESP8266)
unsigned int stringWidth_P(const char *flashStr, const uint8_t *font = NULL);
inline unsigned int stringWidth(const __FlashStringHelper *flashStr, const uint8_t *font = NULL) {
return stringWidth_P((const char*)flashStr, font);
Expand Down Expand Up @@ -262,6 +262,9 @@ class SPIDMD : public BaseDMD
void writeSPIData(volatile uint8_t *rows[4], const int rowsize);
};

#ifdef ESP8266
// No SoftDMD for ESP8266 for now
#else
class SoftDMD : public BaseDMD
{
public:
Expand Down Expand Up @@ -299,6 +302,7 @@ class DMD_TextBox : public Print {
int16_t cur_y;
bool pending_newline;
};
#endif

// Six byte header at beginning of FontCreator font structure, stored in PROGMEM
struct FontHeader {
Expand Down
2 changes: 1 addition & 1 deletion DMD2_Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ template <class StrType> __attribute__((always_inline)) inline unsigned int _str
}


#ifdef __AVR__
#if defined(__AVR__) || defined (ESP8266)
// Small wrapper class to allow indexing of progmem strings via [] (should be inlined out of the actual implementation)
class _FlashStringWrapper {
const char *str;
Expand Down
33 changes: 32 additions & 1 deletion DMD2_Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void BaseDMD::end()
scanDisplay();
}

#else // __ARM__, Due assumed for now
#elif defined (__arm__) // __ARM__, Due assumed for now

/* ARM timer callback (ISR context), checks timer status then scans all running DMDs */
void TC7_Handler(){
Expand Down Expand Up @@ -128,6 +128,37 @@ void BaseDMD::end()
scanDisplay();
}

#elif defined (ESP8266)

void BaseDMD::begin()
{
beginNoTimer();
timer1_disable();

register_running_dmd(this);

timer1_isr_init();
timer1_attachInterrupt(scan_running_dmds);
timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP);
#if defined(F_CPU) && (F_CPU == 160000000L)
timer1_write(50000); // 50000 ticks = ~5ms with /16 divider at 160MHz
#else
timer1_write(25000); // 25000 ticks = ~5ms with /16 divider at 80MHz
#endif
}

void BaseDMD::end()
{
bool still_running = unregister_running_dmd(this);
if(!still_running)
{
timer1_detachInterrupt();
timer1_disable();
}
clearScreen();
scanDisplay();
}

#endif // ifdef __AVR__

/* Following functions are static non-architecture-specific functions
Expand Down
2 changes: 2 additions & 0 deletions fonts/Arial14.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 2 additions & 0 deletions fonts/Arial_Black_16.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 2 additions & 0 deletions fonts/Droid_Sans_12.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 2 additions & 0 deletions fonts/Droid_Sans_16.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 2 additions & 0 deletions fonts/Droid_Sans_24.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 2 additions & 0 deletions fonts/SystemFont5x7.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <inttypes.h>
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined (ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sentence=Updated (beta) library for Freetronics DMD dot matrix displays.
paragraph=Supports graphics operations (test, images, etc.) Still experimental, the stable library is called called "DMD"
category=Display
url=https://github.com/freetronics/DMD2/
architectures=avr,sam
architectures=avr,sam,esp8266

2 comments on commit e5af70e

@mariogren
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi
With, arduino mega, how many modules can I control, my project is 25 modules.

@mariogren
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi , With, arduino mega, how many modules can I control, my project is 25 modules.

Please sign in to comment.