From e27d04d002a40f3b514eeeb60d374df6a8a1280c Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 13 Aug 2012 04:12:42 +0200 Subject: restructure --- drivers/gdisp/gdispNokia6610/GE12.h | 81 +++ drivers/gdisp/gdispNokia6610/GE8.h | 67 ++ drivers/gdisp/gdispNokia6610/gdisp_lld.c | 688 +++++++++++++++++++++ drivers/gdisp/gdispNokia6610/gdisp_lld.mk | 5 + .../gdisp/gdispNokia6610/gdisp_lld_board_example.h | 97 +++ .../gdisp_lld_board_olimexsam7ex256.h | 199 ++++++ drivers/gdisp/gdispNokia6610/gdisp_lld_config.h | 66 ++ drivers/gdisp/gdispNokia6610/readme.txt | 17 + drivers/gdisp/gdispS6d1121/gdisp_lld.c | 688 +++++++++++++++++++++ drivers/gdisp/gdispS6d1121/gdisp_lld.mk | 5 + drivers/gdisp/gdispS6d1121/gdisp_lld_config.h | 66 ++ drivers/gdisp/gdispS6d1121/readme.txt | 16 + drivers/gdisp/gdispS6d1121/s6d1121_lld.c.h | 244 ++++++++ drivers/gdisp/gdispSsd1289/gdisp_lld.c | 610 ++++++++++++++++++ drivers/gdisp/gdispSsd1289/gdisp_lld.mk | 5 + drivers/gdisp/gdispSsd1289/gdisp_lld_config.h | 66 ++ drivers/gdisp/gdispSsd1289/readme.txt | 16 + drivers/gdisp/gdispSsd1289/ssd1289_lld.c.h | 322 ++++++++++ drivers/gdisp/gdispTestStub/gdisp_lld.c | 361 +++++++++++ drivers/gdisp/gdispTestStub/gdisp_lld.mk | 5 + drivers/gdisp/gdispTestStub/gdisp_lld_config.h | 66 ++ drivers/gdisp/gdispTestStub/readme.txt | 17 + drivers/gdisp/gdispVMT/gdisp_lld.c | 249 ++++++++ drivers/gdisp/gdispVMT/gdisp_lld.mk | 7 + drivers/gdisp/gdispVMT/gdisp_lld_config.h | 67 ++ drivers/gdisp/gdispVMT/gdisp_lld_driver1.c | 51 ++ drivers/gdisp/gdispVMT/gdisp_lld_driver2.c | 51 ++ drivers/gdisp/gdispVMT/readme.txt | 23 + drivers/touchpad/touchpadADS7843/readme.txt | 9 + drivers/touchpad/touchpadADS7843/touchpad_lld.c | 146 +++++ drivers/touchpad/touchpadADS7843/touchpad_lld.mk | 6 + .../touchpad/touchpadADS7843/touchpad_lld_config.h | 44 ++ drivers/touchpad/touchpadXPT2046/readme.txt | 9 + drivers/touchpad/touchpadXPT2046/touchpad_lld.c | 158 +++++ drivers/touchpad/touchpadXPT2046/touchpad_lld.mk | 6 + .../touchpad/touchpadXPT2046/touchpad_lld_config.h | 44 ++ 36 files changed, 4577 insertions(+) create mode 100644 drivers/gdisp/gdispNokia6610/GE12.h create mode 100644 drivers/gdisp/gdispNokia6610/GE8.h create mode 100644 drivers/gdisp/gdispNokia6610/gdisp_lld.c create mode 100644 drivers/gdisp/gdispNokia6610/gdisp_lld.mk create mode 100644 drivers/gdisp/gdispNokia6610/gdisp_lld_board_example.h create mode 100644 drivers/gdisp/gdispNokia6610/gdisp_lld_board_olimexsam7ex256.h create mode 100644 drivers/gdisp/gdispNokia6610/gdisp_lld_config.h create mode 100644 drivers/gdisp/gdispNokia6610/readme.txt create mode 100644 drivers/gdisp/gdispS6d1121/gdisp_lld.c create mode 100644 drivers/gdisp/gdispS6d1121/gdisp_lld.mk create mode 100644 drivers/gdisp/gdispS6d1121/gdisp_lld_config.h create mode 100644 drivers/gdisp/gdispS6d1121/readme.txt create mode 100644 drivers/gdisp/gdispS6d1121/s6d1121_lld.c.h create mode 100644 drivers/gdisp/gdispSsd1289/gdisp_lld.c create mode 100644 drivers/gdisp/gdispSsd1289/gdisp_lld.mk create mode 100644 drivers/gdisp/gdispSsd1289/gdisp_lld_config.h create mode 100644 drivers/gdisp/gdispSsd1289/readme.txt create mode 100644 drivers/gdisp/gdispSsd1289/ssd1289_lld.c.h create mode 100644 drivers/gdisp/gdispTestStub/gdisp_lld.c create mode 100644 drivers/gdisp/gdispTestStub/gdisp_lld.mk create mode 100644 drivers/gdisp/gdispTestStub/gdisp_lld_config.h create mode 100644 drivers/gdisp/gdispTestStub/readme.txt create mode 100644 drivers/gdisp/gdispVMT/gdisp_lld.c create mode 100644 drivers/gdisp/gdispVMT/gdisp_lld.mk create mode 100644 drivers/gdisp/gdispVMT/gdisp_lld_config.h create mode 100644 drivers/gdisp/gdispVMT/gdisp_lld_driver1.c create mode 100644 drivers/gdisp/gdispVMT/gdisp_lld_driver2.c create mode 100644 drivers/gdisp/gdispVMT/readme.txt create mode 100644 drivers/touchpad/touchpadADS7843/readme.txt create mode 100644 drivers/touchpad/touchpadADS7843/touchpad_lld.c create mode 100644 drivers/touchpad/touchpadADS7843/touchpad_lld.mk create mode 100644 drivers/touchpad/touchpadADS7843/touchpad_lld_config.h create mode 100644 drivers/touchpad/touchpadXPT2046/readme.txt create mode 100644 drivers/touchpad/touchpadXPT2046/touchpad_lld.c create mode 100644 drivers/touchpad/touchpadXPT2046/touchpad_lld.mk create mode 100644 drivers/touchpad/touchpadXPT2046/touchpad_lld_config.h (limited to 'drivers') diff --git a/drivers/gdisp/gdispNokia6610/GE12.h b/drivers/gdisp/gdispNokia6610/GE12.h new file mode 100644 index 00000000..7f438d9a --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/GE12.h @@ -0,0 +1,81 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +#ifndef GE12_H +#define GE12_H + +// ************************************************************************************* +// LCD Include File for Philips PCF8833 STN RGB- 132x132x3 Driver (GE12) +// +// Taken from Philips data sheet Feb 14, 2003 +// ************************************************************************************* + +// Philips PCF8833 LCD controller command codes +#define NOP 0x00 // nop +#define SWRESET 0x01 // software reset +#define BSTROFF 0x02 // booster voltage OFF +#define BSTRON 0x03 // booster voltage ON +#define RDDIDIF 0x04 // read display identification +#define RDDST 0x09 // read display status +#define SLEEPIN 0x10 // sleep in +#define SLEEPOUT 0x11 // sleep out +#define PTLON 0x12 // partial display mode +#define NORON 0x13 // display normal mode +#define INVOFF 0x20 // inversion OFF +#define INVON 0x21 // inversion ON +#define DALO 0x22 // all pixel OFF +#define DAL 0x23 // all pixel ON +#define SETCON 0x25 // write contrast +#define DISPOFF 0x28 // display OFF +#define DISPON 0x29 // display ON +#define CASET 0x2A // column address set +#define PASET 0x2B // page address set +#define RAMWR 0x2C // memory write +#define RGBSET 0x2D // colour set +#define PTLAR 0x30 // partial area +#define VSCRDEF 0x33 // vertical scrolling definition +#define TEOFF 0x34 // test mode +#define TEON 0x35 // test mode +#define MADCTL 0x36 // memory access control +#define SEP 0x37 // vertical scrolling start address +#define IDMOFF 0x38 // idle mode OFF +#define IDMON 0x39 // idle mode ON +#define COLMOD 0x3A // interface pixel format +#define SETVOP 0xB0 // set Vop +#define BRS 0xB4 // bottom row swap +#define TRS 0xB6 // top row swap +#define DISCTR 0xB9 // display control +#define DOR 0xBA // data order +#define TCDFE 0xBD // enable/disable DF temperature compensation +#define TCVOPE 0xBF // enable/disable Vop temp comp +#define EC 0xC0 // internal or external oscillator +#define SETMUL 0xC2 // set multiplication factor +#define TCVOPAB 0xC3 // set TCVOP slopes A and B +#define TCVOPCD 0xC4 // set TCVOP slopes c and d +#define TCDF 0xC5 // set divider frequency +#define DF8COLOR 0xC6 // set divider frequency 8-color mode +#define SETBS 0xC7 // set bias system +#define RDTEMP 0xC8 // temperature read back +#define NLI 0xC9 // n-line inversion +#define RDID1 0xDA // read ID1 +#define RDID2 0xDB // read ID2 +#define RDID3 0xDC // read ID3 + +#endif /* GE12_H */ diff --git a/drivers/gdisp/gdispNokia6610/GE8.h b/drivers/gdisp/gdispNokia6610/GE8.h new file mode 100644 index 00000000..3ae0be77 --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/GE8.h @@ -0,0 +1,67 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +#ifndef GE8_H +#define GE8_H + +// ***************************************************************************** +// Include file for Epson S1D15G00 LCD Controller (GE8) +// +// Author: James P Lynch August 30, 2007 +// Modified for GDISP: Andrew Hannam August 2, 2012 +// +// ***************************************************************************** + +#define DISON 0xAF // Display on +#define DISOFF 0xAE // Display off +#define DISNOR 0xA6 // Normal display +#define DISINV 0xA7 // Inverse display +#define COMSCN 0xBB // Common scan direction +#define DISCTL 0xCA // Display control +#define SLPIN 0x95 // Sleep in +#define SLPOUT 0x94 // Sleep out +#define PASET 0x75 // Page address set +#define CASET 0x15 // Column address set +#define DATCTL 0xBC // Data scan direction, etc. +#define RGBSET8 0xCE // 256-color position set +#define RAMWR 0x5C // Writing to memory +#define RAMRD 0x5D // Reading from memory +#define PTLIN 0xA8 // Partial display in +#define PTLOUT 0xA9 // Partial display out +#define RMWIN 0xE0 // Read and modify write +#define RMWOUT 0xEE // End +#define ASCSET 0xAA // Area scroll set +#define SCSTART 0xAB // Scroll start set +#define OSCON 0xD1 // Internal oscillation on +#define OSCOFF 0xD2 // Internal oscillation off +#define PWRCTR 0x20 // Power control +#define VOLCTR 0x81 // Electronic volume control +#define VOLUP 0xD6 // Increment electronic control by 1 +#define VOLDOWN 0xD7 // Decrement electronic control by 1 +#define TMPGRD 0x82 // Temperature gradient set +#define EPCTIN 0xCD // Control EEPROM +#define EPCOUT 0xCC // Cancel EEPROM control +#define EPMWR 0xFC // Write into EEPROM +#define EPMRD 0xFD // Read from EEPROM +#define EPSRRD1 0x7C // Read register 1 +#define EPSRRD2 0x7D // Read register 2 +#define NOP 0x25 // NOP instruction + +#endif /* GE8_H */ diff --git a/drivers/gdisp/gdispNokia6610/gdisp_lld.c b/drivers/gdisp/gdispNokia6610/gdisp_lld.c new file mode 100644 index 00000000..5ebe2177 --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/gdisp_lld.c @@ -0,0 +1,688 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispNokia6610/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 display. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gdisp.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +/* Include the emulation code for things we don't support */ +#include "gdisp_emulation.c" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/* Controller definitions */ +#if defined(LCD_USE_GE8) + #include "GE8.h" +#elif defined(LCD_USE_GE12) + #include "GE12.h" +#else + #error "gdispNokia6610: Either LCD_USE_GE8 or LCD_USE_GE12 must be defined depending on your controller" +#endif + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +#include "gdisp_fonts.h" + +#if defined(BOARD_OLIMEX_SAM7_EX256) + #include "gdisp_lld_board_olimexsam7ex256.h" +#else + /* Include the user supplied board definitions */ + #include "gdisp_lld_board.h" +#endif + +#define gdisp_lld_write_command(cmd) GDISP_LLD(write_spi)((cmd) & ~0x0100) +#define gdisp_lld_write_data(data) GDISP_LLD(write_spi)((data) | 0x0100) + +static __inline void gdisp_lld_setviewport(coord_t x, coord_t y, coord_t cx, coord_t cy) { + gdisp_lld_write_command(CASET); // Column address set + gdisp_lld_write_data(x); + gdisp_lld_write_data(x+cx-1); + gdisp_lld_write_command(PASET); // Page address set + gdisp_lld_write_data(y); + gdisp_lld_write_data(y+cy-1); +} + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ +/* + The following 2 routines are required. + All other routines are optional. +*/ + +/** + * @brief Low level GDISP driver initialization. + * + * @notapi + */ +bool_t GDISP_LLD(init)(void) { + /* Initialise your display */ + GDISP_LLD(init_board)(); + + // Hardware reset + GDISP_LLD(setpin_reset)(TRUE); + chThdSleepMilliseconds(20); + GDISP_LLD(setpin_reset)(FALSE); + chThdSleepMilliseconds(20); + + #if defined(LCD_USE_GE8) + #if 1 + gdisp_lld_write_command(DISCTL); // Display control + gdisp_lld_write_data(0x00); // P1: 0x00 = 2 divisions, switching period=8 (default) + gdisp_lld_write_data(0x20); // P2: 0x20 = nlines/4 - 1 = 132/4 - 1 = 32) + gdisp_lld_write_data(0x00); // P3: 0x00 = no inversely highlighted lines + gdisp_lld_write_command(COMSCN); // COM scan + gdisp_lld_write_data(1); // P1: 0x01 = Scan 1->80, 160<-81 + gdisp_lld_write_command(OSCON); // Internal oscilator ON + gdisp_lld_write_command(SLPOUT); // Sleep out + gdisp_lld_write_command(PWRCTR); // Power control + gdisp_lld_write_data(0x0f); // reference voltage regulator on, circuit voltage follower on, BOOST ON + // Interesting - all the code seems to say this should be done. But my display doesn't want it! + //gdisp_lld_write_command(DISINV); // Inverse display + gdisp_lld_write_command(DATCTL); // Data control + gdisp_lld_write_data(0x01); // P1: 0x01 = page address inverted, column address normal, address scan in column direction + gdisp_lld_write_data(0x00); // P2: 0x00 = RGB sequence (default value) + gdisp_lld_write_data(0x02); // P3: 0x02 = Grayscale -> 16 (selects 12-bit color, type A) + gdisp_lld_write_command(VOLCTR); // Voltage control (contrast setting) + gdisp_lld_write_data(32); // P1 = 32 volume value (experiment with this value to get the best contrast) + gdisp_lld_write_data(3); // P2 = 3 resistance ratio (only value that works) + chThdSleepMilliseconds(100); // allow power supply to stabilize + gdisp_lld_write_command(DISON); // Turn on the display + #else + // Alternative + gdisp_lld_write_command(DISCTL); // Display control + gdisp_lld_write_data(0x00); // default + gdisp_lld_write_data(0x20); // (32 + 1) * 4 = 132 lines (of which 130 are visible) + gdisp_lld_write_data(0x0a); // default + gdisp_lld_write_command(COMSCN); // COM scan + gdisp_lld_write_data(0x00); // Scan 1-80 + gdisp_lld_write_command(OSCON); // Internal oscilator ON + chThdSleepMilliseconds(100); // wait aproximetly 100ms + gdisp_lld_write_command(SLPOUT); // Sleep out + gdisp_lld_write_command(VOLCTR); // Voltage control + gdisp_lld_write_data(0x1F); // middle value of V1 + gdisp_lld_write_data(0x03); // middle value of resistance value + gdisp_lld_write_command(TMPGRD); // Temperature gradient + gdisp_lld_write_data(0x00); // default + gdisp_lld_write_command(PWRCTR); // Power control + gdisp_lld_write_data(0x0f); // referance voltage regulator on, circuit voltage follower on, BOOST ON + gdisp_lld_write_command(DISNOR); // Normal display + gdisp_lld_write_command(DISINV); // Inverse display + gdisp_lld_write_command(PTLOUT); // Partial area off + // gdisp_lld_write_command(ASCSET); // Scroll area set + // gdisp_lld_write_data(0); + // gdisp_lld_write_data(0); + // gdisp_lld_write_data(40); + // gdisp_lld_write_data(3); + // gdisp_lld_write_command(SCSTART); // Vertical scrool address start + // gdisp_lld_write_data(0); + gdisp_lld_write_command(DATCTL); // Data control + gdisp_lld_write_data(0x00); // all inversions off, column direction + gdisp_lld_write_data(0x03); // RGB sequence + gdisp_lld_write_data(0x02); // Grayscale -> 16 + gdisp_lld_write_command(PASET); // Page Address set + gdisp_lld_write_data(0); + gdisp_lld_write_data(131); + gdisp_lld_write_command(CASET); // Page Column set + gdisp_lld_write_data(0); + gdisp_lld_write_data(131); + gdisp_lld_write_command(DISON); // Turn on the display + #endif + + #elif defined(LCD_USE_GE12) + #if 1 + gdisp_lld_write_command(SLEEPOUT); // Sleep out + gdisp_lld_write_command(INVON); // Inversion on: seems to be required for this controller + gdisp_lld_write_command(COLMOD); // Color Interface Pixel Format + gdisp_lld_write_data(0x03); // 0x03 = 12 bits-per-pixel + gdisp_lld_write_command(MADCTL); // Memory access controler + gdisp_lld_write_data(0xC8); // 0xC0 = mirror x and y, reverse rgb + gdisp_lld_write_command(SETCON); // Write contrast + gdisp_lld_write_data(0x30); // contrast - experiental value + chThdSleepMilliseconds(20); + gdisp_lld_write_command(DISPON); // Display On + #else + // Alternative + // Hardware reset commented out + gdisp_lld_write_command(SOFTRST); // Software Reset + chThdSleepMilliseconds(20); + gdisp_lld_write_command(INITESC); // Initial escape + chThdSleepMilliseconds(20); + gdisp_lld_write_command(REFSET); // Refresh set + gdisp_lld_write_data(0); + gdisp_lld_write_command(DISPCTRL); // Set Display control + gdisp_lld_write_data(128); // Set the lenght of one selection term + gdisp_lld_write_data(128); // Set N inversion -> no N inversion + gdisp_lld_write_data(134); // Set frame frequence and bias rate -> 2 devision of frequency and 1/8 bias, 1/67 duty, 96x67 size + gdisp_lld_write_data(84); // Set duty parameter + gdisp_lld_write_data(69); // Set duty parameter + gdisp_lld_write_data(82); // Set duty parameter + gdisp_lld_write_data(67); // Set duty parameter + gdisp_lld_write_command(GRAYSCALE0); // Grey scale 0 position set - 15 parameters + gdisp_lld_write_data(1); // GCP1 - gray lavel to be output when the RAM data is "0001" + gdisp_lld_write_data(2); // GCP2 - gray lavel to be output when the RAM data is "0010" + gdisp_lld_write_data(4); // GCP3 - gray lavel to be output when the RAM data is "0011" + gdisp_lld_write_data(8); // GCP4 - gray lavel to be output when the RAM data is "0100" + gdisp_lld_write_data(16); // GCP5 - gray lavel to be output when the RAM data is "0101" + gdisp_lld_write_data(30); // GCP6 - gray lavel to be output when the RAM data is "0110" + gdisp_lld_write_data(40); // GCP7 - gray lavel to be output when the RAM data is "0111" + gdisp_lld_write_data(50); // GCP8 - gray lavel to be output when the RAM data is "1000" + gdisp_lld_write_data(60); // GCP9 - gray lavel to be output when the RAM data is "1001" + gdisp_lld_write_data(70); // GCP10 - gray lavel to be output when the RAM data is "1010" + gdisp_lld_write_data(80); // GCP11 - gray lavel to be output when the RAM data is "1011" + gdisp_lld_write_data(90); // GCP12 - gray lavel to be output when the RAM data is "1100" + gdisp_lld_write_data(100); // GCP13 - gray lavel to be output when the RAM data is "1101" + gdisp_lld_write_data(110); // GCP14 - gray lavel to be output when the RAM data is "1110" + gdisp_lld_write_data(127); // GCP15 - gray lavel to be output when the RAM data is "1111" + gdisp_lld_write_command(GAMMA); // Gamma curve set - select gray scale - GRAYSCALE 0 or GREYSCALE 1 + gdisp_lld_write_data(1); // Select grey scale 0 + gdisp_lld_write_command(COMMONDRV); // Command driver output + gdisp_lld_write_data(0); // Set COM1-COM41 side come first, normal mod + gdisp_lld_write_command(NORMALMODE); // Set Normal mode (my) + // gdisp_lld_write_command(INVERSIONOFF); // Inversion off + gdisp_lld_write_command(COLADDRSET); // Column address set + gdisp_lld_write_data(0); + gdisp_lld_write_data(131); + gdisp_lld_write_command(PAGEADDRSET); // Page address set + gdisp_lld_write_data(0); + gdisp_lld_write_data(131); + gdisp_lld_write_command(ACCESSCTRL); // Memory access controler + gdisp_lld_write_data(0x40); // horizontal + //gdisp_lld_write_data(0x20); // vertical + gdisp_lld_write_command(PWRCTRL); // Power control + gdisp_lld_write_data(4); // Internal resistance, V1OUT -> high power mode, oscilator devision rate + gdisp_lld_write_command(SLEEPOUT); // Sleep out + gdisp_lld_write_command(VOLTCTRL); // Voltage control - voltage control and write contrast define LCD electronic volume + //gdisp_lld_write_data(0x7f); // full voltage control + //gdisp_lld_write_data(0x03); // must be "1" + gdisp_lld_write_command(CONTRAST); // Write contrast + gdisp_lld_write_data(0x3b); // contrast + chThdSleepMilliseconds(20); + gdisp_lld_write_command(TEMPGRADIENT); // Temperature gradient + for(i=0; i<14; i++) gdisp_lld_write_data(0); + gdisp_lld_write_command(BOOSTVON); // Booster voltage ON + gdisp_lld_write_command(DISPLAYON); // Finally - Display On + #endif + #endif + + /* Turn on the back-light */ + GDISP_LLD(setpin_backlight)(TRUE); + + /* Initialise the GDISP structure to match */ + GDISP.Width = 132; + GDISP.Height = 132; + GDISP.Orientation = portrait; + GDISP.Powermode = powerOn; + GDISP.Backlight = 100; + GDISP.Contrast = 50; + return TRUE; +} + +/** + * @brief Draws a pixel on the display. + * + * @param[in] x X location of the pixel + * @param[in] y Y location of the pixel + * @param[in] color The color of the pixel + * + * @notapi + */ +void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { + #if GDISP_NEED_VALIDATION + if (x >= GDISP.Width || y >= GDISP.Height) return; + #endif + gdisp_lld_setviewport(x, y, 1, 1); + gdisp_lld_write_command(RAMWR); + gdisp_lld_write_data((color >> 4) & 0xFF); + gdisp_lld_write_data((color << 4) & 0xF0); + gdisp_lld_write_command(NOP); +} + +/* ---- Optional Routines ---- */ +/* + All the below routines are optional. + Defining them will increase speed but everything + will work if they are not defined. + If you are not using a routine - turn it off using + the appropriate GDISP_HARDWARE_XXXX macro. + Don't bother coding for obvious similar routines if + there is no performance penalty as the emulation software + makes a good job of using similar routines. + eg. If fillarea() is defined there is little + point in defining clear() unless the + performance bonus is significant. + For good performance it is suggested to implement + fillarea() and blitarea(). +*/ + +#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__) + /** + * @brief Clear the display. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] color The color of the pixel + * + * @notapi + */ + void GDISP_LLD(clear(color_t color) { + /* NOT IMPLEMENTED */ + /* Nothing to be gained by implementing this + * as fillarea is just as fast. + */ + } +#endif + +#if GDISP_HARDWARE_LINES || defined(__DOXYGEN__) + /** + * @brief Draw a line. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x0, y0 The start of the line + * @param[in] x1, y1 The end of the line + * @param[in] color The color of the line + * + * @notapi + */ + void GDISP_LLD(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a color. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] color The color of the fill + * + * @notapi + */ + void GDISP_LLD(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { + unsigned i, tuples; + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) cx = GDISP.Width - x; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + tuples = (cx*cy+1)/2; // With an odd sized area we over-print by one pixel. + // This extra pixel is ignored by the controller. + + gdisp_lld_setviewport(x, y, cx, cy); + gdisp_lld_write_command(RAMWR); + for(i=0; i < tuples; i++) { + gdisp_lld_write_data((color >> 4) & 0xFF); + gdisp_lld_write_data(((color << 4) & 0xF0)|((color >> 8) & 0x0F)); + gdisp_lld_write_data(color & 0xFF); + } + } +#endif + +#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a bitmap. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] buffer The pixels to use to fill the area. + * + * @notapi + */ + void GDISP_LLD(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer) { + unsigned i, area, tuples; + #ifndef GDISP_PACKED_PIXELS + color_t c1, c2; + #endif + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) return; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + area = cx*cy; + + gdisp_lld_setviewport(x, y, cx, cy); + gdisp_lld_write_command(RAMWR); + + #ifdef GDISP_PACKED_PIXELS + // 3 bytes per 2 pixels + an extra 2 bytes if the total size is odd. + // Note we can't just over-estimate this and let the controller handle the extra pixel + // as that might over-run our source buffer (very bad in some circumstances). + tuples = (area/2)*3+(area & 0x01)*2; + for(i=0; i < tuples; i++) + gdisp_lld_write_data(*buffer++); + if (area & 0x01) + gdisp_lld_write_command(NOP); + #else + // Although this controller uses packed pixels we support unpacked pixel + // formats in this blit by packing the data as we feed it to the controller. + tuples = area/2; + for(i=0; i < tuples; i++) { + c1 = *buffer++; + c2 = *buffer++; + gdisp_lld_write_data((c1 >> 4) & 0xFF); + gdisp_lld_write_data(((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)); + gdisp_lld_write_data(c2 & 0xFF); + } + if (area & 0x01) { + c1 = *buffer++; + gdisp_lld_write_data((c1 >> 4) & 0xFF); + gdisp_lld_write_data((c1 << 4) & 0xF0); + gdisp_lld_write_command(NOP); + } + #endif + } +#endif + +/* Circular Drawing Functions */ +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLES) || defined(__DOXYGEN__) + /** + * @brief Draw a circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSES) || defined(__DOXYGEN__) + /** + * @brief Draw an ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + #include "gdisp_fonts.h" +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a transparent background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * + * @notapi + */ + void GDISP_LLD(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXTFILLS) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a filled background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * @param[in] bgcolor The background color + * + * @notapi + */ + void GDISP_LLD(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__) + /** + * @brief Get the color of a particular pixel. + * @note Optional. + * @note If x,y is off the screen, the result is undefined. + * + * @param[in] x, y The start of the text + * + * @notapi + */ + color_t GDISP_LLD(getpixelcolor)(coord_t x, coord_t y) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL) || defined(__DOXYGEN__) + /** + * @brief Scroll vertically a section of the screen. + * @note Optional. + * @note If x,y + cx,cy is off the screen, the result is undefined. + * @note If lines is >= cy, it is equivelent to a area fill with bgcolor. + * + * @param[in] x, y The start of the area to be scrolled + * @param[in] cx, cy The size of the area to be scrolled + * @param[in] lines The number of lines to scroll (Can be positive or negative) + * @param[in] bgcolor The color to fill the newly exposed area. + * + * @notapi + */ + void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { + /* NOT IMPLEMENTED */ + } +#endif + +#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__) + /** + * @brief Driver Control + * @detail Unsupported control codes are ignored. + * @note The value parameter should always be typecast to (void *). + * @note There are some predefined and some specific to the low level driver. + * @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t + * GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t + * GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver + * that only supports off/on anything other + * than zero is on. + * GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100. + * GDISP_CONTROL_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to do. + * @param[in] value The value to use (always cast to a void *). + * + * @notapi + */ + void GDISP_LLD(control)(int what, void *value) { + /* NOT IMPLEMENTED YET */ + switch(what) { + case GDISP_CONTROL_POWER: + if (GDISP.Powermode == (gdisp_powermode_t)value) + return; + switch((gdisp_powermode_t)value) { + case powerOff: + /* Code here */ + break; + case powerOn: + /* Code here */ + /* You may need this --- + if (GDISP.Powermode != powerSleep) + GDISP_LLD(init(); + */ + break; + case powerSleep: + /* Code here */ + break; + default: + return; + } + GDISP.Powermode = (gdisp_powermode_t)value; + return; + case GDISP_CONTROL_ORIENTATION: + if (GDISP.Orientation == (gdisp_orientation_t)value) + return; + // WriteSpiData(0x48); // no mirror Y (temporary to satisfy Olimex bmptoarray utility) + // WriteSpiData(0xC8); // restore to (mirror x and y, reverse rgb) + switch((gdisp_orientation_t)value) { + case portrait: + /* Code here */ + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscape: + /* Code here */ + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + case portraitInv: + /* Code here */ + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscapeInv: + /* Code here */ + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + default: + return; + } + GDISP.Orientation = (gdisp_orientation_t)value; + return; +/* + case GDISP_CONTROL_BACKLIGHT: + case GDISP_CONTROL_CONTRAST: +*/ + } + } +#endif + +#if (GDISP_NEED_QUERY && GDISP_HARDWARE_QUERY) || defined(__DOXYGEN__) +/** + * @brief Query a driver value. + * @detail Typecase the result to the type you want. + * @note GDISP_QUERY_WIDTH - (coord_t) Gets the width of the screen + * GDISP_QUERY_HEIGHT - (coord_t) Gets the height of the screen + * GDISP_QUERY_POWER - (gdisp_powermode_t) Get the current powermode + * GDISP_QUERY_ORIENTATION - (gdisp_orientation_t) Get the current screen orientation + * GDISP_QUERY_BACKLIGHT - (coord_t) Get the backlight state (0 to 100) + * GDISP_QUERY_CONTRAST - (coord_t) Get the contrast (0 to 100). + * GDISP_QUERY_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to Query + * + * @notapi + */ +void *GDISP_LLD(query)(unsigned what) { + switch(what) { + case GDISP_QUERY_WIDTH: return (void *)(unsigned)GDISP.Width; + case GDISP_QUERY_HEIGHT: return (void *)(unsigned)GDISP.Height; + case GDISP_QUERY_POWER: return (void *)(unsigned)GDISP.Powermode; + case GDISP_QUERY_ORIENTATION: return (void *)(unsigned)GDISP.Orientation; + case GDISP_QUERY_BACKLIGHT: return (void *)(unsigned)GDISP.Backlight; + case GDISP_QUERY_CONTRAST: return (void *)(unsigned)GDISP.Contrast; + case GDISP_QUERY_LLD+0: + /* Code here */ + default: return (void *)-1; + } +} +#endif + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispNokia6610/gdisp_lld.mk b/drivers/gdisp/gdispNokia6610/gdisp_lld.mk new file mode 100644 index 00000000..4c980c3c --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/gdisp_lld.mk @@ -0,0 +1,5 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/gdisp/gdispNokia6610/gdisp_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/gdisp/gdispNokia6610 diff --git a/drivers/gdisp/gdispNokia6610/gdisp_lld_board_example.h b/drivers/gdisp/gdispNokia6610/gdisp_lld_board_example.h new file mode 100644 index 00000000..0e2b806e --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/gdisp_lld_board_example.h @@ -0,0 +1,97 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispNokia6610/gdisp_lld_board_example.h + * @brief GDISP Graphic Driver subsystem board interface for the Nokia6610 display. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_BOARD_H +#define _GDISP_LLD_BOARD_H + +/** + * @brief Initialise the board for the display. + * @notes Performs the following functions: + * 1. initialise the spi port used by your display + * 2. initialise the reset pin (initial state not-in-reset) + * 3. initialise the chip select pin (initial state not-active) + * 4. initialise the backlight pin (initial state back-light off) + * + * @notapi + */ +static __inline void GDISP_LLD(init_board)(void) { + /* Code here */ +} + +/** + * @brief Set or clear the lcd reset pin. + * + * @param[in] state TRUE = lcd in reset, FALSE = normal operation + * + * @notapi + */ +static __inline void GDISP_LLD(setpin_reset)(bool_t state) { + /* Code here */ +} + +/** + * @brief Set or clear the lcd back-light pin. + * + * @param[in] state TRUE = lcd back-light on, FALSE = lcd back-light off + * + * @notapi + */ +static __inline void GDISP_LLD(setpin_backlight)(bool_t state) { + /* Code here */ +} + +/** + * @brief Send a 9 bit command/data to the lcd. + * @note The chip select may need to be asserted/de-asserted + * around the actual spi write + * + * @param[in] data The data to send + * + * @notapi + */ +static __inline void GDISP_LLD(write_spi)(uint16_t data) { + /* Code here */ +} + +#if GDISP_HARDWARE_READPIXEL || GDISP_HARDWARE_SCROLL || defined(__DOXYGEN__) +/** + * @brief Read data from the lcd. + * + * @return The data from the lcd + * @note The chip select may need to be asserted/de-asserted + * around the actual spi read + * + * @notapi + */ +static __inline uint16_t GDISP_LLD(read_spi)(void) { + /* Code here */ +} +#endif + +#endif /* _GDISP_LLD_BOARD_H */ +/** @} */ diff --git a/drivers/gdisp/gdispNokia6610/gdisp_lld_board_olimexsam7ex256.h b/drivers/gdisp/gdispNokia6610/gdisp_lld_board_olimexsam7ex256.h new file mode 100644 index 00000000..b5b4b1d5 --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/gdisp_lld_board_olimexsam7ex256.h @@ -0,0 +1,199 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispNokia6610/gdisp_lld_board_olimexsam7ex256.h + * @brief GDISP Graphic Driver subsystem board interface for the Olimex SAM7-EX256 board. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_BOARD_H +#define _GDISP_LLD_BOARD_H + +// mask definitions +#define BIT0 0x00000001 +#define BIT1 0x00000002 +#define BIT2 0x00000004 +#define BIT3 0x00000008 +#define BIT4 0x00000010 +#define BIT5 0x00000020 +#define BIT6 0x00000040 +#define BIT7 0x00000080 +#define BIT8 0x00000100 +#define BIT9 0x00000200 +#define BIT10 0x00000400 +#define BIT11 0x00000800 +#define BIT12 0x00001000 +#define BIT13 0x00002000 +#define BIT14 0x00004000 +#define BIT15 0x00008000 +#define BIT16 0x00010000 +#define BIT17 0x00020000 +#define BIT18 0x00040000 +#define BIT19 0x00080000 +#define BIT20 0x00100000 +#define BIT21 0x00200000 +#define BIT22 0x00400000 +#define BIT23 0x00800000 +#define BIT24 0x01000000 +#define BIT25 0x02000000 +#define BIT26 0x04000000 +#define BIT27 0x08000000 +#define BIT28 0x10000000 +#define BIT29 0x20000000 +#define BIT30 0x40000000 +#define BIT31 0x80000000 + +// ****************************************************** +// Pointers to AT91SAM7X256 peripheral data structures +// ****************************************************** +volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA; +volatile AT91PS_PIO pPIOB = AT91C_BASE_PIOB; +volatile AT91PS_SPI pSPI = AT91C_BASE_SPI0; +volatile AT91PS_PMC pPMC = AT91C_BASE_PMC; +volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_SPI0; + +/** + * @brief Initialise the board for the display. + * @notes Performs the following functions: + * 1. initialise the spi port used by your display + * 2. initialise the reset pin (initial state not-in-reset) + * 3. initialise the chip select pin (initial state not-active) + * 4. initialise the backlight pin (initial state back-light off) + * + * @notapi + */ +static __inline void GDISP_LLD(init_board)(void) { + // ********************************************************************************************* + // InitSpi( ) + // + // Sets up SPI channel 0 for communications to Nokia 6610 LCD Display + // + // I/O ports used: PA2 = LCD Reset (set to low to reset) + // PA12 = LCD chip select (set to low to select the LCD chip) + // PA16 = SPI0_MISO Master In - Slave Out (not used in LCD interface) + // PA17 = SPI0_MOSI Master Out - Slave In pin (Serial Data to LCD slave) + // PA18 = SPI0_SPCK Serial Clock (to LCD slave) + // PB20 = backlight control (normally PWM control, 1 = full on) + // + // *********************************************************************************************} + + /* This code should really use the ChibiOS driver for these functions */ + + // Pin for backlight + pPIOB->PIO_CODR = PIOB_LCD_BL_MASK; // Set PB20 to LOW + pPIOB->PIO_OER = PIOB_LCD_BL_MASK; // Configure PB20 as output + + // Reset pin + pPIOA->PIO_SODR = PIOA_LCD_RESET_MASK; // Set PA2 to HIGH + pPIOA->PIO_OER = PIOA_LCD_RESET_MASK; // Configure PA2 as output + + // CS pin - this seems to be ignored + // pPIOA->PIO_SODR = BIT12; // Set PA2 to HIGH + // pPIOA->PIO_OER = BIT12; // Configure PA2 as output + + // Init SPI0 + // Disable the following pins from PIO control (will be used instead by the SPI0 peripheral) + // BIT12 = PA12 -> SPI0_NPCS0 chip select + // BIT16 = PA16 -> SPI0_MISO Master In - Slave Out (not used in LCD interface) + // BIT17 = PA17 -> SPI0_MOSI Master Out - Slave In pin (Serial Data to LCD slave) + // BIT18 = PA18 -> SPI0_SPCK Serial Clock (to LCD slave) + pPIOA->PIO_PDR = BIT12 | BIT16 | BIT17 | BIT18; + pPIOA->PIO_ASR = BIT12 | BIT16 | BIT17 | BIT18; + pPIOA->PIO_BSR = 0; + + //enable the clock of SPI + pPMC->PMC_PCER = 1 << AT91C_ID_SPI0; + + // Fixed mode + pSPI->SPI_CR = 0x81; //SPI Enable, Sowtware reset + pSPI->SPI_CR = 0x01; //SPI Enable + + //pSPI->SPI_MR = 0xE0019; //Master mode, fixed select, disable decoder, FDIV=1 (MCK), PCS=1110 + pSPI->SPI_MR = 0xE0011; //Master mode, fixed select, disable decoder, FDIV=0 (MCK), PCS=1110 + + //pSPI->SPI_CSR[0] = 0x01010C11; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/32*12 = 125kHz + pSPI->SPI_CSR[0] = 0x01010311; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/8 = 6MHz if using commented MR line above +} + +/** + * @brief Set or clear the lcd reset pin. + * + * @param[in] state TRUE = lcd in reset, FALSE = normal operation + * + * @notapi + */ +static __inline void GDISP_LLD(setpin_reset)(bool_t state) { + if (state) + palClearPad(IOPORT1, PIOA_LCD_RESET); +// pPIOA->PIO_CODR = PIOA_LCD_RESET_MASK; + else + palSetPad(IOPORT1, PIOA_LCD_RESET); +// pPIOA->PIO_SODR = PIOA_LCD_RESET_MASK; +} + +/** + * @brief Set or clear the lcd back-light pin. + * + * @param[in] state TRUE = lcd back-light on, FALSE = lcd back-light off + * + * @notapi + */ +static __inline void GDISP_LLD(setpin_backlight)(bool_t state) { + if (state) + palSetPad(IOPORT2, PIOB_LCD_BL); +// pPIOB->PIO_SODR = PIOB_LCD_BL_MASK; + else + palClearPad(IOPORT2, PIOB_LCD_BL); +// pPIOB->PIO_CODR = PIOB_LCD_BL_MASK; +} + +/** + * @brief Send a 9 bit command/data to the lcd. + * + * @param[in] data The data to send + * + * @notapi + */ +static __inline void GDISP_LLD(write_spi)(uint16_t data) { + // wait for the previous transfer to complete + while((pSPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); + // send the data + pSPI->SPI_TDR = data; +} + +#if GDISP_HARDWARE_READPIXEL || GDISP_HARDWARE_SCROLL || defined(__DOXYGEN__) +/** + * @brief Read data from the lcd. + * + * @return The data from the lcd + * + * @notapi + */ +static __inline uint16_t GDISP_LLD(read_spi)(void) { + #error "gdispNokia6610: GDISP_HARDWARE_READPIXEL and GDISP_HARDWARE_SCROLL are not supported on this board" + return 0; +} +#endif + +#endif /* _GDISP_LLD_BOARD_H */ +/** @} */ diff --git a/drivers/gdisp/gdispNokia6610/gdisp_lld_config.h b/drivers/gdisp/gdispNokia6610/gdisp_lld_config.h new file mode 100644 index 00000000..9e2d1258 --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/gdisp_lld_config.h @@ -0,0 +1,66 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispNokia6610/gdisp_lld_config.h + * @brief GDISP Graphic Driver subsystem low level driver header for the Nokia6610 display. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if HAL_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_DRIVER_NAME "Nokia6610" +#define GDISP_LLD(x) gdisp_lld_##x##_Nokia6610 + +#define GDISP_HARDWARE_LINES FALSE +#define GDISP_HARDWARE_CLEARS FALSE +#define GDISP_HARDWARE_FILLS TRUE +#define GDISP_HARDWARE_BITFILLS TRUE +#define GDISP_HARDWARE_CIRCLES FALSE +#define GDISP_HARDWARE_CIRCLEFILLS FALSE +#define GDISP_HARDWARE_ELLIPSES FALSE +#define GDISP_HARDWARE_ELLIPSEFILLS FALSE +#define GDISP_HARDWARE_TEXT FALSE +#define GDISP_HARDWARE_TEXTFILLS FALSE +#define GDISP_HARDWARE_SCROLL FALSE +#define GDISP_HARDWARE_PIXELREAD FALSE +#define GDISP_HARDWARE_CONTROL FALSE +#define GDISP_HARDWARE_QUERY FALSE + +#define GDISP_SOFTWARE_TEXTFILLDRAW TRUE +#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE + +#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB444 +#define GDISP_PACKED_PIXELS FALSE +#define GDISP_PACKED_LINES FALSE + +#endif /* HAL_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/gdisp/gdispNokia6610/readme.txt b/drivers/gdisp/gdispNokia6610/readme.txt new file mode 100644 index 00000000..facb400f --- /dev/null +++ b/drivers/gdisp/gdispNokia6610/readme.txt @@ -0,0 +1,17 @@ +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_GDISP TRUE + b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD + c) One (only) of: + #define LCD_USE_GE8 /* The Epson controller */ + #define LCD_USE_GE12 /* The Philips controller */ + d) If you are not using a known board then create a gdisp_lld_board.h file + and ensure it is on your include path. + Use the gdisp_lld_board_example.h file as a basis. + Currently known boards are: + Olimex SAM7-EX256 + +2. To your makefile add the following lines: + include $(CHIBIOS)/os/halext/halext.mk + include $(CHIBIOS)/os/halext/drivers/gdispXXXXX/gdisp_lld.mk diff --git a/drivers/gdisp/gdispS6d1121/gdisp_lld.c b/drivers/gdisp/gdispS6d1121/gdisp_lld.c new file mode 100644 index 00000000..5811a6ed --- /dev/null +++ b/drivers/gdisp/gdispS6d1121/gdisp_lld.c @@ -0,0 +1,688 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispS6d1121/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the S6d1121 display. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gdisp.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +/* Include the emulation code for things we don't support */ +#include "gdisp_emulation.c" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +#include "s6d1121_lld.c.h" + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ +/* + The following 2 routines are required. + All other routines are optional. +*/ + +/** + * @brief Low level GDISP driver initialization. + * + * @notapi + */ +bool_t GDISP_LLD(init)(void) { + palSetPadMode(LCD_RST_GPIO, LCD_RST_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + // A Good idea to reset the module before using + LCD_RST_LOW; + s6d1121_delay(2); + LCD_RST_HIGH; // Hardware Reset + s6d1121_delay(2); + + #ifdef LCD_USE_GPIO + // IO Default Configurations + palSetPadMode(LCD_CS_GPIO, LCD_CS_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + palSetPadMode(LCD_WR_GPIO, LCD_WR_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + palSetPadMode(LCD_RD_GPIO, LCD_RD_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + palSetPadMode(LCD_RS_GPIO, LCD_RS_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + palSetPadMode(LCD_BL_GPIO, LCD_BL_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + + palSetGroupMode(LCD_D0_GPIO, 0x0000000F, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + palSetGroupMode(LCD_D4_GPIO, 0x0000FFF0, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); + + LCD_CS_HIGH; + LCD_RD_HIGH; + LCD_WR_HIGH; + LCD_BL_LOW; + + #elif defined(LCD_USE_FSMC) + #if defined(STM32F1XX) + /* FSMC setup. TODO: this only works for STM32F1 */ + rccEnableAHB(RCC_AHBENR_FSMCEN, 0); + + /* TODO: pin setup */ + #elif defined(STM32F4XX) + /* STM32F4 FSMC init */ + rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0); + + /* set pins to FSMC mode */ + IOBus busD = {GPIOD, (1 << 0) | (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) | + (1 << 9) | (1 << 10) | (1 << 11) | (1 << 14) | (1 << 15), 0}; + + IOBus busE = {GPIOE, (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) | + (1 << 13) | (1 << 14) | (1 << 15), 0}; + + palSetBusMode(&busD, PAL_MODE_ALTERNATE(12)); + palSetBusMode(&busE, PAL_MODE_ALTERNATE(12)); + #else + #error "FSMC not implemented for this device" + #endif + + int FSMC_Bank = 0; + /* FSMC timing */ + FSMC_Bank1->BTCR[FSMC_Bank+1] = (10) | (10 << 8) | (10 << 16); + + /* Bank1 NOR/SRAM control register configuration */ + FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN; + #endif + + lld_lcdWriteReg(0x11,0x2004); + lld_lcdWriteReg(0x13,0xCC00); + lld_lcdWriteReg(0x15,0x2600); + lld_lcdWriteReg(0x14,0x252A); + lld_lcdWriteReg(0x12,0x0033); + lld_lcdWriteReg(0x13,0xCC04); + + s6d1121_delay(1); + + lld_lcdWriteReg(0x13,0xCC06); + + s6d1121_delay(1); + + lld_lcdWriteReg(0x13,0xCC4F); + + s6d1121_delay(1); + + lld_lcdWriteReg(0x13,0x674F); + lld_lcdWriteReg(0x11,0x2003); + + s6d1121_delay(1); + + // Gamma Setting + lld_lcdWriteReg(0x30,0x2609); + lld_lcdWriteReg(0x31,0x242C); + lld_lcdWriteReg(0x32,0x1F23); + lld_lcdWriteReg(0x33,0x2425); + lld_lcdWriteReg(0x34,0x2226); + lld_lcdWriteReg(0x35,0x2523); + lld_lcdWriteReg(0x36,0x1C1A); + lld_lcdWriteReg(0x37,0x131D); + lld_lcdWriteReg(0x38,0x0B11); + lld_lcdWriteReg(0x39,0x1210); + lld_lcdWriteReg(0x3A,0x1315); + lld_lcdWriteReg(0x3B,0x3619); + lld_lcdWriteReg(0x3C,0x0D00); + lld_lcdWriteReg(0x3D,0x000D); + + lld_lcdWriteReg(0x16,0x0007); + lld_lcdWriteReg(0x02,0x0013); + lld_lcdWriteReg(0x03,0x0003); + lld_lcdWriteReg(0x01,0x0127); + + s6d1121_delay(1); + + lld_lcdWriteReg(0x08,0x0303); + lld_lcdWriteReg(0x0A,0x000B); + lld_lcdWriteReg(0x0B,0x0003); + lld_lcdWriteReg(0x0C,0x0000); + lld_lcdWriteReg(0x41,0x0000); + lld_lcdWriteReg(0x50,0x0000); + lld_lcdWriteReg(0x60,0x0005); + lld_lcdWriteReg(0x70,0x000B); + lld_lcdWriteReg(0x71,0x0000); + lld_lcdWriteReg(0x78,0x0000); + lld_lcdWriteReg(0x7A,0x0000); + lld_lcdWriteReg(0x79,0x0007); + lld_lcdWriteReg(0x07,0x0051); + + s6d1121_delay(1); + + lld_lcdWriteReg(0x07,0x0053); + lld_lcdWriteReg(0x79,0x0000); + + lld_lcdResetViewPort(); + + /* Now initialise the GDISP structure */ + GDISP.Width = SCREEN_WIDTH; + GDISP.Height = SCREEN_HEIGHT; + GDISP.Orientation = portrait; + GDISP.Powermode = powerOn; + GDISP.Backlight = 100; + GDISP.Contrast = 50; + return TRUE; +} + +/** + * @brief Draws a pixel on the display. + * + * @param[in] x X location of the pixel + * @param[in] y Y location of the pixel + * @param[in] color The color of the pixel + * + * @notapi + */ +void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { + #if GDISP_NEED_VALIDATION + if (x >= GDISP.Width || y >= GDISP.Height) return; + #endif + lld_lcdSetCursor(x, y); + lld_lcdWriteReg(0x0022, color); +} + +/* ---- Optional Routines ---- */ +/* + All the below routines are optional. + Defining them will increase speed but everything + will work if they are not defined. + If you are not using a routine - turn it off using + the appropriate GDISP_HARDWARE_XXXX macro. + Don't bother coding for obvious similar routines if + there is no performance penalty as the emulation software + makes a good job of using similar routines. + eg. If fillarea() is defined there is little + point in defining clear() unless the + performance bonus is significant. + For good performance it is suggested to implement + fillarea() and blitarea(). +*/ + +#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__) + /** + * @brief Clear the display. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] color The color of the pixel + * + * @notapi + */ + void GDISP_LLD(clear)(color_t color) { + unsigned i; + + lld_lcdSetCursor(0, 0); + lld_lcdWriteStreamStart(); + + for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) + lld_lcdWriteData(color); + + lld_lcdWriteStreamStop(); + } +#endif + +#if GDISP_HARDWARE_LINES || defined(__DOXYGEN__) + /** + * @brief Draw a line. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x0, y0 The start of the line + * @param[in] x1, y1 The end of the line + * @param[in] color The color of the line + * + * @notapi + */ + void GDISP_LLD(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { + #if GDISP_NEED_VALIDATION + /* Need to clip to screen */ + #endif + /* Code here */ + } +#endif + +#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a color. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] color The color of the fill + * + * @notapi + */ + void GDISP_LLD(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) cx = GDISP.Width - x; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + unsigned i, area; + + area = cx*cy; + lld_lcdSetViewPort(x, y, cx, cy); + lld_lcdWriteStreamStart(); + for(i = 0; i < area; i++) + lld_lcdWriteData(color); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a bitmap. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] buffer The pixels to use to fill the area. + * + * @notapi + */ + void GDISP_LLD(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer) { + unsigned i, area; + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) return; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + area = cx*cy; + lld_lcdSetViewPort(x, y, cx, cy); + lld_lcdWriteStreamStart(); + for(i = 0; i < area; i++) + lld_lcdWriteData(*buffer++); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +/* Circular Drawing Functions */ +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLES) || defined(__DOXYGEN__) + /** + * @brief Draw a circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSES) || defined(__DOXYGEN__) + /** + * @brief Draw an ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + #include "gdisp_fonts.h" +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a transparent background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * + * @notapi + */ + void GDISP_LLD(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXTFILLS) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a filled background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * @param[in] bgcolor The background color + * + * @notapi + */ + void GDISP_LLD(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { + #if GDISP_NEED_VALIDATION + /* Code here */ + #endif + /* Code here */ + } +#endif + +#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__) + /** + * @brief Get the color of a particular pixel. + * @note Optional. + * @note If x,y is off the screen, the result is undefined. + * + * @param[in] x, y The start of the text + * + * @notapi + */ + color_t GDISP_LLD(getpixelcolor)(coord_t x, coord_t y) { + /* This routine is marked "DO NOT USE" in the original + * GLCD driver. We just keep our GDISP_HARDWARE_READPIXEL + * turned off for now. + */ + color_t color; + + #if GDISP_NEED_VALIDATION + if (x >= GDISP.Width || y >= GDISP.Height) return 0; + #endif + + lld_lcdSetCursor(x, y); + lld_lcdWriteStreamStart(); + + color = lld_lcdReadData(); + color = lld_lcdReadData(); + + lld_lcdWriteStreamStop(); + + return color; + } +#endif + +#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL) || defined(__DOXYGEN__) + /** + * @brief Scroll vertically a section of the screen. + * @note Optional. + * @note If x,y + cx,cy is off the screen, the result is undefined. + * @note If lines is >= cy, it is equivelent to a area fill with bgcolor. + * + * @param[in] x, y The start of the area to be scrolled + * @param[in] cx, cy The size of the area to be scrolled + * @param[in] lines The number of lines to scroll (Can be positive or negative) + * @param[in] bgcolor The color to fill the newly exposed area. + * + * @notapi + */ + void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { + /* This is marked as "TODO: Test this" in the original GLCD driver. + * For now we just leave the GDISP_HARDWARE_SCROLL off. + */ + static color_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)]; + coord_t row0, row1; + unsigned i, gap, abslines; + + abslines = lines < 0 ? -lines : lines; + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) cx = GDISP.Width - x; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + if (!abslines) return; + if (abslines >= cy) { + abslines = cy; + gap = 0; + } else { + gap = cy - abslines; + for(i = 0; i < gap; i++) { + if(lines > 0) { + row0 = y + i + lines; + row1 = y + i; + } else { + row0 = (y - i - 1) + lines; + row1 = (y - i - 1); + } + + /* read row0 into the buffer and then write at row1*/ + lld_lcdSetViewPort(x, row0, cx, 1); + lld_lcdReadStreamStart(); + lld_lcdReadStream(buf, cx); + lld_lcdReadStreamStop(); + + lld_lcdSetViewPort(x, row1, cx, 1); + lld_lcdWriteStreamStart(); + lld_lcdWriteStream(buf, cx); + lld_lcdWriteStreamStop(); + } + } + + /* fill the remaining gap */ + lld_lcdSetViewPort(x, lines > 0 ? (y+gap) : y, cx, abslines); + lld_lcdWriteStreamStart(); + gap = cx*abslines; + for(i = 0; i < gap; i++) lld_lcdWriteData(bgcolor); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__) + /** + * @brief Driver Control + * @detail Unsupported control codes are ignored. + * @note The value parameter should always be typecast to (void *). + * @note There are some predefined and some specific to the low level driver. + * @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t + * GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t + * GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver + * that only supports off/on anything other + * than zero is on. + * GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100. + * GDISP_CONTROL_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to do. + * @param[in] value The value to use (always cast to a void *). + * + * @notapi + */ + void GDISP_LLD(control)(unsigned what, void *value) { + switch(what) { + case GDISP_CONTROL_POWER: + if (GDISP.Powermode == (gdisp_powermode_t)value) + return; + switch((gdisp_powermode_t)value) { + case powerOff: + /* Code here */ + /* break; */ + case powerOn: + /* Code here */ + /* You may need this --- + if (GDISP.Powermode != powerSleep) + GDISP_LLD(init(); + */ + /* break; */ + case powerSleep: + /* Code here */ + /* break; */ + default: + return; + } + GDISP.Powermode = (gdisp_powermode_t)value; + return; + case GDISP_CONTROL_ORIENTATION: + if (GDISP.Orientation == (gdisp_orientation_t)value) + return; + switch((gdisp_orientation_t)value) { + case portrait: + lld_lcdWriteReg(0x0001,0x0127); + lld_lcdWriteReg(0x03, 0b0011); + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscape: + lld_lcdWriteReg(0x0001,0x0027); + lld_lcdWriteReg(0x0003, 0b1011); + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + case portraitInv: + lld_lcdWriteReg(0x0001,0x0127); + lld_lcdWriteReg(0x0003, 0b0000); + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscapeInv: + lld_lcdWriteReg(0x0001,0x0027); + lld_lcdWriteReg(0x0003, 0b1000); + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + default: + return; + } + GDISP.Orientation = (gdisp_orientation_t)value; + return; +/* + case GDISP_CONTROL_BACKLIGHT: + case GDISP_CONTROL_CONTRAST: +*/ + } + } +#endif + +#if (GDISP_NEED_QUERY && GDISP_HARDWARE_QUERY) || defined(__DOXYGEN__) +/** + * @brief Query a driver value. + * @detail Typecase the result to the type you want. + * @note GDISP_QUERY_WIDTH - (coord_t) Gets the width of the screen + * GDISP_QUERY_HEIGHT - (coord_t) Gets the height of the screen + * GDISP_QUERY_POWER - (gdisp_powermode_t) Get the current powermode + * GDISP_QUERY_ORIENTATION - (gdisp_orientation_t) Get the current screen orientation + * GDISP_QUERY_BACKLIGHT - (coord_t) Get the backlight state (0 to 100) + * GDISP_QUERY_CONTRAST - (coord_t) Get the contrast (0 to 100). + * GDISP_QUERY_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to Query + * + * @notapi + */ +void *GDISP_LLD(query)(unsigned what) { + switch(what) { + case GDISP_QUERY_WIDTH: return (void *)(unsigned)GDISP.Width; + case GDISP_QUERY_HEIGHT: return (void *)(unsigned)GDISP.Height; + case GDISP_QUERY_POWER: return (void *)(unsigned)GDISP.Powermode; + case GDISP_QUERY_ORIENTATION: return (void *)(unsigned)GDISP.Orientation; + case GDISP_QUERY_BACKLIGHT: return (void *)(unsigned)GDISP.Backlight; + case GDISP_QUERY_CONTRAST: return (void *)(unsigned)GDISP.Contrast; + case GDISP_QUERY_LLD+0: + /* Code here */ + default: return (void *)-1; + } +} +#endif + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispS6d1121/gdisp_lld.mk b/drivers/gdisp/gdispS6d1121/gdisp_lld.mk new file mode 100644 index 00000000..1f9f093a --- /dev/null +++ b/drivers/gdisp/gdispS6d1121/gdisp_lld.mk @@ -0,0 +1,5 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/gdisp/gdispS6d1121/gdisp_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/gdisp/gdispS6d1121 diff --git a/drivers/gdisp/gdispS6d1121/gdisp_lld_config.h b/drivers/gdisp/gdispS6d1121/gdisp_lld_config.h new file mode 100644 index 00000000..ee3fdeee --- /dev/null +++ b/drivers/gdisp/gdispS6d1121/gdisp_lld_config.h @@ -0,0 +1,66 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispS6d1121/gdisp_lld_config.h + * @brief GDISP Graphic Driver subsystem low level driver header for the S6d1121 display. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if HAL_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_DRIVER_NAME "S6d1121" +#define GDISP_LLD(x) gdisp_lld_##x##_S6d1121 + +#define GDISP_HARDWARE_LINES FALSE +#define GDISP_HARDWARE_CLEARS TRUE +#define GDISP_HARDWARE_FILLS TRUE +#define GDISP_HARDWARE_BITFILLS TRUE +#define GDISP_HARDWARE_CIRCLES FALSE +#define GDISP_HARDWARE_CIRCLEFILLS FALSE +#define GDISP_HARDWARE_ELLIPSES FALSE +#define GDISP_HARDWARE_ELLIPSEFILLS FALSE +#define GDISP_HARDWARE_TEXT FALSE +#define GDISP_HARDWARE_TEXTFILLS FALSE +#define GDISP_HARDWARE_SCROLL TRUE +#define GDISP_HARDWARE_PIXELREAD FALSE +#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_HARDWARE_QUERY FALSE + +#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE +#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE + +#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +#define GDISP_PACKED_PIXELS FALSE +#define GDISP_PACKED_LINES FALSE + +#endif /* HAL_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/gdisp/gdispS6d1121/readme.txt b/drivers/gdisp/gdispS6d1121/readme.txt new file mode 100644 index 00000000..fc24d4a2 --- /dev/null +++ b/drivers/gdisp/gdispS6d1121/readme.txt @@ -0,0 +1,16 @@ +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_GDISP TRUE + b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD + c) One (only) of: + #define LCD_USE_GPIO + #define LCD_USE_SPI + #define LCD_USE_FSMC + d) All of the following (with appropriate values): + #define SCREEN_WIDTH 320 + #define SCREEN_HEIGHT 240 + +2. To your makefile add the following lines: + include $(CHIBIOS)/os/halext/halext.mk + include $(CHIBIOS)/os/halext/drivers/gdispS6d1121/gdisp_lld.mk diff --git a/drivers/gdisp/gdispS6d1121/s6d1121_lld.c.h b/drivers/gdisp/gdispS6d1121/s6d1121_lld.c.h new file mode 100644 index 00000000..c1539fe7 --- /dev/null +++ b/drivers/gdisp/gdispS6d1121/s6d1121_lld.c.h @@ -0,0 +1,244 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +#ifndef S6D1121_H +#define S6D1121_H + +// I/O assignments +#define LCD_BL_GPIO GPIOB +#define LCD_BL_PIN 8 + +#define LCD_CS_GPIO GPIOD +#define LCD_CS_PIN 7 + +#define LCD_RS_GPIO GPIOD +#define LCD_RS_PIN 11 + +#define LCD_RST_GPIO GPIOD +#define LCD_RST_PIN 10 + +#define LCD_RD_GPIO GPIOD +#define LCD_RD_PIN 9 + +#define LCD_WR_GPIO GPIOD +#define LCD_WR_PIN 8 + +#define LCD_D0_GPIO GPIOD +#define LCD_D4_GPIO GPIOE + +/* all interfaces use RST via GPIO */ +/* TODO: option to disable RST; assumes RST is tied high */ +#define LCD_RST_LOW palClearPad(LCD_RST_GPIO, LCD_RST_PIN) +#define LCD_RST_HIGH palSetPad(LCD_RST_GPIO, LCD_RST_PIN) + +#define s6d1121_delay(n) halPolledDelay(MS2RTT(n)); + +#if defined(LCD_USE_GPIO) + + #define LCD_CS_LOW palClearPad(LCD_CS_GPIO, LCD_CS_PIN) + #define LCD_CS_HIGH palSetPad(LCD_CS_GPIO, LCD_CS_PIN) + + #define LCD_RS_LOW palClearPad(LCD_RS_GPIO, LCD_RS_PIN) + #define LCD_RS_HIGH palSetPad(LCD_RS_GPIO, LCD_RS_PIN) + + #define LCD_RD_LOW palClearPad(LCD_RD_GPIO, LCD_RD_PIN) + #define LCD_RD_HIGH palSetPad(LCD_RD_GPIO, LCD_RD_PIN) + + #define LCD_WR_LOW palClearPad(LCD_WR_GPIO, LCD_WR_PIN) + #define LCD_WR_HIGH palSetPad(LCD_WR_GPIO, LCD_WR_PIN) + + #define LCD_BL_LOW palClearPad(LCD_BL_GPIO, LCD_BL_PIN) + #define LCD_BL_HIGH palSetPad(LCD_BL_GPIO, LCD_BL_PIN) + + + static inline void lld_lcddelay(void) { asm volatile ("nop"); asm volatile ("nop"); } + static inline void lld_lcdwrite(uint16_t db) { + LCD_D4_GPIO->BSRR.W=((~db&0xFFF0)<<16)|(db&0xFFF0); + LCD_D0_GPIO->BSRR.W=((~db&0x000F)<<16)|(db&0x000F); + LCD_WR_LOW; + lld_lcddelay(); + LCD_WR_HIGH; + } + static __inline uint16_t lld_lcdReadData(void) { + uint16_t value=0; + + LCD_RS_HIGH; LCD_WR_HIGH; LCD_RD_LOW; + #ifndef STM32F4XX + // change pin mode to digital input + LCD_DATA_PORT->CRH = 0x47444444; + LCD_DATA_PORT->CRL = 0x47444444; + #endif + #ifndef STM32F4XX + // change pin mode back to digital output + LCD_DATA_PORT->CRH = 0x33333333; + LCD_DATA_PORT->CRL = 0x33333333; + #endif + LCD_RD_HIGH; + return value; + } + static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { + uint16_t lcdRAM; + + LCD_CS_LOW; LCD_RS_LOW; + lld_lcdwrite(lcdReg); + LCD_RS_HIGH; + lcdRAM = lld_lcdReadData(); + LCD_CS_HIGH; + return lcdRAM; + } + static void lld_lcdWriteIndex(uint16_t lcdReg) { + LCD_RS_LOW; + lld_lcdwrite(lcdReg); + LCD_RS_HIGH; + } + static void lld_lcdWriteData(uint16_t lcdData) { + lld_lcdwrite(lcdData); + } + static void lld_lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue) { + LCD_CS_LOW; + lld_lcdWriteIndex(lcdReg); + lld_lcdWriteData(lcdRegValue); + LCD_CS_HIGH; + } + static __inline void lld_lcdWriteStreamStart(void) { + LCD_CS_LOW; + lld_lcdWriteIndex(0x0022); + } + static __inline void lld_lcdWriteStreamStop(void) { + LCD_CS_HIGH; + } + static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { + uint16_t i; + + for(i = 0; i < size; i++) { lld_lcdwrite(buffer[i]); } + } + static __inline void lld_lcdReadStreamStart(void) { /* TODO */ } + static __inline void lld_lcdReadStreamStop(void) { /* TODO */ } + static __inline void lld_lcdReadStream(uint16_t *UNUSED(buffer), size_t UNUSED(size)) { /* TODO */ } + +#elif defined(LCD_USE_FSMC) + #define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */ + #define LCD_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */ + + static __inline void lld_lcdWriteIndex(uint16_t index) { LCD_REG = index; } + static __inline void lld_lcdWriteData(uint16_t data) { LCD_RAM = data; } + static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) { + LCD_REG = lcdReg; + LCD_RAM = lcdRegValue; + } + static __inline uint16_t lld_lcdReadData(void) { return (LCD_RAM); } + static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { + LCD_REG = lcdReg; + return LCD_RAM; + } + static __inline void lld_lcdWriteStreamStart(void) { LCD_REG = 0x0022; } + static __inline void lld_lcdWriteStreamStop(void) {} + static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { + uint16_t i; + for(i = 0; i < size; i++) LCD_RAM = buffer[i]; + } + static __inline void lld_lcdReadStreamStart(void) { LCD_REG = 0x0022; } + static __inline void lld_lcdReadStreamStop(void) {} + static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) { + uint16_t i; + volatile uint16_t dummy; + + /* throw away first value read */ + dummy = LCD_RAM; + for(i = 0; i < size; i++) buffer[i] = LCD_RAM; + } + +#elif defined(LCD_USE_SPI) + #error "gdispS6d1121: LCD_USE_SPI not implemented yet" + +#else + #error "gdispS6d1121: No known LCD_USE_XXX has been defined" +#endif + +static void lld_lcdSetCursor(coord_t x, coord_t y) { + /* R20h - 8 bit + * R21h - 9 bit + */ + switch(GDISP.Orientation) { + case portraitInv: + lld_lcdWriteReg(0x0020, (SCREEN_WIDTH-1-x) & 0x00FF); + lld_lcdWriteReg(0x0021, (SCREEN_HEIGHT-1-y) & 0x01FF); + break; + case portrait: + lld_lcdWriteReg(0x0020, x & 0x00FF); + lld_lcdWriteReg(0x0021, y & 0x01FF); + break; + case landscape: + lld_lcdWriteReg(0x0020, y & 0x00FF); + lld_lcdWriteReg(0x0021, x & 0x01FF); + break; + case landscapeInv: + lld_lcdWriteReg(0x0020, (SCREEN_WIDTH - y - 1) & 0x00FF); + lld_lcdWriteReg(0x0021, (SCREEN_HEIGHT - x - 1) & 0x01FF); + break; + } +} + +static void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) { + /* HSA / HEA are 8 bit + * VSA / VEA are 9 bit + * use masks 0x00FF and 0x01FF to enforce this + */ + + switch(GDISP.Orientation) { + case portrait: + lld_lcdWriteReg(0x46, (((x+cx-1) << 8) & 0xFF00 ) | (x & 0x00FF)); + lld_lcdWriteReg(0x48, y & 0x01FF); + lld_lcdWriteReg(0x47, (y+cy-1) & 0x01FF); + break; + case landscape: + lld_lcdWriteReg(0x46, (((x+cx-1) << 8) & 0xFF00) | ((y+cy) & 0x00FF)); + lld_lcdWriteReg(0x48, x & 0x01FF); + lld_lcdWriteReg(0x47, (x+cx-1) & 0x01FF); + break; + case portraitInv: + lld_lcdWriteReg(0x46, (((SCREEN_WIDTH-x-1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (x+cx)) & 0x00FF)); + lld_lcdWriteReg(0x48, (SCREEN_HEIGHT-(y+cy)) & 0x01FF); + lld_lcdWriteReg(0x47, (SCREEN_HEIGHT-y-1) & 0x01FF); + break; + case landscapeInv: + lld_lcdWriteReg(0x46, (((SCREEN_WIDTH - y - 1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (y+cy)) & 0x00FF)); + lld_lcdWriteReg(0x48, (SCREEN_HEIGHT - (x+cx)) & 0x01FF); + lld_lcdWriteReg(0x47, (SCREEN_HEIGHT - x - 1) & 0x01FF); + break; + } + + lld_lcdSetCursor(x, y); +} + +static void lld_lcdResetViewPort(void) { + switch(GDISP.Orientation) { + case portrait: + case portraitInv: + lld_lcdSetViewPort(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + break; + case landscape: + case landscapeInv: + lld_lcdSetViewPort(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH); + break; + } +} + +#endif /* S6D1121_H */ diff --git a/drivers/gdisp/gdispSsd1289/gdisp_lld.c b/drivers/gdisp/gdispSsd1289/gdisp_lld.c new file mode 100644 index 00000000..7dfb83a7 --- /dev/null +++ b/drivers/gdisp/gdispSsd1289/gdisp_lld.c @@ -0,0 +1,610 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispSsd1289/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the Ssd1289 display. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gdisp.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +/* Include the emulation code for things we don't support */ +#include "gdisp_emulation.c" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +#include "ssd1289_lld.c.h" + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ +/* + The following 2 routines are required. + All other routines are optional. +*/ + +/** + * @brief Low level GDISP driver initialization. + * + * @notapi + */ +bool_t GDISP_LLD(init)(void) { + uint16_t deviceCode; + + #ifdef LCD_USE_FSMC + /* FSMC setup. TODO: this only works for STM32F1 */ + rccEnableAHB(RCC_AHBENR_FSMCEN, 0); + int FSMC_Bank = 0; + /* timing structure */ + /* from datasheet: + address setup: 0ns + address hold: 0ns + Data setup: 5ns + Data hold: 5ns + Data access: 250ns + output hold: 100ns + */ + FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_1 | FSMC_BTR1_DATAST_1; + + /* Bank1 NOR/SRAM control register configuration */ + FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN; + #endif + + deviceCode = lld_lcdReadReg(0x0000); + + lld_lcdWriteReg(0x0000,0x0001); lld_lcdDelay(5); + lld_lcdWriteReg(0x0003,0xA8A4); lld_lcdDelay(5); + lld_lcdWriteReg(0x000C,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x000D,0x080C); lld_lcdDelay(5); + lld_lcdWriteReg(0x000E,0x2B00); lld_lcdDelay(5); + lld_lcdWriteReg(0x001E,0x00B0); lld_lcdDelay(5); + lld_lcdWriteReg(0x0001,0x2B3F); lld_lcdDelay(5); + lld_lcdWriteReg(0x0002,0x0600); lld_lcdDelay(5); + lld_lcdWriteReg(0x0010,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0011,0x6070); lld_lcdDelay(5); + lld_lcdWriteReg(0x0005,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0006,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0016,0xEF1C); lld_lcdDelay(5); + lld_lcdWriteReg(0x0017,0x0003); lld_lcdDelay(5); + lld_lcdWriteReg(0x0007,0x0133); lld_lcdDelay(5); + lld_lcdWriteReg(0x000B,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x000F,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0041,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0042,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0048,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0049,0x013F); lld_lcdDelay(5); + lld_lcdWriteReg(0x004A,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x004B,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0044,0xEF00); lld_lcdDelay(5); + lld_lcdWriteReg(0x0045,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0046,0x013F); lld_lcdDelay(5); + lld_lcdWriteReg(0x0030,0x0707); lld_lcdDelay(5); + lld_lcdWriteReg(0x0031,0x0204); lld_lcdDelay(5); + lld_lcdWriteReg(0x0032,0x0204); lld_lcdDelay(5); + lld_lcdWriteReg(0x0033,0x0502); lld_lcdDelay(5); + lld_lcdWriteReg(0x0034,0x0507); lld_lcdDelay(5); + lld_lcdWriteReg(0x0035,0x0204); lld_lcdDelay(5); + lld_lcdWriteReg(0x0036,0x0204); lld_lcdDelay(5); + lld_lcdWriteReg(0x0037,0x0502); lld_lcdDelay(5); + lld_lcdWriteReg(0x003A,0x0302); lld_lcdDelay(5); + lld_lcdWriteReg(0x003B,0x0302); lld_lcdDelay(5); + lld_lcdWriteReg(0x0023,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0024,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x0025,0x8000); lld_lcdDelay(5); + lld_lcdWriteReg(0x004f,0x0000); lld_lcdDelay(5); + lld_lcdWriteReg(0x004e,0x0000); lld_lcdDelay(5); + + /* Initialise the GDISP structure */ + GDISP.Width = SCREEN_WIDTH; + GDISP.Height = SCREEN_HEIGHT; + GDISP.Orientation = portrait; + GDISP.Powermode = powerOn; + GDISP.Backlight = 100; + GDISP.Contrast = 50; + return TRUE; +} + +/** + * @brief Draws a pixel on the display. + * + * @param[in] x X location of the pixel + * @param[in] y Y location of the pixel + * @param[in] color The color of the pixel + * + * @notapi + */ +void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { + #if GDISP_NEED_VALIDATION + if (x >= GDISP.Width || y >= GDISP.Height) return; + #endif + lld_lcdSetCursor(x, y); + lld_lcdWriteReg(0x0022, color); +} + +/* ---- Optional Routines ---- */ +/* + All the below routines are optional. + Defining them will increase speed but everything + will work if they are not defined. + If you are not using a routine - turn it off using + the appropriate GDISP_HARDWARE_XXXX macro. + Don't bother coding for obvious similar routines if + there is no performance penalty as the emulation software + makes a good job of using similar routines. + eg. If gfillarea() is defined there is little + point in defining clear() unless the + performance bonus is significant. + For good performance it is suggested to implement + fillarea() and blitarea(). +*/ + +#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__) + /** + * @brief Clear the display. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] color The color of the pixel + * + * @notapi + */ + void GDISP_LLD(clear)(color_t color) { + unsigned i; + + lld_lcdSetCursor(0, 0); + lld_lcdWriteStreamStart(); + + for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) + lld_lcdWriteData(color); + + lld_lcdWriteStreamStop(); + } +#endif + +#if GDISP_HARDWARE_LINES || defined(__DOXYGEN__) + /** + * @brief Draw a line. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x0, y0 The start of the line + * @param[in] x1, y1 The end of the line + * @param[in] color The color of the line + * + * @notapi + */ + void GDISP_LLD(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a color. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] color The color of the fill + * + * @notapi + */ + void GDISP_LLD(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) cx = GDISP.Width - x; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + unsigned i, area; + + area = cx*cy; + lld_lcdSetViewPort(x, y, cx, cy); + lld_lcdWriteStreamStart(); + for(i = 0; i < area; i++) + lld_lcdWriteData(color); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a bitmap. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] buffer The pixels to use to fill the area. + * + * @notapi + */ + void GDISP_LLD(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer) { + unsigned i, area; + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) return; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + area = cx*cy; + lld_lcdSetViewPort(x, y, cx, cy); + lld_lcdWriteStreamStart(); + for(i = 0; i < area; i++) + lld_lcdWriteData(*buffer++); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +/* Circular Drawing Functions */ +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLES) || defined(__DOXYGEN__) + /** + * @brief Draw a circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSES) || defined(__DOXYGEN__) + /** + * @brief Draw an ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + #include "gdisp_fonts.h" +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a transparent background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * + * @notapi + */ + void GDISP_LLD(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXTFILLS) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a filled background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * @param[in] bgcolor The background color + * + * @notapi + */ + void GDISP_LLD(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { + /* NOT IMPLEMENTED */ + } +#endif + +#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__) + /** + * @brief Get the color of a particular pixel. + * @note Optional. + * @note If x,y is off the screen, the result is undefined. + * + * @param[in] x, y The start of the text + * + * @notapi + */ + color_t GDISP_LLD(getpixelcolor)(coord_t x, coord_t y) { + color_t color; + + #if GDISP_NEED_VALIDATION + if (x >= GDISP.Width || y >= GDISP.Height) return 0; + #endif + + lld_lcdSetCursor(x, y); + lld_lcdWriteStreamStart(); + + color = lld_lcdReadData(); + color = lld_lcdReadData(); + + lld_lcdWriteStreamStop(); + + return color; + } +#endif + +#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL) || defined(__DOXYGEN__) + /** + * @brief Scroll vertically a section of the screen. + * @note Optional. + * @note If x,y + cx,cy is off the screen, the result is undefined. + * @note If lines is >= cy, it is equivelent to a area fill with bgcolor. + * + * @param[in] x, y The start of the area to be scrolled + * @param[in] cx, cy The size of the area to be scrolled + * @param[in] lines The number of lines to scroll (Can be positive or negative) + * @param[in] bgcolor The color to fill the newly exposed area. + * + * @notapi + */ + void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { + static color_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)]; + coord_t row0, row1; + unsigned i, gap, abslines; + + abslines = lines < 0 ? -lines : lines; + + #if GDISP_NEED_VALIDATION + if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return; + if (x+cx > GDISP.Width) cx = GDISP.Width - x; + if (y+cy > GDISP.Height) cy = GDISP.Height - y; + #endif + + if (!abslines) return; + if (abslines >= cy) { + abslines = cy; + gap = 0; + } else { + gap = cy - abslines; + for(i = 0; i < gap; i++) { + if(lines > 0) { + row0 = y + i + lines; + row1 = y + i; + } else { + row0 = (y - i - 1) + lines; + row1 = (y - i - 1); + } + + /* read row0 into the buffer and then write at row1*/ + lld_lcdSetViewPort(x, row0, cx, 1); + lld_lcdReadStreamStart(); + lld_lcdReadStream(buf, cx); + lld_lcdReadStreamStop(); + + lld_lcdSetViewPort(x, row1, cx, 1); + lld_lcdWriteStreamStart(); + lld_lcdWriteStream(buf, cx); + lld_lcdWriteStreamStop(); + } + } + + /* fill the remaining gap */ + lld_lcdSetViewPort(x, lines > 0 ? (y+gap) : y, cx, abslines); + lld_lcdWriteStreamStart(); + gap = cx*abslines; + for(i = 0; i < gap; i++) lld_lcdWriteData(color); + lld_lcdWriteStreamStop(); + lld_lcdResetViewPort(); + } +#endif + +#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__) + /** + * @brief Driver Control + * @detail Unsupported control codes are ignored. + * @note The value parameter should always be typecast to (void *). + * @note There are some predefined and some specific to the low level driver. + * @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t + * GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t + * GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver + * that only supports off/on anything other + * than zero is on. + * GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100. + * GDISP_CONTROL_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to do. + * @param[in] value The value to use (always cast to a void *). + * + * @notapi + */ + void GDISP_LLD(control)(unsigned what, void *value) { + switch(what) { + case GDISP_CONTROL_POWER: + if (GDISP.Powermode == (gdisp_powermode_t)value) + return; + switch((gdisp_powermode_t)value) { + case powerOff: + lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode + lld_lcdWriteReg(0x0007, 0x0000); // halt operation + lld_lcdWriteReg(0x0000, 0x0000); // turn off oszillator + lld_lcdWriteReg(0x0010, 0x0001); // enter sleepmode + break; + case powerOn: + lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode + if (GDISP.Powermode != powerSleep) + GDISP_LLD(init)(); + break; + case powerSleep: + lld_lcdWriteReg(0x0010, 0x0001); // enter sleep mode + break; + default: + return; + } + GDISP.Powermode = (gdisp_powermode_t)value; + return; + case GDISP_CONTROL_ORIENTATION: + if (GDISP.Orientation == (gdisp_orientation_t)value) + return; + switch((gdisp_orientation_t)value) { + case portrait: + lld_lcdWriteReg(0x0001, 0x2B3F); + /* ID = 11 AM = 0 */ + lld_lcdWriteReg(0x0011, 0x6070); + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscape: + lld_lcdWriteReg(0x0001, 0x293F); + /* ID = 11 AM = 1 */ + lld_lcdWriteReg(0x0011, 0x6078); + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + case portraitInv: + lld_lcdWriteReg(0x0001, 0x2B3F); + /* ID = 01 AM = 0 */ + lld_lcdWriteReg(0x0011, 0x6040); + GDISP.Height = SCREEN_HEIGHT; + GDISP.Width = SCREEN_WIDTH; + break; + case landscapeInv: + lld_lcdWriteReg(0x0001, 0x293F); + /* ID = 01 AM = 1 */ + lld_lcdWriteReg(0x0011, 0x6048); + GDISP.Height = SCREEN_WIDTH; + GDISP.Width = SCREEN_HEIGHT; + break; + default: + return; + } + GDISP.Orientation = (gdisp_orientation_t)value; + return; +/* + case GDISP_CONTROL_BACKLIGHT: + case GDISP_CONTROL_CONTRAST: +*/ + } + } +#endif + +#if (GDISP_NEED_QUERY && GDISP_HARDWARE_QUERY) || defined(__DOXYGEN__) +/** + * @brief Query a driver value. + * @detail Typecase the result to the type you want. + * @note GDISP_QUERY_WIDTH - (coord_t) Gets the width of the screen + * GDISP_QUERY_HEIGHT - (coord_t) Gets the height of the screen + * GDISP_QUERY_POWER - (gdisp_powermode_t) Get the current powermode + * GDISP_QUERY_ORIENTATION - (gdisp_orientation_t) Get the current screen orientation + * GDISP_QUERY_BACKLIGHT - (coord_t) Get the backlight state (0 to 100) + * GDISP_QUERY_CONTRAST - (coord_t) Get the contrast (0 to 100). + * GDISP_QUERY_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to Query + * + * @notapi + */ +void *GDISP_LLD(query)(unsigned what) { + switch(what) { + case GDISP_QUERY_WIDTH: return (void *)(unsigned)GDISP.Width; + case GDISP_QUERY_HEIGHT: return (void *)(unsigned)GDISP.Height; + case GDISP_QUERY_POWER: return (void *)(unsigned)GDISP.Powermode; + case GDISP_QUERY_ORIENTATION: return (void *)(unsigned)GDISP.Orientation; + case GDISP_QUERY_BACKLIGHT: return (void *)(unsigned)GDISP.Backlight; + case GDISP_QUERY_CONTRAST: return (void *)(unsigned)GDISP.Contrast; + case GDISP_QUERY_LLD+0: + /* Code here */ + default: return (void *)-1; + } +} +#endif + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispSsd1289/gdisp_lld.mk b/drivers/gdisp/gdispSsd1289/gdisp_lld.mk new file mode 100644 index 00000000..8167cbfb --- /dev/null +++ b/drivers/gdisp/gdispSsd1289/gdisp_lld.mk @@ -0,0 +1,5 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/gdisp/gdispSsd1289/gdisp_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/gdisp/gdispSsd1289 diff --git a/drivers/gdisp/gdispSsd1289/gdisp_lld_config.h b/drivers/gdisp/gdispSsd1289/gdisp_lld_config.h new file mode 100644 index 00000000..123ce875 --- /dev/null +++ b/drivers/gdisp/gdispSsd1289/gdisp_lld_config.h @@ -0,0 +1,66 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispSsd1289/gdisp_lld_config.h + * @brief GDISP Graphic Driver subsystem low level driver header for the Ssd1289 display. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if HAL_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_DRIVER_NAME "SSD1289" +#define GDISP_LLD(x) gdisp_lld_##x##_SSD1289 + +#define GDISP_HARDWARE_LINES FALSE +#define GDISP_HARDWARE_CLEARS TRUE +#define GDISP_HARDWARE_FILLS TRUE +#define GDISP_HARDWARE_BITFILLS TRUE +#define GDISP_HARDWARE_CIRCLES FALSE +#define GDISP_HARDWARE_CIRCLEFILLS FALSE +#define GDISP_HARDWARE_ELLIPSES FALSE +#define GDISP_HARDWARE_ELLIPSEFILLS FALSE +#define GDISP_HARDWARE_TEXT FALSE +#define GDISP_HARDWARE_TEXTFILLS FALSE +#define GDISP_HARDWARE_SCROLL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_HARDWARE_QUERY FALSE + +#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE +#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE + +#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +#define GDISP_PACKED_PIXELS FALSE +#define GDISP_PACKED_LINES FALSE + +#endif /* HAL_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/gdisp/gdispSsd1289/readme.txt b/drivers/gdisp/gdispSsd1289/readme.txt new file mode 100644 index 00000000..17d22223 --- /dev/null +++ b/drivers/gdisp/gdispSsd1289/readme.txt @@ -0,0 +1,16 @@ +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_GDISP TRUE + b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD + c) One (only) of: + #define LCD_USE_GPIO + #define LCD_USE_SPI + #define LCD_USE_FSMC + d) All of the following (with appropriate values): + #define SCREEN_WIDTH 320 + #define SCREEN_HEIGHT 240 + +2. To your makefile add the following lines: + include $(CHIBIOS)/os/halext/halext.mk + include $(CHIBIOS)/os/halext/drivers/gdispSsd1289/gdisp_lld.mk diff --git a/drivers/gdisp/gdispSsd1289/ssd1289_lld.c.h b/drivers/gdisp/gdispSsd1289/ssd1289_lld.c.h new file mode 100644 index 00000000..7c0fade2 --- /dev/null +++ b/drivers/gdisp/gdispSsd1289/ssd1289_lld.c.h @@ -0,0 +1,322 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +#ifndef SSD1289_H +#define SSD1289_H + +#if defined(LCD_USE_GPIO) + #define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS); + #define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS); + #define Set_RS palSetPad(LCD_CMD_PORT, LCD_RS); + #define Clr_RS palClearPad(LCD_CMD_PORT, LCD_RS); + #define Set_WR palSetPad(LCD_CMD_PORT, LCD_WR); + #define Clr_WR palClearPad(LCD_CMD_PORT, LCD_WR); + #define Set_RD palSetPad(LCD_CMD_PORT, LCD_RD); + #define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD); + + static __inline void lld_lcdWriteIndex(uint16_t index) { + Clr_RS; Set_RD; + lld_lcdWriteGPIO(index); + Clr_WR; Set_WR; + } + static __inline void lld_lcdWriteData(uint16_t data) { + Set_RS; + lld_lcdWriteGPIO(data); + Clr_WR; Set_WR; + } + static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) { + Clr_CS; + lld_lcdWriteIndex(lcdReg); + lld_lcdWriteData(lcdRegValue); + Set_CS; + } + static __inline uint16_t lld_lcdReadData(void) { + uint16_t value; + + Set_RS; Set_WR; Clr_RD; + value = lld_lcdReadGPIO(); + Set_RD; + return value; + } + static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { + uint16_t value; + + Clr_CS; + lld_lcdWriteIndex(lcdReg); + value = lld_lcdReadData(); + Set_CS; + return value; + } + + static __inline void lld_lcdWriteStreamStart(void) { + Clr_CS; + lld_lcdWriteIndex(0x0022); + } + + static __inline void lld_lcdWriteStreamStop(void) { + Set_CS; + } + + static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { + uint16_t i; + + Set_RS; + for(i = 0; i < size; i++) { lld_lcdWriteGPIO(buffer[i]); Clr_WR; Set_WR; } + } + + static __inline void lld_lcdReadStreamStart(void) { + Clr_CS + lld_lcdWriteIndex(0x0022); + } + + static __inline void lld_lcdReadStreamStop(void) { + Set_CS; + } + + static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) { + uint16_t i; + volatile uint16_t dummy; + + dummy = lld_lcdReadData(); + for(i = 0; i < size; i++) buffer[i] = lld_lcdReadData(); + } + +#elif defined(LCD_USE_FSMC) + /* LCD Registers */ + #define R0 0x00 + #define R1 0x01 + #define R2 0x02 + #define R3 0x03 + #define R4 0x04 + #define R5 0x05 + #define R6 0x06 + #define R7 0x07 + #define R8 0x08 + #define R9 0x09 + #define R10 0x0A + #define R12 0x0C + #define R13 0x0D + #define R14 0x0E + #define R15 0x0F + #define R16 0x10 + #define R17 0x11 + #define R18 0x12 + #define R19 0x13 + #define R20 0x14 + #define R21 0x15 + #define R22 0x16 + #define R23 0x17 + #define R24 0x18 + #define R25 0x19 + #define R26 0x1A + #define R27 0x1B + #define R28 0x1C + #define R29 0x1D + #define R30 0x1E + #define R31 0x1F + #define R32 0x20 + #define R33 0x21 + #define R34 0x22 + #define R36 0x24 + #define R37 0x25 + #define R40 0x28 + #define R41 0x29 + #define R43 0x2B + #define R45 0x2D + #define R48 0x30 + #define R49 0x31 + #define R50 0x32 + #define R51 0x33 + #define R52 0x34 + #define R53 0x35 + #define R54 0x36 + #define R55 0x37 + #define R56 0x38 + #define R57 0x39 + #define R59 0x3B + #define R60 0x3C + #define R61 0x3D + #define R62 0x3E + #define R63 0x3F + #define R64 0x40 + #define R65 0x41 + #define R66 0x42 + #define R67 0x43 + #define R68 0x44 + #define R69 0x45 + #define R70 0x46 + #define R71 0x47 + #define R72 0x48 + #define R73 0x49 + #define R74 0x4A + #define R75 0x4B + #define R76 0x4C + #define R77 0x4D + #define R78 0x4E + #define R79 0x4F + #define R80 0x50 + #define R81 0x51 + #define R82 0x52 + #define R83 0x53 + #define R96 0x60 + #define R97 0x61 + #define R106 0x6A + #define R118 0x76 + #define R128 0x80 + #define R129 0x81 + #define R130 0x82 + #define R131 0x83 + #define R132 0x84 + #define R133 0x85 + #define R134 0x86 + #define R135 0x87 + #define R136 0x88 + #define R137 0x89 + #define R139 0x8B + #define R140 0x8C + #define R141 0x8D + #define R143 0x8F + #define R144 0x90 + #define R145 0x91 + #define R146 0x92 + #define R147 0x93 + #define R148 0x94 + #define R149 0x95 + #define R150 0x96 + #define R151 0x97 + #define R152 0x98 + #define R153 0x99 + #define R154 0x9A + #define R157 0x9D + #define R192 0xC0 + #define R193 0xC1 + #define R229 0xE5 + + #define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */ + #define LCD_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */ + + static __inline void lld_lcdWriteIndex(uint16_t index) { LCD_REG = index; } + static __inline void lld_lcdWriteData(uint16_t data) { LCD_RAM = data; } + static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) { + LCD_REG = lcdReg; + LCD_RAM = lcdRegValue; + } + static __inline uint16_t lld_lcdReadData(void) { return (LCD_RAM); } + static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { + volatile uint16_t dummy; + + LCD_REG = lcdReg; + dummy = LCD_RAM; + return (LCD_RAM); + } + static __inline void lld_lcdWriteStreamStart(void) { LCD_REG = 0x0022; } + static __inline void lld_lcdWriteStreamStop(void) {} + static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { + uint16_t i; + + for(i = 0; i < size; i++) LCD_RAM = buffer[i]; + } + static __inline void lld_lcdReadStreamStart(void) { LCD_REG = 0x0022; } + static __inline void lld_lcdReadStreamStop(void) {} + static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) { + uint16_t i; + volatile uint16_t dummy; + + dummy = LCD_RAM; /* throw away first value read */ + for(i = 0; i < size; i++) buffer[i] = LCD_RAM; + } + +#elif defined(LCD_USE_SPI) + #error "gdispSsd1289: LCD_USE_SPI not implemented yet" + +#else + #error "gdispSsd1289: No known LCD_USE_XXX has been defined" +#endif + +static __inline void lld_lcdDelay(uint16_t us) { + chThdSleepMicroseconds(us); +} + +static void lld_lcdSetCursor(uint16_t x, uint16_t y) { + /* Reg 0x004E is an 8 bit value + * Reg 0x004F is 9 bit + * Use a bit mask to make sure they are not set too high + */ + switch(GDISP.Orientation) { + case portraitInv: + lld_lcdWriteReg(0x004e, (SCREEN_WIDTH-1-x) & 0x00FF); + lld_lcdWriteReg(0x004f, (SCREEN_HEIGHT-1-y) & 0x01FF); + break; + case portrait: + lld_lcdWriteReg(0x004e, x & 0x00FF); + lld_lcdWriteReg(0x004f, y & 0x01FF); + break; + case landscape: + lld_lcdWriteReg(0x004e, y & 0x00FF); + lld_lcdWriteReg(0x004f, x & 0x01FF); + break; + case landscapeInv: + lld_lcdWriteReg(0x004e, (SCREEN_WIDTH - y - 1) & 0x00FF); + lld_lcdWriteReg(0x004f, (SCREEN_HEIGHT - x - 1) & 0x01FF); + break; + } +} + +static void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) { + lld_lcdSetCursor(x, y); + + /* Reg 0x44 - Horizontal RAM address position + * Upper Byte - HEA + * Lower Byte - HSA + * 0 <= HSA <= HEA <= 0xEF + * Reg 0x45,0x46 - Vertical RAM address position + * Lower 9 bits gives 0-511 range in each value + * 0 <= Reg(0x45) <= Reg(0x46) <= 0x13F + */ + + switch(GDISP.Orientation) { + case portrait: + lld_lcdWriteReg(0x44, (((x+cx-1) << 8) & 0xFF00 ) | (x & 0x00FF)); + lld_lcdWriteReg(0x45, y & 0x01FF); + lld_lcdWriteReg(0x46, (y+cy-1) & 0x01FF); + break; + case landscape: + lld_lcdWriteReg(0x44, (((x+cx-1) << 8) & 0xFF00) | ((y+cy) & 0x00FF)); + lld_lcdWriteReg(0x45, x & 0x01FF); + lld_lcdWriteReg(0x46, (x+cx-1) & 0x01FF); + break; + case portraitInv: + lld_lcdWriteReg(0x44, (((SCREEN_WIDTH-x-1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (x+cx)) & 0x00FF)); + lld_lcdWriteReg(0x45, (SCREEN_HEIGHT-(y+cy)) & 0x01FF); + lld_lcdWriteReg(0x46, (SCREEN_HEIGHT-y-1) & 0x01FF); + break; + case landscapeInv: + lld_lcdWriteReg(0x44, (((SCREEN_WIDTH - y - 1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (y+cy)) & 0x00FF)); + lld_lcdWriteReg(0x45, (SCREEN_HEIGHT - (x+cx)) & 0x01FF); + lld_lcdWriteReg(0x46, (SCREEN_HEIGHT - x - 1) & 0x01FF); + break; + } + + lld_lcdSetCursor(x, y); +} + +static __inline void lld_lcdResetViewPort(void) {} + +#endif /* SSD1289_H */ diff --git a/drivers/gdisp/gdispTestStub/gdisp_lld.c b/drivers/gdisp/gdispTestStub/gdisp_lld.c new file mode 100644 index 00000000..fd8410fb --- /dev/null +++ b/drivers/gdisp/gdispTestStub/gdisp_lld.c @@ -0,0 +1,361 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispTestStub/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source (stub). + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gdisp.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +/* Include the emulation code for things we don't support */ +#include "gdisp_emulation.c" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ +/* + The following 2 routines are required. + All other routines are optional. +*/ + +/** + * @brief Low level GDISP driver initialization. + * + * @notapi + */ +bool_t GDISP_LLD(init)(void) { + /* Initialise the GDISP structure */ + GDISP.Width = 128; + GDISP.Height = 128; + GDISP.Orientation = portrait; + GDISP.Powermode = powerOff; + GDISP.Backlight = 100; + GDISP.Contrast = 50; + return TRUE; +} + +/** + * @brief Draws a pixel on the display. + * + * @param[in] x X location of the pixel + * @param[in] y Y location of the pixel + * @param[in] color The color of the pixel + * + * @notapi + */ +void GDISP_LLD(drawpixel)(coord_t UNUSED(x), coord_t UNUSED(y), color_t UNUSED(color)) { +} + +/* ---- Optional Routines ---- */ +/* + All the below routines are optional. + Defining them will increase speed but everything + will work if they are not defined. + If you are not using a routine - turn it off using + the appropriate GDISP_HARDWARE_XXXX macro. + Don't bother coding for obvious similar routines if + there is no performance penalty as the emulation software + makes a good job of using similar routines. + eg. If fillarea() is defined there is little + point in defining clear() unless the + performance bonus is significant. + For good performance it is suggested to implement + fillarea() and blitarea(). +*/ + +#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__) + /** + * @brief Clear the display. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] color The color of the pixel + * + * @notapi + */ + void GDISP_LLD(clear)(color_t UNUSED(color)) { + } +#endif + +#if GDISP_HARDWARE_LINES || defined(__DOXYGEN__) + /** + * @brief Draw a line. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x0, y0 The start of the line + * @param[in] x1, y1 The end of the line + * @param[in] color The color of the line + * + * @notapi + */ + void GDISP_LLD(drawline)(coord_t UNUSED(x0), coord_t UNUSED(y0), coord_t UNUSED(x1), coord_t UNUSED(y1), color_t UNUSED(color)) { + } +#endif + +#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a color. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] color The color of the fill + * + * @notapi + */ + void GDISP_LLD(fillarea)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(cx), coord_t UNUSED(cy), color_t UNUSED(color)) { + } +#endif + +#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__) + /** + * @brief Fill an area with a bitmap. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] buffer The pixels to use to fill the area. + * + * @notapi + */ + void GDISP_LLD(blitarea)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(cx), coord_t UNUSED(cy), const pixel_t *UNUSED(buffer)) { + } +#endif + +/* Circular Drawing Functions */ +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLES) || defined(__DOXYGEN__) + /** + * @brief Draw a circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(drawcircle)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(radius), color_t UNUSED(color)) { + } +#endif + +#if (GDISP_NEED_CIRCLE && GDISP_HARDWARE_CIRCLEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled circle. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the circle is over the edges of the screen. + * + * @param[in] x, y The centre of the circle + * @param[in] radius The radius of the circle + * @param[in] color The color of the circle + * + * @notapi + */ + void GDISP_LLD(fillcircle)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(radius), color_t UNUSED(color)) { + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSES) || defined(__DOXYGEN__) + /** + * @brief Draw an ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(drawellipse)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(a), coord_t UNUSED(b), color_t UNUSED(color)) { + } +#endif + +#if (GDISP_NEED_ELLIPSE && GDISP_HARDWARE_ELLIPSEFILLS) || defined(__DOXYGEN__) + /** + * @brief Create a filled ellipse. + * @note Optional - The high level driver can emulate using software. + * @note If GDISP_NEED_CLIPPING is defined this routine MUST behave + * correctly if the ellipse is over the edges of the screen. + * + * @param[in] x, y The centre of the ellipse + * @param[in] a, b The dimensions of the ellipse + * @param[in] color The color of the ellipse + * + * @notapi + */ + void GDISP_LLD(fillellipse)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(a), coord_t UNUSED(b), color_t UNUSED(color)) { + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXT) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a transparent background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * + * @notapi + */ + void GDISP_LLD(drawchar)(coord_t UNUSED(x), coord_t UNUSED(y), char UNUSED(c), font_t UNUSED(font), color_t UNUSED(color)) { + } +#endif + +#if (GDISP_NEED_TEXT && GDISP_HARDWARE_TEXTFILLS) || defined(__DOXYGEN__) + /** + * @brief Draw a character using a filled background. + * @note Optional - The high level driver can emulate using software. + * + * @param[in] x, y The top-left corner of the text + * @param[in] c The character to print + * @param[in] color The color of the character + * @param[in] bgcolor The background color + * + * @notapi + */ + void GDISP_LLD(fillchar)(coord_t UNUSED(x), coord_t UNUSED(y), char UNUSED(c), font_t UNUSED(font), color_t UNUSED(color), color_t UNUSED(bgcolor)) { + } +#endif + +#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__) + /** + * @brief Get the color of a particular pixel. + * @note Optional. + * @note If x,y is off the screen, the result is undefined. + * + * @param[in] x, y The start of the text + * + * @notapi + */ + color_t GDISP_LLD(getpixelcolor)(coord_t UNUSED(x), coord_t UNUSED(y)) { + return 0; + } +#endif + +#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL) || defined(__DOXYGEN__) + /** + * @brief Scroll vertically a section of the screen. + * @note Optional. + * @note If x,y + cx,cy is off the screen, the result is undefined. + * @note If lines is >= cy, it is equivelent to a area fill with bgcolor. + * + * @param[in] x, y The start of the area to be scrolled + * @param[in] cx, cy The size of the area to be scrolled + * @param[in] lines The number of lines to scroll (Can be positive or negative) + * @param[in] bgcolor The color to fill the newly exposed area. + * + * @notapi + */ + void GDISP_LLD(verticalscroll)(coord_t UNUSED(x), coord_t UNUSED(y), coord_t UNUSED(cx), coord_t UNUSED(cy), int UNUSED(lines), color_t UNUSED(bgcolor)) { + } +#endif + +#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__) + /** + * @brief Driver Control + * @detail Unsupported control codes are ignored. + * @note The value parameter should always be typecast to (void *). + * @note There are some predefined and some specific to the low level driver. + * @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t + * GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t + * GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver + * that only supports off/on anything other + * than zero is on. + * GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100. + * GDISP_CONTROL_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to do. + * @param[in] value The value to use (always cast to a void *). + * + * @notapi + */ + void GDISP_LLD(control)(unsigned UNUSED(what), void *UNUSED(value)) { + } +#endif + +#if (GDISP_NEED_QUERY && GDISP_HARDWARE_QUERY) || defined(__DOXYGEN__) +/** + * @brief Query a driver value. + * @detail Typecase the result to the type you want. + * @note GDISP_QUERY_WIDTH - (coord_t) Gets the width of the screen + * GDISP_QUERY_HEIGHT - (coord_t) Gets the height of the screen + * GDISP_QUERY_POWER - (gdisp_powermode_t) Get the current powermode + * GDISP_QUERY_ORIENTATION - (gdisp_orientation_t) Get the current screen orientation + * GDISP_QUERY_BACKLIGHT - (coord_t) Get the backlight state (0 to 100) + * GDISP_QUERY_CONTRAST - (coord_t) Get the contrast (0 to 100). + * GDISP_QUERY_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to Query + * + * @notapi + */ +void *GDISP_LLD(query)(unsigned what) { + switch(what) { + case GDISP_QUERY_WIDTH: return (void *)(unsigned)GDISP.Width; + case GDISP_QUERY_HEIGHT: return (void *)(unsigned)GDISP.Height; + case GDISP_QUERY_POWER: return (void *)(unsigned)GDISP.Powermode; + case GDISP_QUERY_ORIENTATION: return (void *)(unsigned)GDISP.Orientation; + case GDISP_QUERY_BACKLIGHT: return (void *)(unsigned)GDISP.Backlight; + case GDISP_QUERY_CONTRAST: return (void *)(unsigned)GDISP.Contrast; + case GDISP_QUERY_LLD+0: + /* Code here */ + default: return (void *)-1; + } +} +#endif + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispTestStub/gdisp_lld.mk b/drivers/gdisp/gdispTestStub/gdisp_lld.mk new file mode 100644 index 00000000..9c5d02ea --- /dev/null +++ b/drivers/gdisp/gdispTestStub/gdisp_lld.mk @@ -0,0 +1,5 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/gdisp/gdispTestStub/gdisp_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/gdisp/gdispTestStub diff --git a/drivers/gdisp/gdispTestStub/gdisp_lld_config.h b/drivers/gdisp/gdispTestStub/gdisp_lld_config.h new file mode 100644 index 00000000..d66e050f --- /dev/null +++ b/drivers/gdisp/gdispTestStub/gdisp_lld_config.h @@ -0,0 +1,66 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispTestStub/gdisp_lld_config.h + * @brief GDISP Graphic Driver subsystem low level driver header (stub). + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if HAL_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_DRIVER_NAME "TestStub" +#define GDISP_LLD(x) gdisp_lld_##x##_TestStub + +#define GDISP_HARDWARE_LINES FALSE +#define GDISP_HARDWARE_CLEARS FALSE +#define GDISP_HARDWARE_FILLS FALSE +#define GDISP_HARDWARE_BITFILLS FALSE +#define GDISP_HARDWARE_CIRCLES FALSE +#define GDISP_HARDWARE_CIRCLEFILLS FALSE +#define GDISP_HARDWARE_ELLIPSES FALSE +#define GDISP_HARDWARE_ELLIPSEFILLS FALSE +#define GDISP_HARDWARE_TEXT FALSE +#define GDISP_HARDWARE_TEXTFILLS FALSE +#define GDISP_HARDWARE_SCROLL GDISP_NEED_SCROLL +#define GDISP_HARDWARE_PIXELREAD GDISP_NEED_PIXELREAD +#define GDISP_HARDWARE_CONTROL FALSE +#define GDISP_HARDWARE_QUERY FALSE + +#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE +#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE + +#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +#define GDISP_PACKED_PIXELS FALSE +#define GDISP_PACKED_LINES FALSE + +#endif /* HAL_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/gdisp/gdispTestStub/readme.txt b/drivers/gdisp/gdispTestStub/readme.txt new file mode 100644 index 00000000..83611acf --- /dev/null +++ b/drivers/gdisp/gdispTestStub/readme.txt @@ -0,0 +1,17 @@ +This low level driver is a test stub that doesn't talk to any +real hardware. It is included to allow testing of the compilation +process. + +Do not use this driver as a template for new drivers. Use the + templates/gdispXXXXX directory for that. + +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_GDISP TRUE + b) Any optional high level driver defines (see gdisp.h) + you want to compile test eg: GDISP_NEED_MULTITHREAD + +2. To your makefile add the following lines: + include $(CHIBIOS)/os/halext/halext.mk + include $(CHIBIOS)/os/halext/drivers/gdispTestStub/gdisp_lld.mk diff --git a/drivers/gdisp/gdispVMT/gdisp_lld.c b/drivers/gdisp/gdispVMT/gdisp_lld.c new file mode 100644 index 00000000..1528f470 --- /dev/null +++ b/drivers/gdisp/gdispVMT/gdisp_lld.c @@ -0,0 +1,249 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispVMT/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for VMT. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gdisp.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +#define GDISP_LLD_NO_STRUCT + +/* Include the emulation code for things we don't support */ +#include "gdisp_emulation.c" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#define GDISP_LLD1(x) GDISP_VMT_NAME1(gdisp_lld_##x##_) +#define GDISP_LLD2(x) GDISP_VMT_NAME2(gdisp_lld_##x##_) + +/* Prototypes for lld driver functions */ +bool_t GDISP_LLD1(init)(void); +void GDISP_LLD1(clear)(color_t color); +void GDISP_LLD1(drawpixel)(coord_t x, coord_t y, color_t color); +void GDISP_LLD1(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); +void GDISP_LLD1(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer); +void GDISP_LLD1(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color); +#if GDISP_NEED_CIRCLE + void GDISP_LLD1(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color); + void GDISP_LLD1(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color); +#endif +#if GDISP_NEED_ELLIPSE + void GDISP_LLD1(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); + void GDISP_LLD1(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); +#endif +#if GDISP_NEED_TEXT + void GDISP_LLD1(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color); + void GDISP_LLD1(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor); +#endif +#if GDISP_NEED_PIXELREAD + color_t GDISP_LLD1(getpixelcolor)(coord_t x, coord_t y); +#endif +#if GDISP_NEED_SCROLL + void GDISP_LLD1(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor); +#endif +#if GDISP_NEED_CONTROL + void GDISP_LLD1(control)(unsigned what, void *value); +#endif +#if GDISP_NEED_QUERY + void *GDISP_LLD1(query)(unsigned what); +#endif + +bool_t GDISP_LLD2(init)(void); +void GDISP_LLD2(clear)(color_t color); +void GDISP_LLD2(drawpixel)(coord_t x, coord_t y, color_t color); +void GDISP_LLD2(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); +void GDISP_LLD2(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer); +void GDISP_LLD2(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color); +#if GDISP_NEED_CIRCLE + void GDISP_LLD2(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color); + void GDISP_LLD2(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color); +#endif +#if GDISP_NEED_ELLIPSE + void GDISP_LLD2(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); + void GDISP_LLD2(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); +#endif +#if GDISP_NEED_TEXT + void GDISP_LLD2(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color); + void GDISP_LLD2(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor); +#endif +#if GDISP_NEED_PIXELREAD + color_t GDISP_LLD2(getpixelcolor)(coord_t x, coord_t y); +#endif +#if GDISP_NEED_SCROLL + void GDISP_LLD2(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor); +#endif +#if GDISP_NEED_CONTROL + void GDISP_LLD2(control)(unsigned what, void *value); +#endif +#if GDISP_NEED_QUERY + void *GDISP_LLD2(query)(unsigned what); +#endif + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/* Our VMT table variables */ +void GDISP_LLD_VMT(clear)(color_t color); +void GDISP_LLD_VMT(drawpixel)(coord_t x, coord_t y, color_t color); +void GDISP_LLD_VMT(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); +void GDISP_LLD_VMT(blitarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer); +void GDISP_LLD_VMT(drawline)(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color); + +#if GDISP_NEED_CIRCLE +void GDISP_LLD_VMT(drawcircle)(coord_t x, coord_t y, coord_t radius, color_t color); +void GDISP_LLD_VMT(fillcircle)(coord_t x, coord_t y, coord_t radius, color_t color); +#endif + +#if GDISP_NEED_ELLIPSE +void GDISP_LLD_VMT(drawellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); +void GDISP_LLD_VMT(fillellipse)(coord_t x, coord_t y, coord_t a, coord_t b, color_t color); +#endif + +/* Text Rendering Functions */ +#if GDISP_NEED_TEXT +void GDISP_LLD_VMT(drawchar)(coord_t x, coord_t y, char c, font_t font, color_t color); +void GDISP_LLD_VMT(fillchar)(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor); +#endif + +/* Pixel readback */ +#if GDISP_NEED_PIXELREAD +color_t GDISP_LLD_VMT(getpixelcolor)(coord_t x, coord_t y); +#endif + +/* Scrolling Function - clears the area scrolled out */ +#if GDISP_NEED_SCROLL +void GDISP_LLD_VMT(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor); +#endif + +/* Set driver specific control */ +#if GDISP_NEED_CONTROL +void GDISP_LLD_VMT(control)(unsigned what, void *value); +#endif +/* Set driver specific control */ +#if GDISP_NEED_QUERY +void *GDISP_LLD_VMT(query)(unsigned what); +#endif + + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +bool_t gdisp_lld_init_VMT(void) { + if (GDISP_VMT_NAME1(gdisp_lld_init_)()) { + gdisp_lld_clear_VMT = GDISP_VMT_NAME1(gdisp_lld_clear_); + gdisp_lld_drawpixel_VMT = GDISP_VMT_NAME1(gdisp_lld_drawpixel_); + gdisp_lld_fillarea_VMT = GDISP_VMT_NAME1(gdisp_lld_fillarea_); + gdisp_lld_blitarea_VMT = GDISP_VMT_NAME1(gdisp_lld_blitarea_); + gdisp_lld_drawline_VMT = GDISP_VMT_NAME1(gdisp_lld_drawline_); + #if GDISP_NEED_CIRCLE + gdisp_lld_drawcircle_VMT = GDISP_VMT_NAME1(gdisp_lld_drawcircle_); + gdisp_lld_fillcircle_VMT = GDISP_VMT_NAME1(gdisp_lld_fillcircle_); + #endif + #if GDISP_NEED_ELLIPSE + gdisp_lld_drawellipse_VMT = GDISP_VMT_NAME1(gdisp_lld_drawellipse_); + gdisp_lld_fillellipse_VMT = GDISP_VMT_NAME1(gdisp_lld_fillellipse_); + #endif + #if GDISP_NEED_TEXT + gdisp_lld_drawchar_VMT = GDISP_VMT_NAME1(gdisp_lld_drawchar_); + gdisp_lld_fillchar_VMT = GDISP_VMT_NAME1(gdisp_lld_fillchar_); + #endif + #if GDISP_NEED_PIXELREAD + gdisp_lld_getpixelcolor_VMT = GDISP_VMT_NAME1(gdisp_lld_pixelread_); + #endif + #if GDISP_NEED_SCROLL + gdisp_lld_verticalscroll_VMT = GDISP_VMT_NAME1(gdisp_lld_scroll_); + #endif + #if GDISP_NEED_CONTROL + gdisp_lld_control_VMT = GDISP_VMT_NAME1(gdisp_lld_control_); + #endif + #if GDISP_NEED_QUERY + gdisp_lld_query_VMT = GDISP_VMT_NAME1(gdisp_lld_query_); + #endif + + return TRUE; + } + + if (GDISP_VMT_NAME2(gdisp_lld_init_)()) { + gdisp_lld_clear_VMT = GDISP_VMT_NAME2(gdisp_lld_clear_); + gdisp_lld_drawpixel_VMT = GDISP_VMT_NAME2(gdisp_lld_drawpixel_); + gdisp_lld_fillarea_VMT = GDISP_VMT_NAME2(gdisp_lld_fillarea_); + gdisp_lld_blitarea_VMT = GDISP_VMT_NAME2(gdisp_lld_blitarea_); + gdisp_lld_drawline_VMT = GDISP_VMT_NAME2(gdisp_lld_drawline_); + #if GDISP_NEED_CIRCLE + gdisp_lld_drawcircle_VMT = GDISP_VMT_NAME2(gdisp_lld_drawcircle_); + gdisp_lld_fillcircle_VMT = GDISP_VMT_NAME2(gdisp_lld_fillcircle_); + #endif + #if GDISP_NEED_ELLIPSE + gdisp_lld_drawellipse_VMT = GDISP_VMT_NAME2(gdisp_lld_drawellipse_); + gdisp_lld_fillellipse_VMT = GDISP_VMT_NAME2(gdisp_lld_fillellipse_); + #endif + #if GDISP_NEED_TEXT + gdisp_lld_drawchar_VMT = GDISP_VMT_NAME2(gdisp_lld_drawchar_); + gdisp_lld_fillchar_VMT = GDISP_VMT_NAME2(gdisp_lld_fillchar_); + #endif + #if GDISP_NEED_PIXELREAD + gdisp_lld_getpixelcolor_VMT = GDISP_VMT_NAME2(gdisp_lld_pixelread_); + #endif + #if GDISP_NEED_SCROLL + gdisp_lld_verticalscroll_VMT = GDISP_VMT_NAME2(gdisp_lld_scroll_); + #endif + #if GDISP_NEED_CONTROL + gdisp_lld_control_VMT = GDISP_VMT_NAME2(gdisp_lld_control_); + #endif + #if GDISP_NEED_QUERY + gdisp_lld_query_VMT = GDISP_VMT_NAME2(gdisp_lld_query_); + #endif + + return TRUE; + } + return FALSE; +} + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispVMT/gdisp_lld.mk b/drivers/gdisp/gdispVMT/gdisp_lld.mk new file mode 100644 index 00000000..f89470a6 --- /dev/null +++ b/drivers/gdisp/gdispVMT/gdisp_lld.mk @@ -0,0 +1,7 @@ +# List the required driver. +LCDSRC += ${CHIBIOS}/os/halext/drivers/gdispVMT/gdisp_lld.c \ + ${CHIBIOS}/os/halext/drivers/gdispVMT/gdisp_lld_driver1.c \ + ${CHIBIOS}/os/halext/drivers/gdispVMT/gdisp_lld_driver2.c + +# Required include directories +LCDINC += ${CHIBIOS}/os/halext/drivers/gdispVMT diff --git a/drivers/gdisp/gdispVMT/gdisp_lld_config.h b/drivers/gdisp/gdispVMT/gdisp_lld_config.h new file mode 100644 index 00000000..6c6f7c80 --- /dev/null +++ b/drivers/gdisp/gdispVMT/gdisp_lld_config.h @@ -0,0 +1,67 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispVMT/gdisp_lld_config.h + * @brief GDISP Graphic Driver subsystem low level driver header template. + * + * @addtogroup GDISP + * @{ + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if HAL_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_DRIVER_NAME "VMT" +#define GDISP_LLD(x) gdisp_lld_##x##_VMT +#define GDISP_LLD_VMT(x) (*GDISP_LLD(x)) + +#define GDISP_HARDWARE_LINES TRUE +#define GDISP_HARDWARE_CLEARS TRUE +#define GDISP_HARDWARE_FILLS TRUE +#define GDISP_HARDWARE_BITFILLS TRUE +#define GDISP_HARDWARE_CIRCLES TRUE +#define GDISP_HARDWARE_CIRCLEFILLS TRUE +#define GDISP_HARDWARE_ELLIPSES TRUE +#define GDISP_HARDWARE_ELLIPSEFILLS TRUE +#define GDISP_HARDWARE_TEXT TRUE +#define GDISP_HARDWARE_TEXTFILLS TRUE +#define GDISP_HARDWARE_SCROLL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_HARDWARE_QUERY TRUE + +#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE +#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE + +#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +#define GDISP_PACKED_PIXELS FALSE +#define GDISP_PACKED_LINES FALSE + +#endif /* HAL_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/gdisp/gdispVMT/gdisp_lld_driver1.c b/drivers/gdisp/gdispVMT/gdisp_lld_driver1.c new file mode 100644 index 00000000..f088623e --- /dev/null +++ b/drivers/gdisp/gdispVMT/gdisp_lld_driver1.c @@ -0,0 +1,51 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispVMT/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for VMT. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +#define CONFIGFILE() <../GDISP_VMT_NAME1(gdisp)/gdisp_lld_config.h> +#define DRIVERFILE() <../GDISP_VMT_NAME1(gdisp)/gdisp_lld.c> + +/* We don't need these in our VMT referenced driver */ +#undef GDISP_NEED_MSGAPI +#define GDISP_NEED_MSGAPI FALSE + +/* Include the specific config file we want */ +#include CONFIGFILE() + +/* Bring in our API */ +#include "gdisp.h" + +/* Add the low level driver */ +#include DRIVERFILE() + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispVMT/gdisp_lld_driver2.c b/drivers/gdisp/gdispVMT/gdisp_lld_driver2.c new file mode 100644 index 00000000..325a53e6 --- /dev/null +++ b/drivers/gdisp/gdispVMT/gdisp_lld_driver2.c @@ -0,0 +1,51 @@ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file gdispVMT/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for VMT. + * + * @addtogroup GDISP + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_GDISP || defined(__DOXYGEN__) + +#define CONFIGFILE() <../GDISP_VMT_NAME2(gdisp)/gdisp_lld_config.h> +#define DRIVERFILE() <../GDISP_VMT_NAME2(gdisp)/gdisp_lld.c> + +/* We don't need these in our VMT referenced driver */ +#undef GDISP_NEED_MSGAPI +#define GDISP_NEED_MSGAPI FALSE + +/* Include the specific config file we want */ +#include CONFIGFILE() + +/* Bring in our API */ +#include "gdisp.h" + +/* Add the low level driver */ +#include DRIVERFILE() + +#endif /* HAL_USE_GDISP */ +/** @} */ diff --git a/drivers/gdisp/gdispVMT/readme.txt b/drivers/gdisp/gdispVMT/readme.txt new file mode 100644 index 00000000..91d3f58c --- /dev/null +++ b/drivers/gdisp/gdispVMT/readme.txt @@ -0,0 +1,23 @@ +This driver enables you to have two underlying drivers handling different hardware. +A choice is made at run-time of which driver to call based on which driver succeeds +to initialise first (init returns TRUE). + +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_GDISP TRUE + b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD + c) Define these: + #define GDISP_VMT_NAME1(x) x##YourDriver1 + #define GDISP_VMT_NAME2(x) x##YourDriver2 + Note YourDriver1 & 2 are the basenames of the directories containing the driver. + Note that both drivers must be the same pixel format which is + GDISP_PIXELFORMAT_RGB565 by default. Alter gdispVMT/gdisp_lld_config.h if your + pixel format is different on both drivers. + d) Any driver specific defines. If both drivers use the same defines then they must + accept the same values for the define. + +2. To your makefile add the following lines: + include $(CHIBIOS)/os/halext/halext.mk + include $(CHIBIOS)/os/halext/drivers/gdispVMT/gdisp_lld.mk + \ No newline at end of file diff --git a/drivers/touchpad/touchpadADS7843/readme.txt b/drivers/touchpad/touchpadADS7843/readme.txt new file mode 100644 index 00000000..34a57bc0 --- /dev/null +++ b/drivers/touchpad/touchpadADS7843/readme.txt @@ -0,0 +1,9 @@ +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_TOUCHPAD TRUE + +2. To your makefile add the following lines: + include $(LCDLIB)/lcd.mk + include $(LCDLIB)/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.mk + diff --git a/drivers/touchpad/touchpadADS7843/touchpad_lld.c b/drivers/touchpad/touchpadADS7843/touchpad_lld.c new file mode 100644 index 00000000..a5265995 --- /dev/null +++ b/drivers/touchpad/touchpadADS7843/touchpad_lld.c @@ -0,0 +1,146 @@ +/* + ChibiOS-LCD-Driver - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file touchpadADS7843/touchpad_lld.c + * @brief Touchpad Driver subsystem low level driver source. + * + * @addtogroup TOUCHPAD + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "touchpad.h" + +#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS) +#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS) + +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +#if !defined(__DOXYGEN__) + TOUCHPADDriver Touchpad; +#endif + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ + +/** + * @brief Low level Touchpad driver initialization. + * + * @notapi + */ +void tp_lld_init(TOUCHPADDriver *tp) { + spiStart(tp->spid, tp->spicfg); +} + +/** + * @brief Reads out the X direction. + * + * @notapi + */ +uint16_t tp_lld_read_x(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0xd0; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + +/* + * @brief Reads out the X direction. + * + * @notapi + */ +uint16_t tp_lld_read_y(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0x90; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + +/* ---- Optional Routines ---- */ +#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__) + /* + * @brief for checking if touchpad is pressed or not. + * + * @return 1 if pressed / 0 if not pressed + * + * @noapi + */ + uint8_t tp_lld_irq(void) { + return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); + } +#endif + +#endif /* HAL_USE_TOUCHPAD */ +/** @} */ + diff --git a/drivers/touchpad/touchpadADS7843/touchpad_lld.mk b/drivers/touchpad/touchpadADS7843/touchpad_lld.mk new file mode 100644 index 00000000..f70f0dd1 --- /dev/null +++ b/drivers/touchpad/touchpadADS7843/touchpad_lld.mk @@ -0,0 +1,6 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/touchpad/touchpadADS7843/touchpad_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/touchpad/touchpadADS7843 + diff --git a/drivers/touchpad/touchpadADS7843/touchpad_lld_config.h b/drivers/touchpad/touchpadADS7843/touchpad_lld_config.h new file mode 100644 index 00000000..1e878795 --- /dev/null +++ b/drivers/touchpad/touchpadADS7843/touchpad_lld_config.h @@ -0,0 +1,44 @@ +/* + ChibiOS-LCD-Driver - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file touchpadADS7843/touchpad_lld_config.h + * @brief Touchpad Driver subsystem low level driver. + * + * @addtogroup TOUCHPAD + * @{ + */ + +#ifndef _TOUCHPAD_LLD_CONFIG_H +#define _TOUCHPAD_LLD_CONFIG_H + +#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define TOUCHPAD_HAS_IRQ TRUE +#define TOUCHPAD_HAS_PRESSURE FALSE + +#endif /* HAL_USE_TOUCHPAD */ + +#endif /* _TOUCHPAD_LLD_CONFIG_H */ +/** @} */ diff --git a/drivers/touchpad/touchpadXPT2046/readme.txt b/drivers/touchpad/touchpadXPT2046/readme.txt new file mode 100644 index 00000000..992d346d --- /dev/null +++ b/drivers/touchpad/touchpadXPT2046/readme.txt @@ -0,0 +1,9 @@ +To use this driver: + +1. Add in your halconf.h: + a) #define HAL_USE_TOUCHPAD TRUE + +2. To your makefile add the following lines: + include $(LCDLIB)/lcd.mk + include $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk + diff --git a/drivers/touchpad/touchpadXPT2046/touchpad_lld.c b/drivers/touchpad/touchpadXPT2046/touchpad_lld.c new file mode 100644 index 00000000..195c8aa6 --- /dev/null +++ b/drivers/touchpad/touchpadXPT2046/touchpad_lld.c @@ -0,0 +1,158 @@ +/* + ChibiOS-LCD-Driver - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file touchpadXPT2046/touchpad_lld.c + * @brief Touchpad Driver subsystem low level driver source. + * + * @addtogroup TOUCHPAD + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "touchpad.h" + +#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS) +#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS) + +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +#if !defined(__DOXYGEN__) + TOUCHPADDriver Touchpad; +#endif + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/* ---- Required Routines ---- */ + +/** + * @brief Low level Touchpad driver initialization. + * + * @notapi + */ +void tp_lld_init(TOUCHPADDriver *tp) { + spiStart(tp->spid, tp->spicfg); +} + +/** + * @brief Reads out the X direction. + * + * @notapi + */ +uint16_t tp_lld_read_x(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0xd0; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + +/* + * @brief Reads out the Y direction. + * + * @notapi + */ +uint16_t tp_lld_read_y(void) { + uint8_t txbuf[1]; + uint8_t rxbuf[2]; + uint16_t y; + + txbuf[0] = 0x90; + TP_CS_LOW; + spiSend(&SPID1, 1, txbuf); + spiReceive(&SPID1, 2, rxbuf); + TP_CS_HIGH; + + y = rxbuf[0] << 4; + y |= rxbuf[1] >> 4; + + return y; +} + +/* ---- Optional Routines ---- */ +#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__) + /* + * @brief for checking if touchpad is pressed or not. + * + * @return 1 if pressed / 0 if not pressed + * + * @notapi + */ + uint8_t tp_lld_irq(void) { + return (!palReadPad(TP_IRQ_PORT, TP_IRQ)); + } +#endif + +#if TOUCHPAD_HAS_PRESSURE || defined(__DOXYGEN__) + /* + * @brief Reads out the Z direction / pressure. + * + * @notapi + */ + uint16_t tp_lld_read_z(void) { + /* ToDo */ + return 42; + } +#endif + +#endif /* HAL_USE_TOUCHPAD */ +/** @} */ + diff --git a/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk b/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk new file mode 100644 index 00000000..26e27c1c --- /dev/null +++ b/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk @@ -0,0 +1,6 @@ +# List the required driver. +LCDSRC += $(LCDLIB)/drivers/touchpad/touchpadXPT2046/touchpad_lld.c + +# Required include directories +LCDINC += $(LCDLIB)/drivers/touchpad/touchpadXPT2046 + diff --git a/drivers/touchpad/touchpadXPT2046/touchpad_lld_config.h b/drivers/touchpad/touchpadXPT2046/touchpad_lld_config.h new file mode 100644 index 00000000..4ddd8da0 --- /dev/null +++ b/drivers/touchpad/touchpadXPT2046/touchpad_lld_config.h @@ -0,0 +1,44 @@ +/* + ChibiOS-LCD-Driver - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver 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 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver 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 . +*/ + +/** + * @file touchpadXPT2046/touchpad_lld_config.h + * @brief Touchppad Driver subsystem low level driver. + * + * @addtogroup TOUCHPAD + * @{ + */ + +#ifndef _TOUCHPAD_LLD_CONFIG_H +#define _TOUCHPAD_LLD_CONFIG_H + +#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define TOUCHPAD_HAS_IRQ TRUE +#define TOUCHPAD_HAS_PRESSURE TRUE + +#endif /* HAL_USE_TOUCHPAD */ + +#endif /* _TOUCHPAD_LLD_CONFIG_H */ +/** @} */ -- cgit v1.2.3