diff --git a/README.md b/README.md index fb55a684..9ffec70a 100644 --- a/README.md +++ b/README.md @@ -346,24 +346,50 @@ The integration in nodemcu is developed for SSD1306 based display attached via t U8glib v1.17 #####I2C connection -Hook up SDA and SCL to any free GPIOs. Eg. [lua_examples/graphics_test.lua](https://github.com/devsaurus/nodemcu-firmware/blob/dev/lua_examples/graphics_test.lua) expects SDA=5 (GPIO14) and SCL=6 (GPIO12). They are used to set up nodemcu's I2C driver before accessing the display: +Hook up SDA and SCL to any free GPIOs. Eg. `lua_examples/u8glib/graphics_test.lua` expects SDA=5 (GPIO14) and SCL=6 (GPIO12). They are used to set up nodemcu's I2C driver before accessing the display: ```lua sda = 5 scl = 6 i2c.setup(0, sda, scl, i2c.SLOW) ``` +#####SPI connection +The HSPI module is used, so certain pins are fixed: +* HSPI CLK = GPIO14 +* HSPI MOSI = GPIO13 +* HPSI MISO = GPIO12 (not used) + +All other pins can be assigned to any available GPIO: +* CS +* D/C +* RES (optional) + +Also refer to the initialization sequence eg in `lua_examples/u8glib/graphics_test.lua`: +```lua +spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0) +``` + + #####Library usage -The Lua bindings for this library closely follow u8glib's object oriented C++ API. Based on the u8g class, you create an object for your display type: +The Lua bindings for this library closely follow u8glib's object oriented C++ API. Based on the u8g class, you create an object for your display type. + +SSD1306 via I2C: ```lua sla = 0x3c disp = u8g.ssd1306_128x64_i2c(sla) ``` +SSD1306 via SPI: +```lua +cs = 8 -- GPIO15, pull-down 10k to GND +dc = 4 -- GPIO2 +disp = u8g.ssd1306_128x64_spi(cs, dc) +``` + This object provides all of u8glib's methods to control the display. -Again, refer to [lua_examples/graphics_test.lua](https://github.com/devsaurus/nodemcu-firmware/blob/dev/lua_examples/u8g_graphics_test.lua) to get an impression how this is achieved with Lua code. Visit the [u8glib homepage](https://code.google.com/p/u8glib/) for technical details. +Again, refer to `lua_examples/u8glib/graphics_test.lua` to get an impression how this is achieved with Lua code. Visit the [u8glib homepage](https://code.google.com/p/u8glib/) for technical details. #####Fonts -u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in [app/include/user_config.h](https://github.com/devsaurus/nodemcu-firmware/blob/dev/app/include/user_config.h) and recompile. Simply add the desired fonts to the font table: +u8glib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in `app/include/user_config.h` and recompile. Simply add the desired fonts to the font table: ```c #define U8G_FONT_TABLE \ U8G_FONT_TABLE_ENTRY(font_6x10) \ @@ -371,6 +397,9 @@ u8glib comes with a wide range of fonts for small displays. Since they need to b ``` They'll be available as `u8g.` in Lua. +#####Bitmaps +Bitmaps and XBMs are supplied as strings to `drawBitmap()` and `drawXBM()`. This off-loads all data handling from the u8g module to generic methods for binary files. See `lua_examples/u8glib/u8g_bitmaps.lua`. Binary files can be uploaded with [nodemcu-uploader.py](https://github.com/kmpm/nodemcu-uploader). + #####Unimplemented functions - [ ] Cursor handling - [ ] disableCursor() @@ -379,12 +408,7 @@ They'll be available as `u8g.` in Lua. - [ ] setCursorFont() - [ ] setCursorPos() - [ ] setCursorStyle() -- [x] Bitmaps - - [x] drawBitmap() - - [x] drawXBM() - [ ] General functions - - [x] begin() - - [ ] print() - [ ] setContrast() - [ ] setPrintPos() - [ ] setHardwareBackup()