--- /dev/null
+Oled display example for displays using SSD130x driver
+
+Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+This example shows the support of the I²C driver for the SSD130x oled display
+controller, as found on MCOT128064N2Z-YM DISPLAY from MIDAS, used on
+Seeed-Studio's 128 x 64 Oled display board, and on Techno-Innov's Scialys
+display board.
+
+Other display are supported by using charge_pump configuration setting.
+
+The example starts with one pixel line "on" per character line, and then
+displays text received from the uart on the second line of the display.
--- /dev/null
+/****************************************************************************
+ * apps/base/oled/main.c
+ *
+ * Example of Support for Oled 128*64 display
+ *
+ * Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+
+#include "core/system.h"
+#include "core/systick.h"
+#include "core/pio.h"
+#include "lib/stdio.h"
+#include "drivers/serial.h"
+#include "drivers/gpio.h"
+#include "drivers/i2c.h"
+
+#include "extdrv/status_led.h"
+#include "extdrv/ssd130x_oled_driver.h"
+#include "lib/font.h"
+
+
+#define MODULE_VERSION 0x04
+#define MODULE_NAME "GPIO Demo Module"
+
+
+#define SELECTED_FREQ FREQ_SEL_48MHz
+
+
+/***************************************************************************** */
+/* Pins configuration */
+/* pins blocks are passed to set_pins() for pins configuration.
+ * Unused pin blocks can be removed safely with the corresponding set_pins() call
+ * All pins blocks may be safelly merged in a single block for single set_pins() call..
+ */
+const struct pio_config common_pins[] = {
+ /* UART 0 : Config / Debug / USB */
+ { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL },
+ { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL },
+ /* I2C : Display */
+ { LPC_I2C0_SCL_PIO_0_10, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) },
+ { LPC_I2C0_SDA_PIO_0_11, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) },
+ ARRAY_LAST_PIO,
+};
+
+const struct pio status_led_green = LPC_GPIO_1_4;
+const struct pio status_led_red = LPC_GPIO_1_5;
+
+
+
+
+/***************************************************************************** */
+/* Basic system init and configuration */
+
+void system_init()
+{
+ /* Stop the Watchdog */
+ startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */
+ system_set_default_power_state();
+ clock_config(SELECTED_FREQ);
+ set_pins(common_pins);
+ gpio_on();
+ status_led_config(&status_led_green, &status_led_red);
+ /* System tick timer MUST be configured and running in order to use the sleeping
+ * functions */
+ systick_timer_on(1); /* 1ms */
+ systick_start();
+}
+
+/* Define our fault handler. This one is not mandatory, the dummy fault handler
+ * will be used when it's not overridden here.
+ * Note : The default one does a simple infinite loop. If the watchdog is deactivated
+ * the system will hang.
+ */
+void fault_info(const char* name, uint32_t len)
+{
+ uprintf(UART0, name);
+ while (1);
+}
+
+
+/***************************************************************************** */
+/* Oled Display */
+#define DISPLAY_ADDR 0x78
+struct oled_display display = {
+ .address = DISPLAY_ADDR,
+ .bus_num = I2C0,
+ .charge_pump = SSD130x_EXT_VCC, /* Alt is SSD130x_INTERNAL_PUMP */
+ .video_mode = SSD130x_DISP_NORMAL,
+ .contrast = 128,
+ .scan_dir = SSD130x_SCAN_BOTTOM_TOP,
+ .read_dir = SSD130x_RIGHT_TO_LEFT,
+ .display_offset_dir = SSD130x_MOVE_TOP,
+ .display_offset = 4,
+};
+
+#define ROW(x) VERTICAL_REV(x)
+DECLARE_FONT(font);
+
+void display_char(uint8_t line, uint8_t col, uint8_t c)
+{
+ uint8_t tile = (c > FIRST_FONT_CHAR) ? (c - FIRST_FONT_CHAR) : 0;
+ uint8_t* tile_data = (uint8_t*)(&font[tile]);
+ ssd130x_set_tile(&display, col, line, tile_data);
+}
+int display_line(uint8_t line, uint8_t col, char* text)
+{
+ int len = strlen((char*)text);
+ int i = 0;
+
+ for (i = 0; i < len; i++) {
+ uint8_t tile = (text[i] > FIRST_FONT_CHAR) ? (text[i] - FIRST_FONT_CHAR) : 0;
+ uint8_t* tile_data = (uint8_t*)(&font[tile]);
+ ssd130x_set_tile(&display, col++, line, tile_data);
+ if (col >= (SSD130x_NB_COL / 8)) {
+ col = 0;
+ line++;
+ if (line >= SSD130x_NB_PAGES) {
+ return i;
+ }
+ }
+ }
+ return len;
+}
+
+/***************************************************************************** */
+/* Communication over USB */
+uint8_t text_received = 0;
+#define NB_CHARS 15
+char inbuff[NB_CHARS + 1];
+void data_rx(uint8_t c)
+{
+ static int idx = 0;
+ if ((c != 0) && (c != '\n') && (c != '\r')) {
+ inbuff[idx++] = c;
+ if (idx >= NB_CHARS) {
+ inbuff[NB_CHARS] = 0;
+ idx = 0;
+ text_received = 1;
+ }
+ } else {
+ if (idx != 0) {
+ inbuff[idx] = 0;
+ text_received = 1;
+ }
+ idx = 0;
+ }
+}
+
+
+/***************************************************************************** */
+int main(void)
+{
+ int ret = 0;
+ system_init();
+ uart_on(UART0, 115200, data_rx);
+ i2c_on(I2C0, I2C_CLK_100KHz, I2C_MASTER);
+
+ status_led(green_only);
+
+ /* Configure and start display */
+ ret = ssd130x_display_on(&display);
+ /* Erase screen with lines, makes it easier to know things are going right */
+ ssd130x_display_set(&display, 0x10);
+ ret = ssd130x_display_full_screen(&display);
+
+ while (1) {
+ chenillard(500);
+ if (text_received != 0) {
+ display_line(2, 1, inbuff);
+ ret = ssd130x_display_full_screen(&display);
+ if (ret != 0) {
+ uprintf(UART0, "Display update error: %d\n", ret);
+ }
+ text_received = 0;
+ }
+ }
+ return 0;
+}
+
+
+