olikraus / u8glib

Arduino Monochrom Graphics Library for LCDs and OLEDs
https://github.com/olikraus/u8glib/wiki
Other
1.25k stars 315 forks source link

Teensy 3.0\3.1 Hardware SPI Support #255

Open olikraus opened 9 years ago

olikraus commented 9 years ago

Originally reported on Google Code with ID 256

What steps will reproduce the problem?
1. Constructor for HW SPI 
U8GLIB_SSD1306_128X64_2X display(SS, 9, 14);
vs for SW which works
U8GLIB_SSD1306_128X64_2X display(SLK, MOSI, SS, 9, 14);

What is the expected output? What do you see instead?
Blank Display, works in software mode but conflicts with SD Card on SPI bus.

What version of the product are you using? On what operating system?
Windows 7 X64 with Arduino IDE 1.0.5 with Teensy addon.

Please provide any additional information below.

Reported by blackspartan117 on 2014-04-22 02:32:03

olikraus commented 9 years ago
Not sure how to support this as it is difficult for me to test. Precondition is to use
different chip signal lines for both devices.
Is it Teensy 3.x? Currently there is no HW support for Teensy 3.x

Reported by olikraus on 2014-04-22 17:08:34

olikraus commented 9 years ago
I am using different CS pins. I understand that is it hard to test and not supported.
Maybe you can point me to the function I can try and work on to get it to work. I had
it working with the Adafruit lib modified for hardware SPI.

I am working with a PCB so currently can't make any changes to hardware till the next
hardware revision.

Thanks for anything you can help with.

Reported by blackspartan117 on 2014-04-22 17:15:29

olikraus commented 9 years ago
you need to implement your own "com" procedure. Someone else had done a nice description
on this:
http://blog.bastelhalde.de/?p=759

Reported by olikraus on 2014-04-22 17:36:33

olikraus commented 9 years ago
Awesome, I will try and get it to work then. Let you know how it goes.

Reported by blackspartan117 on 2014-04-22 19:27:01

olikraus commented 9 years ago
Does the Arduino version of the library support adding your own stub or is it only the
ARM version? Do you think the ARM version will still working with the Arduino IDE?
I am trying to keep using the Arduino IDE so the device is easily hackable by others.

Thanks.

Reported by blackspartan117 on 2014-04-23 04:39:31

olikraus commented 9 years ago
The arm version does not include the C++ interface. So it might be difficult for the
Arduino users.
On the other side, there is a generic C++ constructor, which allows you to specify
the com interface:
U8GLIB(u8g_dev_t *dev, u8g_com_fnptr com_fn)

Then, for the Arduino Users, this should be:
U8GLIB(u8g_dev_ssd1306_128x64_2x_sw_spi, my_com_fn)
where "my_com_fn" has to be supplied by you as described in the mentioned tutorial.
Another good thing by using the arduino variant is, that you do not need to provide
the delay procedures (these are already part of the arduino variant).

Reported by olikraus on 2014-04-23 04:51:47

olikraus commented 9 years ago
Okay I have this mostly setup.

How do I specify the DC and reset pins, in the com interface?

So something like this?

U8GLIB(u8g_dev_ssd1306_128x64_2x_hw_spi, u8g_com_hw_spi_fn);

or is it sw_spi even if using hardware?

Also where do you define the object name? In my case display.

Reported by blackspartan117 on 2014-04-23 05:28:03

olikraus commented 9 years ago
> How do I specify the DC and reset pins, in the com interface?
Your com procedure has to deal with these lines, so if you use fixed pins, then just
use fixed bins in your com callback procedure. No need to specify them on the constructor.

> or is it sw_spi even if using hardware?
The device type does not matter. You can use u8g_dev_ssd1306_128x64_2x_hw_spi or u8g_dev_ssd1306_128x64_2x_sw_spi.
Only your com procedure matters.

> Also where do you define the object name? In my case display.
Should be this:
U8GLIB display(u8g_dev_ssd1306_128x64_2x_hw_spi, u8g_com_hw_spi_fn);

Reported by olikraus on 2014-04-23 09:32:12

olikraus commented 9 years ago
Thanks so much!!! I got it to work!! Now I just need to clean it up and make it more
flexiable so anyone can use it. 

I will post on github once its ready.

Actually all it does is uses the Arduino SPI library which is installed by Teensy software
so the same functions work.  Might be easy to get it to work on the core library. 

This post helped as well
http://forum.pjrc.com/threads/24357-u8glib-now-has-an-ARM-variant?p=46427

And looked the Adafruit library as well.

So does your library use the Arduino SPI library or direct port\registers?

Thanks.

Reported by blackspartan117 on 2014-04-24 04:09:30

olikraus commented 9 years ago
Great.

Regarding HW SPI: I decided to to write directly to the uC registers. Now i know it
had been a wrong devision. In ucglib (another more recent lib from me) i am using SPI
fronm the IDE to be more portable.

Reported by olikraus on 2014-04-24 04:42:34

olikraus commented 9 years ago
No problem, it was a good exercise, ;). Cool, I will have to check out the ucglib library.
I have a Color LCD here. If you want I can test for you. Its a 2.2in LCD with the iL9341
driver. Right now its connected to a Arduino UNO. I haven't had a chance to really
play with it.

Reported by blackspartan117 on 2014-04-24 05:06:35

olikraus commented 9 years ago
Yes, iL9341 is supported and standard SPI.h should work. In fact i learned a lot from
U8glib and did a major cleanup of the internal interfaces for Ucglib.

Reported by olikraus on 2014-04-24 08:08:34

olikraus commented 9 years ago
Ucglib is available here for download:
http://forum.arduino.cc/index.php?topic=222327.0
Or drop me an e-mail for the latest release.

Reported by olikraus on 2014-04-24 08:11:49

olikraus commented 9 years ago
u8glib 2.x should use the Arduino SPI library instead of the AVR sub system.
will put this into "Milestone-Collect"
However i did not check if this request already exists.

Reported by olikraus on 2014-06-16 19:20:51

olikraus commented 9 years ago
Any updates on the status of hardware SPI for the Teensy 3.0/3.1?

Reported by lucas.berezy on 2014-10-03 22:15:12

olikraus commented 9 years ago
It works great with the code stub that uses the Arduino\Teensy SPI library. 

Reported by blackspartan117 on 2014-10-03 22:18:32

olikraus commented 9 years ago
Which code stub exactly, have you published any of your code to github yet (if not,
could you)?

I'm currently trying to get an eBay SSD1306 128x64 OLED working with the Teensy 3.1,
but to no avail. I've got the display working on an Uno with u8glib, so I know the
display works. Not sure if it's a voltage level thing (shouldn't be) or SPI speed thing.

Thanks

Reported by lucas.berezy on 2014-10-05 23:38:40

olikraus commented 9 years ago
I'm currently using NHD-3.12-25664UMB3 Controller: SSD1322, 256x64 pixels BLUE graphic
OLED display by New Haven with HW SPI on Teensy 3.0 in 16bit mode.
About 50 FPS ):

Thanks to Hoss from pjrc Teensy forum, he was able to adapt the Teensy 3 hardware SPI
code from Adafruit_ST7735 driver to work in U8G.

Here is the forum link:
page 3,post #52
http://forum.pjrc.com/threads/23445-Teensy-3-0-and-u8glib/page3

complete U8glib Arduino library folder containing U8G version 1.15 for Arduino/Teensy3.x
including Hoss tweaks.
link: 
http://forum.pjrc.com/attachment.php?attachmentid=2033&d=1400770307

IMPORTANT NOTE: Needed for HW Spi on teensy 3.x with Hoss U8G modify Library, in you're
code.
#include <SPI.h>

Chris O.

Reported by dieselko@netzero.net on 2014-10-06 03:52:03

olikraus commented 9 years ago
Thank you for the update.

Reported by olikraus on 2014-10-06 18:52:02

olikraus commented 9 years ago
Hi, sorry for late reply.

Here is my add-on that I use with the Teensy 3.1

https://github.com/FriedCircuits/Ug8lib_Teensy

Works well since it is using the Teensy SPI library and therefore hardware SPI. Should
work for any SPI display.

Remember most displays are 3.3v buy Teensy can handle 3.3v and is mostly 5v tolerant.

Reported by blackspartan117 on 2014-10-06 21:23:57

christophepersoz commented 8 years ago

Hello Olivier,

About your last post of this thread, I there a way to implement directly the Transactional SPI for Teensy directly inside U8Glib instead of doing it with U8Glib_Teensy ? I need to keep the U8Glib structure, because I'm trying to implement inside an another library (ArduinoMenu) the U8Glib to draw the menu on HW_SPI display, and it is running on Teensy 3.2.

Thanks for you reply. Christophe

olikraus commented 8 years ago

I rewrote u8glib and renamed everything to u8g2. This new version (so to say u8glib v2) uses SPI.h only.

Repo: https://github.com/olikraus/u8g2

U8g2 also comes with some simple menus... https://github.com/olikraus/u8g2/wiki/u8g2reference#userinterfaceinputvalue

christophepersoz commented 8 years ago

Hello Olivier,

Thanks for your quick reply, and the v2 seems to have great improvements ! Can you tell me if U8G2 run on Teensy 3.x and if you plan to include SSD1322 from NHD which is actually the one I'm using. I noticed that Chris O. made a lot of improvements in this library to transactional SPI, are they included in the new version ? At this time I'm using u8g_teensy.cpp and the prototype looks like this :

// HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11) U8GLIB _U8G(&u8g_dev_ssd1322_nhd31oled_2x_gr_hw_spi, u8g_com_hw_spi_fn);

Finally, the Menu inputs are a great idea, but is there a way to use ClickEncoder Library to use quadrature encoder instead of buttons inputs ? Any way to implements that in the begin() declaration ?

#include <ClickEncoder.h> /* Quad Encoder */ #define CK_ENC 2 // ISR capable input #define DT_ENC 7 #define SW_ENC 6 ClickEncoder Encoder(DT_ENC, CK_ENC, SW_ENC, 4, LOW);

Thanks

olikraus commented 8 years ago
  1. U8G2 and SSD1322 I do not own a SSD1322 based display at the moment. If there would be a person willing to test this, i can definitly move the related code from U8glib to U8g2 If you would like to be the test engineer for this please create an issue for the U8g2 project
  2. Encoder Input I had added the input buttons to U8g2 more as a quick and dirty hack to support Arduboy and the Adafruit Feather Wing Oled. I think it is better and more flexibly to add your own menu function and event handling on top of plain U8g2 and ignore the u8g2-internal event handling. I also do not plan to extend this at the moment. It is more something simple so that less experienced user can create interactive devices.
christophepersoz commented 8 years ago

Thanks for your answers, so I will put an issue for the SSD1322 for which I can perform tests and debugs. Understood for the menu and encoder, I will develop my own solution ;)

yoonghm commented 7 years ago

I am trying to use ucgIib with Teensy 3.6 and was able to compile by making the following changes ucg.h

//#ifdef __AVR__
  volatile uint8_t *data_port[UCG_PIN_COUNT];
  uint8_t data_mask[UCG_PIN_COUNT];
//#endif

Ucglib.h

class Ucglib4WireHWSPI : public Ucglib
{
  public:
    Ucglib4WireHWSPI(ucg_dev_fnptr dev, ucg_dev_fnptr ext, uint8_t cd, uint8_t cs = UCG_PIN_VAL_NONE, uint8_t reset = UCG_PIN_VAL_NONE)
      { init(); dev_cb = dev; ext_cb = ext;

    ucg.pin_list[UCG_PIN_RST] = reset;
    ucg.pin_list[UCG_PIN_CD] = cd;
    ucg.pin_list[UCG_PIN_CS] = cs;

// #ifdef __AVR__
      ucg.data_port[UCG_PIN_RST] =  portOutputRegister(digitalPinToPort(reset));
      ucg.data_mask[UCG_PIN_RST] =  digitalPinToBitMask(reset);
      ucg.data_port[UCG_PIN_CD] =  portOutputRegister(digitalPinToPort(cd));
      ucg.data_mask[UCG_PIN_CD] =  digitalPinToBitMask(cd);
      ucg.data_port[UCG_PIN_CS] =  portOutputRegister(digitalPinToPort(cs));
      ucg.data_mask[UCG_PIN_CS] =  digitalPinToBitMask(cs);
// #endif
    }
    void begin(uint8_t is_transparent);
};

Ucglib.cpp

#if defined(KINETISK)
static volatile uint8_t *u8g_data_port[9];
static uint8_t u8g_data_mask[9];
#elif defined(__PIC32MX) || defined(__arm__) || defined(ESP8266)
/* CHIPKIT PIC32 */
static volatile uint32_t *u8g_data_port[9];
static uint32_t u8g_data_mask[9];
#else
static volatile uint8_t *u8g_data_port[9];
static uint8_t u8g_data_mask[9];
#endif
#if defined(__arm__)
__attribute__( ( always_inline ) ) static inline void __NOP(void)
{
  __asm volatile ("nop");
}
#endif

static void ucg_com_arduino_send_8bit(ucg_t *ucg, uint8_t data)
{
  int i;
  #if defined(__arm__)
  __NOP;

I tested the library using HelloWorld.ino and make the following changes

Ucglib_SSD1351_18x128x128_HWSPI ucg(/cd=/ 15 , /cs=/ 10, /reset=/ 16);

I connected Adafruit 1.5" OLED (SSD1351):

OLED TEENSY 3.6
GND GND
Vin Vin
3Vo 3.3V
OLEDCS 10
RESET 16
DC 15
SCK 14
MOSI 11

However, the OLED screen remained blank.

olikraus commented 7 years ago

I think this is the wrong project... last comment should be a new issue in ucglib

olikraus commented 6 years ago

even I do not know what he means. mad_device_sd is part of my mk2tklib if I remember correctly. Maybe it works if you install m2tk.

snapedumbledore commented 6 years ago

I'll try it. thanks Is there are other solutions to deal with sw spi and sd except "u8g2" @olikraus

olikraus commented 6 years ago

u8g2 does not deal with sd drives.

snapedumbledore commented 6 years ago

when i use "u8g2", i can't read sd ,even initialize sd card. what should i do?

olikraus commented 6 years ago

I do not know, u8g2 is not responsible for reading from SD. I have never heard about any conflicts between u8g2 and SD libraries.

Ok, there is one point: If pins are shared, then you (usually) must use hardware SPI for u8g2 (HW SPI). For SPI the same is true as for I2C: https://github.com/olikraus/u8g2/blob/master/doc/faq.txt#L9

But even this is not u8g2 specific. It is a general topic.

snapedumbledore commented 6 years ago

it must be my mistake. Thank a lot.

snapedumbledore commented 6 years ago

@olikraus Hello, i installed "m2tklib_arduino_u8g_1.08", but i still get the error"'mas_device_sd' was not declared in this scope" then i add "#include mas.h", i get the error "no such file or directory'mas.h'", but i can find the mas.h in m2tklib/utility Any suggestion? Thanks.

olikraus commented 6 years ago

maybe you need to write #include "utility/mas.h"

snapedumbledore commented 6 years ago

You are right. Thanks a lot.