aboutsummaryrefslogtreecommitdiffstats
path: root/boards
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2015-11-21 19:28:12 +1000
committerinmarket <andrewh@inmarket.com.au>2015-11-21 19:28:12 +1000
commit3ae120406e1244d728276b2bcc74d03d1ccb230d (patch)
treef429f479c6e146e1c3cdfc986689ca6750b1c4c2 /boards
parentc5a86757bd8309027d50f82d8947250c8e1197e6 (diff)
downloaduGFX-3ae120406e1244d728276b2bcc74d03d1ccb230d.tar.gz
uGFX-3ae120406e1244d728276b2bcc74d03d1ccb230d.tar.bz2
uGFX-3ae120406e1244d728276b2bcc74d03d1ccb230d.zip
Add an Arduino Sketch project.
It shows how to add ugfx as a sketch library.
Diffstat (limited to 'boards')
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/board_SSD1331.cpp88
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/board_SSD1331.h34
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/driver_SSD1331.c1
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/gdisp_lld_config.h1
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/gfx.c1
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/gfx.h1
-rw-r--r--boards/base/ArduinoTinyScreen/gfx/gfxconf.h48
-rw-r--r--boards/base/ArduinoTinyScreen/readme.txt17
-rw-r--r--boards/base/ArduinoTinyScreen/ugfx_test.ino38
9 files changed, 229 insertions, 0 deletions
diff --git a/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.cpp b/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.cpp
new file mode 100644
index 00000000..5065c34d
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.cpp
@@ -0,0 +1,88 @@
+#include <Arduino.h>
+#include <SPI.h>
+#include <Wire.h>
+
+#include "board_SSD1331.h"
+
+#define LCD_BOARD_ID 0 // 0 or 1 - set by the position of a resistor near SX1505 (see schematic and board design)
+
+// GPIO Pins
+#define GPIO_DC 0x01
+#define GPIO_CS 0x02
+#define GPIO_RES 0x08
+#define GPIO_BTN1 0x10
+#define GPIO_BTN2 0x20
+#define GPIO_BTN3 0x40
+#define GPIO_BTN4 0x80
+#define GPIO_CMD_START ~(GPIO_CS|GPIO_DC)
+#define GPIO_DATA_START ~GPIO_CS
+#define GPIO_TRANSFER_END GPIO_CS
+
+//GPIO Registers
+#define GPIO_RegData 0x00
+#define GPIO_RegDir 0x01
+#define GPIO_RegPullUp 0x02
+
+// Wire address of the SX1505 chip
+#define GPIO_ADDR 0x20
+
+static void writeGPIO(uint8_t regAddr, uint8_t regData)
+{
+ uint8_t oldTWBR=TWBR;
+ TWBR=0;
+ Wire.beginTransmission(GPIO_ADDR + LCD_BOARD_ID);
+ Wire.write(regAddr);
+ Wire.write(regData);
+ Wire.endTransmission();
+ TWBR=oldTWBR;
+}
+
+static bool isDataMode = false;
+static bool isCmdMode = false;
+
+void SSD1331_init_board(void) {
+ //setup GPIO, reset SSD1331
+ writeGPIO(GPIO_RegData,~GPIO_RES);//reset low, CS/other pins high
+ writeGPIO(GPIO_RegDir,~GPIO_RES);//set reset to output
+ delay(5);
+ writeGPIO(GPIO_RegDir,~(GPIO_CS|GPIO_DC));//reset to input, CS/DC output
+ writeGPIO(GPIO_RegPullUp,GPIO_BTN1|GPIO_BTN2|GPIO_BTN3|GPIO_BTN4);//button pullup enable
+ //init SPI
+ SPI.begin();
+ SPI.setDataMode(SPI_MODE0);//wrong mode, works because we're only writing. this mode is compatible with SD cards.
+ SPI.setClockDivider(SPI_CLOCK_DIV2);
+
+ isDataMode = isCmdMode = false;
+}
+
+void SSD1331_setpin_reset(int state) {
+ // Ignore this as we did it in the init_board
+}
+
+void SSD1331_aquirebus(void) {
+ // Do nothing as we do it in the data transfer
+}
+
+void SSD1331_releasebus(void) {
+ if (!isDataMode && !isCmdMode) return;
+ writeGPIO(GPIO_RegData,GPIO_TRANSFER_END);
+ isDataMode = isCmdMode = false;
+}
+
+void SSD1331_write_cmd(uint8_t cmd) {
+ if (!isCmdMode) {
+ writeGPIO(GPIO_RegData,GPIO_CMD_START);
+ isDataMode = false;
+ isCmdMode = true;
+ }
+ SPI.transfer(cmd);
+}
+
+void SSD1331_write_data(uint8_t data) {
+ if (!isDataMode) {
+ writeGPIO(GPIO_RegData,GPIO_DATA_START);
+ isDataMode = true;
+ isCmdMode = false;
+ }
+ SPI.transfer(data);
+}
diff --git a/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.h b/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.h
new file mode 100644
index 00000000..17b125c8
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/board_SSD1331.h
@@ -0,0 +1,34 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+#define init_board(g) SSD1331_init_board()
+#define post_init_board(g)
+#define setpin_reset(g, state) SSD1331_setpin_reset(state)
+#define acquire_bus(g) SSD1331_aquirebus()
+#define release_bus(g) SSD1331_releasebus()
+#define write_cmd(g, cmd) SSD1331_write_cmd(cmd)
+#define write_data(g, data) SSD1331_write_data(data)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void SSD1331_init_board(void);
+void SSD1331_setpin_reset(int state);
+void SSD1331_aquirebus(void);
+void SSD1331_releasebus(void);
+void SSD1331_write_cmd(uint8_t cmd);
+void SSD1331_write_data(uint8_t data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GDISP_LLD_BOARD_H */
diff --git a/boards/base/ArduinoTinyScreen/gfx/driver_SSD1331.c b/boards/base/ArduinoTinyScreen/gfx/driver_SSD1331.c
new file mode 100644
index 00000000..910ea06a
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/driver_SSD1331.c
@@ -0,0 +1 @@
+#include "ugfx/drivers/gdisp/SSD1331/gdisp_lld_SSD1331.c" \ No newline at end of file
diff --git a/boards/base/ArduinoTinyScreen/gfx/gdisp_lld_config.h b/boards/base/ArduinoTinyScreen/gfx/gdisp_lld_config.h
new file mode 100644
index 00000000..29757d09
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/gdisp_lld_config.h
@@ -0,0 +1 @@
+#include "ugfx/drivers/gdisp/SSD1331/gdisp_lld_config.h" \ No newline at end of file
diff --git a/boards/base/ArduinoTinyScreen/gfx/gfx.c b/boards/base/ArduinoTinyScreen/gfx/gfx.c
new file mode 100644
index 00000000..b5836987
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/gfx.c
@@ -0,0 +1 @@
+#include "ugfx/src/gfx_mk.c"
diff --git a/boards/base/ArduinoTinyScreen/gfx/gfx.h b/boards/base/ArduinoTinyScreen/gfx/gfx.h
new file mode 100644
index 00000000..19116626
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/gfx.h
@@ -0,0 +1 @@
+#include "ugfx/gfx.h" \ No newline at end of file
diff --git a/boards/base/ArduinoTinyScreen/gfx/gfxconf.h b/boards/base/ArduinoTinyScreen/gfx/gfxconf.h
new file mode 100644
index 00000000..1a1f8623
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/gfx/gfxconf.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu <joel@unormal.org>
+ * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GFXCONF_H
+#define _GFXCONF_H
+
+/* The operating system to use. One of these must be defined - preferably in your Makefile */
+//#define GFX_USE_OS_CHIBIOS FALSE
+//#define GFX_USE_OS_WIN32 FALSE
+//#define GFX_USE_OS_LINUX FALSE
+//#define GFX_USE_OS_OSX FALSE
+#define GFX_USE_OS_ARDUINO TRUE
+
+/* GFX sub-systems to turn on */
+#define GFX_USE_GDISP TRUE
+
+/* Features for the GDISP sub-system. */
+#define GDISP_NEED_VALIDATION TRUE
+#define GDISP_NEED_CLIP TRUE
+
+#endif /* _GFXCONF_H */
+
diff --git a/boards/base/ArduinoTinyScreen/readme.txt b/boards/base/ArduinoTinyScreen/readme.txt
new file mode 100644
index 00000000..5c047e8b
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/readme.txt
@@ -0,0 +1,17 @@
+This is a working Arduino project for the TinyScreen ATmega board.
+
+To use this with the Arduino IDE Development Environment follow these steps...
+
+1/ Copy the gfx directory from this directory to your Arduino library. eg <Documents>/Arduino/libraries/gfx
+3/ Create a subdirectory under "gfx" called "ugfx" and copy the entire ugfx system to that directory.
+4/ In the "gfx" directory adjust the gfxconf.h for your project.
+5/ In the gfx directory create a .c file for each driver that you want to use that contains a single line
+ to #include the driver source in the repository file. For a GDISP driver you will also need to create
+ a gdisp_lld_config.h file that contains a single line that #include's the gdisp_lld_config.h file for
+ the GDISP driver. Don't forget to add the board files for your drivers.
+ This example has the files for the SSD1331 TinyScreen display.
+6/ Copy the example ugfx_test.ino file to your Arduino projects directory eg <Documents>/Arduino/ugfx_test
+7/ Modify the ugfx_test.ino project to suit.
+8/ Remember that for ATmega platforms RAM and FLASH are very limited. Be careful which ugfx options you turn on.
+ Arduino ARM based boards are much less limited.
+
diff --git a/boards/base/ArduinoTinyScreen/ugfx_test.ino b/boards/base/ArduinoTinyScreen/ugfx_test.ino
new file mode 100644
index 00000000..25bbcdef
--- /dev/null
+++ b/boards/base/ArduinoTinyScreen/ugfx_test.ino
@@ -0,0 +1,38 @@
+#include <Wire.h>
+#include <SPI.h>
+#include <gfx.h>
+
+void setup() {
+ coord_t width, height;
+ coord_t i, j;
+
+ pinMode(13, OUTPUT);
+
+ // Initialize and clear the display
+ gfxInit();
+
+#if 1
+ // Get the screen size
+ width = gdispGetWidth();
+ height = gdispGetHeight();
+
+ // Code Here
+ gdispDrawBox(10, 10, width / 2, height / 2, Yellow);
+ gdispFillArea(width / 2, height / 2, width / 2 - 10, height / 2 - 10, Blue);
+ gdispDrawLine(5, 30, width - 50, height - 40, Red);
+
+ for (i = 5, j = 0; i < width && j < height; i += 7, j += i / 20)
+ gdispDrawPixel(i, j, White);
+#endif
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(500);
+ //gfxSleepMilliseconds(500);
+ digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
+ delay(500);
+ //gfxSleepMilliseconds(500);
+}
+