aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gadc/AT91SAM7/gadc_lld_board_template.h (renamed from drivers/gadc/AT91SAM7/gadc_lld_board_olimexsam7ex256.h)12
-rw-r--r--drivers/gadc/AT91SAM7/gadc_lld_config.h12
-rw-r--r--drivers/gaudin/gadc/gaudin_lld_board_template.h (renamed from drivers/gaudin/gadc/gaudin_lld_board_olimexsam7ex256.h)15
-rw-r--r--drivers/gaudin/gadc/gaudin_lld_config.h11
-rw-r--r--drivers/gdisp/ED060SC4/board_ED060SC4_template.h202
-rw-r--r--drivers/gdisp/ED060SC4/gdisp_lld.mk2
-rw-r--r--drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c625
-rw-r--r--drivers/gdisp/ED060SC4/gdisp_lld_config.h9
-rw-r--r--drivers/gdisp/ED060SC4/readme.txt3
-rw-r--r--drivers/gdisp/HX8347D/HX8347D.h2
-rw-r--r--drivers/gdisp/HX8347D/board_HX8347D_template.h156
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld.c485
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c236
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld_board_st_stm32f4_discovery.h202
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld_board_template.h120
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld_config.h10
-rw-r--r--drivers/gdisp/ILI9320/board_ILI9320_template.h157
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld.c584
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld.mk7
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c380
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_board_olimex_pic32mx_lcd.h106
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_board_olimex_stm32_lcd.h80
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_board_template.h53
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld_config.h64
-rw-r--r--drivers/gdisp/ILI9325/board_ILI9325_template.h155
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld.c582
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c368
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld_board_hy_stm32_100p.h83
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld_board_template.h45
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld_config.h14
-rw-r--r--drivers/gdisp/ILI9341/ILI9341.h87
-rw-r--r--drivers/gdisp/ILI9341/board_ILI9341_template.h154
-rw-r--r--drivers/gdisp/ILI9341/gdisp_lld.mk2
-rw-r--r--drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c353
-rw-r--r--drivers/gdisp/ILI9341/gdisp_lld_config.h35
-rw-r--r--drivers/gdisp/ILI9481/board_ILI9481_template.h155
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld.c598
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c328
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_board_firebullstm32f103.h145
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_board_template.h107
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_config.h11
-rw-r--r--drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_template.h131
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld.c505
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c262
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld_board_olimexsam7ex256.h183
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld_board_template.h114
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h17
-rw-r--r--drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_template.h131
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld.c545
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c570
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld_board_olimexsam7ex256.h225
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld_board_template.h114
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h33
-rw-r--r--drivers/gdisp/RA8875/board_RA8875_template.h143
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld.c449
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld.mk6
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld_RA8875.c283
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld_board_marlin.h193
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld_board_template.h119
-rw-r--r--drivers/gdisp/RA8875/gdisp_lld_config.h13
-rw-r--r--drivers/gdisp/RA8875/ra8875.h18
-rw-r--r--drivers/gdisp/S6D1121/board_S6D1121_template.h154
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld.c561
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c338
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld_board_olimex_e407.h81
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld_board_template.h106
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld_config.h12
-rw-r--r--drivers/gdisp/SSD1289/board_SSD1289_template.h191
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c361
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_board_firebullstm32f103.h144
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_board_st_stm32f4_discovery.h172
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_board_template.h106
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_config.h24
-rw-r--r--drivers/gdisp/SSD1306/SSD1306.h3
-rw-r--r--drivers/gdisp/SSD1306/board_SSD1306_template.h116
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld.c646
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c280
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_board_example_i2c.h137
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_board_example_spi.h139
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_board_template.h74
-rw-r--r--drivers/gdisp/SSD1306/gdisp_lld_config.h16
-rw-r--r--drivers/gdisp/SSD1963/board_SSD1963_template.h148
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld.c427
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld.mk6
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c285
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h177
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_board_example_gpio.h191
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_board_template.h115
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_config.h12
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_panel_example.h74
-rw-r--r--drivers/gdisp/SSD1963/ssd1963.h5
-rw-r--r--drivers/gdisp/SSD2119/board_SSD2119_template.h191
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld.c704
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c411
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld_board_embest_dmstf4bb.h193
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld_board_template.h109
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld_config.h20
-rw-r--r--drivers/gdisp/ST7565/board_ST7565_template.h108
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld.c267
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld.mk6
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld_ST7565.c262
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld_board_template.h82
-rw-r--r--drivers/gdisp/ST7565/gdisp_lld_config.h11
-rw-r--r--drivers/gdisp/ST7565/st7565.h3
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld.c118
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld.mk5
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld_TestStub.c61
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld_config.h10
-rw-r--r--drivers/ginput/dial/GADC/ginput_lld_dial_board_template.h (renamed from drivers/ginput/dial/GADC/ginput_lld_dial_board_olimexsam7ex256.h)9
-rw-r--r--drivers/ginput/dial/GADC/ginput_lld_dial_config.h11
-rw-r--r--drivers/ginput/toggle/Pal/ginput_lld_toggle_board_olimexsam7ex256.h44
-rw-r--r--drivers/ginput/toggle/Pal/ginput_lld_toggle_board_template.h (renamed from drivers/ginput/toggle/Pal/ginput_lld_toggle_board_example.h)84
-rw-r--r--drivers/ginput/toggle/Pal/ginput_lld_toggle_config.h11
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_firebull_stm32f103.h90
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h90
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h90
-rw-r--r--drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h111
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse.c10
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h151
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h152
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h126
-rw-r--r--drivers/multiple/Win32/gdisp_lld.c1028
-rw-r--r--drivers/multiple/Win32/gdisp_lld.mk5
-rw-r--r--drivers/multiple/Win32/gdisp_lld_Win32.c1160
-rw-r--r--drivers/multiple/Win32/gdisp_lld_config.h46
-rw-r--r--drivers/multiple/Win32/ginput_lld_toggle_config.h15
-rw-r--r--drivers/multiple/Win32/readme.txt13
-rw-r--r--drivers/multiple/X/gdisp_lld.c294
-rw-r--r--drivers/multiple/X/gdisp_lld.mk5
-rw-r--r--drivers/multiple/X/gdisp_lld_X.c340
-rw-r--r--drivers/multiple/X/gdisp_lld_config.h14
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld.c10
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h59
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h122
143 files changed, 9588 insertions, 13018 deletions
diff --git a/drivers/gadc/AT91SAM7/gadc_lld_board_olimexsam7ex256.h b/drivers/gadc/AT91SAM7/gadc_lld_board_template.h
index 8f047015..045c0ed7 100644
--- a/drivers/gadc/AT91SAM7/gadc_lld_board_olimexsam7ex256.h
+++ b/drivers/gadc/AT91SAM7/gadc_lld_board_template.h
@@ -6,15 +6,15 @@
*/
/**
- * @file drivers/gadc/AT91SAM7/gadc_lld_board_olimexsam7ex256.h
+ * @file drivers/gadc/AT91SAM7/gadc_lld_board_template.h
* @brief GADC Driver config file.
*
* @addtogroup GADC
* @{
*/
-#ifndef _GADC_LLD_BOARD_OLIMEXSAM7EX256_H
-#define _GADC_LLD_BOARD_OLIMEXSAM7EX256_H
+#ifndef _GADC_LLD_BOARD_H
+#define _GADC_LLD_BOARD_H
#if GFX_USE_GADC
@@ -22,12 +22,16 @@
/* Analogue devices on this board */
/*===========================================================================*/
+/**
+ * @brief The physical devices that are accessible via GADC and their physical device numbers.
+ * @note The numbers below are examples for this template file
+ */
#define GADC_PHYSDEV_MICROPHONE 0x00000080
#define GADC_PHYSDEV_DIAL 0x00000040
#define GADC_PHYSDEV_TEMPERATURE 0x00000020
#endif /* GFX_USE_GADC */
-#endif /* _GADC_LLD_BOARD_OLIMEXSAM7EX256_H */
+#endif /* _GADC_LLD_BOARD_H */
/** @} */
diff --git a/drivers/gadc/AT91SAM7/gadc_lld_config.h b/drivers/gadc/AT91SAM7/gadc_lld_config.h
index 8c6e1cc0..ba6cbda2 100644
--- a/drivers/gadc/AT91SAM7/gadc_lld_config.h
+++ b/drivers/gadc/AT91SAM7/gadc_lld_config.h
@@ -52,16 +52,8 @@
*/
#define GADC_SAMPLE_FORMAT ARRAY_DATA_10BITUNSIGNED
-/* Pull in board specific defines */
-#if defined(GADC_USE_CUSTOM_BOARD) && GADC_USE_CUSTOM_BOARD
- /* Include the user supplied board definitions */
- #include "gadc_lld_board.h"
-#elif defined(BOARD_OLIMEX_SAM7_EX256)
- #include "gadc_lld_board_olimexsam7ex256.h"
-#else
- /* Include the user supplied board definitions */
- #include "gadc_lld_board.h"
-#endif
+/* Include the user supplied board definitions */
+#include "gadc_lld_board.h"
#endif /* GFX_USE_GADC */
diff --git a/drivers/gaudin/gadc/gaudin_lld_board_olimexsam7ex256.h b/drivers/gaudin/gadc/gaudin_lld_board_template.h
index a98f392c..89cc0c12 100644
--- a/drivers/gaudin/gadc/gaudin_lld_board_olimexsam7ex256.h
+++ b/drivers/gaudin/gadc/gaudin_lld_board_template.h
@@ -6,15 +6,15 @@
*/
/**
- * @file drivers/gaudin/gadc/gaudin_lld_board_olimexsam7ex256.h
- * @brief GAUDIN Driver board config file for the Olimex SAM7EX256 board
+ * @file drivers/gaudin/gadc/gaudin_lld_board_template.h
+ * @brief GAUDIN Driver board config board file
*
* @addtogroup GAUDIN
* @{
*/
-#ifndef _GAUDIN_LLD_BOARD_OLIMEXSAM7EX256_H
-#define _GAUDIN_LLD_BOARD_OLIMEXSAM7EX256_H
+#ifndef _GAUDIN_LLD_BOARD_H
+#define _GAUDIN_LLD_BOARD_H
/*===========================================================================*/
/* Audio inputs on this board */
@@ -22,18 +22,21 @@
/**
* @brief The number of audio channels supported by this driver
+ * @note This is an example
*/
#define GAUDIN_NUM_CHANNELS 1
/**
* @brief The list of audio channels and their uses
+ * @note This is an example
* @{
*/
#define GAUDIN_MICROPHONE 0
/** @} */
/**
- * @brief The following defines are for the low level driver use only
+ * @brief The audio channel to GADC physical device assignment
+ * @note This is an example
* @{
*/
#ifdef GAUDIN_LLD_IMPLEMENTATION
@@ -43,5 +46,5 @@
#endif
/** @} */
-#endif /* _GAUDIN_LLD_BOARD_OLIMEXSAM7EX256_H */
+#endif /* _GAUDIN_LLD_BOARD_H */
/** @} */
diff --git a/drivers/gaudin/gadc/gaudin_lld_config.h b/drivers/gaudin/gadc/gaudin_lld_config.h
index f10e0575..a9fd02ae 100644
--- a/drivers/gaudin/gadc/gaudin_lld_config.h
+++ b/drivers/gaudin/gadc/gaudin_lld_config.h
@@ -50,15 +50,8 @@ typedef adcsample_t audin_sample_t;
* For the GAUDIN driver that uses GADC - all the remaining config definitions are specific
* to the board.
*/
-#if defined(GADC_USE_CUSTOM_BOARD) && GADC_USE_CUSTOM_BOARD
- /* Include the user supplied board definitions */
- #include "gaudin_lld_board.h"
-#elif defined(BOARD_OLIMEX_SAM7_EX256)
- #include "gaudin_lld_board_olimexsam7ex256.h"
-#else
- /* Include the user supplied board definitions */
- #include "gaudin_lld_board.h"
-#endif
+/* Include the user supplied board definitions */
+#include "gaudin_lld_board.h"
#endif /* GFX_USE_GAUDIN */
diff --git a/drivers/gdisp/ED060SC4/board_ED060SC4_template.h b/drivers/gdisp/ED060SC4/board_ED060SC4_template.h
new file mode 100644
index 00000000..6d71a986
--- /dev/null
+++ b/drivers/gdisp/ED060SC4/board_ED060SC4_template.h
@@ -0,0 +1,202 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ST7565/board_ST7565_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the ST7565 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Optional parameters that can be put in this file.
+ * @note The values listed below are the defaults.
+ *
+ * @note #define GDISP_SCREEN_HEIGHT 600
+ * @note #define GDISP_SCREEN_WIDTH 800
+ *
+ * @note Number of pixels per byte<br>
+ * #define EINK_PPB 4
+ *
+ * @note Delay for generating clock pulses.
+ * Unit is approximate clock cycles of the CPU (0 to 15).
+ * This should be atleast 50 ns.<br>
+ * #define EINK_CLOCKDELAY 0
+ *
+ * @note Width of one framebuffer block.
+ * Must be divisible by EINK_PPB and evenly divide GDISP_SCREEN_WIDTH.<br>
+ * #define EINK_BLOCKWIDTH 20
+ *
+ * @note
+ * @note Height of one framebuffer block.
+ * Must evenly divide GDISP_SCREEN_WIDTH.<br>
+ * #define EINK_BLOCKHEIGHT 20
+ *
+ * @note Number of block buffers to use for framebuffer emulation.<br>
+ * #define EINK_NUMBUFFERS 40
+ *
+ * @note Do a "blinking" clear, i.e. clear to opposite polarity first.
+ * This reduces the image persistence.<br>
+ * #define EINK_BLINKCLEAR TRUE
+ *
+ * @note Number of passes to use when clearing the display<br>
+ * #define EINK_CLEARCOUNT 10
+ *
+ * @note Number of passes to use when writing to the display<br>
+ * #define EINK_WRITECOUNT 4
+ */
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Delay for display waveforms. Should be an accurate microsecond delay.
+ *
+ * @param[in] us The number of microseconds
+ */
+static void eink_delay(int us) {
+ (void) us;
+}
+
+/**
+ * @brief Turn the E-ink panel Vdd supply (+3.3V) on or off.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpower_vdd(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Turn the E-ink panel negative supplies (-15V, -20V) on or off.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpower_vneg(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Turn the E-ink panel positive supplies (-15V, -20V) on or off.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpower_vpos(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the LE (source driver Latch Enable) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_le(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the OE (source driver Output Enable) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_oe(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the CL (source driver Clock) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_cl(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the SPH (source driver Start Pulse Horizontal) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_sph(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the D0-D7 (source driver Data) pins.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] value The byte to write
+ */
+static inline void setpins_data(GDisplay *g, uint8_t value) {
+ (void) g;
+ (void) value;
+}
+
+/**
+ * @brief Set the state of the CKV (gate driver Clock Vertical) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_ckv(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the GMODE (gate driver Gate Mode) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_gmode(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+/**
+ * @brief Set the state of the SPV (gate driver Start Pulse Vertical) pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] on On or off
+ */
+static inline void setpin_spv(GDisplay *g, bool_t on) {
+ (void) g;
+ (void) on;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/ED060SC4/gdisp_lld.mk b/drivers/gdisp/ED060SC4/gdisp_lld.mk
index d5c1492f..0c78e1a7 100644
--- a/drivers/gdisp/ED060SC4/gdisp_lld.mk
+++ b/drivers/gdisp/ED060SC4/gdisp_lld.mk
@@ -1,2 +1,2 @@
-GFXSRC += $(GFXLIB)/drivers/gdisp/ED060SC4/gdisp_lld.c
GFXINC += $(GFXLIB)/drivers/gdisp/ED060SC4
+GFXSRC += $(GFXLIB)/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c
diff --git a/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c b/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c
new file mode 100644
index 00000000..3ab1de79
--- /dev/null
+++ b/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c
@@ -0,0 +1,625 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ED060SC4/gdisp_lld.c
+ * @brief GDISP Graphics Driver for the E-ink panel ED060SC4.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_ED060SC4
+#include "../drivers/gdisp/ED060SC4/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ED060SC4.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 600
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 800
+#endif
+
+/* Number of pixels per byte */
+#ifndef EINK_PPB
+ #define EINK_PPB 4
+#endif
+
+/* Delay for generating clock pulses.
+ * Unit is approximate clock cycles of the CPU (0 to 15).
+ * This should be atleast 50 ns.
+ */
+#ifndef EINK_CLOCKDELAY
+ #define EINK_CLOCKDELAY 0
+#endif
+
+/* Width of one framebuffer block.
+ * Must be divisible by EINK_PPB and evenly divide GDISP_SCREEN_WIDTH. */
+#ifndef EINK_BLOCKWIDTH
+ #define EINK_BLOCKWIDTH 20
+#endif
+
+/* Height of one framebuffer block.
+ * Must evenly divide GDISP_SCREEN_WIDTH. */
+#ifndef EINK_BLOCKHEIGHT
+ #define EINK_BLOCKHEIGHT 20
+#endif
+
+/* Number of block buffers to use for framebuffer emulation. */
+#ifndef EINK_NUMBUFFERS
+ #define EINK_NUMBUFFERS 40
+#endif
+
+/* Do a "blinking" clear, i.e. clear to opposite polarity first.
+ * This reduces the image persistence. */
+#ifndef EINK_BLINKCLEAR
+ #define EINK_BLINKCLEAR TRUE
+#endif
+
+/* Number of passes to use when clearing the display */
+#ifndef EINK_CLEARCOUNT
+ #define EINK_CLEARCOUNT 10
+#endif
+
+/* Number of passes to use when writing to the display */
+#ifndef EINK_WRITECOUNT
+ #define EINK_WRITECOUNT 4
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+#define PRIV(g) ((drvPriv *)g->priv)
+
+/** Delay between signal changes, to give time for IO pins to change state. */
+static inline void clockdelay(void)
+{
+ #if EINK_CLOCKDELAY & 1
+ asm("nop");
+ #endif
+ #if EINK_CLOCKDELAY & 2
+ asm("nop");
+ asm("nop");
+ #endif
+ #if EINK_CLOCKDELAY & 4
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ #endif
+ #if EINK_CLOCKDELAY & 8
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ asm("nop");
+ #endif
+}
+
+/** Fast vertical clock pulse for gate driver, used during initializations */
+static void vclock_quick(GDisplay *g)
+{
+ setpin_ckv(g, TRUE);
+ eink_delay(1);
+ setpin_ckv(g, FALSE);
+ eink_delay(4);
+}
+
+/** Horizontal clock pulse for clocking data into source driver */
+static void hclock(GDisplay *g)
+{
+ clockdelay();
+ setpin_cl(g, TRUE);
+ clockdelay();
+ setpin_cl(g, FALSE);
+}
+
+/** Start a new vertical gate driver scan from top.
+ * Note: Does not clear any previous bits in the shift register,
+ * so you should always scan through the whole display before
+ * starting a new scan.
+ */
+static void vscan_start(GDisplay *g)
+{
+ setpin_gmode(g, TRUE);
+ vclock_quick(g);
+ setpin_spv(g, FALSE);
+ vclock_quick(g);
+ setpin_spv(g, TRUE);
+ vclock_quick(g);
+}
+
+/** Waveform for strobing a row of data onto the display.
+ * Attempts to minimize the leaking of color to other rows by having
+ * a long idle period after a medium-length strobe period.
+ */
+static void vscan_write(GDisplay *g)
+{
+ setpin_ckv(g, TRUE);
+ setpin_oe(g, TRUE);
+ eink_delay(5);
+ setpin_oe(g, FALSE);
+ setpin_ckv(g, FALSE);
+ eink_delay(200);
+}
+
+/** Waveform used when clearing the display. Strobes a row of data to the
+ * screen, but does not mind some of it leaking to other rows.
+ */
+static void vscan_bulkwrite(GDisplay *g)
+{
+ setpin_ckv(g, TRUE);
+ eink_delay(20);
+ setpin_ckv(g, FALSE);
+ eink_delay(200);
+}
+
+/** Waveform for skipping a vertical row without writing anything.
+ * Attempts to minimize the amount of change in any row.
+ */
+static void vscan_skip(GDisplay *g)
+{
+ setpin_ckv(g, TRUE);
+ eink_delay(1);
+ setpin_ckv(g, FALSE);
+ eink_delay(100);
+}
+
+/** Stop the vertical scan. The significance of this escapes me, but it seems
+ * necessary or the next vertical scan may be corrupted.
+ */
+static void vscan_stop(GDisplay *g)
+{
+ setpin_gmode(g, FALSE);
+ vclock_quick(g);
+ vclock_quick(g);
+ vclock_quick(g);
+ vclock_quick(g);
+ vclock_quick(g);
+}
+
+/** Start updating the source driver data (from left to right). */
+static void hscan_start(GDisplay *g)
+{
+ /* Disable latching and output enable while we are modifying the row. */
+ setpin_le(g, FALSE);
+ setpin_oe(g, FALSE);
+
+ /* The start pulse should remain low for the duration of the row. */
+ setpin_sph(g, FALSE);
+}
+
+/** Write data to the horizontal row. */
+static void hscan_write(GDisplay *g, const uint8_t *data, int count)
+{
+ while (count--)
+ {
+ /* Set the next byte on the data pins */
+ setpins_data(g, *data++);
+
+ /* Give a clock pulse to the shift register */
+ hclock(g);
+ }
+}
+
+/** Finish and transfer the row to the source drivers.
+ * Does not set the output enable, so the drivers are not yet active. */
+static void hscan_stop(GDisplay *g)
+{
+ /* End the scan */
+ setpin_sph(g, TRUE);
+ hclock(g);
+
+ /* Latch the new data */
+ setpin_le(g, TRUE);
+ clockdelay();
+ setpin_le(g, FALSE);
+}
+
+/** Turn on the power to the E-Ink panel, observing proper power sequencing. */
+static void power_on(GDisplay *g)
+{
+ unsigned i;
+
+ /* First the digital power supply and signal levels. */
+ setpower_vdd(g, TRUE);
+ setpin_le(g, FALSE);
+ setpin_oe(g, FALSE);
+ setpin_cl(g, FALSE);
+ setpin_sph(g, TRUE);
+ setpins_data(g, 0);
+ setpin_ckv(g, FALSE);
+ setpin_gmode(g, FALSE);
+ setpin_spv(g, TRUE);
+
+ /* Min. 100 microsecond delay after digital supply */
+ gfxSleepMicroseconds(100);
+
+ /* Then negative voltages and min. 1000 microsecond delay. */
+ setpower_vneg(g, TRUE);
+ gfxSleepMicroseconds(1000);
+
+ /* Finally the positive voltages. */
+ setpower_vpos(g, TRUE);
+
+ /* Clear the vscan shift register */
+ vscan_start(g);
+ for (i = 0; i < GDISP_SCREEN_HEIGHT; i++)
+ vclock_quick(g);
+ vscan_stop(g);
+}
+
+/** Turn off the power, observing proper power sequencing. */
+static void power_off(GDisplay *g)
+{
+ /* First the high voltages */
+ setpower_vpos(g, FALSE);
+ setpower_vneg(g, FALSE);
+
+ /* Wait for any capacitors to drain */
+ gfxSleepMilliseconds(100);
+
+ /* Then put all signals and digital supply to ground. */
+ setpin_le(g, FALSE);
+ setpin_oe(g, FALSE);
+ setpin_cl(g, FALSE);
+ setpin_sph(g, FALSE);
+ setpins_data(g, 0);
+ setpin_ckv(g, FALSE);
+ setpin_gmode(g, FALSE);
+ setpin_spv(g, FALSE);
+ setpower_vdd(g, FALSE);
+}
+
+/* ====================================
+ * Framebuffer emulation layer
+ * ==================================== */
+
+#if EINK_PPB == 4
+ #define PIXELMASK 3
+ #define PIXEL_WHITE 2
+ #define PIXEL_BLACK 1
+ #define BYTE_WHITE 0xAA
+ #define BYTE_BLACK 0x55
+#else
+ #error Unsupported EINK_PPB value.
+#endif
+
+#if GDISP_SCREEN_HEIGHT % EINK_BLOCKHEIGHT != 0
+ #error GDISP_SCREEN_HEIGHT must be evenly divisible by EINK_BLOCKHEIGHT
+#endif
+
+#if GDISP_SCREEN_WIDTH % EINK_BLOCKWIDTH != 0
+ #error GDISP_SCREEN_WIDTH must be evenly divisible by EINK_BLOCKWIDTH
+#endif
+
+#if EINK_BLOCKWIDTH % EINK_PPB != 0
+ #error EINK_BLOCKWIDTH must be evenly divisible by EINK_PPB
+#endif
+
+#if EINK_NUMBUFFERS > 254
+ #error EINK_NUMBUFFERS must be at most 254.
+#endif
+
+#define BLOCKS_Y (GDISP_SCREEN_HEIGHT / EINK_BLOCKHEIGHT)
+#define BLOCKS_X (GDISP_SCREEN_WIDTH / EINK_BLOCKWIDTH)
+#define WIDTH_BYTES (EINK_BLOCKWIDTH / EINK_PPB)
+
+/* Buffers that store the data for a small area of the display. */
+typedef struct {
+ uint8_t data[EINK_BLOCKHEIGHT][WIDTH_BYTES];
+} block_t;
+
+typedef struct drvPriv {
+ uint8_t g_next_block; /* Index of the next free block buffer. */
+ block_t g_blocks[EINK_NUMBUFFERS];
+
+ /* Map that stores the buffers associated to each area of the display.
+ * Value of 0 means that the block is not allocated.
+ * Other values are the index in g_blocks + 1.
+ */
+ uint8_t g_blockmap[BLOCKS_Y][BLOCKS_X];
+} drvPriv;
+
+/** Check if the row contains any allocated blocks. */
+static bool_t blocks_on_row(GDisplay *g, unsigned by)
+{
+ unsigned bx;
+ for (bx = 0; bx < BLOCKS_X; bx++)
+ {
+ if (PRIV(g)->g_blockmap[by][bx] != 0)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/** Write out a block row. */
+static void write_block_row(GDisplay *g, unsigned by)
+{
+ unsigned bx, dy, dx;
+ for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
+ {
+ hscan_start(g);
+ for (bx = 0; bx < BLOCKS_X; bx++)
+ {
+ if (PRIV(g)->g_blockmap[by][bx] == 0)
+ {
+ for (dx = 0; dx < WIDTH_BYTES; dx++)
+ {
+ const uint8_t dummy = 0;
+ hscan_write(g, &dummy, 1);
+ }
+ }
+ else
+ {
+ block_t *block = &PRIV(g)->g_blocks[PRIV(g)->g_blockmap[by][bx] - 1];
+ hscan_write(g, &block->data[dy][0], WIDTH_BYTES);
+ }
+ }
+ hscan_stop(g);
+
+ vscan_write(g);
+ }
+}
+
+/** Clear the block map, i.e. deallocate all blocks */
+static void clear_block_map(GDisplay *g)
+{
+ unsigned bx, by;
+ for (by = 0; by < BLOCKS_Y; by++)
+ {
+ for (bx = 0; bx < BLOCKS_X; bx++)
+ {
+ PRIV(g)->g_blockmap[by][bx] = 0;
+ }
+ }
+
+ PRIV(g)->g_next_block = 0;
+}
+
+/** Initialize a newly allocated block. */
+static void zero_block(block_t *block)
+{
+ unsigned dx, dy;
+ for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
+ {
+ for (dx = 0; dx < WIDTH_BYTES; dx++)
+ {
+ block->data[dy][dx] = 0;
+ }
+ }
+}
+
+/** Allocate a buffer
+ * Automatically flushes if all buffers are full. */
+static block_t *alloc_buffer(GDisplay *g, unsigned bx, unsigned by)
+{
+ block_t *result;
+ drvPriv *priv;
+
+ priv = PRIV(g);
+ if (priv->g_blockmap[by][bx] == 0)
+ {
+ if (priv->g_next_block >= EINK_NUMBUFFERS)
+ gdisp_lld_flush(g);
+
+ result = &priv->g_blocks[priv->g_next_block];
+ priv->g_blockmap[by][bx] = priv->g_next_block + 1;
+ priv->g_next_block++;
+ zero_block(result);
+ return result;
+ }
+ else
+ {
+ result = &priv->g_blocks[priv->g_blockmap[by][bx] - 1];
+ return result;
+ }
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ g->priv = gfxAlloc(sizeof(drvPriv));
+
+ init_board(g);
+
+ /* Make sure that all the pins are in "off" state.
+ * Having any pin high could cause voltage leaking to the
+ * display, which in turn causes the image to leak slowly away.
+ */
+ power_off(g);
+
+ clear_block_map(g);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = 100;
+ g->g.Contrast = 100;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_FLUSH
+ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+ unsigned by, dy, i;
+
+ for (i = 0; i < EINK_WRITECOUNT; i++) {
+ vscan_start(g);
+
+ for (by = 0; by < BLOCKS_Y; by++) {
+ if (!blocks_on_row(g, by)) {
+ /* Skip the whole row of blocks. */
+ for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
+ vscan_skip(g);
+ } else {
+ /* Write out the blocks. */
+ write_block_row(g, by);
+ }
+ }
+
+ vscan_stop(g);
+ }
+
+ clear_block_map(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ void gdisp_lld_draw_pixel(GDisplay *g) {
+ block_t *block;
+ uint8_t byte;
+ unsigned bx, by, dx, dy;
+ uint8_t bitpos;
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ bx = g->p.x / EINK_BLOCKWIDTH;
+ dx = g->p.x % EINK_BLOCKWIDTH;
+ by = g->p.y / EINK_BLOCKHEIGHT;
+ dy = g->p.y % EINK_BLOCKHEIGHT;
+ break;
+ case GDISP_ROTATE_90:
+ bx = g->p.y / EINK_BLOCKWIDTH;
+ dx = g->p.y % EINK_BLOCKWIDTH;
+ by = (GDISP_SCREEN_HEIGHT-1 - g->p.x) / EINK_BLOCKHEIGHT;
+ dy = (GDISP_SCREEN_HEIGHT-1 - g->p.x) % EINK_BLOCKHEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ bx = (GDISP_SCREEN_WIDTH-1 - g->p.x) / EINK_BLOCKWIDTH;
+ dx = (GDISP_SCREEN_WIDTH-1 - g->p.x) % EINK_BLOCKWIDTH;
+ by = (GDISP_SCREEN_HEIGHT-1 - g->p.y) / EINK_BLOCKHEIGHT;
+ dy = (GDISP_SCREEN_HEIGHT-1 - g->p.y) % EINK_BLOCKHEIGHT;
+ break;
+ case GDISP_ROTATE_270:
+ bx = (GDISP_SCREEN_WIDTH-1 - g->p.y) / EINK_BLOCKWIDTH;
+ dx = (GDISP_SCREEN_WIDTH-1 - g->p.y) % EINK_BLOCKWIDTH;
+ by = g->p.x / EINK_BLOCKHEIGHT;
+ dy = g->p.x % EINK_BLOCKHEIGHT;
+ break;
+ }
+
+ block = alloc_buffer(g, bx, by);
+
+ bitpos = (6 - 2 * (dx % EINK_PPB));
+ byte = block->data[dy][dx / EINK_PPB];
+ byte &= ~(PIXELMASK << bitpos);
+ if (COLOR2NATIVE(g->p.color) != Black)
+ byte |= PIXEL_WHITE << bitpos;
+ else
+ byte |= PIXEL_BLACK << bitpos;
+ block->data[dy][dx / EINK_PPB] = byte;
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerSleep:
+ case powerDeepSleep:
+ gdisp_lld_flush(g);
+ power_off(g);
+ break;
+ case powerOn:
+ power_on(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ default:
+ return;
+ }
+ }
+#endif
+
+/* ===============================
+ * Accelerated routines
+ * =============================== */
+
+#if GDISP_HARDWARE_CLEARS
+ static void subclear(GDisplay *g, color_t color) {
+ unsigned x, y;
+ uint8_t byte;
+
+ hscan_start(g);
+ byte = color ? BYTE_WHITE : BYTE_BLACK;
+ for (x = 0; x < GDISP_SCREEN_WIDTH; x++)
+ {
+ hscan_write(g, &byte, 1);
+ }
+ hscan_stop(g);
+
+ setpin_oe(g, TRUE);
+ vscan_start(g);
+ for (y = 0; y < GDISP_SCREEN_HEIGHT; y++)
+ vscan_bulkwrite(g);
+ vscan_stop(g);
+ setpin_oe(g, FALSE);
+ }
+
+ void gdisp_lld_clear(GDisplay *g) {
+ unsigned i;
+
+ clear_block_map(g);
+
+ if (EINK_BLINKCLEAR) {
+ subclear(g, !g->p.color);
+ gfxSleepMilliseconds(50);
+ }
+
+ for (i = 0; i < EINK_CLEARCOUNT; i++) {
+ subclear(g, g->p.color);
+ gfxSleepMilliseconds(10);
+ }
+ }
+#endif
+
+#endif // GFX_USE_GDISP
diff --git a/drivers/gdisp/ED060SC4/gdisp_lld_config.h b/drivers/gdisp/ED060SC4/gdisp_lld_config.h
index befd997c..47e84779 100644
--- a/drivers/gdisp/ED060SC4/gdisp_lld_config.h
+++ b/drivers/gdisp/ED060SC4/gdisp_lld_config.h
@@ -12,15 +12,12 @@
#if GFX_USE_GDISP
-#define GDISP_DRIVER_NAME "ED060SC4"
+#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS FALSE
-#define GDISP_HARDWARE_BITFILLS FALSE
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_PIXELREAD FALSE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
#endif
diff --git a/drivers/gdisp/ED060SC4/readme.txt b/drivers/gdisp/ED060SC4/readme.txt
index 5409d810..852a0010 100644
--- a/drivers/gdisp/ED060SC4/readme.txt
+++ b/drivers/gdisp/ED060SC4/readme.txt
@@ -38,8 +38,7 @@ result in faster drawing, but also use more RAM on the processor:
After drawing your images, you should flush the buffers using the following
command:
- #include <ed060sc4.h>
- gdispControl(GDISP_CONTROL_FLUSH, 0);
+ gdispFlush();
The buffers are also flushed whenever you turn the display off using:
diff --git a/drivers/gdisp/HX8347D/HX8347D.h b/drivers/gdisp/HX8347D/HX8347D.h
index b35dda12..280cd748 100644
--- a/drivers/gdisp/HX8347D/HX8347D.h
+++ b/drivers/gdisp/HX8347D/HX8347D.h
@@ -33,7 +33,7 @@
#define HX8347D_REG_PSLL 0x0b /* Partial area start row low */
#define HX8347D_REG_PELH 0x0c /* Partial area end row high */
#define HX8347D_REG_PELL 0x0d /* Partial area end row low */
-#define HX8347D_REG_TFAH 0x0e /* Vertical srcoll top fixed area high */
+#define HX8347D_REG_TFAH 0x0e /* Vertical scroll top fixed area high */
#define HX8347D_REG_TFAL 0x0f /* Vertical scroll top fixed area low */
#define HX8347D_REG_VSAH 0x10 /* Vertical scroll height area high */
diff --git a/drivers/gdisp/HX8347D/board_HX8347D_template.h b/drivers/gdisp/HX8347D/board_HX8347D_template.h
new file mode 100644
index 00000000..57ec75f6
--- /dev/null
+++ b/drivers/gdisp/HX8347D/board_HX8347D_template.h
@@ -0,0 +1,156 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/HX8347D/board_HX8347D_template.h
+ * @brief GDISP Graphic Driver subsystem board SPI interface for the HX8347D display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus in 16 bit mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void busmode16(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus in 8 bit mode (the default)
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void busmode8(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint8_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send 8 bits of data to the lcd.
+ * @pre The bus is in 8 bit mode
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint8_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Send 16 bits of data to the lcd.
+ * @pre The bus is in 16 bit mode
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_ram16(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/HX8347D/gdisp_lld.c b/drivers/gdisp/HX8347D/gdisp_lld.c
deleted file mode 100644
index bcb6dfc0..00000000
--- a/drivers/gdisp/HX8347D/gdisp_lld.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/HX8347D/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the HX8347D display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#include "HX8347D.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 320
-#endif
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 240
-#endif
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 50
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-// Some common routines and macros
-#define write_reg(reg, data) { write_index(reg); write_data(data); }
-#define write_ram(color1, color2) { write_index(0x22); write_ram8(color1,color2); }
-#define stream_start() { write_index(0x22); spiStart(&SPID1, &spi1cfg2); }
-#define stream_stop() {while(((SPI1->SR & SPI_SR_TXE) == 0) || ((SPI1->SR & SPI_SR_BSY) != 0));palSetPad(GPIOA, 4);spiStart(&SPID1, &spi1cfg1); }
-#define delay(us) gfxSleepMicroseconds(us)
-#define delayms(ms) gfxSleepMilliseconds(ms)
-
-static inline void set_cursor(coord_t x, coord_t y) {
- write_reg(HX8347D_REG_SCL, (uint8_t) x);
- write_reg(HX8347D_REG_SCH, (uint8_t) (x >> 8));
- write_reg(HX8347D_REG_SPL, (uint8_t) y);
- write_reg(HX8347D_REG_SPH, (uint8_t) (y >> 8));
-}
-
-static void set_viewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- write_reg(HX8347D_REG_SCL, (uint8_t) x);
- write_reg(HX8347D_REG_SCH, (uint8_t) (x >> 8));
- write_reg(HX8347D_REG_ECL, (uint8_t) (x + cx -1));
- write_reg(HX8347D_REG_ECH, (uint8_t) ((x + cx -1) >> 8));
- write_reg(HX8347D_REG_SPL, (uint8_t) y);
- write_reg(HX8347D_REG_SPH, (uint8_t) (y >> 8));
- write_reg(HX8347D_REG_EPL, (uint8_t) (y + cy -1));
- write_reg(HX8347D_REG_EPH, (uint8_t) ((y + cy -1) >> 8));
-}
-
-static inline void reset_viewport(void) {
- set_viewport(0, 0, GDISP.Width, GDISP.Height);
-}
-
-/*===========================================================================*/
-/* 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 */
- init_board();
-
- // Hardware reset
- setpin_reset(TRUE);
- delayms(1);
- setpin_reset(FALSE);
- delayms(5);
-
- // Get the bus for the following initialisation commands
- acquire_bus();
-
- /* Start Initial Sequence ----------------------------------------------------*/
- write_reg(HX8347D_REG_STBAH, 0x00); /* Reset Power Control 1 */
- write_reg(HX8347D_REG_STBAL, 0x20); /* Power Control 2 */
- write_reg(HX8347D_REG_PTBAH, 0x0C); /* Power Control 1 */
- write_reg(HX8347D_REG_PTBAL, 0xC4); /* Power Control 2 */
- write_reg(HX8347D_REG_OPONN, 0x40); /* Source OPON_N */
- write_reg(HX8347D_REG_OPONI, 0x38); /* Source OPON_I */
- write_reg(HX8347D_REG_DC2, 0xA3); /* Display Control 2 */
-
- /* Power On sequence ---------------------------------------------------------*/
- write_reg(HX8347D_REG_PWC2, 0x1B); /* Power Control 2 */
- write_reg(HX8347D_REG_PWC1, 0x01); /* Power Control 1 */
- write_reg(HX8347D_REG_VMH, 0x2F); /* Vcom Control 2 */
- write_reg(HX8347D_REG_VML, 0x57); /* Vcom Control 3 */
- write_reg(HX8347D_REG_VMF, 0x8D); /* Vcom Control 1 */
-
- /* Gamma settings -----------------------------------------------------------*/
- write_reg(HX8347D_REG_VRP0,0x01); // default setup
- write_reg(HX8347D_REG_VRP1,0x0e); //
- write_reg(HX8347D_REG_VRP2,0x11); //
- write_reg(HX8347D_REG_VRP3,0x1a); //
- write_reg(HX8347D_REG_VRP4,0x18); //
- write_reg(HX8347D_REG_VRP5,0x24); //
- write_reg(HX8347D_REG_PRP0,0x15); //
- write_reg(HX8347D_REG_PRP1,0x65); //
- write_reg(HX8347D_REG_PKP0,0x0b); //
- write_reg(HX8347D_REG_PKP1,0x18); //
- write_reg(HX8347D_REG_PKP2,0x19); //
- write_reg(HX8347D_REG_PKP3,0x1a); //
- write_reg(HX8347D_REG_PKP4,0x18); //
- write_reg(HX8347D_REG_VRN0,0x1b); //
- write_reg(HX8347D_REG_VRN1,0x27); //
- write_reg(HX8347D_REG_VRN2,0x25); //
- write_reg(HX8347D_REG_VRN3,0x2e); //
- write_reg(HX8347D_REG_VRN4,0x31); //
- write_reg(HX8347D_REG_VRN5,0x3e); //
- write_reg(HX8347D_REG_PRN0,0x1a); //
- write_reg(HX8347D_REG_PRN1,0x6a); //
- write_reg(HX8347D_REG_PKN0,0x07); //
- write_reg(HX8347D_REG_PKN1,0x05); //
- write_reg(HX8347D_REG_PKN2,0x06); //
- write_reg(HX8347D_REG_PKN3,0x0b); //
- write_reg(HX8347D_REG_PKN4,0x14); //
- write_reg(HX8347D_REG_CGM,0xcc); //
-
- /* Power + Osc ---------------------------------------------------------------*/
- write_reg(HX8347D_REG_OSCCH, 0x36); /* OSC Control 1 */
- write_reg(HX8347D_REG_OSCCL, 0x01); /* OSC Control 2 */
- write_reg(HX8347D_REG_DMODE, 0x00); /* Display Mode Control */
- write_reg(HX8347D_REG_PWC6, 0x88); /* Power Control 6 */
- delayms(5); /* Delay 5 ms */
- write_reg(HX8347D_REG_PWC6, 0x80); /* Power Control 6 */
- delayms(5); /* Delay 5 ms */
- write_reg(HX8347D_REG_PWC6, 0x90); /* Power Control 6 */
- delayms(5); /* Delay 5 ms */
- write_reg(HX8347D_REG_PWC6, 0xD0); /* Power Control 6 */
- delayms(5); /* Delay 5 ms */
- write_reg(HX8347D_REG_COLMOD, 0x05); /* Colmod 16Bit/Pixel */
- write_reg(HX8347D_REG_PCH, 0x00); /* Panel Characteristic */
- write_reg(HX8347D_REG_DC3, 0x38); /* Display Control 3 */
- delayms(40);
- write_reg(HX8347D_REG_DC3, 0x3C); /* Display Control 3 */
- write_reg(HX8347D_REG_MAC, 0x08); /* Memory access control */
-
- write_reg(HX8347D_REG_SCL, 0x00);
- write_reg(HX8347D_REG_SCH, 0x00);
- write_reg(HX8347D_REG_ECL, 0xef);
- write_reg(HX8347D_REG_ECH, 0x00);
- write_reg(HX8347D_REG_SPL, 0x00);
- write_reg(HX8347D_REG_SPH, 0x00);
- write_reg(HX8347D_REG_EPL, 0x3f);
- write_reg(HX8347D_REG_EPH, 0x01);
-
- // Release the bus
- release_bus();
-
- /* Turn on the backlight */
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- acquire_bus();
- set_cursor(x, y);
- write_ram((color >> 8) & 0xFF, color & 0xFF);
- release_bus();
-}
-
-/* ---- 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;
-
- acquire_bus();
- reset_viewport();
- stream_start();
- for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
- write_ram16(color);
- stream_stop();
- release_bus();
- }
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned i, area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
- for(i = 0; i < area; i++)
- write_ram16(color);
- stream_stop();
- release_bus();
- }
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy;
- unsigned lg;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
-
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- buffer += srcx + srcy * srccx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- stream_stop();
- release_bus();
- }
-#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 pixel to be read
- *
- * @notapi
- */
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
- #endif
-}
-#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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, abslines, j;
- static int gap;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- }
-#endif
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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.
- *
- * @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_ORIENTATION:
- if (GDISP.Orientation == (gdisp_orientation_t)value)
- return;
- switch((gdisp_orientation_t)value) {
- case GDISP_ROTATE_0:
- acquire_bus();
- write_reg(HX8347D_REG_MAC, 0x08); /* Memory access control */
- write_reg(HX8347D_REG_ECL, 0xef);
- write_reg(HX8347D_REG_ECH, 0x00);
- write_reg(HX8347D_REG_EPL, 0x3f);
- write_reg(HX8347D_REG_EPH, 0x01);
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_90:
- acquire_bus();
- write_reg(HX8347D_REG_MAC, 0x68); /* Memory access control */
- write_reg(HX8347D_REG_ECL, 0x3f);
- write_reg(HX8347D_REG_ECH, 0x01);
- write_reg(HX8347D_REG_EPL, 0xef);
- write_reg(HX8347D_REG_EPH, 0x00);
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- case GDISP_ROTATE_180:
- acquire_bus();
- write_reg(HX8347D_REG_MAC, 0xc8); /* Memory access control */
- write_reg(HX8347D_REG_ECL, 0xef);
- write_reg(HX8347D_REG_ECH, 0x00);
- write_reg(HX8347D_REG_EPL, 0x3f);
- write_reg(HX8347D_REG_EPH, 0x01);
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_270:
- acquire_bus();
- write_reg(HX8347D_REG_MAC, 0xa8); /* Memory access control */
- write_reg(HX8347D_REG_ECL, 0x3f);
- write_reg(HX8347D_REG_ECH, 0x01);
- write_reg(HX8347D_REG_EPL, 0xef);
- write_reg(HX8347D_REG_EPH, 0x00);
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- default:
- return;
- }
-
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-
- case GDISP_CONTROL_BACKLIGHT:
- if ((unsigned)value > 100)
- value = (void *)100;
- set_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- return;
-
- default:
- return;
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/HX8347D/gdisp_lld.mk b/drivers/gdisp/HX8347D/gdisp_lld.mk
index fed905e1..581e53e7 100644
--- a/drivers/gdisp/HX8347D/gdisp_lld.mk
+++ b/drivers/gdisp/HX8347D/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/HX8347D/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/HX8347D
+GFXSRC += $(GFXLIB)/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c
diff --git a/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c b/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c
new file mode 100644
index 00000000..4514b495
--- /dev/null
+++ b/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c
@@ -0,0 +1,236 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/HX8347D/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the HX8347D display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_HX8347D
+#include "../drivers/gdisp/HX8347D/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_HX8347D.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+#include "../drivers/gdisp/HX8347D/HX8347D.h"
+
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+
+static inline void set_viewport(GDisplay* g) {
+ write_reg(g, HX8347D_REG_SCL, g->p.x);
+ write_reg(g, HX8347D_REG_SCH, g->p.x >> 8);
+ write_reg(g, HX8347D_REG_ECL, g->p.x + g->p.cx -1);
+ write_reg(g, HX8347D_REG_ECH, (g->p.x + g->p.cx -1) >> 8);
+ write_reg(g, HX8347D_REG_SPL, g->p.y);
+ write_reg(g, HX8347D_REG_SPH, g->p.y >> 8);
+ write_reg(g, HX8347D_REG_EPL, g->p.y + g->p.cy -1);
+ write_reg(g, HX8347D_REG_EPH, (g->p.y + g->p.cy -1) >> 8);
+ write_index(g, HX8347D_REG_SRAMWC);
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(1);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(5);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ /* Start Initial Sequence ----------------------------------------------------*/
+ write_reg(g, HX8347D_REG_STBAH, 0x00); /* Reset Power Control 1 */
+ write_reg(g, HX8347D_REG_STBAL, 0x20); /* Power Control 2 */
+ write_reg(g, HX8347D_REG_PTBAH, 0x0C); /* Power Control 1 */
+ write_reg(g, HX8347D_REG_PTBAL, 0xC4); /* Power Control 2 */
+ write_reg(g, HX8347D_REG_OPONN, 0x40); /* Source OPON_N */
+ write_reg(g, HX8347D_REG_OPONI, 0x38); /* Source OPON_I */
+ write_reg(g, HX8347D_REG_DC2, 0xA3); /* Display Control 2 */
+
+ /* Power On sequence ---------------------------------------------------------*/
+ write_reg(g, HX8347D_REG_PWC2, 0x1B); /* Power Control 2 */
+ write_reg(g, HX8347D_REG_PWC1, 0x01); /* Power Control 1 */
+ write_reg(g, HX8347D_REG_VMH, 0x2F); /* Vcom Control 2 */
+ write_reg(g, HX8347D_REG_VML, 0x57); /* Vcom Control 3 */
+ write_reg(g, HX8347D_REG_VMF, 0x8D); /* Vcom Control 1 */
+
+ /* Gamma settings -----------------------------------------------------------*/
+ write_reg(g, HX8347D_REG_VRP0, 0x01); // default setup
+ write_reg(g, HX8347D_REG_VRP1, 0x0e); //
+ write_reg(g, HX8347D_REG_VRP2, 0x11); //
+ write_reg(g, HX8347D_REG_VRP3, 0x1a); //
+ write_reg(g, HX8347D_REG_VRP4, 0x18); //
+ write_reg(g, HX8347D_REG_VRP5, 0x24); //
+ write_reg(g, HX8347D_REG_PRP0, 0x15); //
+ write_reg(g, HX8347D_REG_PRP1, 0x65); //
+ write_reg(g, HX8347D_REG_PKP0, 0x0b); //
+ write_reg(g, HX8347D_REG_PKP1, 0x18); //
+ write_reg(g, HX8347D_REG_PKP2, 0x19); //
+ write_reg(g, HX8347D_REG_PKP3, 0x1a); //
+ write_reg(g, HX8347D_REG_PKP4, 0x18); //
+ write_reg(g, HX8347D_REG_VRN0, 0x1b); //
+ write_reg(g, HX8347D_REG_VRN1, 0x27); //
+ write_reg(g, HX8347D_REG_VRN2, 0x25); //
+ write_reg(g, HX8347D_REG_VRN3, 0x2e); //
+ write_reg(g, HX8347D_REG_VRN4, 0x31); //
+ write_reg(g, HX8347D_REG_VRN5, 0x3e); //
+ write_reg(g, HX8347D_REG_PRN0, 0x1a); //
+ write_reg(g, HX8347D_REG_PRN1, 0x6a); //
+ write_reg(g, HX8347D_REG_PKN0, 0x07); //
+ write_reg(g, HX8347D_REG_PKN1, 0x05); //
+ write_reg(g, HX8347D_REG_PKN2, 0x06); //
+ write_reg(g, HX8347D_REG_PKN3, 0x0b); //
+ write_reg(g, HX8347D_REG_PKN4, 0x14); //
+ write_reg(g, HX8347D_REG_CGM, 0xcc); //
+
+ /* Power + Osc ---------------------------------------------------------------*/
+ write_reg(g, HX8347D_REG_OSCCH, 0x36); /* OSC Control 1 */
+ write_reg(g, HX8347D_REG_OSCCL, 0x01); /* OSC Control 2 */
+ write_reg(g, HX8347D_REG_DMODE, 0x00); /* Display Mode Control */
+ write_reg(g, HX8347D_REG_PWC6, 0x88); /* Power Control 6 */
+ gfxSleepMilliseconds(5); /* Delay 5 ms */
+ write_reg(g, HX8347D_REG_PWC6, 0x80); /* Power Control 6 */
+ gfxSleepMilliseconds(5); /* Delay 5 ms */
+ write_reg(g, HX8347D_REG_PWC6, 0x90); /* Power Control 6 */
+ gfxSleepMilliseconds(5); /* Delay 5 ms */
+ write_reg(g, HX8347D_REG_PWC6, 0xD0); /* Power Control 6 */
+ gfxSleepMilliseconds(5); /* Delay 5 ms */
+ write_reg(g, HX8347D_REG_COLMOD, 0x05); /* Colmod 16Bit/Pixel */
+ write_reg(g, HX8347D_REG_PCH, 0x00); /* Panel Characteristic */
+ write_reg(g, HX8347D_REG_DC3, 0x38); /* Display Control 3 */
+ gfxSleepMilliseconds(40); /* Delay 40 ms */
+ write_reg(g, HX8347D_REG_DC3, 0x3C); /* Display Control 3 */
+ write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the backlight */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ busmode16(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_ram16(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ busmode8(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, HX8347D_REG_MAC, 0x68); /* Memory access control */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, HX8347D_REG_MAC, 0xc8); /* Memory access control */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, HX8347D_REG_MAC, 0xa8); /* Memory access control */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/HX8347D/gdisp_lld_board_st_stm32f4_discovery.h b/drivers/gdisp/HX8347D/gdisp_lld_board_st_stm32f4_discovery.h
deleted file mode 100644
index 984b92dd..00000000
--- a/drivers/gdisp/HX8347D/gdisp_lld_board_st_stm32f4_discovery.h
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/HX8347D/gdisp_lld_board_st_stm32f4_discovery.h
- * @brief GDISP Graphic Driver subsystem board SPI interface for the HX8347D display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define SET_RST palSetPad(GPIOB, 8);
-#define CLR_RST palClearPad(GPIOB, 8);
-
-/* PWM configuration structure. We use timer 4 channel 2 (orange LED on board). */
-static const PWMConfig pwmcfg = {
- 1000000, /* 1 MHz PWM clock frequency. */
- 100, /* PWM period is 100 cycles. */
- NULL,
- {
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL}
- },
- 0
-};
-
-/*
- * SPI1 configuration structure.
- * Speed 42MHz, CPHA=0, CPOL=0, 8bits frames, MSb transmitted first.
- * The slave select line is the pin 4 on the port GPIOA.
- */
-static const SPIConfig spi1cfg1 = {
- NULL,
- /* HW dependent part.*/
- GPIOA,
- 4,
- 0 //SPI_CR1_BR_0
-};
-
-/*
- * SPI1 configuration structure.
- * Speed 42MHz, CPHA=0, CPOL=0, 16bits frames, MSb transmitted first.
- * The slave select line is the pin 4 on the port GPIOA.
- */
-static const SPIConfig spi1cfg2 = {
- NULL,
- /* HW dependent part.*/
- GPIOA,
- 4,
- SPI_CR1_DFF //SPI_CR1_BR_0
-};
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
-
- /* Display backlight control */
- /* TIM4 is an alternate function 2 (AF2) */
- pwmStart(&PWMD4, &pwmcfg);
- palSetPadMode(GPIOD, 13, PAL_MODE_ALTERNATE(2));
- pwmEnableChannel(&PWMD4, 1, 100);
-
- palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL |
- PAL_STM32_OSPEED_HIGHEST); /* RST */
- palSetPadMode(GPIOB, 9, PAL_MODE_OUTPUT_PUSHPULL |
- PAL_STM32_OSPEED_HIGHEST); /* RS */
- /*
- * Initializes the SPI driver 1. The SPI1 signals are routed as follow:
- * PB12 - NSS.
- * PB13 - SCK.
- * PB14 - MISO.
- * PB15 - MOSI.
- */
- spiStart(&SPID1, &spi1cfg1);
- palSetPad(GPIOA, 4);
- palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL |
- PAL_STM32_OSPEED_HIGHEST); /* NSS. */
- palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) |
- PAL_STM32_OSPEED_HIGHEST); /* SCK. */
- palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5)); /* MISO. */
- palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) |
- PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- if (state) {
- CLR_RST;
- } else {
- SET_RST;
- }
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- pwmEnableChannel(&PWMD4, 1, percent);
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- spiAcquireBus(&SPID1);
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void release_bus(void) {
- spiReleaseBus(&SPID1);
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint8_t cmd) {
- palClearPad(GPIOB, 9);
- palClearPad(GPIOA, 4);
- while((SPI1->SR & SPI_SR_TXE) == 0);
- SPI1->DR = cmd;
- while(((SPI1->SR & SPI_SR_TXE) == 0) || ((SPI1->SR & SPI_SR_BSY) != 0));
- palSetPad(GPIOB, 9);
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint8_t data) {
- SPI1->DR = data;
- while(((SPI1->SR & SPI_SR_TXE) == 0) || ((SPI1->SR & SPI_SR_BSY) != 0));
- palSetPad(GPIOA, 4);
-}
-
-static inline void write_ram8(uint8_t data1, uint8_t data2) {
- SPI1->DR = data1;
- while((SPI1->SR & SPI_SR_TXE) == 0);
- SPI1->DR = data2;
- while(((SPI1->SR & SPI_SR_TXE) == 0) || ((SPI1->SR & SPI_SR_BSY) != 0));
- palSetPad(GPIOA, 4);
-}
-
-static inline void write_ram16(uint16_t data) {
- while((SPI1->SR & SPI_SR_TXE) == 0);
- SPI1->DR = data;
-}
-
-#if GDISP_HARDWARE_READPIXEL || 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 read_data(void) {
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/HX8347D/gdisp_lld_board_template.h b/drivers/gdisp/HX8347D/gdisp_lld_board_template.h
deleted file mode 100644
index 295a7997..00000000
--- a/drivers/gdisp/HX8347D/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/HX8347D/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board SPI interface for the HX8347D display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint8_t cmd) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint8_t data) {
-
-
-
-}
-
-static inline void write_ram8(uint8_t data1, uint8_t data2) {
-
-}
-
-static inline void write_ram16(uint16_t data) {
-
-}
-
-#if GDISP_HARDWARE_READPIXEL || 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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/HX8347D/gdisp_lld_config.h b/drivers/gdisp/HX8347D/gdisp_lld_config.h
index 7bf47ade..ab4c8639 100644
--- a/drivers/gdisp/HX8347D/gdisp_lld_config.h
+++ b/drivers/gdisp/HX8347D/gdisp_lld_config.h
@@ -22,16 +22,10 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "HX8347D"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_PIXELREAD FALSE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9320/board_ILI9320_template.h b/drivers/gdisp/ILI9320/board_ILI9320_template.h
new file mode 100644
index 00000000..6f5ad16d
--- /dev/null
+++ b/drivers/gdisp/ILI9320/board_ILI9320_template.h
@@ -0,0 +1,157 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9320/board_ILI9320_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the ILI9320 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef GDISP_LLD_BOARD_H
+#define GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note The chip select may need to be asserted/de-asserted
+ * around the actual spi read
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+#endif /* GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/ILI9320/gdisp_lld.c b/drivers/gdisp/ILI9320/gdisp_lld.c
deleted file mode 100644
index c432cd35..00000000
--- a/drivers/gdisp/ILI9320/gdisp_lld.c
+++ /dev/null
@@ -1,584 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9320/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the ILI9320 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#include "gdisp_lld_board.h"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-/* This controller is only ever used with a 240 x 320 display */
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-
-#define GDISP_SCREEN_WIDTH 240
-#define GDISP_SCREEN_HEIGHT 320
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-uint32_t DISPLAY_CODE;
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-static inline void lld_lcdDelay(uint16_t us) {
- gfxSleepMicroseconds(us);
-}
-
-static inline void lld_lcdWriteIndex(uint16_t index) {
- gdisp_lld_write_index(index);
-}
-
-static inline void lld_lcdWriteData(uint16_t data) {
- gdisp_lld_write_data(data);
-}
-
-static inline void lld_lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue) {
- gdisp_lld_write_index(lcdReg);
- gdisp_lld_write_data(lcdRegValue);
-}
-
-static inline uint16_t lld_lcdReadData(void) {
- return gdisp_lld_read_data();
-}
-
-static inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
- volatile uint16_t dummy;
-
- gdisp_lld_write_index(lcdReg);
- dummy = lld_lcdReadData();
- (void)dummy;
-
- return lld_lcdReadData();
-}
-
-static inline void lld_lcdWriteStreamStart(void) {
- lld_lcdWriteIndex(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++)
- lld_lcdWriteData(buffer[i]);
-}
-
-static inline void lld_lcdReadStreamStart(void) {
- lld_lcdWriteIndex(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 = lld_lcdReadData();
- (void)dummy;
-
- for(i = 0; i < size; i++)
- buffer[i] = lld_lcdReadData();
-}
-
-bool_t gdisp_lld_init(void) {
- /* Initialise your display */
- gdisp_lld_init_board();
-
- /* Hardware reset */
- gdisp_lld_reset_pin(TRUE);
- lld_lcdDelay(1000);
- gdisp_lld_reset_pin(FALSE);
- lld_lcdDelay(1000);
-
- DISPLAY_CODE = lld_lcdReadReg(0);
- lld_lcdWriteReg(0x0000, 0x0001); //start Int. osc
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0001, 0x0100); //Set SS bit (shift direction of outputs is from S720 to S1)
- lld_lcdWriteReg(0x0002, 0x0700); //select the line inversion
- lld_lcdWriteReg(0x0003, 0x1038); //Entry mode(Horizontal : increment,Vertical : increment, AM=1)
- lld_lcdWriteReg(0x0004, 0x0000); //Resize control(No resizing)
- lld_lcdWriteReg(0x0008, 0x0202); //front and back porch 2 lines
- lld_lcdWriteReg(0x0009, 0x0000); //select normal scan
- lld_lcdWriteReg(0x000A, 0x0000); //display control 4
- lld_lcdWriteReg(0x000C, 0x0000); //system interface(2 transfer /pixel), internal sys clock,
- lld_lcdWriteReg(0x000D, 0x0000); //Frame marker position
- lld_lcdWriteReg(0x000F, 0x0000); //selects clk, enable and sync signal polarity,
- lld_lcdWriteReg(0x0010, 0x0000); //
- lld_lcdWriteReg(0x0011, 0x0000); //power control 2 reference voltages = 1:1,
- lld_lcdWriteReg(0x0012, 0x0000); //power control 3 VRH
- lld_lcdWriteReg(0x0013, 0x0000); //power control 4 VCOM amplitude
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0010, 0x17B0); //power control 1 BT,AP
- lld_lcdWriteReg(0x0011, 0x0137); //power control 2 DC,VC
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0012, 0x0139); //power control 3 VRH
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0013, 0x1d00); //power control 4 vcom amplitude
- lld_lcdWriteReg(0x0029, 0x0011); //power control 7 VCOMH
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0030, 0x0007);
- lld_lcdWriteReg(0x0031, 0x0403);
- lld_lcdWriteReg(0x0032, 0x0404);
- lld_lcdWriteReg(0x0035, 0x0002);
- lld_lcdWriteReg(0x0036, 0x0707);
- lld_lcdWriteReg(0x0037, 0x0606);
- lld_lcdWriteReg(0x0038, 0x0106);
- lld_lcdWriteReg(0x0039, 0x0007);
- lld_lcdWriteReg(0x003c, 0x0700);
- lld_lcdWriteReg(0x003d, 0x0707);
- lld_lcdWriteReg(0x0020, 0x0000); //starting Horizontal GRAM Address
- lld_lcdWriteReg(0x0021, 0x0000); //starting Vertical GRAM Address
- lld_lcdWriteReg(0x0050, 0x0000); //Horizontal GRAM Start Position
- lld_lcdWriteReg(0x0051, 0x00EF); //Horizontal GRAM end Position
- lld_lcdWriteReg(0x0052, 0x0000); //Vertical GRAM Start Position
- lld_lcdWriteReg(0x0053, 0x013F); //Vertical GRAM end Position
- switch (DISPLAY_CODE) {
- case 0x9320:
- lld_lcdWriteReg(0x0060, 0x2700); //starts scanning from G1, and 320 drive lines
- break;
- case 0x9325:
- lld_lcdWriteReg(0x0060, 0xA700); //starts scanning from G1, and 320 drive lines
- break;
- }
-
- lld_lcdWriteReg(0x0061, 0x0001); //fixed base display
- lld_lcdWriteReg(0x006a, 0x0000); //no scroll
- lld_lcdWriteReg(0x0090, 0x0010); //set Clocks/Line =16, Internal Operation Clock Frequency=fosc/1,
- lld_lcdWriteReg(0x0092, 0x0000); //set gate output non-overlap period=0
- lld_lcdWriteReg(0x0093, 0x0003); //set Source Output Position=3
- lld_lcdWriteReg(0x0095, 0x0110); //RGB interface(Clocks per line period=16 clocks)
- lld_lcdWriteReg(0x0097, 0x0110); //set Gate Non-overlap Period 0 locksc
- lld_lcdWriteReg(0x0098, 0x0110); //
- lld_lcdWriteReg(0x0007, 0x0173); //display On
-
- // Turn on the backlight
- gdisp_lld_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
-
- return TRUE;
-}
-
-static void lld_lcdSetCursor(uint16_t x, uint16_t y) {
-
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- lld_lcdWriteReg(0x0020, x);
- lld_lcdWriteReg(0x0021, y);
- break;
-
- case GDISP_ROTATE_90:
- lld_lcdWriteReg(0x0020, y);
- lld_lcdWriteReg(0x0021, x);
- break;
-
- case GDISP_ROTATE_180:
- lld_lcdWriteReg(0x0020, x);
- lld_lcdWriteReg(0x0021, y);
- break;
-
- case GDISP_ROTATE_270:
- lld_lcdWriteReg(0x0020, y);
- lld_lcdWriteReg(0x0021, x);
- break;
- }
-}
-
-static void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- lld_lcdWriteReg(0x0050, x);
- lld_lcdWriteReg(0x0051, x + cx - 1);
- lld_lcdWriteReg(0x0052, y);
- lld_lcdWriteReg(0x0053, y + cy - 1);
- break;
-
- case GDISP_ROTATE_90:
- lld_lcdWriteReg(0x0050, y);
- lld_lcdWriteReg(0x0051, y + cy - 1);
- lld_lcdWriteReg(0x0052, x);
- lld_lcdWriteReg(0x0053, x + cx - 1);
- break;
-
- case GDISP_ROTATE_180:
- lld_lcdWriteReg(0x0050, x);
- lld_lcdWriteReg(0x0051, x + cx - 1);
- lld_lcdWriteReg(0x0052, y);
- lld_lcdWriteReg(0x0053, y + cy - 1);
- break;
-
- case GDISP_ROTATE_270:
- lld_lcdWriteReg(0x0050, y);
- lld_lcdWriteReg(0x0051, y + cy - 1);
- lld_lcdWriteReg(0x0052, x);
- lld_lcdWriteReg(0x0053, x + cx - 1);
- break;
- }
-
- lld_lcdSetCursor(x, y);
-}
-
-static inline void lld_lcdResetViewPort(void) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- case GDISP_ROTATE_180:
- lld_lcdSetViewPort(0, 0, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
- break;
- case GDISP_ROTATE_90:
- case GDISP_ROTATE_270:
- lld_lcdSetViewPort(0, 0, GDISP_SCREEN_HEIGHT, GDISP_SCREEN_WIDTH);
- break;
- }
-}
-
-void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
- lld_lcdSetCursor(x, y);
- lld_lcdWriteReg(0x0022, color);
-}
-
-#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__)
- void gdisp_lld_clear(color_t color) {
- unsigned i;
-
- lld_lcdSetCursor(0, 0);
- lld_lcdWriteStreamStart();
-
- for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
- lld_lcdWriteData(color);
-
- lld_lcdWriteStreamStop();
- }
-#endif
-
-#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__)
- void gdisp_lld_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - 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__)
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy;
- unsigned lg;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- lld_lcdSetViewPort(x, y, cx, cy);
- lld_lcdWriteStreamStart();
-
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- buffer += srcx + srcy * srccx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- lld_lcdWriteData(*buffer++);
- lld_lcdWriteStreamStop();
- lld_lcdResetViewPort();
- }
-#endif
-
-#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__)
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || 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__)
- void gdisp_lld_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, gap, abslines;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- abslines = lines < 0 ? -lines : lines;
-
- 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_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- 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:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000);
- lld_lcdWriteReg(0x0010, 0x0000);
- lld_lcdWriteReg(0x0011, 0x0000);
- lld_lcdWriteReg(0x0012, 0x0000);
- lld_lcdWriteReg(0x0013, 0x0000);
- release_bus();
-
- gdisp_lld_backlight(0);
- break;
-
- case powerOn:
- //*************Power On sequence ******************//
- acquire_bus();
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
- lld_lcdWriteReg(0x0011, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0012, 0x013C); /* VREG1OUT voltage */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0013, 0x0E00); /* VDV[4:0] for VCOM amplitude */
- lld_lcdWriteReg(0x0029, 0x0009); /* VCM[4:0] for VCOMH */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */
- release_bus();
-
- gdisp_lld_backlight(GDISP.Backlight);
- if(GDISP.Powermode != powerSleep || GDISP.Powermode != powerDeepSleep)
- gdisp_lld_init();
- break;
-
- case powerSleep:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- release_bus();
-
- gdisp_lld_backlight(0);
- break;
-
- case powerDeepSleep:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- release_bus();
-
- gdisp_lld_backlight(0);
- 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 GDISP_ROTATE_0:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0100);
- lld_lcdWriteReg(0x0003, 0x1038);
- lld_lcdWriteReg(0x0060, 0x2700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_90:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0100);
- lld_lcdWriteReg(0x0003, 0x1030);
- lld_lcdWriteReg(0x0060, 0x2700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- case GDISP_ROTATE_180:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0000);
- lld_lcdWriteReg(0x0003, 0x1030);
- lld_lcdWriteReg(0x0060, 0x2700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_270:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0000);
- lld_lcdWriteReg(0x0003, 0x1038);
- lld_lcdWriteReg(0x0060, 0xA700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- default:
- return;
- }
-
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-
- case GDISP_CONTROL_BACKLIGHT:
- if((unsigned)value > 100) value = (void *)100;
- gdisp_lld_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- break;
-
- default:
- return;
- }
- }
-
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9320/gdisp_lld.mk b/drivers/gdisp/ILI9320/gdisp_lld.mk
index bcdd3230..d61fbc33 100644
--- a/drivers/gdisp/ILI9320/gdisp_lld.mk
+++ b/drivers/gdisp/ILI9320/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9320/gdisp_lld.c
-
-# Required include directories
-GFXINC += $(GFXLIB)/drivers/gdisp/ILI9320
+GFXINC += $(GFXLIB)/drivers/gdisp/ILI9320
+GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c b/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c
new file mode 100644
index 00000000..e65e0a77
--- /dev/null
+++ b/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c
@@ -0,0 +1,380 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9320/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the ILI9320 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+/* This controller is only ever used with a 240 x 320 display */
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_ILI9320
+#include "../drivers/gdisp/ILI9320/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ILI9320.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+
+static void set_cursor(GDisplay *g) {
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x20, g->p.x);
+ write_reg(g, 0x21, g->p.y);
+ break;
+
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x20, g->p.y);
+ write_reg(g, 0x21, g->p.x);
+ break;
+ }
+ write_index(g, 0x22);
+}
+
+static void set_viewport(GDisplay *g) {
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x50, g->p.x);
+ write_reg(g, 0x51, g->p.x + g->p.cx - 1);
+ write_reg(g, 0x52, g->p.y);
+ write_reg(g, 0x53, g->p.y + g->p.cy - 1);
+ break;
+
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x50, g->p.y);
+ write_reg(g, 0x51, g->p.y + g->p.cy - 1);
+ write_reg(g, 0x52, g->p.x);
+ write_reg(g, 0x53, g->p.x + g->p.cx - 1);
+ break;
+ }
+}
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ uint16_t cver;
+
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ /* Hardware reset */
+ setpin_reset(g, TRUE);
+ gfxSleepMicroseconds(1000);
+ setpin_reset(g, FALSE);
+ gfxSleepMicroseconds(1000);
+
+ acquire_bus(g);
+ write_index(g, 0); // Get controller version
+ setreadmode(g);
+ dummy_read(g);
+ cver = read_data(g);
+ setwritemode(g);
+ write_reg(g, 0x00, 0x0001); //start Int. osc
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x01, 0x0100); //Set SS bit (shift direction of outputs is from S720 to S1)
+ write_reg(g, 0x02, 0x0700); //select the line inversion
+ write_reg(g, 0x03, 0x1038); //Entry mode(Horizontal : increment,Vertical : increment, AM=1)
+ write_reg(g, 0x04, 0x0000); //Resize control(No resizing)
+ write_reg(g, 0x08, 0x0202); //front and back porch 2 lines
+ write_reg(g, 0x09, 0x0000); //select normal scan
+ write_reg(g, 0x0A, 0x0000); //display control 4
+ write_reg(g, 0x0C, 0x0000); //system interface(2 transfer /pixel), internal sys clock,
+ write_reg(g, 0x0D, 0x0000); //Frame marker position
+ write_reg(g, 0x0F, 0x0000); //selects clk, enable and sync signal polarity,
+ write_reg(g, 0x10, 0x0000); //
+ write_reg(g, 0x11, 0x0000); //power control 2 reference voltages = 1:1,
+ write_reg(g, 0x12, 0x0000); //power control 3 VRH
+ write_reg(g, 0x13, 0x0000); //power control 4 VCOM amplitude
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x10, 0x17B0); //power control 1 BT,AP
+ write_reg(g, 0x11, 0x0137); //power control 2 DC,VC
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x12, 0x0139); //power control 3 VRH
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x13, 0x1d00); //power control 4 vcom amplitude
+ write_reg(g, 0x29, 0x0011); //power control 7 VCOMH
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x30, 0x0007);
+ write_reg(g, 0x31, 0x0403);
+ write_reg(g, 0x32, 0x0404);
+ write_reg(g, 0x35, 0x0002);
+ write_reg(g, 0x36, 0x0707);
+ write_reg(g, 0x37, 0x0606);
+ write_reg(g, 0x38, 0x0106);
+ write_reg(g, 0x39, 0x0007);
+ write_reg(g, 0x3c, 0x0700);
+ write_reg(g, 0x3d, 0x0707);
+ write_reg(g, 0x20, 0x0000); //starting Horizontal GRAM Address
+ write_reg(g, 0x21, 0x0000); //starting Vertical GRAM Address
+ write_reg(g, 0x50, 0x0000); //Horizontal GRAM Start Position
+ write_reg(g, 0x51, 0x00EF); //Horizontal GRAM end Position
+ write_reg(g, 0x52, 0x0000); //Vertical GRAM Start Position
+ write_reg(g, 0x53, 0x013F); //Vertical GRAM end Position
+ switch (cver) {
+ case 0x9320:
+ write_reg(g, 0x60, 0x2700); //starts scanning from G1, and 320 drive lines
+ break;
+ case 0x9325:
+ write_reg(g, 0x60, 0xA700); //starts scanning from G1, and 320 drive lines
+ break;
+ }
+
+ write_reg(g, 0x61, 0x0001); //fixed base display
+ write_reg(g, 0x6a, 0x0000); //no scroll
+ write_reg(g, 0x90, 0x0010); //set Clocks/Line =16, Internal Operation Clock Frequency=fosc/1,
+ write_reg(g, 0x92, 0x0000); //set gate output non-overlap period=0
+ write_reg(g, 0x93, 0x0003); //set Source Output Position=3
+ write_reg(g, 0x95, 0x0110); //RGB interface(Clocks per line period=16 clocks)
+ write_reg(g, 0x97, 0x0110); //set Gate Non-overlap Period 0 locksc
+ write_reg(g, 0x98, 0x0110); //
+ write_reg(g, 0x07, 0x0173); //display On
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ // Turn on the backlight
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ #if !GDISP_HARDWARE_STREAM_POS
+ set_cursor(g);
+ #endif
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+ #if GDISP_HARDWARE_STREAM_POS
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ set_cursor(g);
+ }
+ #endif
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000);
+ write_reg(g, 0x10, 0x0000);
+ write_reg(g, 0x11, 0x0000);
+ write_reg(g, 0x12, 0x0000);
+ write_reg(g, 0x13, 0x0000);
+ release_bus(g);
+
+ set_backlight(g, 0);
+ break;
+
+ case powerOn:
+ //*************Power On sequence ******************//
+ acquire_bus(g);
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ write_reg(g, 0x11, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x12, 0x013C); /* VREG1OUT voltage */
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x13, 0x0E00); /* VDV[4:0] for VCOM amplitude */
+ write_reg(g, 0x29, 0x0009); /* VCM[4:0] for VCOMH */
+ gfxSleepMicroseconds(500);
+ write_reg(g, 0x07, 0x0173); /* 262K color and display ON */
+ release_bus(g);
+
+ set_backlight(g, g->g.Backlight);
+ break;
+
+ case powerSleep:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000); /* display OFF */
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ release_bus(g);
+
+ set_backlight(g, 0);
+ break;
+
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000); /* display OFF */
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMicroseconds(2000); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ release_bus(g);
+
+ set_backlight(g, 0);
+ break;
+
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0100);
+ write_reg(g, 0x03, 0x1038);
+ write_reg(g, 0x60, 0x2700);
+ release_bus(g);
+
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0100);
+ write_reg(g, 0x03, 0x1030);
+ write_reg(g, 0x60, 0x2700);
+ release_bus(g);
+
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0000);
+ write_reg(g, 0x03, 0x1030);
+ write_reg(g, 0x60, 0x2700);
+ release_bus(g);
+
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0000);
+ write_reg(g, 0x03, 0x1038);
+ write_reg(g, 0x60, 0xA700);
+ release_bus(g);
+
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_pic32mx_lcd.h b/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_pic32mx_lcd.h
deleted file mode 100644
index 177a7cd8..00000000
--- a/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_pic32mx_lcd.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9320/gdisp_lld_board_olimex_pic32mx_lcd.h
- * @brief GDISP Graphic Driver subsystem board interface for the ILI9325 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_BOARD_H
-#define GDISP_LLD_BOARD_H
-
-#ifndef noinline
-#define noinline __attribute__((noinline))
-#endif
-
-static void gdisp_lld_init_board(void) {
- // RST
- palSetPadMode(IOPORTA, 7, PAL_MODE_OUTPUT);
- palClearPad(IOPORTA, 7);
-
- // RS
- palSetPadMode(IOPORTA, 10, PAL_MODE_OUTPUT);
- palSetPad(IOPORTA, 10);
-
- // CS
- palSetPadMode(IOPORTA, 9, PAL_MODE_OUTPUT);
- palClearPad(IOPORTA, 9);
-
- // Backlight
- palSetPadMode(IOPORTD, 3, PAL_MODE_OUTPUT);
- palSetPad(IOPORTD, 3);
-
- // PMP setup
- PMMODE = 0;
- PMAEN = 0;
- PMCON = 0;
- PMMODEbits.MODE = 2;
- PMMODEbits.WAITB = 0;
- PMMODEbits.WAITM = 1;
- PMMODEbits.WAITE = 0;
- PMCONbits.CSF = 0;
- PMCONbits.PTRDEN = 1;
- PMCONbits.PTWREN = 1;
- PMMODEbits.MODE16 = 1;
- PMCONbits.PMPEN = 1;
-
- palClearPad(IOPORTA, 9);
-}
-
-#define PmpWaitBusy() do {} while (PMMODEbits.BUSY)
-
-static noinline void gdisp_lld_reset_pin(bool_t state) {
- if (state)
- palClearPad(IOPORTA, 7);
- else
- palSetPad(IOPORTA, 7);
-}
-
-static noinline void gdisp_lld_write_index(uint16_t data) {
- volatile uint16_t dummy;
-
- PmpWaitBusy();
- palClearPad(IOPORTA, 10);
- PMDIN = data;
- PmpWaitBusy();
- palSetPad(IOPORTA, 10);
-
- dummy = PMDIN;
- (void)dummy;
-}
-
-static noinline void gdisp_lld_write_data(uint16_t data) {
- PMDIN = data;
- PmpWaitBusy();
-}
-
-static noinline uint16_t gdisp_lld_read_data(void) {
- PmpWaitBusy();
- return PMDIN;
-}
-
-/* if not available, just ignore the argument and return */
-static void gdisp_lld_backlight(uint8_t percentage) {
- if (percentage)
- palClearPad(IOPORTD, 3);
- else
- palSetPad(IOPORTD, 3);
-}
-
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-#endif /* GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_stm32_lcd.h b/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_stm32_lcd.h
deleted file mode 100644
index 0d9f8364..00000000
--- a/drivers/gdisp/ILI9320/gdisp_lld_board_olimex_stm32_lcd.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9320/gdisp_lld_board_olimex_stm32_lcd.h
- * @brief GDISP Graphic Driver subsystem board interface for the ILI9320 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_BOARD_H
-#define GDISP_LLD_BOARD_H
-
-#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
-#define GDISP_RAM (*((volatile uint16_t *) 0x60100000)) /* RS = 1 */
-
-static inline void gdisp_lld_init_board(void) {
- /* FSMC setup for F1 */
- rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
-
- /* set pin modes */
- IOBus busD = {GPIOD, PAL_WHOLE_PORT, 0};
- IOBus busE = {GPIOE, PAL_WHOLE_PORT, 0};
- palSetBusMode(&busD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetBusMode(&busE, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetPadMode(GPIOE, GPIOE_TFT_RST, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, GPIOD_TFT_LIGHT, PAL_MODE_OUTPUT_PUSHPULL);
-
- const unsigned char FSMC_Bank = 0;
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = (6) | (10 << 8) | (10 << 16);
-
- /* Bank1 NOR/SRAM control register configuration
- * This is actually not needed as already set by default after reset */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-}
-
-static inline void gdisp_lld_reset_pin(bool_t state) {
- if(state)
- palClearPad(GPIOE, GPIOE_TFT_RST);
- else
- palSetPad(GPIOE, GPIOE_TFT_RST);
-}
-
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-static inline void gdisp_lld_write_index(uint16_t reg) {
- GDISP_REG = reg;
-}
-
-static inline void gdisp_lld_write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-static inline uint16_t gdisp_lld_read_data(void) {
- return GDISP_RAM;
-}
-
-static inline void gdisp_lld_backlight(uint8_t percent) {
- if(percent == 100)
- palClearPad(GPIOD, GPIOD_TFT_LIGHT);
- else
- palSetPad(GPIOD, GPIOD_TFT_LIGHT);
-}
-
-#endif /* GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_board_template.h b/drivers/gdisp/ILI9320/gdisp_lld_board_template.h
deleted file mode 100644
index dafaec48..00000000
--- a/drivers/gdisp/ILI9320/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9320/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the ILI9320 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_BOARD_H
-#define GDISP_LLD_BOARD_H
-
-static inline void gdisp_lld_init_board(void) {
-
-}
-
-static inline void gdisp_lld_reset_pin(bool_t state) {
-
-}
-
-static inline void acquire_bus(void) {
-
-}
-
-static inline void release_bus(void) {
-
-}
-
-static inline void gdisp_lld_write_index(uint16_t data) {
-
-}
-
-static inline void gdisp_lld_write_data(uint16_t data) {
-
-}
-
-static inline uint16_t gdisp_lld_read_data(void) {
-
-}
-
-static inline uint16_t gdisp_lld_backlight(uint8_t percentage) {
-
-}
-
-#endif /* GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9320/gdisp_lld_config.h b/drivers/gdisp/ILI9320/gdisp_lld_config.h
index 4907c6b8..5709de50 100644
--- a/drivers/gdisp/ILI9320/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9320/gdisp_lld_config.h
@@ -4,37 +4,33 @@
*
* http://ugfx.org/license.html
*/
-
-/**
- * @file drivers/gdisp/ILI9320/gdisp_lld_config.h
- * @brief GDISP Graphic Driver subsystem low level driver header for the ILI9320 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_CONFIG_H
-#define GDISP_LLD_CONFIG_H
-
-#if GFX_USE_GDISP
-
-/*===========================================================================*/
-/* Driver hardware support. */
-/*===========================================================================*/
-
-#define GDISP_DRIVER_NAME "ILI9320"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS FALSE
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
-
-#endif /* GFX_USE_GDISP */
-
-#endif /* _GDISP_LLD_CONFIG_H */
-/** @} */
-
+
+/**
+ * @file drivers/gdisp/ILI9320/gdisp_lld_config.h
+ * @brief GDISP Graphic Driver subsystem low level driver header for the ILI9320 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef GDISP_LLD_CONFIG_H
+#define GDISP_LLD_CONFIG_H
+
+#if GFX_USE_GDISP
+
+/*===========================================================================*/
+/* Driver hardware support. */
+/*===========================================================================*/
+
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+//#define GDISP_HARDWARE_STREAM_POS TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+
+#endif /* GFX_USE_GDISP */
+
+#endif /* _GDISP_LLD_CONFIG_H */
+/** @} */
+
diff --git a/drivers/gdisp/ILI9325/board_ILI9325_template.h b/drivers/gdisp/ILI9325/board_ILI9325_template.h
new file mode 100644
index 00000000..07c2fdee
--- /dev/null
+++ b/drivers/gdisp/ILI9325/board_ILI9325_template.h
@@ -0,0 +1,155 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9325/board_ILI9325_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the ILI9325 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef GDISP_LLD_BOARD_H
+#define GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+#endif /* GDISP_LLD_BOARD_H */
+/** @} */
+
diff --git a/drivers/gdisp/ILI9325/gdisp_lld.c b/drivers/gdisp/ILI9325/gdisp_lld.c
deleted file mode 100644
index d47adb3a..00000000
--- a/drivers/gdisp/ILI9325/gdisp_lld.c
+++ /dev/null
@@ -1,582 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9325/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the ILI9325 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#include "gdisp_lld_board.h"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-/* This controller is only ever used with a 240 x 320 display */
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-
-#define GDISP_SCREEN_WIDTH 240
-#define GDISP_SCREEN_HEIGHT 320
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-uint32_t DISPLAY_CODE;
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-static inline void lld_lcdDelay(uint16_t us) {
- gfxSleepMicroseconds(us);
-}
-
-static inline void lld_lcdWriteIndex(uint16_t index) {
- gdisp_lld_write_index(index);
-}
-
-static inline void lld_lcdWriteData(uint16_t data) {
- gdisp_lld_write_data(data);
-}
-
-static inline void lld_lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue) {
- gdisp_lld_write_index(lcdReg);
- gdisp_lld_write_data(lcdRegValue);
-}
-
-static inline uint16_t lld_lcdReadData(void) {
- return gdisp_lld_read_data();
-}
-
-static inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
- volatile uint16_t dummy;
-
- gdisp_lld_write_index(lcdReg);
- dummy = lld_lcdReadData();
- (void)dummy;
-
- return lld_lcdReadData();
-}
-
-static inline void lld_lcdWriteStreamStart(void) {
- lld_lcdWriteIndex(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++)
- lld_lcdWriteData(buffer[i]);
-}
-
-static inline void lld_lcdReadStreamStart(void) {
- lld_lcdWriteIndex(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 = lld_lcdReadData();
- (void)dummy;
-
- for(i = 0; i < size; i++)
- buffer[i] = lld_lcdReadData();
-}
-
-bool_t gdisp_lld_init(void) {
- /* Initialise your display */
- gdisp_lld_init_board();
-
- /* Hardware reset */
- gdisp_lld_reset_pin(TRUE);
- lld_lcdDelay(1000);
- gdisp_lld_reset_pin(FALSE);
- lld_lcdDelay(1000);
-
- DISPLAY_CODE = lld_lcdReadReg(0);
-
- // chinese code starts here
- lld_lcdWriteReg(0x0000,0x0001);
- lld_lcdDelay(10);
-
- lld_lcdWriteReg(0x0015,0x0030);
- lld_lcdWriteReg(0x0011,0x0040);
- lld_lcdWriteReg(0x0010,0x1628);
- lld_lcdWriteReg(0x0012,0x0000);
- lld_lcdWriteReg(0x0013,0x104d);
- lld_lcdDelay(10);
- lld_lcdWriteReg(0x0012,0x0010);
- lld_lcdDelay(10);
- lld_lcdWriteReg(0x0010,0x2620);
- lld_lcdWriteReg(0x0013,0x344d); //304d
- lld_lcdDelay(10);
-
- lld_lcdWriteReg(0x0001,0x0100);
- lld_lcdWriteReg(0x0002,0x0300);
- lld_lcdWriteReg(0x0003,0x1038);//0x1030
- lld_lcdWriteReg(0x0008,0x0604);
- lld_lcdWriteReg(0x0009,0x0000);
- lld_lcdWriteReg(0x000A,0x0008);
-
- lld_lcdWriteReg(0x0041,0x0002);
- lld_lcdWriteReg(0x0060,0x2700);
- lld_lcdWriteReg(0x0061,0x0001);
- lld_lcdWriteReg(0x0090,0x0182);
- lld_lcdWriteReg(0x0093,0x0001);
- lld_lcdWriteReg(0x00a3,0x0010);
- lld_lcdDelay(10);
-
- //################# void Gamma_Set(void) ####################//
- lld_lcdWriteReg(0x30,0x0000);
- lld_lcdWriteReg(0x31,0x0502);
- lld_lcdWriteReg(0x32,0x0307);
- lld_lcdWriteReg(0x33,0x0305);
- lld_lcdWriteReg(0x34,0x0004);
- lld_lcdWriteReg(0x35,0x0402);
- lld_lcdWriteReg(0x36,0x0707);
- lld_lcdWriteReg(0x37,0x0503);
- lld_lcdWriteReg(0x38,0x1505);
- lld_lcdWriteReg(0x39,0x1505);
- lld_lcdDelay(10);
-
- //################## void Display_ON(void) ####################//
- lld_lcdWriteReg(0x0007,0x0001);
- lld_lcdDelay(10);
- lld_lcdWriteReg(0x0007,0x0021);
- lld_lcdWriteReg(0x0007,0x0023);
- lld_lcdDelay(10);
- lld_lcdWriteReg(0x0007,0x0033);
- lld_lcdDelay(10);
- lld_lcdWriteReg(0x0007,0x0133);
-
- // chinese code ends here
-
- // Turn on the backlight
- gdisp_lld_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
-
- return TRUE;
-}
-
-static void lld_lcdSetCursor(uint16_t x, uint16_t y) {
-
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- lld_lcdWriteReg(0x0020, x);
- lld_lcdWriteReg(0x0021, y);
- break;
-
- case GDISP_ROTATE_90:
- lld_lcdWriteReg(0x0020, y);
- lld_lcdWriteReg(0x0021, x);
- break;
-
- case GDISP_ROTATE_180:
- lld_lcdWriteReg(0x0020, x);
- lld_lcdWriteReg(0x0021, y);
- break;
-
- case GDISP_ROTATE_270:
- lld_lcdWriteReg(0x0020, y);
- lld_lcdWriteReg(0x0021, x);
- break;
- }
-}
-
-static void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- lld_lcdWriteReg(0x0050, x);
- lld_lcdWriteReg(0x0051, x + cx - 1);
- lld_lcdWriteReg(0x0052, y);
- lld_lcdWriteReg(0x0053, y + cy - 1);
- break;
-
- case GDISP_ROTATE_90:
- lld_lcdWriteReg(0x0050, y);
- lld_lcdWriteReg(0x0051, y + cy - 1);
- lld_lcdWriteReg(0x0052, x);
- lld_lcdWriteReg(0x0053, x + cx - 1);
- break;
-
- case GDISP_ROTATE_180:
- lld_lcdWriteReg(0x0050, x);
- lld_lcdWriteReg(0x0051, x + cx - 1);
- lld_lcdWriteReg(0x0052, y);
- lld_lcdWriteReg(0x0053, y + cy - 1);
- break;
-
- case GDISP_ROTATE_270:
- lld_lcdWriteReg(0x0050, y);
- lld_lcdWriteReg(0x0051, y + cy - 1);
- lld_lcdWriteReg(0x0052, x);
- lld_lcdWriteReg(0x0053, x + cx - 1);
- break;
-
- }
-
- lld_lcdSetCursor(x, y);
-}
-
-static inline void lld_lcdResetViewPort(void) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- case GDISP_ROTATE_180:
- lld_lcdSetViewPort(0, 0, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
- break;
- case GDISP_ROTATE_90:
- case GDISP_ROTATE_270:
- lld_lcdSetViewPort(0, 0, GDISP_SCREEN_HEIGHT, GDISP_SCREEN_WIDTH);
- break;
- }
-}
-
-void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
- lld_lcdSetCursor(x, y);
- lld_lcdWriteReg(0x0022, color);
-}
-
-#if GDISP_HARDWARE_CLEARS || defined(__DOXYGEN__)
- void gdisp_lld_clear(color_t color) {
- unsigned i;
-
- lld_lcdSetCursor(0, 0);
- lld_lcdWriteStreamStart();
-
- for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
- lld_lcdWriteData(color);
-
- lld_lcdWriteStreamStop();
- }
-#endif
-
-#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__)
- void gdisp_lld_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - 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__)
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy;
- unsigned lg;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- lld_lcdSetViewPort(x, y, cx, cy);
- lld_lcdWriteStreamStart();
-
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- buffer += srcx + srcy * srccx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- lld_lcdWriteData(*buffer++);
- lld_lcdWriteStreamStop();
- lld_lcdResetViewPort();
- }
-#endif
-
-#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD) || defined(__DOXYGEN__)
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || 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__)
- void gdisp_lld_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, gap, abslines;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- abslines = lines < 0 ? -lines : lines;
-
- 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_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- 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:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000);
- lld_lcdWriteReg(0x0010, 0x0000);
- lld_lcdWriteReg(0x0011, 0x0000);
- lld_lcdWriteReg(0x0012, 0x0000);
- lld_lcdWriteReg(0x0013, 0x0000);
- release_bus();
-
- gdisp_lld_backlight(0);
- break;
-
- case powerOn:
- //*************Power On sequence ******************//
- acquire_bus();
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
- lld_lcdWriteReg(0x0011, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0012, 0x013C); /* VREG1OUT voltage */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0013, 0x0E00); /* VDV[4:0] for VCOM amplitude */
- lld_lcdWriteReg(0x0029, 0x0009); /* VCM[4:0] for VCOMH */
- lld_lcdDelay(500);
- lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */
- release_bus();
-
- gdisp_lld_backlight(GDISP.Backlight);
- if(GDISP.Powermode != powerSleep || GDISP.Powermode != powerDeepSleep)
- gdisp_lld_init();
- break;
-
- case powerSleep:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- release_bus();
-
- gdisp_lld_backlight(0);
- break;
-
- case powerDeepSleep:
- acquire_bus();
- lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */
- lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
- lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */
- lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */
- lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */
- lld_lcdWriteReg(0x0010, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
- release_bus();
-
- gdisp_lld_backlight(0);
- 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 GDISP_ROTATE_0:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0100);
- lld_lcdWriteReg(0x0003, 0x1038);
- lld_lcdWriteReg(0x0060, 0x2700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_90:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0000);
- lld_lcdWriteReg(0x0003, 0x1030);
- lld_lcdWriteReg(0x0060, 0x2700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- case GDISP_ROTATE_180:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0000);
- lld_lcdWriteReg(0x0003, 0x1038);
- lld_lcdWriteReg(0x0060, 0xa700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_270:
- acquire_bus();
- lld_lcdWriteReg(0x0001, 0x0100);
- lld_lcdWriteReg(0x0003, 0x1030);
- lld_lcdWriteReg(0x0060, 0xA700);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- default:
- return;
- }
-
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-
- case GDISP_CONTROL_BACKLIGHT:
- if((unsigned)value > 100) value = (void *)100;
- gdisp_lld_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- break;
-
- default:
- return;
- }
- }
-
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9325/gdisp_lld.mk b/drivers/gdisp/ILI9325/gdisp_lld.mk
index b5061324..4dbda578 100644
--- a/drivers/gdisp/ILI9325/gdisp_lld.mk
+++ b/drivers/gdisp/ILI9325/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9325/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/ILI9325
+GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c
diff --git a/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c b/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c
new file mode 100644
index 00000000..ffd67cf7
--- /dev/null
+++ b/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c
@@ -0,0 +1,368 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9325/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the ILI9325 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
+
+/* This controller is only ever used with a 240 x 320 display */
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_ILI9325
+#include "../drivers/gdisp/ILI9325/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ILI9325.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+
+static void set_cursor(GDisplay *g) {
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x20, g->p.x);
+ write_reg(g, 0x21, g->p.y);
+ break;
+
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x20, g->p.y);
+ write_reg(g, 0x21, g->p.x);
+ break;
+ }
+ write_index(g, 0x22);
+}
+
+static void set_viewport(GDisplay* g) {
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x50, g->p.x);
+ write_reg(g, 0x51, g->p.x + g->p.cx - 1);
+ write_reg(g, 0x52, g->p.y);
+ write_reg(g, 0x53, g->p.y + g->p.cy - 1);
+ break;
+
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x50, g->p.y);
+ write_reg(g, 0x51, g->p.y + g->p.cy - 1);
+ write_reg(g, 0x52, g->p.x);
+ write_reg(g, 0x53, g->p.x + g->p.cx - 1);
+ break;
+ }
+}
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ uint16_t cver;
+
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ /* Hardware reset */
+ setpin_reset(g, TRUE);
+ gfxSleepMicroseconds(1000);
+ setpin_reset(g, FALSE);
+ gfxSleepMicroseconds(1000);
+
+ acquire_bus(g);
+ write_index(g, 0); // Get controller version
+ setreadmode(g);
+ dummy_read(g);
+ cver = read_data(g);
+ setwritemode(g);
+
+ // chinese code starts here
+ write_reg(g, 0x00, 0x0001);
+ gfxSleepMilliseconds(10);
+
+ write_reg(g, 0x15, 0x0030);
+ write_reg(g, 0x11, 0x0040);
+ write_reg(g, 0x10, 0x1628);
+ write_reg(g, 0x12, 0x0000);
+ write_reg(g, 0x13, 0x104d);
+ gfxSleepMilliseconds(10);
+ write_reg(g, 0x12, 0x0010);
+ gfxSleepMilliseconds(10);
+ write_reg(g, 0x10, 0x2620);
+ write_reg(g, 0x13, 0x344d); //304d
+ gfxSleepMilliseconds(10);
+
+ write_reg(g, 0x01, 0x0100);
+ write_reg(g, 0x02, 0x0300);
+ write_reg(g, 0x03, 0x1038);//0x1030
+ write_reg(g, 0x08, 0x0604);
+ write_reg(g, 0x09, 0x0000);
+ write_reg(g, 0x0A, 0x0008);
+
+ write_reg(g, 0x41, 0x0002);
+ write_reg(g, 0x60, 0x2700);
+ write_reg(g, 0x61, 0x0001);
+ write_reg(g, 0x90, 0x0182);
+ write_reg(g, 0x93, 0x0001);
+ write_reg(g, 0xa3, 0x0010);
+ gfxSleepMilliseconds(10);
+
+ //################# void Gamma_Set(void) ####################//
+ write_reg(g, 0x30, 0x0000);
+ write_reg(g, 0x31, 0x0502);
+ write_reg(g, 0x32, 0x0307);
+ write_reg(g, 0x33, 0x0305);
+ write_reg(g, 0x34, 0x0004);
+ write_reg(g, 0x35, 0x0402);
+ write_reg(g, 0x36, 0x0707);
+ write_reg(g, 0x37, 0x0503);
+ write_reg(g, 0x38, 0x1505);
+ write_reg(g, 0x39, 0x1505);
+ gfxSleepMilliseconds(10);
+
+ //################## void Display_ON(void) ####################//
+ write_reg(g, 0x07, 0x0001);
+ gfxSleepMilliseconds(10);
+ write_reg(g, 0x07, 0x0021);
+ write_reg(g, 0x07, 0x0023);
+ gfxSleepMilliseconds(10);
+ write_reg(g, 0x07, 0x0033);
+ gfxSleepMilliseconds(10);
+ write_reg(g, 0x07, 0x0133);
+
+ // chinese code ends here
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ // Turn on the backlight
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ set_cursor(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000);
+ write_reg(g, 0x10, 0x0000);
+ write_reg(g, 0x11, 0x0000);
+ write_reg(g, 0x12, 0x0000);
+ write_reg(g, 0x13, 0x0000);
+ release_bus(g);
+ set_backlight(g, 0);
+ break;
+
+ case powerOn:
+ //*************Power On sequence ******************//
+ acquire_bus(g);
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ write_reg(g, 0x11, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ gfxSleepMilliseconds(50);
+ write_reg(g, 0x12, 0x013C); /* VREG1OUT voltage */
+ gfxSleepMilliseconds(50);
+ write_reg(g, 0x13, 0x0E00); /* VDV[4:0] for VCOM amplitude */
+ write_reg(g, 0x29, 0x0009); /* VCM[4:0] for VCOMH */
+ gfxSleepMilliseconds(50);
+ write_reg(g, 0x07, 0x0173); /* 262K color and display ON */
+ release_bus(g);
+ set_backlight(g, g->g.Backlight);
+ break;
+
+ case powerSleep:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000); /* display OFF */
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ release_bus(g);
+ gdisp_lld_backlight(g, 0);
+ break;
+
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_reg(g, 0x07, 0x0000); /* display OFF */
+ write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
+ write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
+ write_reg(g, 0x10, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
+ release_bus(g);
+ gdisp_lld_backlight(g, 0);
+ break;
+
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0100);
+ write_reg(g, 0x03, 0x1038);
+ write_reg(g, 0x60, 0x2700);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0000);
+ write_reg(g, 0x03, 0x1030);
+ write_reg(g, 0x60, 0x2700);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0000);
+ write_reg(g, 0x03, 0x1038);
+ write_reg(g, 0x60, 0xa700);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, 0x01, 0x0100);
+ write_reg(g, 0x03, 0x1030);
+ write_reg(g, 0x60, 0xA700);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+
+ default:
+ return;
+ }
+
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9325/gdisp_lld_board_hy_stm32_100p.h b/drivers/gdisp/ILI9325/gdisp_lld_board_hy_stm32_100p.h
deleted file mode 100644
index 3c2cc78b..00000000
--- a/drivers/gdisp/ILI9325/gdisp_lld_board_hy_stm32_100p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/*
- driver quickly hacked together from a chinese sourcecode that came
- with the board and existing ili9320 code by Chris van Dongen (sjaak)
- (sjaak2002 at msn.com)
-
- Also added rotation for 180 and 270 degrees and minor tweaks to
- setcursor
-
- Added code comes without warranty and free bugs. Feel free to use
- or misuse the added code :D
-*/
-
-
-/**
- * @file drivers/gdisp/ILI9325/gdisp_lld_board_hy_stm32_100p.h
- * @brief GDISP Graphic Driver subsystem board interface for the ILI9325 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_BOARD_H
-#define GDISP_LLD_BOARD_H
-
-#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
-#define GDISP_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */
-
-static inline void gdisp_lld_init_board(void) {
- /* FSMC setup for F1 */
- rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
-
- /* set pin modes */
-/* IOBus busD = {GPIOD, PAL_WHOLE_PORT, 0};
- IOBus busE = {GPIOE, PAL_WHOLE_PORT, 0};
- palSetBusMode(&busD, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetBusMode(&busE, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetPadMode(GPIOE, GPIOE_TFT_RST, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, GPIOD_TFT_LIGHT, PAL_MODE_OUTPUT_PUSHPULL); */
-
- const unsigned char FSMC_Bank = 0;
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = (6) | (10 << 8) | (10 << 16);
-
- /* Bank1 NOR/SRAM control register configuration
- * This is actually not needed as already set by default after reset */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-
-}
-
-static inline void gdisp_lld_reset_pin(bool_t state) {
- if(state)
- palClearPad(GPIOE, GPIOE_TFT_RST);
- else
- palSetPad(GPIOE, GPIOE_TFT_RST);
-}
-
-static inline void gdisp_lld_write_index(uint16_t reg) {
- GDISP_REG = reg;
-}
-
-static inline void gdisp_lld_write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-static inline uint16_t gdisp_lld_read_data(void) {
- return GDISP_RAM;
-}
-
-static inline void gdisp_lld_backlight(uint8_t percent) {
- percent=percent; // avoid a warning
-}
-
-#endif /* GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9325/gdisp_lld_board_template.h b/drivers/gdisp/ILI9325/gdisp_lld_board_template.h
deleted file mode 100644
index 2dd346a3..00000000
--- a/drivers/gdisp/ILI9325/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9325/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the ILI9325 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef GDISP_LLD_BOARD_H
-#define GDISP_LLD_BOARD_H
-
-static inline void gdisp_lld_init_board(void) {
-
-}
-
-static inline void gdisp_lld_reset_pin(bool_t state) {
-
-}
-
-static inline void gdisp_lld_write_index(uint16_t data) {
-
-}
-
-static inline void gdisp_lld_write_data(uint16_t data) {
-
-}
-
-static inline uint16_t gdisp_lld_read_data(void) {
-
-}
-
-static inline uint16_t gdisp_lld_backlight(uint8_t percentage) {
-
-}
-
-#endif /* GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ILI9325/gdisp_lld_config.h b/drivers/gdisp/ILI9325/gdisp_lld_config.h
index ac07173c..c40bd2b7 100644
--- a/drivers/gdisp/ILI9325/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9325/gdisp_lld_config.h
@@ -22,16 +22,12 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "ILI9325"
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_STREAM_POS TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS FALSE
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9341/ILI9341.h b/drivers/gdisp/ILI9341/ILI9341.h
new file mode 100644
index 00000000..bace6907
--- /dev/null
+++ b/drivers/gdisp/ILI9341/ILI9341.h
@@ -0,0 +1,87 @@
+
+#define LCD_VERTICAL_MAX 320
+#define LCD_HORIZONTAL_MAX 240
+
+#define ILI9341_DEVICE_CODE_READ_REG 0x00
+#define ILI9341_SOFT_RESET_REG 0x01
+#define ILI9341_IDENTINFO_R_REG 0x04
+#define ILI9341_STATUS_R_REG 0x09
+#define ILI9341_POWERMODE_R_REG 0x0A
+#define ILI9341_MADCTL_R_REG 0x0B
+#define ILI9341_PIXFORMAT_R_REG 0x0C
+#define ILI9341_IMGFORMAT_R_REG 0x0D
+#define ILI9341_SIGMODE_R_REG 0x0E
+#define ILI9341_SD_RESULT_R_REG 0x0F
+#define ILI9341_SLEEP_ENTER_REG 0x10
+#define ILI9341_SLEEP_OUT_REG 0x11
+#define ILI9341_PARTIALMODE_REG 0x12
+#define ILI9341_NORDISPMODE_REG 0x13
+#define ILI9341_INVERSIONOFF_REG 0x20
+#define ILI9341_INVERSIONON_REG 0x21
+#define ILI9341_GAMMASET_REG 0x26
+#define ILI9341_DISPLAYOFF_REG 0x28
+#define ILI9341_DISPLAYON_REG 0x29
+#define ILI9341_COLADDRSET_REG 0x2A
+#define ILI9341_PAGEADDRSET_REG 0x2B
+#define ILI9341_MEMORYWRITE_REG 0x2C
+#define ILI9341_COLORSET_REG 0x2D
+#define ILI9341_MEMORYREAD_REG 0x2E
+#define ILI9341_PARTIALAREA_REG 0x30
+#define ILI9341_VERTSCROLL_REG 0x33
+#define ILI9341_TEAREFFECTLINEOFF_REG 0x34
+#define ILI9341_TEAREFFECTLINEON_REG 0x35
+#define ILI9341_MEMACCESS_REG 0x36
+#define ILI9341_VERSCRSRART_REG 0x37
+#define ILI9341_IDLEMODEOFF_REG 0x38
+#define ILI9341_IDLEMODEON_REG 0x39
+#define ILI9341_PIXFORMATSET_REG 0x3A
+#define ILI9341_WRITEMEMCONTINUE_REG 0x3C
+#define ILI9341_READMEMCONTINUE_REG 0x3E
+#define ILI9341_SETTEATSCAN_REG 0x44
+#define ILI9341_GETSCANLINE_REG 0x45
+#define ILI9341_WRITEBRIGHT_REG 0x51
+#define ILI9341_READBRIGHT_REG 0x52
+#define ILI9341_WRITECTRL_REG 0x53
+#define ILI9341_READCTRL_REG 0x54
+#define ILI9341_WRITECABC_REG 0x55
+#define ILI9341_READCABC_REG 0x56
+#define ILI9341_WRITECABCMB_REG 0x5E
+#define ILI9341_READCABCMB_REG 0x5F
+#define ILI9341_RGB_ISCTL_REG 0xB0
+#define ILI9341_FRAMECTL_NOR_REG 0xB1
+#define ILI9341_FRAMECTL_IDLE_REG 0xB2
+#define ILI9341_FRAMECTL_PARTIAL_REG 0xB3
+#define ILI9341_INVERCTL_REG 0xB4
+#define ILI9341_BLANKPORCTL_REG 0xB5
+#define ILI9341_FUNCTONCTL_REG 0xB6
+#define ILI9341_ENTRYMODE_REG 0xB7
+#define ILI9341_BLIGHTCTL1_REG 0xB8
+#define ILI9341_BLIGHTCTL2_REG 0xB9
+#define ILI9341_BLIGHTCTL3_REG 0xBA
+#define ILI9341_BLIGHTCTL4_REG 0xBB
+#define ILI9341_BLIGHTCTL5_REG 0xBC
+#define ILI9341_BLIGHTCTL7_REG 0xBE
+#define ILI9341_BLIGHTCTL8_REG 0xBF
+#define ILI9341_POWERCTL1_REG 0xC0
+#define ILI9341_POWERCTL2_REG 0xC1
+#define ILI9341_VCOMCTL1_REG 0xC5
+#define ILI9341_VCOMCTL2_REG 0xC7
+#define ILI9341_POWERCTLA_REG 0xCB
+#define ILI9341_POWERCTLB_REG 0xCF
+#define ILI9341_NVMEMWRITE_REG 0xD0
+#define ILI9341_NVMEMPROTECTKEY_REG 0xD1
+#define ILI9341_NVMEMSTATUS_REG 0xD2
+#define ILI9341_READID4_REG 0xD3
+#define ILI9341_READID1_REG 0xDA
+#define ILI9341_READID2_REG 0xDB
+#define ILI9341_READID3_REG 0xDC
+#define ILI9341_POSGAMMACORRECTION_REG 0xE0
+#define ILI9341_NEGGAMMACORRECTION_REG 0xE1
+#define ILI9341_DIGGAMCTL1_REG 0xE2
+#define ILI9341_DIGGAMCTL2_REG 0xE3
+#define ILI9341_DIVTIMCTL_A_REG 0xE8
+#define ILI9341_DIVTIMCTL_B_REG 0xEA
+#define ILI9341_POWONSEQCTL_REG 0xED
+#define ILI9341_ENABLE_3G_REG 0xF2
+#define ILI9341_INTERFCTL_REG 0xF6
+#define ILI9341_PUMPRATIOCTL_REG 0xF7
diff --git a/drivers/gdisp/ILI9341/board_ILI9341_template.h b/drivers/gdisp/ILI9341/board_ILI9341_template.h
new file mode 100644
index 00000000..b8f55dc1
--- /dev/null
+++ b/drivers/gdisp/ILI9341/board_ILI9341_template.h
@@ -0,0 +1,154 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9341/board_ILI9341_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the ILI9341 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/ILI9341/gdisp_lld.mk b/drivers/gdisp/ILI9341/gdisp_lld.mk
new file mode 100644
index 00000000..326b67ad
--- /dev/null
+++ b/drivers/gdisp/ILI9341/gdisp_lld.mk
@@ -0,0 +1,2 @@
+GFXINC += $(GFXLIB)/drivers/gdisp/ILI9341
+GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c
diff --git a/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c b/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c
new file mode 100644
index 00000000..2513c48d
--- /dev/null
+++ b/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c
@@ -0,0 +1,353 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9341/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for
+ * the ILI9341 and compatible HVGA display
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_ILI9341
+#include "../drivers/gdisp/ILI9341/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ILI9341.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+#include "../drivers/gdisp/ILI9341/ILI9341.h"
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+#define write_data16(g, data) { write_data(g, data >> 8); write_data(g, (uint8_t)data); }
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
+
+static void set_viewport(GDisplay *g) {
+ write_index(g, 0x2A);
+ write_data(g, (g->p.x >> 8));
+ write_data(g, (uint8_t) g->p.x);
+ write_data(g, (g->p.x + g->p.cx - 1) >> 8);
+ write_data(g, (uint8_t) (g->p.x + g->p.cx - 1));
+
+ write_index(g, 0x2B);
+ write_data(g, (g->p.y >> 8));
+ write_data(g, (uint8_t) g->p.y);
+ write_data(g, (g->p.y + g->p.cy - 1) >> 8);
+ write_data(g, (uint8_t) (g->p.y + g->p.cy - 1));
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ write_index(g, 0x01); //software reset
+ chThdSleepMilliseconds(5);
+ write_index(g, 0x28);
+ // display off
+ //---------------------------------------------------------
+ // magic?
+ write_index(g, 0xcf);
+ write_data(g, 0x00);
+ write_data(g, 0x83);
+ write_data(g, 0x30);
+
+ write_index(g, 0xed);
+ write_data(g, 0x64);
+ write_data(g, 0x03);
+ write_data(g, 0x12);
+ write_data(g, 0x81);
+ write_index(g, 0xe8);
+ write_data(g, 0x85);
+ write_data(g, 0x01);
+ write_data(g, 0x79);
+ write_index(g, 0xcb);
+ write_data(g, 0x39);
+ write_data(g, 0x2c);
+ write_data(g, 0x00);
+ write_data(g, 0x34);
+ write_data(g, 0x02);
+ write_index(g, 0xf7);
+ write_data(g, 0x20);
+ write_index(g, 0xea);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ //------------power control------------------------------
+ write_index(g, 0xc0); //power control
+ write_data(g, 0x26);
+ write_index(g, 0xc1); //power control
+ write_data(g, 0x11);
+ //--------------VCOM
+ write_index(g, 0xc5); //vcom control
+ write_data(g, 0x35);//35
+ write_data(g, 0x3e);//3E
+ write_index(g, 0xc7); //vcom control
+ write_data(g, 0xbe); // 0x94
+ //------------memory access control------------------------
+ write_index(g, 0x36);
+ // memory access control
+ write_data(g, 0x48); //0048 my,mx,mv,ml,BGR,mh,0.0
+ write_index(g, 0x3a); // pixel format set
+ write_data(g, 0x55);//16bit /pixel
+ //----------------- frame rate------------------------------
+ write_index(g, 0xb1);
+ // frame rate
+ write_data(g, 0x00);
+ write_data(g, 0x1B); //70
+ //----------------Gamma---------------------------------
+ write_index(g, 0xf2); // 3Gamma Function Disable
+ write_data(g, 0x08);
+ write_index(g, 0x26);
+ write_data(g, 0x01); // gamma set 4 gamma curve 01/02/04/08
+
+ write_index(g, 0xE0); //positive gamma correction
+ write_data(g, 0x1f);
+ write_data(g, 0x1a);
+ write_data(g, 0x18);
+ write_data(g, 0x0a);
+ write_data(g, 0x0f);
+ write_data(g, 0x06);
+ write_data(g, 0x45);
+ write_data(g, 0x87);
+ write_data(g, 0x32);
+ write_data(g, 0x0a);
+ write_data(g, 0x07);
+ write_data(g, 0x02);
+ write_data(g, 0x07);
+ write_data(g, 0x05);
+ write_data(g, 0x00);
+ write_index(g, 0xE1); //negamma correction
+ write_data(g, 0x00);
+ write_data(g, 0x25);
+ write_data(g, 0x27);
+ write_data(g, 0x05);
+ write_data(g, 0x10);
+ write_data(g, 0x09);
+ write_data(g, 0x3a);
+ write_data(g, 0x78);
+ write_data(g, 0x4d);
+ write_data(g, 0x05);
+ write_data(g, 0x18);
+ write_data(g, 0x0d);
+ write_data(g, 0x38);
+ write_data(g, 0x3a);
+ write_data(g, 0x1f);
+ //--------------ddram ---------------------
+ write_index(g, 0x2a);
+ // column set
+ // size = 239
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0xEF);
+ write_index(g, 0x2b);
+ // page address set
+ // size = 319
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x01);
+ write_data(g, 0x3F);
+ // write_index(g, 0x34);
+ //write_index(g, 0x35);
+ // tearing effect off
+ // tearing effect on
+ // write_index(g, 0xb4); // display inversion
+ // write_data(g, 0x00);
+ write_index(g, 0xb7); //entry mode set
+ write_data(g, 0x07);
+ //-----------------display---------------------
+ write_index(g, 0xb6);
+ // display function control
+ write_data(g, 0x0a);
+ write_data(g, 0x82);
+ write_data(g, 0x27);
+ write_data(g, 0x00);
+ write_index(g, 0x11); //sleep out
+ chThdSleepMilliseconds(100);
+ write_index(g, 0x29); // display on
+ chThdSleepMilliseconds(100);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ write_index(g, 0x2C);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data16(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ write_index(g, 0x2E);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerSleep:
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_reg(g, 0x0010, 0x0001); /* enter sleep mode */
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_reg(g, 0x0010, 0x0000); /* leave sleep mode */
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, 0x36, 0x00); /* X and Y axes non-inverted */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, 0x36, 0xE8); /* Invert X and Y axes */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, 0x36, 0x88); /* X and Y axes non-inverted */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, 0x36, 0x28); /* Invert X and Y axes */
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ILI9341/gdisp_lld_config.h b/drivers/gdisp/ILI9341/gdisp_lld_config.h
new file mode 100644
index 00000000..668a06c9
--- /dev/null
+++ b/drivers/gdisp/ILI9341/gdisp_lld_config.h
@@ -0,0 +1,35 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9481/gdisp_lld_config.h
+ * @brief GDISP Graphics Driver subsystem low level driver source for
+ * the ILI9481 and compatible HVGA display
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_CONFIG_H
+#define _GDISP_LLD_CONFIG_H
+
+#if GFX_USE_GDISP
+
+/*===========================================================================*/
+/* Driver hardware support. */
+/*===========================================================================*/
+
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+//#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+
+#endif /* GFX_USE_GDISP */
+
+#endif /* _GDISP_LLD_CONFIG_H */
+/** @} */
diff --git a/drivers/gdisp/ILI9481/board_ILI9481_template.h b/drivers/gdisp/ILI9481/board_ILI9481_template.h
new file mode 100644
index 00000000..7824c936
--- /dev/null
+++ b/drivers/gdisp/ILI9481/board_ILI9481_template.h
@@ -0,0 +1,155 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9481/board_ILI9481_template.h
+ * @brief GDISP Graphics Driver subsystem low level driver source for
+ * the ILI9481 and compatible HVGA display
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld.c b/drivers/gdisp/ILI9481/gdisp_lld.c
deleted file mode 100644
index cb407dce..00000000
--- a/drivers/gdisp/ILI9481/gdisp_lld.c
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9481/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for
- * the ILI9481 and compatible HVGA display
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-
-#define GDISP_SCREEN_HEIGHT 480
-#define GDISP_SCREEN_WIDTH 320
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-// Some common routines and macros
-#define write_reg(reg, data) { write_index(reg); write_data(data); }
-#define stream_start() write_index(0x2C);
-#define stream_stop()
-#define delay(us) gfxSleepMicroseconds(us)
-#define delayms(ms) gfxSleepMilliseconds(ms)
-
-static inline void set_cursor(coord_t x, coord_t y) {
- write_index(0x2A);
- write_data((x >> 8));
- write_data((uint8_t) x);
- write_data((x) >> 8);
- write_data((uint8_t) (x));
-
- write_index(0x2B);
- write_data((y >> 8));
- write_data((uint8_t) y);
- write_data((y) >> 8);
- write_data((uint8_t) (y));
-}
-
-static void set_viewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- write_index(0x2A);
- write_data((x >> 8));
- write_data((uint8_t) x);
- write_data((x + cx - 1) >> 8);
- write_data((uint8_t) (x + cx - 1));
-
- write_index(0x2B);
- write_data((y >> 8));
- write_data((uint8_t) y);
- write_data((y + cy - 1) >> 8);
- write_data((uint8_t) (y + cy - 1));
-}
-
-static inline void reset_viewport(void) {
- set_viewport(0, 0, GDISP.Width, GDISP.Height);
-}
-
-/*===========================================================================*/
-/* 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 */
- init_board();
-
- /* Hardware reset */
- setpin_reset(TRUE);
- delayms(20);
- setpin_reset(FALSE);
- delayms(20);
-
- /* Get the bus for the following initialisation commands */
- acquire_bus();
-
- /* Enable Access to all Manufacturer commands (0xB0 and higher opcodes) */
- write_index(0xB0);
- write_data(0x00);
-
- /* Frame Memory Access and Interface Setting */
- write_index(0xB3);
- write_data(0x02);
- write_data(0x00);
- write_data(0x00);
- write_data(0x10);
-
- /* Display Mode and Frame Memory Write Mode Setting (B4h) */
- /* Use internal clock for synchronization */
- /* Use DBI interface (only DB0-17, no HSYNC, VSYNC or CLK) */
- write_index(0xB4);
- write_data(0x00);
-
- /* Internal Backlight Control */
-/* write_index(0xB9); /*PWM Settings for Brightness Control */
-/* write_data(0x01); /* Disabled by default. */
-/* write_data(0xFF); /*0xFF = Max brightness */
-/* write_data(0xFF);
-/* write_data(0x18);
-
- /* Panel Driving settings */
- write_index(0xC0);
- write_data(0x03);
- write_data(0x3B);
- write_data(0x00);
- write_data(0x00);
- write_data(0x00);
- write_data(0x01);
- write_data(0x00); /* NW */
- write_data(0x43);
-
- /* Display timings in Operating Mode */
- write_index(0xC1);
- write_data(0x08);
- write_data(0x15); /* CLOCK */
- write_data(0x08);
- write_data(0x08);
-
- /* S/VCOM/Gate Driving timing setting */
- write_index(0xC4);
- write_data(0x15);
- write_data(0x03);
- write_data(0x03);
- write_data(0x01);
-
- /* Interface Setting */
- write_index(0xC6);
- write_data(0x02);
-
- /* Gamma Setting - should be changed if using a different panel */
- write_index(0xC8);
- write_data(0x0C);
- write_data(0x05);
- write_data(0x0A); /*0X12 */
- write_data(0x6B); /*0x7D */
- write_data(0x04);
- write_data(0x06); /*0x08 */
- write_data(0x15); /*0x0A */
- write_data(0x10);
- write_data(0x00);
- write_data(0x60); /*0x23 */
-
- /* Address Mode setting */
- write_index(0x36);
- write_data(0x00);
-
- /* Set Pixel Format = 16 bits per pixel */
- /* The driver supports upto 24 bits per pixel, with dither */
- write_index(0x3A);
- write_data(0x55);
-
- /* Exit Idle Mode */
- write_index(0x38);
-
- /* Power Setting */
- write_index(0xD0);
- write_data(0x07);
- write_data(0x07); /* VCI = VCI1 */
- write_data(0x14); /* VRH 0x1D */
- write_data(0xA2); /* BT 0x06 */
-
- /* VCOM Setting */
- write_index(0xD1);
- write_data(0x03);
- write_data(0x5A); /* VCM 0x5A */
- write_data(0x10); /* VDV */
-
- /* Power Setting for Normal Mode */
- write_index(0xD2);
- write_data(0x03);
- write_data(0x04); /* 0x24 */
- write_data(0x04);
-
- /* Exit Sleep Mode */
- write_index(0x11);
- delay(150);
-
- /* Display ON */
- write_index(0x29);
- delay(30);
-
- /* Release the bus */
- release_bus();
-
- /* Turn on the back-light */
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- acquire_bus();
-
- set_cursor(x, y);
- write_reg(0x002c, color);
-
- release_bus();
-}
-
-/* ---- 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;
-
- acquire_bus();
- reset_viewport();
- stream_start();
- for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
- write_data(color);
- stream_stop();
- release_bus();
- }
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned i, area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
-
- acquire_bus();
-
- set_viewport(x, y, cx, cy);
-
- stream_start();
- for(i = 0; i < area; i++)
- write_data(color);
- stream_stop();
-
- release_bus();
- }
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy;
- unsigned lg;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
-
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- buffer += srcx + srcy * srccx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- stream_stop();
- release_bus();
- }
-#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 pixel to be read
- *
- * @notapi
- */
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
- #endif
-
- acquire_bus();
- set_cursor(x, y);
- stream_start();
- color = read_data(); // dummy read
- color = read_data();
- stream_stop();
- release_bus();
-
- 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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, gap, abslines, j;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- abslines = lines < 0 ? -lines : lines;
-
- acquire_bus();
- if ((coord_t)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*/
- set_viewport(x, row0, cx, 1);
- stream_start();
- j = read_data(); // dummy read
- for (j = 0; (coord_t)j < cx; j++)
- buf[j] = read_data();
- stream_stop();
-
- set_viewport(x, row1, cx, 1);
- stream_start();
- for (j = 0; (coord_t)j < cx; j++)
- write_data(buf[j]);
- stream_stop();
- }
- }
-
- /* fill the remaining gap */
- set_viewport(x, lines > 0 ? (y+(coord_t)gap) : y, cx, abslines);
- stream_start();
- gap = cx*abslines;
- for(i = 0; i < gap; i++) write_data(bgcolor);
- stream_stop();
- release_bus();
- }
-#endif
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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:
- acquire_bus();
- write_reg(0x0010, 0x0001); /* enter sleep mode */
- release_bus();
- break;
- case powerOn:
- acquire_bus();
- write_reg(0x0010, 0x0000); /* leave sleep mode */
- release_bus();
- if (GDISP.Powermode != powerSleep)
- gdisp_lld_init();
- break;
- case powerSleep:
- acquire_bus();
- write_reg(0x0010, 0x0001); /* enter sleep mode */
- release_bus();
- 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 GDISP_ROTATE_0:
- acquire_bus();
-
- write_reg(0xC0, 0x03);
- write_reg(0x36, 0x00); /* X and Y axes non-inverted */
-
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- acquire_bus();
-
- write_reg(0xC0, 0x02);
- write_reg(0x36, 0x20); /* Invert X and Y axes */
-
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- acquire_bus();
-
- write_reg(0xC0, 0x06);
- write_reg(0x36, 0x00); /* X and Y axes non-inverted */
-
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- acquire_bus();
-
- write_reg(0xC0, 0x07);
- write_reg(0x36, 0x20); /* Invert X and Y axes */
-
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-/*
- case GDISP_CONTROL_BACKLIGHT:
- case GDISP_CONTROL_CONTRAST:
-*/
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld.mk b/drivers/gdisp/ILI9481/gdisp_lld.mk
index b0b3f533..8c971788 100644
--- a/drivers/gdisp/ILI9481/gdisp_lld.mk
+++ b/drivers/gdisp/ILI9481/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9481/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/ILI9481
+GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c b/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c
new file mode 100644
index 00000000..2b2f0917
--- /dev/null
+++ b/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c
@@ -0,0 +1,328 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ILI9481/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for
+ * the ILI9481 and compatible HVGA display
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_ILI9481
+#include "../drivers/gdisp/ILI9481/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ILI9481.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 480
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 320
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+#define write_reg2x16(g, reg, data1, data2) { write_index(g, reg); write_data(g, (data1)>>8); write_data(g, (uint8_t)(data1)); write_data(g, (data2)>>8); write_data(g, (uint8_t)(data2));}
+
+static void set_viewport(GDisplay* g) {
+ write_reg2x16(g, 0x2A, g->p.x, g->p.x + g->p.cx - 1);
+ write_reg2x16(g, 0x2B, g->p.y, g->p.y + g->p.cy - 1);
+ write_index(g, 0x2C);
+}
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ /* Hardware reset */
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ /* Get the bus for the following initialisation commands */
+ acquire_bus(g);
+
+ /* Enable Access to all Manufacturer commands (0xB0 and higher opcodes) */
+ write_reg(g, 0xB0, 0x00);
+
+ /* Frame Memory Access and Interface Setting */
+ write_index(g, 0xB3);
+ write_data(g, 0x02);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x10);
+
+ /* Display Mode and Frame Memory Write Mode Setting (B4h) */
+ /* Use internal clock for synchronization */
+ /* Use DBI interface (only DB0-17, no HSYNC, VSYNC or CLK) */
+ write_reg(g, 0xB4, 0x00);
+
+ /* Internal Backlight Control */
+/* write_index(g, 0xB9); // PWM Settings for Brightness Control
+ write_data(g, 0x01); // Disabled by default.
+ write_data(g, 0xFF); // 0xFF = Max brightness
+ write_data(g, 0xFF);
+ write_data(g, 0x18); */
+
+ /* Panel Driving settings */
+ write_index(g, 0xC0);
+ write_data(g, 0x03);
+ write_data(g, 0x3B);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x01);
+ write_data(g, 0x00); /* NW */
+ write_data(g, 0x43);
+
+ /* Display timings in Operating Mode */
+ write_index(g, 0xC1);
+ write_data(g, 0x08);
+ write_data(g, 0x15); /* CLOCK */
+ write_data(g, 0x08);
+ write_data(g, 0x08);
+
+ /* S/VCOM/Gate Driving timing setting */
+ write_index(g, 0xC4);
+ write_data(g, 0x15);
+ write_data(g, 0x03);
+ write_data(g, 0x03);
+ write_data(g, 0x01);
+
+ /* Interface Setting */
+ write_reg(g, 0xC6, 0x02);
+
+ /* Gamma Setting - should be changed if using a different panel */
+ write_index(g, 0xC8);
+ write_data(g, 0x0C);
+ write_data(g, 0x05);
+ write_data(g, 0x0A); /*0X12 */
+ write_data(g, 0x6B); /*0x7D */
+ write_data(g, 0x04);
+ write_data(g, 0x06); /*0x08 */
+ write_data(g, 0x15); /*0x0A */
+ write_data(g, 0x10);
+ write_data(g, 0x00);
+ write_data(g, 0x60); /*0x23 */
+
+ /* Address Mode setting */
+ write_reg(g, 0x36, 0x00);
+
+ /* Set Pixel Format = 16 bits per pixel */
+ /* The driver supports upto 24 bits per pixel, with dither */
+ write_reg(g, 0x3A, 0x55);
+
+ /* Exit Idle Mode */
+ write_index(g, 0x38);
+
+ /* Power Setting */
+ write_index(g, 0xD0);
+ write_data(g, 0x07);
+ write_data(g, 0x07); /* VCI = VCI1 */
+ write_data(g, 0x14); /* VRH 0x1D */
+ write_data(g, 0xA2); /* BT 0x06 */
+
+ /* VCOM Setting */
+ write_index(g, 0xD1);
+ write_data(g, 0x03);
+ write_data(g, 0x5A); /* VCM 0x5A */
+ write_data(g, 0x10); /* VDV */
+
+ /* Power Setting for Normal Mode */
+ write_index(g, 0xD2);
+ write_data(g, 0x03);
+ write_data(g, 0x04); /* 0x24 */
+ write_data(g, 0x04);
+
+ /* Exit Sleep Mode */
+ write_index(g, 0x11);
+ gfxSleepMilliseconds(150);
+
+ /* Display ON */
+ write_index(g, 0x29);
+ gfxSleepMilliseconds(30);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_reg(g, 0x0010, 0x0001); /* enter sleep mode */
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_reg(g, 0x0010, 0x0000); /* leave sleep mode */
+ release_bus(g);
+ if (g->g.Powermode != powerSleep)
+ gdisp_lld_init();
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ write_reg(g, 0x0010, 0x0001); /* enter sleep mode */
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+
+ write_reg(g, 0xC0, 0x03);
+ write_reg(g, 0x36, 0x00); /* X and Y axes non-inverted */
+
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+
+ write_reg(g, 0xC0, 0x02);
+ write_reg(g, 0x36, 0x20); /* Invert X and Y axes */
+
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+
+ write_reg(g, 0xC0, 0x06);
+ write_reg(g, 0x36, 0x00); /* X and Y axes non-inverted */
+
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+
+ write_reg(g, 0xC0, 0x07);
+ write_reg(g, 0x36, 0x20); /* Invert X and Y axes */
+
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+ //case GDISP_CONTROL_BACKLIGHT:
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
+/** @} */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_board_firebullstm32f103.h b/drivers/gdisp/ILI9481/gdisp_lld_board_firebullstm32f103.h
deleted file mode 100644
index cef9911d..00000000
--- a/drivers/gdisp/ILI9481/gdisp_lld_board_firebullstm32f103.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9481/gdisp_lld_board_firebullstm32f103.h
- * @brief GDISP Graphics Driver subsystem low level driver source for
- * the ILI9481 and compatible HVGA display
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define SET_CS palSetPad(GPIOD, 12);
-#define CLR_CS palClearPad(GPIOD, 12);
-#define SET_RS palSetPad(GPIOD, 13);
-#define CLR_RS palClearPad(GPIOD, 13);
-#define SET_WR palSetPad(GPIOD, 14);
-#define CLR_WR palClearPad(GPIOD, 14);
-#define SET_RD palSetPad(GPIOD, 15);
-#define CLR_RD palClearPad(GPIOD, 15);
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 12, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 14, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 15, PAL_MODE_OUTPUT_PUSHPULL);
-
- // Configure the pins to a well know state
- SET_RS;
- SET_RD;
- SET_WR;
- CLR_CS;
-}
-
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- (void) state;
- /* Nothing to do here - reset pin tied to Vcc */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- (void) percent;
- /* Nothing to do here - Backlight always on */
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- palWritePort(GPIOE, index);
- CLR_RS; CLR_WR; SET_WR; SET_RS;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- palWritePort(GPIOE, data);
- CLR_WR; SET_WR;
-}
-
-#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 read_data(void) {
- uint16_t value;
-
- // change pin mode to digital input
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_INPUT);
-
- CLR_RD;
- value = palReadPort(GPIOE);
- value = palReadPort(GPIOE);
- SET_RD;
-
- // change pin mode back to digital output
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
-
- return value;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_board_template.h b/drivers/gdisp/ILI9481/gdisp_lld_board_template.h
deleted file mode 100644
index 1bbcf282..00000000
--- a/drivers/gdisp/ILI9481/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/ILI9481/gdisp_lld_board_template.h
- * @brief GDISP Graphics Driver subsystem low level driver source for
- * the ILI9481 and compatible HVGA display
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialise the board for the display.
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_config.h b/drivers/gdisp/ILI9481/gdisp_lld_config.h
index 79fea9f3..3f3a4834 100644
--- a/drivers/gdisp/ILI9481/gdisp_lld_config.h
+++ b/drivers/gdisp/ILI9481/gdisp_lld_config.h
@@ -23,16 +23,11 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "ILI9481"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD TRUE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_template.h b/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_template.h
new file mode 100644
index 00000000..160c9278
--- /dev/null
+++ b/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_template.h
@@ -0,0 +1,131 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the Nokia6610 GE12 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/*
+ * Set various display properties. These properties mostly depend on the exact controller chip you get.
+ * The defaults should work for most controllers.
+ */
+//#define GDISP_SCREEN_HEIGHT 130 // The visible display height
+//#define GDISP_SCREEN_WIDTH 130 // The visible display width
+//#define GDISP_RAM_X_OFFSET 0 // The x offset of the visible area
+//#define GDISP_RAM_Y_OFFSET 2 // The y offset of the visible area
+//#define GDISP_SLEEP_POS 50 // The position of the sleep mode partial display
+//#define GDISP_INITIAL_CONTRAST 50 // The initial contrast percentage
+//#define GDISP_INITIAL_BACKLIGHT 100 // The initial backlight percentage
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c b/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
deleted file mode 100644
index a991a9a6..00000000
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
+++ /dev/null
@@ -1,505 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE12/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE12 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-/* Controller definitions */
-#include "GE12.h"
-
-/* This controller is only ever used with a 132 x 132 display */
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-#define GDISP_SCREEN_HEIGHT 132
-#define GDISP_SCREEN_WIDTH 132
-
-#define GDISP_INITIAL_CONTRAST 38
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-// Some macros just to make reading the code easier
-#define delayms(ms) gfxSleepMilliseconds(ms)
-#define write_data2(d1, d2) { write_data(d1); write_data(d2); }
-#define write_data3(d1, d2, d3) { write_data(d1); write_data(d2); write_data(d3); }
-#define write_cmd1(cmd, d1) { write_cmd(cmd); write_data(d1); }
-#define write_cmd2(cmd, d1, d2) { write_cmd(cmd); write_data2(d1, d2); }
-#define write_cmd3(cmd, d1, d2, d3) { write_cmd(cmd); write_data3(d1, d2, d3); }
-
-// A very common thing to do.
-// An inline function has been used here incase the parameters have side effects with the internal calculations.
-static inline void setviewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- write_cmd2(CASET, x, x+cx-1); // Column address set
- write_cmd2(PASET, y, y+cy-1); // Page address set
-}
-
-/*===========================================================================*/
-/* 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 */
- init_board();
-
- // Hardware reset
- setpin_reset(TRUE);
- delayms(20);
- setpin_reset(FALSE);
- delayms(20);
-
- // Get the bus for the following initialisation commands
- acquire_bus();
-
- // UNTESTED
- #if 1
- write_cmd(SLEEPOUT); // Sleep out
- write_cmd(INVON); // Inversion on: seems to be required for this controller
- write_cmd1(COLMOD, 0x03); // Color Interface Pixel Format - 0x03 = 12 bits-per-pixel
- write_cmd1(MADCTL, 0xC8); // Memory access controler - 0xC0 = mirror x and y, reverse rgb
- write_cmd1(SETCON, GDISP_INITIAL_CONTRAST); // Write contrast
- delayms(20);
- write_cmd(DISPON); // Display On
- #else
- // Alternative
- write_cmd(SOFTRST); // Software Reset
- delayms(20);
- write_cmd(INITESC); // Initial escape
- delayms(20);
- write_cmd1(REFSET, 0x00); // Refresh set
- write_cmd(DISPCTRL); // Set Display control - really 7 bytes of data
- write_data(128); // Set the lenght of one selection term
- write_data(128); // Set N inversion -> no N inversion
- write_data(134); // Set frame frequence and bias rate -> 2 devision of frequency and 1/8 bias, 1/67 duty, 96x67 size
- write_data(84); // Set duty parameter
- write_data(69); // Set duty parameter
- write_data(82); // Set duty parameter
- write_data(67); // Set duty parameter
- write_cmd(GRAYSCALE0); // Grey scale 0 position set - really 15 bytes of data
- write_data(1); // GCP1 - gray lavel to be output when the RAM data is "0001"
- write_data(2); // GCP2 - gray lavel to be output when the RAM data is "0010"
- write_data(4); // GCP3 - gray lavel to be output when the RAM data is "0011"
- write_data(8); // GCP4 - gray lavel to be output when the RAM data is "0100"
- write_data(16); // GCP5 - gray lavel to be output when the RAM data is "0101"
- write_data(30); // GCP6 - gray lavel to be output when the RAM data is "0110"
- write_data(40); // GCP7 - gray lavel to be output when the RAM data is "0111"
- write_data(50); // GCP8 - gray lavel to be output when the RAM data is "1000"
- write_data(60); // GCP9 - gray lavel to be output when the RAM data is "1001"
- write_data(70); // GCP10 - gray lavel to be output when the RAM data is "1010"
- write_data(80); // GCP11 - gray lavel to be output when the RAM data is "1011"
- write_data(90); // GCP12 - gray lavel to be output when the RAM data is "1100"
- write_data(100); // GCP13 - gray lavel to be output when the RAM data is "1101"
- write_data(110); // GCP14 - gray lavel to be output when the RAM data is "1110"
- write_data(127); // GCP15 - gray lavel to be output when the RAM data is "1111"
- write_cmd1(GAMMA, 0x01); // Gamma curve set - select gray scale - GRAYSCALE 0 or GREYSCALE 1 - Select grey scale 0
- write_cmd1(COMMONDRV, 0x00); // Command driver output - Set COM1-COM41 side come first, normal mod
- write_cmd(NORMALMODE); // Set Normal mode (my)
- // write_cmd(INVERSIONOFF); // Inversion off
- write_cmd2(COLADDRSET, 0, 131); // Column address set
- write_cmd2(PAGEADDRSET, 0, 131); // Page address set
- write_cmd1(ACCESSCTRL, 0x40); // Memory access controler - 0x40 horizontal
- // write_data(0x20); // vertical
- write_cmd1(PWRCTRL, 0x04); // Power control - Internal resistance, V1OUT -> high power mode, oscilator devision rate
- write_cmd(SLEEPOUT); // Sleep out
- write_cmd(VOLTCTRL); // Voltage control - voltage control and write contrast define LCD electronic volume
- // write_data(0x7f); // full voltage control
- // write_data(0x03); // must be "1"
- write_cmd1(CONTRAST, GDISP_INITIAL_CONTRAST); // Write contrast
- delayms(20);
- write_cmd(TEMPGRADIENT); // Temperature gradient - really 14 bytes of data
- for(i=0; i<14; i++)
- write_data(0);
- write_cmd(BOOSTVON); // Booster voltage ON
- write_cmd(DISPLAYON); // Finally - Display On
- #endif
-
- // Release the bus
- release_bus();
-
- /* Turn on the back-light */
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure to match */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
- acquire_bus();
- setviewport(x, y, 1, 1);
- write_cmd3(RAMWR, 0, (color>>8) & 0x0F, color & 0xFF);
- release_bus();
-}
-
-/* ---- Optional Routines ---- */
-
-#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__)
- /**
- * @brief Fill an area with a color.
- *
- * @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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned i, tuples;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - 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.
-
- acquire_bus();
- setviewport(x, y, cx, cy);
- write_cmd(RAMWR);
- for(i=0; i < tuples; i++)
- write_data3(((color >> 4) & 0xFF), (((color << 4) & 0xF0)|((color >> 8) & 0x0F)), (color & 0xFF));
- release_bus();
- }
-#endif
-
-#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__)
- /**
- * @brief Fill an area with a bitmap.
- *
- * @param[in] x, y The start filled area
- * @param[in] cx, cy The width and height to be filled
- * @param[in] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy, lg;
- color_t c1, c2;
- #if GDISP_PACKED_PIXELS
- coord_t pos;
- const uint8_t *p;
- #endif
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- /* What are our end points */
- endx = srcx + cx;
- endy = y + cy;
-
- acquire_bus();
- setviewport(x, y, cx, cy);
- write_cmd(RAMWR);
-
- #if !GDISP_PACKED_PIXELS
- // 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.
- lg = srccx - cx;
- buffer += srcy * srccx + srcx;
- x = srcx;
- while (1) {
- /* Get a pixel */
- c1 = *buffer++;
- if (++x >= endx) {
- if (++y >= endy) {
- /* Odd pixel at end */
- write_data3(0, ((c1 >> 8) & 0x0F), (c1 & 0xFF));
- break;
- }
- x = srcx;
- buffer += lg;
- }
- /* Get the next pixel */
- c2 = *buffer++;
- write_data3(((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
- if (++x >= endx) {
- if (++y >= endy)
- break;
- x = srcx;
- buffer += lg;
- }
- }
-
- #else
-
- // Although this controller uses packed pixels, we may have to feed it into
- // the controller with different packing to the source bitmap
- #if !GDISP_PACKED_LINES
- srccx = (srccx + 1) & ~1;
- #endif
- pos = srcy*srccx;
- lg = (srccx - cx)/2*3;
- p = ((const uint8_t *)buffer) + ((pos+srcx)/2 * 3);
-
- x = srcx;
- while (1) {
- /* Get a pixel */
- switch((pos+x)&1) {
- case 0: c1 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
- case 1: c1 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); break;
- }
- if (++x >= endx) {
- if (++y >= endy) {
- /* Odd pixel at end */
- write_data3(0, ((c1 >> 8) & 0x0F), (c1 & 0xFF));
- break;
- }
- x = srcx;
- p += lg;
- pos += srccx;
- }
- /* Get the next pixel */
- switch((pos+x)&1) {
- case 0: c2 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
- case 1: c2 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); break;
- }
- write_data3(((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
- if (++x >= endx) {
- if (++y >= endy)
- break;
- x = srcx;
- p += lg;
- pos += srccx;
- }
- }
- #endif
- release_bus();
- }
-#endif
-
-#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD)
- /**
- * @brief Get the color of a particular pixel.
- * @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_get_pixel_color(coord_t x, coord_t y) {
- /* NOT IMPLEMENTED */
- /* Some board hardware might support this in the future.
- * The Olimex board doesn't.
- */
- }
-#endif
-
-#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL)
- /**
- * @brief Scroll vertically a section of the screen.
- * @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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- /* NOT IMPLEMENTED */
- /* The hardware seems capable of doing this.
- * It is just really complex so we leave it out for now.
- */
- }
-#endif
-
-#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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) {
- /* The hardware is capable of supporting...
- * GDISP_CONTROL_POWER - not implemented yet
- * GDISP_CONTROL_ORIENTATION - not implemented yet
- * GDISP_CONTROL_BACKLIGHT - supported (the OlimexSAM7EX256 board.h currently only implements off/on although PWM is supported by the hardware)
- * GDISP_CONTROL_CONTRAST - supported
- */
- switch(what) {
-#if 0
- // NOT IMPLEMENTED YET
- 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;
-#endif
-#if 0
- // NOT IMPLEMENTED YET
- 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 GDISP_ROTATE_0:
- // Code here
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- // Code here
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- // Code here
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- // Code here
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-#endif
- case GDISP_CONTROL_BACKLIGHT:
- if ((unsigned)value > 100) value = (void *)100;
- set_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- return;
- case GDISP_CONTROL_CONTRAST:
- if ((unsigned)value > 100) value = (void *)100;
- acquire_bus();
- write_cmd1(CONTRAST,(unsigned)value);
- release_bus();
- GDISP.Contrast = (unsigned)value;
- return;
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk b/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk
index 575d52a3..65781667 100644
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk
+++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12
+GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c b/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c
new file mode 100644
index 00000000..28a2fceb
--- /dev/null
+++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c
@@ -0,0 +1,262 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/Nokia6610GE12/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE12 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_Nokia6610GE12
+#include "../drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_Nokia6610GE12.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#include "GE12.h"
+
+#define GDISP_SCAN_LINES 132
+#define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines - this must be 32 on this controller */
+
+// Set parameters if they are not already set
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 130
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 130
+#endif
+#ifndef GDISP_RAM_X_OFFSET
+ #define GDISP_RAM_X_OFFSET 0 /* Offset in RAM of visible area */
+#endif
+#ifndef GDISP_RAM_Y_OFFSET
+ #define GDISP_RAM_Y_OFFSET 2 /* Offset in RAM of visible area */
+#endif
+#ifndef GDISP_SLEEP_POS
+ #define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2 & ~3)
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+// Use the priv pointer itself to save our color. This save allocating ram for it
+// and works provided sizeof(uint16_t) <= sizeof(void *)
+#define savecolor(g) (*(uint16_t *)&g->priv)
+
+#define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some macros just to make reading the code easier
+#define delayms(ms) gfxSleepMilliseconds(ms)
+#define write_data2(g, d1, d2) { write_data(g, d1); write_data(g, d2); }
+#define write_data3(g, d1, d2, d3) { write_data(g, d1); write_data(g, d2); write_data(g, d3); }
+#define write_reg(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
+#define write_reg2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
+#define write_reg3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
+
+static inline void set_viewport(GDisplay* g) {
+ write_reg2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
+ write_reg2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
+ write_index(g, RAMWR);
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ delayms(20);
+ setpin_reset(g, FALSE);
+ delayms(20);
+
+ acquire_bus(g);
+
+ write_index(g, SLEEPOUT); // Sleep out
+ write_reg(g, COLMOD, 0x03); // Color Interface Pixel Format - 0x03 = 12 bits-per-pixel
+ write_reg(g, MADCTL, 0x00); // Memory access controller
+ write_reg(g, SETCON, 128*GDISP_INITIAL_CONTRAST/101-64); // Write contrast
+ delayms(20);
+
+ // Finish Init
+ post_init_board(g);
+
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure to match */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ g->flags &= ~GDISP_FLG_ODDBYTE;
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ uint16_t c;
+
+ c = COLOR2NATIVE(g->p.color);
+ if ((g->flags & GDISP_FLG_ODDBYTE)) {
+ // Write the pair of pixels to the display
+ write_data3(g, ((savecolor(g) >> 4) & 0xFF),
+ (((savecolor(g) << 4) & 0xF0)|((c >> 8) & 0x0F)),
+ (c & 0xFF));
+ g->flags &= ~GDISP_FLG_ODDBYTE;
+ } else {
+ savecolor(g) = c;
+ g->flags |= GDISP_FLG_ODDBYTE;
+ }
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ if ((g->flags & GDISP_FLG_ODDBYTE)) {
+ write_data2(g, ((savecolor(g) >> 4) & 0xFF), ((savecolor(g) << 4) & 0xF0));
+ write_index(g, NOP);
+ }
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ /* The hardware is capable of supporting...
+ * GDISP_CONTROL_POWER - supported
+ * GDISP_CONTROL_ORIENTATION - supported
+ * GDISP_CONTROL_BACKLIGHT - supported
+ * GDISP_CONTROL_CONTRAST - supported
+ */
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_index(g, SLEEPIN);
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_index(g, SLEEPOUT);
+ delayms(20);
+ write_index(g, NORON); // Set Normal mode (my)
+ release_bus(g);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ write_index(g, SLEEPOUT);
+ delayms(20);
+ write_reg2(g, PTLAR, GDISP_SLEEP_POS, GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)
+ write_index(g, PTLON);
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, MADCTL, 0x00);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, MADCTL, 0xA0); // MY, MX, V, LAO, RGB, X, X, X
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, MADCTL, 0xC0);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, MADCTL, 0x60);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+ case GDISP_CONTROL_CONTRAST:
+ if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
+ acquire_bus(g);
+ write_reg(g, SETCON,(unsigned)128*(unsigned)g->p.ptr/101-64);
+ release_bus(g);
+ g->g.Contrast = (unsigned)g->p.ptr;
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld_board_olimexsam7ex256.h b/drivers/gdisp/Nokia6610GE12/gdisp_lld_board_olimexsam7ex256.h
deleted file mode 100644
index ce0f7362..00000000
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld_board_olimexsam7ex256.h
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE12/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
-
-// ******************************************************
-// 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 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 = 1<<12; // Set PA2 to HIGH
- // pPIOA->PIO_OER = 1<<12; // 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 = (1<<12) | (1<<16) | (1<<17) | (1<<18);
- pPIOA->PIO_ASR = (1<<12) | (1<<16) | (1<<17) | (1<<18);
- 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 setpin_reset(bool_t state) {
- if (state)
- palClearPad(IOPORT1, PIOA_LCD_RESET);
- else
- palSetPad(IOPORT1, PIOA_LCD_RESET);
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @note For now 0% turns the backlight off, anything else the backlight is on.
- * While the hardware supports PWM backlight control, we are not using it
- * yet.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- if (percent)
- palSetPad(IOPORT2, PIOB_LCD_BL);
- else
- palClearPad(IOPORT2, PIOB_LCD_BL);
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do for this board as the LCD is the only device on the SPI port */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- // Nothing to do for this board as the LCD is the only device on the SPI port
-}
-
-/**
- * @brief Send an 8 bit command to the lcd.
- *
- * @param[in] cmd The command to send
- *
- * @notapi
- */
-static inline void write_cmd(uint16_t cmd) {
- // wait for the previous transfer to complete
- while((pSPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0);
- // send the command
- pSPI->SPI_TDR = cmd & 0xFF;
-}
-
-/**
- * @brief Send an 8 bit data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(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 | 0x0100;
-}
-
-#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 read_data(void) {
- #error "gdispNokia6610GE12: 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/Nokia6610GE12/gdisp_lld_board_template.h b/drivers/gdisp/Nokia6610GE12/gdisp_lld_board_template.h
deleted file mode 100644
index a1fa6050..00000000
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE8/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the Nokia6610 GE8 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 init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @note For now 0% turns the backlight off, anything else the backlight is on.
- * While the hardware supports PWM backlight control, we are not using it
- * yet.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send an 8 bit command to the lcd.
- *
- * @param[in] cmd The command to send
- *
- * @notapi
- */
-static inline void write_cmd(uint16_t cmd) {
-
-}
-
-/**
- * @brief Send an 8 bit data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h b/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
index 57b8b916..19a455d8 100644
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
+++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h
@@ -22,21 +22,10 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "Nokia6610GE12"
+#define GDISP_HARDWARE_CONTROL TRUE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE
-#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
-/* This driver supports both packed and unpacked pixel formats and line formats.
- * By default we leave these as FALSE.
- */
-#define GDISP_PACKED_PIXELS FALSE
-#define GDISP_PACKED_LINES FALSE
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_template.h b/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_template.h
new file mode 100644
index 00000000..28fc9f70
--- /dev/null
+++ b/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_template.h
@@ -0,0 +1,131 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the Nokia6610 GE12 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/*
+ * Set various display properties. These properties mostly depend on the exact controller chip you get.
+ * The defaults should work for most controllers.
+ */
+//#define GDISP_SCREEN_HEIGHT 130 // The visible display height
+//#define GDISP_SCREEN_WIDTH 130 // The visible display width
+//#define GDISP_RAM_X_OFFSET 0 // The x offset of the visible area
+//#define GDISP_RAM_Y_OFFSET 2 // The y offset of the visible area
+//#define GDISP_SLEEP_POS 50 // The position of the sleep mode partial display
+//#define GDISP_INITIAL_CONTRAST 50 // The initial contrast percentage
+//#define GDISP_INITIAL_BACKLIGHT 100 // The initial backlight percentage
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c b/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
deleted file mode 100644
index ba5178d8..00000000
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
+++ /dev/null
@@ -1,545 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE8/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE8 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#include "GE8.h"
-
-/* This controller is only ever used with a 130 x 130 display */
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-#define GDISP_SCREEN_HEIGHT 130
-#define GDISP_SCREEN_WIDTH 130
-
-#define GDISP_SCAN_LINES 132 /* 130 lines + 2 invisible lines */
-#define GDISP_RAM_X_OFFSET 0 /* Offset in RAM of visible area */
-#define GDISP_RAM_Y_OFFSET 2 /* Offset in RAM of visible area */
-#define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines */
-#define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2)
-
-#define GDISP_INITIAL_CONTRAST 38
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-// Some macros just to make reading the code easier
-#define delayms(ms) gfxSleepMilliseconds(ms)
-#define write_data2(d1, d2) { write_data(d1); write_data(d2); }
-#define write_data3(d1, d2, d3) { write_data(d1); write_data(d2); write_data(d3); }
-#define write_data4(d1, d2, d3, d4) { write_data(d1); write_data(d2); write_data(d3); write_data(d4); }
-#define write_cmd1(cmd, d1) { write_cmd(cmd); write_data(d1); }
-#define write_cmd2(cmd, d1, d2) { write_cmd(cmd); write_data2(d1, d2); }
-#define write_cmd3(cmd, d1, d2, d3) { write_cmd(cmd); write_data3(d1, d2, d3); }
-#define write_cmd4(cmd, d1, d2, d3, d4) { write_cmd(cmd); write_data4(d1, d2, d3, d4); }
-
-// Set the drawing window on the controller.
-// An inline function has been used here incase the parameters have side effects with the internal calculations.
-static __inline void setviewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- write_cmd2(CASET, GDISP_RAM_X_OFFSET+x, GDISP_RAM_X_OFFSET+x+cx-1); // Column address set
- write_cmd2(PASET, GDISP_RAM_Y_OFFSET+y, GDISP_RAM_Y_OFFSET+y+cy-1); // Page address set
- break;
- case GDISP_ROTATE_90:
- write_cmd2(CASET, GDISP_RAM_X_OFFSET+GDISP.Height-y-cy, GDISP_RAM_X_OFFSET+GDISP.Height-y-1);
- write_cmd2(PASET, GDISP_RAM_Y_OFFSET+x, GDISP_RAM_Y_OFFSET+x+cx-1);
- break;
- case GDISP_ROTATE_180:
- write_cmd2(CASET, GDISP_RAM_X_OFFSET+GDISP.Width-x-cx, GDISP_RAM_X_OFFSET+GDISP.Width-x-1);
- write_cmd2(PASET, GDISP_RAM_Y_OFFSET+GDISP.Height-y-cy, GDISP_RAM_Y_OFFSET+GDISP.Height-y-1);
- break;
- case GDISP_ROTATE_270:
- write_cmd2(CASET, GDISP_RAM_X_OFFSET+y, GDISP_RAM_X_OFFSET+y+cy-1);
- write_cmd2(PASET, GDISP_RAM_Y_OFFSET+GDISP.Width-x-cx, GDISP_RAM_Y_OFFSET+GDISP.Width-x-1);
- break;
- }
-}
-
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
-
-/**
- * @brief Low level GDISP driver initialisation.
- *
- * @notapi
- */
-bool_t gdisp_lld_init(void) {
- /* Initialise your display */
- init_board();
-
- // Hardware reset
- setpin_reset(TRUE);
- delayms(20);
- setpin_reset(FALSE);
- delayms(20);
-
- // Get the bus for the following initialisation commands
- acquire_bus();
-
- write_cmd4(DISCTL, 0x00, GDISP_SCAN_LINES/4-1, 0x0A, 0x00); // Display control - How the controller drives the LCD
- // P1: 0x00 = 2 divisions, switching period=8 (default)
- // P2: 0x20 = nlines/4 - 1 = 132/4 - 1 = 32)
- // P3: 0x0A = standard inverse highlight, inversion every frame
- // P4: 0x00 = dispersion on
- write_cmd1(COMSCN, 0x01); // COM scan - How the LCD is connected to the controller
- // P1: 0x01 = Scan 1->80, 160<-81
- write_cmd(OSCON); // Internal oscillator ON
- write_cmd(SLPOUT); // Sleep out
- write_cmd1(PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
- write_cmd3(DATCTL, 0x00, 0x00, 0x02); // Data control
- // P1: 0x00 = page address normal, column address normal, address scan in column direction
- // P2: 0x00 = RGB sequence (default value)
- // P3: 0x02 = 4 bits per colour (Type A)
- write_cmd2(VOLCTR, GDISP_INITIAL_CONTRAST, 0x03); // Voltage control (contrast setting)
- // P1 = Contrast
- // P2 = 3 resistance ratio (only value that works)
- delayms(100); // Allow power supply to stabilise
- write_cmd(DISON); // Turn on the display
-
- // Release the bus
- release_bus();
-
- /* Turn on the back-light */
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure to match */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
- acquire_bus();
- setviewport(x, y, 1, 1);
- write_cmd3(RAMWR, 0, (color>>8) & 0x0F, color & 0xFF);
- release_bus();
-}
-
-/* ---- Optional Routines ---- */
-
-#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__)
- /**
- * @brief Fill an area with a color.
- *
- * @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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned tuples;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- tuples = (cx*cy+1)>>1; // With an odd sized area we over-print by one pixel.
- // This extra pixel overwrites the first pixel (harmless as it is the same colour)
-
- acquire_bus();
- setviewport(x, y, cx, cy);
- write_cmd(RAMWR);
- while(tuples--)
- write_data3(((color >> 4) & 0xFF), (((color << 4) & 0xF0)|((color >> 8) & 0x0F)), (color & 0xFF));
- release_bus();
- }
-#endif
-
-#if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__)
- /**
- * @brief Fill an area with a bitmap.
- *
- * @param[in] x, y The start filled area
- * @param[in] cx, cy The width and height to be filled
- * @param[in] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t lg;
- color_t c1, c2;
- unsigned tuples;
- #if GDISP_PACKED_PIXELS
- unsigned pnum, pstart;
- const uint8_t *p;
- #else
- const pixel_t *p;
- #endif
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- /* Set up the data window to transfer */
- tuples = (cx * cy + 1)>>1;
- acquire_bus();
- setviewport(x, y, cx, cy);
- write_cmd(RAMWR);
-
- /*
- * Due to the way the Nokia6610 handles a decrementing column or page,
- * we have to make adjustments as to where it is actually drawing from in the bitmap.
- * For example, for 90 degree rotation the column is decremented on each
- * memory write. The controller always starts with column 0 and then decrements
- * to column cx-1, cx-2 etc. We therefore have to write-out the last bitmap line first.
- */
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0: x = 0; y = 0; break;
- case GDISP_ROTATE_90: x = 0; y = cy-1; break;
- case GDISP_ROTATE_180: x = cx-1; y = cy-1; break;
- case GDISP_ROTATE_270: x = cx-1; y = 0; break;
- }
-
- #if !GDISP_PACKED_PIXELS
- // 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.
-
- lg = srccx - cx; // The buffer gap between lines
- buffer += srcy * srccx + srcx; // The buffer start position
- p = buffer + srccx*y + x; // Adjustment for controller craziness
-
- while(tuples--) {
- /* Get a pixel */
- c1 = *p++;
-
- /* Check for line or buffer wrapping */
- if (++x >= cx) {
- x = 0;
- p += lg;
- if (++y >= cy) {
- y = 0;
- p = buffer;
- }
- }
-
- /* Get the next pixel */
- c2 = *p++;
-
- /* Check for line or buffer wrapping */
- if (++x >= cx) {
- x = 0;
- p += lg;
- if (++y >= cy) {
- y = 0;
- p = buffer;
- }
- }
-
- /* Write the pair of pixels to the display */
- write_data3(((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
- }
-
- #else
-
- // Although this controller uses packed pixels, we may have to feed it into
- // the controller with different packing to the source bitmap
- // There are 2 pixels per 3 bytes
-
- #if !GDISP_PACKED_LINES
- srccx = (srccx + 1) & ~1;
- #endif
- pstart = srcy * srccx + srcx; // The starting pixel number
- buffer = (const pixel_t)(((const uint8_t *)buffer) + ((pstart>>1) * 3)); // The buffer start position
- lg = ((srccx-cx)>>1)*3; // The buffer gap between lines
- pnum = pstart + srccx*y + x; // Adjustment for controller craziness
- p = ((const uint8_t *)buffer) + (((srccx*y + x)>>1)*3); // Adjustment for controller craziness
-
- while (tuples--) {
- /* Get a pixel */
- switch(pnum++ & 1) {
- case 0: c1 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
- case 1: c1 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
- }
-
- /* Check for line or buffer wrapping */
- if (++x >= cx) {
- x = 0;
- p += lg;
- pnum += srccx - cx;
- if (++y >= cy) {
- y = 0;
- p = (const uint8_t *)buffer;
- pnum = pstart;
- }
- }
-
- /* Get the next pixel */
- switch(pnum++ & 1) {
- case 0: c1 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
- case 1: c1 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
- }
-
- /* Check for line or buffer wrapping */
- if (++x >= cx) {
- x = 0;
- p += lg;
- pnum += srccx - cx;
- if (++y >= cy) {
- y = 0;
- p = (const uint8_t *)buffer;
- pnum = pstart;
- }
- }
-
- /* Write the pair of pixels to the display */
- write_data3(((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
- }
- #endif
-
- /* All done */
- release_bus();
- }
-#endif
-
-#if (GDISP_NEED_PIXELREAD && GDISP_HARDWARE_PIXELREAD)
- /**
- * @brief Get the color of a particular pixel.
- * @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_get_pixel_color(coord_t x, coord_t y) {
- /* NOT IMPLEMENTED */
- /* This controller does not support reading back over the SPI interface.
- * Additionally, the Olimex board doesn't even connect the pin.
- */
- }
-#endif
-
-#if (GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL)
- /**
- * @brief Scroll vertically a section of the screen.
- * @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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- /* NOT IMPLEMENTED */
- /**
- * The hardware is capable of doing full width vertical scrolls aligned
- * on a 4 line boundary however that is not sufficient to support this routine.
- *
- * We also can't manually do read/modify scrolling because we can't read in SPI mode.
- */
- }
-#endif
-
-#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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) {
- /* The hardware is capable of supporting...
- * GDISP_CONTROL_POWER - supported
- * GDISP_CONTROL_ORIENTATION - supported
- * GDISP_CONTROL_BACKLIGHT - supported
- * GDISP_CONTROL_CONTRAST - supported
- */
- switch(what) {
- case GDISP_CONTROL_POWER:
- if (GDISP.Powermode == (gdisp_powermode_t)value)
- return;
- acquire_bus();
- switch((gdisp_powermode_t)value) {
- case powerOff:
- set_backlight(0); // Turn off the backlight
- write_cmd(DISOFF); // Turn off the display
- write_cmd1(PWRCTR, 0x00); // Power control - all off
- write_cmd(SLPIN); // Sleep in
- write_cmd(OSCOFF); // Internal oscillator off
- break;
- case powerOn:
- write_cmd(OSCON); // Internal oscillator on
- write_cmd(SLPOUT); // Sleep out
- write_cmd1(PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
- write_cmd2(VOLCTR, GDISP.Contrast, 0x03); // Voltage control (contrast setting)
- delayms(100); // Allow power supply to stabilise
- write_cmd(DISON); // Turn on the display
- write_cmd(PTLOUT); // Remove sleep window
- set_backlight(GDISP.Backlight); // Turn on the backlight
- break;
- case powerSleep:
- write_cmd(OSCON); // Internal oscillator on
- write_cmd(SLPOUT); // Sleep out
- write_cmd1(PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
- write_cmd2(VOLCTR, GDISP.Contrast, 0x03); // Voltage control (contrast setting)
- delayms(100); // Allow power supply to stabilise
- write_cmd(DISON); // Turn on the display
- write_cmd2(PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
- set_backlight(GDISP.Backlight); // Turn on the backlight
- break;
- case powerDeepSleep:
- write_cmd(OSCON); // Internal oscillator on
- write_cmd(SLPOUT); // Sleep out
- write_cmd1(PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
- write_cmd2(VOLCTR, GDISP.Contrast, 0x03); // Voltage control (contrast setting)
- delayms(100); // Allow power supply to stabilise
- write_cmd(DISON); // Turn on the display
- write_cmd2(PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
- set_backlight(0); // Turn off the backlight
- break;
- default:
- release_bus();
- return;
- }
- release_bus();
- GDISP.Powermode = (gdisp_powermode_t)value;
- return;
- case GDISP_CONTROL_ORIENTATION:
- if (GDISP.Orientation == (gdisp_orientation_t)value)
- return;
- acquire_bus();
- switch((gdisp_orientation_t)value) {
- case GDISP_ROTATE_0:
- write_cmd3(DATCTL, 0x00, 0x00, 0x02); // P1: page normal, column normal, scan in column direction
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- write_cmd3(DATCTL, 0x06, 0x00, 0x02); // P1: page normal, column reverse, scan in page direction
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- write_cmd3(DATCTL, 0x03, 0x00, 0x02); // P1: page reverse, column reverse, scan in column direction
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- write_cmd3(DATCTL, 0x05, 0x00, 0x02); // P1: page reverse, column normal, scan in page direction
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- release_bus();
- return;
- }
- release_bus();
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
- case GDISP_CONTROL_BACKLIGHT:
- if ((unsigned)value > 100) value = (void *)100;
- set_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- return;
- case GDISP_CONTROL_CONTRAST:
- if ((unsigned)value > 100) value = (void *)100;
- acquire_bus();
- write_cmd2(VOLCTR, (unsigned)value, 0x03);
- release_bus();
- GDISP.Contrast = (unsigned)value;
- return;
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk b/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk
index 3e1f1851..a61948b3 100644
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk
+++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8
+GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c b/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c
new file mode 100644
index 00000000..f6ce4278
--- /dev/null
+++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c
@@ -0,0 +1,570 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/Nokia6610GE8/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE8 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+/**
+ * This is for the EPSON (GE8) controller driving a Nokia6610 color LCD display.
+ * Note that there is also a PHILIPS (GE12) controller for the same display that this code
+ * does not support.
+ *
+ * The controller drives a 132x132 display but a 1 pixel surround is not visible
+ * which gives a visible area of 130x130.
+ *
+ * This controller does not support reading back over the SPI interface.
+ * Additionally, the Olimex board doesn't even connect the pin.
+ *
+ * The hardware is capable of doing full width vertical scrolls aligned
+ * on a 4 line boundary however that is not sufficient to support general vertical scrolling.
+ * We also can't manually do read/modify scrolling because we can't read in SPI mode.
+ *
+ * The controller has some quirkyness when operating in other than rotation 0 mode.
+ * When any direction is decremented it starts at location 0 rather than the end of
+ * the area. Whilst this can be handled when we know the specific operation (pixel, fill, blit)
+ * it cannot be handled in a generic stream operation. So, when orientation support is turned
+ * on (and needed) we use complex operation specific routines instead of simple streaming
+ * routines. This has a (small) performance penalty and a significant code size penalty so
+ * don't turn on orientation support unless you really need it.
+ *
+ * Some of the more modern controllers have a broken command set. If you have one of these
+ * you will recognise it by the colors being off on anything drawn after an odd (as opposed to
+ * even) pixel count area being drawn. If so then set GDISP_GE8_BROKEN_CONTROLLER to TRUE
+ * on your gdisp_lld_board.h file. The price is that streaming calls that are completed
+ * without exactly the window size write operations and where the number of write operations
+ * is odd (rather than even), it will draw an extra pixel. If this is important to you, turn on
+ * orientation support and the streaming operations will be emulated (as described above).
+ */
+
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_Nokia6610GE8
+#include "../drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_Nokia6610GE8.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#include "GE8.h"
+
+#define GDISP_SCAN_LINES 132
+
+// Set parameters if they are not already set
+#ifndef GDISP_GE8_BROKEN_CONTROLLER
+ #define GDISP_GE8_BROKEN_CONTROLLER TRUE
+#endif
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 130
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 130
+#endif
+#ifndef GDISP_RAM_X_OFFSET
+ #define GDISP_RAM_X_OFFSET 0 /* Offset in RAM of visible area */
+#endif
+#ifndef GDISP_RAM_Y_OFFSET
+ #define GDISP_RAM_Y_OFFSET 2 /* Offset in RAM of visible area */
+#endif
+#ifndef GDISP_SLEEP_SIZE
+ #define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines */
+#endif
+#ifndef GDISP_SLEEP_POS
+ #define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2)
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 60
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ typedef struct dvrPriv {
+ uint16_t savecolor;
+ #if GDISP_GE8_BROKEN_CONTROLLER
+ uint16_t firstcolor;
+ #endif
+ } dvrPriv;
+ #define PRIV ((dvrPriv *)g->priv)
+#endif
+
+#define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
+#define GDISP_FLG_RUNBYTE (GDISP_FLG_DRIVER<<1)
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some macros just to make reading the code easier
+#define delayms(ms) gfxSleepMilliseconds(ms)
+#define write_data2(g, d1, d2) { write_data(g, d1); write_data(g, d2); }
+#define write_data3(g, d1, d2, d3) { write_data(g, d1); write_data(g, d2); write_data(g, d3); }
+#define write_data4(g, d1, d2, d3, d4) { write_data(g, d1); write_data(g, d2); write_data(g, d3); write_data(g, d4); }
+#define write_cmd1(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
+#define write_cmd2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
+#define write_cmd3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
+#define write_cmd4(g, cmd, d1, d2, d3, d4) { write_index(g, cmd); write_data4(g, d1, d2, d3, d4); }
+
+static inline void set_viewport(GDisplay* g) {
+ #if GDISP_NOKIA_ORIENTATION && GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x); // Column address set
+ write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y); // Page address set
+ break;
+ case GDISP_ROTATE_90:
+ write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.y, GDISP_RAM_X_OFFSET+g->p.y);
+ write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET-1+g->g.Width-g->p.x, GDISP_RAM_Y_OFFSET-1+g->g.Width-g->p.x);
+ break;
+ case GDISP_ROTATE_180:
+ write_cmd2(g, CASET, GDISP_RAM_X_OFFSET-1+g->g.Width-g->p.x, GDISP_RAM_X_OFFSET-1+g->g.Width-g->p.x);
+ write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET-1+g->g.Height-g->p.y, GDISP_RAM_Y_OFFSET-1+g->g.Height-g->p.y);
+ break;
+ case GDISP_ROTATE_270:
+ write_cmd2(g, CASET, GDISP_RAM_X_OFFSET-1+g->g.Height-g->p.y, GDISP_RAM_X_OFFSET-1+g->g.Height-g->p.y);
+ write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.x, GDISP_RAM_Y_OFFSET+g->p.x);
+ break;
+ }
+ #else
+ write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
+ write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
+ #endif
+ write_index(g, RAMWR);
+}
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ #if GDISP_HARDWARE_STREAM_WRITE
+ g->priv = gfxAlloc(sizeof(dvrPriv));
+ #else
+ g->priv = 0;
+ #endif
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ delayms(20);
+ setpin_reset(g, FALSE);
+ delayms(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ write_cmd4(g, DISCTL, 0x00, GDISP_SCAN_LINES/4-1, 0x0A, 0x00); // Display control - How the controller drives the LCD
+ // P1: 0x00 = 2 divisions, switching period=8 (default)
+ // P2: 0x20 = nlines/4 - 1 = 132/4 - 1 = 32)
+ // P3: 0x0A = standard inverse highlight, inversion every frame
+ // P4: 0x00 = dispersion on
+ write_cmd1(g, COMSCN, 0x01); // COM scan - How the LCD is connected to the controller
+ // P1: 0x01 = Scan 1->80, 160<-81
+ write_index(g, OSCON); // Internal oscillator ON
+ write_index(g, SLPOUT); // Sleep out
+ write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
+ write_cmd3(g, DATCTL, 0x00, 0x00, 0x02); // Data control
+ // P1: 0x00 = page address normal, column address normal, address scan in column direction
+ // P2: 0x00 = RGB sequence (default value)
+ // P3: 0x02 = 4 bits per colour (Type A)
+ write_cmd2(g, VOLCTR, 64*GDISP_INITIAL_CONTRAST/101, 0x03); // Voltage control (contrast setting)
+ // P1 = Contrast (0..63)
+ // P2 = 3 resistance ratio (only value that works)
+ delayms(100); // Allow power supply to stabilise
+ write_index(g, DISON); // Turn on the display
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure to match */
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ g->flags &= ~(GDISP_FLG_ODDBYTE|GDISP_FLG_RUNBYTE);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ uint16_t c;
+
+ c = COLOR2NATIVE(g->p.color);
+ #if GDISP_GE8_BROKEN_CONTROLLER
+ if (!(g->flags & GDISP_FLG_RUNBYTE)) {
+ PRIV->firstcolor = c;
+ g->flags |= GDISP_FLG_RUNBYTE;
+ }
+ #endif
+ if ((g->flags & GDISP_FLG_ODDBYTE)) {
+ // Write the pair of pixels to the display
+ write_data3(g, ((PRIV->savecolor >> 4) & 0xFF),
+ (((PRIV->savecolor << 4) & 0xF0)|((c >> 8) & 0x0F)),
+ (c & 0xFF));
+ g->flags &= ~GDISP_FLG_ODDBYTE;
+ } else {
+ PRIV->savecolor = c;
+ g->flags |= GDISP_FLG_ODDBYTE;
+ }
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ if ((g->flags & GDISP_FLG_ODDBYTE)) {
+ #if GDISP_GE8_BROKEN_CONTROLLER
+ /**
+ * We have a real problem here - we need to write a singular pixel
+ * Methods that are supposed to work...
+ * 1/ Write the pixel (2 bytes) and then send a NOP command. This doesn't work, the pixel doesn't get written
+ * and it is maintained in the latch where it causes problems for the next window.
+ * 2/ Just write a dummy extra pixel as stuff beyond the window gets discarded. This doesn't work as contrary to
+ * the documentation the buffer wraps and the first pixel gets overwritten.
+ * 3/ Put the controller in 16 bits per pixel Type B mode where each pixel is performed by writing two bytes. This
+ * also doesn't work as the controller refuses to enter Type B mode (it stays in Type A mode).
+ *
+ * These methods might work on some controllers - just not on the one of the broken versions.
+ *
+ * For these broken controllers:
+ * We know we can wrap to the first byte (just overprint it) if we are at the end of the stream area.
+ * If not, we need to create a one pixel by one pixel window to fix this - Uuch. Fortunately this should only happen if the
+ * user application uses the streaming calls and then terminates the stream early or after buffer wrap.
+ * Since this is such an unlikely situation we just don't handle it.
+ */
+ write_data3(g, ((PRIV->savecolor >> 4) & 0xFF),
+ (((PRIV->savecolor << 4) & 0xF0)|((PRIV->firstcolor >> 8) & 0x0F)),
+ (PRIV->firstcolor & 0xFF));
+ #else
+ write_data2(g, ((PRIV->savecolor >> 4) & 0xFF), ((PRIV->savecolor << 4) & 0xF0));
+ write_index(g, NOP);
+ #endif
+ }
+
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+ uint16_t c;
+
+ c = COLOR2NATIVE(g->p.color);
+ acquire_bus(g);
+ set_viewport(g);
+ write_data3(g, 0, (c>>8) & 0x0F, c & 0xFF);
+ release_bus(g);
+ }
+#endif
+
+/* ---- Optional Routines ---- */
+
+#if GDISP_HARDWARE_FILLS
+ LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
+ unsigned tuples;
+ uint16_t c;
+
+ tuples = (g->p.cx*g->p.cy+1)>>1; // With an odd sized area we over-print by one pixel.
+ // This extra pixel overwrites the first pixel (harmless as it is the same colour)
+
+ c = COLOR2NATIVE(g->p.color);
+ acquire_bus(g);
+ set_viewport(g);
+ while(tuples--)
+ write_data3(g, ((c >> 4) & 0xFF), (((c << 4) & 0xF0)|((c >> 8) & 0x0F)), (c & 0xFF));
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_BITFILLS
+ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
+ coord_t lg, x, y;
+ uint16_t c1, c2;
+ unsigned tuples;
+ const pixel_t *buffer;
+ #if GDISP_PACKED_PIXELS
+ unsigned pnum, pstart;
+ const uint8_t *p;
+ #else
+ const pixel_t *p;
+ #endif
+
+ tuples = (g->p.cx * g->p.cy + 1)>>1;
+ buffer = (const pixel_t *)g->p.ptr;
+
+ /* Set up the data window to transfer */
+ acquire_bus(g);
+ set_viewport(g);
+
+ /* to suppress compiler warnings */
+ x = 0;
+ y = 0;
+
+ /*
+ * Due to the way the Nokia6610 handles a decrementing column or page,
+ * we have to make adjustments as to where it is actually drawing from in the bitmap.
+ * For example, for 90 degree rotation the column is decremented on each
+ * memory write. The controller always starts with column 0 and then decrements
+ * to column cx-1, cx-2 etc. We therefore have to write-out the last bitmap line first.
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0: x = 0; y = 0; break;
+ case GDISP_ROTATE_90: x = g->p.cx-1; y = 0; break;
+ case GDISP_ROTATE_180: x = g->p.cx-1; y = g->p.cy-1; break;
+ case GDISP_ROTATE_270: x = 0; y = g->p.cy-1; break;
+ }
+
+ #if !GDISP_PACKED_PIXELS
+ // 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.
+
+ lg = g->p.x2 - g->p.cx; // The buffer gap between lines
+ buffer += g->p.y1 * g->p.x2 + g->p.x1; // The buffer start position
+ p = buffer + g->p.x2*y + x; // Adjustment for controller craziness
+
+ while(tuples--) {
+ /* Get a pixel */
+ c1 = COLOR2NATIVE(*p++);
+
+ /* Check for line or buffer wrapping */
+ if (++x >= g->p.cx) {
+ x = 0;
+ p += lg;
+ if (++y >= g->p.cy) {
+ y = 0;
+ p = buffer;
+ }
+ }
+
+ /* Get the next pixel */
+ c2 = COLOR2NATIVE(*p++);
+
+ /* Check for line or buffer wrapping */
+ if (++x >= g->p.cx) {
+ x = 0;
+ p += lg;
+ if (++y >= g->p.cy) {
+ y = 0;
+ p = buffer;
+ }
+ }
+
+ /* Write the pair of pixels to the display */
+ write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
+ }
+
+ #elif GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT
+
+ // Although this controller uses packed pixels, we may have to feed it into
+ // the controller with different packing to the source bitmap
+ // There are 2 pixels per 3 bytes
+
+ #if !GDISP_PACKED_LINES
+ srccx = (g->p.x2 + 1) & ~1;
+ #endif
+ pstart = g->p.y1 * g->p.x2 + g->p.x1; // The starting pixel number
+ buffer = (const pixel_t)(((const uint8_t *)buffer) + ((pstart>>1) * 3)); // The buffer start position
+ lg = ((g->p.x2-g->p.cx)>>1)*3; // The buffer gap between lines
+ pnum = pstart + g->p.x2*y + x; // Adjustment for controller craziness
+ p = ((const uint8_t *)buffer) + (((g->p.x2*y + x)>>1)*3); // Adjustment for controller craziness
+
+ while (tuples--) {
+ /* Get a pixel */
+ switch(pnum++ & 1) {
+ case 0: c1 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
+ case 1: c1 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
+ }
+
+ /* Check for line or buffer wrapping */
+ if (++x >= g->p.cx) {
+ x = 0;
+ p += lg;
+ pnum += g->p.x2 - g->p.cx;
+ if (++y >= g->p.cy) {
+ y = 0;
+ p = (const uint8_t *)buffer;
+ pnum = pstart;
+ }
+ }
+
+ /* Get the next pixel */
+ switch(pnum++ & 1) {
+ case 0: c2 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
+ case 1: c2 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
+ }
+
+ /* Check for line or buffer wrapping */
+ if (++x >= g->p.cx) {
+ x = 0;
+ p += lg;
+ pnum += g->p.x2 - g->p.cx;
+ if (++y >= g->p.cy) {
+ y = 0;
+ p = (const uint8_t *)buffer;
+ pnum = pstart;
+ }
+ }
+
+ /* Write the pair of pixels to the display */
+ write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
+ }
+
+ #else
+ #error "Packed pixels is broken if you are not running native pixel format"
+ #endif
+
+ /* All done */
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ /* The hardware is capable of supporting...
+ * GDISP_CONTROL_POWER - supported
+ * GDISP_CONTROL_ORIENTATION - supported
+ * GDISP_CONTROL_BACKLIGHT - supported
+ * GDISP_CONTROL_CONTRAST - supported
+ */
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ acquire_bus(g);
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ set_backlight(g, 0); // Turn off the backlight
+ write_index(g, DISOFF); // Turn off the display
+ write_cmd1(g, PWRCTR, 0x00); // Power control - all off
+ write_index(g, SLPIN); // Sleep in
+ write_index(g, OSCOFF); // Internal oscillator off
+ break;
+ case powerOn:
+ write_index(g, OSCON); // Internal oscillator on
+ write_index(g, SLPOUT); // Sleep out
+ write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
+ write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
+ delayms(100); // Allow power supply to stabilise
+ write_index(g, DISON); // Turn on the display
+ write_index(g, PTLOUT); // Remove sleep window
+ set_backlight(g, g->g.Backlight); // Turn on the backlight
+ break;
+ case powerSleep:
+ write_index(g, OSCON); // Internal oscillator on
+ write_index(g, SLPOUT); // Sleep out
+ write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
+ write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
+ delayms(100); // Allow power supply to stabilise
+ write_index(g, DISON); // Turn on the display
+ write_cmd2(g, PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
+ set_backlight(g, g->g.Backlight); // Turn on the backlight
+ break;
+ case powerDeepSleep:
+ write_index(g, OSCON); // Internal oscillator on
+ write_index(g, SLPOUT); // Sleep out
+ write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
+ write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
+ delayms(100); // Allow power supply to stabilise
+ write_index(g, DISON); // Turn on the display
+ write_cmd2(g, PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
+ set_backlight(g, 0); // Turn off the backlight
+ break;
+ default:
+ release_bus(g);
+ return;
+ }
+ release_bus(g);
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+ #if GDISP_NOKIA_ORIENTATION
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ acquire_bus(g);
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ write_cmd3(g, DATCTL, 0x00, 0x00, 0x02); // P1: page normal, column normal, scan in column direction
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ write_cmd3(g, DATCTL, 0x05, 0x00, 0x02); // P1: page reverse, column normal, scan in page direction
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ write_cmd3(g, DATCTL, 0x03, 0x00, 0x02); // P1: page reverse, column reverse, scan in column direction
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ write_cmd3(g, DATCTL, 0x06, 0x00, 0x02); // P1: page normal, column reverse, scan in page direction
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ release_bus(g);
+ return;
+ }
+ release_bus(g);
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+ #endif
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+ case GDISP_CONTROL_CONTRAST:
+ if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
+ acquire_bus(g);
+ write_cmd2(g, VOLCTR, 64*(unsigned)g->p.ptr/101, 0x03);
+ release_bus(g);
+ g->g.Contrast = (unsigned)g->p.ptr;
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
+/** @} */
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld_board_olimexsam7ex256.h b/drivers/gdisp/Nokia6610GE8/gdisp_lld_board_olimexsam7ex256.h
deleted file mode 100644
index 90a1277b..00000000
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld_board_olimexsam7ex256.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE8/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
-
-// ******************************************************
-// Pointers to AT91SAM7X256 peripheral data structures
-// ******************************************************
-static volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
-static volatile AT91PS_PIO pPIOB = AT91C_BASE_PIOB;
-static volatile AT91PS_SPI pSPI = AT91C_BASE_SPI0;
-static volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
-static volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_SPI0;
-
-/* The PWM backlight control is non-linear on this board.
- * We pick values here that make it look a bit more linear.
- */
-#define PWM_TOP_VALUE 500
-#define PWM_BOTTOM_VALUE 200
-
-#define PWM_VALUE(x) (PWM_BOTTOM_VALUE+(PWM_TOP_VALUE-PWM_BOTTOM_VALUE)*(x)/100)
-
-/* PWM configuration structure. The LCD Backlight is on PWM1/PB20 ie PWM2/PIN1 in ChibiOS speak */
-static const PWMConfig pwmcfg = {
- 1000000, /* 1 MHz PWM clock frequency. Ignored as we are using PWM_MCK_DIV_n */
- 1000, /* PWM period is 1000 cycles. */
- NULL,
- {
- {PWM_MCK_DIV_1 | PWM_OUTPUT_ACTIVE_HIGH | PWM_OUTPUT_PIN1 | PWM_DISABLEPULLUP_PIN1, NULL},
- },
-};
-
-static bool_t pwmRunning = FALSE;
-
-/**
- * @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 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 = 1<<12; // Set PA2 to HIGH
- // pPIOA->PIO_OER = 1<<12; // 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 = (1<<12) | (1<<16) | (1<<17) | (1<<18);
- pPIOA->PIO_ASR = (1<<12) | (1<<16) | (1<<17) | (1<<18);
- 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
-
- /* Display backlight control at 100% */
- pwmRunning = FALSE;
- palSetPad(IOPORT2, PIOB_LCD_BL);
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- if (state)
- palClearPad(IOPORT1, PIOA_LCD_RESET);
- else
- palSetPad(IOPORT1, PIOA_LCD_RESET);
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @note For now 0% turns the backlight off, anything else the backlight is on.
- * While the hardware supports PWM backlight control, we are not using it
- * yet.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- if (percent == 100) {
- /* Turn the pin on - No PWM */
- if (pwmRunning) {
- pwmStop(&PWMD2);
- pwmRunning = FALSE;
- }
- palSetPad(IOPORT2, PIOB_LCD_BL);
- } else if (percent == 0) {
- /* Turn the pin off - No PWM */
- if (pwmRunning) {
- pwmStop(&PWMD2);
- pwmRunning = FALSE;
- }
- palClearPad(IOPORT2, PIOB_LCD_BL);
- } else {
- /* Use the PWM */
- if (!pwmRunning) {
- pwmStart(&PWMD2, &pwmcfg);
- pwmRunning = TRUE;
- }
- pwmEnableChannel(&PWMD2, 0, PWM_VALUE(percent));
- }
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do for this board as the LCD is the only device on the SPI port */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- // Nothing to do for this board as the LCD is the only device on the SPI port
-}
-
-/**
- * @brief Send an 8 bit command to the lcd.
- *
- * @param[in] cmd The command to send
- *
- * @notapi
- */
-static inline void write_cmd(uint16_t cmd) {
- // wait for the previous transfer to complete
- while((pSPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0);
- // send the command
- pSPI->SPI_TDR = cmd & 0xFF;
-}
-
-/**
- * @brief Send an 8 bit data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(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 | 0x0100;
-}
-
-#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 read_data(void) {
- #error "gdispNokia6610GE8: 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/Nokia6610GE8/gdisp_lld_board_template.h b/drivers/gdisp/Nokia6610GE8/gdisp_lld_board_template.h
deleted file mode 100644
index a1fa6050..00000000
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/Nokia6610GE8/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the Nokia6610 GE8 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 init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @note For now 0% turns the backlight off, anything else the backlight is on.
- * While the hardware supports PWM backlight control, we are not using it
- * yet.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send an 8 bit command to the lcd.
- *
- * @param[in] cmd The command to send
- *
- * @notapi
- */
-static inline void write_cmd(uint16_t cmd) {
-
-}
-
-/**
- * @brief Send an 8 bit data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h b/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
index 1a748684..1476dbcf 100644
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
+++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h
@@ -22,21 +22,26 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "Nokia6610GE8"
-
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_SOFTWARE_TEXTFILLDRAW FALSE
-#define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
-/* This driver supports both packed and unpacked pixel formats and line formats.
- * By default we leave these as FALSE.
+/* This driver has problems with other orientations and requires significantly
+ * extra code to handle them. By default we turn this on (only if the GDISP_NEED_CONTROL
+ * is turned on). If you are worried about code size and don't need orientation support
+ * define GDISP_NOKIA_ORIENTATION as false.
*/
-#define GDISP_PACKED_PIXELS FALSE
-#define GDISP_PACKED_LINES FALSE
+#ifndef GDISP_NOKIA_ORIENTATION
+ #define GDISP_NOKIA_ORIENTATION TRUE
+#endif
+
+#if GDISP_NOKIA_ORIENTATION && GDISP_NEED_CONTROL
+ #define GDISP_HARDWARE_CONTROL TRUE
+ #define GDISP_HARDWARE_DRAWPIXEL TRUE
+ #define GDISP_HARDWARE_FILLS TRUE
+ #define GDISP_HARDWARE_BITFILLS TRUE
+#else
+ #define GDISP_HARDWARE_CONTROL TRUE
+ #define GDISP_HARDWARE_STREAM_WRITE TRUE
+#endif
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB444
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/RA8875/board_RA8875_template.h b/drivers/gdisp/RA8875/board_RA8875_template.h
new file mode 100644
index 00000000..fce05129
--- /dev/null
+++ b/drivers/gdisp/RA8875/board_RA8875_template.h
@@ -0,0 +1,143 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1963/board_RA8875_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the RA8875 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note The chip select may need to be asserted/de-asserted
+ * around the actual spi read
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/RA8875/gdisp_lld.c b/drivers/gdisp/RA8875/gdisp_lld.c
deleted file mode 100644
index 397c933a..00000000
--- a/drivers/gdisp/RA8875/gdisp_lld.c
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/RA8875/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#include "ra8875.h"
-
-/* include the board abstraction */
-#include "gdisp_lld_board.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 initialisation.
- * @return TRUE if successful, FALSE on error.
- *
- * @notapi
- */
-bool_t gdisp_lld_init(void) {
- /* Initialise the display */
- init_board();
-
- /* soft reset */
- write_index(0x01);
- write_data(0x01);
- write_data(0x00);
- gfxSleepMilliseconds(1);
-
- /* Driver PLL config 480x272*/
- write_index(0x88);
- write_data(0x08);
- gfxSleepMilliseconds(1);
- write_index(0x89);
- write_data(0x02);
- gfxSleepMilliseconds(1);
-
- write_index(0x10); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
- write_data(0x0F); // if 16bit MCU interface and 65k color display
-
- write_index(0x04); //set PCLK invers
- write_data(0x82);
- gfxSleepMilliseconds(1);
-
- //Horizontal set
- write_index(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0]
- write_data(0x3B);//Horizontal display width(pixels) = (HDWR + 1)*8
- write_index(0x15); //Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR)
- write_data(0x00);//Horizontal Non-Display Period Fine Tuning(HNDFT) [3:0]
- write_index(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
- write_data(0x01);//Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
- write_index(0x17); //HSTR//HSYNC Start Position[4:0]
- write_data(0x00);//HSYNC Start Position(PCLK) = (HSTR + 1)*8
- write_index(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
- write_data(0x05);//HSYNC Width [4:0] HSYNC Pulse width(PCLK) = (HPWR + 1)*8
-
- //Vertical set
- write_index(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
- write_data(0x0f); //Vertical pixels = VDHR + 1
- write_index(0x1a); //VDHR1 //Vertical Display Height Bit [8]
- write_data(0x01); //Vertical pixels = VDHR + 1
- write_index(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
- write_data(0x02); //VSYNC Start Position(PCLK) = (VSTR + 1)
- write_index(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
- write_data(0x00); //Vertical Non-Display area = (VNDR + 1)
- write_index(0x1d); //VSTR0 //VSYNC Start Position[7:0]
- write_data(0x07);//VSYNC Start Position(PCLK) = (VSTR + 1)
- write_index(0x1e); //VSTR1 //VSYNC Start Position[8]
- write_data(0x00);//VSYNC Start Position(PCLK) = (VSTR + 1)
- write_index(0x1f); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
- write_data(0x09); //VSYNC Pulse Width(PCLK) = (VPWR + 1)
-
- //Active window set
- //setting active window X
- write_index(0x30); //Horizontal Start Point 0 of Active Window (HSAW0)
- write_data(0x00); //Horizontal Start Point of Active Window [7:0]
- write_index(0x31); //Horizontal Start Point 1 of Active Window (HSAW1)
- write_data(0x00); //Horizontal Start Point of Active Window [9:8]
- write_index(0x34); //Horizontal End Point 0 of Active Window (HEAW0)
- write_data(0xDF); //Horizontal End Point of Active Window [7:0]
- write_index(0x35); //Horizontal End Point 1 of Active Window (HEAW1)
- write_data(0x01); //Horizontal End Point of Active Window [9:8]
-
- //setting active window Y
- write_index(0x32); //Vertical Start Point 0 of Active Window (VSAW0)
- write_data(0x00); //Vertical Start Point of Active Window [7:0]
- write_index(0x33); //Vertical Start Point 1 of Active Window (VSAW1)
- write_data(0x00); //Vertical Start Point of Active Window [8]
- write_index(0x36); //Vertical End Point of Active Window 0 (VEAW0)
- write_data(0x0F); //Vertical End Point of Active Window [7:0]
- write_index(0x37); //Vertical End Point of Active Window 1 (VEAW1)
- write_data(0x01); //Vertical End Point of Active Window [8]
-
- // Display ON
- write_index(0x01); //PWRR
- write_data(0x80);
-
- // GPO0 DISP high
- write_index(0x13); //GPO
- write_data(0x01);
-
- set_backlight(0x80); //set to 90% brightness
-
- post_init_board();
-
- /* Initialise the GDISP structure to match */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
-
- return TRUE;
-}
-
-void gdisp_lld_setwindow(coord_t x0, coord_t y0, coord_t x1, coord_t y1) {
- /* We don't need to validate here as the LLD routines will validate first.
- *
- * #if GDISP_NEED_VALIDATION
- * if (x0 >= GDISP.Width || y0 >= GDISP.Height || x0 < 0 || y0 < 0) return;
- * else if (x1 >= GDISP.Width || y1 >= GDISP.Height || y1 < 0 || y2 < 0) return;
- * #endif
- */
-
- //setting active window X
- write_index(0x30); //HSAW0
- write_data(x0);
- write_index(0x31); //HSAW1
- write_data(x0>>8);
-
- write_index(0x34); //HEAW0
- write_data(x1);
- write_index(0x35); //HEAW1
- write_data(x1>>8);
-
- //setting active window Y
- write_index(0x32); //VSAW0
- write_data(y0);
- write_index(0x33); //VSAW1
- write_data(y0>>8);
-
- write_index(0x36); //VEAW0
- write_data(y1);
- write_index(0x37); //VEAW1
- write_data(y1>>8);
-
- write_index(0x46);
- write_data(x0);
- write_index(0x47);
- write_data(x0>>8);
-
- write_index(0x48);
- write_data(y0);
- write_index(0x49);
- write_data(y0>>8);
-}
-
-/**
- * @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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- gdisp_lld_setwindow(x, y, x, y);
- write_index(RA8875_WRITE_MEMORY_START);
- write_data(color);
-}
-
-/* ---- Optional Routines ---- */
-
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- uint32_t area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
-
- gdisp_lld_setwindow(x, y, x+cx-1, y+cy-1);
- write_index(RA8875_WRITE_MEMORY_START);
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, &color);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area/65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area%65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- uint32_t index;
- for(index = 0; index < area; index++)
- write_data(color);
- #endif //#ifdef GDISP_USE_DMA
-}
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- gdisp_lld_setwindow(x, y, x+cx-1, y+cy-1);
- write_index(RA8875_WRITE_MEMORY_START);
-
- buffer += srcx + srcy * srccx;
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint32_t area = cx*cy;
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, buffer);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PINC | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area/65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area%65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- coord_t endx, endy;
- uint32_t lg;
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- #endif //#ifdef GDISP_USE_DMA
- }
-#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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
- /* NOT IMPLEMENTED YET */
-
- /*
- uint16_t size = x1 - x0 ;
-
- write_index(SSD1963_SET_SCROLL_AREA);
- write_data((x0 >> 8) & 0xFF);
- write_data((x0 >> 0) & 0xFF);
- write_data((size >> 8) & 0xFF);
- write_data((size >> 0) & 0xFF);
- write_data(((lcd_height-x1) >> 8) & 0xFF);
- write_data(((lcd_height-x1) >> 0) & 0xFF);
-
- write_index(SSD1963_SET_SCROLL_START);
- write_data((lines >> 8) & 0xFF);
- write_data((lines >> 0) & 0xFF);
- */
- }
-
-#endif
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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) {
- /* NOT IMPLEMENTED YET */
- switch(what) {
- case GDISP_CONTROL_POWER:
- if (GDISP.Powermode == (gdisp_powermode_t)value)
- return;
- switch((gdisp_powermode_t)value) {
- case powerOff:
- /* ToDo */
- break;
- case powerOn:
- /* ToDo */
- break;
- case powerSleep:
- /* ToDo */
- 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 GDISP_ROTATE_0:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
- case GDISP_CONTROL_BACKLIGHT:
- set_backlight((uint8_t )value);
- //gdisp_lld_bg_dimmer(54 + ((uint8_t)value) << 1);//turn 0..100% in 54..255
- return;
-/*
- case GDISP_CONTROL_CONTRAST:
-*/
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/gdisp/RA8875/gdisp_lld.mk b/drivers/gdisp/RA8875/gdisp_lld.mk
index 471b7e83..146cf255 100644
--- a/drivers/gdisp/RA8875/gdisp_lld.mk
+++ b/drivers/gdisp/RA8875/gdisp_lld.mk
@@ -1,6 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/RA8875/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/RA8875
-
+GFXSRC += $(GFXLIB)/drivers/gdisp/RA8875/gdisp_lld_RA8875.c
diff --git a/drivers/gdisp/RA8875/gdisp_lld_RA8875.c b/drivers/gdisp/RA8875/gdisp_lld_RA8875.c
new file mode 100644
index 00000000..d28670c6
--- /dev/null
+++ b/drivers/gdisp/RA8875/gdisp_lld_RA8875.c
@@ -0,0 +1,283 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/RA8875/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
+
+#define GDISP_DRIVER_VMT GDISPVMT_RA8875
+#include "../drivers/gdisp/RA8875/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+/* include the users board interface */
+#include "board_RA8875.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 272
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 480
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 74
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg8(g, reg, data) { write_index(g, reg); write_data(g, data); }
+#define write_reg16(g, reg, data) { write_index(g, reg); write_data(g, data); write_index(g, reg+1); write_data(g, (data)>>8); }
+#define write_reg8x2(g, reg, d1, d2) { write_index(g, reg); write_data(g, d1); write_data(g, d2); }
+
+static inline void set_cursor(GDisplay *g) {
+ write_reg16(g, 0x46, g->p.x);
+ write_reg16(g, 0x48, g->p.y);
+ write_index(g, 0x02);
+}
+
+static inline void set_viewport(GDisplay* g) {
+ write_reg16(g, 0x30, g->p.x); //HSAW0 & HSAW1
+ write_reg16(g, 0x34, g->p.x+g->p.cx-1); //HEAW0 & HEAW1
+ write_reg16(g, 0x32, g->p.y); //VSAW0 & VSAW1
+ write_reg16(g, 0x36, g->p.y+g->p.cy-1); //VEAW0 & VEAW1
+}
+
+// On this controller the back-light is controlled by the controllers internal PWM
+// which is why it is in this file rather than the board file.
+static inline void set_backlight(GDisplay* g, uint8_t percent) {
+ uint8_t temp;
+
+ //Work in progress: the RA8875 has a built-in PWM, its output can
+ //be used by a Dynamic Background Control or by a host (user)
+
+ // Enable PWM1
+ write_index(g, 0x8a); //MCLR
+ setreadmode(g);
+ temp = read_data(g);
+ setwritemode(g);
+ temp |= 1<<7 ;
+ write_data(g, temp);
+
+ // PWM1 function select
+ write_index(g, 0x8a); //MCLR
+ setreadmode(g);
+ temp = read_data(g);
+ setwritemode(g);
+ temp &= ~(1<<4);
+ write_data(g, temp);
+
+ // PWM1 Clock ratio
+ write_index(g, 0x8a); //MCLR
+ setreadmode(g);
+ temp = read_data(g);
+ setwritemode(g);
+ temp &= 0xf0;
+ temp |= 0x0b & 0x0f;
+ write_data(g, temp);
+
+ // PWM1 Write duty cycle
+ write_reg8(g, 0x8b, 54+percent); // PTNO: Also change percent to range from 0x00 to 0xFF
+}
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ // Soft reset
+ write_reg8x2(g, 0x01, 0x01, 0x00); gfxSleepMilliseconds(1);
+
+ // PLL config
+ write_reg8(g, 0x88, 0x08); gfxSleepMilliseconds(1);
+ write_reg8(g, 0x89, 0x02); gfxSleepMilliseconds(1);
+
+ write_reg8(g, 0x10, 0x0F); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
+ // 0x0F = 16bit MCU interface and 65k color display
+
+ write_reg8(g, 0x04, 0x82); gfxSleepMilliseconds(1); //set PCLK inverse
+
+ // Horizontal set
+ write_reg8(g, 0x14, GDISP_SCREEN_WIDTH/8-1); //HDWR: Horizontal Display Width Setting Bit[6:0] - pixels = (HDWR + 1)*8
+ write_reg8(g, 0x15, 0x00); //Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR) - HNDFT = [3:0]
+ write_reg8(g, 0x16, 0x01); //HNDR: Horizontal Non-Display Period Bit[4:0] - pixels = (HNDR + 1)*8
+ write_reg8(g, 0x17, 0x00); //HSTR: HSYNC Start Position[4:0] - Position(PCLK) = (HSTR + 1)*8
+ write_reg8(g, 0x18, 0x05); //HPWR: HSYNC Polarity, The period width of HSYNC. Width [4:0] width(PCLK) = (HPWR + 1)*8
+
+ // Vertical set
+ write_reg16(g, 0x19, GDISP_SCREEN_HEIGHT-1); //VDHR0,1: Vertical Display Height = VDHR + 1
+ write_reg16(g, 0x1b, 0x0002); //VNDR0,1: Vertical Non-Display Period Bit = (VSTR + 1)
+ write_reg16(g, 0x1d, 0x0007); //VSTR0,1: VSYNC Start Position = (VSTR + 1)
+ write_reg8(g, 0x1f, 0x09); //VPWR: VSYNC Polarity, VSYNC Pulse Width[6:0] - Width(PCLK) = (VPWR + 1)
+
+ // Active window set
+ write_reg16(g, 0x30, 0); //HSAW0 & HSAW1
+ write_reg16(g, 0x34, GDISP_SCREEN_WIDTH-1); //HEAW0 & HEAW1
+ write_reg16(g, 0x32, 0); //VSAW0 & VSAW1
+ write_reg16(g, 0x36, GDISP_SCREEN_HEIGHT-1); //VEAW0 & VEAW1
+
+ // Display ON
+ write_reg8(g, 0x01, 0x80); //PWRR
+
+ // GPO0 DISP high
+ write_reg8(g, 0x13, 0x01); //GPO
+
+ // Set initial back-light
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ // Change timings for faster access
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ set_cursor(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ #if 0
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+ #endif
+
+ #if 0
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+ #endif
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ acquire_bus(g);
+ set_backlight(g, (unsigned)g->p.ptr);
+ release_bus(g);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/RA8875/gdisp_lld_board_marlin.h b/drivers/gdisp/RA8875/gdisp_lld_board_marlin.h
deleted file mode 100644
index 072ba32e..00000000
--- a/drivers/gdisp/RA8875/gdisp_lld_board_marlin.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/RA8875/gdisp_lld_board_marlin.h
- * @brief GDISP Graphic Driver subsystem board interface for the RA8875 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/* Using FSMC A16 as RS */
-#define GDISP_RAM (*((volatile uint16_t *) 0x68000000)) /* RS = 0 */
-#define GDISP_REG (*((volatile uint16_t *) 0x68020000)) /* RS = 1 */
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- GDISP_REG = index;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-/**
- * @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 read_data(void) {
- return GDISP_RAM;
-}
-
-/**
- * @brief Initialise the board for the display.
- * @notes Performs the following functions:
- * 1. initialise the io 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 init_board(void) {
- const unsigned char FSMC_Bank = 4;
-
- #if defined(STM32F1XX) || defined(STM32F3XX)
- /* FSMC setup for F1/F3 */
- rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- #error "DMA not implemented for F1/F3 Devices"
- #endif
- #elif defined(STM32F4XX) || defined(STM32F2XX)
- /* STM32F2-F4 FSMC init */
- rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) chSysHalt();
- dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- #endif
- #else
- #error "FSMC not implemented for this device"
- #endif
-
- /* set pins to FSMC mode */
- IOBus busD = {GPIOD, (1 << 0) | (1 << 1) | (1 << 4) | (1 << 5) | (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};
-
- IOBus busG = {GPIOG, (1 << 10), 0};
-
- palSetBusMode(&busD, PAL_MODE_ALTERNATE(12));
- palSetBusMode(&busE, PAL_MODE_ALTERNATE(12));
- palSetBusMode(&busG, PAL_MODE_ALTERNATE(12));
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = (FSMC_BTR1_ADDSET_1 | FSMC_BTR1_ADDSET_3) \
- | (FSMC_BTR1_DATAST_1 | FSMC_BTR1_DATAST_3) \
- | (FSMC_BTR1_BUSTURN_1 | FSMC_BTR1_BUSTURN_3) ;
-
- /* Bank1 NOR/SRAM control register configuration
- * This is actually not needed as already set by default after reset */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-}
-
-static inline void post_init_board(void) {
- const unsigned char FSMC_Bank = 2;
- /* FSMC delay reduced as the controller now runs at full speed */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_0 | FSMC_BTR1_DATAST_2 | FSMC_BTR1_BUSTURN_0 ;
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- (void) state;
- /* Nothing to do here */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
- //duty_cycle is 00..FF
- //Work in progress: the RA8875 has a built-in PWM, its output can
- //be used by a Dynamic Background Control or by a host (user)
-
- uint8_t temp, temp1;
- // Enable PWM1
- write_index(0x8a);//MCLR
- temp = read_data();
- temp |= 1<<7 ;
- write_data(temp);
-
- // PWM1 function select
- write_index(0x8a);//MCLR
- temp = read_data();
- temp &= ~(1<<4);
- write_data(temp);
-
- // PWM1 Clock ratio
- temp1= 0x0b&0x0f;
- write_index(0x8a);//MCLR
- temp = read_data();
- temp &= 0xf0;
- temp |= temp1 ;
- write_data(temp);
-
- // Write duty cycle
- write_index(0x8b);//PTNO
- write_data(percent);
- // PWM1 duty cycle
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here */
-}
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/RA8875/gdisp_lld_board_template.h b/drivers/gdisp/RA8875/gdisp_lld_board_template.h
deleted file mode 100644
index a11c11ab..00000000
--- a/drivers/gdisp/RA8875/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1963 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-/**
- * @brief Initialise the board for the display.
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-static inline void post_init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-__inline void write_stream(uint16_t *buffer, uint16_t size) {
-
-}
-
-__inline void read_stream(uint16_t *buffer, size_t size) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/RA8875/gdisp_lld_config.h b/drivers/gdisp/RA8875/gdisp_lld_config.h
index f49c3e03..55a07839 100644
--- a/drivers/gdisp/RA8875/gdisp_lld_config.h
+++ b/drivers/gdisp/RA8875/gdisp_lld_config.h
@@ -22,17 +22,12 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "RA8875"
-
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILL TRUE
-#define GDISP_HARDWARE_READPIXEL TRUE
-
-/* Maybe someday soon */
-#define GDISP_HARDWARE_SCROLL FALSE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/RA8875/ra8875.h b/drivers/gdisp/RA8875/ra8875.h
deleted file mode 100644
index 43210b66..00000000
--- a/drivers/gdisp/RA8875/ra8875.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#ifndef RA8875_H
-#define RA8875_H
-
-#define mHIGH(x) (x >> 8)
-#define mLOW(x) (x & 0xFF)
-
-#define RA8875_WRITE_MEMORY_START 0x0002
-#define RA8875_READ_MEMORY_START 0x0002
-
-#endif
-
diff --git a/drivers/gdisp/S6D1121/board_S6D1121_template.h b/drivers/gdisp/S6D1121/board_S6D1121_template.h
new file mode 100644
index 00000000..04742f56
--- /dev/null
+++ b/drivers/gdisp/S6D1121/board_S6D1121_template.h
@@ -0,0 +1,154 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/S6D1121/board_S6D1121_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the S6D1121 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/S6D1121/gdisp_lld.c b/drivers/gdisp/S6D1121/gdisp_lld.c
deleted file mode 100644
index e570c1e8..00000000
--- a/drivers/gdisp/S6D1121/gdisp_lld.c
+++ /dev/null
@@ -1,561 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/S6D1121/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the S6d1121 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#if defined(GDISP_SCREEN_HEIGHT)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GISP_SCREEN_HEIGHT
-#endif
-#if defined(GDISP_SCREEN_WIDTH)
- #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
- #undef GDISP_SCREEN_WIDTH
-#endif
-
-#define GDISP_SCREEN_HEIGHT 320
-#define GDISP_SCREEN_WIDTH 240
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-/* Some common routines and macros */
-#define write_reg(reg, data) { write_index(reg); write_data(data); }
-#define stream_start() write_index(0x0022);
-#define stream_stop()
-#define delay(us) gfxSleepMicroseconds(us)
-#define delayms(ms) gfxSleepMilliseconds(ms)
-
-static inline void set_cursor(coord_t x, coord_t y) {
- /* R20h - 8 bit
- * R21h - 9 bit
- */
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- write_reg(0x0020, x & 0x00FF);
- write_reg(0x0021, y & 0x01FF);
- break;
- case GDISP_ROTATE_90:
- /* Note X has already been mirrored, so we do it directly */
- write_reg(0x0020, y & 0x00FF);
- write_reg(0x0021, x & 0x01FF);
- break;
- case GDISP_ROTATE_180:
- write_reg(0x0020, (GDISP_SCREEN_WIDTH - 1 - x) & 0x00FF);
- write_reg(0x0021, (GDISP_SCREEN_HEIGHT - 1 - y) & 0x01FF);
- break;
- case GDISP_ROTATE_270:
- write_reg(0x0020, (GDISP_SCREEN_WIDTH - 1 - y) & 0x00FF);
- write_reg(0x0021, (GDISP_SCREEN_HEIGHT - 1 - x) & 0x01FF);
- break;
- }
-}
-
-static inline void set_viewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- /* HSA / HEA are 8 bit
- * VSA / VEA are 9 bit
- * use masks 0x00FF and 0x01FF to enforce this
- */
-
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- write_reg(0x46, (((x + cx - 1) << 8) & 0xFF00 ) |
- (x & 0x00FF));
-
- write_reg(0x48, y & 0x01FF);
- write_reg(0x47, (y + cy - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_90:
- write_reg(0x46, (((y + cy - 1) << 8) & 0xFF00) |
- (y & 0x00FF));
-
- write_reg(0x48, x & 0x01FF);
- write_reg(0x47, (x + cx - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_180:
- write_reg(0x46, (((GDISP_SCREEN_WIDTH - x - 1) & 0x00FF) << 8) |
- ((GDISP_SCREEN_WIDTH - (x + cx)) & 0x00FF));
- write_reg(0x48, (GDISP_SCREEN_HEIGHT - (y + cy)) & 0x01FF);
- write_reg(0x47, (GDISP_SCREEN_HEIGHT- y - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_270:
- write_reg(0x46, (((GDISP_SCREEN_WIDTH - y - 1) & 0x00FF) << 8) |
- ((GDISP_SCREEN_WIDTH - (y + cy)) & 0x00FF));
- write_reg(0x48, (GDISP_SCREEN_HEIGHT - (x + cx)) & 0x01FF);
- write_reg(0x47, (GDISP_SCREEN_HEIGHT - x - 1) & 0x01FF);
- break;
- }
-
- set_cursor(x, y);
-}
-
-static inline void reset_viewport(void) {
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- case GDISP_ROTATE_180:
- set_viewport(0, 0, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
- break;
- case GDISP_ROTATE_90:
- case GDISP_ROTATE_270:
- set_viewport(0, 0, GDISP_SCREEN_HEIGHT, GDISP_SCREEN_WIDTH);
- break;
- }
-}
-
-bool_t gdisp_lld_init(void) {
- /* initialize the hardware */
- init_board();
-
- /* Hardware reset */
- setpin_reset(TRUE);
- delayms(20);
- setpin_reset(TRUE);
- delayms(20);
-
- /* Get the bus for the following initialisation commands */
- acquire_bus();
-
- write_reg(0x11,0x2004);
- write_reg(0x13,0xCC00);
- write_reg(0x15,0x2600);
- write_reg(0x14,0x252A);
- write_reg(0x12,0x0033);
- write_reg(0x13,0xCC04);
-
- delayms(1);
-
- write_reg(0x13,0xCC06);
-
- delayms(1);
-
- write_reg(0x13,0xCC4F);
-
- delayms(1);
-
- write_reg(0x13,0x674F);
- write_reg(0x11,0x2003);
-
- delayms(1);
-
- // Gamma Setting
- write_reg(0x30,0x2609);
- write_reg(0x31,0x242C);
- write_reg(0x32,0x1F23);
- write_reg(0x33,0x2425);
- write_reg(0x34,0x2226);
- write_reg(0x35,0x2523);
- write_reg(0x36,0x1C1A);
- write_reg(0x37,0x131D);
- write_reg(0x38,0x0B11);
- write_reg(0x39,0x1210);
- write_reg(0x3A,0x1315);
- write_reg(0x3B,0x3619);
- write_reg(0x3C,0x0D00);
- write_reg(0x3D,0x000D);
-
- write_reg(0x16,0x0007);
- write_reg(0x02,0x0013);
- write_reg(0x03,0x0003);
- write_reg(0x01,0x0127);
-
- delayms(1);
-
- write_reg(0x08,0x0303);
- write_reg(0x0A,0x000B);
- write_reg(0x0B,0x0003);
- write_reg(0x0C,0x0000);
- write_reg(0x41,0x0000);
- write_reg(0x50,0x0000);
- write_reg(0x60,0x0005);
- write_reg(0x70,0x000B);
- write_reg(0x71,0x0000);
- write_reg(0x78,0x0000);
- write_reg(0x7A,0x0000);
- write_reg(0x79,0x0007);
- write_reg(0x07,0x0051);
-
- delayms(1);
-
- write_reg(0x07,0x0053);
- write_reg(0x79,0x0000);
-
- reset_viewport();
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Now initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- acquire_bus();
- set_cursor(x, y);
- write_reg(0x0022, color);
- release_bus();
-}
-
-/* ---- Optional Routines ---- */
-
-#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;
-
- acquire_bus();
- set_cursor(0, 0);
- stream_start();
-
- for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
- write_data(color);
-
- stream_stop();
- release_bus();
- }
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned i, area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
- for(i = 0; i < area; i++)
- write_data(color);
- stream_stop();
- reset_viewport();
- release_bus();
- }
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- coord_t endx, endy;
- unsigned lg;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
-
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- buffer += srcx + srcy * srccx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- stream_stop();
- reset_viewport();
- release_bus();
- }
-#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_get_pixel_color(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 || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
- #endif
-
- aquire_bus();
- set_cursor(x, y);
- stream_start();
-
- color = lld_lcdReadData();
- color = lld_lcdReadData();
-
- stream_stop();
- release_bus();
-
- 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_vertical_scroll(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[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, gap, abslines;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- abslines = lines < 0 ? -lines : lines;
-
- acquire_bus();
- 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*/
- set_viewport(x, row0, cx, 1);
- lld_lcdReadStreamStart();
- lld_lcdReadStream(buf, cx);
- lld_lcdReadStreamStop();
-
- set_viewport(x, row1, cx, 1);
- stream_start();
- write_data(buf, cx);
- stream_stop();
- }
- }
-
- /* fill the remaining gap */
- set_viewport(x, lines > 0 ? (y+gap) : y, cx, abslines);
- stream_start();
- gap = cx*abslines;
- for(i = 0; i < gap; i++) write_data(bgcolor);
- stream_stop();
- reset_viewport();
- release_bus();
- }
-#endif
-
-#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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 GDISP_ROTATE_0:
- acquire_bus();
- write_reg(0x0001,0x0127);
- write_reg(0x03, 0b0011);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- acquire_bus();
- write_reg(0x0001,0x0027);
- write_reg(0x0003, 0b1011);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- acquire_bus();
- write_reg(0x0001,0x0127);
- write_reg(0x0003, 0b0000);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- acquire_bus();
- write_reg(0x0001,0x0027);
- write_reg(0x0003, 0b1000);
- release_bus();
-
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-/*
- case GDISP_CONTROL_BACKLIGHT:
- case GDISP_CONTROL_CONTRAST:
-*/
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/gdisp/S6D1121/gdisp_lld.mk b/drivers/gdisp/S6D1121/gdisp_lld.mk
index 07f9c380..583feb41 100644
--- a/drivers/gdisp/S6D1121/gdisp_lld.mk
+++ b/drivers/gdisp/S6D1121/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/S6D1121/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/S6D1121
+GFXSRC += $(GFXLIB)/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c
diff --git a/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c b/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c
new file mode 100644
index 00000000..cca9d67e
--- /dev/null
+++ b/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c
@@ -0,0 +1,338 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/S6D1121/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the S6d1121 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#if defined(GDISP_SCREEN_HEIGHT)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GISP_SCREEN_HEIGHT
+#endif
+#if defined(GDISP_SCREEN_WIDTH)
+ #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
+ #undef GDISP_SCREEN_WIDTH
+#endif
+
+#define GDISP_DRIVER_VMT GDISPVMT_S6D1121
+#include "../drivers/gdisp/S6D1121/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_S6D1121.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/* Some common routines and macros */
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
+
+static inline void set_cursor(GDisplay *g) {
+ /* R20h - 8 bit
+ * R21h - 9 bit
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, 0x20, g->p.x & 0x00FF);
+ write_reg(g, 0x21, g->p.y & 0x01FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, 0x20, g->p.y & 0x00FF);
+ write_reg(g, 0x21, (GDISP_SCREEN_HEIGHT - 1 - g->p.x) & 0x01FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x20, (GDISP_SCREEN_WIDTH - 1 - g->p.x) & 0x00FF);
+ write_reg(g, 0x21, (GDISP_SCREEN_HEIGHT - 1 - g->p.y) & 0x01FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x20, (GDISP_SCREEN_WIDTH - 1 - g->p.y) & 0x00FF);
+ write_reg(g, 0x21, g->p.x & 0x01FF);
+ break;
+ }
+ write_index(g, 0x22);
+}
+
+static inline void set_viewport(GDisplay *g) {
+ /* HSA / HEA are 8 bit
+ * VSA / VEA are 9 bit
+ * use masks 0x00FF and 0x01FF to enforce this
+ */
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, 0x46, (((g->p.x + g->p.cx - 1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF));
+ write_reg(g, 0x48, g->p.y & 0x01FF);
+ write_reg(g, 0x47, (g->p.y + g->p.cy - 1) & 0x01FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, 0x46, (((g->p.y + g->p.cy - 1) << 8) & 0xFF00) | (g->p.y & 0x00FF));
+ write_reg(g, 0x48, (GDISP_SCREEN_HEIGHT - (g->p.x + g->p.cx)) & 0x01FF);
+ write_reg(g, 0x47, (GDISP_SCREEN_HEIGHT-1 - g->p.x) & 0x01FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x46, (((GDISP_SCREEN_WIDTH-1 - g->p.x) & 0x00FF) << 8) |
+ ((GDISP_SCREEN_WIDTH - (g->p.x + g->p.cx)) & 0x00FF));
+ write_reg(g, 0x48, (GDISP_SCREEN_HEIGHT - (g->p.y + g->p.cy)) & 0x01FF);
+ write_reg(g, 0x47, (GDISP_SCREEN_HEIGHT-1 - g->p.y) & 0x01FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x46, (((GDISP_SCREEN_WIDTH-1 - g->p.y) & 0x00FF) << 8) |
+ ((GDISP_SCREEN_WIDTH - (g->p.y + g->p.cy)) & 0x00FF));
+ write_reg(g, 0x48, g->p.x & 0x01FF);
+ write_reg(g, 0x47, (g->p.x + g->p.cx - 1) & 0x01FF);
+ break;
+ }
+}
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ /* Hardware reset */
+ setpin_reset(g, TRUE);
+ delayms(20);
+ setpin_reset(g, TRUE);
+ delayms(20);
+
+ /* Get the bus for the following initialisation commands */
+ acquire_bus(g);
+
+ write_reg(g, 0x11, 0x2004);
+ write_reg(g, 0x13, 0xCC00);
+ write_reg(g, 0x15, 0x2600);
+ write_reg(g, 0x14, 0x252A);
+ write_reg(g, 0x12, 0x0033);
+ write_reg(g, 0x13, 0xCC04);
+
+ delayms(1);
+
+ write_reg(g, 0x13, 0xCC06);
+
+ delayms(1);
+
+ write_reg(g, 0x13, 0xCC4F);
+
+ delayms(1);
+
+ write_reg(g, 0x13, 0x674F);
+ write_reg(g, 0x11, 0x2003);
+
+ delayms(1);
+
+ // Gamma Setting
+ write_reg(g, 0x30, 0x2609);
+ write_reg(g, 0x31, 0x242C);
+ write_reg(g, 0x32, 0x1F23);
+ write_reg(g, 0x33, 0x2425);
+ write_reg(g, 0x34, 0x2226);
+ write_reg(g, 0x35, 0x2523);
+ write_reg(g, 0x36, 0x1C1A);
+ write_reg(g, 0x37, 0x131D);
+ write_reg(g, 0x38, 0x0B11);
+ write_reg(g, 0x39, 0x1210);
+ write_reg(g, 0x3A, 0x1315);
+ write_reg(g, 0x3B, 0x3619);
+ write_reg(g, 0x3C, 0x0D00);
+ write_reg(g, 0x3D, 0x000D);
+
+ write_reg(g, 0x16, 0x0007);
+ write_reg(g, 0x02, 0x0013);
+ write_reg(g, 0x03, 0x0003);
+ write_reg(g, 0x01, 0x0127);
+
+ delayms(1);
+
+ write_reg(g, 0x08, 0x0303);
+ write_reg(g, 0x0A, 0x000B);
+ write_reg(g, 0x0B, 0x0003);
+ write_reg(g, 0x0C, 0x0000);
+ write_reg(g, 0x41, 0x0000);
+ write_reg(g, 0x50, 0x0000);
+ write_reg(g, 0x60, 0x0005);
+ write_reg(g, 0x70, 0x000B);
+ write_reg(g, 0x71, 0x0000);
+ write_reg(g, 0x78, 0x0000);
+ write_reg(g, 0x7A, 0x0000);
+ write_reg(g, 0x79, 0x0007);
+ write_reg(g, 0x07, 0x0051);
+
+ delayms(1);
+
+ write_reg(g, 0x07,0x0053);
+ write_reg(g, 0x79,0x0000);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ set_cursor(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ #if 0
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ // TODO
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+ #endif
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ write_reg(g, 0x03, 0b0011);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ write_reg(g, 0x03, 0b1001);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ write_reg(g, 0x03, 0b0000);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ write_reg(g, 0x03, 0b1010);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
+/** @} */
+
diff --git a/drivers/gdisp/S6D1121/gdisp_lld_board_olimex_e407.h b/drivers/gdisp/S6D1121/gdisp_lld_board_olimex_e407.h
deleted file mode 100644
index 0ce843b4..00000000
--- a/drivers/gdisp/S6D1121/gdisp_lld_board_olimex_e407.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/S6D1121/gdisp_lld_board_olimex_e407.h
- * @brief GDISP Graphic Driver subsystem board interface for the S6D1121 display
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
-#define GDISP_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */
-
-static inline void init_board(void) {
- int FSMC_Bank = 0;
-
- /* 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));
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = (6) | (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;
-}
-
-static inline void setpin_reset(bool_t state) {
- (void)state;
-
- /* Nothing to do here */
-}
-
-static inline void set_backlight(uint8_t percent) {
- (void)percent;
-
- /* Nothing to do here */
-}
-
-static inline void acquire_bus(void) {
- /* Nothing to do here */
-}
-
-static inline void release_bus(void) {
- /* Nothing to do here */
-}
-
-static inline void write_index(uint16_t index) {
- GDISP_REG = index;
-}
-
-static inline void write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-#if GDISP_HARDWARE_READPIXEL || GDISP_HARDWARE_SCROLL || defined(__DOXYGEN__)
-static inline uint16_t read_data(void) {
- return GDISP_RAM;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/S6D1121/gdisp_lld_board_template.h b/drivers/gdisp/S6D1121/gdisp_lld_board_template.h
deleted file mode 100644
index f123bd06..00000000
--- a/drivers/gdisp/S6D1121/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/S6D1121/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the S6D1121 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialise the board for the display.
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/S6D1121/gdisp_lld_config.h b/drivers/gdisp/S6D1121/gdisp_lld_config.h
index bace096c..79e859bc 100644
--- a/drivers/gdisp/S6D1121/gdisp_lld_config.h
+++ b/drivers/gdisp/S6D1121/gdisp_lld_config.h
@@ -22,16 +22,12 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "S6D1121"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD FALSE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1289/board_SSD1289_template.h b/drivers/gdisp/SSD1289/board_SSD1289_template.h
new file mode 100644
index 00000000..7c9cd757
--- /dev/null
+++ b/drivers/gdisp/SSD1289/board_SSD1289_template.h
@@ -0,0 +1,191 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1289/board_SSD1289_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the SSD1289 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+/**
+ * The below section you can replace with #error if your interface doesn't support DMA
+ */
+#if defined(GDISP_USE_DMA) || defined(__DOXYGEN__)
+ //#error "GDISP - SSD1289: This interface does not support DMA"
+
+ /**
+ * @brief Transfer data using DMA but don't increment the source address
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] buffer The source buffer location
+ * @param[in] area The number of pixels to transfer
+ *
+ * @notapi
+ */
+ static inline void dma_with_noinc(GDisplay *g, color_t *buffer, int area) {
+ (void) g;
+ (void) buffer;
+ (void) area;
+ }
+
+ /**
+ * @brief Transfer data using DMA incrementing the source address
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] buffer The source buffer location
+ * @param[in] area The number of pixels to transfer
+ *
+ * @notapi
+ */
+ static inline void dma_with_inc(GDisplay *g, color_t *buffer, int area) {
+ (void) g;
+ (void) buffer;
+ (void) area;
+ }
+#endif
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld.mk b/drivers/gdisp/SSD1289/gdisp_lld.mk
index e340a7dc..fd2713bc 100644
--- a/drivers/gdisp/SSD1289/gdisp_lld.mk
+++ b/drivers/gdisp/SSD1289/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1289/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/SSD1289
+GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c b/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c
new file mode 100644
index 00000000..a33b6564
--- /dev/null
+++ b/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c
@@ -0,0 +1,361 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1289/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1289 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_SSD1289
+#include "../drivers/gdisp/SSD1289/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_SSD1289.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 320
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 240
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+
+static void set_cursor(GDisplay *g) {
+ /*
+ * Reg 0x004E is an 8 bit value - start x position
+ * Reg 0x004F is 9 bit - start y position
+ * Use a bit mask to make sure they are not set too high
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, 0x4e, g->p.x & 0x00FF);
+ write_reg(g, 0x4f, g->p.y & 0x01FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, 0x4e, g->p.y & 0x00FF);
+ write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF);
+ write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF);
+ write_reg(g, 0x4f, g->p.x & 0x01FF);
+ break;
+ }
+ write_index(g, 0x22);
+}
+
+static void set_viewport(GDisplay* g) {
+ /* 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
+ * Use a bit mask to make sure they are not set too high
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, 0x44, (((g->p.x+g->p.cx-1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF));
+ write_reg(g, 0x45, g->p.y & 0x01FF);
+ write_reg(g, 0x46, (g->p.y+g->p.cy-1) & 0x01FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, 0x44, (((g->p.y+g->p.cy-1) << 8) & 0xFF00 ) | (g->p.y & 0x00FF));
+ write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.x+g->p.cx)) & 0x01FF);
+ write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH - (g->p.x+g->p.cx)) & 0x00FF));
+ write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.y+g->p.cy)) & 0x01FF);
+ write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH-(g->p.y+g->p.cy)) & 0x00FF));
+ write_reg(g, 0x45, g->p.x & 0x01FF);
+ write_reg(g, 0x46, (g->p.x+g->p.cx-1) & 0x01FF);
+ break;
+ }
+}
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // No private area for this controller
+ g->priv = 0;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ write_reg(g, 0x00, 0x0001); gfxSleepMicroseconds(5);
+ write_reg(g, 0x03, 0xA8A4); gfxSleepMicroseconds(5);
+ write_reg(g, 0x0C, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x0D, 0x080C); gfxSleepMicroseconds(5);
+ write_reg(g, 0x0E, 0x2B00); gfxSleepMicroseconds(5);
+ write_reg(g, 0x1E, 0x00B0); gfxSleepMicroseconds(5);
+ write_reg(g, 0x01, 0x2B3F); gfxSleepMicroseconds(5);
+ write_reg(g, 0x02, 0x0600); gfxSleepMicroseconds(5);
+ write_reg(g, 0x10, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x11, 0x6070); gfxSleepMicroseconds(5);
+ write_reg(g, 0x05, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x06, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x16, 0xEF1C); gfxSleepMicroseconds(5);
+ write_reg(g, 0x17, 0x0003); gfxSleepMicroseconds(5);
+ write_reg(g, 0x07, 0x0133); gfxSleepMicroseconds(5);
+ write_reg(g, 0x0B, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x0F, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x41, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x42, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x48, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x49, 0x013F); gfxSleepMicroseconds(5);
+ write_reg(g, 0x4A, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x4B, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x44, 0xEF00); gfxSleepMicroseconds(5);
+ write_reg(g, 0x45, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x46, 0x013F); gfxSleepMicroseconds(5);
+ write_reg(g, 0x30, 0x0707); gfxSleepMicroseconds(5);
+ write_reg(g, 0x31, 0x0204); gfxSleepMicroseconds(5);
+ write_reg(g, 0x32, 0x0204); gfxSleepMicroseconds(5);
+ write_reg(g, 0x33, 0x0502); gfxSleepMicroseconds(5);
+ write_reg(g, 0x34, 0x0507); gfxSleepMicroseconds(5);
+ write_reg(g, 0x35, 0x0204); gfxSleepMicroseconds(5);
+ write_reg(g, 0x36, 0x0204); gfxSleepMicroseconds(5);
+ write_reg(g, 0x37, 0x0502); gfxSleepMicroseconds(5);
+ write_reg(g, 0x3A, 0x0302); gfxSleepMicroseconds(5);
+ write_reg(g, 0x3B, 0x0302); gfxSleepMicroseconds(5);
+ write_reg(g, 0x23, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x24, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x25, 0x8000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x4f, 0x0000); gfxSleepMicroseconds(5);
+ write_reg(g, 0x4e, 0x0000); gfxSleepMicroseconds(5);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ #if !GDISP_HARDWARE_STREAM_POS
+ set_cursor(g);
+ #endif
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+ #if GDISP_HARDWARE_STREAM_POS
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ set_cursor(g);
+ }
+ #endif
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA)
+ LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
+ uint16_t c;
+
+ c = COLOR2NATIVE(g->p.color);
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ dma_with_noinc(g, &c, g->p.cx*g->p.cy)
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA)
+ #if GDISP_PIXELFORMAT != GDISP_LLD_PIXELFORMAT
+ #error "GDISP: SSD1289: BitBlit is only available in RGB565 pixel format"
+ #endif
+
+ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
+ pixel_t *buffer;
+ coord_t ycnt;
+
+ buffer = (pixel_t *)g->p.ptr + g->p.x1 + g->p.y1 * g->p.x2;
+
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ if (g->p.x2 == g->p.cx) {
+ dma_with_inc(g, buffer, g->p.cx*g->p.cy);
+ } else {
+ for (ycnt = g->p.cy; ycnt; ycnt--, buffer += g->p.x2)
+ dma_with_inc(g, buffer, g->p.cy);
+ }
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_reg(g, 0x10, 0x0000); // leave sleep mode
+ write_reg(g, 0x07, 0x0000); // halt operation
+ write_reg(g, 0x00, 0x0000); // turn off oscillator
+ write_reg(g, 0x10, 0x0001); // enter sleep mode
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_reg(g, 0x10, 0x0000); // leave sleep mode
+ write_reg(g, 0x00, 0x0001); // turn on oscillator
+ gfxSleepMicroseconds(5);
+ release_bus(g);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ write_reg(g, 0x10, 0x0001); // enter sleep mode
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ /* ID = 11 AM = 0 */
+ write_reg(g, 0x11, 0x6070);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ /* ID = 01 AM = 1 */
+ write_reg(g, 0x11, 0x6058);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ /* ID = 00 AM = 0 */
+ write_reg(g, 0x11, 0x6040);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ /* ID = 10 AM = 1 */
+ write_reg(g, 0x11, 0x6068);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_board_firebullstm32f103.h b/drivers/gdisp/SSD1289/gdisp_lld_board_firebullstm32f103.h
deleted file mode 100644
index 38d9e04d..00000000
--- a/drivers/gdisp/SSD1289/gdisp_lld_board_firebullstm32f103.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1289/gdisp_lld_board_firebullstm32f103.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1289 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define SET_CS palSetPad(GPIOD, 12);
-#define CLR_CS palClearPad(GPIOD, 12);
-#define SET_RS palSetPad(GPIOD, 13);
-#define CLR_RS palClearPad(GPIOD, 13);
-#define SET_WR palSetPad(GPIOD, 14);
-#define CLR_WR palClearPad(GPIOD, 14);
-#define SET_RD palSetPad(GPIOD, 15);
-#define CLR_RD palClearPad(GPIOD, 15);
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 12, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 14, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 15, PAL_MODE_OUTPUT_PUSHPULL);
-
- // Configure the pins to a well know state
- SET_RS;
- SET_RD;
- SET_WR;
- CLR_CS;
-}
-
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- (void) state;
- /* Nothing to do here - reset pin tied to Vcc */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- (void) percent;
- /* Nothing to do here - Backlight always on */
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- palWritePort(GPIOE, index);
- CLR_RS; CLR_WR; SET_WR; SET_RS;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- palWritePort(GPIOE, data);
- CLR_WR; SET_WR;
-}
-
-#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 read_data(void) {
- uint16_t value;
-
- // change pin mode to digital input
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_INPUT);
-
- CLR_RD;
- value = palReadPort(GPIOE);
- value = palReadPort(GPIOE);
- SET_RD;
-
- // change pin mode back to digital output
- palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
-
- return value;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_board_st_stm32f4_discovery.h b/drivers/gdisp/SSD1289/gdisp_lld_board_st_stm32f4_discovery.h
deleted file mode 100644
index 9d46d64b..00000000
--- a/drivers/gdisp/SSD1289/gdisp_lld_board_st_stm32f4_discovery.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1289/gdisp_lld_board_st_stm32f4_discovery.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1289 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define GDISP_REG ((volatile uint16_t *) 0x60000000)[0] /* RS = 0 */
-#define GDISP_RAM ((volatile uint16_t *) 0x60020000)[0] /* RS = 1 */
-
-#define GDISP_USE_FSMC
-#define GDISP_USE_DMA
-#define GDISP_DMA_STREAM STM32_DMA2_STREAM6
-
-const unsigned char FSMC_Bank = 0;
-
-/* PWM configuration structure. We use timer 3 channel 3 */
-static const PWMConfig pwmcfg = {
- 100000, /* 100 kHz PWM clock frequency. */
- 100, /* PWM period is 100 cycles. */
- NULL,
- {
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_DISABLED, NULL}
- },
- 0
-};
-
-/**
- * @brief Initialise the board for the display.
- * @notes Performs the following functions:
- * 1. initialise the io 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 init_board(void) {
-
- #if defined(STM32F1XX) || defined(STM32F3XX)
- /* FSMC setup for F1/F3 */
- rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- #error "DMA not implemented for F1/F3 Devices"
- #endif
- #elif defined(STM32F4XX) || defined(STM32F2XX)
- /* STM32F2-F4 FSMC init */
- rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) gfxExit();
- dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- #endif
- #else
- #error "FSMC not implemented for this device"
- #endif
-
- /* 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));
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_0 | FSMC_BTR1_DATAST_2 | FSMC_BTR1_BUSTURN_0 ;
-
- /* Bank1 NOR/SRAM control register configuration
- * This is actually not needed as already set by default after reset */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-
- /* Display backlight control */
- /* TIM3 is an alternate function 2 (AF2) */
- pwmStart(&PWMD3, &pwmcfg);
- palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
- pwmEnableChannel(&PWMD3, 2, 100);
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- (void) state;
- /* Nothing to do here */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- pwmEnableChannel(&PWMD3, 2, percent);
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) { GDISP_REG = index; }
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) { GDISP_RAM = data; }
-
-#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 read_data(void) { return GDISP_RAM; }
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_board_template.h b/drivers/gdisp/SSD1289/gdisp_lld_board_template.h
deleted file mode 100644
index e5d10355..00000000
--- a/drivers/gdisp/SSD1289/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1289/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1289 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialise the board for the display.
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_config.h b/drivers/gdisp/SSD1289/gdisp_lld_config.h
index 989cc3af..a9166553 100644
--- a/drivers/gdisp/SSD1289/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1289/gdisp_lld_config.h
@@ -22,16 +22,20 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "SSD1289"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_STREAM_POS TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
+
+#if defined(GDISP_USE_DMA)
+ #define GDISP_HARDWARE_FILLS TRUE
+ #if !defined(GDISP_PIXELFORMAT) || GDISP_PIXELFORMAT == 0x2565
+ // Hardware BitBlts are only supported in native pixel format on this controller
+ #define GDISP_HARDWARE_BITFILLS TRUE
+ #endif
+#endif
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1306/SSD1306.h b/drivers/gdisp/SSD1306/SSD1306.h
index 38507d48..47ca39e4 100644
--- a/drivers/gdisp/SSD1306/SSD1306.h
+++ b/drivers/gdisp/SSD1306/SSD1306.h
@@ -8,9 +8,6 @@
#ifndef _SSD1306_H
#define _SSD1306_H
-#define SSD1306_BLACK 0
-#define SSD1306_WHITE 1
-
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
diff --git a/drivers/gdisp/SSD1306/board_SSD1306_template.h b/drivers/gdisp/SSD1306/board_SSD1306_template.h
new file mode 100644
index 00000000..5b4bd05c
--- /dev/null
+++ b/drivers/gdisp/SSD1306/board_SSD1306_template.h
@@ -0,0 +1,116 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1306/board_SSD1306_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the SSD1306 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Optional: A byte to prefix on each display page line.
+ * @note If not defined then no byte is prefixed on each page line.
+ *
+ * @notapi
+ */
+//#define SSD1306_PAGE_PREFIX 0x40
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send a command to the controller.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] cmd The command to send *
+ *
+ * @notapi
+ */
+static inline void write_cmd(GDisplay *g, uint8_t cmd) {
+ (void) g;
+ (void) cmd;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
+ (void) g;
+ (void) data;
+ (void) length;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
+
diff --git a/drivers/gdisp/SSD1306/gdisp_lld.c b/drivers/gdisp/SSD1306/gdisp_lld.c
deleted file mode 100644
index 9c20d853..00000000
--- a/drivers/gdisp/SSD1306/gdisp_lld.c
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#include "gfx.h"
-
-#include "SSD1306.h"
-
-#if GFX_USE_GDISP
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 64
-#endif
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 128
-#endif
-
-#define GDISP_INITIAL_CONTRAST 0xFF
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-// Include wiring specific header
-#include "gdisp_lld_board_example_i2c.h"
-
-// Some common routines and macros
-#define delay(us) gfxSleepMicroseconds(us)
-#define delayms(ms) gfxSleepMilliseconds(ms)
-
-// The memory buffer for the display
-static uint8_t gdisp_buffer[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8];
-
-/** Set the display to normal or inverse.
- * @param[in] value 0 for normal mode, or 1 for inverse mode.
- * @notapi
- */
-static void invert_display(uint8_t i) {
- write_cmd(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
-}
-
-/** Turn the whole display off.
- * Sends the display to sleep, but leaves RAM intact.
- * @notapi
- */
-static void display_off(){
- write_cmd(SSD1306_DISPLAYOFF);
-}
-
-/** Turn the whole display on.
- * Wakes up this display following a sleep() call.
- * @notapi
- */
-static void display_on() {
- write_cmd(SSD1306_DISPLAYON);
-}
-
-/** Set the vertical shift by COM.
- * @param[in] value The number of rows to shift, from 0 - 63.
- * @notapi
-*/
-static void set_display_offset(unsigned char value) {
- write_cmd(SSD1306_SETDISPLAYOFFSET);
- write_cmd(value & 0x3F);
-}
-
-/** Set the display contrast.
- * @param[in] value The contrast, from 1 to 256.
- * @notapi
- */
-static void set_contrast(unsigned char value) {
- write_cmd(SSD1306_SETCONTRAST);
- write_cmd(value);
-}
-
-/** Set the display start line. This is the line at which the display will start rendering.
- * @param[in] value A value from 0 to 63 denoting the line to start at.
- * @notapi
- */
-static void set_display_start_line(unsigned char value) {
- write_cmd(SSD1306_SETSTARTLINE | value);
-}
-
-/** Set the segment remap state. This allows the module to be addressed as if flipped horizontally.
- * NOTE: Changing this setting has no effect on data already in the module's GDDRAM.
- * @param[in] value 0 = column address 0 = segment 0 (the default), 1 = column address 127 = segment 0 (flipped).
- * @notapi
- */
-static void set_segment_remap(unsigned char value) {
- write_cmd(value ? SSD1306_SEGREMAP+1 : SSD1306_SEGREMAP);
-}
-
-/** Set the multiplex ratio.
- * @param[in] value MUX will be set to (value+1). Valid values range from 15 to 63 - MUX 16 to 64.
- * @notapi
- */
-static void set_multiplex_ratio(unsigned char value) {
- write_cmd(SSD1306_SETMULTIPLEX);
- write_cmd(value & 0x3F);
-}
-
-/** Set COM output scan direction. If the display is active, this will immediately vertically
- * flip the display.
- * @param[in] value 0 = Scan from COM0 (default), 1 = reversed (scan from COM[N-1]).
- * @notapi
- */
-static void set_com_output_scan_direction(unsigned char value) {
- write_cmd(value ? SSD1306_COMSCANDEC : SSD1306_COMSCANINC);
-}
-
-static void set_com_pins_hardware_configuration(unsigned char sequential, unsigned char lr_remap) {
- write_cmd(SSD1306_SETCOMPINS);
- write_cmd(0x02 | ((sequential & 1) << 4) | ((lr_remap & 1) << 5));
-}
-
-/** Flip display content horizontally.
- * NOTE: This only flips display content, but doesn't turn the char writing around.
- * You have to unmirror everything manually.
- * @param[in] value 0 = column address 0 = segment 0 (the default), 1 = column address 127 = segment 0 (flipped).
- * @notapi
- */
-static void flip_display(unsigned char enable) {
- if( enable && GDISP.Orientation == GDISP_ROTATE_0) {
- set_com_output_scan_direction(0);
- set_segment_remap(0);
- GDISP.Orientation = GDISP_ROTATE_0;
- }
- if( !enable && GDISP.Orientation == GDISP_ROTATE_180) {
- set_com_output_scan_direction(1);
- set_segment_remap(1);
- GDISP.Orientation = GDISP_ROTATE_180;
- }
- else
- return;
-}
-
-/** Perform a "no operation".
- * @notapi
- */
-static void nop() {
- write_cmd(0xE3);
-}
-
-/** Page Addressing Mode: Set the column start address register for
- * page addressing mode.
- * @param[in] address The address (full byte).
- * @notapi
- */
-static void set_start_address_pam(unsigned char address)
-{
- // "Set Lower Column Start Address for Page Addressing Mode"
- write_cmd(address & 0x0F);
-
- // "Set Higher Column Start Address for Page Addressing Mode"
- write_cmd((address << 4) & 0x0F);
-}
-
-/** Set memory addressing mode to the given value.
- * @param[in] mode 0 for Horizontal addressing mode,\n 1 for Vertical addressing mode,\n or 2 for Page addressing mode (PAM). 2 is the default.
- * @notapi
- */
-static void set_memory_addressing_mode(unsigned char mode)
-{
- write_cmd(SSD1306_MEMORYMODE);
- write_cmd(mode & 0x3);
-}
-
-/** Set column address range for horizontal/vertical addressing mode.
- * @param[in] start Column start address, 0 - 127.
- * @param[in] end Column end address, 0 - 127.
- * @notapi
- */
-static void set_column_address_hvam(unsigned char start, unsigned char end)
-{
- write_cmd(SSD1306_HV_COLUMN_ADDRESS);
- write_cmd(start & 0x7F);
- write_cmd(end & 0x7F);
-}
-
-/** Set page start and end address for horizontal/vertical addressing mode.
- * @param[in] start The start page, 0 - 7.
- * @param[in] end The end page, 0 - 7.
- * @notapi
- */
-static void set_page_address_hvam(unsigned char start, unsigned char end)
-{
- write_cmd(SSD1306_HV_PAGE_ADDRESS);
- write_cmd(start & 0x07);
- write_cmd(end & 0x07);
-}
-
-/** Set the GDDRAM page start address for page addressing mode.
- * @param[in] address The start page, 0 - 7.
- * @notapi
- */
-static void set_page_start_pam(unsigned char address)
-{
- write_cmd(SSD1306_PAM_PAGE_START | (address & 0x07));
-}
-
-/** Set the display clock divide ratio and the oscillator frequency.
- * @param[in] ratio The divide ratio, default is 0.
- * @param[in] frequency The oscillator frequency, 0 - 127. Default is 8.
- * @notapi
- */
-static void set_display_clock_ratio_and_frequency(unsigned char ratio, unsigned char frequency)
-{
- write_cmd(SSD1306_SETDISPLAYCLOCKDIV);
- write_cmd((ratio & 0x0F) | ((frequency & 0x0F) << 4));
-}
-
-/** Set the precharge period.
- * @param[in] phase1 Phase 1 period in DCLK clocks. 1 - 15, default is 2.
- * @param[in] phase2 Phase 2 period in DCLK clocks. 1 - 15, default is 2.
- * @notapi
- */
-static void set_precharge_period(unsigned char phase1, unsigned char phase2)
-{
- write_cmd(SSD1306_SETPRECHARGE);
- write_cmd((phase1 & 0x0F) | ((phase2 & 0x0F ) << 4));
-}
-
-/** Set the Vcomh deselect level.
- * @param[in] level @p 0 = 0.65 x Vcc, @p 1 = 0.77 x Vcc (default), @p 2 = 0.83 x Vcc.
- * @notapi
- */
-static void set_vcomh_deselect_level(unsigned char level)
-{
- write_cmd(SSD1306_SETVCOMDETECT);
- write_cmd((level & 0x03) << 4);
-}
-
-/** Enable/disable charge pump.
- * @param[in] enable 0 to disable, 1 to enable the internal charge pump.
- * @notapi
- */
-static void set_charge_pump(unsigned char enable)
-{
- write_cmd(SSD1306_ENABLE_CHARGE_PUMP);
- write_cmd(enable ? 0x14 : 0x10);
-}
-
-/*===========================================================================*/
-/* 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) {
- // Initialize your display
- init_board();
-
- // Hardware reset.
- setpin_reset(TRUE);
- delayms(1);
- setpin_reset(FALSE);
- delayms(10);
- setpin_reset(TRUE);
-
- // Get the bus for the following initialization commands.
- acquire_bus();
-
- display_off();
- set_display_clock_ratio_and_frequency(0, 8);
- #if GDISP_SCREEN_HEIGHT == 64
- set_multiplex_ratio(0x3F); // 1/64 duty
- #endif
- #if GDISP_SCREEN_HEIGHT == 32
- set_multiplex_ratio(0x1F); // 1/32 duty
- #endif
- set_precharge_period(0xF, 0x01); //
- set_display_offset(0); //
- set_display_start_line(0); //
- set_charge_pump(1); // Enable internal charge pump.
- set_memory_addressing_mode(0); // horizontal addressing mode; across then down //act like ks0108 (horizontal addressing mode)
- set_segment_remap(1); //
- set_com_output_scan_direction(1); //
- #if GDISP_SCREEN_HEIGHT == 64
- set_com_pins_hardware_configuration(1, 0);
- #endif
- #if GDISP_SCREEN_HEIGHT == 32
- set_com_pins_hardware_configuration(0, 1);
- #endif
- set_contrast(GDISP_INITIAL_CONTRAST); // Set initial contrast.
- set_vcomh_deselect_level(1); //
- display_on(); // Turn on OLED panel.
- invert_display(0); // Disable Inversion of display.
- set_column_address_hvam(0, 127); //
- set_page_address_hvam(0, 7); //
-
- release_bus();
-
- gdisp_lld_display();
-
- // Initialize the GDISP structure
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- if (color == SSD1306_WHITE)
- gdisp_buffer[x+ (y/8)*GDISP_SCREEN_WIDTH] |= (1<<y%8);
- else
- gdisp_buffer[x+ (y/8)*GDISP_SCREEN_WIDTH] &= ~(1<<y%8);
-}
-
-void gdisp_lld_display() {
- set_display_start_line(0);
-
- /* We're sending half a line in one X-mission.*/
- uint8_t command[GDISP_SCREEN_WIDTH/2],
- cmdLength = sizeof(command)/sizeof(command[0]),
- parts = GDISP_SCREEN_WIDTH/cmdLength;
-
- for(int i=0; i<GDISP_SCREEN_HEIGHT/8; i++){
- for(int j = 0; j<parts; j++){
- memmove(command, &gdisp_buffer[i*GDISP_SCREEN_WIDTH + j*cmdLength], cmdLength);
- write_data(command, cmdLength);
- }
- }
-}
-
-/* ---- 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_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 equivalent 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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- /* See datasheet table T10-1 for this*/
- uint8_t fHeight = (uint8_t)gdispGetFontMetric(gwinGetDefaultFont(), fontLineSpacing);
- set_multiplex_ratio(GDISP_SCREEN_HEIGHT - fHeight+1);
- set_display_offset(fHeight-2);
-
- /* Scrolling animation.*/
- for(int i=0; i<fHeight; i++){
- set_display_start_line(i);
- gfxSleepMilliseconds(10);
- }
-
- /* Shift buffer up a font line.*/
- for (int i = 0; i < GDISP_SCREEN_WIDTH*(GDISP_SCREEN_HEIGHT/8-1); i++) {
- gdisp_buffer[i] = gdisp_buffer[i+GDISP_SCREEN_WIDTH*(fHeight/8)] >> fHeight % 8;
- gdisp_buffer[i] |= gdisp_buffer[i+GDISP_SCREEN_WIDTH*(fHeight/8 + 1)] << (8 - fHeight%8);
- }
-
- /* Clear last page.*/
- memset( &gdisp_buffer[GDISP_SCREEN_HEIGHT*GDISP_SCREEN_WIDTH/8 - GDISP_SCREEN_WIDTH*2], SSD1306_BLACK, GDISP_SCREEN_WIDTH*2);
-
- /* Update display.*/
- gdisp_lld_display();
- }
-
- /**
- * @warning Implementation only fully supports left and right...some command issues here.
- * Activate a scroll for rows start through stop.
- * Hint, the display is 16 rows tall. To scroll the whole display, run:
- * @code
- * display.scrollright(0x00, 0x0F)
- * @endcode
- * @param[in] start The start of the area to be scrolled
- * @param[in] stop The size of the area to be scrolled
- * @param[in] dir direction of scrolling
- * [left, right, up, down, up_right, up_left, down_left, down_right]
- * @note Optional. *
- *
- * @notapi
- */
- void gdisp_lld_start_scroll(uint8_t dir, uint8_t start, uint8_t stop, uint8_t interval){
-// if(dir == GDISP_SCROLL_RIGHT || GDISP_SCROLL_LEFT || GDISP_SCROLL_UP) {
-// switch (dir) {
-// case GDISP_SCROLL_RIGHT:
-// write_cmd(SSD1306_SCROLL_HORIZONTAL_RIGHT);
-// break;
-// case GDISP_SCROLL_LEFT:
-// write_cmd(SSD1306_SCROLL_HORIZONTAL_LEFT);
-// break;
-// }
-// write_cmd(0X00); // Dummy byte.
-// write_cmd(start & 0x07); // Define start page address.
-// switch (interval) { // Set time interval between each scroll step (5 frames)
-// case 2: write_cmd(0x07); break; // 111b
-// case 3: write_cmd(0x04); break; // 100b
-// case 4: write_cmd(0x05); break; // 101b
-// case 5: write_cmd(0x00); break; // 000b
-// case 25: write_cmd(0x06); break; // 110b
-// case 64: write_cmd(0x01); break; // 001b
-// case 128: write_cmd(0x02); break; // 010b
-// case 256: write_cmd(0x03); break; // 011b
-// default:
-// // default to 2 frame interval
-// write_cmd(0x07); break;
-// }
-// write_cmd(stop & 0x07); // Define stop page address
-// write_cmd(0X01); // Set vertical scrolling offset as no row.
-// write_cmd(0XFF); // Undocumented but needed.
-// write_cmd(SSD1306_SCROLL_ACTIVATE);
-// }
-// else if(dir == GDISP_SCROLL_UP || GDISP_SCROLL_DOWN) {
-// switch (dir) {
-// case GDISP_SCROLL_UP:
-// gdisp_lld_set_vertical_scroll_area(0x00, GDISP_SCREEN_HEIGHT);
-// write_cmd(SSD1306_SCROLL_VERTICAL_AND_HORIZONTAL_RIGHT);
-// break;
-//
-// case GDISP_SCROLL_DOWN:
-// gdisp_lld_set_vertical_scroll_area(0x00, GDISP_SCREEN_HEIGHT);
-// write_cmd(SSD1306_SCROLL_VERTICAL_AND_HORIZONTAL_LEFT);
-// break;
-// }
-// write_cmd(0X00); // Dummy byte.
-// write_cmd(start); // Define start page address.
-// write_cmd(0X00); // Set time interval between each scroll step (5 frames)
-// write_cmd(stop); // Define stop page address
-// write_cmd(0X01); // Set vertical scrolling offset as no row.
-// write_cmd(SSD1306_SCROLL_ACTIVATE);
-// gdisp_lld_set_vertical_scroll_area(0x00, GDISP_SCREEN_HEIGHT-10);
-// write_cmd(SSD1306_SCROLL_VERTICAL_AND_HORIZONTAL_RIGHT);
-// write_cmd(0X00); // Dummy byte.
-// write_cmd(start); // Define start page address.
-// write_cmd(0X00); // Set time interval between each scroll step (5 frames)
-// write_cmd(stop); // Define stop page address
-// write_cmd(0X03); // Set vertical scrolling offset as no row.
-// write_cmd(SSD1306_SCROLL_ACTIVATE);
-// }
- }
-
- /**
- * Sets vertical scroll area of display.
- * @param[in] start The start of the area to be scrolled [y coordinate]
- * @param[in] stop The size of the area to be scrolled [y coordinate]
- * @note Optional. *
- *
- * @notapi
- */
- void gdisp_lld_set_vertical_scroll_area(uint8_t start, uint8_t stop){
- write_cmd(SSD1306_SCROLL_SET_VERTICAL_SCROLL_AREA);
- write_cmd(start);
- write_cmd(stop);
- }
-
- /** Deactivate the continuous scroll set up with start_horizontal_scroll() or
- * start_vertical_and_horizontal_scroll().
- * @see set_horizontal_scroll, set_vertical_and_horizontal_scroll
- * @notapi
- */
- void gdisp_lld_stop_scroll(void){
- write_cmd(SSD1306_SCROLL_DEACTIVATE);
- }
-#endif // GDISP_NEED_SCROLL
-
-#if GDISP_HARDWARE_FILLS || defined(__DOXYGEN__)
- void gdisp_lld_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- for(int i=x; i<x+cx; i++) {
- for(int j=y; j<y+cy; j++) {
- gdisp_lld_draw_pixel(i,j,color);
- }
- }
- }
-#endif // GDISP_HARDWARE_FILLS
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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:
- display_off();
- case powerSleep:
- display_off();
- case powerDeepSleep:
- display_off();
- case powerOn:
- display_on();
- 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 GDISP_ROTATE_0:
- flip_display(0);
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_180:
- flip_display(1);
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
- case GDISP_CONTROL_CONTRAST:
- if ((unsigned)value > 100)
- value = (void *)100;
- if (GDISP.Contrast == (uint8_t)((float)((uint8_t)value) * 256.0/100.0) )
- return;
- set_contrast((uint8_t)((float)((uint8_t)value) * 256.0/100.0) );
- GDISP.Contrast = (unsigned)value;
- return;
- }
- }
-#endif // GDISP_NEED_CONTROL
-
-/**
- * Let the display blink several times by means of invert and invert back.
- * @param num number of blink cycles to do
- * @param speed milliseconds to wait between toggling inversion
- * @param wait milliseconds to wait before start of all blink cycles and after finishing blink cycles
- * @notapi
- */
- void gdisp_lld_display_blink(uint8_t num, uint16_t speed, uint16_t wait){
- uint8_t inv = 0;
-
- gfxSleepMilliseconds(wait);
- for(int i=0; i<2*num; i++) {
- inv ^= 1;
- invert_display(inv);
- gfxSleepMilliseconds(speed);
- }
- gfxSleepMilliseconds(wait);
-}
-
-#endif // GFX_USE_GDISP
-/** @} */
-
diff --git a/drivers/gdisp/SSD1306/gdisp_lld.mk b/drivers/gdisp/SSD1306/gdisp_lld.mk
index 2a2e1364..13df4230 100644
--- a/drivers/gdisp/SSD1306/gdisp_lld.mk
+++ b/drivers/gdisp/SSD1306/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1306/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/SSD1306
+GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c b/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c
new file mode 100644
index 00000000..b72ba781
--- /dev/null
+++ b/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c
@@ -0,0 +1,280 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1306/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1306 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_SSD1306
+#include "../drivers/gdisp/SSD1306/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_SSD1306.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 64 // This controller should support 32 (untested) or 64
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 128
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 100
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+#ifdef SSD1306_PAGE_PREFIX
+ #define SSD1306_PAGE_WIDTH (GDISP_SCREEN_WIDTH+1)
+ #define SSD1306_PAGE_OFFSET 1
+#else
+ #define SSD1306_PAGE_WIDTH GDISP_SCREEN_WIDTH
+ #define SSD1306_PAGE_OFFSET 0
+#endif
+
+#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
+
+#include "SSD1306.h"
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define RAM(g) ((uint8_t *)g->priv)
+#define write_cmd2(g, cmd1, cmd2) { write_cmd(g, cmd1); write_cmd(g, cmd2); }
+#define write_cmd3(g, cmd1, cmd2, cmd3) { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); }
+
+// Some common routines and macros
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
+
+#define xyaddr(x, y) (SSD1306_PAGE_OFFSET + (x) + ((y)>>3)*SSD1306_PAGE_WIDTH)
+#define xybit(y) (1<<((y)&7))
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * As this controller can't update on a pixel boundary we need to maintain the
+ * the entire display surface in memory so that we can do the necessary bit
+ * operations. Fortunately it is a small display in monochrome.
+ * 64 * 128 / 8 = 1024 bytes.
+ */
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // The private area is the display surface.
+ g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH);
+
+ // Fill in the prefix command byte on each page line of the display buffer
+ // We can do it during initialisation as this byte is never overwritten.
+ #ifdef SSD1306_PAGE_PREFIX
+ {
+ unsigned i;
+
+ for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH)
+ RAM(g)[i] = SSD1306_PAGE_PREFIX;
+ }
+ #endif
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ acquire_bus(g);
+
+ write_cmd(g, SSD1306_DISPLAYOFF);
+ write_cmd2(g, SSD1306_SETDISPLAYCLOCKDIV, 0x80);
+ write_cmd2(g, SSD1306_SETMULTIPLEX, GDISP_SCREEN_HEIGHT-1);
+ write_cmd2(g, SSD1306_SETPRECHARGE, 0x1F);
+ write_cmd2(g, SSD1306_SETDISPLAYOFFSET, 0);
+ write_cmd(g, SSD1306_SETSTARTLINE | 0);
+ write_cmd2(g, SSD1306_ENABLE_CHARGE_PUMP, 0x14);
+ write_cmd2(g, SSD1306_MEMORYMODE, 0);
+ write_cmd(g, SSD1306_SEGREMAP+1);
+ write_cmd(g, SSD1306_COMSCANDEC);
+ #if GDISP_SCREEN_HEIGHT == 64
+ write_cmd2(g, SSD1306_SETCOMPINS, 0x12);
+ #else
+ write_cmd2(g, SSD1306_SETCOMPINS, 0x22);
+ #endif
+ write_cmd2(g, SSD1306_SETCONTRAST, (uint8_t)(GDISP_INITIAL_CONTRAST*256/101)); // Set initial contrast.
+ write_cmd2(g, SSD1306_SETVCOMDETECT, 0x10);
+ write_cmd(g, SSD1306_DISPLAYON);
+ write_cmd(g, SSD1306_NORMALDISPLAY);
+ write_cmd3(g, SSD1306_HV_COLUMN_ADDRESS, 0, GDISP_SCREEN_WIDTH-1);
+ write_cmd3(g, SSD1306_HV_PAGE_ADDRESS, 0, GDISP_SCREEN_HEIGHT/8-1);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_FLUSH
+ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+ unsigned i;
+
+ // Don't flush if we don't need it.
+ if (!(g->flags & GDISP_FLG_NEEDFLUSH))
+ return;
+
+ write_cmd(g, SSD1306_SETSTARTLINE | 0);
+
+ for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH)
+ write_data(g, RAM(g)+i, SSD1306_PAGE_WIDTH);
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+ coord_t x, y;
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ x = g->p.x;
+ break;
+ }
+ if (COLOR2NATIVE(g->p.color) != Black)
+ RAM(g)[xyaddr(x, y)] |= xybit(y);
+ else
+ RAM(g)[xyaddr(x, y)] &= ~xybit(y);
+ g->flags |= GDISP_FLG_NEEDFLUSH;
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ coord_t x, y;
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ y = g->p.x;
+ break;
+ }
+ return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black;
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerSleep:
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_cmd(g, SSD1306_DISPLAYOFF);
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_cmd(g, SSD1306_DISPLAYON);
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ /* Rotation is handled by the drawing routines */
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_CONTRAST:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ acquire_bus(g);
+ write_cmd2(g, SSD1306_SETCONTRAST, (((unsigned)g->p.ptr)<<8)/101);
+ release_bus(g);
+ g->g.Contrast = (unsigned)g->p.ptr;
+ return;
+
+ // Our own special controller code to inverse the display
+ // 0 = normal, 1 = inverse
+ case GDISP_CONTROL_INVERSE:
+ acquire_bus(g);
+ write_cmd(g, g->p.ptr ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
+ release_bus(g);
+ return;
+ }
+ }
+#endif // GDISP_NEED_CONTROL
+
+#endif // GFX_USE_GDISP
+
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_board_example_i2c.h b/drivers/gdisp/SSD1306/gdisp_lld_board_example_i2c.h
deleted file mode 100644
index 0e7e153a..00000000
--- a/drivers/gdisp/SSD1306/gdisp_lld_board_example_i2c.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define SSD1306_RESET_PORT GPIOB
-#define SSD1306_RESET_PIN 5
-
-/**
- * The default slave address is 0x3D, (talking about
- * only the real address part here) and the slave
- * address can be changed to 0x3C by soldering the
- * SA0 pads on the bottom side of the module.
- *
- * b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0
- * --------------------------------------
- * 0 | 1 | 1 | 1 | 1 | 0 |SA0 | R/W
- */
-#define SSD1306_I2C_ADDRESS 0x3D
-#define SSD1306_SDA_PORT GPIOB
-#define SSD1306_SDA_PIN 7
-#define SSD1306_SCL_PORT GPIOB
-#define SSD1306_SCL_PIN 6
-#define SET_RST palSetPad(SSD1306_RESET_PORT, SSD1306_RESET_PIN);
-#define CLR_RST palClearPad(SSD1306_RESET_PORT, SSD1306_RESET_PIN);
-int8_t vccstate;
-int32_t row_offset = 0;
-
-// I2C configuration structure.
-static I2CConfig i2cconfig;
-
-
-/**
- * @brief Initialize the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- * @notapi
- */
-static inline void init_board(void) {
-
- // RESET pin.
- palSetPadMode(SSD1306_RESET_PORT, SSD1306_RESET_PIN, PAL_MODE_OUTPUT_PUSHPULL);
-
-
- /*
- * Initializes the I2C driver 1. The I2C1 signals are routed as follows:
- * PB6 - SCL.
- * PB7 - SDA.
- * Timing value comes from ST I2C config tool (xls):
- * 0x00901D2B; // 100kHz Standard Mode
- * 0x00300444; // 100kHz Fast Mode
- * 0x0030020A; // 400kHz Fast Mode
- * 0x00100002; // 800kHz Fast Mode +
- */
- i2cconfig.timingr = 0x00100002; // 800kHz Fast Mode+
- i2cInit();
- palSetPadMode(SSD1306_SCL_PORT, SSD1306_SCL_PIN, PAL_MODE_ALTERNATE(1));
- palSetPadMode(SSD1306_SDA_PORT, SSD1306_SDA_PIN, PAL_MODE_ALTERNATE(1));
- vccstate = SSD1306_SWITCHCAPVCC;
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- if(state)
- SET_RST
- else
- CLR_RST
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @param[in] percent 0 to 100%
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- // Since we are on OLED no backlight needed
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @notapi
- */
-static inline void acquire_bus(void) {
- i2cAcquireBus(&I2CD1);
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @notapi
- */
-static inline void release_bus(void) {
- i2cReleaseBus(&I2CD1);
-}
-
-/**
- * @brief Send command to the display.
- * @param[in] cmd The command to send *
- * @notapi
- */
-static inline void write_cmd(uint8_t cmd) {
- uint8_t command[] = { 0x00, // Co = 0, D/C = 0
- cmd },
- txLength = sizeof(command)/sizeof(command[0]),
- rxLength = 0;
- i2cStart(&I2CD1, &i2cconfig);
- i2cMasterTransmitTimeout(&I2CD1, SSD1306_I2C_ADDRESS, command, txLength, NULL, rxLength, MS2ST(10));
- i2cStop(&I2CD1);
-}
-
-/**
- * @brief Send data to the display.
- * @param[in] data The data to send
- * @notapi
- */
-static inline void write_data(uint8_t* data, uint16_t length) {
- uint8_t command[length+1],
- txLength = length+1,
- rxLength = 0;
- command[0] = 0x40; // Co = 0, D/C = 1
- memmove(&command[1], data, length);
-
- i2cStart(&I2CD1, &i2cconfig);
- i2cMasterTransmitTimeout(&I2CD1, SSD1306_I2C_ADDRESS, command, txLength, NULL, rxLength, MS2ST(10));
- i2cStop(&I2CD1);
-}
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_board_example_spi.h b/drivers/gdisp/SSD1306/gdisp_lld_board_example_spi.h
deleted file mode 100644
index 232cd58c..00000000
--- a/drivers/gdisp/SSD1306/gdisp_lld_board_example_spi.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-#define SSD1306_RESET_PORT GPIOB
-#define SSD1306_RESET_PIN 5
-#define SSD1306_MISO_PORT GPIOB
-#define SSD1306_MISO_PIN 8
-#define SSD1306_MOSI_PORT GPIOB
-#define SSD1306_MOSI_PIN 7
-#define SSD1306_SCK_PORT GPIOB
-#define SSD1306_SCK_PIN 6
-#define SSD1306_CS_PORT GPIOB
-#define SSD1306_CS_PIN 5
-#define SET_RST palSetPad(SSD1306_RESET_PORT, SSD1306_RESET_PIN);
-#define CLR_RST palClearPad(SSD1306_RESET_PORT, SSD1306_RESET_PIN);
-int8_t vccstate;
-int32_t row_offset = 0;
-
-/*
- * SPI1 configuration structure.
- * Speed 42MHz, CPHA=0, CPOL=0, 8bits frames, MSb transmitted first.
- * The slave select line is the pin 4 on the port GPIOA.
- */
-static const SPIConfig spi1config = {
- NULL,
- /* HW dependent part.*/
- SSD1306_MISO_PORT,
- SSD1306_MISO_PIN,
- 0
- //SPI_CR1_BR_0
-};
-
-/**
- * @brief Initialize the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- * @notapi
- */
-static inline void init_board(void) {
-
- // RESET pin.
- palSetPadMode(SSD1306_RESET_PORT, SSD1306_RESET_PIN, PAL_MODE_OUTPUT_PUSHPULL);
-
- spiInit();
- palSetPadMode(SSD1306_MISO_PORT, SSD1306_MISO_PIN, PAL_MODE_ALTERNATE(1)|
- PAL_STM32_OSPEED_HIGHEST);
- palSetPadMode(SSD1306_MOSI_PORT, SSD1306_MOSI_PIN, PAL_MODE_ALTERNATE(1)|
- PAL_STM32_OSPEED_HIGHEST);
- palSetPadMode(SSD1306_SCK_PORT, SSD1306_SCK_PIN, PAL_MODE_ALTERNATE(1)|
- PAL_STM32_OSPEED_HIGHEST);
- palSetPad(SSD1306_CS_PORT, SSD1306_CS_PIN);
- palSetPadMode(SSD1306_CS_PORT, SSD1306_CS_PIN, PAL_MODE_ALTERNATE(1)|
- PAL_STM32_OSPEED_HIGHEST);
- vccstate = SSD1306_SWITCHCAPVCC;
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- if(state)
- SET_RST
- else
- CLR_RST
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @param[in] percent 0 to 100%
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- // Since we are on OLED no backlight needed
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @notapi
- */
-static inline void acquire_bus(void) {
- spiAcquireBus(&SPID1);
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @notapi
- */
-static inline void release_bus(void) {
- spiReleaseBus(&SPID1);
-}
-
-/**
- * @brief Send command to the display.
- * @param[in] cmd The command to send *
- * @notapi
- */
-static inline void write_cmd(uint8_t cmd) {
- uint8_t command[] = { 0x00, // Co = 0, D/C = 0
- cmd },
- txLength = sizeof(command)/sizeof(command[0]),
- rxLength = 0;
-
- spiStart(&SPID1, &spi1config);
- spiSelect(&SPID1);
- spiStartSend(&SPID1, txLength, command);
- spiUnselect(&SPID1);
- spiStop(&SPID1);
-}
-
-/**
- * @brief Send data to the display.
- * @param[in] data The data to send
- * @notapi
- */
-static inline void write_data(uint8_t* data, uint16_t length) {
- uint8_t command[length+1],
- txLength = length+1;
- command[0] = 0x40; // Co = 0, D/C = 1
- memmove(&command[1], data, length);
-
- spiStart(&SPID1, &spi1config);
- spiSelect(&SPID1);
- spiStartSend(&SPID1, txLength, command);
- spiUnselect(&SPID1);
- spiStop(&SPID1);
-}
-
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_board_template.h b/drivers/gdisp/SSD1306/gdisp_lld_board_template.h
deleted file mode 100644
index 48028e83..00000000
--- a/drivers/gdisp/SSD1306/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialize the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @param[in] percent 0 to 100%
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- // Since we are on OLED no backlight needed
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send command to the display.
- * @param[in] cmd The command to send *
- * @notapi
- */
-static inline void write_cmd(uint8_t cmd) {
-
-}
-
-/**
- * @brief Send data to the display.
- * @param[in] data The data to send
- * @notapi
- */
-static inline void write_data(uint8_t* data, uint16_t length) {
-
-}
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/SSD1306/gdisp_lld_config.h b/drivers/gdisp/SSD1306/gdisp_lld_config.h
index f0efc18e..627de17b 100644
--- a/drivers/gdisp/SSD1306/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1306/gdisp_lld_config.h
@@ -14,16 +14,16 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "SSD1306"
-
-#define GDISP_HARDWARE_CLEARS FALSE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS FALSE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD FALSE
+#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
+#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
+
+// This controller supports a special gdispControl() to inverse the display.
+// Pass a parameter of 1 for inverse and 0 for normal.
+#define GDISP_CONTROL_INVERSE (GDISP_CONTROL_LLD+0)
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1963/board_SSD1963_template.h b/drivers/gdisp/SSD1963/board_SSD1963_template.h
new file mode 100644
index 00000000..5e1999b8
--- /dev/null
+++ b/drivers/gdisp/SSD1963/board_SSD1963_template.h
@@ -0,0 +1,148 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1963/board_SSD1963_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the SSD1963 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief LCD panel specs
+ *
+ * @note The timings need to follow the datasheet for your particular TFT/LCD screen
+ * (the actual screen, not the controller).
+ * @note Datasheets normally use a specific set of timings and acronyms, their value refers
+ * to the number of pixel clocks. Non-display periods refer to pulses/timings that occur
+ * before or after the timings that actually put pixels on the screen. Display periods
+ * refer to pulses/timings that directly put pixels on the screen.
+ * @note HDP: Horizontal Display Period, normally the width - 1<br>
+ * HT: Horizontal Total period (display + non-display)<br>
+ * HPS: non-display period between the start of the horizontal sync (LLINE) signal
+ * and the first display data<br>
+ * LPS: horizontal sync pulse (LLINE) start location in pixel clocks<br>
+ * HPW: Horizontal sync Pulse Width<br>
+ * VDP: Vertical Display period, normally height - 1<br>
+ * VT: Vertical Total period (display + non-display)<br>
+ * VPS: non-display period in lines between the start of the frame and the first display
+ * data in number of lines<br>
+ * FPS: vertical sync pulse (LFRAME) start location in lines.<br>
+ * VPW: Vertical sync Pulse Width
+ * @note Here's how to convert them:<br>
+ * SCREEN_HSYNC_FRONT_PORCH = ( HT - HPS ) - GDISP_SCREEN_WIDTH<br>
+ * SCREEN_HSYNC_PULSE = HPW<br>
+ * SCREEN_HSYNC_BACK_PORCH = HPS - HPW<br>
+ * SCREEN_VSYNC_FRONT_PORCH = ( VT - VPS ) - GDISP_SCREEN_HEIGHT<br>
+ * SCREEN_VSYNC_PULSE = VPW<br>
+ * SCREEN_VSYNC_BACK_PORCH = VPS - LPS<br>
+ */
+
+static const LCD_Parameters DisplayTimings[] = {
+ // You need one of these array elements per display
+ {
+ 480, 272, // Panel width and height
+ 2, 2, 41, // Horizontal Timings (back porch, front porch, pulse)
+ CALC_PERIOD(480,2,2,41), // Total Horizontal Period (calculated from above line)
+ 2, 2, 10, // Vertical Timings (back porch, front porch, pulse)
+ CALC_PERIOD(272,2,2,10), // Total Vertical Period (calculated from above line)
+ CALC_FPR(480,272,2,2,41,2,2,10,60ULL) // FPR - the 60ULL is the frames per second. Note the ULL!
+ },
+};
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/SSD1963/gdisp_lld.c b/drivers/gdisp/SSD1963/gdisp_lld.c
deleted file mode 100644
index 39889731..00000000
--- a/drivers/gdisp/SSD1963/gdisp_lld.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#include "ssd1963.h"
-
-/* All the board specific code should go in these include file so the driver
- * can be ported to another board just by creating a suitable file.
- */
-#include "gdisp_lld_board.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 initialisation.
- * @return TRUE if successful, FALSE on error.
- *
- * @notapi
- */
-bool_t gdisp_lld_init(void) {
- /* Initialise the display */
-
- init_board();
-
- write_index(SSD1963_SOFT_RESET);
- gfxSleepMicroseconds(100);
-
- /* Driver PLL config */
- write_index(SSD1963_SET_PLL_MN);
- write_data(35); // PLLclk = REFclk (10Mhz) * 36 (360Mhz)
- write_data(2); // SYSclk = PLLclk / 3 (120MHz)
- write_data(4); // Apply calculation bit, else it is ignored
-
- write_index(SSD1963_SET_PLL); // Enable PLL
- write_data(0x01);
- gfxSleepMicroseconds(200);
-
- write_index(SSD1963_SET_PLL); // Use PLL
- write_data(0x03);
- gfxSleepMicroseconds(200);
-
- write_index(SSD1963_SOFT_RESET);
- gfxSleepMicroseconds(100);
-
- /* Screen size */
- write_index(SSD1963_SET_GDISP_MODE);
-// write_data(0x0000);
- write_data(0b00011000); //Enabled dithering
- write_data(0x0000);
- write_data(mHIGH((GDISP_SCREEN_WIDTH+1)));
- write_data((GDISP_SCREEN_WIDTH+1));
- write_data(mHIGH((GDISP_SCREEN_HEIGHT+1)));
- write_data((GDISP_SCREEN_HEIGHT+1));
- write_data(0x0000);
-
- write_index(SSD1963_SET_PIXEL_DATA_INTERFACE);
- write_data(SSD1963_PDI_16BIT565);
-
- /* LCD Clock specs */
- write_index(SSD1963_SET_LSHIFT_FREQ);
- write_data((GDISP_FPR >> 16) & 0xFF);
- write_data((GDISP_FPR >> 8) & 0xFF);
- write_data(GDISP_FPR & 0xFF);
-
- write_index(SSD1963_SET_HORI_PERIOD);
- write_data(mHIGH(SCREEN_HSYNC_PERIOD));
- write_data(mLOW(SCREEN_HSYNC_PERIOD));
- write_data(mHIGH((SCREEN_HSYNC_PULSE + SCREEN_HSYNC_BACK_PORCH)));
- write_data(mLOW((SCREEN_HSYNC_PULSE + SCREEN_HSYNC_BACK_PORCH)));
- write_data(SCREEN_HSYNC_PULSE);
- write_data(0x00);
- write_data(0x00);
- write_data(0x00);
-
- write_index(SSD1963_SET_VERT_PERIOD);
- write_data(mHIGH(SCREEN_VSYNC_PERIOD));
- write_data(mLOW(SCREEN_VSYNC_PERIOD));
- write_data(mHIGH((SCREEN_VSYNC_PULSE + SCREEN_VSYNC_BACK_PORCH)));
- write_data(mLOW((SCREEN_VSYNC_PULSE + SCREEN_VSYNC_BACK_PORCH)));
- write_data(SCREEN_VSYNC_PULSE);
- write_data(0x00);
- write_data(0x00);
-
- /* Tear effect indicator ON. This is used to tell the host MCU when the driver is not refreshing the panel (during front/back porch) */
- write_index(SSD1963_SET_TEAR_ON);
- write_data(0x0000);
-
- /* Turn on */
- write_index(SSD1963_SET_DISPLAY_ON);
-
- set_backlight(0xE5);//set to 90% brightness
-
- post_init_board();
-
- /* Initialise the GDISP structure to match */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
-
- return TRUE;
-}
-
-void gdisp_lld_setwindow(coord_t x0, coord_t y0, coord_t x1, coord_t y1) {
- /* We don't need to validate here as the LLD routines will validate first.
- *
- * #if GDISP_NEED_VALIDATION
- * if (x0 >= GDISP.Width || y0 >= GDISP.Height || x0 < 0 || y0 < 0) return;
- * else if (x1 >= GDISP.Width || y1 >= GDISP.Height || y1 < 0 || y2 < 0) return;
- * #endif
- */
- write_index(SSD1963_SET_PAGE_ADDRESS);
- write_data((y0 >> 8) & 0xFF);
- write_data((y0 >> 0) & 0xFF);
- write_data((y1 >> 8) & 0xFF);
- write_data((y1 >> 0) & 0xFF);
- write_index(SSD1963_SET_COLUMN_ADDRESS);
- write_data((x0 >> 8) & 0xFF);
- write_data((x0 >> 0) & 0xFF);
- write_data((x1 >> 8) & 0xFF);
- write_data((x1 >> 0) & 0xFF);
-}
-
-/**
- * @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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- gdisp_lld_setwindow(x, y, x, y);
- write_index(SSD1963_WRITE_MEMORY_START);
- write_data(color);
-}
-
-/* ---- Optional Routines ---- */
-
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- uint32_t area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
-
- gdisp_lld_setwindow(x, y, x+cx-1, y+cy-1);
- write_index(SSD1963_WRITE_MEMORY_START);
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, &color);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area/65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area%65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- uint32_t index;
- for(index = 0; index < area; index++)
- write_data(color);
- #endif //#ifdef GDISP_USE_DMA
-}
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- gdisp_lld_setwindow(x, y, x+cx-1, y+cy-1);
- write_index(SSD1963_WRITE_MEMORY_START);
-
- buffer += srcx + srcy * srccx;
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint32_t area = cx*cy;
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, buffer);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PINC | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area/65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area%65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- coord_t endx, endy;
- uint32_t lg;
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- #endif //#ifdef GDISP_USE_DMA
- }
-#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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
- /* NOT IMPLEMENTED YET */
-
- /*
- uint16_t size = x1 - x0 ;
-
- write_index(SSD1963_SET_SCROLL_AREA);
- write_data((x0 >> 8) & 0xFF);
- write_data((x0 >> 0) & 0xFF);
- write_data((size >> 8) & 0xFF);
- write_data((size >> 0) & 0xFF);
- write_data(((lcd_height-x1) >> 8) & 0xFF);
- write_data(((lcd_height-x1) >> 0) & 0xFF);
-
- write_index(SSD1963_SET_SCROLL_START);
- write_data((lines >> 8) & 0xFF);
- write_data((lines >> 0) & 0xFF);
- */
- }
-
-#endif
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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) {
- /* NOT IMPLEMENTED YET */
- switch(what) {
- case GDISP_CONTROL_POWER:
- if (GDISP.Powermode == (gdisp_powermode_t)value)
- return;
- switch((gdisp_powermode_t)value) {
- case powerOff:
- write_index(SSD1963_EXIT_SLEEP_MODE); // leave sleep mode
- gfxSleepMilliseconds(5);
- write_index(SSD1963_SET_DISPLAY_OFF);
- write_index(SSD1963_SET_DEEP_SLEEP); // enter deep sleep mode
- break;
- case powerOn:
- read_reg(0x0000); gfxSleepMilliseconds(5); // 2x Dummy reads to wake up from deep sleep
- read_reg(0x0000); gfxSleepMilliseconds(5);
- if (GDISP.Powermode != powerSleep)
- gdisp_lld_init();
- write_index(SSD1963_SET_DISPLAY_ON);
-
- break;
- case powerSleep:
- write_index(SSD1963_SET_DISPLAY_OFF);
- write_index(SSD1963_ENTER_SLEEP_MODE); // enter sleep mode
- gfxSleepMilliseconds(5);
- 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 GDISP_ROTATE_0:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_90:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- case GDISP_ROTATE_180:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
- case GDISP_ROTATE_270:
- /* Code here */
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
- case GDISP_CONTROL_BACKLIGHT:
- gdisp_lld_bg_dimmer(54 + ((uint8_t)value) << 1);//turn 0..100% in 54..255
- return;
-/*
- case GDISP_CONTROL_CONTRAST:
-*/
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/gdisp/SSD1963/gdisp_lld.mk b/drivers/gdisp/SSD1963/gdisp_lld.mk
index c2ce22b6..f56f11de 100644
--- a/drivers/gdisp/SSD1963/gdisp_lld.mk
+++ b/drivers/gdisp/SSD1963/gdisp_lld.mk
@@ -1,6 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1963/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/SSD1963
-
+GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c b/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c
new file mode 100644
index 00000000..eb1b9b15
--- /dev/null
+++ b/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c
@@ -0,0 +1,285 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD1963/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_SSD1963
+#include "../drivers/gdisp/SSD1963/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#define CALC_PERIOD(w,b,f,p) (p+b+w+f)
+#define CALC_FPR(w,h,hb,hf,hp,vb,vf,vp,fps) ((fps * CALC_PERIOD(w,hb,hf,hp) * CALC_PERIOD(h,vb,vf,vp) * 1048576)/100000000)
+
+typedef struct LCD_Parameters {
+ coord_t width, height; // Panel width and height
+ uint16_t hbporch; // Horizontal Back Porch
+ uint16_t hfporch; // Horizontal Front Porch
+ uint16_t hpulse; // Horizontal Pulse
+ uint16_t hperiod; // Horizontal Period (Total)
+ uint16_t vbporch; // Vertical Back Porch
+ uint16_t vfporch; // Vertical Front Porch
+ uint16_t vpulse; // Vertical Pulse
+ uint16_t vperiod; // Vertical Period (Total)
+ uint32_t fpr; // Calculated FPR
+} LCD_Parameters;
+
+#include "board_SSD1963.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 90
+#endif
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+#include "ssd1963.h"
+
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+#define write_data16(g, data) { write_data(g, (data)>>8); write_data(g, (data) & 0xFF); }
+
+static inline void set_viewport(GDisplay* g) {
+ write_index(g, SSD1963_SET_PAGE_ADDRESS);
+ write_data16(g, g->p.y);
+ write_data16(g, g->p.y+g->p.cy-1);
+ write_index(g, SSD1963_SET_COLUMN_ADDRESS);
+ write_data16(g, g->p.x);
+ write_data16(g, g->p.x+g->p.cx-1);
+ write_index(g, SSD1963_WRITE_MEMORY_START);
+}
+
+/**
+ * The backlight is controlled by the controller.
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ //duty_cycle is 00..FF
+ //Work in progress: the SSD1963 has a built-in PWM, its output can
+ //be used by a Dynamic Background Control or by a host (user)
+ //Check your LCD's hardware, the PWM connection is default left open and instead
+ //connected to a LED connection on the breakout board
+ write_index(g, SSD1963_SET_PWM_CONF); //set PWM for BackLight
+ write_data(g, 0x01);
+ write_data(g, (55+percent*2) & 0x00FF);
+ write_data(g, 0x01); //controlled by host (not DBC), enabled
+ write_data(g, 0xFF);
+ write_data(g, 0x60); //don't let it go too dark, avoid a useless LCD
+ write_data(g, 0x0F); //prescaler ???
+}
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ LCD_Parameters * lcdp;
+
+ // The private area for this controller is the LCD timings
+ lcdp = (void *)&DisplayTimings[g->controllerdisplay];
+ g->priv = lcdp;
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ write_index(g, SSD1963_SOFT_RESET);
+ gfxSleepMilliseconds(5);
+
+ /* Driver PLL config */
+ write_index(g, SSD1963_SET_PLL_MN);
+ write_data(g, 35); // PLLclk = REFclk (10Mhz) * 36 (360Mhz)
+ write_data(g, 2); // SYSclk = PLLclk / 3 (120MHz)
+ write_data(g, 4); // Apply calculation bit, else it is ignored
+ write_reg(g, SSD1963_SET_PLL, 0x01); // Enable PLL
+ gfxSleepMilliseconds(5);
+ write_reg(g, SSD1963_SET_PLL, 0x03); // Use PLL
+ gfxSleepMilliseconds(5);
+ write_index(g, SSD1963_SOFT_RESET);
+ gfxSleepMilliseconds(5);
+
+ /* Screen size */
+ write_index(g, SSD1963_SET_GDISP_MODE);
+ write_data(g, 0x18); //Enabled dithering
+ write_data(g, 0x00);
+ write_data16(g, lcdp->width-1);
+ write_data16(g, lcdp->height-1);
+ write_data(g, 0x00); // RGB
+
+ write_reg(g, SSD1963_SET_PIXEL_DATA_INTERFACE, SSD1963_PDI_16BIT565);
+
+ /* LCD Clock specs */
+ write_index(g, SSD1963_SET_LSHIFT_FREQ);
+ write_data(g, (lcdp->fpr >> 16) & 0xFF);
+ write_data(g, (lcdp->fpr >> 8) & 0xFF);
+ write_data(g, lcdp->fpr & 0xFF);
+
+ write_index(g, SSD1963_SET_HORI_PERIOD);
+ write_data16(g, lcdp->hperiod);
+ write_data16(g, lcdp->hpulse + lcdp->hbporch);
+ write_data(g, lcdp->hpulse);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+
+ write_index(g, SSD1963_SET_VERT_PERIOD);
+ write_data16(g, lcdp->vperiod);
+ write_data16(g, lcdp->vpulse + lcdp->vbporch);
+ write_data(g, lcdp->vpulse);
+ write_data(g, 0x00);
+ write_data(g, 0x00);
+
+ /* Tear effect indicator ON. This is used to tell the host MCU when the driver is not refreshing the panel (during front/back porch) */
+ write_reg(g, SSD1963_SET_TEAR_ON, 0x00);
+
+ /* Turn on */
+ write_index(g, SSD1963_SET_DISPLAY_ON);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = lcdp->width;
+ g->g.Height = lcdp->height;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ release_bus(g);
+ }
+#endif
+
+// Not implemented yet.
+#if 0 && GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ acquire_bus(g);
+ write_index(g, SSD1963_EXIT_SLEEP_MODE); // leave sleep mode
+ gfxSleepMilliseconds(5);
+ write_index(g, SSD1963_SET_DISPLAY_OFF);
+ write_index(g, SSD1963_SET_DEEP_SLEEP); // enter deep sleep mode
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ read_reg(0x0000); gfxSleepMilliseconds(5); // 2x Dummy reads to wake up from deep sleep
+ read_reg(0x0000); gfxSleepMilliseconds(5);
+ write_index(g, SSD1963_SET_DISPLAY_ON);
+ release_bus(g);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ write_index(g, SSD1963_SET_DISPLAY_OFF);
+ write_index(g, SSD1963_ENTER_SLEEP_MODE); // enter sleep mode
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ /* Code here */
+ release_bus(g);
+ g->g.Height = ((LCD_Parameters *)g->priv)->height;
+ g->g.Width = ((LCD_Parameters *)g->priv)->width;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ /* Code here */
+ release_bus(g);
+ g->g.Height = ((LCD_Parameters *)g->priv)->width;
+ g->g.Width = ((LCD_Parameters *)g->priv)->height;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ /* Code here */
+ release_bus(g);
+ g->g.Height = ((LCD_Parameters *)g->priv)->height;
+ g->g.Width = ((LCD_Parameters *)g->priv)->width;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ /* Code here */
+ release_bus(g);
+ g->g.Height = ((LCD_Parameters *)g->priv)->width;
+ g->g.Width = ((LCD_Parameters *)g->priv)->height;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
+
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h b/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
deleted file mode 100644
index a2c296b9..00000000
--- a/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1963 display.
- *
- * @details This file demonstrates how to interface an SSD1963 based display to an
- * STM32 microcontroller using ChibiOS/RT.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/* Using FSMC A16 as RS */
-#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
-#define GDISP_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- GDISP_REG = index;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-/**
- * @brief Initialise the board for the display.
- * @notes Performs the following functions:
- * 1. initialise the io 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 init_board(void) {
- const unsigned char FSMC_Bank = 0;
-
- #if defined(STM32F1XX) || defined(STM32F3XX)
- /* FSMC setup for F1/F3 */
- rccEnableAHB(RCC_AHBENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- #error "DMA not implemented for F1/F3 Devices"
- #endif
- #elif defined(STM32F4XX) || defined(STM32F2XX)
- /* STM32F2-F4 FSMC init */
- rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) gfxExit();
- dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- #endif
- #else
- #error "FSMC not implemented for this device"
- #endif
-
-< /* 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));
-
- /* FSMC timing */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = (FSMC_BTR1_ADDSET_1 | FSMC_BTR1_ADDSET_3) \
- | (FSMC_BTR1_DATAST_1 | FSMC_BTR1_DATAST_3) \
- | (FSMC_BTR1_BUSTURN_1 | FSMC_BTR1_BUSTURN_3) ;
-
- /* Bank1 NOR/SRAM control register configuration
- * This is actually not needed as already set by default after reset */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-}
-
-static inline void post_init_board(void) {
- const unsigned char FSMC_Bank = 0;
- /* FSMC delay reduced as the controller now runs at full speed */
- FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_0 | FSMC_BTR1_DATAST_2 | FSMC_BTR1_BUSTURN_0 ;
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN;
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- (void) state;
- /* Nothing to do here */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- //duty_cycle is 00..FF
- //Work in progress: the SSD1963 has a built-in PWM, its output can
- //be used by a Dynamic Background Control or by a host (user)
- //Check your LCD's hardware, the PWM connection is default left open and instead
- //connected to a LED connection on the breakout board
- write_index(SSD1963_SET_PWM_CONF);//set PWM for BackLight
- write_data(0x0001);
- write_data(percent & 0x00FF);
- write_data(0x0001);//controlled by host (not DBC), enabled
- write_data(0x00FF);
- write_data(0x0060);//don't let it go too dark, avoid a useless LCD
- write_data(0x000F);//prescaler ???
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do 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 read_data(void) {
- return GDISP_RAM;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_board_example_gpio.h b/drivers/gdisp/SSD1963/gdisp_lld_board_example_gpio.h
deleted file mode 100644
index 38f5b2a5..00000000
--- a/drivers/gdisp/SSD1963/gdisp_lld_board_example_gpio.h
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld_board_example_gpio.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1963 display.
- *
- * @brief This file demonstrates how to interface an SSD1963 based display using
- * a GPIO interface of an STM32 out of ChibiOS/RT.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief The GPIO pin config
- *
- * @details This block of defines tell your driver how you wired your display
- * controller to your MCU. Please change them accordingly.
- */
-#define GDISP_CMD_PORT GPIOC
-#define GDISP_DATA_PORT GPIOD
-#define GDISP_CS 0
-#define GDISP_RS 1
-#define GDISP_WR 2
-#define GDISP_RD 3
-
-#define Set_CS palSetPad(GDISP_CMD_PORT, GDISP_CS);
-#define Clr_CS palClearPad(GDISP_CMD_PORT, GDISP_CS);
-#define Set_RS palSetPad(GDISP_CMD_PORT, GDISP_RS);
-#define Clr_RS palClearPad(GDISP_CMD_PORT, GDISP_RS);
-#define Set_WR palSetPad(GDISP_CMD_PORT, GDISP_WR);
-#define Clr_WR palClearPad(GDISP_CMD_PORT, GDISP_WR);
-#define Set_RD palSetPad(GDISP_CMD_PORT, GDISP_RD);
-#define Clr_RD palClearPad(GDISP_CMD_PORT, GDISP_RD);
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- Set_CS; Set_RS; Set_WR; Clr_RD;
-
- palWritePort(GDISP_DATA_PORT, index);
-
- Clr_CS;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- Set_CS; Clr_RS; Set_WR; Clr_RD;
-
- palWritePort(GDISP_DATA_PORT, data);
-
- Clr_CS;
-}
-
-/**
- * @brief Initialise the board for the display.
- *
- * @notapi
- */
-static inline void init_board(void) {
- IOBus busCMD = {GDISP_CMD_PORT, (1 << GDISP_CS) | (1 << GDISP_RS) | (1 << GDISP_WR) | (1 << GDISP_RD), 0};
- IOBus busDATA = {GDISP_CMD_PORT, 0xFFFFF, 0};
- palSetBusMode(&busCMD, PAL_MODE_OUTPUT_PUSHPULL);
- palSetBusMode(&busDATA, PAL_MODE_OUTPUT_PUSHPULL);
-}
-
-static inline void post_init_board(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- /* optional */
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- //duty_cycle is 00..FF
- //Work in progress: the SSD1963 has a built-in PWM, its output can
- //be used by a Dynamic Background Control or by a host (user)
- //Check your LCD's hardware, the PWM connection is default left open and instead
- //connected to a LED connection on the breakout board
- write_index(SSD1963_SET_PWM_CONF);//set PWM for BackLight
- write_data(0x0001);
- write_data(percent & 0x00FF);
- write_data(0x0001);//controlled by host (not DBC), enabled
- write_data(0x00FF);
- write_data(0x0060);//don't let it go too dark, avoid a useless LCD
- write_data(0x000F);//prescaler ???
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here */
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here */
-}
-
-__inline void write_stream(uint16_t *buffer, uint16_t size) {
- uint16_t i;
-
- Set_CS; Clr_RS; Set_WR; Clr_RD;
-
- for (i = 0; i < size; i++) {
- Set_WR;
- palWritePort(GDISP_DATA_PORT, buffer[i]);
- Clr_WR;
- }
-
- Clr_CS;
-}
-
-__inline void read_stream(uint16_t *buffer, size_t size) {
- uint16_t i;
-
- Set_CS; Clr_RS; Clr_WR; Set_RD;
-
- for (i = 0; i < size; i++) {
- Set_RD;
- buffer[i] = palReadPort(GDISP_DATA_PORT);
- Clr_RD;
- }
-}
-
-#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 read_data(void) {
- uint16_t data;
-
- Set_CS; Clr_RS; Clr_WR; Set_RD;
-
- data = palReadPort(GDISP_DATA_PORT);
-
- Clr_CS;
-
- return data;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_board_template.h b/drivers/gdisp/SSD1963/gdisp_lld_board_template.h
deleted file mode 100644
index 44cd3712..00000000
--- a/drivers/gdisp/SSD1963/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board interface for the SSD1963 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-/**
- * @brief Initialise the board for the display.
- * @notes Performs the following functions:
- * 1. initialise the io 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 init_board(void) {
-
-}
-
-static inline void post_init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_config.h b/drivers/gdisp/SSD1963/gdisp_lld_config.h
index 70eec579..8ad94738 100644
--- a/drivers/gdisp/SSD1963/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD1963/gdisp_lld_config.h
@@ -22,16 +22,10 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "SSD1963"
-#define GDISP_LLD(x) gdisp_lld_##x##_SSD1963
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+//#define GDISP_HARDWARE_CONTROL TRUE // Not Yet.
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-/* Maybe someday soon */
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_CONTROL FALSE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_panel_example.h b/drivers/gdisp/SSD1963/gdisp_lld_panel_example.h
deleted file mode 100644
index 72095495..00000000
--- a/drivers/gdisp/SSD1963/gdisp_lld_panel_example.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD1963/gdisp_lld_panel_example.h
- * @brief TFT LCD panel properties.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_PANEL_H
-#define _GDISP_LLD_PANEL_H
-
-/* LCD panel specs */
-
-/* The timings need to follow the datasheet for your particular TFT/LCD screen (the actual screen, not the controller)
-*** Datasheets normally use a specific set of timings and acronyms, their value refers to the number of pixel clocks
-** Non-display periods refer to pulses/timings that occur before or after the timings that actually put pixels on the screen
-** Display periods refer to pulses/timings that directly put pixels on the screen
-HDP: Horizontal Display Period, normally the width - 1
-HT: Horizontal Total period (display + non-display)
-HPS: non-display period between the start of the horizontal sync (LLINE) signal and the first display data
-LPS: horizontal sync pulse (LLINE) start location in pixel clocks
-HPW: Horizontal sync Pulse Width
-VDP: Vertical Display period, normally height - 1
-VT: Vertical Total period (display + non-display)
-VPS: non-display period in lines between the start of the frame and the first display data in number of lines
-FPS: vertical sync pulse (LFRAME) start location in lines.
-VPW: Vertical sync Pulse Width
-
-*** Here's how to convert them:
-HPS = SCREEN_HSYNC_PULSE + SCREEN_HSYNC_BACK_PORCH
-HT - HPS = GDISP_SCREEN_WIDTH + SCREEN_HSYNC_FRONT_PORCH
-=> SCREEN_HSYNC_FRONT_PORCH = ( HT - HPS ) - GDISP_SCREEN_WIDTH
- SCREEN_HSYNC_PULSE = HPW
- SCREEN_HSYNC_BACK_PORCH = HPS - HPW
- SCREEN_HSYNC_PERIOD = HT
-
-VPS = SCREEN_VSYNC_PULSE + SCREEN_VSYNC_BACK_PORCH
-VT - VPS = GDISP_SCREEN_HEIGHT + SCREEN_VSYNC_FRONT_PORCH
-=> SCREEN_VSYNC_FRONT_PORCH = ( VT - VPS ) - GDISP_SCREEN_HEIGHT
- SCREEN_VSYNC_PULSE = VPW
- SCREEN_VSYNC_BACK_PORCH = VPS - LPS
- SCREEN_VSYNC_PERIOD = VT
-*/
-
-#define SCREEN_FPS 60ULL
-
-//The following values are for a 4.3" TFT LCD
-
-#define GDISP_SCREEN_WIDTH 480
-#define GDISP_SCREEN_HEIGHT 272
-
-#define SCREEN_HSYNC_BACK_PORCH 2
-#define SCREEN_HSYNC_FRONT_PORCH 2
-#define SCREEN_HSYNC_PULSE 41
-
-#define SCREEN_VSYNC_BACK_PORCH 2
-#define SCREEN_VSYNC_FRONT_PORCH 2
-#define SCREEN_VSYNC_PULSE 10
-
-#define SCREEN_HSYNC_PERIOD (SCREEN_HSYNC_PULSE + SCREEN_HSYNC_BACK_PORCH + GDISP_SCREEN_WIDTH + SCREEN_HSYNC_FRONT_PORCH)
-#define SCREEN_VSYNC_PERIOD (SCREEN_VSYNC_PULSE + SCREEN_VSYNC_BACK_PORCH + GDISP_SCREEN_HEIGHT + SCREEN_VSYNC_FRONT_PORCH)
-
-#define SCREEN_PCLK (SCREEN_HSYNC_PERIOD * SCREEN_VSYNC_PERIOD * SCREEN_FPS)
-#define GDISP_FPR ((SCREEN_PCLK * 1048576)/100000000)
-
-#endif
-/** @} */
diff --git a/drivers/gdisp/SSD1963/ssd1963.h b/drivers/gdisp/SSD1963/ssd1963.h
index 46369be6..be328775 100644
--- a/drivers/gdisp/SSD1963/ssd1963.h
+++ b/drivers/gdisp/SSD1963/ssd1963.h
@@ -8,11 +8,6 @@
#ifndef SSD1963_H
#define SSD1963_H
-#include "gdisp_lld_panel.h"
-
-#define mHIGH(x) (x >> 8)
-#define mLOW(x) (x & 0xFF)
-
/* SSD1963 commands */
#define SSD1963_NOP 0x0000
diff --git a/drivers/gdisp/SSD2119/board_SSD2119_template.h b/drivers/gdisp/SSD2119/board_SSD2119_template.h
new file mode 100644
index 00000000..b4c6341d
--- /dev/null
+++ b/drivers/gdisp/SSD2119/board_SSD2119_template.h
@@ -0,0 +1,191 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD2119/board_SSD2119_template.h
+ * @brief GDISP Graphic Driver subsystem board template for the SSD2119 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Set the lcd back-light level.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] percent 0 to 100%
+ *
+ * @notapi
+ */
+static inline void set_backlight(GDisplay *g, uint8_t percent) {
+ (void) g;
+ (void) percent;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send data to the index register.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] index The index register to set
+ *
+ * @notapi
+ */
+static inline void write_index(GDisplay *g, uint16_t index) {
+ (void) g;
+ (void) index;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint16_t data) {
+ (void) g;
+ (void) data;
+}
+
+/**
+ * @brief Set the bus in read mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setreadmode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set the bus back into write mode
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void setwritemode(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Read data from the lcd.
+ * @return The data from the lcd
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline uint16_t read_data(GDisplay *g) {
+ (void) g;
+ return 0;
+}
+
+/**
+ * The below section you can replace with #error if your interface doesn't support DMA
+ */
+#if defined(GDISP_USE_DMA) || defined(__DOXYGEN__)
+ //#error "GDISP - SSD2119: This interface does not support DMA"
+
+ /**
+ * @brief Transfer data using DMA but don't increment the source address
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] buffer The source buffer location
+ * @param[in] area The number of pixels to transfer
+ *
+ * @notapi
+ */
+ static inline void dma_with_noinc(GDisplay *g, color_t *buffer, int area) {
+ (void) g;
+ (void) buffer;
+ (void) area;
+ }
+
+ /**
+ * @brief Transfer data using DMA incrementing the source address
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] buffer The source buffer location
+ * @param[in] area The number of pixels to transfer
+ *
+ * @notapi
+ */
+ static inline void dma_with_inc(GDisplay *g, color_t *buffer, int area) {
+ (void) g;
+ (void) buffer;
+ (void) area;
+ }
+#endif
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld.c
deleted file mode 100644
index de97d805..00000000
--- a/drivers/gdisp/SSD2119/gdisp_lld.c
+++ /dev/null
@@ -1,704 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD2119/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for the SSD2119 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#include "ssd2119.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 240
-#endif
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 320
-#endif
-
-#define GDISP_INITIAL_CONTRAST 50
-#define GDISP_INITIAL_BACKLIGHT 100
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-#include "gdisp_lld_board.h"
-
-// Some common routines and macros
-#define write_reg(reg, data) { write_index(reg); write_data(data); }
-#define stream_start() write_index(SSD2119_REG_RAM_DATA);
-#define stream_stop()
-#define delay(us) gfxSleepMicroseconds(us)
-#define delayms(ms) gfxSleepMilliseconds(ms)
-
-static inline void set_cursor(coord_t x, coord_t y) {
- /* Reg SSD2119_REG_X_RAM_ADDR is 9 bit value
- * Reg SSD2119_REG_Y_RAM_ADDR is an 8 bit
- * Use a bit mask to make sure they are not set too high
- */
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- write_reg(SSD2119_REG_X_RAM_ADDR, x & 0x01FF);
- write_reg(SSD2119_REG_Y_RAM_ADDR, y & 0x00FF);
- break;
- case GDISP_ROTATE_90:
- write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
- write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF);
- break;
- case GDISP_ROTATE_180:
- write_reg(SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH - 1 - x) & 0x01FF);
- write_reg(SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT - 1 - y) & 0x00FF);
- break;
- case GDISP_ROTATE_270:
- write_reg(SSD2119_REG_X_RAM_ADDR, y & 0x01FF);
- write_reg(SSD2119_REG_Y_RAM_ADDR, x & 0x00FF);
- break;
- }
-}
-
-static void set_viewport(coord_t x, coord_t y, coord_t cx, coord_t cy) {
-
- set_cursor(x, y);
-
- /* Reg 0x44 - Vertical RAM address position
- * Upper Byte - VEA
- * Lower Byte - VSA
- * 0 <= VSA <= VEA <= 0xEF
- * Reg 0x45,0x46 - Horizontal RAM address position
- * Lower 9 bits gives 0-511 range in each value, HSA and HEA respectively
- * 0 <= HSA <= HEA <= 0x13F
- */
-
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- write_reg(SSD2119_REG_V_RAM_POS, (((y + cy - 1) << 8) & 0xFF00 ) | (y & 0x00FF));
- write_reg(SSD2119_REG_H_RAM_START, (x & 0x01FF));
- write_reg(SSD2119_REG_H_RAM_END, (x + cx - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_90:
- write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - x - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (x + cx)) & 0x00FF));
- write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (y + cy)) & 0x01FF);
- write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - y - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_180:
- write_reg(SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT - y - 1) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (y + cy)) & 0x00FF));
- write_reg(SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (x + cx)) & 0x01FF);
- write_reg(SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH - x - 1) & 0x01FF);
- break;
- case GDISP_ROTATE_270:
- write_reg(SSD2119_REG_V_RAM_POS, (((x + cx - 1) << 8) & 0xFF00 ) | (x & 0x00FF));
- write_reg(SSD2119_REG_H_RAM_START, (y & 0x01FF));
- write_reg(SSD2119_REG_H_RAM_END, (y + cy - 1) & 0x01FF);
- break;
- }
-
- set_cursor(x, y);
-}
-
-static inline void reset_viewport(void) {
- set_viewport(0, 0, GDISP.Width, GDISP.Height);
-}
-
-/*===========================================================================*/
-/* 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 */
- init_board();
-
- // Hardware reset
- setpin_reset(TRUE);
- delayms(20);
- setpin_reset(FALSE);
- delayms(20);
-
- // Get the bus for the following initialisation commands
- acquire_bus();
-
- // Enter sleep mode (if we are not already there).
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001);
- delay(5);
-
- // Set initial power parameters.
- write_reg(SSD2119_REG_PWR_CTRL_5, 0x00B2);
- delay(5);
- write_reg(SSD2119_REG_VCOM_OTP_1, 0x0006);
- delay(5);
-
- // Start the oscillator.
- write_reg(SSD2119_REG_OSC_START, 0x0001);
- delay(5);
-
- // Set pixel format and basic display orientation (scanning direction).
- write_reg(SSD2119_REG_OUTPUT_CTRL, 0x30EF);
- delay(5);
- write_reg(SSD2119_REG_LCD_DRIVE_AC_CTRL, 0x0600);
- delay(5);
-
- // Exit sleep mode.
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000);
- delay(5);
-
- // Configure pixel color format and MCU interface parameters.
- write_reg(SSD2119_REG_ENTRY_MODE, 0x6830); // ENTRY_MODE_DEFAULT
- delay(5);
-
- // Set analog parameters.
- write_reg(SSD2119_REG_SLEEP_MODE_2, 0x0999);
- delay(5);
- write_reg(SSD2119_REG_ANALOG_SET, 0x3800);
- delay(5);
-
- // Enable the display.
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0033);
- delay(5);
-
- // Set VCIX2 voltage to 6.1V.
- write_reg(SSD2119_REG_PWR_CTRL_2, 0x0005);
- delay(5);
-
- // Configure gamma correction.
- write_reg(SSD2119_REG_GAMMA_CTRL_1, 0x0000);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_2, 0x0303);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_3, 0x0407);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_4, 0x0301);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_5, 0x0301);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_6, 0x0403);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_7, 0x0707);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_8, 0x0400);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_9, 0x0a00);
- delay(5);
- write_reg(SSD2119_REG_GAMMA_CTRL_10, 0x1000);
- delay(5);
-
- // Configure Vlcd63 and VCOMl.
- write_reg(SSD2119_REG_PWR_CTRL_3, 0x000A);
- delay(5);
- write_reg(SSD2119_REG_PWR_CTRL_4, 0x2E00);
- delay(5);
-
- // Set the display size and ensure that the GRAM window is set to allow access to the full display buffer.
- write_reg(SSD2119_REG_V_RAM_POS, (GDISP_SCREEN_HEIGHT - 1) << 8);
- delay(5);
- write_reg(SSD2119_REG_H_RAM_START, 0x0000);
- delay(5);
- write_reg(SSD2119_REG_H_RAM_END, GDISP_SCREEN_WIDTH - 1);
- delay(5);
-
- write_reg(SSD2119_REG_X_RAM_ADDR, 0x00);
- delay(5);
- write_reg(SSD2119_REG_Y_RAM_ADDR, 0x00);
- delay(5);
-
- // Release the bus
- release_bus();
-
- /* Turn on the backlight */
- set_backlight(GDISP_INITIAL_BACKLIGHT);
-
- /* Initialise the GDISP structure */
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = GDISP_INITIAL_BACKLIGHT;
- GDISP.Contrast = GDISP_INITIAL_CONTRAST;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- acquire_bus();
- set_cursor(x, y);
- write_reg(SSD2119_REG_RAM_DATA, color);
- release_bus();
-}
-
-/* ---- 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 area;
-
- area = GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT;
-
- acquire_bus();
- reset_viewport();
- set_cursor(0, 0);
- stream_start();
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, &color);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area / 65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area % 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- uint32_t index;
- for(index = 0; index < area; index++)
- write_data(color);
- #endif // defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
-
- stream_stop();
- release_bus();
- }
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- unsigned area;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- area = cx*cy;
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, &color);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area / 65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area % 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- uint32_t index;
- for(index = 0; index < area; index++)
- write_data(color);
- #endif // defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
-
- stream_stop();
- release_bus();
- }
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- buffer += srcx + srcy * srccx;
-
- acquire_bus();
- set_viewport(x, y, cx, cy);
- stream_start();
-
- #if defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- uint32_t area = cx * cy;
- uint8_t i;
- dmaStreamSetPeripheral(GDISP_DMA_STREAM, buffer);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PINC | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- for (i = area / 65535; i; i--) {
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- }
- dmaStreamSetTransactionSize(GDISP_DMA_STREAM, area % 65535);
- dmaStreamEnable(GDISP_DMA_STREAM);
- dmaWaitCompletion(GDISP_DMA_STREAM);
- #else
- coord_t endx, endy;
- uint32_t lg;
- endx = srcx + cx;
- endy = y + cy;
- lg = srccx - cx;
- for(; y < endy; y++, buffer += lg)
- for(x=srcx; x < endx; x++)
- write_data(*buffer++);
- #endif // defined(GDISP_USE_FSMC) && defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
-
- stream_stop();
- release_bus();
- }
-#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 pixel to be read
- *
- * @notapi
- */
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
- #endif
-
- acquire_bus();
- set_cursor(x, y);
- stream_start();
-
- color = read_data(); // dummy read
- color = read_data();
-
- stream_stop();
- release_bus();
-
- 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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
- coord_t row0, row1;
- unsigned i, gap, abslines, j;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- abslines = lines < 0 ? -lines : lines;
-
- acquire_bus();
- if ((coord_t)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*/
- set_viewport(x, row0, cx, 1);
- stream_start();
-
- j = read_data(); // dummy read
- for (j = 0; (coord_t)j < cx; j++)
- buf[j] = read_data();
-
- stream_stop();
-
- set_viewport(x, row1, cx, 1);
- stream_start();
- for (j = 0; (coord_t)j < cx; j++)
- write_data(buf[j]);
- stream_stop();
- }
- }
-
- /* fill the remaining gap */
- set_viewport(x, lines > 0 ? (y+(coord_t)gap) : y, cx, abslines);
- stream_start();
- gap = cx*abslines;
- for(i = 0; i < gap; i++) write_data(bgcolor);
- stream_stop();
- release_bus();
- }
-#endif
-
-#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
- /**
- * @brief Driver Control
- * @details 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.
- *
- * @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:
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
- write_reg(SSD2119_REG_OSC_START, 0x0000); // Turn off oscillator
- release_bus();
- set_backlight(0);
- break;
-
- case powerOn:
- if (GDISP.Powermode == powerSleep) {
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0033); // Display on
- release_bus();
- delayms(170);
- } else if (GDISP.Powermode == powerDeepSleep) {
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_2, 0x0999); // Disable deep sleep function
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0033); // Display on
- release_bus();
- delayms(170);
- } else {
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
- release_bus();
- gdisp_lld_init();
- }
- set_backlight(100);
- break;
-
- case powerSleep:
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
- release_bus();
- set_backlight(0);
- delayms(25);
- break;
-
- case powerDeepSleep:
- acquire_bus();
- write_reg(SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
- write_reg(SSD2119_REG_SLEEP_MODE_2, 0x2999); // Enable deep sleep function
- write_reg(SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
- release_bus();
- set_backlight(0);
- delayms(25);
- 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 GDISP_ROTATE_0:
- acquire_bus();
- /* TB = 0 */
- write_reg(SSD2119_REG_OUTPUT_CTRL, 0x30EF);
- /* ID = 11 AM = 0 */
- write_reg(SSD2119_REG_ENTRY_MODE, 0x6830);
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_90:
- acquire_bus();
- /* TB = 1 */
- write_reg(SSD2119_REG_OUTPUT_CTRL, 0x32EF);
- /* ID = 10 AM = 1 */
- write_reg(SSD2119_REG_ENTRY_MODE, 0x6828);
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- case GDISP_ROTATE_180:
- acquire_bus();
- /* TB = 0 */
- write_reg(SSD2119_REG_OUTPUT_CTRL, 0x30EF);
- /* ID = 00 AM = 0 */
- write_reg(SSD2119_REG_ENTRY_MODE, 0x6800);
- release_bus();
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- break;
-
- case GDISP_ROTATE_270:
- acquire_bus();
- /* TB = 1 */
- write_reg(SSD2119_REG_OUTPUT_CTRL, 0x32EF);
- /* ID = 01 AM = 1 */
- write_reg(SSD2119_REG_ENTRY_MODE, 0x6818);
- release_bus();
- GDISP.Height = GDISP_SCREEN_WIDTH;
- GDISP.Width = GDISP_SCREEN_HEIGHT;
- break;
-
- default:
- return;
- }
-
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-
- case GDISP_CONTROL_BACKLIGHT:
- if ((unsigned)value > 100)
- value = (void *)100;
- set_backlight((unsigned)value);
- GDISP.Backlight = (unsigned)value;
- return;
-
- default:
- return;
- }
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld.mk b/drivers/gdisp/SSD2119/gdisp_lld.mk
index e9c70efb..921eaa2c 100644
--- a/drivers/gdisp/SSD2119/gdisp_lld.mk
+++ b/drivers/gdisp/SSD2119/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/SSD2119/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/SSD2119
+GFXSRC += $(GFXLIB)/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c
diff --git a/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c b/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c
new file mode 100644
index 00000000..9594ff95
--- /dev/null
+++ b/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c
@@ -0,0 +1,411 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/SSD2119/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the SSD2119 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_SSD2119
+#include "../drivers/gdisp/SSD2119/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_SSD2119.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 240
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 320
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+#include "ssd2119.h"
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; }
+#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
+
+static void set_cursor(GDisplay* g) {
+ /* Reg SSD2119_REG_X_RAM_ADDR is 9 bit value
+ * Reg SSD2119_REG_Y_RAM_ADDR is an 8 bit
+ * Use a bit mask to make sure they are not set too high
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, SSD2119_REG_X_RAM_ADDR, g->p.x & 0x01FF);
+ write_reg(g, SSD2119_REG_Y_RAM_ADDR, g->p.y & 0x00FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, SSD2119_REG_X_RAM_ADDR, g->p.y & 0x01FF);
+ write_reg(g, SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT-1 - g->p.x) & 0x00FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH-1 - g->p.x) & 0x01FF);
+ write_reg(g, SSD2119_REG_Y_RAM_ADDR, (GDISP_SCREEN_HEIGHT-1 - g->p.y) & 0x00FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, SSD2119_REG_X_RAM_ADDR, (GDISP_SCREEN_WIDTH-1 - g->p.y) & 0x01FF);
+ write_reg(g, SSD2119_REG_Y_RAM_ADDR, g->p.x & 0x00FF);
+ break;
+ }
+ write_index(g, SSD2119_REG_RAM_DATA);
+}
+
+static void set_viewport(GDisplay* g) {
+ /* Reg 0x44 - Vertical RAM address position
+ * Upper Byte - VEA
+ * Lower Byte - VSA
+ * 0 <= VSA <= VEA <= 0xEF
+ * Reg 0x45,0x46 - Horizontal RAM address position
+ * Lower 9 bits gives 0-511 range in each value, HSA and HEA respectively
+ * 0 <= HSA <= HEA <= 0x13F
+ */
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ write_reg(g, SSD2119_REG_V_RAM_POS, (((g->p.y + g->p.cy - 1) << 8) & 0xFF00 ) | (g->p.y & 0x00FF));
+ write_reg(g, SSD2119_REG_H_RAM_START, (g->p.x & 0x01FF));
+ write_reg(g, SSD2119_REG_H_RAM_END, (g->p.x + g->p.cx - 1) & 0x01FF);
+ break;
+ case GDISP_ROTATE_90:
+ write_reg(g, SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT-1 - g->p.x) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (g->p.x + g->p.cx)) & 0x00FF));
+ write_reg(g, SSD2119_REG_H_RAM_START, (g->p.y & 0x01FF));
+ write_reg(g, SSD2119_REG_H_RAM_END, (g->p.y + g->p.cy - 1) & 0x01FF);
+ break;
+ case GDISP_ROTATE_180:
+ write_reg(g, SSD2119_REG_V_RAM_POS, (((GDISP_SCREEN_HEIGHT-1 - g->p.y) & 0x00FF) << 8) | ((GDISP_SCREEN_HEIGHT - (g->p.y + g->p.cy)) & 0x00FF));
+ write_reg(g, SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (g->p.x + g->p.cx)) & 0x01FF);
+ write_reg(g, SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH-1 - g->p.x) & 0x01FF);
+ break;
+ case GDISP_ROTATE_270:
+ write_reg(g, SSD2119_REG_V_RAM_POS, (((g->p.x + g->p.cx - 1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF));
+ write_reg(g, SSD2119_REG_H_RAM_START, (GDISP_SCREEN_WIDTH - (g->p.y + g->p.cy)) & 0x01FF);
+ write_reg(g, SSD2119_REG_H_RAM_END, (GDISP_SCREEN_WIDTH-1 - g->p.y) & 0x01FF);
+ break;
+ }
+}
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay* g) {
+ // no private area for this controller
+ g->priv = 0;
+
+ // initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ // Get the bus for the following initialisation commands
+ acquire_bus(g);
+
+ // Enter sleep mode (if we are not already there).
+ write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0001);
+ gfxSleepMicroseconds(5);
+
+ // Set initial power parameters.
+ write_reg(g, SSD2119_REG_PWR_CTRL_5, 0x00B2);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_VCOM_OTP_1, 0x0006);
+ gfxSleepMicroseconds(5);
+
+ // Start the oscillator.
+ write_reg(g, SSD2119_REG_OSC_START, 0x0001);
+ gfxSleepMicroseconds(5);
+
+ // Set pixel format and basic display orientation (scanning direction).
+ write_reg(g, SSD2119_REG_OUTPUT_CTRL, 0x30EF);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_LCD_DRIVE_AC_CTRL, 0x0600);
+ gfxSleepMicroseconds(5);
+
+ // Exit sleep mode.
+ write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0000);
+ gfxSleepMicroseconds(5);
+
+ // Configure pixel color format and MCU interface parameters.
+ write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6830); // ENTRY_MODE_DEFAULT
+ gfxSleepMicroseconds(5);
+
+ // Set analog parameters.
+ write_reg(g, SSD2119_REG_SLEEP_MODE_2, 0x0999);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_ANALOG_SET, 0x3800);
+ gfxSleepMicroseconds(5);
+
+ // Enable the display.
+ write_reg(g, SSD2119_REG_DISPLAY_CTRL, 0x0033);
+ gfxSleepMicroseconds(5);
+
+ // Set VCIX2 voltage to 6.1V.
+ write_reg(g, SSD2119_REG_PWR_CTRL_2, 0x0005);
+ gfxSleepMicroseconds(5);
+
+ // Configure gamma correction.
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_1, 0x0000);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_2, 0x0303);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_3, 0x0407);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_4, 0x0301);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_5, 0x0301);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_6, 0x0403);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_7, 0x0707);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_8, 0x0400);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_9, 0x0a00);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_GAMMA_CTRL_10, 0x1000);
+ gfxSleepMicroseconds(5);
+
+ // Configure Vlcd63 and VCOMl.
+ write_reg(g, SSD2119_REG_PWR_CTRL_3, 0x000A);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_PWR_CTRL_4, 0x2E00);
+ gfxSleepMicroseconds(5);
+
+ // Set the display size and ensure that the GRAM window is set to allow access to the full display buffer.
+ write_reg(g, SSD2119_REG_V_RAM_POS, (GDISP_SCREEN_HEIGHT - 1) << 8);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_H_RAM_START, 0x0000);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_H_RAM_END, GDISP_SCREEN_WIDTH - 1);
+ gfxSleepMicroseconds(5);
+
+ write_reg(g, SSD2119_REG_X_RAM_ADDR, 0x00);
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_Y_RAM_ADDR, 0x00);
+ gfxSleepMicroseconds(5);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Turn on the back-light */
+ set_backlight(g, GDISP_INITIAL_BACKLIGHT);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay* g) {
+ acquire_bus(g);
+ set_viewport(g);
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay* g) {
+ write_data(g, COLOR2NATIVE(g->p.color));
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay* g) {
+ release_bus(g);
+ }
+ LLDSPEC void gdisp_lld_write_pos(GDisplay* g) {
+ set_cursor(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay* g) {
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ setreadmode(g);
+ dummy_read(g);
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay* g) {
+ uint16_t data;
+
+ data = read_data(g);
+ return NATIVE2COLOR(data);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay* g) {
+ setwritemode(g);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA)
+ LLDSPEC void gdisp_lld_fill_area(GDisplay* g) {
+ uint16_t c;
+
+ c = COLOR2NATIVE(g->p.color);
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+ dma_with_noinc(g, &c, g->p.cx * g->p.cy);
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA)
+ #if GDISP_PIXELFORMAT != GDISP_LLD_PIXELFORMAT
+ #error "GDISP: SSD2119: BitBlit is only available in RGB565 pixel format"
+ #endif
+
+ LLDSPEC void gdisp_lld_blit_area(GDisplay* g) {
+ pixel_t* buffer;
+ coord_t ynct;
+
+ buffer = (pixel_t*)g->p.ptr + g->p.x1 + g->p.y1 * g->p.x2;
+
+ acquire_bus(g);
+ set_viewport(g);
+ set_cursor(g);
+
+ if (g->p.x2 == g->p.cx) {
+ dma_with_inc(g, buffer, g->p.cx * g->p.cy);
+ } else {
+ for (ycnt = g->p.cy; ycnt; ycnt--, buffer += g->p.x2)
+ dma_with_inc(g, buffer, g->p.cy);
+ }
+
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
+ write_reg(g, SSD2119_REG_SLEEP_MODE_2, 0x2999); // Enable deep sleep function
+ write_reg(g, SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
+ if ((powermode_t)g->p.ptr == powerOff)
+ write_reg(g, SSD2119_REG_OSC_START, 0x0000); // Turn off oscillator
+ release_bus(g);
+ set_backlight(g, 0);
+ break;
+ case powerSleep:
+ acquire_bus(g);
+ write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0001); // Enter sleep mode
+ write_reg(g, SSD2119_REG_DISPLAY_CTRL, 0x0000); // Display off
+ release_bus(g);
+ set_backlight(g, 0);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ if (g->g.Powermode == powerOff) {
+ write_reg(g, SSD2119_REG_OSC_START, 0x0001); // Start the oscillator
+ gfxSleepMicroseconds(5);
+ write_reg(g, SSD2119_REG_SLEEP_MODE_2, 0x0999); // Disable deep sleep function
+ } else if (g->g.Powermode == powerDeepSleep)
+ write_reg(g, SSD2119_REG_SLEEP_MODE_2, 0x0999); // Disable deep sleep function
+ write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0000); // Leave sleep mode
+ write_reg(g, SSD2119_REG_DISPLAY_CTRL, 0x0033); // Display on
+ release_bus(g);
+ gfxSleepMicroseconds(25);
+ set_backlight(g, g->g.Backlight);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ acquire_bus(g);
+ /* ID = 11 AM = 0 */
+ write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6830);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ acquire_bus(g);
+ /* ID = 01 AM = 1 */
+ write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6818);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_180:
+ acquire_bus(g);
+ /* ID = 00 AM = 0 */
+ write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6800);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_270:
+ acquire_bus(g);
+ /* ID = 10 AM = 1 */
+ write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6828);
+ release_bus(g);
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_BACKLIGHT:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ set_backlight(g, (unsigned)g->p.ptr);
+ g->g.Backlight = (unsigned)g->p.ptr;
+ return;
+
+ //case GDISP_CONTROL_CONTRAST:
+ default:
+ return;
+ }
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld_board_embest_dmstf4bb.h b/drivers/gdisp/SSD2119/gdisp_lld_board_embest_dmstf4bb.h
deleted file mode 100644
index 126cd960..00000000
--- a/drivers/gdisp/SSD2119/gdisp_lld_board_embest_dmstf4bb.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD2119/gdisp_lld_board_embest_dmstf4bb.h
- * @brief GDISP Graphic Driver subsystem board FSMC interface for the SSD2119 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/* This board file uses only FSMC, so don't undefine this. */
-#define GDISP_USE_FSMC
-/* But it is OK to disable DMA use. */
-#define GDISP_USE_DMA
-#define GDISP_DMA_STREAM STM32_DMA2_STREAM6
-
-/* Using FSMC A19 (PE3) as DC */
-#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* DC = 0 */
-#define GDISP_RAM (*((volatile uint16_t *) 0x60100000)) /* DC = 1 */
-
-#define SET_RST palSetPad(GPIOD, 3);
-#define CLR_RST palClearPad(GPIOD, 3);
-
-/*
- * PWM configuration structure. We use timer 4 channel 2 (orange LED on board).
- * The reason for so high clock is that with any lower, onboard coil is squeaking.
- * The major disadvantage of this clock is a lack of linearity between PWM duty
- * cycle width and brightness. In fact only with low preset one sees any change
- * (eg. duty cycle between 1-20). Feel free to adjust this, maybe only my board
- * behaves like this. According to the G5126 datesheet (backlight LED driver)
- * the PWM frequency should be somewhere between 200 Hz to 200 kHz.
- */
-static const PWMConfig pwmcfg = {
- 1000000, /* 1 MHz PWM clock frequency. */
- 100, /* PWM period is 100 cycles. */
- NULL,
- {
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL},
- {PWM_OUTPUT_ACTIVE_HIGH, NULL}
- },
- 0
-};
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
- unsigned char FSMC_Bank;
-
- #ifndef GDISP_USE_FSMC
- #error "This board uses only FSMC, please define GDISP_USE_FSMC"
- #endif
-
- #if defined(STM32F4XX) || defined(STM32F2XX)
- /* STM32F4 FSMC init */
- rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
-
- #if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL))
- gfxExit();
- dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
- dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
- #endif
- #else
- #error "FSMC not implemented for this device"
- #endif
-
- /* Group pins */
- IOBus busD = {GPIOD, (1 << 0) | (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) |
- (1 << 9) | (1 << 10) | (1 << 14) | (1 << 15), 0};
-
- IOBus busE = {GPIOE, (1 << 3) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) |
- (1 << 13) | (1 << 14) | (1 << 15), 0};
-
- /* FSMC is an alternate function 12 (AF12) */
- palSetBusMode(&busD, PAL_MODE_ALTERNATE(12));
- palSetBusMode(&busE, PAL_MODE_ALTERNATE(12));
-
- FSMC_Bank = 0;
- /* FSMC timing register configuration */
- FSMC_Bank1->BTCR[FSMC_Bank + 1] = (FSMC_BTR1_ADDSET_2 | FSMC_BTR1_ADDSET_1) \
- | (FSMC_BTR1_DATAST_2 | FSMC_BTR1_DATAST_1) \
- | FSMC_BTR1_BUSTURN_0;
-
- /* Bank1 NOR/PSRAM control register configuration
- * Write enable, memory databus width set to 16 bit, memory bank enable */
- FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_WREN | FSMC_BCR1_MWID_0 | FSMC_BCR1_MBKEN;
-
- /* Display backlight control */
- /* TIM4 is an alternate function 2 (AF2) */
- pwmStart(&PWMD4, &pwmcfg);
- palSetPadMode(GPIOD, 13, PAL_MODE_ALTERNATE(2));
- pwmEnableChannel(&PWMD4, 1, 100);
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- if (state) {
- CLR_RST;
- } else {
- SET_RST;
- }
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
- pwmEnableChannel(&PWMD4, 1, percent);
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
- GDISP_REG = index;
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
- GDISP_RAM = data;
-}
-
-#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 read_data(void) {
- return GDISP_RAM;
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld_board_template.h b/drivers/gdisp/SSD2119/gdisp_lld_board_template.h
deleted file mode 100644
index 2e4d53df..00000000
--- a/drivers/gdisp/SSD2119/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/SSD2119/gdisp_lld_board_template.h
- * @brief GDISP Graphic Driver subsystem board template for the SSD2119 display.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialise the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- *
- * @notapi
- */
-static inline void init_board(void) {
-
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- *
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- *
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
-
-}
-
-/**
- * @brief Set the lcd back-light level.
- *
- * @param[in] percent 0 to 100%
- *
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void acquire_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @note Not needed, not implemented
- *
- * @notapi
- */
-static inline void release_bus(void) {
- /* Nothing to do here since LCD is the only device on that bus */
-}
-
-/**
- * @brief Send data to the index register.
- *
- * @param[in] index The index register to set
- *
- * @notapi
- */
-static inline void write_index(uint16_t index) {
-
-}
-
-/**
- * @brief Send data to the lcd.
- *
- * @param[in] data The data to send
- *
- * @notapi
- */
-static inline void write_data(uint16_t data) {
-
-}
-
-#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 read_data(void) {
-
-}
-#endif
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
diff --git a/drivers/gdisp/SSD2119/gdisp_lld_config.h b/drivers/gdisp/SSD2119/gdisp_lld_config.h
index 3ad247e6..ec034bef 100644
--- a/drivers/gdisp/SSD2119/gdisp_lld_config.h
+++ b/drivers/gdisp/SSD2119/gdisp_lld_config.h
@@ -22,16 +22,20 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "SSD2119"
-
-#define GDISP_HARDWARE_CLEARS TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD TRUE
+#define GDISP_HARDWARE_STREAM_WRITE TRUE
+#define GDISP_HARDWARE_STREAM_READ TRUE
+#define GDISP_HARDWARE_STREAM_POS TRUE
#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
+#if defined(GDISP_USE_DMA)
+ #define GDISP_HARDWARE_FILLS TRUE
+ #if !defined(GDISP_PIXELFORMAT) || GDISP_PIXELFORMAT == 0x2565
+ // Hardware BitBlts are only supported in native pixel format on this controller
+ #define GDISP_HARDWARE_BITFILLS TRUE
+ #endif
+#endif
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ST7565/board_ST7565_template.h b/drivers/gdisp/ST7565/board_ST7565_template.h
new file mode 100644
index 00000000..aef6cf2b
--- /dev/null
+++ b/drivers/gdisp/ST7565/board_ST7565_template.h
@@ -0,0 +1,108 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ST7565/board_ST7565_template.h
+ * @brief GDISP Graphic Driver subsystem board interface for the ST7565 display.
+ *
+ * @addtogroup GDISP
+ * @{
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+/**
+ * @brief Initialise the board for the display.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @note Set the g->board member to whatever is appropriate. For multiple
+ * displays this might be a pointer to the appropriate register set.
+ *
+ * @notapi
+ */
+static inline void init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief After the initialisation.
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Set or clear the lcd reset pin.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] state TRUE = lcd in reset, FALSE = normal operation
+ *
+ * @notapi
+ */
+static inline void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+/**
+ * @brief Take exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Release exclusive control of the bus
+ *
+ * @param[in] g The GDisplay structure
+ *
+ * @notapi
+ */
+static inline void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+/**
+ * @brief Send a command to the controller.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] cmd The command to send *
+ *
+ * @notapi
+ */
+static inline void write_cmd(GDisplay *g, uint8_t cmd) {
+ (void) g;
+ (void) cmd;
+}
+
+/**
+ * @brief Send data to the lcd.
+ *
+ * @param[in] g The GDisplay structure
+ * @param[in] data The data to send
+ *
+ * @notapi
+ */
+static inline void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
+ (void) g;
+ (void) data;
+ (void) length;
+}
+
+#endif /* _GDISP_LLD_BOARD_H */
+/** @} */
+
diff --git a/drivers/gdisp/ST7565/gdisp_lld.c b/drivers/gdisp/ST7565/gdisp_lld.c
deleted file mode 100644
index f46a166c..00000000
--- a/drivers/gdisp/ST7565/gdisp_lld.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-#include "st7565.h"
-#include "gdisp_lld_board.h"
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#ifndef GDISP_SCREEN_HEIGHT
-#define GDISP_SCREEN_HEIGHT 64
-#endif
-#ifndef GDISP_SCREEN_WIDTH
-#define GDISP_SCREEN_WIDTH 128
-#endif
-
-#define GDISP_INITIAL_CONTRAST 0xFF
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-// Some common routines and macros
-#define delay(us) gfxSleepMicroseconds(us)
-#define delay_ms(ms) gfxSleepMilliseconds(ms)
-
-// The memory buffer for the display
-static uint8_t gdisp_buffer[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8];
-
-/** Set the display to normal or inverse.
- * @param[in] value 0 for normal mode, or 1 for inverse mode.
- * @notapi
- */
-static void invert_display(uint8_t i) {
- write_cmd(i ? ST7565_INVERT_DISPLAY : ST7565_POSITIVE_DISPLAY);
-}
-
-/** Turn the whole display off.
- * Sends the display to sleep, but leaves RAM intact.
- * @notapi
- */
-static void display_off(void) {
- write_cmd(ST7565_DISPLAY_OFF);
-}
-
-/** Turn the whole display on.
- * Wakes up this display following a sleep() call.
- * @notapi
- */
-static void display_on(void) {
- write_cmd(ST7565_DISPLAY_ON);
-}
-
-/** Set the display contrast.
- * @param[in] value The contrast, from 1 to 63.
- * @notapi
- */
-static void set_contrast(uint8_t value) {
- write_cmd(ST7565_CONTRAST);
- write_cmd(value & 0x3F);
-}
-
-/** Set the display start line. This is the line at which the display will start rendering.
- * @param[in] value A value from 0 to 63 denoting the line to start at.
- * @notapi
- */
-static void set_display_start_line(unsigned char value) {
- write_cmd(ST7565_START_LINE | value);
-}
-
-static void gdisp_lld_display(void) {
- uint8_t p;
- set_display_start_line(0);
-
- for (p = 0; p < 8; p++) {
- write_cmd(ST7565_PAGE | p);
- write_cmd(ST7565_COLUMN_MSB | 0);
- write_cmd(ST7565_COLUMN_LSB | 0);
- write_cmd(ST7565_RMW);
- write_data(&gdisp_buffer[p * GDISP_SCREEN_WIDTH], GDISP_SCREEN_WIDTH);
- }
-}
-
-/*===========================================================================*/
-/* 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) {
- // Initialize your display
- init_board();
-
- // Hardware reset.
- setpin_reset(TRUE);
- delay_ms(10);
- setpin_reset(FALSE);
- delay_ms(1);
-
- write_cmd(ST7565_LCD_BIAS_7);
- write_cmd(ST7565_ADC_NORMAL);
- write_cmd(ST7565_COM_SCAN_INC);
- set_display_start_line(0);
-
- set_contrast(32);
- write_cmd(ST7565_RESISTOR_RATIO | 0x3);
-
- // turn on voltage converter (VC=1, VR=0, VF=0)
- write_cmd(ST7565_POWER_CONTROL | 0x04);
- delay_ms(50);
- // turn on voltage regulator (VC=1, VR=1, VF=0)
- write_cmd(ST7565_POWER_CONTROL | 0x06);
- delay_ms(50);
- // turn on voltage follower (VC=1, VR=1, VF=1)
- write_cmd(ST7565_POWER_CONTROL | 0x07);
- delay_ms(50);
-
- display_on();
- write_cmd(ST7565_ALLON_NORMAL);
- invert_display(0);// Disable Inversion of display.
-
- write_cmd(ST7565_RMW);
- gdisp_lld_display();
-
- // Initialize the GDISP structure
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Contrast = 50;
-#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
-#endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
-#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
-#endif
-
- if (color == 1)
- gdisp_buffer[x+ (y/8)*GDISP_SCREEN_WIDTH] |= (1<<y%8);
- else
- gdisp_buffer[x+ (y/8)*GDISP_SCREEN_WIDTH] &= ~(1<<y%8);
-}
-
-/* ---- 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_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__)
-/**
- * @brief Driver Control
- * @details 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:
- display_off();
- break;
- case powerSleep:
- display_off();
- break;
- case powerDeepSleep:
- display_off();
- break;
- case powerOn:
- display_on();
- break;
- default:
- return;
- }
- GDISP.Powermode = (gdisp_powermode_t)value;
- return;
-
- case GDISP_CONTROL_BACKLIGHT:
- set_backlight((uint8_t)(size_t)value);
- return;
-
- case GDISP_CONTROL_CONTRAST:
- if ((unsigned)value > 100) value = (void*)100;
- if (GDISP.Contrast == (uint8_t)((float)((size_t)value) * 63.0/100.0))
- return;
- set_contrast((uint8_t)((float)((size_t)value) * 63.0/100.0) );
- GDISP.Contrast = (unsigned)value;
- return;
-
- case GDISP_CONTROL_LLD_FLUSH:
- gdisp_lld_display();
- return;
- }
-}
-#endif // GDISP_NEED_CONTROL
-
-#endif // GFX_USE_GDISP
-/** @} */
-
diff --git a/drivers/gdisp/ST7565/gdisp_lld.mk b/drivers/gdisp/ST7565/gdisp_lld.mk
index cd925824..9f9c5408 100644
--- a/drivers/gdisp/ST7565/gdisp_lld.mk
+++ b/drivers/gdisp/ST7565/gdisp_lld.mk
@@ -1,6 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/ST7565/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/ST7565
-
+GFXSRC += $(GFXLIB)/drivers/gdisp/ST7565/gdisp_lld_ST7565.c
diff --git a/drivers/gdisp/ST7565/gdisp_lld_ST7565.c b/drivers/gdisp/ST7565/gdisp_lld_ST7565.c
new file mode 100644
index 00000000..2bb5406f
--- /dev/null
+++ b/drivers/gdisp/ST7565/gdisp_lld_ST7565.c
@@ -0,0 +1,262 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/ST7565/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for the ST7565 display.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_ST7565
+#include "../drivers/gdisp/ST7565/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#include "board_ST7565.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 64
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 128
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 51
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
+
+#include "st7565.h"
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define RAM(g) ((uint8_t *)g->priv)
+#define write_cmd2(g, cmd1, cmd2) { write_cmd(g, cmd1); write_cmd(g, cmd2); }
+#define write_cmd3(g, cmd1, cmd2, cmd3) { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); }
+
+// Some common routines and macros
+#define delay(us) gfxSleepMicroseconds(us)
+#define delay_ms(ms) gfxSleepMilliseconds(ms)
+
+#define xyaddr(x, y) ((x) + ((y)>>3)*GDISP_SCREEN_WIDTH)
+#define xybit(y) (1<<((y)&7))
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * As this controller can't update on a pixel boundary we need to maintain the
+ * the entire display surface in memory so that we can do the necessary bit
+ * operations. Fortunately it is a small display in monochrome.
+ * 64 * 128 / 8 = 1024 bytes.
+ */
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // The private area is the display surface.
+ g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8);
+
+ // Initialise the board interface
+ init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(20);
+
+ acquire_bus(g);
+
+ write_cmd(g, ST7565_LCD_BIAS_7);
+ write_cmd(g, ST7565_ADC_NORMAL);
+ write_cmd(g, ST7565_COM_SCAN_INC);
+ write_cmd(g, ST7565_START_LINE | 0);
+
+ write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101);
+ write_cmd(g, ST7565_RESISTOR_RATIO | 0x3);
+
+ // turn on voltage converter (VC=1, VR=0, VF=0)
+ write_cmd(g, ST7565_POWER_CONTROL | 0x04);
+ delay_ms(50);
+
+ // turn on voltage regulator (VC=1, VR=1, VF=0)
+ write_cmd(g, ST7565_POWER_CONTROL | 0x06);
+ delay_ms(50);
+
+ // turn on voltage follower (VC=1, VR=1, VF=1)
+ write_cmd(g, ST7565_POWER_CONTROL | 0x07);
+ delay_ms(50);
+
+ write_cmd(g, ST7565_DISPLAY_ON);
+ write_cmd(g, ST7565_ALLON_NORMAL);
+ write_cmd(g, ST7565_POSITIVE_DISPLAY); // Disable Inversion of display.
+
+ write_cmd(g, ST7565_RMW);
+
+ // Finish Init
+ post_init_board(g);
+
+ // Release the bus
+ release_bus(g);
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_FLUSH
+ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+ unsigned p;
+
+ // Don't flush if we don't need it.
+ if (!(g->flags & GDISP_FLG_NEEDFLUSH))
+ return;
+
+ acquire_bus(g);
+ for (p = 0; p < 8; p++) {
+ write_cmd(g, ST7565_PAGE | p);
+ write_cmd(g, ST7565_COLUMN_MSB | 0);
+ write_cmd(g, ST7565_COLUMN_LSB | 0);
+ write_cmd(g, ST7565_RMW);
+ write_data(g, RAM(g) + (p*GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH);
+ }
+ release_bus(g);
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+ coord_t x, y;
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ y = g->p.x;
+ break;
+ }
+ if (COLOR2NATIVE(g->p.color) != Black)
+ RAM(g)[xyaddr(x, y)] |= xybit(y);
+ else
+ RAM(g)[xyaddr(x, y)] &= ~xybit(y);
+ g->flags |= GDISP_FLG_NEEDFLUSH;
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ coord_t x, y;
+
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ x = g->p.x;
+ break;
+ }
+ return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black;
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerSleep:
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_cmd(g, ST7565_DISPLAY_OFF);
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_cmd(g, ST7565_DISPLAY_ON);
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ /* Rotation is handled by the drawing routines */
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_CONTRAST:
+ if ((unsigned)g->p.ptr > 100)
+ g->p.ptr = (void *)100;
+ acquire_bus(g);
+ write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F);
+ release_bus(g);
+ g->g.Contrast = (unsigned)g->p.ptr;
+ return;
+ }
+ }
+#endif // GDISP_NEED_CONTROL
+
+#endif // GFX_USE_GDISP
diff --git a/drivers/gdisp/ST7565/gdisp_lld_board_template.h b/drivers/gdisp/ST7565/gdisp_lld_board_template.h
deleted file mode 100644
index 2f40ccc7..00000000
--- a/drivers/gdisp/ST7565/gdisp_lld_board_template.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-#ifndef _GDISP_LLD_BOARD_H
-#define _GDISP_LLD_BOARD_H
-
-/**
- * @brief Initialize the board for the display.
- * @notes This board definition uses GPIO and assumes exclusive access to these GPIO pins
- * @notapi
- */
-static inline void init_board(void) {
- /* Configure SPI bus here. Up to 10Mhz, SPI Mode = 3 (CPOL = 1, CPHA = 0) */
- /* Configure A0, !CS, !RST pin for output */
-}
-
-/**
- * @brief Set or clear the lcd reset pin.
- * @param[in] state TRUE = lcd in reset, FALSE = normal operation
- * @notapi
- */
-static inline void setpin_reset(bool_t state) {
- /* Set !CS to low */
- if (state) {
- /* Set !RST to low */
- } else {
- /* Set !RST to high */
- }
-}
-
-/**
- * @brief Set the lcd back-light level.
- * @param[in] percent 0 to 100%
- * @notapi
- */
-static inline void set_backlight(uint8_t percent) {
-
-}
-
-/**
- * @brief Take exclusive control of the bus
- * @notapi
- */
-static inline void acquire_bus(void) {
-
-}
-
-/**
- * @brief Release exclusive control of the bus
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Send command to the display.
- * @param[in] cmd The command to send
- * @notapi
- */
-static inline void write_cmd(uint8_t cmd) {
- /* Set A0 to low */
- /* Transmit cmd over SPI */
-}
-
-/**
- * @brief Send data to the display.
- * @param[in] data The data to send
- * @notapi
- */
-static inline void write_data(uint8_t* data, uint16_t length) {
- /* Set A0 to high */
- /* Transmit data for length over SPI. DMA is recommended. */
-}
-
-#endif /* _GDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/gdisp/ST7565/gdisp_lld_config.h b/drivers/gdisp/ST7565/gdisp_lld_config.h
index 8d26a0aa..f774e8fa 100644
--- a/drivers/gdisp/ST7565/gdisp_lld_config.h
+++ b/drivers/gdisp/ST7565/gdisp_lld_config.h
@@ -14,13 +14,12 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "ST7565"
+#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
+#define GDISP_HARDWARE_PIXELREAD TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_MONO
-
-#define GDISP_CONTROL_LLD_FLUSH (GDISP_CONTROL_LLD + 1)
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO
#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/ST7565/st7565.h b/drivers/gdisp/ST7565/st7565.h
index b1f43f6b..9542dd3f 100644
--- a/drivers/gdisp/ST7565/st7565.h
+++ b/drivers/gdisp/ST7565/st7565.h
@@ -8,9 +8,6 @@
#ifndef _ST7565_H
#define _ST7565_H
-#define ST7565_BLACK 0
-#define ST7565_WHITE 1
-
#define ST7565_CONTRAST 0x81
#define ST7565_ALLON_NORMAL 0xA4
#define ST7565_ALLON 0xA5
diff --git a/drivers/gdisp/TestStub/gdisp_lld.c b/drivers/gdisp/TestStub/gdisp_lld.c
deleted file mode 100644
index e5167989..00000000
--- a/drivers/gdisp/TestStub/gdisp_lld.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/gdisp/TestStub/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source (stub).
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 128
-#endif
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 128
-#endif
-
-/* ---- 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 = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOff;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- (void)x;
- (void)y;
- (void)color;
-}
-
-/* ---- Optional Routines ---- */
-
-#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_get_pixel_color(coord_t x, coord_t y) {
- (void)x;
- (void)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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- (void)x;
- (void)y;
- (void)cx;
- (void)cy;
- (void)lines;
- (void)bgcolor;
- }
-#endif
-
-#endif /* GFX_USE_GDISP */
-/** @} */
diff --git a/drivers/gdisp/TestStub/gdisp_lld.mk b/drivers/gdisp/TestStub/gdisp_lld.mk
index 5f35be9d..d8faa3e9 100644
--- a/drivers/gdisp/TestStub/gdisp_lld.mk
+++ b/drivers/gdisp/TestStub/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/gdisp/TestStub/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/gdisp/TestStub
+GFXSRC += $(GFXLIB)/drivers/gdisp/TestStub/gdisp_lld_TestStub.c
diff --git a/drivers/gdisp/TestStub/gdisp_lld_TestStub.c b/drivers/gdisp/TestStub/gdisp_lld_TestStub.c
new file mode 100644
index 00000000..1a5ad81f
--- /dev/null
+++ b/drivers/gdisp/TestStub/gdisp_lld_TestStub.c
@@ -0,0 +1,61 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/gdisp/TestStub/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source (stub).
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
+
+#define GDISP_DRIVER_VMT GDISPVMT_TestStub
+#include "../drivers/gdisp/TestStub/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 128
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 128
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 50
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ /* No board interface and no private driver area */
+ g->priv = g->board = 0;
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ void gdisp_lld_draw_pixel(GDisplay *g) {
+ (void) g;
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ (void) g;
+ return 0;
+ }
+#endif
+
+#endif /* GFX_USE_GDISP */
diff --git a/drivers/gdisp/TestStub/gdisp_lld_config.h b/drivers/gdisp/TestStub/gdisp_lld_config.h
index 38c55992..63471c6c 100644
--- a/drivers/gdisp/TestStub/gdisp_lld_config.h
+++ b/drivers/gdisp/TestStub/gdisp_lld_config.h
@@ -22,14 +22,10 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "TestStub"
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
+#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_HARDWARE_SCROLL GDISP_NEED_SCROLL
-#define GDISP_HARDWARE_PIXELREAD GDISP_NEED_PIXELREAD
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
-#define GDISP_PACKED_PIXELS FALSE
-#define GDISP_PACKED_LINES FALSE
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565
#endif /* GFX_USE_GDISP */
diff --git a/drivers/ginput/dial/GADC/ginput_lld_dial_board_olimexsam7ex256.h b/drivers/ginput/dial/GADC/ginput_lld_dial_board_template.h
index 09ca3dc0..202b5386 100644
--- a/drivers/ginput/dial/GADC/ginput_lld_dial_board_olimexsam7ex256.h
+++ b/drivers/ginput/dial/GADC/ginput_lld_dial_board_template.h
@@ -6,7 +6,7 @@
*/
/**
- * @file drivers/ginput/dial/GADC/ginput_lld_dial_board_olimexsam7ex256.h
+ * @file drivers/ginput/dial/GADC/ginput_lld_dial_board_template.h
* @brief GINPUT Dial Driver config file.
*
* @defgroup Dial Dial
@@ -14,8 +14,8 @@
* @{
*/
-#ifndef _GINPUT_LLD_DIAL_BOARD_OLIMEXSAM7EX256_H
-#define _GINPUT_LLD_DIAL_BOARD_OLIMEXSAM7EX256_H
+#ifndef _GINPUT_LLD_DIAL_BOARD_H
+#define _GINPUT_LLD_DIAL_BOARD_H
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL
@@ -23,6 +23,7 @@
/* Analogue devices on this board */
/*===========================================================================*/
+/* Example values */
#define GINPUT_DIAL_NUM_PORTS 1
#define GINPUT_DIAL_DEVICE0 GADC_PHYSDEV_DIAL
#define GINPUT_DIAL_POLL_PERIOD 200
@@ -30,6 +31,6 @@
#endif /* GFX_USE_GINPUT && GINPUT_NEED_DIAL */
-#endif /* _GINPUT_LLD_DIAL_BOARD_OLIMEXSAM7EX256_H */
+#endif /* _GINPUT_LLD_DIAL_BOARD_H */
/** @} */
diff --git a/drivers/ginput/dial/GADC/ginput_lld_dial_config.h b/drivers/ginput/dial/GADC/ginput_lld_dial_config.h
index 3dc7bfca..3e54b4ca 100644
--- a/drivers/ginput/dial/GADC/ginput_lld_dial_config.h
+++ b/drivers/ginput/dial/GADC/ginput_lld_dial_config.h
@@ -21,15 +21,8 @@
#define GINPUT_DIAL_MAX_VALUE ((1<<GADC_BITS_PER_SAMPLE)-1)
-#if GINPUT_TOGGLE_USE_CUSTOM_BOARD
- /* Include the user supplied board definitions */
- #include "ginput_lld_dial_board.h"
-#elif defined(BOARD_OLIMEX_SAM7_EX256)
- #include "ginput_lld_dial_board_olimexsam7ex256.h"
-#else
- /* Include the user supplied board definitions */
- #include "ginput_lld_dial_board.h"
-#endif
+/* Include the user supplied board definitions */
+#include "ginput_lld_dial_board.h"
#endif /* GFX_USE_GDISP && GINPUT_NEED_DIAL */
diff --git a/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_olimexsam7ex256.h b/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_olimexsam7ex256.h
deleted file mode 100644
index 5861b6f5..00000000
--- a/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_olimexsam7ex256.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/toggle/Pal/ginput_lld_toggle_board_olimexsam7ex256.h
- * @brief GINPUT Toggle low level driver source for the ChibiOS PAL hardware on the Olimex SAM7EX256 board.
- *
- * @defgroup Toggle Toggle
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GDISP_LLD_TOGGLE_BOARD_H
-#define _GDISP_LLD_TOGGLE_BOARD_H
-
-#define GINPUT_TOGGLE_NUM_PORTS 7 // The total number of toggle inputs
-#define GINPUT_TOGGLE_CONFIG_ENTRIES 2 // The total number of GToggleConfig entries
-
-#define GINPUT_TOGGLE_SW1 0 // Switch 1
-#define GINPUT_TOGGLE_SW2 1 // Switch 2
-#define GINPUT_TOGGLE_LEFT 2 // Joystick Left
-#define GINPUT_TOGGLE_DOWN 3 // Joystick Down
-#define GINPUT_TOGGLE_UP 4 // Joystick Up
-#define GINPUT_TOGGLE_RIGHT 5 // Joystick Right
-#define GINPUT_TOGGLE_CENTER 6 // Joystick Center
-
-#define GINPUT_TOGGLE_DECLARE_STRUCTURE() \
- const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = { \
- {AT91C_BASE_PIOB, /* Switch 1 and Switch 2 */ \
- PIOB_SW1_MASK|PIOB_SW2_MASK, \
- PIOB_SW1_MASK|PIOB_SW2_MASK, \
- PAL_MODE_INPUT}, \
- {AT91C_BASE_PIOA, /* B1..4 Joystick */ \
- PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
- PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
- PAL_MODE_INPUT}, \
- }
-
-#endif /* _GDISP_LLD_TOGGLE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_example.h b/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_template.h
index e0a501df..84038d16 100644
--- a/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_example.h
+++ b/drivers/ginput/toggle/Pal/ginput_lld_toggle_board_template.h
@@ -4,45 +4,45 @@
*
* http://ugfx.org/license.html
*/
-
-/**
- * @file drivers/ginput/toggle/Pal/ginput_lld_toggle_board_example.h
- * @brief GINPUT Toggle low level driver source for the ChibiOS PAL hardware on the example board.
- *
- * @defgroup Toggle Toggle
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GDISP_LLD_TOGGLE_BOARD_H
-#define _GDISP_LLD_TOGGLE_BOARD_H
-
-#error "GINPUT Toggle Pal Driver: You need to define your board definitions"
-
-// The below are example values
-
-#define GINPUT_TOGGLE_NUM_PORTS 7 // The total number of toggle inputs
-#define GINPUT_TOGGLE_CONFIG_ENTRIES 2 // The total number of GToggleConfig entries
-
-#define GINPUT_TOGGLE_SW1 0 // Switch 1
-#define GINPUT_TOGGLE_SW2 1 // Switch 2
-#define GINPUT_TOGGLE_UP 2 // Joystick Up
-#define GINPUT_TOGGLE_DOWN 3 // Joystick Down
-#define GINPUT_TOGGLE_LEFT 4 // Joystick Left
-#define GINPUT_TOGGLE_RIGHT 5 // Joystick Right
-#define GINPUT_TOGGLE_CENTER 6 // Joystick Center
-
-#define GINPUT_TOGGLE_DECLARE_STRUCTURE() \
- const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = { \
- {AT91C_BASE_PIOB, /* Switch 1 and Switch 2 */ \
- PIOB_SW1_MASK|PIOB_SW2_MASK, \
- PIOB_SW1_MASK|PIOB_SW2_MASK, \
- PAL_MODE_INPUT}, \
- {AT91C_BASE_PIOA, /* B1..4 Joystick */ \
- PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
- PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
- PAL_MODE_INPUT}, \
- }
-
-#endif /* _GDISP_LLD_TOGGLE_BOARD_H */
-/** @} */
+
+/**
+ * @file drivers/ginput/toggle/Pal/ginput_lld_toggle_board_template.h
+ * @brief GINPUT Toggle low level driver source for the ChibiOS PAL hardware on the example board.
+ *
+ * @defgroup Toggle Toggle
+ * @ingroup GINPUT
+ * @{
+ */
+
+#ifndef _GDISP_LLD_TOGGLE_BOARD_H
+#define _GDISP_LLD_TOGGLE_BOARD_H
+
+#error "GINPUT Toggle Pal Driver: You need to define your board definitions"
+
+// The below are example values
+
+#define GINPUT_TOGGLE_NUM_PORTS 7 // The total number of toggle inputs
+#define GINPUT_TOGGLE_CONFIG_ENTRIES 2 // The total number of GToggleConfig entries
+
+#define GINPUT_TOGGLE_SW1 0 // Switch 1
+#define GINPUT_TOGGLE_SW2 1 // Switch 2
+#define GINPUT_TOGGLE_UP 2 // Joystick Up
+#define GINPUT_TOGGLE_DOWN 3 // Joystick Down
+#define GINPUT_TOGGLE_LEFT 4 // Joystick Left
+#define GINPUT_TOGGLE_RIGHT 5 // Joystick Right
+#define GINPUT_TOGGLE_CENTER 6 // Joystick Center
+
+#define GINPUT_TOGGLE_DECLARE_STRUCTURE() \
+ const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = { \
+ {AT91C_BASE_PIOB, /* Switch 1 and Switch 2 */ \
+ PIOB_SW1_MASK|PIOB_SW2_MASK, \
+ PIOB_SW1_MASK|PIOB_SW2_MASK, \
+ PAL_MODE_INPUT}, \
+ {AT91C_BASE_PIOA, /* B1..4 Joystick */ \
+ PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
+ PIOA_B1_MASK|PIOA_B2_MASK|PIOA_B3_MASK|PIOA_B4_MASK|PIOA_B5_MASK, \
+ PAL_MODE_INPUT}, \
+ }
+
+#endif /* _GDISP_LLD_TOGGLE_BOARD_H */
+/** @} */
diff --git a/drivers/ginput/toggle/Pal/ginput_lld_toggle_config.h b/drivers/ginput/toggle/Pal/ginput_lld_toggle_config.h
index e2bff490..84155956 100644
--- a/drivers/ginput/toggle/Pal/ginput_lld_toggle_config.h
+++ b/drivers/ginput/toggle/Pal/ginput_lld_toggle_config.h
@@ -19,15 +19,8 @@
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
-#if GINPUT_TOGGLE_USE_CUSTOM_BOARD
- /* Include the user supplied board definitions */
- #include "ginput_lld_toggle_board.h"
-#elif defined(BOARD_OLIMEX_SAM7_EX256)
- #include "ginput_lld_toggle_board_olimexsam7ex256.h"
-#else
- /* Include the user supplied board definitions */
- #include "ginput_lld_toggle_board.h"
-#endif
+/* Include the user supplied board definitions */
+#include "ginput_lld_toggle_board.h"
#endif /* GFX_USE_GDISP && GINPUT_NEED_TOGGLE */
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_firebull_stm32f103.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_firebull_stm32f103.h
deleted file mode 100644
index ebcc26c7..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_firebull_stm32f103.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_firebull_stm32f103.h
- * @brief GINPUT ouch low level driver source for the ADS7843 on the FireBull STM32F103-FB board.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-static const SPIConfig spicfg = {
- NULL,
- GPIOC,
- 6,
- /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static inline void init_board(void) {
- spiStart(&SPID1, &spicfg);
-}
-
-/**
- * @brief Check whether the surface is currently touched
- * @return TRUE if the surface is currently touched
- *
- * @notapi
- */
-static inline bool_t getpin_pressed(void) {
- return (!palReadPad(GPIOC, 4));
-}
-/**
- * @brief Aquire the bus ready for readings
- *
- * @notapi
- */
-static inline void aquire_bus(void) {
- spiAcquireBus(&SPID1);
- //TOUCHSCREEN_SPI_PROLOGUE();
- palClearPad(GPIOC, 6);
-}
-
-/**
- * @brief Release the bus after readings
- *
- * @notapi
- */
-static inline void release_bus(void) {
- palSetPad(GPIOC, 6);
- spiReleaseBus(&SPID1);
- //TOUCHSCREEN_SPI_EPILOGUE();
-}
-
-/**
- * @brief Read a value from touch controller
- * @return The value read from the controller
- *
- * params[in] port The controller port to read.
- *
- * @notapi
- */
-static inline uint16_t read_value(uint16_t port) {
- static uint8_t txbuf[3] = {0};
- static uint8_t rxbuf[3] = {0};
- uint16_t ret;
-
- txbuf[0] = port;
-
- spiExchange(&SPID1, 3, txbuf, rxbuf);
-
- ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3);
-
- return ret;
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h
deleted file mode 100644
index 01572f0d..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h
- * @brief GINPUT Touch low level driver source for the ADS7843 on an Olimex STM32E407.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-static const SPIConfig spicfg = {
- NULL,
- GPIOG,
- 10,
- /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static inline void init_board(void) {
- spiStart(&SPID2, &spicfg);
-}
-
-/**
- * @brief Check whether the surface is currently touched
- * @return TRUE if the surface is currently touched
- *
- * @notapi
- */
-static inline bool_t getpin_pressed(void) {
- return (!palReadPad(GPIOG, 0));
-}
-/**
- * @brief Aquire the bus ready for readings
- *
- * @notapi
- */
-static inline void aquire_bus(void) {
- spiAcquireBus(&SPID2);
- //TOUCHSCREEN_SPI_PROLOGUE();
- palClearPad(GPIOG, 10);
-}
-
-/**
- * @brief Release the bus after readings
- *
- * @notapi
- */
-static inline void release_bus(void) {
- palSetPad(GPIOG, 10);
- spiReleaseBus(&SPID2);
- //TOUCHSCREEN_SPI_EPILOGUE();
-}
-
-/**
- * @brief Read a value from touch controller
- * @return The value read from the controller
- *
- * params[in] port The controller port to read.
- *
- * @notapi
- */
-static inline uint16_t read_value(uint16_t port) {
- static uint8_t txbuf[3] = {0};
- static uint8_t rxbuf[3] = {0};
- uint16_t ret;
-
- txbuf[0] = port;
-
- spiExchange(&SPID2, 3, txbuf, rxbuf);
-
- ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3);
-
- return ret;
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h
deleted file mode 100644
index 158934b6..00000000
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h
- * @brief GINPUT Touch low level driver source for the ADS7843 on an Olimex STM32E407.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-static const SPIConfig spicfg = {
- NULL,
- GPIOC,
- 4,
- /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static inline void init_board(void) {
- spiStart(&SPID2, &spicfg);
-}
-
-/**
- * @brief Check whether the surface is currently touched
- * @return TRUE if the surface is currently touched
- *
- * @notapi
- */
-static inline bool_t getpin_pressed(void) {
- return (!palReadPad(GPIOC, 5));
-}
-/**
- * @brief Aquire the bus ready for readings
- *
- * @notapi
- */
-static inline void aquire_bus(void) {
- spiAcquireBus(&SPID2);
- //TOUCHSCREEN_SPI_PROLOGUE();
- palClearPad(GPIOC, 4);
-}
-
-/**
- * @brief Release the bus after readings
- *
- * @notapi
- */
-static inline void release_bus(void) {
- palSetPad(GPIOC, 4);
- spiReleaseBus(&SPID2);
- //TOUCHSCREEN_SPI_EPILOGUE();
-}
-
-/**
- * @brief Read a value from touch controller
- * @return The value read from the controller
- *
- * params[in] port The controller port to read.
- *
- * @notapi
- */
-static inline uint16_t read_value(uint16_t port) {
- static uint8_t txbuf[3] = {0};
- static uint8_t rxbuf[3] = {0};
- uint16_t ret;
-
- txbuf[0] = port;
-
- spiExchange(&SPID2, 3, txbuf, rxbuf);
-
- ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3);
-
- return ret;
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h
deleted file mode 100644
index e3e18c24..00000000
--- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h
- * @brief GINPUT Touch low level driver source for the FT5x06.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-/* I2C interface #2 - Touchscreen controller */
-static const I2CConfig i2ccfg2 = {
- OPMODE_I2C,
- 400000,
- FAST_DUTY_CYCLE_2,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static void init_board(void) {
-
-}
-
-
-/**
- * @brief Write a value into a certain register
- *
- * @param[in] reg The register address
- * @param[in] n The amount of bytes (one or two)
- * @param[in] val The value
- *
- * @notapi
- */
-static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {
- uint8_t txbuf[3];
-
- i2cAcquireBus(&I2CD2);
-
- txbuf[0] = reg;
-
- if (n == 1) {
- txbuf[1] = val;
- i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, NULL, 0, MS2ST(FT5x06_TIMEOUT));
- } else if (n == 2) {
- txbuf[1] = ((val & 0xFF00) >> 8);
- txbuf[2] = (val & 0x00FF);
- i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 3, NULL, 0, MS2ST(FT5x06_TIMEOUT));
- }
-
- i2cReleaseBus(&I2CD2);
-}
-
-/**
- * @brief Read the value of a certain register
- *
- * @param[in] reg The register address
- * @param[in] n The amount of bytes (one or two)
- *
- * @return Data read from device (one byte or two depending on n param)
- *
- * @notapi
- */
-static uint16_t read_reg(uint8_t reg, uint8_t n) {
- uint8_t txbuf[1], rxbuf[2];
- uint16_t ret;
-
- rxbuf[0] = 0;
- rxbuf[1] = 0;
-
- i2cAcquireBus(&I2CD2);
-
- txbuf[0] = reg;
- i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT));
-
- if (n == 1) {
- ret = rxbuf[0];
- } else if (n == 2) {
- ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF));
- }
-
- i2cReleaseBus(&I2CD2);
-
- return ret;
-}
-
-static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) {
- uint8_t txbuf[1];
-
- i2cAcquireBus(&I2CD2);
-
- txbuf[0] = reg;
- i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT));
-
- i2cReleaseBus(&I2CD2);
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
-
diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse.c b/drivers/ginput/touch/MCU/ginput_lld_mouse.c
index 1bb7cd50..a64bf6cb 100644
--- a/drivers/ginput/touch/MCU/ginput_lld_mouse.c
+++ b/drivers/ginput/touch/MCU/ginput_lld_mouse.c
@@ -21,15 +21,7 @@
#include "ginput/lld/mouse.h"
-#if defined(GINPUT_MOUSE_USE_CUSTOM_BOARD) && GINPUT_MOUSE_USE_CUSTOM_BOARD
- #include "ginput_lld_mouse_board.h"
-#elif defined(BOARD_OLIMEX_STM32_LCD)
- #include "ginput_lld_mouse_board_olimex_stm32_lcd.h"
-#elif defined(BOARD_OLIMEX_PIC32MX_LCD)
- #include "ginput_lld_mouse_board_olimex_pic32mx_lcd.h"
-#else
- #include "ginput_lld_mouse_board.h"
-#endif
+#include "ginput_lld_mouse_board.h"
static uint16_t sampleBuf[7];
static coord_t lastx, lasty;
diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h
deleted file mode 100644
index c4689ecb..00000000
--- a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
- * @brief GINPUT Touch low level driver source for the MCU on the example board.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- *
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-static const ADCConfig ADCC = {
- .vref = ADC_VREF_CFG_AVDD_AVSS,
- .stime = 15,
- .irq = EIC_IRQ_ADC,
- .base = _ADC10_BASE_ADDRESS,
-};
-static struct ADCDriver ADCD;
-
-#define YNEG 13 // U
-#define XNEG 15 // R
-#define XPOS 12 // L
-#define YPOS 11 // D
-
-#define ADC_MAX 1023
-
-#define TOUCH_THRESHOULD 50
-
-static const ADCConversionGroup ADC_X_CG = {
- .circular = FALSE,
- .num_channels = 1,
- .channels = 1 << XNEG,
-};
-
-static const ADCConversionGroup ADC_Y_CG = {
- .circular = FALSE,
- .num_channels = 1,
- .channels = 1 << YPOS,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static inline void init_board(void) {
- adcObjectInit(&ADCD);
- adcStart(&ADCD, &ADCC);
-}
-
-/**
- * @brief Check whether the surface is currently touched
- * @return TRUE if the surface is currently touched
- *
- * @notapi
- */
-static inline bool_t getpin_pressed(void) {
- adcsample_t samples[2] = {0, };
-
- // Set X+ to ground
- palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
- palClearPad(IOPORTB, XPOS);
-
- // Set Y- to VCC
- palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT);
- palSetPad(IOPORTB, YNEG);
-
- palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG);
-
- adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1);
- adcConvert(&ADCD, &ADC_Y_CG, &samples[1], 1);
-
- return (ADC_MAX - (samples[1] - samples[0])) > TOUCH_THRESHOULD;
-}
-
-/**
- * @brief Aquire the bus ready for readings
- *
- * @notapi
- */
-static inline void aquire_bus(void) {
-}
-
-/**
- * @brief Release the bus after readings
- *
- * @notapi
- */
-static inline void release_bus(void) {
-}
-
-/**
- * @brief Read an x value from touch controller
- * @return The value read from the controller
- *
- * @notapi
- */
-static inline uint16_t read_x_value(void) {
- adcsample_t sample;
-
- palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT);
- palSetPad(IOPORTB, XPOS);
-
- palSetPadMode(IOPORTB, XNEG, PAL_MODE_OUTPUT);
- palClearPad(IOPORTB, XNEG);
-
- palSetPadMode(IOPORTB, YNEG, PAL_MODE_INPUT);
-
- palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG);
-
- adcConvert(&ADCD, &ADC_Y_CG, &sample, 1);
-
- return ADC_MAX - sample;
-}
-
-/**
- * @brief Read an y value from touch controller
- * @return The value read from the controller
- *
- * @notapi
- */
-static inline uint16_t read_y_value(void) {
- adcsample_t sample;
-
- palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT);
- palClearPad(IOPORTB, YNEG);
-
- palSetPadMode(IOPORTB, YPOS, PAL_MODE_OUTPUT);
- palSetPad(IOPORTB, YPOS);
-
- palSetPadMode(IOPORTB, XPOS, PAL_MODE_INPUT);
-
- palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG);
-
- adcConvert(&ADCD, &ADC_X_CG, &sample, 1);
-
- return ADC_MAX - sample;
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
deleted file mode 100644
index 2cc58f3c..00000000
--- a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
- * @brief GINPUT Touch low level driver source for the MCU on the example board.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- *
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-#define ADC_NUM_CHANNELS 2
-#define ADC_BUF_DEPTH 1
-
-static const ADCConversionGroup adc_y_config = {
- FALSE,
- ADC_NUM_CHANNELS,
- NULL,
- NULL,
- 0, 0,
- 0, 0,
- ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
- 0,
- ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13)
-};
-
-static const ADCConversionGroup adc_x_config = {
- FALSE,
- ADC_NUM_CHANNELS,
- NULL,
- NULL,
- 0, 0,
- 0, 0,
- ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
- 0,
- ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static inline void init_board(void) {
- adcStart(&ADCD1, NULL);
-}
-
-/**
- * @brief Check whether the surface is currently touched
- * @return TRUE if the surface is currently touched
- *
- * @notapi
- */
-static inline bool_t getpin_pressed(void) {
- palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN);
- palSetPadMode(GPIOC, 1, PAL_MODE_INPUT);
- palSetPadMode(GPIOC, 2, PAL_MODE_INPUT);
- palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPad(GPIOC, 3);
-
- return palReadPad(GPIOC, 0);
-}
-
-/**
- * @brief Aquire the bus ready for readings
- *
- * @notapi
- */
-static inline void aquire_bus(void) {
-
-}
-
-/**
- * @brief Release the bus after readings
- *
- * @notapi
- */
-static inline void release_bus(void) {
-
-}
-
-/**
- * @brief Read an x value from touch controller
- * @return The value read from the controller
- *
- * @notapi
- */
-static inline uint16_t read_x_value(void) {
- uint16_t val1, val2;
- adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
-
- palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL);
-
- palSetPad(GPIOC, 2);
- palClearPad(GPIOC, 3);
- gfxSleepMilliseconds(1);
- adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
- val1 = ((samples[0] + samples[1])/2);
-
- palClearPad(GPIOC, 2);
- palSetPad(GPIOC, 3);
- gfxSleepMilliseconds(1);
- adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
- val2 = ((samples[0] + samples[1])/2);
-
- return ((val1+((1<<12)-val2))/4);
-}
-
-/**
- * @brief Read an y value from touch controller
- * @return The value read from the controller
- *
- * @notapi
- */
-static inline uint16_t read_y_value(void) {
- uint16_t val1, val2;
- adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
-
- palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL);
-
- palSetPad(GPIOC, 1);
- palClearPad(GPIOC, 0);
- gfxSleepMilliseconds(1);
- adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
- val1 = ((samples[0] + samples[1])/2);
-
- palClearPad(GPIOC, 1);
- palSetPad(GPIOC, 0);
- gfxSleepMilliseconds(1);
- adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
- val2 = ((samples[0] + samples[1])/2);
-
- return ((val1+((1<<12)-val2))/4);
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
deleted file mode 100644
index 7246378d..00000000
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
- * @brief GINPUT Touch low level driver source for the STMPE811 on the Embest DM-STF4BB board.
- *
- * @defgroup Mouse Mouse
- * @ingroup GINPUT
- * @{
- */
-
-#ifndef _GINPUT_LLD_MOUSE_BOARD_H
-#define _GINPUT_LLD_MOUSE_BOARD_H
-
-static const I2CConfig i2ccfg = {
- OPMODE_I2C,
- 400000,
- FAST_DUTY_CYCLE_2,
-};
-
-/**
- * @brief Initialise the board for the touch.
- *
- * @notapi
- */
-static void init_board(void)
-{
- palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */
- palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */
- palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */
-
- i2cStart(&I2CD1, &i2ccfg);
-}
-
-/**
- * @brief Check whether an interrupt is raised
- * @return TRUE if there is an interrupt signal present
- *
- * @notapi
- */
-static inline bool_t getpin_irq(void) {
- return (!(palReadPad(GPIOC, 13)));
-}
-
-/**
- * @brief Write a value into a certain register
- *
- * @param[in] reg The register address
- * @param[in] n The amount of bytes (one or two)
- * @param[in] val The value
- *
- * @notapi
- */
-static void write_reg(uint8_t reg, uint8_t n, uint16_t val)
-{
- uint8_t txbuf[3];
-
- i2cAcquireBus(&I2CD1);
-
- txbuf[0] = reg;
-
- if (n == 1) {
- txbuf[1] = val;
- i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, NULL, 0, MS2ST(STMPE811_TIMEOUT));
- } else if (n == 2) {
- txbuf[1] = ((val & 0xFF00) >> 8);
- txbuf[2] = (val & 0x00FF);
- i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 3, NULL, 0, MS2ST(STMPE811_TIMEOUT));
- }
-
- i2cReleaseBus(&I2CD1);
-}
-
-/**
- * @brief Read the value of a certain register
- *
- * @param[in] reg The register address
- * @param[in] n The amount of bytes (one or two)
- *
- * @return Data read from device (one byte or two depending on n param)
- *
- * @notapi
- */
-static uint16_t read_reg(uint8_t reg, uint8_t n)
-{
- uint8_t txbuf[1], rxbuf[2];
- uint16_t ret;
-
- rxbuf[0] = 0;
- rxbuf[1] = 0;
-
- i2cAcquireBus(&I2CD1);
-
- txbuf[0] = reg;
- i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT));
-
- if (n == 1) {
- ret = rxbuf[0];
- } else if (n == 2) {
- ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF));
- }
-
- i2cReleaseBus(&I2CD1);
-
- return ret;
-}
-
-static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf)
-{
- uint8_t txbuf[1];
-
- i2cAcquireBus(&I2CD1);
-
- txbuf[0] = reg;
- i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT));
-
- i2cReleaseBus(&I2CD1);
-}
-
-#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
-/** @} */
diff --git a/drivers/multiple/Win32/gdisp_lld.c b/drivers/multiple/Win32/gdisp_lld.c
deleted file mode 100644
index 0bac0fde..00000000
--- a/drivers/multiple/Win32/gdisp_lld.c
+++ /dev/null
@@ -1,1028 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/multiple/Win32/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for Win32.
- *
- * @addtogroup GDISP
- * @{
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <windows.h>
-#include <wingdi.h>
-#include <assert.h>
-
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 640
-#endif
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 480
-#endif
-
-#if GINPUT_NEED_TOGGLE
- /* Include toggle support code */
- #include "ginput/lld/toggle.h"
-
- const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = {
- {0, 0xFF, 0x00, 0},
- };
-#endif
-
-#if GINPUT_NEED_MOUSE
- /* Include mouse support code */
- #include "ginput/lld/mouse.h"
-#endif
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-/*===========================================================================*/
-/* Driver local routines . */
-/*===========================================================================*/
-
-#define WIN32_USE_MSG_REDRAW FALSE
-#if GINPUT_NEED_TOGGLE
- #define WIN32_BUTTON_AREA 16
-#else
- #define WIN32_BUTTON_AREA 0
-#endif
-
-#define APP_NAME "GDISP"
-
-#define COLOR2BGR(c) ((((c) & 0xFF)<<16)|((c) & 0xFF00)|(((c)>>16) & 0xFF))
-#define BGR2COLOR(c) COLOR2BGR(c)
-
-static HWND winRootWindow = NULL;
-static HDC dcBuffer = NULL;
-static HBITMAP dcBitmap = NULL;
-static HBITMAP dcOldBitmap;
-static volatile bool_t isReady = FALSE;
-static coord_t wWidth, wHeight;
-
-#if GINPUT_NEED_MOUSE
- static coord_t mousex, mousey;
- static uint16_t mousebuttons;
-#endif
-#if GINPUT_NEED_TOGGLE
- static uint8_t toggles = 0;
-#endif
-
-static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
- HDC dc;
- PAINTSTRUCT ps;
- #if GINPUT_NEED_TOGGLE
- HBRUSH hbrOn, hbrOff;
- HPEN pen;
- RECT rect;
- HGDIOBJ old;
- POINT p;
- coord_t pos;
- uint8_t bit;
- #endif
-
- switch (Msg) {
- case WM_CREATE:
- break;
- case WM_LBUTTONDOWN:
- #if GINPUT_NEED_MOUSE
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons |= GINPUT_MOUSE_BTN_LEFT;
- goto mousemove;
- }
- #endif
- #if GINPUT_NEED_TOGGLE
- bit = 1 << ((coord_t)LOWORD(lParam)*8/wWidth);
- toggles ^= bit;
- rect.left = 0;
- rect.right = wWidth;
- rect.top = wHeight;
- rect.bottom = wHeight + WIN32_BUTTON_AREA;
- InvalidateRect(hWnd, &rect, FALSE);
- UpdateWindow(hWnd);
- #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE
- ginputToggleWakeup();
- #endif
- #endif
- break;
- case WM_LBUTTONUP:
- #if GINPUT_NEED_TOGGLE
- if ((toggles & 0x0F)) {
- toggles &= ~0x0F;
- rect.left = 0;
- rect.right = wWidth;
- rect.top = wHeight;
- rect.bottom = wHeight + WIN32_BUTTON_AREA;
- InvalidateRect(hWnd, &rect, FALSE);
- UpdateWindow(hWnd);
- #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE
- ginputToggleWakeup();
- #endif
- }
- #endif
- #if GINPUT_NEED_MOUSE
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT;
- goto mousemove;
- }
- #endif
- break;
-#if GINPUT_NEED_MOUSE
- case WM_MBUTTONDOWN:
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE;
- goto mousemove;
- }
- break;
- case WM_MBUTTONUP:
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE;
- goto mousemove;
- }
- break;
- case WM_RBUTTONDOWN:
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons |= GINPUT_MOUSE_BTN_RIGHT;
- goto mousemove;
- }
- break;
- case WM_RBUTTONUP:
- if ((coord_t)HIWORD(lParam) < wHeight) {
- mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT;
- goto mousemove;
- }
- break;
- case WM_MOUSEMOVE:
- if ((coord_t)HIWORD(lParam) >= wHeight)
- break;
- mousemove:
- mousex = (coord_t)LOWORD(lParam);
- mousey = (coord_t)HIWORD(lParam);
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
- break;
-#endif
- case WM_SYSKEYDOWN:
- case WM_KEYDOWN:
- case WM_SYSKEYUP:
- case WM_KEYUP:
- break;
- case WM_CHAR:
- case WM_DEADCHAR:
- case WM_SYSCHAR:
- case WM_SYSDEADCHAR:
- break;
- case WM_PAINT:
- dc = BeginPaint(hWnd, &ps);
- BitBlt(dc, ps.rcPaint.left, ps.rcPaint.top,
- ps.rcPaint.right - ps.rcPaint.left,
- (ps.rcPaint.bottom > wHeight ? wHeight : ps.rcPaint.bottom) - ps.rcPaint.top,
- dcBuffer, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
- #if GINPUT_NEED_TOGGLE
- if (ps.rcPaint.bottom >= wHeight) {
- pen = CreatePen(PS_SOLID, 1, COLOR2BGR(Black));
- hbrOn = CreateSolidBrush(COLOR2BGR(Blue));
- hbrOff = CreateSolidBrush(COLOR2BGR(Gray));
- old = SelectObject(dc, pen);
- MoveToEx(dc, 0, wHeight, &p);
- LineTo(dc, wWidth, wHeight);
- for(pos = 0, bit=1; pos < wWidth; pos=rect.right, bit <<= 1) {
- rect.left = pos;
- rect.right = pos + wWidth/8;
- rect.top = wHeight;
- rect.bottom = wHeight + WIN32_BUTTON_AREA;
- FillRect(dc, &rect, (toggles & bit) ? hbrOn : hbrOff);
- if (pos > 0) {
- MoveToEx(dc, rect.left, rect.top, &p);
- LineTo(dc, rect.left, rect.bottom);
- }
- }
- DeleteObject(hbrOn);
- DeleteObject(hbrOff);
- SelectObject(dc, old);
- }
- #endif
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- SelectObject(dcBuffer, dcOldBitmap);
- DeleteDC(dcBuffer);
- DeleteObject(dcBitmap);
- winRootWindow = NULL;
- break;
- default:
- return DefWindowProc(hWnd, Msg, wParam, lParam);
- }
- return 0;
-}
-
-static void InitWindow(void) {
- HANDLE hInstance;
- WNDCLASS wc;
- RECT rect;
- HDC dc;
-
- hInstance = GetModuleHandle(NULL);
-
- wc.style = CS_HREDRAW | CS_VREDRAW; // | CS_OWNDC;
- wc.lpfnWndProc = (WNDPROC)myWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = APP_NAME;
- RegisterClass(&wc);
-
- rect.top = 0; rect.bottom = wHeight+WIN32_BUTTON_AREA;
- rect.left = 0; rect.right = wWidth;
- AdjustWindowRect(&rect, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0);
- winRootWindow = CreateWindow(APP_NAME, "", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0, 0,
- rect.right-rect.left, rect.bottom-rect.top, 0, 0, hInstance, NULL);
- assert(winRootWindow != NULL);
-
-
- GetClientRect(winRootWindow, &rect);
- wWidth = rect.right-rect.left;
- wHeight = rect.bottom - rect.top - WIN32_BUTTON_AREA;
-
- dc = GetDC(winRootWindow);
- dcBitmap = CreateCompatibleBitmap(dc, wWidth, wHeight);
- dcBuffer = CreateCompatibleDC(dc);
- ReleaseDC(winRootWindow, dc);
- dcOldBitmap = SelectObject(dcBuffer, dcBitmap);
-
- ShowWindow(winRootWindow, SW_SHOW);
- UpdateWindow(winRootWindow);
- isReady = TRUE;
-}
-
-static DECLARE_THREAD_STACK(waWindowThread, 1024);
-static DECLARE_THREAD_FUNCTION(WindowThread, param) {
- (void)param;
- MSG msg;
-
- InitWindow();
- do {
- gfxSleepMilliseconds(1);
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- } while (msg.message != WM_QUIT);
- ExitProcess(0);
- return msg.wParam;
-}
-
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
-
-/* ---- Required Routines ---- */
-/*
- The following 2 routines are required.
- All other routines are optional.
-*/
-
-/**
- * @brief Low level GDISP driver initialisation.
- * @return TRUE if successful, FALSE on error.
- *
- * @notapi
- */
-bool_t gdisp_lld_init(void) {
- RECT rect;
- gfxThreadHandle hth;
-
- /* Set the window dimensions */
- GetWindowRect(GetDesktopWindow(), &rect);
- wWidth = rect.right - rect.left;
- wHeight = rect.bottom - rect.top - WIN32_BUTTON_AREA;
- if (wWidth > GDISP_SCREEN_WIDTH)
- wWidth = GDISP_SCREEN_WIDTH;
- if (wHeight > GDISP_SCREEN_HEIGHT)
- wHeight = GDISP_SCREEN_HEIGHT;
-
- /* Initialise the window */
- if (!(hth = gfxThreadCreate(waWindowThread, sizeof(waWindowThread), HIGH_PRIORITY, WindowThread, 0))) {
- fprintf(stderr, "Cannot create window thread\n");
- exit(-1);
- }
- gfxThreadClose(hth);
- while (!isReady)
- Sleep(1);
-
- /* Initialise the GDISP structure to match */
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- GDISP.Width = wWidth;
- GDISP.Height = wHeight;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- 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_draw_pixel(coord_t x, coord_t y, color_t color) {
- HDC dc;
- #if WIN32_USE_MSG_REDRAW
- RECT rect;
- #endif
- #if GDISP_NEED_CONTROL
- coord_t t;
- #endif
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- #if GDISP_NEED_CONTROL
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- break;
- case GDISP_ROTATE_90:
- t = GDISP.Height - 1 - y;
- y = x;
- x = t;
- break;
- case GDISP_ROTATE_180:
- x = GDISP.Width - 1 - x;
- y = GDISP.Height - 1 - y;
- break;
- case GDISP_ROTATE_270:
- t = GDISP.Width - 1 - x;
- x = y;
- y = t;
- break;
- }
- #endif
-
- // Draw the pixel in the buffer
- color = COLOR2BGR(color);
- SetPixel(dcBuffer, x, y, color);
-
- #if WIN32_USE_MSG_REDRAW
- rect.left = x; rect.right = x+1;
- rect.top = y; rect.bottom = y+1;
- InvalidateRect(winRootWindow, &rect, FALSE);
- UpdateWindow(winRootWindow);
- #else
- // Draw the pixel again directly on the screen.
- // This is cheaper than invalidating a single pixel in the window
- dc = GetDC(winRootWindow);
- SetPixel(dc, x, y, color);
- ReleaseDC(winRootWindow, dc);
- #endif
-}
-
-/* ---- Optional Routines ---- */
-
-#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_draw_line(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) {
- POINT p;
- HPEN pen;
- HDC dc;
- HGDIOBJ old;
- #if GDISP_NEED_CLIP
- HRGN clip;
- #endif
- #if WIN32_USE_MSG_REDRAW
- RECT rect;
- #endif
- #if GDISP_NEED_CONTROL
- coord_t t;
- #endif
-
- #if GDISP_NEED_CLIP
- clip = NULL;
- #endif
-
- #if GDISP_NEED_CONTROL
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- #if GDISP_NEED_CLIP
- // Clip post orientation change
- if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height)
- clip = CreateRectRgn(GDISP.clipx0, GDISP.clipy0, GDISP.clipx1, GDISP.clipy1);
- #endif
- break;
- case GDISP_ROTATE_90:
- t = GDISP.Height - 1 - y0;
- y0 = x0;
- x0 = t;
- t = GDISP.Height - 1 - y1;
- y1 = x1;
- x1 = t;
- #if GDISP_NEED_CLIP
- // Clip post orientation change
- if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height)
- clip = CreateRectRgn(GDISP.Height-1-GDISP.clipy1, GDISP.clipx0, GDISP.Height-1-GDISP.clipy0, GDISP.clipx1);
- #endif
- break;
- case GDISP_ROTATE_180:
- x0 = GDISP.Width - 1 - x0;
- y0 = GDISP.Height - 1 - y0;
- x1 = GDISP.Width - 1 - x1;
- y1 = GDISP.Height - 1 - y1;
- #if GDISP_NEED_CLIP
- // Clip post orientation change
- if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height)
- clip = CreateRectRgn(GDISP.Width-1-GDISP.clipx1, GDISP.Height-1-GDISP.clipy1, GDISP.Width-1-GDISP.clipx0, GDISP.Height-1-GDISP.clipy0);
- #endif
- break;
- case GDISP_ROTATE_270:
- t = GDISP.Width - 1 - x0;
- x0 = y0;
- y0 = t;
- t = GDISP.Width - 1 - x1;
- x1 = y1;
- y1 = t;
- #if GDISP_NEED_CLIP
- // Clip post orientation change
- if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height)
- clip = CreateRectRgn(GDISP.clipy0, GDISP.Width-1-GDISP.clipx1, GDISP.clipy1, GDISP.Width-1-GDISP.clipx0);
- #endif
- break;
- }
- #else
- #if GDISP_NEED_CLIP
- clip = NULL;
- if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height)
- clip = CreateRectRgn(GDISP.clipx0, GDISP.clipy0, GDISP.clipx1, GDISP.clipy1);
- #endif
- #endif
-
- color = COLOR2BGR(color);
- pen = CreatePen(PS_SOLID, 1, color);
- if (pen) {
- // Draw the line in the buffer
- #if GDISP_NEED_CLIP
- if (clip) SelectClipRgn(dcBuffer, clip);
- #endif
- old = SelectObject(dcBuffer, pen);
- MoveToEx(dcBuffer, x0, y0, &p);
- LineTo(dcBuffer, x1, y1);
- SelectObject(dcBuffer, old);
- SetPixel(dcBuffer, x1, y1, color);
- #if GDISP_NEED_CLIP
- if (clip) SelectClipRgn(dcBuffer, NULL);
- #endif
-
- #if WIN32_USE_MSG_REDRAW
- rect.left = x0; rect.right = x1+1;
- rect.top = y0; rect.bottom = y1+1;
- InvalidateRect(winRootWindow, &rect, FALSE);
- UpdateWindow(winRootWindow);
- #else
- // Redrawing the line on the screen is cheaper than invalidating the whole rectangular area
- dc = GetDC(winRootWindow);
- #if GDISP_NEED_CLIP
- if (clip) SelectClipRgn(dc, clip);
- #endif
- old = SelectObject(dc, pen);
- MoveToEx(dc, x0, y0, &p);
- LineTo(dc, x1, y1);
- SelectObject(dc, old);
- SetPixel(dc, x1, y1, color);
- #if GDISP_NEED_CLIP
- if (clip) SelectClipRgn(dc, NULL);
- #endif
- ReleaseDC(winRootWindow, dc);
- #endif
-
- DeleteObject(pen);
- }
- }
-#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_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- HDC dc;
- RECT rect;
- HBRUSH hbr;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- #if GDISP_NEED_CONTROL
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- break;
- case GDISP_ROTATE_90:
- rect.top = x;
- rect.bottom = rect.top+cx;
- rect.right = GDISP.Height - y;
- rect.left = rect.right-cy;
- break;
- case GDISP_ROTATE_180:
- rect.bottom = GDISP.Height - y;
- rect.top = rect.bottom-cy;
- rect.right = GDISP.Width - x;
- rect.left = rect.right-cx;
- break;
- case GDISP_ROTATE_270:
- rect.bottom = GDISP.Width - x;
- rect.top = rect.bottom-cx;
- rect.left = y;
- rect.right = rect.left+cy;
- break;
- }
- #else
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- #endif
-
- color = COLOR2BGR(color);
- hbr = CreateSolidBrush(color);
-
- if (hbr) {
- // Fill the area
- FillRect(dcBuffer, &rect, hbr);
-
- #if WIN32_USE_MSG_REDRAW
- InvalidateRect(winRootWindow, &rect, FALSE);
- UpdateWindow(winRootWindow);
- #else
- // Filling the area directly on the screen is likely to be cheaper than invalidating it
- dc = GetDC(winRootWindow);
- FillRect(dc, &rect, hbr);
- ReleaseDC(winRootWindow, dc);
- #endif
-
- DeleteObject(hbr);
- }
- }
-#endif
-
-#if (GDISP_HARDWARE_BITFILLS && GDISP_NEED_CONTROL) || defined(__DOXYGEN__)
- static pixel_t *rotateimg(coord_t cx, coord_t cy, coord_t srcx, coord_t srccx, const pixel_t *buffer) {
- pixel_t *dstbuf;
- pixel_t *dst;
- const pixel_t *src;
- size_t sz;
- coord_t i, j;
-
- // Shortcut.
- if (GDISP.Orientation == GDISP_ROTATE_0 && srcx == 0 && cx == srccx)
- return (pixel_t *)buffer;
-
- // Allocate the destination buffer
- sz = (size_t)cx * (size_t)cy;
- if (!(dstbuf = (pixel_t *)malloc(sz * sizeof(pixel_t))))
- return 0;
-
- // Copy the bits we need
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- for(dst = dstbuf, src = buffer+srcx, j = 0; j < cy; j++)
- for(i = 0; i < cx; i++, src += srccx - cx)
- *dst++ = *src++;
- break;
- case GDISP_ROTATE_90:
- for(src = buffer+srcx, j = 0; j < cy; j++) {
- dst = dstbuf+cy-j-1;
- for(i = 0; i < cx; i++, src += srccx - cx, dst += cy)
- *dst = *src++;
- }
- break;
- case GDISP_ROTATE_180:
- for(dst = dstbuf+sz, src = buffer+srcx, j = 0; j < cy; j++)
- for(i = 0; i < cx; i++, src += srccx - cx)
- *--dst = *src++;
- break;
- case GDISP_ROTATE_270:
- for(src = buffer+srcx, j = 0; j < cy; j++) {
- dst = dstbuf+sz-cy+j;
- for(i = 0; i < cx; i++, src += srccx - cx, dst -= cy)
- *dst = *src++;
- }
- break;
- }
- return dstbuf;
- }
-#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] srcx, srcy The bitmap position to start the fill from
- * @param[in] srccx The width of a line in the bitmap.
- * @param[in] buffer The pixels to use to fill the area.
- *
- * @notapi
- */
- void gdisp_lld_blit_area_ex(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- BITMAPV4HEADER bmpInfo;
- RECT rect;
- #if GDISP_NEED_CONTROL
- pixel_t *srcimg;
- #endif
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (srcx+cx > srccx) cx = srccx - srcx;
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- // Make everything relative to the start of the line
- buffer += srccx*srcy;
- srcy = 0;
-
- memset(&bmpInfo, 0, sizeof(bmpInfo));
- bmpInfo.bV4Size = sizeof(bmpInfo);
- bmpInfo.bV4Planes = 1;
- bmpInfo.bV4BitCount = 32;
- bmpInfo.bV4AlphaMask = 0;
- bmpInfo.bV4RedMask = RGB2COLOR(255,0,0);
- bmpInfo.bV4GreenMask = RGB2COLOR(0,255,0);
- bmpInfo.bV4BlueMask = RGB2COLOR(0,0,255);
- bmpInfo.bV4V4Compression = BI_BITFIELDS;
- bmpInfo.bV4XPelsPerMeter = 3078;
- bmpInfo.bV4YPelsPerMeter = 3078;
- bmpInfo.bV4ClrUsed = 0;
- bmpInfo.bV4ClrImportant = 0;
- bmpInfo.bV4CSType = 0; //LCS_sRGB;
-
- #if GDISP_NEED_CONTROL
- bmpInfo.bV4SizeImage = (cy*cx) * sizeof(pixel_t);
- srcimg = rotateimg(cx, cy, srcx, srccx, buffer);
- if (!srcimg) return;
-
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- bmpInfo.bV4Width = cx;
- bmpInfo.bV4Height = -cy; /* top-down image */
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- break;
- case GDISP_ROTATE_90:
- bmpInfo.bV4Width = cy;
- bmpInfo.bV4Height = -cx; /* top-down image */
- rect.top = x;
- rect.bottom = rect.top+cx;
- rect.right = GDISP.Height - y;
- rect.left = rect.right-cy;
- break;
- case GDISP_ROTATE_180:
- bmpInfo.bV4Width = cx;
- bmpInfo.bV4Height = -cy; /* top-down image */
- rect.bottom = GDISP.Height - y;
- rect.top = rect.bottom-cy;
- rect.right = GDISP.Width - x;
- rect.left = rect.right-cx;
- break;
- case GDISP_ROTATE_270:
- bmpInfo.bV4Width = cy;
- bmpInfo.bV4Height = -cx; /* top-down image */
- rect.bottom = GDISP.Width - x;
- rect.top = rect.bottom-cx;
- rect.left = y;
- rect.right = rect.left+cy;
- break;
- }
- SetDIBitsToDevice(dcBuffer, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0, 0, 0, rect.bottom-rect.top, srcimg, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS);
- if (srcimg != (pixel_t *)buffer)
- free(srcimg);
-
- #else
- bmpInfo.bV4Width = srccx;
- bmpInfo.bV4Height = -cy; /* top-down image */
- bmpInfo.bV4SizeImage = (cy*srccx) * sizeof(pixel_t);
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- SetDIBitsToDevice(dcBuffer, x, y, cx, cy, srcx, 0, 0, cy, buffer, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS);
- #endif
-
- // Invalidate the region to get it on the screen.
- InvalidateRect(winRootWindow, &rect, FALSE);
- UpdateWindow(winRootWindow);
- }
-#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.
- * @return The color of the specified pixel.
- *
- * @param[in] x, y The start of the text
- *
- * @notapi
- */
- color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
- color_t color;
- #if GDISP_NEED_CONTROL
- coord_t t;
- #endif
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
- #endif
-
- #if GDISP_NEED_CONTROL
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- break;
- case GDISP_ROTATE_90:
- t = GDISP.Height - 1 - y;
- y = x;
- x = t;
- break;
- case GDISP_ROTATE_180:
- x = GDISP.Width - 1 - x;
- y = GDISP.Height - 1 - y;
- break;
- case GDISP_ROTATE_270:
- t = GDISP.Width - 1 - x;
- x = y;
- y = t;
- break;
- }
- #endif
-
- color = GetPixel(dcBuffer, x, y);
- return BGR2COLOR(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_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- RECT rect, frect, srect;
- HBRUSH hbr;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- if (lines > cy) lines = cy;
- else if (-lines > cy) lines = -cy;
-
- bgcolor = COLOR2BGR(bgcolor);
- hbr = CreateSolidBrush(bgcolor);
-
- #if GDISP_NEED_CONTROL
- switch(GDISP.Orientation) {
- case GDISP_ROTATE_0:
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- lines = -lines;
- goto vertical_scroll;
- case GDISP_ROTATE_90:
- rect.top = x;
- rect.bottom = rect.top+cx;
- rect.right = GDISP.Height - y;
- rect.left = rect.right-cy;
- goto horizontal_scroll;
- case GDISP_ROTATE_180:
- rect.bottom = GDISP.Height - y;
- rect.top = rect.bottom-cy;
- rect.right = GDISP.Width - x;
- rect.left = rect.right-cx;
- vertical_scroll:
- srect.left = frect.left = rect.left;
- srect.right = frect.right = rect.right;
- if (lines > 0) {
- srect.top = frect.top = rect.top;
- frect.bottom = rect.top+lines;
- srect.bottom = rect.bottom-lines;
- } else {
- srect.bottom = frect.bottom = rect.bottom;
- frect.top = rect.bottom+lines;
- srect.top = rect.top-lines;
- }
- if (cy >= lines && cy >= -lines)
- ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0);
- break;
- case GDISP_ROTATE_270:
- rect.bottom = GDISP.Width - x;
- rect.top = rect.bottom-cx;
- rect.left = y;
- rect.right = rect.left+cy;
- lines = -lines;
- horizontal_scroll:
- srect.top = frect.top = rect.top;
- srect.bottom = frect.bottom = rect.bottom;
- if (lines > 0) {
- srect.left = frect.left = rect.left;
- frect.right = rect.left+lines;
- srect.right = rect.right-lines;
- } else {
- srect.right = frect.right = rect.right;
- frect.left = rect.right+lines;
- srect.left = rect.left-lines;
- }
- if (cy >= lines && cy >= -lines)
- ScrollDC(dcBuffer, lines, 0, &srect, 0, 0, 0);
- break;
- }
- #else
- rect.top = y;
- rect.bottom = rect.top+cy;
- rect.left = x;
- rect.right = rect.left+cx;
- lines = -lines;
- srect.left = frect.left = rect.left;
- srect.right = frect.right = rect.right;
- if (lines > 0) {
- srect.top = frect.top = rect.top;
- frect.bottom = rect.top+lines;
- srect.bottom = rect.bottom-lines;
- } else {
- srect.bottom = frect.bottom = rect.bottom;
- frect.top = rect.bottom+lines;
- srect.top = rect.top-lines;
- }
- if (cy >= lines && cy >= -lines)
- ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0);
- #endif
-
- if (hbr)
- FillRect(dcBuffer, &frect, hbr);
- InvalidateRect(winRootWindow, &rect, FALSE);
- UpdateWindow(winRootWindow);
- }
-#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 what, void *value) {
- switch(what) {
- case GDISP_CONTROL_ORIENTATION:
- if (GDISP.Orientation == (gdisp_orientation_t)value)
- return;
- switch((gdisp_orientation_t)value) {
- case GDISP_ROTATE_0:
- GDISP.Width = wWidth;
- GDISP.Height = wHeight;
- break;
- case GDISP_ROTATE_90:
- GDISP.Height = wWidth;
- GDISP.Width = wHeight;
- break;
- case GDISP_ROTATE_180:
- GDISP.Width = wWidth;
- GDISP.Height = wHeight;
- break;
- case GDISP_ROTATE_270:
- GDISP.Height = wWidth;
- GDISP.Width = wHeight;
- break;
- default:
- return;
- }
-
- #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- GDISP.Orientation = (gdisp_orientation_t)value;
- return;
-/*
- case GDISP_CONTROL_POWER:
- case GDISP_CONTROL_BACKLIGHT:
- case GDISP_CONTROL_CONTRAST:
-*/
- }
- }
-#endif
-
-#if GINPUT_NEED_MOUSE
-
- void ginput_lld_mouse_init(void) {}
-
- void ginput_lld_mouse_get_reading(MouseReading *pt) {
- pt->x = mousex;
- pt->y = mousey > wHeight ? wHeight : mousey;
- pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
- pt->buttons = mousebuttons;
- }
-
-#endif /* GINPUT_NEED_MOUSE */
-
-#if GINPUT_NEED_TOGGLE
-
- void ginput_lld_toggle_init(const GToggleConfig *ptc) { (void) ptc; }
- unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc) { (void) ptc; return toggles; }
-
-#endif /* GINPUT_NEED_MOUSE */
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/multiple/Win32/gdisp_lld.mk b/drivers/multiple/Win32/gdisp_lld.mk
index b116088b..f9242380 100644
--- a/drivers/multiple/Win32/gdisp_lld.mk
+++ b/drivers/multiple/Win32/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/multiple/Win32/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/multiple/Win32
+GFXSRC += $(GFXLIB)/drivers/multiple/Win32/gdisp_lld_Win32.c
diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c
new file mode 100644
index 00000000..9484c823
--- /dev/null
+++ b/drivers/multiple/Win32/gdisp_lld_Win32.c
@@ -0,0 +1,1160 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/multiple/Win32/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for Win32.
+ */
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_Win32
+#include "../drivers/multiple/Win32/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 640
+#endif
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 480
+#endif
+
+// Setting this to TRUE delays updating the screen
+// to the windows paint routine. Due to the
+// drawing lock this does not add as much speed
+// as might be expected but it is still faster in
+// all tested circumstances and for all operations
+// even draw_pixel().
+// This is probably due to drawing operations being
+// combined as the update regions are merged.
+// The only time you might want to turn this off is
+// if you are debugging drawing and want to see each
+// pixel as it is set.
+#define GDISP_WIN32_USE_INDIRECT_UPDATE TRUE
+//#define GDISP_WIN32_USE_INDIRECT_UPDATE FALSE
+
+// How far extra windows (multiple displays) should be offset from the first.
+#define DISPLAY_X_OFFSET 50
+#define DISPLAY_Y_OFFSET 50
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <wingdi.h>
+#include <assert.h>
+
+#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
+#define GDISP_FLG_HASTOGGLE (GDISP_FLG_DRIVER<<1)
+#define GDISP_FLG_HASMOUSE (GDISP_FLG_DRIVER<<2)
+#if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
+ #define GDISP_FLG_WSTREAM (GDISP_FLG_DRIVER<<3)
+ #define GDISP_FLG_WRAPPED (GDISP_FLG_DRIVER<<4)
+#endif
+
+#if GINPUT_NEED_TOGGLE
+ /* Include toggle support code */
+ #include "ginput/lld/toggle.h"
+#endif
+
+#if GINPUT_NEED_MOUSE
+ /* Include mouse support code */
+ #include "ginput/lld/mouse.h"
+#endif
+
+static DWORD winThreadId;
+static ATOM winClass;
+static volatile bool_t QReady;
+static HANDLE drawMutex;
+#if GINPUT_NEED_MOUSE
+ static GDisplay * mouseDisplay;
+#endif
+
+/*===========================================================================*/
+/* Driver local routines . */
+/*===========================================================================*/
+
+#if GINPUT_NEED_TOGGLE
+ #define WIN32_BUTTON_AREA 16
+#else
+ #define WIN32_BUTTON_AREA 0
+#endif
+
+#define APP_NAME "uGFX"
+
+typedef struct winPriv {
+ HWND hwnd;
+ HDC dcBuffer;
+ HBITMAP dcBitmap;
+ HBITMAP dcOldBitmap;
+ #if GINPUT_NEED_MOUSE
+ coord_t mousex, mousey;
+ uint16_t mousebuttons;
+ #endif
+ #if GINPUT_NEED_TOGGLE
+ uint8_t toggles;
+ #endif
+ #if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
+ coord_t x0, y0, x1, y1;
+ coord_t x, y;
+ #endif
+} winPriv;
+
+
+static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+ HDC dc;
+ PAINTSTRUCT ps;
+ GDisplay * g;
+ winPriv * priv;
+ #if GINPUT_NEED_TOGGLE
+ HBRUSH hbrOn, hbrOff;
+ HPEN pen;
+ RECT rect;
+ HGDIOBJ old;
+ POINT p;
+ coord_t pos;
+ uint8_t bit;
+ #endif
+
+ switch (Msg) {
+ case WM_CREATE:
+ // Get our GDisplay structure and attach it to the window
+ g = (GDisplay *)((LPCREATESTRUCT)lParam)->lpCreateParams;
+ priv = (winPriv *)g->priv;
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)g);
+
+ // Fill in the private area
+ priv->hwnd = hWnd;
+ dc = GetDC(hWnd);
+ priv->dcBitmap = CreateCompatibleBitmap(dc, g->g.Width, g->g.Height);
+ priv->dcBuffer = CreateCompatibleDC(dc);
+ ReleaseDC(hWnd, dc);
+ priv->dcOldBitmap = SelectObject(priv->dcBuffer, priv->dcBitmap);
+
+ // Mark the window as ready to go
+ g->flags |= GDISP_FLG_READY;
+ break;
+
+ #if GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE
+ case WM_LBUTTONDOWN:
+ // Get our GDisplay structure
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+
+ // Handle mouse down on the window
+ #if GINPUT_NEED_MOUSE
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons |= GINPUT_MOUSE_BTN_LEFT;
+ goto mousemove;
+ }
+ #endif
+
+ // Handle mouse down on the toggle area
+ #if GINPUT_NEED_TOGGLE
+ if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) {
+ bit = 1 << ((coord_t)LOWORD(lParam)*8/g->g.Width);
+ priv->toggles ^= bit;
+ rect.left = 0;
+ rect.right = GDISP_SCREEN_WIDTH;
+ rect.top = GDISP_SCREEN_HEIGHT;
+ rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA;
+ InvalidateRect(hWnd, &rect, FALSE);
+ UpdateWindow(hWnd);
+ #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE
+ ginputToggleWakeup();
+ #endif
+ }
+ #endif
+ break;
+
+ case WM_LBUTTONUP:
+ // Get our GDisplay structure
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+
+ // Handle mouse up on the toggle area
+ #if GINPUT_NEED_TOGGLE
+ if ((g->flags & GDISP_FLG_HASTOGGLE)) {
+ if ((priv->toggles & 0x0F)) {
+ priv->toggles &= ~0x0F;
+ rect.left = 0;
+ rect.right = GDISP_SCREEN_WIDTH;
+ rect.top = GDISP_SCREEN_HEIGHT;
+ rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA;
+ InvalidateRect(hWnd, &rect, FALSE);
+ UpdateWindow(hWnd);
+ #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE
+ ginputToggleWakeup();
+ #endif
+ }
+ }
+ #endif
+
+ // Handle mouse up on the window
+ #if GINPUT_NEED_MOUSE
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT;
+ goto mousemove;
+ }
+ #endif
+ break;
+ #endif
+
+ #if GINPUT_NEED_MOUSE
+ case WM_MBUTTONDOWN:
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE;
+ goto mousemove;
+ }
+ break;
+ case WM_MBUTTONUP:
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE;
+ goto mousemove;
+ }
+ break;
+ case WM_RBUTTONDOWN:
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons |= GINPUT_MOUSE_BTN_RIGHT;
+ goto mousemove;
+ }
+ break;
+ case WM_RBUTTONUP:
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+ if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) {
+ priv->mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT;
+ goto mousemove;
+ }
+ break;
+ case WM_MOUSEMOVE:
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+ if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT || !(g->flags & GDISP_FLG_HASMOUSE))
+ break;
+ mousemove:
+ priv->mousex = (coord_t)LOWORD(lParam);
+ priv->mousey = (coord_t)HIWORD(lParam);
+ #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
+ ginputMouseWakeup();
+ #endif
+ break;
+ #endif
+
+ case WM_SYSKEYDOWN:
+ case WM_KEYDOWN:
+ case WM_SYSKEYUP:
+ case WM_KEYUP:
+ break;
+ case WM_CHAR:
+ case WM_DEADCHAR:
+ case WM_SYSCHAR:
+ case WM_SYSDEADCHAR:
+ break;
+
+ case WM_ERASEBKGND:
+ // Pretend we have erased the background.
+ // We know we don't really need to do this as we
+ // redraw the entire surface in the WM_PAINT handler.
+ return TRUE;
+
+ case WM_PAINT:
+ // Get our GDisplay structure
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+
+ // Paint the main window area
+ WaitForSingleObject(drawMutex, INFINITE);
+ dc = BeginPaint(hWnd, &ps);
+ BitBlt(dc, ps.rcPaint.left, ps.rcPaint.top,
+ ps.rcPaint.right - ps.rcPaint.left,
+ (ps.rcPaint.bottom > GDISP_SCREEN_HEIGHT ? GDISP_SCREEN_HEIGHT : ps.rcPaint.bottom) - ps.rcPaint.top,
+ priv->dcBuffer, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
+
+ // Paint the toggle area
+ #if GINPUT_NEED_TOGGLE
+ if (ps.rcPaint.bottom >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) {
+ pen = CreatePen(PS_SOLID, 1, COLOR2NATIVE(Black));
+ hbrOn = CreateSolidBrush(COLOR2NATIVE(Blue));
+ hbrOff = CreateSolidBrush(COLOR2NATIVE(Gray));
+ old = SelectObject(dc, pen);
+ MoveToEx(dc, 0, GDISP_SCREEN_HEIGHT, &p);
+ LineTo(dc, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
+ for(pos = 0, bit=1; pos < wWidth; pos=rect.right, bit <<= 1) {
+ rect.left = pos;
+ rect.right = pos + GDISP_SCREEN_WIDTH/8;
+ rect.top = GDISP_SCREEN_HEIGHT;
+ rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA;
+ FillRect(dc, &rect, (priv->toggles & bit) ? hbrOn : hbrOff);
+ if (pos > 0) {
+ MoveToEx(dc, rect.left, rect.top, &p);
+ LineTo(dc, rect.left, rect.bottom);
+ }
+ }
+ DeleteObject(hbrOn);
+ DeleteObject(hbrOff);
+ SelectObject(dc, old);
+ }
+ #endif
+ EndPaint(hWnd, &ps);
+ ReleaseMutex(drawMutex);
+ break;
+
+ case WM_DESTROY:
+ // Get our GDisplay structure
+ g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ priv = (winPriv *)g->priv;
+
+ // Restore the window and free our bitmaps
+ SelectObject(priv->dcBuffer, priv->dcOldBitmap);
+ DeleteDC(priv->dcBuffer);
+ DeleteObject(priv->dcBitmap);
+
+ // Cleanup the private area
+ gfxFree(priv);
+
+ // Quit the application
+ PostQuitMessage(0);
+
+ // Actually the above doesn't work (who knows why)
+ ExitProcess(0);
+ break;
+
+ default:
+ return DefWindowProc(hWnd, Msg, wParam, lParam);
+ }
+ return 0;
+}
+
+static DECLARE_THREAD_STACK(waWindowThread, 1024);
+static DECLARE_THREAD_FUNCTION(WindowThread, param) {
+ (void)param;
+ MSG msg;
+
+ // Establish this thread as a message queue thread
+ winThreadId = GetCurrentThreadId();
+ PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+ QReady = TRUE;
+
+ do {
+ gfxSleepMilliseconds(1);
+ while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ // Is this our special thread message to create a new window?
+ if (!msg.hwnd && msg.message == WM_USER) {
+ RECT rect;
+ GDisplay *g;
+
+ g = (GDisplay *)msg.lParam;
+
+ // Set the window rectangle
+ rect.top = 0; rect.bottom = g->g.Height;
+ rect.left = 0; rect.right = g->g.Width;
+ #if GINPUT_NEED_TOGGLE
+ if ((g->flags & GDISP_FLG_HASTOGGLE))
+ rect.bottom += WIN32_BUTTON_AREA;
+ #endif
+ AdjustWindowRect(&rect, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0);
+
+ // Create the window
+ msg.hwnd = CreateWindow(APP_NAME, "", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_BORDER, msg.wParam*DISPLAY_X_OFFSET, msg.wParam*DISPLAY_Y_OFFSET,
+ rect.right-rect.left, rect.bottom-rect.top, 0, 0,
+ GetModuleHandle(NULL), g);
+ assert(msg.hwnd != NULL);
+
+ // Or just a normal window message
+ } else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ } while (msg.message != WM_QUIT);
+ ExitProcess(0);
+ return msg.wParam;
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ winPriv * priv;
+ char buf[132];
+
+ // Initialise the window thread and the window class (if it hasn't been done already)
+ if (!QReady) {
+ gfxThreadHandle hth;
+ WNDCLASS wc;
+
+ // Create the draw mutex
+ drawMutex = CreateMutex(NULL, FALSE, NULL);
+
+ // Create the thread
+ hth = gfxThreadCreate(waWindowThread, sizeof(waWindowThread), HIGH_PRIORITY, WindowThread, 0);
+ assert(hth != NULL);
+ gfxThreadClose(hth);
+
+ wc.style = CS_HREDRAW | CS_VREDRAW; // | CS_OWNDC;
+ wc.lpfnWndProc = (WNDPROC)myWindowProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = GetStockObject(WHITE_BRUSH);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = APP_NAME;
+ winClass = RegisterClass(&wc);
+ assert(winClass != 0);
+
+ // Wait for our thread to be ready
+ while (!QReady)
+ Sleep(1);
+ }
+
+ // Initialise the GDISP structure
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = 100;
+ g->g.Contrast = 50;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+
+ // Turn on toggles for the first GINPUT_TOGGLE_CONFIG_ENTRIES windows
+ #if GINPUT_NEED_TOGGLE
+ if (g->controllerdisplay < GINPUT_TOGGLE_CONFIG_ENTRIES)
+ g->flags |= GDISP_FLG_HASTOGGLE;
+ #endif
+
+ // Only turn on mouse on the first window for now
+ #if GINPUT_NEED_MOUSE
+ if (!g->controllerdisplay) {
+ mouseDisplay = g;
+ g->flags |= GDISP_FLG_HASMOUSE;
+ }
+ #endif
+
+ // Create a private area for this window
+ priv = (winPriv *)gfxAlloc(sizeof(winPriv));
+ assert(priv != NULL);
+ memset(priv, 0, sizeof(winPriv));
+ g->priv = priv;
+ #if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
+ // Initialise with an invalid window
+ g->flags &= ~GDISP_FLG_WSTREAM;
+ #endif
+ g->board = 0; // no board interface for this controller
+
+ // Create the window in the message thread
+ PostThreadMessage(winThreadId, WM_USER, (WPARAM)g->controllerdisplay, (LPARAM)g);
+
+ // Wait for the window creation to complete (for safety)
+ while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
+ Sleep(1);
+
+ sprintf(buf, APP_NAME " - %u", g->systemdisplay+1);
+ SetWindowText(priv->hwnd, buf);
+ ShowWindow(priv->hwnd, SW_SHOW);
+ UpdateWindow(priv->hwnd);
+
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_FLUSH
+ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+ winPriv * priv;
+
+ priv = g->priv;
+ UpdateWindow(priv->hwnd);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ
+ void BAD_PARAMETER(const char *msg) {
+ fprintf(stderr, "%s\n", msg);
+ }
+#endif
+
+#if GDISP_HARDWARE_STREAM_WRITE
+ LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
+ winPriv * priv;
+
+ if (g->flags & GDISP_FLG_WSTREAM)
+ BAD_PARAMETER("write_start: already in streaming mode");
+ if (g->p.cx <= 0 || g->p.cy <= 0 || g->p.x < 0 || g->p.y < 0 || g->p.x+g->p.cx > g->g.Width || g->p.y+g->p.cy > g->g.Height)
+ BAD_PARAMETER("write_start: bad window parameter");
+
+ priv = g->priv;
+ priv->x0 = g->p.x; priv->x1 = g->p.x + g->p.cx - 1;
+ priv->y0 = g->p.y; priv->y1 = g->p.y + g->p.cy - 1;
+ #if GDISP_HARDWARE_STREAM_POS
+ priv->x = g->p.x-1; // Make sure these values are invalid (for testing)
+ priv->y = g->p.y-1;
+ #else
+ priv->x = g->p.x;
+ priv->y = g->p.y;
+ #endif
+ g->flags |= GDISP_FLG_WSTREAM;
+ g->flags &= ~GDISP_FLG_WRAPPED;
+ }
+ LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
+ winPriv * priv;
+ int x, y;
+ COLORREF color;
+
+ priv = g->priv;
+ color = COLOR2NATIVE(g->p.color);
+
+ if (!(g->flags & GDISP_FLG_WSTREAM))
+ BAD_PARAMETER("write_color: not in streaming mode");
+ if (priv->x < priv->x0 || priv->x > priv->x1 || priv->y < priv->y0 || priv->y > priv->y1)
+ BAD_PARAMETER("write_color: cursor outside streaming area");
+ if (g->flags & GDISP_FLG_WRAPPED) {
+ BAD_PARAMETER("write_color: Warning - Area wrapped.");
+ g->flags &= ~GDISP_FLG_WRAPPED;
+ }
+
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = priv->x;
+ y = priv->y;
+ break;
+ case GDISP_ROTATE_90:
+ x = priv->y;
+ y = g->g.Width - 1 - priv->x;
+ break;
+ case GDISP_ROTATE_180:
+ x = g->g.Width - 1 - priv->x;
+ y = g->g.Height - 1 - priv->y;
+ break;
+ case GDISP_ROTATE_270:
+ x = g->g.Height - 1 - priv->y;
+ y = priv->x;
+ break;
+ }
+ #else
+ x = priv->x;
+ y = priv->y;
+ #endif
+
+ // Draw the pixel on the screen and in the buffer.
+ WaitForSingleObject(drawMutex, INFINITE);
+ SetPixel(priv->dcBuffer, x, y, color);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ {
+ RECT r;
+ r.left = x; r.right = x+1;
+ r.top = y; r.bottom = y+1;
+ InvalidateRect(priv->hwnd, &r, FALSE);
+ }
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ SetPixel(dc, x, y, color);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+
+ // Update the cursor
+ if (++priv->x > priv->x1) {
+ priv->x = priv->x0;
+ if (++priv->y > priv->y1) {
+ g->flags |= GDISP_FLG_WRAPPED;
+ priv->y = priv->y0;
+ }
+ }
+ }
+ LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
+ if (!(g->flags & GDISP_FLG_WSTREAM))
+ BAD_PARAMETER("write_stop: not in streaming mode");
+ g->flags &= ~GDISP_FLG_WSTREAM;
+ }
+ #if GDISP_HARDWARE_STREAM_POS
+ LLDSPEC void gdisp_lld_write_pos(GDisplay *g) {
+ winPriv * priv;
+
+ priv = g->priv;
+
+ if (!(g->flags & GDISP_FLG_WSTREAM))
+ BAD_PARAMETER("write_pos: not in streaming mode");
+ if (g->p.x < priv->x0 || g->p.x > priv->x1 || g->p.y < priv->y0 || g->p.y > priv->y1)
+ BAD_PARAMETER("write_color: new cursor outside streaming area");
+ priv->x = g->p.x;
+ priv->y = g->p.y;
+ }
+ #endif
+#endif
+
+#if GDISP_HARDWARE_STREAM_READ
+ LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
+ winPriv * priv;
+
+ if (g->flags & GDISP_FLG_WSTREAM)
+ BAD_PARAMETER("read_start: already in streaming mode");
+ if (g->p.cx <= 0 || g->p.cy <= 0 || g->p.x < 0 || g->p.y < 0 || g->p.x+g->p.cx > g->g.Width || g->p.y+g->p.cy > g->g.Height)
+ BAD_PARAMETER("read_start: bad window parameter");
+
+ priv = g->priv;
+ priv->x0 = g->p.x; priv->x1 = g->p.x + g->p.cx - 1;
+ priv->y0 = g->p.y; priv->y1 = g->p.y + g->p.cy - 1;
+ priv->x = g->p.x;
+ priv->y = g->p.y;
+ g->flags |= GDISP_FLG_WSTREAM;
+ g->flags &= ~GDISP_FLG_WRAPPED;
+ }
+ LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
+ winPriv * priv;
+ COLORREF color;
+
+ priv = g->priv;
+
+ if (!(g->flags & GDISP_FLG_WSTREAM))
+ BAD_PARAMETER("read_color: not in streaming mode");
+ if (priv->x < priv->x0 || priv->x > priv->x1 || priv->y < priv->y0 || priv->y > priv->y1)
+ BAD_PARAMETER("read_color: cursor outside streaming area");
+ if (g->flags & GDISP_FLG_WRAPPED) {
+ BAD_PARAMETER("read_color: Warning - Area wrapped.");
+ g->flags &= ~GDISP_FLG_WRAPPED;
+ }
+
+ WaitForSingleObject(drawMutex, INFINITE);
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ color = GetPixel(priv->dcBuffer, priv->x, priv->y);
+ break;
+ case GDISP_ROTATE_90:
+ color = GetPixel(priv->dcBuffer, priv->y, g->g.Width - 1 - priv->x);
+ break;
+ case GDISP_ROTATE_180:
+ color = GetPixel(priv->dcBuffer, g->g.Width - 1 - priv->x, g->g.Height - 1 - priv->y);
+ break;
+ case GDISP_ROTATE_270:
+ color = GetPixel(priv->dcBuffer, g->g.Height - 1 - priv->y, priv->x);
+ break;
+ }
+ #else
+ color = GetPixel(priv->dcBuffer, priv->x, priv->y);
+ #endif
+ ReleaseMutex(drawMutex);
+
+ // Update the cursor
+ if (++priv->x > priv->x1) {
+ priv->x = priv->x0;
+ if (++priv->y > priv->y1) {
+ g->flags |= GDISP_FLG_WRAPPED;
+ priv->y = priv->y0;
+ }
+ }
+
+ return NATIVE2COLOR(color);
+ }
+ LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
+ if (!(g->flags & GDISP_FLG_WSTREAM))
+ BAD_PARAMETER("write_stop: not in streaming mode");
+ g->flags &= ~GDISP_FLG_WSTREAM;
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+ winPriv * priv;
+ int x, y;
+ COLORREF color;
+
+ priv = g->priv;
+ color = COLOR2NATIVE(g->p.color);
+
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = g->g.Width - 1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = g->g.Width - 1 - g->p.x;
+ y = g->g.Height - 1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = g->g.Height - 1 - g->p.y;
+ y = g->p.x;
+ break;
+ }
+ #else
+ x = g->p.x;
+ y = g->p.y;
+ #endif
+
+ // Draw the pixel on the screen and in the buffer.
+ WaitForSingleObject(drawMutex, INFINITE);
+ SetPixel(priv->dcBuffer, x, y, color);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ {
+ RECT r;
+ r.left = x; r.right = x+1;
+ r.top = y; r.bottom = y+1;
+ InvalidateRect(priv->hwnd, &r, FALSE);
+ }
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ SetPixel(dc, x, y, color);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+ }
+#endif
+
+/* ---- Optional Routines ---- */
+
+#if GDISP_HARDWARE_FILLS
+ LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
+ winPriv * priv;
+ RECT rect;
+ HBRUSH hbr;
+ COLORREF color;
+
+ priv = g->priv;
+ color = COLOR2NATIVE(g->p.color);
+ hbr = CreateSolidBrush(color);
+
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ rect.top = g->p.y;
+ rect.bottom = rect.top + g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left + g->p.cx;
+ break;
+ case GDISP_ROTATE_90:
+ rect.bottom = g->g.Width - g->p.x;
+ rect.top = rect.bottom - g->p.cx;
+ rect.left = g->p.y;
+ rect.right = rect.left + g->p.cy;
+ break;
+ case GDISP_ROTATE_180:
+ rect.bottom = g->g.Height - g->p.y;
+ rect.top = rect.bottom - g->p.cy;
+ rect.right = g->g.Width - g->p.x;
+ rect.left = rect.right - g->p.cx;
+ break;
+ case GDISP_ROTATE_270:
+ rect.top = g->p.x;
+ rect.bottom = rect.top + g->p.cx;
+ rect.right = g->g.Height - g->p.y;
+ rect.left = rect.right - g->p.cy;
+ break;
+ }
+ #else
+ rect.top = g->p.y;
+ rect.bottom = rect.top + g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left + g->p.cx;
+ #endif
+
+
+ WaitForSingleObject(drawMutex, INFINITE);
+ FillRect(priv->dcBuffer, &rect, hbr);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ InvalidateRect(priv->hwnd, &rect, FALSE);
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ FillRect(dc, &rect, hbr);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+
+ DeleteObject(hbr);
+ }
+#endif
+
+#if GDISP_HARDWARE_BITFILLS && GDISP_NEED_CONTROL
+ static pixel_t *rotateimg(GDisplay *g, const pixel_t *buffer) {
+ pixel_t *dstbuf;
+ pixel_t *dst;
+ const pixel_t *src;
+ size_t sz;
+ coord_t i, j;
+
+ // Allocate the destination buffer
+ sz = (size_t)g->p.cx * (size_t)g->p.cy;
+ if (!(dstbuf = (pixel_t *)malloc(sz * sizeof(pixel_t))))
+ return 0;
+
+ // Copy the bits we need
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ return 0; // not handled as it doesn't need to be.
+ case GDISP_ROTATE_90:
+ for(src = buffer+g->p.x1, j = 0; j < g->p.cy; j++, src += g->p.x2 - g->p.cx) {
+ dst = dstbuf+sz-g->p.cy+j;
+ for(i = 0; i < g->p.cx; i++, dst -= g->p.cy)
+ *dst = *src++;
+ }
+ break;
+ case GDISP_ROTATE_180:
+ for(dst = dstbuf+sz, src = buffer+g->p.x1, j = 0; j < g->p.cy; j++, src += g->p.x2 - g->p.cx)
+ for(i = 0; i < g->p.cx; i++)
+ *--dst = *src++;
+ break;
+ case GDISP_ROTATE_270:
+ for(src = buffer+g->p.x1, j = 0; j < g->p.cy; j++, src += g->p.x2 - g->p.cx) {
+ dst = dstbuf+g->p.cy-j-1;
+ for(i = 0; i < g->p.cx; i++, dst += g->p.cy)
+ *dst = *src++;
+ }
+ break;
+ }
+ return dstbuf;
+ }
+#endif
+
+#if GDISP_HARDWARE_BITFILLS
+ #if COLOR_SYSTEM != GDISP_COLORSYSTEM_TRUECOLOR || COLOR_TYPE_BITS <= 8
+ #error "GDISP Win32: This driver's bitblit currently only supports true-color with bit depths > 8 bits."
+ #endif
+
+ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
+ winPriv * priv;
+ pixel_t * buffer;
+ RECT rect;
+ BITMAPV4HEADER bmpInfo;
+
+ // Make everything relative to the start of the line
+ priv = g->priv;
+ buffer = g->p.ptr;
+ buffer += g->p.x2*g->p.y1;
+
+ memset(&bmpInfo, 0, sizeof(bmpInfo));
+ bmpInfo.bV4Size = sizeof(bmpInfo);
+ bmpInfo.bV4Planes = 1;
+ bmpInfo.bV4BitCount = COLOR_TYPE_BITS;
+ bmpInfo.bV4AlphaMask = 0;
+ bmpInfo.bV4RedMask = RGB2COLOR(255,0,0);
+ bmpInfo.bV4GreenMask = RGB2COLOR(0,255,0);
+ bmpInfo.bV4BlueMask = RGB2COLOR(0,0,255);
+ bmpInfo.bV4V4Compression = BI_BITFIELDS;
+ bmpInfo.bV4XPelsPerMeter = 3078;
+ bmpInfo.bV4YPelsPerMeter = 3078;
+ bmpInfo.bV4ClrUsed = 0;
+ bmpInfo.bV4ClrImportant = 0;
+ bmpInfo.bV4CSType = 0; //LCS_sRGB;
+
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ bmpInfo.bV4SizeImage = (g->p.cy*g->p.x2) * sizeof(pixel_t);
+ bmpInfo.bV4Width = g->p.x2;
+ bmpInfo.bV4Height = -g->p.cy; /* top-down image */
+ rect.top = g->p.y;
+ rect.bottom = rect.top+g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left+g->p.cx;
+ break;
+ case GDISP_ROTATE_90:
+ if (!(buffer = rotateimg(g, buffer))) return;
+ bmpInfo.bV4SizeImage = (g->p.cy*g->p.cx) * sizeof(pixel_t);
+ bmpInfo.bV4Width = g->p.cy;
+ bmpInfo.bV4Height = -g->p.cx; /* top-down image */
+ rect.bottom = g->g.Width - g->p.x;
+ rect.top = rect.bottom-g->p.cx;
+ rect.left = g->p.y;
+ rect.right = rect.left+g->p.cy;
+ break;
+ case GDISP_ROTATE_180:
+ if (!(buffer = rotateimg(g, buffer))) return;
+ bmpInfo.bV4SizeImage = (g->p.cy*g->p.cx) * sizeof(pixel_t);
+ bmpInfo.bV4Width = g->p.cx;
+ bmpInfo.bV4Height = -g->p.cy; /* top-down image */
+ rect.bottom = g->g.Height-1 - g->p.y;
+ rect.top = rect.bottom-g->p.cy;
+ rect.right = g->g.Width - g->p.x;
+ rect.left = rect.right-g->p.cx;
+ break;
+ case GDISP_ROTATE_270:
+ if (!(buffer = rotateimg(g, buffer))) return;
+ bmpInfo.bV4SizeImage = (g->p.cy*g->p.cx) * sizeof(pixel_t);
+ bmpInfo.bV4Width = g->p.cy;
+ bmpInfo.bV4Height = -g->p.cx; /* top-down image */
+ rect.top = g->p.x;
+ rect.bottom = rect.top+g->p.cx;
+ rect.right = g->g.Height - g->p.y;
+ rect.left = rect.right-g->p.cy;
+ break;
+ }
+ #else
+ bmpInfo.bV4SizeImage = (g->p.cy*g->p.x2) * sizeof(pixel_t);
+ bmpInfo.bV4Width = g->p.x2;
+ bmpInfo.bV4Height = -g->p.cy; /* top-down image */
+ rect.top = g->p.y;
+ rect.bottom = rect.top+g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left+g->p.cx;
+ #endif
+
+ WaitForSingleObject(drawMutex, INFINITE);
+ SetDIBitsToDevice(priv->dcBuffer, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0, 0, 0, rect.bottom-rect.top, buffer, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ InvalidateRect(priv->hwnd, &rect, FALSE);
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ SetDIBitsToDevice(dc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0, 0, 0, rect.bottom-rect.top, buffer, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+
+ #if GDISP_NEED_CONTROL
+ if (buffer != (pixel_t *)g->p.ptr)
+ free(buffer);
+ #endif
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ winPriv * priv;
+ COLORREF color;
+
+ priv = g->priv;
+
+ WaitForSingleObject(drawMutex, INFINITE);
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ color = GetPixel(priv->dcBuffer, g->p.x, g->p.y);
+ break;
+ case GDISP_ROTATE_90:
+ color = GetPixel(priv->dcBuffer, g->p.y, g->g.Width - 1 - g->p.x);
+ break;
+ case GDISP_ROTATE_180:
+ color = GetPixel(priv->dcBuffer, g->g.Width - 1 - g->p.x, g->g.Height - 1 - g->p.y);
+ break;
+ case GDISP_ROTATE_270:
+ color = GetPixel(priv->dcBuffer, g->g.Height - 1 - g->p.y, g->p.x);
+ break;
+ }
+ #else
+ color = GetPixel(priv->dcBuffer, g->p.x, g->p.y);
+ #endif
+ ReleaseMutex(drawMutex);
+
+ return NATIVE2COLOR(color);
+ }
+#endif
+
+#if GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL
+ LLDSPEC void gdisp_lld_vertical_scroll(GDisplay *g) {
+ winPriv * priv;
+ RECT rect;
+ coord_t lines;
+
+ priv = g->priv;
+
+ #if GDISP_NEED_CONTROL
+ switch(g->g.Orientation) {
+ case GDISP_ROTATE_0:
+ rect.top = g->p.y;
+ rect.bottom = rect.top+g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left+g->p.cx;
+ lines = -g->p.y1;
+ goto vertical_scroll;
+ case GDISP_ROTATE_90:
+ rect.bottom = g->g.Width - g->p.x;
+ rect.top = rect.bottom-g->p.cx;
+ rect.left = g->p.y;
+ rect.right = rect.left+g->p.cy;
+ lines = -g->p.y1;
+ goto horizontal_scroll;
+ case GDISP_ROTATE_180:
+ rect.bottom = g->g.Height - g->p.y;
+ rect.top = rect.bottom-g->p.cy;
+ rect.right = g->g.Width - g->p.x;
+ rect.left = rect.right-g->p.cx;
+ lines = g->p.y1;
+ vertical_scroll:
+ if (lines > 0) {
+ rect.bottom -= lines;
+ } else {
+ rect.top -= lines;
+ }
+ if (g->p.cy >= lines && g->p.cy >= -lines) {
+ WaitForSingleObject(drawMutex, INFINITE);
+ ScrollDC(priv->dcBuffer, 0, lines, &rect, 0, 0, 0);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ InvalidateRect(priv->hwnd, &rect, FALSE);
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ ScrollDC(dc, 0, lines, &rect, 0, 0, 0);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+ }
+ break;
+ case GDISP_ROTATE_270:
+ rect.top = g->p.x;
+ rect.bottom = rect.top+g->p.cx;
+ rect.right = g->g.Height - g->p.y;
+ rect.left = rect.right-g->p.cy;
+ lines = g->p.y1;
+ horizontal_scroll:
+ if (lines > 0) {
+ rect.right -= lines;
+ } else {
+ rect.left -= lines;
+ }
+ if (g->p.cy >= lines && g->p.cy >= -lines) {
+ WaitForSingleObject(drawMutex, INFINITE);
+ ScrollDC(priv->dcBuffer, lines, 0, &rect, 0, 0, 0);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ InvalidateRect(priv->hwnd, &rect, FALSE);
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ ScrollDC(dc, lines, 0, &rect, 0, 0, 0);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+ }
+ break;
+ }
+ #else
+ rect.top = g->p.y;
+ rect.bottom = rect.top+g->p.cy;
+ rect.left = g->p.x;
+ rect.right = rect.left+g->p.cx;
+ lines = -g->p.y1;
+ if (lines > 0) {
+ rect.bottom -= lines;
+ } else {
+ rect.top -= lines;
+ }
+ if (g->p.cy >= lines && g->p.cy >= -lines) {
+ WaitForSingleObject(drawMutex, INFINITE);
+ ScrollDC(priv->dcBuffer, 0, lines, &rect, 0, 0, 0);
+ #if GDISP_WIN32_USE_INDIRECT_UPDATE
+ ReleaseMutex(drawMutex);
+ InvalidateRect(priv->hwnd, &rect, FALSE);
+ #else
+ {
+ HDC dc;
+ dc = GetDC(priv->hwnd);
+ ScrollDC(dc, 0, lines, &rect, 0, 0, 0);
+ ReleaseDC(priv->hwnd, dc);
+ ReleaseMutex(drawMutex);
+ }
+ #endif
+ }
+ #endif
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ break;
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+/*
+ case GDISP_CONTROL_POWER:
+ case GDISP_CONTROL_BACKLIGHT:
+ case GDISP_CONTROL_CONTRAST:
+*/
+ }
+ }
+#endif
+
+#if GINPUT_NEED_MOUSE
+ void ginput_lld_mouse_init(void) {}
+ void ginput_lld_mouse_get_reading(MouseReading *pt) {
+ GDisplay * g;
+ winPriv * priv;
+
+ g = mouseDisplay;
+ priv = g->priv;
+
+ pt->x = priv->mousex;
+ pt->y = priv->mousey > g->g.Height ? g->g.Height : priv->mousey;
+ pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
+ pt->buttons = priv->mousebuttons;
+ }
+#endif /* GINPUT_NEED_MOUSE */
+
+#if GINPUT_NEED_TOGGLE
+ #if GINPUT_TOGGLE_CONFIG_ENTRIES > GDISP_DRIVER_COUNT_WIN32
+ #error "GDISP Win32: GINPUT_TOGGLE_CONFIG_ENTRIES must not be greater than GDISP_DRIVER_COUNT_WIN32"
+ #endif
+
+ GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES];
+
+ void ginput_lld_toggle_init(const GToggleConfig *ptc) {
+ // Save the associated window struct
+ ptc->id = &GDISP_WIN32[ptc - GInputToggleConfigTable];
+
+ // We have 8 buttons per window.
+ ptc->mask = 0xFF;
+
+ // No inverse or special mode
+ ptc->invert = 0x00;
+ ptc->mode = 0;
+ }
+ unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc) {
+ return ((GDisplay *)(ptc->id))->priv->toggles;
+ }
+#endif /* GINPUT_NEED_TOGGLE */
+
+#endif /* GFX_USE_GDISP */
+
diff --git a/drivers/multiple/Win32/gdisp_lld_config.h b/drivers/multiple/Win32/gdisp_lld_config.h
index b6fa874a..1554161b 100644
--- a/drivers/multiple/Win32/gdisp_lld_config.h
+++ b/drivers/multiple/Win32/gdisp_lld_config.h
@@ -16,22 +16,44 @@
#ifndef _GDISP_LLD_CONFIG_H
#define _GDISP_LLD_CONFIG_H
-#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
+#if GFX_USE_GDISP
/*===========================================================================*/
/* Driver hardware support. */
/*===========================================================================*/
-
-#define GDISP_DRIVER_NAME "Win32"
-
-#define GDISP_HARDWARE_LINES TRUE
-#define GDISP_HARDWARE_FILLS TRUE
-#define GDISP_HARDWARE_BITFILLS TRUE
-#define GDISP_HARDWARE_SCROLL TRUE
-#define GDISP_HARDWARE_PIXELREAD TRUE
-#define GDISP_HARDWARE_CONTROL TRUE
-
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
+
+// Calling gdispGFlush() is optional for this driver but can be used by the
+// application to force a display update. eg after streaming.
+
+#define GDISP_HARDWARE_FLUSH TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
+
+//#define GDISP_WIN32_STREAMING_TEST
+#ifdef GDISP_WIN32_STREAMING_TEST
+ // These streaming routines are here only to debug the high level gdisp
+ // code for streaming controllers. They are slow, inefficient and have
+ // lots of debugging turned on.
+ #define GDISP_HARDWARE_STREAM_WRITE TRUE
+ #define GDISP_HARDWARE_STREAM_READ TRUE
+ #define GDISP_HARDWARE_STREAM_POS TRUE
+#else
+ // The proper way on the Win32. These routines are nice and fast.
+ #define GDISP_HARDWARE_DRAWPIXEL TRUE
+ #define GDISP_HARDWARE_FILLS TRUE
+ #define GDISP_HARDWARE_PIXELREAD TRUE
+ #define GDISP_HARDWARE_SCROLL TRUE
+
+ // Bit-blits on Win32 are currently only supported for True-Color bit-depths greater than 8 bits
+ // Note: At the time this file is included we have not calculated all our color
+ // definitions so we need to do this by hand.
+ #if !defined(GDISP_PIXELFORMAT)
+ #define GDISP_HARDWARE_BITFILLS TRUE
+ #elif (GDISP_PIXELFORMAT & 0x2000) && (((GDISP_PIXELFORMAT & 0x0F00)>>8)+((GDISP_PIXELFORMAT & 0x00F0)>>4)+((GDISP_PIXELFORMAT & 0x000F))) > 8
+ #define GDISP_HARDWARE_BITFILLS TRUE
+ #endif
+#endif
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_BGR888
#endif /* GFX_USE_GDISP */
diff --git a/drivers/multiple/Win32/ginput_lld_toggle_config.h b/drivers/multiple/Win32/ginput_lld_toggle_config.h
index 2e61d073..dd0c9b5c 100644
--- a/drivers/multiple/Win32/ginput_lld_toggle_config.h
+++ b/drivers/multiple/Win32/ginput_lld_toggle_config.h
@@ -20,9 +20,16 @@
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
-#define GINPUT_TOGGLE_POLL_PERIOD TIME_INFINITE // We are interrupt driven (or polled - ether works here)
-#define GINPUT_TOGGLE_NUM_PORTS 8 // The total number of toggle inputs
-#define GINPUT_TOGGLE_CONFIG_ENTRIES 1 // The total number of GToggleConfig entries
+#define GINPUT_TOGGLE_POLL_PERIOD TIME_INFINITE // We are interrupt driven (or polled - either works here)
+
+// This driver is unique in that it can support 8 buttons per window across multiple windows.
+// GINPUT_TOGGLE_CONFIG_ENTRIES just must be less than the number of GDISP windows (GDISP_DRIVER_COUNT_WIN32).
+#ifndef GINPUT_TOGGLE_CONFIG_ENTRIES
+ #define GINPUT_TOGGLE_CONFIG_ENTRIES 1 // The total number of GToggleConfig entries
+#endif
+
+// The total number of toggle inputs
+#define GINPUT_TOGGLE_NUM_PORTS (8 * GINPUT_TOGGLE_CONFIG_ENTRIES)
#define GINPUT_TOGGLE_SW1 0 // Switch 1 - Toggle
#define GINPUT_TOGGLE_SW2 1 // Switch 2 - Toggle
@@ -33,6 +40,8 @@
#define GINPUT_TOGGLE_MOMENTARY2 5 // Switch 6 - Momentary
#define GINPUT_TOGGLE_MOMENTARY3 6 // Switch 7 - Momentary
#define GINPUT_TOGGLE_MOMENTARY4 7 // Switch 8 - Momentary
+
+// This pattern of switch and momentary action is repeated across all windows.
#endif /* GFX_USE_GDISP && GINPUT_NEED_TOGGLE */
diff --git a/drivers/multiple/Win32/readme.txt b/drivers/multiple/Win32/readme.txt
index 7ff8546c..353f5a5b 100644
--- a/drivers/multiple/Win32/readme.txt
+++ b/drivers/multiple/Win32/readme.txt
@@ -1,14 +1,15 @@
To use this driver:
-This driver is special in that it implements both the gdisp low level driver
-and a touchscreen driver.
+This driver is special in that it implements both the gdisp low level driver,
+optionally a touchscreen driver, and optionally a toggle driver.
1. Add in your gfxconf.h:
a) #define GFX_USE_GDISP TRUE
- b) #define GFX_USE_GINPUT TRUE
- #define GINPUT_USE_MOUSE TRUE
+ b) Optionally #define GFX_USE_GINPUT TRUE
+ #define GINPUT_USE_MOUSE TRUE
+ #define GINPUT_USE_TOGGLE TRUE
c) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD
- d) All of the following (with appropriate values):
+ d) Optionally the following (with appropriate values):
#define GDISP_SCREEN_WIDTH 640
#define GDISP_SCREEN_HEIGHT 480
@@ -17,5 +18,5 @@ and a touchscreen driver.
include $(GFXLIB)/gfx.mk
include $(GFXLIB)/drivers/multiple/Win32/gdisp_lld.mk
-3. Modify your makefile to add -lgdi32 to the DLIBS line. i.e.
+3. Modify your makefile to add -lws2_32 and -lgdi32 to the DLIBS line. i.e.
DLIBS = -lws2_32 -lgdi32
diff --git a/drivers/multiple/X/gdisp_lld.c b/drivers/multiple/X/gdisp_lld.c
deleted file mode 100644
index 13368bc1..00000000
--- a/drivers/multiple/X/gdisp_lld.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/multiple/X/gdisp_lld.c
- * @brief GDISP Graphics Driver subsystem low level driver source for X.
- */
-
-#include "gfx.h"
-
-#if GFX_USE_GDISP
-
-/**
- * Our color model - Default or 24 bit only.
- *
- * At present we don't define this as we don't need to.
- * It may however be useful later if we implement bitblits.
- * As this may be dead code we don't include it in gdisp/options.h
- */
-#ifndef GDISP_FORCE_24BIT
- #define GDISP_FORCE_24BIT FALSE
-#endif
-
-#if GINPUT_NEED_MOUSE
- /* Include mouse support code */
- #include "ginput/lld/mouse.h"
-#endif
-
-/* Include the emulation code for things we don't support */
-#include "gdisp/lld/emulation.c"
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 480
-#endif
-#ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 640
-#endif
-
-Display *dis;
-int scr;
-Window win;
-Pixmap pix;
-XEvent evt;
-GC gc;
-Colormap cmap;
-XVisualInfo vis;
-int depth;
-#if GINPUT_NEED_MOUSE
- coord_t mousex, mousey;
- uint16_t mousebuttons;
-#endif
-
-static void ProcessEvent(void) {
- XColor col;
-
- switch(evt.type) {
- case Expose:
- XCopyArea(dis, pix, win, gc,
- evt.xexpose.x, evt.xexpose.y,
- evt.xexpose.width, evt.xexpose.height,
- evt.xexpose.x, evt.xexpose.y);
- break;
-#if GINPUT_NEED_MOUSE
- case ButtonPress:
- mousex = evt.xbutton.x;
- mousey = evt.xbutton.y;
- switch(evt.xbutton.button){
- case 1: mousebuttons |= GINPUT_MOUSE_BTN_LEFT; break;
- case 2: mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
- case 3: mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; break;
- case 4: mousebuttons |= GINPUT_MOUSE_BTN_4; break;
- }
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
- break;
- case ButtonRelease:
- mousex = evt.xbutton.x;
- mousey = evt.xbutton.y;
- switch(evt.xbutton.button){
- case 1: mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
- case 2: mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
- case 3: mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
- case 4: mousebuttons &= ~GINPUT_MOUSE_BTN_4; break;
- }
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
- break;
- case MotionNotify:
- mousex = evt.xmotion.x;
- mousey = evt.xmotion.y;
- #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
- #endif
- break;
-#endif
- }
-}
-
-/* this is the X11 thread which keeps track of all events */
-static DECLARE_THREAD_STACK(waXThread, 1024);
-static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
- (void)arg;
-
- while(1) {
- gfxSleepMilliseconds(100);
- while(XPending(dis)) {
- XNextEvent(dis, &evt);
- ProcessEvent();
- }
- }
- return 0;
-}
-
-static int FatalXIOError(Display *d) {
- (void) d;
-
- /* The window has closed */
- fprintf(stderr, "GFX Window closed!\n");
- exit(0);
-}
-
-bool_t gdisp_lld_init(void)
-{
- XSizeHints *pSH;
- XSetWindowAttributes xa;
- XTextProperty WindowTitle;
- char * WindowTitleText;
- gfxThreadHandle hth;
-
- #if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
- XInitThreads();
- #endif
-
- dis = XOpenDisplay(NULL);
- scr = DefaultScreen(dis);
-
- #if GDISP_FORCE_24BIT
- if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
- fprintf(stderr, "Your display has no TrueColor mode\n");
- XCloseDisplay(dis);
- return FALSE;
- }
- cmap = XCreateColormap(dis, RootWindow(dis, scr),
- vis.visual, AllocNone);
- #else
- vis.visual = CopyFromParent;
- vis.depth = DefaultDepth(dis, scr);
- cmap = DefaultColormap(dis, scr);
- #endif
- fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);
-
- xa.colormap = cmap;
- xa.border_pixel = 0xFFFFFF;
- xa.background_pixel = 0x000000;
-
- win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
- GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
- 0, vis.depth, InputOutput, vis.visual,
- CWBackPixel|CWColormap|CWBorderPixel, &xa);
- XSync(dis, TRUE);
-
- WindowTitleText = "GFX";
- XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
- XSetWMName(dis, win, &WindowTitle);
- XSetWMIconName(dis, win, &WindowTitle);
- XSync(dis, TRUE);
-
- pSH = XAllocSizeHints();
- pSH->flags = PSize | PMinSize | PMaxSize;
- pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
- pSH->min_height = pSH->max_height = pSH->base_height = GDISP_SCREEN_HEIGHT;
- XSetWMNormalHints(dis, win, pSH);
- XFree(pSH);
- XSync(dis, TRUE);
-
- pix = XCreatePixmap(dis, win,
- GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
- XSync(dis, TRUE);
-
- gc = XCreateGC(dis, win, 0, 0);
- XSetBackground(dis, gc, BlackPixel(dis, scr));
- XSync(dis, TRUE);
-
- XSelectInput(dis, win, StructureNotifyMask);
- XMapWindow(dis, win);
- do { XNextEvent(dis, &evt); } while (evt.type != MapNotify);
-
- /* start the X11 thread */
- XSetIOErrorHandler(FatalXIOError);
- XSelectInput(dis, win,
- ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
-
- if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
- fprintf(stderr, "Cannot start X Thread\n");
- XCloseDisplay(dis);
- exit(0);
- }
- #if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
- pthread_detach(hth);
- #endif
- gfxThreadClose(hth);
-
- /* Initialise the GDISP structure to match */
- GDISP.Orientation = GDISP_ROTATE_0;
- GDISP.Powermode = powerOn;
- GDISP.Backlight = 100;
- GDISP.Contrast = 50;
- GDISP.Width = GDISP_SCREEN_WIDTH;
- GDISP.Height = GDISP_SCREEN_HEIGHT;
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- GDISP.clipx0 = 0;
- GDISP.clipy0 = 0;
- GDISP.clipx1 = GDISP.Width;
- GDISP.clipy1 = GDISP.Height;
- #endif
- return TRUE;
-}
-
-void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color)
-{
- XColor col;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- #endif
-
- col.red = RED_OF(color) << 8;
- col.green = GREEN_OF(color) << 8;
- col.blue = BLUE_OF(color) << 8;
- XAllocColor(dis, cmap, &col);
- XSetForeground(dis, gc, col.pixel);
- XDrawPoint(dis, pix, gc, (int)x, (int)y );
- XDrawPoint(dis, win, gc, (int)x, (int)y );
- XFlush(dis);
-}
-
-void gdisp_lld_fill_area(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- XColor col;
-
- #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
- // Clip pre orientation change
- if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
- if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
- if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
- if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
- if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
- #endif
-
- col.red = RED_OF(color) << 8;
- col.green = GREEN_OF(color) << 8;
- col.blue = BLUE_OF(color) << 8;
- XAllocColor(dis, cmap, &col);
- XSetForeground(dis, gc, col.pixel);
- XFillRectangle(dis, pix, gc, x, y, cx, cy);
- XFillRectangle(dis, win, gc, x, y, cx, cy);
- XFlush(dis);
-}
-
-// Start of Bitblit code
-//XImage bitmap;
-//pixel_t *bits;
-// bits = malloc(vis.depth * GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT);
-// bitmap = XCreateImage(dis, vis, vis.depth, ZPixmap,
-// 0, bits, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
-// 0, 0);
-
-#if GINPUT_NEED_MOUSE
-
- void ginput_lld_mouse_init(void) {}
-
- void ginput_lld_mouse_get_reading(MouseReading *pt) {
- pt->x = mousex;
- pt->y = mousey;
- pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
- pt->buttons = mousebuttons;
- }
-
-#endif /* GINPUT_NEED_MOUSE */
-
-#endif /* GFX_USE_GDISP */
-/** @} */
-
diff --git a/drivers/multiple/X/gdisp_lld.mk b/drivers/multiple/X/gdisp_lld.mk
index 1a4fc4d7..572a5b7d 100644
--- a/drivers/multiple/X/gdisp_lld.mk
+++ b/drivers/multiple/X/gdisp_lld.mk
@@ -1,5 +1,2 @@
-# List the required driver.
-GFXSRC += $(GFXLIB)/drivers/multiple/X/gdisp_lld.c
-
-# Required include directories
GFXINC += $(GFXLIB)/drivers/multiple/X
+GFXSRC += $(GFXLIB)/drivers/multiple/X/gdisp_lld_X.c
diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c
new file mode 100644
index 00000000..c9beb821
--- /dev/null
+++ b/drivers/multiple/X/gdisp_lld_X.c
@@ -0,0 +1,340 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file drivers/multiple/X/gdisp_lld.c
+ * @brief GDISP Graphics Driver subsystem low level driver source for X.
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_X11
+#include "../drivers/multiple/X/gdisp_lld_config.h"
+#include "gdisp/lld/gdisp_lld.h"
+
+/**
+ * Our color model - Default or 24 bit only.
+ *
+ * At present we don't define this as we don't need to.
+ * It may however be useful later if we implement bitblits.
+ * As this may be dead code we don't include it in gdisp/options.h
+ */
+#ifndef GDISP_FORCE_24BIT
+ #define GDISP_FORCE_24BIT FALSE
+#endif
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 480
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 640
+#endif
+
+#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
+
+#if GINPUT_NEED_MOUSE
+ /* Include mouse support code */
+ #include "ginput/lld/mouse.h"
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static bool_t initdone;
+static Display *dis;
+static int scr;
+static XEvent evt;
+static Colormap cmap;
+static XVisualInfo vis;
+static XContext cxt;
+#if GINPUT_NEED_MOUSE
+ coord_t mousex, mousey;
+ uint16_t mousebuttons;
+#endif
+
+typedef struct xPriv {
+ Pixmap pix;
+ GC gc;
+ Window win;
+} xPriv;
+
+static void ProcessEvent(GDisplay *g, xPriv *priv) {
+ switch(evt.type) {
+ case MapNotify:
+ XSelectInput(dis, evt.xmap.window, StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
+ g->flags |= GDISP_FLG_READY;
+ break;
+ case UnmapNotify:
+ XCloseDisplay(dis);
+ exit(0);
+ break;
+ case Expose:
+ XCopyArea(dis, priv->pix, evt.xexpose.window, priv->gc,
+ evt.xexpose.x, evt.xexpose.y,
+ evt.xexpose.width, evt.xexpose.height,
+ evt.xexpose.x, evt.xexpose.y);
+ break;
+#if GINPUT_NEED_MOUSE
+ case ButtonPress:
+ mousex = evt.xbutton.x;
+ mousey = evt.xbutton.y;
+ switch(evt.xbutton.button){
+ case 1: mousebuttons |= GINPUT_MOUSE_BTN_LEFT; break;
+ case 2: mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; break;
+ case 3: mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; break;
+ case 4: mousebuttons |= GINPUT_MOUSE_BTN_4; break;
+ }
+ #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
+ ginputMouseWakeup();
+ #endif
+ break;
+ case ButtonRelease:
+ mousex = evt.xbutton.x;
+ mousey = evt.xbutton.y;
+ switch(evt.xbutton.button){
+ case 1: mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; break;
+ case 2: mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break;
+ case 3: mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; break;
+ case 4: mousebuttons &= ~GINPUT_MOUSE_BTN_4; break;
+ }
+ #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
+ ginputMouseWakeup();
+ #endif
+ break;
+ case MotionNotify:
+ mousex = evt.xmotion.x;
+ mousey = evt.xmotion.y;
+ #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
+ ginputMouseWakeup();
+ #endif
+ break;
+#endif
+ }
+}
+
+/* this is the X11 thread which keeps track of all events */
+static DECLARE_THREAD_STACK(waXThread, 1024);
+static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
+ GDisplay *g;
+ (void)arg;
+
+ while(1) {
+ gfxSleepMilliseconds(100);
+ while(XPending(dis)) {
+ XNextEvent(dis, &evt);
+ XFindContext(evt.xany.display, evt.xany.window, cxt, (XPointer*)&g);
+ ProcessEvent(g, (xPriv *)g->priv);
+ }
+ }
+ return 0;
+}
+
+static int FatalXIOError(Display *d) {
+ (void) d;
+
+ /* The window has closed */
+ fprintf(stderr, "GFX Window closed!\n");
+ exit(0);
+}
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ XSizeHints *pSH;
+ XSetWindowAttributes xa;
+ XTextProperty WindowTitle;
+ char * WindowTitleText;
+ xPriv *priv;
+
+ if (!initdone) {
+ gfxThreadHandle hth;
+
+ initdone = TRUE;
+ #if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
+ XInitThreads();
+ #endif
+
+ dis = XOpenDisplay(NULL);
+ scr = DefaultScreen(dis);
+ cxt = XUniqueContext();
+ XSetIOErrorHandler(FatalXIOError);
+
+ #if GDISP_FORCE_24BIT
+ if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
+ fprintf(stderr, "Your display has no TrueColor mode\n");
+ XCloseDisplay(dis);
+ return FALSE;
+ }
+ cmap = XCreateColormap(dis, RootWindow(dis, scr),
+ vis.visual, AllocNone);
+ #else
+ vis.visual = CopyFromParent;
+ vis.depth = DefaultDepth(dis, scr);
+ cmap = DefaultColormap(dis, scr);
+ #endif
+ fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);
+
+ if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
+ fprintf(stderr, "Cannot start X Thread\n");
+ XCloseDisplay(dis);
+ exit(0);
+ }
+ #if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
+ pthread_detach(hth);
+ #endif
+ gfxThreadClose(hth);
+ }
+
+ g->priv = gfxAlloc(sizeof(xPriv));
+ priv = (xPriv *)g->priv;
+ g->board = 0; // No board interface for this driver
+
+ xa.colormap = cmap;
+ xa.border_pixel = 0xFFFFFF;
+ xa.background_pixel = 0x000000;
+
+ priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
+ GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
+ 0, vis.depth, InputOutput, vis.visual,
+ CWBackPixel|CWColormap|CWBorderPixel, &xa);
+ XSync(dis, TRUE);
+
+ XSaveContext(dis, priv->win, cxt, (XPointer)g);
+
+ {
+ char buf[132];
+ sprintf(buf, "uGFX - %u", g->systemdisplay+1);
+ WindowTitleText = buf;
+ XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
+ XSetWMName(dis, priv->win, &WindowTitle);
+ XSetWMIconName(dis, priv->win, &WindowTitle);
+ XSync(dis, TRUE);
+ }
+
+ pSH = XAllocSizeHints();
+ pSH->flags = PSize | PMinSize | PMaxSize;
+ pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
+ pSH->min_height = pSH->max_height = pSH->base_height = GDISP_SCREEN_HEIGHT;
+ XSetWMNormalHints(dis, priv->win, pSH);
+ XFree(pSH);
+ XSync(dis, TRUE);
+
+ priv->pix = XCreatePixmap(dis, priv->win,
+ GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
+ XSync(dis, TRUE);
+
+ priv->gc = XCreateGC(dis, priv->win, 0, 0);
+ XSetBackground(dis, priv->gc, BlackPixel(dis, scr));
+ XSync(dis, TRUE);
+
+ XSelectInput(dis, priv->win, StructureNotifyMask);
+ XMapWindow(dis, priv->win);
+
+ // Wait for the window creation to complete (for safety)
+ while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
+ gfxSleepMilliseconds(100);
+
+ /* Initialise the GDISP structure to match */
+ g->g.Orientation = GDISP_ROTATE_0;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = 100;
+ g->g.Contrast = 50;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ return TRUE;
+}
+
+LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g)
+{
+ xPriv * priv = (xPriv *)g->priv;
+ XColor col;
+
+ col.red = RED_OF(g->p.color) << 8;
+ col.green = GREEN_OF(g->p.color) << 8;
+ col.blue = BLUE_OF(g->p.color) << 8;
+ XAllocColor(dis, cmap, &col);
+ XSetForeground(dis, priv->gc, col.pixel);
+ XDrawPoint(dis, priv->pix, priv->gc, (int)g->p.x, (int)g->p.y );
+ XDrawPoint(dis, priv->win, priv->gc, (int)g->p.x, (int)g->p.y );
+ XFlush(dis);
+}
+
+#if GDISP_HARDWARE_FILLS
+ LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
+ xPriv * priv = (xPriv *)g->priv;
+ XColor col;
+
+ col.red = RED_OF(g->p.color) << 8;
+ col.green = GREEN_OF(g->p.color) << 8;
+ col.blue = BLUE_OF(g->p.color) << 8;
+ XAllocColor(dis, cmap, &col);
+ XSetForeground(dis, priv->gc, col.pixel);
+ XFillRectangle(dis, priv->pix, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
+ XFillRectangle(dis, priv->win, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
+ XFlush(dis);
+ }
+#endif
+
+#if 0 && GDISP_HARDWARE_BITFILLS
+ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
+ // Start of Bitblit code
+
+ //XImage bitmap;
+ //pixel_t *bits;
+ // bits = malloc(vis.depth * GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT);
+ // bitmap = XCreateImage(dis, vis, vis.depth, ZPixmap,
+ // 0, bits, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
+ // 0, 0);
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ xPriv * priv = (xPriv *)g->priv;
+ XColor color;
+ XImage *img;
+
+ img = XGetImage (dis, priv->pix, g->p.x, g->p.y, 1, 1, AllPlanes, XYPixmap);
+ color.pixel = XGetPixel (img, 0, 0);
+ XFree(img);
+ XQueryColor(dis, cmap, &color);
+ return RGB2COLOR(color.red>>8, color.green>>8, color.blue>>8);
+ }
+#endif
+
+#if GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL
+ LLDSPEC void gdisp_lld_vertical_scroll(GDisplay *g) {
+ xPriv * priv = (xPriv *)g->priv;
+
+ if (g->p.y1 > 0) {
+ XCopyArea(dis, priv->pix, priv->pix, priv->gc, g->p.x, g->p.y+g->p.y1, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
+ XCopyArea(dis, priv->pix, priv->win, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
+ } else {
+ XCopyArea(dis, priv->pix, priv->pix, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
+ XCopyArea(dis, priv->pix, priv->win, priv->gc, g->p.x, g->p.y-g->p.y1, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
+ }
+ }
+#endif
+
+#if GINPUT_NEED_MOUSE
+
+ void ginput_lld_mouse_init(void) {}
+
+ void ginput_lld_mouse_get_reading(MouseReading *pt) {
+ pt->x = mousex;
+ pt->y = mousey;
+ pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0;
+ pt->buttons = mousebuttons;
+ }
+
+#endif /* GINPUT_NEED_MOUSE */
+
+#endif /* GFX_USE_GDISP */
+/** @} */
+
diff --git a/drivers/multiple/X/gdisp_lld_config.h b/drivers/multiple/X/gdisp_lld_config.h
index 0cacc4f8..631ecf46 100644
--- a/drivers/multiple/X/gdisp_lld_config.h
+++ b/drivers/multiple/X/gdisp_lld_config.h
@@ -22,20 +22,14 @@
/* Driver hardware support. */
/*===========================================================================*/
-#define GDISP_DRIVER_NAME "Linux emulator - X11"
-
-#define GDISP_HARDWARE_CLEARS FALSE
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
#define GDISP_HARDWARE_FILLS TRUE
#define GDISP_HARDWARE_BITFILLS FALSE
-#define GDISP_HARDWARE_SCROLL FALSE
-#define GDISP_HARDWARE_PIXELREAD FALSE
+#define GDISP_HARDWARE_SCROLL TRUE
+#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_CONTROL FALSE
-#define GDISP_HARDWARE_CIRCLES FALSE
-#define GDISP_HARDWARE_CIRCLEFILLS FALSE
-#define GDISP_HARDWARE_ARCS FALSE
-#define GDISP_HARDWARE_ARCFILLS FALSE
-#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
#endif /* GFX_USE_GDISP */
diff --git a/drivers/tdisp/HD44780/tdisp_lld.c b/drivers/tdisp/HD44780/tdisp_lld.c
index 2232955c..7b731c34 100644
--- a/drivers/tdisp/HD44780/tdisp_lld.c
+++ b/drivers/tdisp/HD44780/tdisp_lld.c
@@ -17,15 +17,7 @@
#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/
-/* check first if the user has defined his/her own lowlevel-board file */
-#if defined(TDISP_USE_CUSTOM_BOARD) && TDISP_USE_CUSTOM_BOARD
- /* Include the user supplied board definitions */
- #include "tdisp_lld_board.h"
-#elif defined(BOARD_OLIMEX_STM32_E407)
- #include "tdisp_lld_board_olimex_e407.h"
-#elif defined(BOARD_ST_STM32F4_DISCOVERY)
- #include "tdisp_lld_board_example.h"
-#endif
+#include "tdisp_lld_board.h"
/* Controller Specific Properties */
#define CUSTOM_CHAR_COUNT 8
diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h b/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
deleted file mode 100644
index 7eda4e38..00000000
--- a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
- * @brief TDISP driver subsystem board interface for the HD44780 display
- *
- * @addtogroup TDISP
- * @{
- */
-
-#ifndef _TDISP_LLD_BOARD_H
-#define _TDISP_LLD_BOARD_H
-
-/* Configure these to match the hardware connections on your board */
-#define BUS_4BITS FALSE
-#define PORT_DATA GPIOG
-#define PORT_CTRL GPIOE
-#define PIN_RS 0
-#define PIN_RW 1
-#define PIN_EN 2
-
-static void init_board(void) {
- palSetGroupMode(PORT_CTRL, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetGroupMode(PORT_DATA, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palClearPad(PORT_CTRL, PIN_RW);
-}
-
-static void writeToLCD(uint8_t data) {
- palWritePort(PORT_DATA, data);
- palSetPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(1);
- palClearPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(5);
-}
-
-static void write_cmd(uint8_t data) {
- palClearPad(PORT_CTRL, PIN_RS);
- #if BUS_4BITS
- writeToLCD(data>>4);
- #endif
- writeToLCD(data);
-}
-
-static void write_data(uint8_t data) {
- palSetPad(PORT_CTRL, PIN_RS);
- #if BUS_4BITS
- writeToLCD(data>>4);
- #endif
- writeToLCD(data);
-}
-
-#endif /* _TDISP_LLD_BOARD_H */
-/** @} */
-
diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
deleted file mode 100644
index e9a7ae33..00000000
--- a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * This file is subject to the terms of the GFX License. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://ugfx.org/license.html
- */
-
-/**
- * @file drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
- * @brief TDISP driver subsystem board interface for the HD44780 display
- *
- * @addtogroup TDISP
- * @{
- */
-
-#ifndef _TDISP_LLD_BOARD_H
-#define _TDISP_LLD_BOARD_H
-
-/* Configure these to match the hardware connections on your board */
-#define BUS_4BITS TRUE
-
-/* Configure the bitoffset in the dataport so they match with the
- * hardware pins. An offset of 0 means bit0 stays at bit0 of the dataport.
- * If the offset is set to 3, bit0 of the nibble will be positioned at
- * P[A..G]3 of the hardware-port.
- */
-#define hardware_offset 3
-
-/* The port where the data is sent to. In the
- * low-leveldriver het hardware_offset is taken
- * into account. If for example the hardware_offset
- * is set to 3, then de data will be sent to
- * PE3, PE4, PE5 en PE6, if the dataport where GPIOE.
- */
-#define PORT_DATA GPIOE
-
-/* The port used to controle the controle lines of
- * the display.
- */
-#define PORT_CTRL GPIOD
-/* Pin to controle the R/S-line of the display */
-#define PIN_RS 0
-/* Pin to controle the EN-line of the display */
-#define PIN_EN 1
-/* Pin to controle the R/W-pin of the display.
- * If reading of the display is not used disable
- * reading in the gfxconf.h and put a dummy value here
- * as it will not be used.
- */
-#define PIN_RW 7
-
-
-static void init_board(void) {
- /* Initialize the ports for data and controle-lines */
- palSetGroupMode(PORT_CTRL, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetGroupMode(PORT_DATA, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- /* Set alle controle pins to low */
- palClearPad(PORT_CTRL, PIN_RS);
- palClearPad(PORT_CTRL, PIN_EN);
- #if TDISP_NEED_READ
- palClearPad(PORT_CTRL, PIN_RW);
- #endif
-}
-
-/* This is the low-level routine for sending the bits
- * to the LCD-display. This routine shifts
- * the bits so they match the hardware port.
- */
-static void writeToLCD(uint8_t data) {
- palWritePort(PORT_DATA, data<<hardware_offset);
- palSetPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(1);
- palClearPad(PORT_CTRL, PIN_EN);
- /* wait a little while so that de display can process the data */
- gfxSleepMicroseconds(5);
-}
-
-/* Writes a command to the display. The
- * RS-line is pulled low and than the
- * data is send.
- */
-static void write_cmd(uint8_t data) {
- palClearPad(PORT_CTRL, PIN_RS);
- #if BUS_4BITS
- /* first send the high-nibble */
- writeToLCD(data>>4);
- #endif
- /* send the low-nibble */
- #if BUS_4BITS
- /* in 4-bit mode the high-nibble is zeroed out */
- writeToLCD(data & 0x0F);
- #else
- writeToLCD(data);
- #endif
-}
-
-// static void write_initcmd(uint8_t data) {
-// write_cmd(data);
-// }
-
-/* Write data to the display. The
- * RS-line is pulled high and than the
- * data is send.
- */
-static void write_data(uint8_t data) {
- palSetPad(PORT_CTRL, PIN_RS);
- #if BUS_4BITS
- /* first send the high-nibble */
- writeToLCD(data>>4);
- #endif
- /* send the low-nibble */
- #if BUS_4BITS
- /* in 4-bit mode the high-nibble is zeroed out */
- writeToLCD(data & 0x0F);
- #else
- writeToLCD(data);
- #endif
-}
-
-#endif /* _TDISP_LLD_BOARD_H */
-/** @} */
-