Browse Source

AVR RRD works

LPC1768 VIKI2 & RRDFG are working

looks like all SPIs are working

library change

sh1106 locks up

fixed lockup, started I2C SW com

pretty

re-org

restore a few files

make library happy

switched HAL version of rrd

fix travis error

travis error fixes

another travis fix

cleanup

minor update

one more

correct spacing in platformio.ini
Bob-the-Kuhn 6 years ago
parent
commit
0483a7df91
25 changed files with 2711 additions and 369 deletions
  1. 43
    0
      Marlin/src/HAL/HAL_LCD_defines.h
  2. 183
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LCD_I2C_routines.c
  3. 35
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LCD_I2C_routines.h
  4. 46
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LCD_delay.h
  5. 116
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LCD_pin_routines.c
  6. 47
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LCD_pin_routines.h
  7. 58
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_LPC1768_LCD_defines.h
  8. 3
    3
      Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
  9. 1
    0
      Marlin/src/HAL/HAL_LPC1768/HAL_temp.h
  10. 146
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_hw_spi.cpp
  11. 204
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
  12. 283
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction
  13. 164
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
  14. 198
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
  15. 184
    0
      Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_sw_spi.cpp
  16. 82
    0
      Marlin/src/lcd/dogm/HAL_LCD_class_defines.h
  17. 66
    0
      Marlin/src/lcd/dogm/HAL_LCD_com_defines.h
  18. 320
    0
      Marlin/src/lcd/dogm/u8g_dev_ssd1306_sh1106_128x64_I2C.cpp
  19. 229
    0
      Marlin/src/lcd/dogm/u8g_dev_st7565_64128n_HAL.cpp
  20. 202
    0
      Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp
  21. 0
    259
      Marlin/src/lcd/dogm/ultralcd_st7565_u8glib_VIKI.h
  22. 50
    73
      Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp
  23. 5
    0
      Marlin/src/lcd/ultralcd.cpp
  24. 35
    30
      Marlin/src/lcd/ultralcd_impl_DOGM.h
  25. 11
    4
      platformio.ini

+ 43
- 0
Marlin/src/HAL/HAL_LCD_defines.h View File

@@ -0,0 +1,43 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+#ifndef HAL_LCD_DEFINES_H_
25
+#define HAL_LCD_DEFINES_H_
26
+
27
+#ifdef ARDUINO_ARCH_SAM
28
+//  #include "HAL_DUE/HAL_DUE_LCD_defines.h"
29
+
30
+#elif defined(IS_32BIT_TEENSY)
31
+//  #include "HAL_TEENSY35_36/HAL_TEENSY_LCD_defines.h"
32
+
33
+#elif defined(ARDUINO_ARCH_AVR)
34
+//  #include "HAL_AVR/HAL_ARDUINO_LCD_defines.h"
35
+
36
+#elif defined(TARGET_LPC1768)
37
+  #include "HAL_LPC1768/HAL_LPC1768_LCD_defines.h"
38
+
39
+#else
40
+  #error "Unsupported Platform!"
41
+#endif
42
+
43
+#endif // HAL_LCD_DEFINES_H_

+ 183
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LCD_I2C_routines.c View File

@@ -0,0 +1,183 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+// adapted from  I2C/master/master.c example
24
+//   https://www-users.cs.york.ac.uk/~pcc/MCP/HAPR-Course-web/CMSIS/examples/html/master_8c_source.html
25
+
26
+
27
+
28
+#if defined(TARGET_LPC1768)
29
+
30
+  #ifdef __cplusplus
31
+    extern "C" {
32
+  #endif
33
+
34
+  #include <lpc17xx_i2c.h>
35
+  #include <lpc17xx_pinsel.h>
36
+  #include <lpc17xx_libcfg_default.h>
37
+
38
+  //////////////////////////////////////////////////////////////////////////////////////
39
+
40
+  // These two routines are exact copies of the lpc17xx_i2c.c routines.  Couldn't link to
41
+  // to the lpc17xx_i2c.c routines so had to copy them into this file & rename them.
42
+
43
+  static uint32_t _I2C_Start (LPC_I2C_TypeDef *I2Cx)
44
+  {
45
+    // Reset STA, STO, SI
46
+    I2Cx->I2CONCLR = I2C_I2CONCLR_SIC|I2C_I2CONCLR_STOC|I2C_I2CONCLR_STAC;
47
+
48
+    // Enter to Master Transmitter mode
49
+    I2Cx->I2CONSET = I2C_I2CONSET_STA;
50
+
51
+    // Wait for complete
52
+    while (!(I2Cx->I2CONSET & I2C_I2CONSET_SI));
53
+    I2Cx->I2CONCLR = I2C_I2CONCLR_STAC;
54
+    return (I2Cx->I2STAT & I2C_STAT_CODE_BITMASK);
55
+  }
56
+
57
+  static void _I2C_Stop (LPC_I2C_TypeDef *I2Cx)
58
+  {
59
+
60
+    /* Make sure start bit is not active */
61
+    if (I2Cx->I2CONSET & I2C_I2CONSET_STA)
62
+    {
63
+      I2Cx->I2CONCLR = I2C_I2CONCLR_STAC;
64
+    }
65
+
66
+    I2Cx->I2CONSET = I2C_I2CONSET_STO|I2C_I2CONSET_AA;
67
+
68
+    I2Cx->I2CONCLR = I2C_I2CONCLR_SIC;
69
+  }
70
+
71
+
72
+  //////////////////////////////////////////////////////////////////////////////////////
73
+
74
+  #define U8G_I2C_OPT_FAST 16  // from u8g.h
75
+
76
+  #define USEDI2CDEV_M            1
77
+
78
+  #define I2CDEV_S_ADDR   0x78  // from SSD1306  //actual address is 0x3C - shift left 1 with LSB set to 0 to indicate write
79
+
80
+  #define BUFFER_SIZE                     0x1  // only do single byte transfers with LCDs
81
+
82
+  #if (USEDI2CDEV_M == 0)
83
+    #define I2CDEV_M LPC_I2C0
84
+  #elif (USEDI2CDEV_M == 1)
85
+    #define I2CDEV_M LPC_I2C1
86
+  #elif (USEDI2CDEV_M == 2)
87
+    #define I2CDEV_M LPC_I2C2
88
+  #else
89
+    #error "Master I2C device not defined!"
90
+  #endif
91
+
92
+
93
+  PINSEL_CFG_Type PinCfg;
94
+  I2C_M_SETUP_Type transferMCfg;
95
+
96
+  #define I2C_status (LPC_I2C1->I2STAT & I2C_STAT_CODE_BITMASK)
97
+
98
+
99
+  uint8_t u8g_i2c_start(uint8_t sla) {  // send slave address and write bit
100
+    // Sometimes TX data ACK or NAK status is returned.  That mean the start state didn't
101
+    // happen which means only the value of the slave address was send.  Keep looping until
102
+    // the slave address and write bit are actually sent.
103
+    do{
104
+      _I2C_Stop(I2CDEV_M); // output stop state on I2C bus
105
+      _I2C_Start(I2CDEV_M); // output start state on I2C bus
106
+      while ((I2C_status != I2C_I2STAT_M_TX_START)
107
+          && (I2C_status != I2C_I2STAT_M_TX_RESTART)
108
+          && (I2C_status != I2C_I2STAT_M_TX_DAT_ACK)
109
+          && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK));  //wait for start to be asserted
110
+
111
+      LPC_I2C1->I2CONCLR = I2C_I2CONCLR_STAC; // clear start state before tansmitting slave address
112
+      LPC_I2C1->I2DAT = I2CDEV_S_ADDR & I2C_I2DAT_BITMASK; // transmit slave address & write bit
113
+      LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
114
+      LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
115
+      while ((I2C_status != I2C_I2STAT_M_TX_SLAW_ACK)
116
+          && (I2C_status != I2C_I2STAT_M_TX_SLAW_NACK)
117
+          && (I2C_status != I2C_I2STAT_M_TX_DAT_ACK)
118
+          && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK));  //wait for slaw to finish
119
+    }while ( (I2C_status == I2C_I2STAT_M_TX_DAT_ACK) ||  (I2C_status == I2C_I2STAT_M_TX_DAT_NACK));
120
+    return 1;
121
+  }
122
+
123
+
124
+  void u8g_i2c_init(uint8_t clock_option) {
125
+
126
+    /*
127
+      * Init I2C pin connect
128
+    */
129
+    PinCfg.OpenDrain = 0;
130
+    PinCfg.Pinmode = 0;
131
+    #if ((USEDI2CDEV_M == 0))
132
+      PinCfg.Funcnum = 1;
133
+      PinCfg.Pinnum = 27;
134
+      PinCfg.Portnum = 0;
135
+      PINSEL_ConfigPin(&PinCfg); // SDA0 / D57  AUX-1
136
+      PinCfg.Pinnum = 28;
137
+      PINSEL_ConfigPin(&PinCfg); // SCL0 / D58  AUX-1
138
+    #endif
139
+    #if ((USEDI2CDEV_M == 1))
140
+      PinCfg.Funcnum = 3;
141
+      PinCfg.Pinnum = 0;
142
+      PinCfg.Portnum = 0;
143
+      PINSEL_ConfigPin(&PinCfg);  // SDA1 / D20 SCA
144
+      PinCfg.Pinnum = 1;
145
+      PINSEL_ConfigPin(&PinCfg);  // SCL1 / D21 SCL
146
+    #endif
147
+    #if ((USEDI2CDEV_M == 2))
148
+      PinCfg.Funcnum = 2;
149
+      PinCfg.Pinnum = 10;
150
+      PinCfg.Portnum = 0;
151
+      PINSEL_ConfigPin(&PinCfg); // SDA2 / D38  X_ENABLE_PIN
152
+      PinCfg.Pinnum = 11;
153
+      PINSEL_ConfigPin(&PinCfg); // SCL2 / D55  X_DIR_PIN
154
+    #endif
155
+    // Initialize I2C peripheral
156
+    I2C_Init(I2CDEV_M, (clock_option & U8G_I2C_OPT_FAST) ? 400000: 100000);  // LCD data rates
157
+
158
+    /* Enable Master I2C operation */
159
+    I2C_Cmd(I2CDEV_M, I2C_MASTER_MODE, ENABLE);
160
+
161
+    u8g_i2c_start(0); // send slave address and write bit
162
+  }
163
+
164
+  volatile extern uint32_t _millis;
165
+  uint8_t u8g_i2c_send_byte(uint8_t data) {
166
+    #define I2C_TIMEOUT 3
167
+    LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
168
+    LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
169
+    LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
170
+    uint32_t timeout = _millis + I2C_TIMEOUT;
171
+    while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && (timeout > _millis));  // wait for xmit to finish
172
+    // had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
173
+    return 1;
174
+  }
175
+
176
+  void u8g_i2c_stop(void) {
177
+  }
178
+
179
+
180
+  #ifdef __cplusplus
181
+    }
182
+  #endif
183
+#endif

+ 35
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LCD_I2C_routines.h View File

@@ -0,0 +1,35 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#if defined(TARGET_LPC1768)
24
+
25
+   void u8g_i2c_init(uint8_t options);
26
+
27
+  uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos);
28
+
29
+  uint8_t u8g_i2c_start(uint8_t sla);
30
+
31
+  uint8_t u8g_i2c_send_byte(uint8_t data);
32
+
33
+  void u8g_i2c_stop(void);
34
+
35
+#endif

+ 46
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LCD_delay.h View File

@@ -0,0 +1,46 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * LCD delay routines - used by all the drivers.
25
+ *
26
+ * These are based on the LPC1768 routines.
27
+ *
28
+ * Couldn't just call exact copies because the overhead resulted in the
29
+ * one microsecond delay being about 4uS.
30
+ */
31
+
32
+
33
+
34
+#ifdef __cplusplus
35
+  extern "C" {
36
+#endif
37
+
38
+void U8g_delay(int msec);
39
+
40
+void u8g_MicroDelay(void);
41
+
42
+void u8g_10MicroDelay(void);
43
+
44
+#ifdef __cplusplus
45
+  }
46
+#endif

+ 116
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LCD_pin_routines.c View File

@@ -0,0 +1,116 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Low level pin manipulation routines - used by all the drivers.
25
+ *
26
+ * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines.
27
+ *
28
+ * Couldn't just call exact copies because the overhead killed the LCD update speed
29
+ * With an intermediate level the softspi was running in the 10-20kHz range which
30
+ * resulted in using about about 25% of the CPU's time.
31
+ */
32
+
33
+#if defined(TARGET_LPC1768)
34
+
35
+  #include <LPC17xx.h>
36
+  #include <lpc17xx_pinsel.h>
37
+  #include "src/core/macros.h"
38
+//  #include "pinmapping.h"
39
+
40
+  #define LPC_PORT_OFFSET         (0x0020)
41
+  #define LPC_PIN(pin)            (1UL << pin)
42
+  #define LPC_GPIO(port)          ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))
43
+
44
+  #define INPUT 0
45
+  #define OUTPUT 1
46
+  #define INPUT_PULLUP 2
47
+
48
+
49
+uint8_t LPC1768_PIN_PORT(const uint8_t pin);
50
+uint8_t LPC1768_PIN_PIN(const uint8_t pin);
51
+
52
+  #ifdef __cplusplus
53
+      extern "C" {
54
+  #endif
55
+
56
+// IO functions
57
+// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
58
+void pinMode_LCD(uint8_t pin, uint8_t mode) {
59
+#define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
60
+#define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
61
+  PINSEL_CFG_Type config = { LPC1768_PIN_PORT(pin),
62
+                             LPC1768_PIN_PIN(pin),
63
+                             PINSEL_FUNC_0,
64
+                             PINSEL_PINMODE_TRISTATE,
65
+                             PINSEL_PINMODE_NORMAL };
66
+  switch(mode) {
67
+  case INPUT:
68
+    LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
69
+    PINSEL_ConfigPin(&config);
70
+    break;
71
+  case OUTPUT:
72
+    LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR |=  LPC_PIN(LPC1768_PIN_PIN(pin));
73
+    PINSEL_ConfigPin(&config);
74
+    break;
75
+  case INPUT_PULLUP:
76
+    LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
77
+    config.Pinmode = PINSEL_PINMODE_PULLUP;
78
+    PINSEL_ConfigPin(&config);
79
+    break;
80
+  default:
81
+    break;
82
+  }
83
+}
84
+
85
+
86
+  void u8g_SetPinOutput(uint8_t internal_pin_number) {
87
+     pinMode_LCD(internal_pin_number, 1);  // OUTPUT
88
+  }
89
+
90
+  void u8g_SetPinInput(uint8_t internal_pin_number) {
91
+     pinMode_LCD(internal_pin_number, 0);  // INPUT
92
+  }
93
+
94
+
95
+
96
+  void u8g_SetPinLevel(uint8_t  pin, uint8_t  pin_status) {
97
+#define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
98
+#define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
99
+    if (pin_status)
100
+      LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOSET = LPC_PIN(LPC1768_PIN_PIN(pin));
101
+    else
102
+      LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(pin));
103
+  }
104
+
105
+  uint8_t u8g_GetPinLevel(uint8_t pin) {
106
+#define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
107
+#define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
108
+    return (uint32_t)LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(pin)) ? 1 : 0;
109
+  }
110
+
111
+
112
+  #ifdef __cplusplus
113
+    }
114
+  #endif
115
+
116
+#endif

+ 47
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LCD_pin_routines.h View File

@@ -0,0 +1,47 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Low level pin manipulation routines - used by all the drivers.
25
+ *
26
+ * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines.
27
+ *
28
+ * Couldn't just call exact copies because the overhead killed the LCD update speed
29
+ * With an intermediate level the softspi was running in the 10-20kHz range which
30
+ * resulted in using about about 25% of the CPU's time.
31
+ */
32
+
33
+
34
+
35
+
36
+
37
+void u8g_SetPinOutput(uint8_t internal_pin_number);
38
+
39
+void u8g_SetPinInput(uint8_t internal_pin_number);
40
+
41
+void u8g_SetPinLevel(uint8_t  pin, uint8_t  pin_status);
42
+
43
+uint8_t u8g_GetPinLevel(uint8_t pin);
44
+
45
+
46
+
47
+

+ 58
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_LPC1768_LCD_defines.h View File

@@ -0,0 +1,58 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+* LPC1768 LCD specific defines
25
+*/
26
+
27
+#if defined(TARGET_LPC1768)
28
+
29
+  // pointers to low level routines - must always supply these
30
+//  #define U8G_HAL_LINKS
31
+  #define HAL_LCD_pin_routines "HAL_LPC1768/HAL_LCD_pin_routines.h"
32
+  #define HAL_LCD_I2C_routines  "HAL_LPC1768/HAL_LCD_I2C_routines.h"
33
+  #define HAL_LCD_delay "HAL_LPC1768/HAL_LCD_delay.h"
34
+
35
+  // The following are optional depending on the platform.
36
+
37
+  // definitions of HAL specific com and device drivers.
38
+  uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
39
+  uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
40
+  uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
41
+  uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
42
+  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
43
+
44
+
45
+  // connect U8g com generic com names to the desired driver
46
+  #define U8G_COM_HW_SPI u8g_com_HAL_LPC1768_hw_spi_fn  // use LPC1768 specific hardware SPI routine
47
+  #define U8G_COM_SW_SPI u8g_com_HAL_LPC1768_sw_spi_fn  // use LPC1768 specific software SPI routine
48
+  #define U8G_COM_ST7920_HW_SPI u8g_com_HAL_LPC1768_ST7920_hw_spi_fn
49
+  #define U8G_COM_ST7920_SW_SPI u8g_com_HAL_LPC1768_ST7920_sw_spi_fn
50
+  #define U8G_COM_SSD_I2C u8g_com_HAL_LPC1768_ssd_hw_i2c_fn
51
+
52
+  // let these default for now
53
+  #define U8G_COM_PARALLEL u8g_com_null_fn
54
+  #define U8G_COM_T6963 u8g_com_null_fn
55
+  #define U8G_COM_FAST_PARALLEL u8g_com_null_fn
56
+  #define U8G_COM_UC_I2C u8g_com_null_fn
57
+
58
+#endif

+ 3
- 3
Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp View File

@@ -104,14 +104,14 @@
104 104
     else if (SPI_speed == 1) { // medium - about 1 MHz
105 105
       for (int bits = 0; bits < 8; bits++) {
106 106
         if (b & 0x80) {
107
-          for (uint8_t i = 0; i < 8; i++) WRITE(MOSI_PIN, HIGH);
107
+          for (uint8_t i = 0; i < 9; i++) WRITE(MOSI_PIN, HIGH);
108 108
         }
109 109
         else {
110
-          for (uint8_t i = 0; i < 8; i++) WRITE(MOSI_PIN, LOW);
110
+          for (uint8_t i = 0; i < 9; i++) WRITE(MOSI_PIN, LOW);
111 111
         }
112 112
         b <<= 1;
113 113
 
114
-        for (uint8_t i = 0; i < 6; i++) WRITE(SCK_PIN, HIGH);
114
+        for (uint8_t i = 0; i < 7; i++) WRITE(SCK_PIN, HIGH);
115 115
 
116 116
         if (READ(MISO_PIN)) {
117 117
           b |= 1;

+ 1
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_temp.h View File

@@ -0,0 +1 @@
1
+// blank file needed until I get platformio to update it's copy of U8Glib-HAL

+ 146
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_hw_spi.cpp View File

@@ -0,0 +1,146 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+/*
25
+
26
+  based on u8g_com_msp430_hw_spi.c
27
+
28
+  Universal 8bit Graphics Library
29
+
30
+  Copyright (c) 2012, olikraus@gmail.com
31
+  All rights reserved.
32
+
33
+  Redistribution and use in source and binary forms, with or without modification,
34
+  are permitted provided that the following conditions are met:
35
+
36
+  * Redistributions of source code must retain the above copyright notice, this list
37
+  of conditions and the following disclaimer.
38
+
39
+  * Redistributions in binary form must reproduce the above copyright notice, this
40
+  list of conditions and the following disclaimer in the documentation and/or other
41
+  materials provided with the distribution.
42
+
43
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
44
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
46
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
48
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+
57
+*/
58
+
59
+
60
+#ifdef TARGET_LPC1768
61
+
62
+//  #include <inttypes.h>
63
+
64
+//  #include "src/core/macros.h"
65
+//  #include "Configuration.h"
66
+
67
+  #include <lib/u8g.h>
68
+
69
+  #define SPI_FULL_SPEED 0
70
+  #define SPI_HALF_SPEED 1
71
+  #define SPI_QUARTER_SPEED 2
72
+  #define SPI_EIGHTH_SPEED 3
73
+  #define SPI_SIXTEENTH_SPEED 4
74
+  #define SPI_SPEED_5 5
75
+  #define SPI_SPEED_6 6
76
+
77
+  void spiBegin();
78
+  void spiInit(uint8_t spiRate);
79
+  void spiSend(uint8_t b);
80
+  void spiSend(const uint8_t* buf, size_t n);
81
+
82
+
83
+  uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
84
+  {
85
+    switch(msg)
86
+    {
87
+      case U8G_COM_MSG_STOP:
88
+        break;
89
+
90
+      case U8G_COM_MSG_INIT:
91
+        u8g_SetPILevel(u8g, U8G_PI_CS, 1);
92
+        u8g_SetPILevel(u8g, U8G_PI_A0, 1);
93
+        u8g_SetPILevel(u8g, U8G_PI_RESET, 1);
94
+        u8g_SetPIOutput(u8g, U8G_PI_CS);
95
+        u8g_SetPIOutput(u8g, U8G_PI_A0);
96
+        u8g_SetPIOutput(u8g, U8G_PI_RESET);
97
+        u8g_Delay(5);
98
+        spiBegin();
99
+        #ifndef SPI_SPEED
100
+          #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
101
+        #endif
102
+        spiInit(SPI_SPEED);
103
+        break;
104
+
105
+      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
106
+        u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
107
+        break;
108
+
109
+      case U8G_COM_MSG_CHIP_SELECT:
110
+        u8g_SetPILevel(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
111
+        break;
112
+
113
+      case U8G_COM_MSG_RESET:
114
+        u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
115
+        break;
116
+
117
+      case U8G_COM_MSG_WRITE_BYTE:
118
+        spiSend((uint8_t)arg_val);
119
+        break;
120
+
121
+      case U8G_COM_MSG_WRITE_SEQ:
122
+        {
123
+          uint8_t *ptr = (uint8_t*) arg_ptr;
124
+          while( arg_val > 0 )
125
+          {
126
+            spiSend(*ptr++);
127
+            arg_val--;
128
+          }
129
+        }
130
+        break;
131
+
132
+      case U8G_COM_MSG_WRITE_SEQ_P:
133
+        {
134
+          uint8_t *ptr = (uint8_t*) arg_ptr;
135
+          while( arg_val > 0 )
136
+          {
137
+            spiSend(*ptr++);
138
+            arg_val--;
139
+          }
140
+        }
141
+        break;
142
+    }
143
+    return 1;
144
+  }
145
+
146
+#endif  //TARGET_LPC1768

+ 204
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp View File

@@ -0,0 +1,204 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+/*
25
+
26
+  based on u8g_com_arduino_ssd_i2c.c
27
+
28
+  com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
29
+  I2C protocol
30
+
31
+  ToDo: Rename this to u8g_com_avr_ssd_i2c.c
32
+
33
+  Universal 8bit Graphics Library
34
+
35
+  Copyright (c) 2012, olikraus@gmail.com
36
+  All rights reserved.
37
+
38
+  Redistribution and use in source and binary forms, with or without modification,
39
+  are permitted provided that the following conditions are met:
40
+
41
+  * Redistributions of source code must retain the above copyright notice, this list
42
+  of conditions and the following disclaimer.
43
+
44
+  * Redistributions in binary form must reproduce the above copyright notice, this
45
+  list of conditions and the following disclaimer in the documentation and/or other
46
+  materials provided with the distribution.
47
+
48
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
49
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
50
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
51
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
53
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
58
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61
+
62
+  Special pin usage:
63
+  U8G_PI_I2C_OPTION additional options
64
+  U8G_PI_A0_STATE used to store the last value of the command/data register selection
65
+  U8G_PI_SET_A0   1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
66
+  U8G_PI_SCL    clock line (NOT USED)
67
+  U8G_PI_SDA    data line (NOT USED)
68
+
69
+  U8G_PI_RESET    reset line (currently disabled, see below)
70
+
71
+  Protocol:
72
+  SLA, Cmd/Data Selection, Arguments
73
+  The command/data register is selected by a special instruction byte, which is sent after SLA
74
+
75
+  The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
76
+*/
77
+
78
+#ifdef TARGET_LPC1768
79
+
80
+  #include <lib/u8g.h>
81
+
82
+  #define I2C_SLA         (0x3c*2)
83
+  //#define I2C_CMD_MODE  0x080
84
+  #define I2C_CMD_MODE    0x000
85
+  #define I2C_DATA_MODE   0x040
86
+
87
+//    #define U8G_I2C_OPT_FAST 16
88
+
89
+  uint8_t  u8g_com_ssd_I2C_start_sequence(u8g_t *u8g)
90
+  {
91
+    /* are we requested to set the a0 state? */
92
+    if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
93
+      return 1;
94
+
95
+    /* setup bus, might be a repeated start */
96
+    if ( u8g_i2c_start(I2C_SLA) == 0 )
97
+      return 0;
98
+    if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
99
+    {
100
+      if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
101
+        return 0;
102
+    }
103
+    else
104
+    {
105
+      if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
106
+        return 0;
107
+    }
108
+
109
+    u8g->pin_list[U8G_PI_SET_A0] = 0;
110
+      return 1;
111
+  }
112
+
113
+  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
114
+  {
115
+    switch(msg)
116
+    {
117
+      case U8G_COM_MSG_INIT:
118
+        //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
119
+        //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
120
+        //u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: unknown mode */
121
+
122
+        u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
123
+        u8g_com_ssd_I2C_start_sequence(u8g);
124
+        break;
125
+
126
+      case U8G_COM_MSG_STOP:
127
+        break;
128
+
129
+      case U8G_COM_MSG_RESET:
130
+        /* Currently disabled, but it could be enable. Previous restrictions have been removed */
131
+        /* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
132
+        break;
133
+
134
+      case U8G_COM_MSG_CHIP_SELECT:
135
+        u8g->pin_list[U8G_PI_A0_STATE] = 0;
136
+        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
137
+        if ( arg_val == 0 )
138
+        {
139
+          /* disable chip, send stop condition */
140
+          u8g_i2c_stop();
141
+        }
142
+        else
143
+        {
144
+          /* enable, do nothing: any byte writing will trigger the i2c start */
145
+        }
146
+        break;
147
+
148
+      case U8G_COM_MSG_WRITE_BYTE:
149
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
150
+//          if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
151
+//            return u8g_i2c_stop(), 0;
152
+        if ( u8g_i2c_send_byte(arg_val) == 0 )
153
+          return u8g_i2c_stop(), 0;
154
+        // u8g_i2c_stop();
155
+        break;
156
+
157
+      case U8G_COM_MSG_WRITE_SEQ:
158
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
159
+        if ( u8g_com_ssd_I2C_start_sequence(u8g) == 0 )
160
+          return u8g_i2c_stop(), 0;
161
+        {
162
+          register uint8_t *ptr = (uint8_t *)arg_ptr;
163
+          while( arg_val > 0 )
164
+          {
165
+            if ( u8g_i2c_send_byte(*ptr++) == 0 )
166
+              return u8g_i2c_stop(), 0;
167
+            arg_val--;
168
+          }
169
+        }
170
+        // u8g_i2c_stop();
171
+        break;
172
+
173
+      case U8G_COM_MSG_WRITE_SEQ_P:
174
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
175
+        if ( u8g_com_ssd_I2C_start_sequence(u8g) == 0 )
176
+          return u8g_i2c_stop(), 0;
177
+        {
178
+          register uint8_t *ptr = (uint8_t *)arg_ptr;
179
+          while( arg_val > 0 )
180
+          {
181
+            if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
182
+              return 0;
183
+            ptr++;
184
+            arg_val--;
185
+          }
186
+        }
187
+        // u8g_i2c_stop();
188
+        break;
189
+
190
+      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
191
+        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
192
+        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
193
+
194
+        u8g_i2c_start(0); // send slave address and write bit
195
+        if (arg_val)
196
+          u8g_i2c_send_byte(0x40);  // write to graphics DRAM mode
197
+        else
198
+          u8g_i2c_send_byte(0x80);  //command mode
199
+        break;
200
+    }
201
+    return 1;
202
+  }
203
+
204
+#endif // TARGET_LPC1768

+ 283
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction View File

@@ -0,0 +1,283 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*  based on U8G2 code
24
+
25
+  u8x8_byte.c
26
+
27
+  Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
28
+
29
+  Copyright (c) 2016, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+
57
+*/
58
+
59
+/*
60
+  software i2c,
61
+  ignores ACK response (which is anyway not provided by some displays)
62
+  also does not allow reading from the device
63
+*/
64
+
65
+#ifdef TARGET_LPC1768
66
+
67
+  #include <lib/u8g.h>
68
+
69
+void delayMicroseconds(uint32_t us);
70
+//void pinMode(int16_t pin, uint8_t mode);
71
+//void digitalWrite(int16_t pin, uint8_t pin_status);
72
+
73
+
74
+  #define I2C_SLA         (0x3c*2)
75
+  //#define I2C_CMD_MODE  0x080
76
+  #define I2C_CMD_MODE    0x000
77
+  #define I2C_DATA_MODE   0x040
78
+
79
+//static uint8_t I2C_speed; // 3 - 400KHz, 13 - 100KHz
80
+//#define SPEED_400KHz 3
81
+//#define SPEED_100KHz 13
82
+
83
+
84
+//    #define U8G_I2C_OPT_FAST 16
85
+
86
+
87
+
88
+uint8_t SCL_pin_HAL_LPC1768_sw_I2C, SCL_port_HAL_LPC1768_sw_I2C, SDA_pin_HAL_LPC1768_sw_I2C, SDA_port_HAL_LPC1768_sw_I2C;
89
+
90
+#define SPI_SPEED 2  //20: 200KHz 5:750KHz 2:3-4MHz
91
+
92
+uint8_t u8g_i2c_send_byte_sw(uint8_t data) {
93
+{
94
+  for (uint8_t i = 0; i < 9; i++) {   // 1 extra bit for the ack/nak
95
+
96
+    if (val & 0x80)
97
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
98
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
99
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
100
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
101
+      }
102
+    else
103
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
104
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
105
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
106
+        LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
107
+      }
108
+
109
+    for (uint8_t j = 0; j < SPI_SPEED; j++) {
110
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
111
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
112
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
113
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
114
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
115
+    }
116
+
117
+    for (uint8_t j = 0; j < SPI_SPEED; j++) {
118
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
119
+      LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
120
+    }
121
+    val = val << 1;
122
+  }
123
+  return 1;
124
+}
125
+
126
+
127
+uint8_t u8g_i2c_start_sw(uint8_t sla) {  // assert start condition and then send slave address with write bit
128
+{
129
+  /* send the start condition, both lines go from 1 to 0 */
130
+
131
+  LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
132
+  LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
133
+  delayMicroseconds(2);
134
+  LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
135
+  delayMicroseconds(2);
136
+  LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
137
+  delayMicroseconds(2);
138
+  LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
139
+  delayMicroseconds(2);
140
+  LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
141
+
142
+  u8g_i2c_send_byte_sw(I2C_SLA);  // send slave address with write bit
143
+}
144
+
145
+
146
+void u8g_i2c_stop_sw(void) {
147
+}
148
+
149
+void u8g_i2c_init_sw(uint8_t clock_option) {
150
+  u8g_i2c_start(0); // send slave address and write bit
151
+}
152
+
153
+
154
+
155
+  uint8_t  u8g_com_ssd_I2C_start_sequence_sw(u8g_t *u8g)
156
+  {
157
+    /* are we requested to set the a0 state? */
158
+    if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
159
+      return 1;
160
+
161
+    /* setup bus, might be a repeated start */
162
+    if ( u8g_i2c_start(I2C_SLA) == 0 )
163
+      return 0;
164
+    if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
165
+    {
166
+      if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
167
+        return 0;
168
+    }
169
+    else
170
+    {
171
+      if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
172
+        return 0;
173
+    }
174
+
175
+    u8g->pin_list[U8G_PI_SET_A0] = 0;
176
+      return 1;
177
+  }
178
+
179
+  uint8_t u8g_com_HAL_LPC1768_ssd_sw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
180
+  {
181
+    switch(msg)
182
+    {
183
+      case U8G_COM_MSG_INIT:
184
+
185
+        #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
186
+        #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
187
+        SCL_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCL]);
188
+        SCL_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCL]);
189
+        SDA_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SDA]);
190
+        SDA_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SDA]);
191
+        // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
192
+        #define OUPUT 0x1
193
+        u8g_SetPIOutput(u8g, U8G_PI_SCL);
194
+        u8g_SetPIOutput(u8g, U8G_PI_SDA);
195
+        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])  u8g_SetPIOutput(u8g, U8G_PI_CS);
196
+        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_A0])  u8g_SetPIOutput(u8g, U8G_PI_A0);
197
+        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET])  u8g_SetPIOutput(u8g, U8G_PI_RESET);
198
+
199
+        //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
200
+        //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
201
+        //u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: unknown mode */
202
+
203
+        u8g_i2c_init_sw(u8g->pin_list[U8G_PI_I2C_OPTION]);
204
+        u8g_com_ssd_I2C_start_sequence_sw((u8g);
205
+        break;
206
+
207
+      case U8G_COM_MSG_STOP:
208
+        break;
209
+
210
+      case U8G_COM_MSG_RESET:
211
+        break;
212
+
213
+      case U8G_COM_MSG_CHIP_SELECT:
214
+        u8g->pin_list[U8G_PI_A0_STATE] = 0;
215
+        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
216
+        if ( arg_val == 0 )
217
+        {
218
+          /* disable chip, send stop condition */
219
+          u8g_i2c_stop_sw();
220
+        }
221
+        else
222
+        {
223
+          /* enable, do nothing: any byte writing will trigger the i2c start */
224
+        }
225
+        break;
226
+
227
+      case U8G_COM_MSG_WRITE_BYTE:
228
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
229
+//          if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
230
+//            return u8g_i2c_stop(), 0;
231
+        if ( u8g_i2c_send_byte_sw(arg_val) == 0 )
232
+          return u8g_i2c_stop_sw(), 0;
233
+        // u8g_i2c_stop();
234
+        break;
235
+
236
+      case U8G_COM_MSG_WRITE_SEQ:
237
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
238
+        if ( u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0 )
239
+          return u8g_i2c_stop_sw(), 0;
240
+        {
241
+          register uint8_t *ptr = (uint8_t *)arg_ptr;
242
+          while( arg_val > 0 )
243
+          {
244
+            if ( u8g_i2c_send_byte_sw(*ptr++) == 0 )
245
+              return u8g_i2c_stop_sw(), 0;
246
+            arg_val--;
247
+          }
248
+        }
249
+        // u8g_i2c_stop();
250
+        break;
251
+
252
+      case U8G_COM_MSG_WRITE_SEQ_P:
253
+        //u8g->pin_list[U8G_PI_SET_A0] = 1;
254
+        if ( u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0 )
255
+          return u8g_i2c_stop_sw(), 0;
256
+        {
257
+          register uint8_t *ptr = (uint8_t *)arg_ptr;
258
+          while( arg_val > 0 )
259
+          {
260
+            if ( u8g_i2c_send_byte_sw(u8g_pgm_read(ptr)) == 0 )
261
+              return 0;
262
+            ptr++;
263
+            arg_val--;
264
+          }
265
+        }
266
+        // u8g_i2c_stop();
267
+        break;
268
+
269
+      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
270
+        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
271
+        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
272
+
273
+        u8g_i2c_start_sw(0); // send slave address and write bit
274
+        if (arg_val)
275
+          u8g_i2c_send_byte_sw(0x40);  // write to graphics DRAM mode
276
+        else
277
+          u8g_i2c_send_byte_sw(0x80);  //command mode
278
+        break;
279
+    }
280
+    return 1;
281
+  }
282
+
283
+#endif  // TARGET_LPC1768

+ 164
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp View File

@@ -0,0 +1,164 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+
25
+  based on u8g_com_LPC1768_st7920_hw_spi.c
26
+
27
+  Universal 8bit Graphics Library
28
+
29
+  Copyright (c) 2011, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+*/
57
+
58
+#ifdef TARGET_LPC1768
59
+
60
+//  #include <inttypes.h>
61
+
62
+//  #include "src/core/macros.h"
63
+//  #include "Configuration.h"
64
+
65
+  #include <lib/u8g.h>
66
+
67
+  #define SPI_FULL_SPEED 0
68
+  #define SPI_HALF_SPEED 1
69
+  #define SPI_QUARTER_SPEED 2
70
+  #define SPI_EIGHTH_SPEED 3
71
+  #define SPI_SIXTEENTH_SPEED 4
72
+  #define SPI_SPEED_5 5
73
+  #define SPI_SPEED_6 6
74
+
75
+
76
+  void spiBegin();
77
+  void spiInit(uint8_t spiRate);
78
+  void spiSend(uint8_t b);
79
+  void spiSend(const uint8_t* buf, size_t n);
80
+
81
+
82
+  static uint8_t rs_last_state = 255;
83
+
84
+  static void u8g_com_LPC1768_st7920_write_byte_hw_spi(uint8_t rs, uint8_t val)
85
+  {
86
+    uint8_t i;
87
+
88
+    if ( rs != rs_last_state) {  // time to send a command/data byte
89
+      rs_last_state = rs;
90
+
91
+      if ( rs == 0 )
92
+        /* command */
93
+        spiSend(0x0f8);
94
+      else
95
+         /* data */
96
+        spiSend(0x0fa);
97
+
98
+      for( i = 0; i < 4; i++ )   // give the controller some time to process the data
99
+        u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
100
+    }
101
+
102
+    spiSend(val & 0x0f0);
103
+    spiSend(val << 4);
104
+  }
105
+
106
+
107
+  uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
108
+  {
109
+    switch(msg)
110
+    {
111
+      case U8G_COM_MSG_INIT:
112
+        u8g_SetPILevel(u8g, U8G_PI_CS, 0);
113
+        u8g_SetPIOutput(u8g, U8G_PI_CS);
114
+        u8g_Delay(5);
115
+        spiBegin();
116
+        spiInit(SPI_EIGHTH_SPEED);  // ST7920 max speed is about 1.1 MHz
117
+        u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: command mode */
118
+        break;
119
+
120
+      case U8G_COM_MSG_STOP:
121
+        break;
122
+
123
+      case U8G_COM_MSG_RESET:
124
+        u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
125
+        break;
126
+
127
+      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
128
+        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
129
+        break;
130
+
131
+      case U8G_COM_MSG_CHIP_SELECT:
132
+        u8g_SetPILevel(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
133
+        break;
134
+
135
+      case U8G_COM_MSG_WRITE_BYTE:
136
+        u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
137
+        break;
138
+
139
+      case U8G_COM_MSG_WRITE_SEQ:
140
+        {
141
+          uint8_t *ptr = (uint8_t*) arg_ptr;
142
+          while( arg_val > 0 )
143
+          {
144
+            u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
145
+            arg_val--;
146
+          }
147
+        }
148
+        break;
149
+
150
+        case U8G_COM_MSG_WRITE_SEQ_P:
151
+        {
152
+          uint8_t *ptr = (uint8_t*) arg_ptr;
153
+          while( arg_val > 0 )
154
+          {
155
+            u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
156
+            arg_val--;
157
+          }
158
+        }
159
+        break;
160
+    }
161
+    return 1;
162
+  }
163
+
164
+#endif  // TARGET_LPC1768

+ 198
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp View File

@@ -0,0 +1,198 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+
25
+  based on u8g_com_st7920_hw_spi.c
26
+
27
+  Universal 8bit Graphics Library
28
+
29
+  Copyright (c) 2011, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+*/
57
+
58
+#ifdef TARGET_LPC1768
59
+
60
+  #include <lib/u8g.h>
61
+
62
+  #include <lpc17xx_pinsel.h>
63
+
64
+  #define LPC_PORT_OFFSET         (0x0020)
65
+  #define LPC_PIN(pin)            (1UL << pin)
66
+  #define LPC_GPIO(port)          ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))
67
+
68
+
69
+  uint8_t SCK_pin_ST7920_HAL, SCK_port_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL, MOSI_port_ST7920_HAL;
70
+
71
+
72
+  #define SPI_SPEED 4  //20: 200KHz 5:750KHz 4:1MHz 3:1.5MHz 2:3-4MHz
73
+
74
+  static void spiSend_sw(uint8_t val)
75
+  {
76
+    for (uint8_t i = 0; i < 8; i++) {
77
+
78
+      if (val & 0x80)
79
+        for (uint8_t j = 0; j < SPI_SPEED; j++) {
80
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOSET = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
81
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOSET = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
82
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOSET = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
83
+        }
84
+      else
85
+        for (uint8_t j = 0; j < SPI_SPEED; j++) {
86
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOCLR = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
87
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOCLR = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
88
+          LPC_GPIO(MOSI_port_ST7920_HAL)->FIOCLR = LPC_PIN(MOSI_pin_ST7920_HAL_HAL);
89
+        }
90
+
91
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
92
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOSET = LPC_PIN(SCK_pin_ST7920_HAL);
93
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOSET = LPC_PIN(SCK_pin_ST7920_HAL);
94
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOSET = LPC_PIN(SCK_pin_ST7920_HAL);
95
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOSET = LPC_PIN(SCK_pin_ST7920_HAL);
96
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOSET = LPC_PIN(SCK_pin_ST7920_HAL);
97
+      }
98
+
99
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
100
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOCLR = LPC_PIN(SCK_pin_ST7920_HAL);
101
+        LPC_GPIO(SCK_port_ST7920_HAL)->FIOCLR = LPC_PIN(SCK_pin_ST7920_HAL);
102
+      }
103
+      val = val << 1;
104
+    }
105
+  }
106
+
107
+  static uint8_t rs_last_state = 255;
108
+
109
+  static void u8g_com_LPC1768_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val)
110
+  {
111
+    uint8_t i;
112
+
113
+    if ( rs != rs_last_state) {  // time to send a command/data byte
114
+      rs_last_state = rs;
115
+
116
+      if ( rs == 0 )
117
+        /* command */
118
+        spiSend_sw(0x0f8);
119
+      else
120
+         /* data */
121
+        spiSend_sw(0x0fa);
122
+
123
+      for( i = 0; i < 4; i++ )   // give the controller some time to process the data
124
+        u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
125
+    }
126
+
127
+    spiSend_sw(val & 0x0f0);
128
+    spiSend_sw(val << 4);
129
+  }
130
+
131
+
132
+  uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
133
+  {
134
+    switch(msg)
135
+    {
136
+      case U8G_COM_MSG_INIT:
137
+        #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
138
+        #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
139
+        SCK_pin_ST7920_HAL = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCK]);
140
+        SCK_port_ST7920_HAL = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCK]);
141
+        MOSI_pin_ST7920_HAL_HAL = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_MOSI]);
142
+        MOSI_port_ST7920_HAL = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_MOSI]);
143
+
144
+        u8g_SetPILevel(u8g, U8G_PI_CS, 0);
145
+        u8g_SetPIOutput(u8g, U8G_PI_CS);
146
+        u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
147
+        u8g_SetPIOutput(u8g, U8G_PI_SCK);
148
+        u8g_SetPILevel(u8g, U8G_PI_MOSI, 0);
149
+        u8g_SetPIOutput(u8g, U8G_PI_MOSI);
150
+        u8g_Delay(5);
151
+        u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: command mode */
152
+        break;
153
+
154
+      case U8G_COM_MSG_STOP:
155
+        break;
156
+
157
+      case U8G_COM_MSG_RESET:
158
+         if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
159
+        break;
160
+
161
+      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
162
+        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
163
+        break;
164
+
165
+      case U8G_COM_MSG_CHIP_SELECT:
166
+        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS]) u8g_SetPILevel(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
167
+        break;
168
+
169
+      case U8G_COM_MSG_WRITE_BYTE:
170
+        u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
171
+        break;
172
+
173
+      case U8G_COM_MSG_WRITE_SEQ:
174
+        {
175
+          uint8_t *ptr = (uint8_t*) arg_ptr;
176
+          while( arg_val > 0 )
177
+          {
178
+            u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
179
+            arg_val--;
180
+          }
181
+        }
182
+        break;
183
+
184
+        case U8G_COM_MSG_WRITE_SEQ_P:
185
+        {
186
+          uint8_t *ptr = (uint8_t*) arg_ptr;
187
+          while( arg_val > 0 )
188
+          {
189
+            u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
190
+            arg_val--;
191
+          }
192
+        }
193
+        break;
194
+    }
195
+    return 1;
196
+  }
197
+
198
+#endif  //TARGET_LPC1768

+ 184
- 0
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_sw_spi.cpp View File

@@ -0,0 +1,184 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+
25
+  adapted from u8g_com_std_sw_spi.c
26
+
27
+  Universal 8bit Graphics Library
28
+
29
+  Copyright (c) 2015, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+*/
57
+
58
+
59
+
60
+#if defined (TARGET_LPC1768)
61
+
62
+
63
+#include <lib/u8g.h>
64
+#include <U8glib.h>
65
+
66
+#include <lpc17xx_pinsel.h>
67
+
68
+#define LPC_PORT_OFFSET         (0x0020)
69
+#define LPC_PIN(pin)            (1UL << pin)
70
+#define LPC_GPIO(port)          ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))
71
+
72
+void delayMicroseconds(uint32_t us);
73
+void pinMode(int16_t pin, uint8_t mode);
74
+void digitalWrite(int16_t pin, uint8_t pin_status);
75
+
76
+
77
+uint8_t SCK_pin, SCK_port, MOSI_pin, MOSI_port;
78
+
79
+#define SPI_SPEED 2  //20: 200KHz 5:750KHz 2:3-4MHz
80
+
81
+static void u8g_sw_spi_HAL_LPC1768_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val)
82
+{
83
+  for (uint8_t i = 0; i < 8; i++) {
84
+
85
+    if (val & 0x80)
86
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
87
+        LPC_GPIO(MOSI_port)->FIOSET = LPC_PIN(MOSI_pin);
88
+        LPC_GPIO(MOSI_port)->FIOSET = LPC_PIN(MOSI_pin);
89
+        LPC_GPIO(MOSI_port)->FIOSET = LPC_PIN(MOSI_pin);
90
+      }
91
+    else
92
+      for (uint8_t j = 0; j < SPI_SPEED; j++) {
93
+        LPC_GPIO(MOSI_port)->FIOCLR = LPC_PIN(MOSI_pin);
94
+        LPC_GPIO(MOSI_port)->FIOCLR = LPC_PIN(MOSI_pin);
95
+        LPC_GPIO(MOSI_port)->FIOCLR = LPC_PIN(MOSI_pin);
96
+      }
97
+
98
+    for (uint8_t j = 0; j < SPI_SPEED; j++) {
99
+      LPC_GPIO(SCK_port)->FIOSET = LPC_PIN(SCK_pin);
100
+      LPC_GPIO(SCK_port)->FIOSET = LPC_PIN(SCK_pin);
101
+      LPC_GPIO(SCK_port)->FIOSET = LPC_PIN(SCK_pin);
102
+      LPC_GPIO(SCK_port)->FIOSET = LPC_PIN(SCK_pin);
103
+      LPC_GPIO(SCK_port)->FIOSET = LPC_PIN(SCK_pin);
104
+    }
105
+
106
+    for (uint8_t j = 0; j < SPI_SPEED; j++) {
107
+      LPC_GPIO(SCK_port)->FIOCLR = LPC_PIN(SCK_pin);
108
+      LPC_GPIO(SCK_port)->FIOCLR = LPC_PIN(SCK_pin);
109
+    }
110
+    val = val << 1;
111
+  }
112
+}
113
+
114
+
115
+uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
116
+{
117
+
118
+
119
+  switch(msg)
120
+  {
121
+    case U8G_COM_MSG_INIT:
122
+      #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
123
+      #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
124
+      SCK_pin = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCK]);
125
+      SCK_port = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCK]);
126
+      MOSI_pin = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_MOSI]);
127
+      MOSI_port = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_MOSI]);
128
+      // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
129
+      #define OUPUT 0x1
130
+      pinMode(u8g->pin_list[U8G_PI_SCK], OUPUT);
131
+      pinMode(u8g->pin_list[U8G_PI_MOSI], OUPUT);
132
+      pinMode(u8g->pin_list[U8G_PI_CS], OUPUT);
133
+      pinMode(u8g->pin_list[U8G_PI_A0], OUPUT);
134
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET])  pinMode(u8g->pin_list[U8G_PI_RESET], OUPUT);
135
+      digitalWrite(u8g->pin_list[U8G_PI_SCK], 0);
136
+      digitalWrite(u8g->pin_list[U8G_PI_MOSI], 0);
137
+      break;
138
+
139
+    case U8G_COM_MSG_STOP:
140
+      break;
141
+
142
+    case U8G_COM_MSG_RESET:
143
+      digitalWrite(u8g->pin_list[U8G_PI_RESET], arg_val);
144
+      break;
145
+
146
+    case U8G_COM_MSG_CHIP_SELECT:
147
+      digitalWrite(u8g->pin_list[U8G_PI_CS], !arg_val);
148
+      break;
149
+
150
+    case U8G_COM_MSG_WRITE_BYTE:
151
+      u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
152
+      break;
153
+
154
+    case U8G_COM_MSG_WRITE_SEQ:
155
+      {
156
+        uint8_t *ptr = (uint8_t *)arg_ptr;
157
+        while( arg_val > 0 )
158
+        {
159
+          u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
160
+          arg_val--;
161
+        }
162
+      }
163
+      break;
164
+
165
+      case U8G_COM_MSG_WRITE_SEQ_P:
166
+      {
167
+        uint8_t *ptr = (uint8_t *)arg_ptr;
168
+        while( arg_val > 0 )
169
+        {
170
+          u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
171
+          ptr++;
172
+          arg_val--;
173
+        }
174
+      }
175
+      break;
176
+
177
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
178
+      digitalWrite(u8g->pin_list[U8G_PI_A0], arg_val);
179
+      break;
180
+  }
181
+  return 1;
182
+}
183
+
184
+#endif  // TARGET_LPC1768

+ 82
- 0
Marlin/src/lcd/dogm/HAL_LCD_class_defines.h View File

@@ -0,0 +1,82 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+// use this file to create the public interface for device drivers that are NOT in the U8G library
25
+
26
+extern u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_sw_spi;
27
+extern u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_hw_spi;
28
+class U8GLIB_64128N_2X_HAL : public U8GLIB
29
+{
30
+  public:
31
+    U8GLIB_64128N_2X_HAL(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE)
32
+      : U8GLIB(&u8g_dev_st7565_64128n_HAL_2x_sw_spi, sck, mosi, cs, a0, reset)
33
+      { }
34
+    U8GLIB_64128N_2X_HAL(uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE)
35
+      : U8GLIB(&u8g_dev_st7565_64128n_HAL_2x_hw_spi, cs, a0, reset)
36
+      { }
37
+};
38
+
39
+
40
+extern u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_sw_spi;
41
+extern u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_hw_spi;
42
+class U8GLIB_ST7920_128X64_4X_HAL : public U8GLIB
43
+{
44
+  public:
45
+    U8GLIB_ST7920_128X64_4X_HAL(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t reset = U8G_PIN_NONE)
46
+      : U8GLIB(&u8g_dev_st7920_128x64_HAL_4x_sw_spi, sck, mosi, cs, U8G_PIN_NONE, reset)    // a0 = U8G_PIN_NONE
47
+      { }
48
+    U8GLIB_ST7920_128X64_4X_HAL(uint8_t cs, uint8_t reset = U8G_PIN_NONE)
49
+      : U8GLIB(&u8g_dev_st7920_128x64_HAL_4x_hw_spi, cs, U8G_PIN_NONE, reset)   // a0 = U8G_PIN_NONE
50
+      { }
51
+};
52
+
53
+
54
+
55
+extern u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi;
56
+class U8GLIB_ST7920_128X64_RRD : public U8GLIB
57
+{
58
+  public:
59
+    U8GLIB_ST7920_128X64_RRD(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t reset = U8G_PIN_NONE)
60
+      : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi, sck, mosi, cs, U8G_PIN_NONE, reset)   // a0 = U8G_PIN_NONE
61
+      { }
62
+};
63
+
64
+
65
+
66
+extern u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire;
67
+class U8GLIB_SH1106_128X64_2X_I2C_2_WIRE : public U8GLIB {
68
+  public:
69
+    U8GLIB_SH1106_128X64_2X_I2C_2_WIRE(uint8_t options = U8G_I2C_OPT_NONE)
70
+    : U8GLIB(&u8g_dev_sh1106_128x64_2x_i2c_2_wire, options)
71
+    {  }
72
+};
73
+
74
+
75
+
76
+extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c_2_wire;
77
+class U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE : public U8GLIB {
78
+  public:
79
+    U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE(uint8_t options = U8G_I2C_OPT_NONE)
80
+    : U8GLIB(&u8g_dev_ssd1306_128x64_2x_i2c_2_wire, options)
81
+    {  }
82
+};

+ 66
- 0
Marlin/src/lcd/dogm/HAL_LCD_com_defines.h View File

@@ -0,0 +1,66 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+// use this file to select the com driver for device drivers that are NOT in the U8G library
24
+
25
+
26
+#ifndef U8G_HAL_LINKS
27
+
28
+  uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29
+  #define U8G_COM_HAL_SW_SPI_FN  u8g_com_arduino_sw_spi_fn
30
+
31
+  uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
32
+  #define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
33
+
34
+  uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
35
+  #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
36
+
37
+  uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
38
+  #define U8G_COM_ST7920_HAL_HW_SPI u8g_com_arduino_st7920_hw_spi_fn
39
+
40
+  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
41
+  #define U8G_COM_SSD_I2C_HAL u8g_com_arduino_ssd_i2c_fn
42
+
43
+#elif TARGET_LPC1768
44
+  uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
45
+  #define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_LPC1768_sw_spi_fn
46
+
47
+  uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
48
+  #define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_LPC1768_hw_spi_fn
49
+
50
+  uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
51
+  #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_LPC1768_ST7920_sw_spi_fn
52
+
53
+  uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
54
+  #define U8G_COM_ST7920_HAL_HW_SPI u8g_com_HAL_LPC1768_ST7920_hw_spi_fn
55
+
56
+  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
57
+  #define U8G_COM_SSD_I2C_HAL u8g_com_HAL_LPC1768_ssd_hw_i2c_fn
58
+
59
+#else  // need to give them some definition or else get compiler errors
60
+  uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 
61
+  #define U8G_COM_HAL_SW_SPI_FN u8g_com_null_fn
62
+  #define U8G_COM_HAL_HW_SPI_FN u8g_com_null_fn
63
+  #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_null_fn
64
+  #define U8G_COM_ST7920_HAL_HW_SPI u8g_com_null_fn
65
+  #define U8G_COM_SSD_I2C_HAL u8g_com_null_fn
66
+#endif

+ 320
- 0
Marlin/src/lcd/dogm/u8g_dev_ssd1306_sh1106_128x64_I2C.cpp View File

@@ -0,0 +1,320 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+/*
25
+
26
+  u8g_dev_ssd1306_128x64.c
27
+
28
+  Universal 8bit Graphics Library
29
+
30
+  Copyright (c) 2011, olikraus@gmail.com
31
+  All rights reserved.
32
+
33
+  Redistribution and use in source and binary forms, with or without modification,
34
+  are permitted provided that the following conditions are met:
35
+
36
+  * Redistributions of source code must retain the above copyright notice, this list
37
+    of conditions and the following disclaimer.
38
+
39
+  * Redistributions in binary form must reproduce the above copyright notice, this
40
+    list of conditions and the following disclaimer in the documentation and/or other
41
+    materials provided with the distribution.
42
+
43
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
44
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
46
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
48
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+
57
+
58
+*/
59
+
60
+/**
61
+ * These routines are meant for two wire I2C interfaces.
62
+ *
63
+ * Three and four wire I2C interfaces have an A0 line.  That line is
64
+ * used to switch between command and data modes.
65
+ *
66
+ * The two wire LCDs use an instruction byte to signal if data or
67
+ * command info is to follow.  The command stream needs the instruction
68
+ * byte between eack command byte.  The data stream needs one at the
69
+ * beginning.
70
+ */
71
+
72
+#include <lib/u8g.h>
73
+#include <src/lcd/dogm/HAL_LCD_com_defines.h>
74
+
75
+#define WIDTH 128
76
+#define HEIGHT 64
77
+#define PAGE_HEIGHT 8
78
+
79
+uint8_t u8g_WriteEscSeqP_2_wire(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq);
80
+
81
+// The sh1106 is compatible to the ssd1306, but is 132x64. 128x64 display area is centered within
82
+// the 132x64.
83
+
84
+
85
+static const uint8_t u8g_dev_sh1106_128x64_data_start_2_wire[] PROGMEM = {
86
+  0x010,    // set upper 4 bit of the col adr to 0
87
+  0x002,    // set lower 4 bit of the col adr to 2 (centered display with ssd1306)
88
+  U8G_ESC_END                // end of sequence
89
+};
90
+
91
+
92
+static const uint8_t u8g_dev_sh1106_128x64_init_seq_2_wire[] PROGMEM = {
93
+  U8G_ESC_ADR(0),  // initiate command mode
94
+  0x0ae,        /* display off, sleep mode */
95
+  0x0a8, 0x03f,   /* mux ratio */
96
+  0x0d3, 0x00,    /* display offset */
97
+  0x040,        /* start line */
98
+  0x0a1,        /* segment remap a0/a1*/
99
+  0x0c8,        /* c0: scan dir normal, c8: reverse */
100
+  0x0da, 0x012,   /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
101
+  0x081, 0x0cf,   /* [2] set contrast control */
102
+  0x020, 0x002,   /* 2012-05-27: page addressing mode */
103
+  0x21, 2, 0x81,   // set column range from 0 through 131
104
+  0x22, 0, 7,   // set page range from 0 through 7
105
+  0x0d9, 0x0f1,   /* [2] pre-charge period 0x022/f1*/
106
+  0x0db, 0x040,   /* vcomh deselect level */
107
+  0x0a4,        /* output ram to display */
108
+  0x0a6,        /* none inverted normal display mode */
109
+  0x0d5, 0x080,   /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
110
+  0x08d, 0x014,   /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
111
+  0x02e,        /* 2012-05-27: Deactivate scroll */
112
+  0x0af,        /* display on */
113
+  U8G_ESC_END                /* end of sequence */
114
+};
115
+
116
+
117
+uint8_t u8g_dev_sh1106_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
118
+{
119
+  switch(msg)
120
+  {
121
+    case U8G_DEV_MSG_INIT:
122
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
123
+      u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_init_seq_2_wire);
124
+      break;
125
+    case U8G_DEV_MSG_STOP:
126
+      break;
127
+    case U8G_DEV_MSG_PAGE_NEXT:
128
+      {
129
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
130
+        u8g_SetAddress(u8g, dev, 0);           // instruction mode
131
+        u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_data_start_2_wire);
132
+        u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); // select current page
133
+        u8g_SetAddress(u8g, dev, 1);           // data mode
134
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *) pb->buf);
135
+        u8g_SetChipSelect(u8g, dev, 0);
136
+        u8g_SetAddress(u8g, dev, 0);           // instruction mode
137
+        u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_data_start_2_wire);
138
+        u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); // select current page
139
+        u8g_SetAddress(u8g, dev, 1);           // data mode
140
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
141
+        u8g_SetChipSelect(u8g, dev, 0);
142
+      }
143
+      break;
144
+    case U8G_DEV_MSG_SLEEP_ON:
145
+      return 1;
146
+    case U8G_DEV_MSG_SLEEP_OFF:
147
+      return 1;
148
+  }
149
+  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
150
+}
151
+
152
+
153
+uint8_t u8g_dev_sh1106_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
154
+u8g_pb_t u8g_dev_sh1106_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_sh1106_128x64_2x_buf};
155
+u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c = { u8g_dev_sh1106_128x64_2x_2_wire_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SSD_I2C_HAL };
156
+
157
+
158
+uint8_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf[WIDTH*2] U8G_NOCOMMON ;
159
+u8g_pb_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf};
160
+u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire = { u8g_dev_sh1106_128x64_2x_2_wire_fn, &u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb, U8G_COM_SSD_I2C_HAL };
161
+
162
+/////////////////////////////////////////////////////////////////////////////////////////////
163
+
164
+static const uint8_t u8g_dev_ssd1306_128x64_data_start_2_wire[] PROGMEM = {
165
+  0x010,    // set upper 4 bit of the col adr to 0
166
+  0x000,    // set lower 4 bit of the col adr to 0
167
+  U8G_ESC_END                // end of sequence
168
+};
169
+
170
+
171
+static const uint8_t u8g_dev_ssd1306_128x64_init_seq_2_wire[] PROGMEM = {
172
+  U8G_ESC_ADR(0),  // initiate command mode
173
+  0x0ae,        /* display off, sleep mode */
174
+  0x0a8, 0x03f,   /* mux ratio */
175
+  0x0d3, 0x00,    /* display offset */
176
+  0x040,        /* start line */
177
+  0x0a1,        /* segment remap a0/a1*/
178
+  0x0c8,        /* c0: scan dir normal, c8: reverse */
179
+  0x0da, 0x012,   /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
180
+  0x081, 0x0cf,   /* [2] set contrast control */
181
+  0x020, 0x002,   /* 2012-05-27: page addressing mode */
182
+  0x21, 0, 0x7f,   // set column range from 0 through 127
183
+  0x22, 0, 7,   // set page range from 0 through 7
184
+  0x0d9, 0x0f1,   /* [2] pre-charge period 0x022/f1*/
185
+  0x0db, 0x040,   /* vcomh deselect level */
186
+  0x0a4,        /* output ram to display */
187
+  0x0a6,        /* none inverted normal display mode */
188
+  0x0d5, 0x080,   /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
189
+  0x08d, 0x014,   /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
190
+  0x02e,        /* 2012-05-27: Deactivate scroll */
191
+  0x0af,        /* display on */
192
+  U8G_ESC_END                /* end of sequence */
193
+};
194
+
195
+
196
+uint8_t u8g_dev_ssd1306_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
197
+{
198
+  switch(msg)
199
+  {
200
+    case U8G_DEV_MSG_INIT:
201
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
202
+      u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_init_seq_2_wire);
203
+      break;
204
+    case U8G_DEV_MSG_STOP:
205
+      break;
206
+    case U8G_DEV_MSG_PAGE_NEXT:
207
+      {
208
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
209
+        u8g_SetAddress(u8g, dev, 0);           // instruction mode
210
+        u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_data_start_2_wire);
211
+        u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); // select current page
212
+        u8g_SetAddress(u8g, dev, 1);           // data mode
213
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *) pb->buf);
214
+        u8g_SetChipSelect(u8g, dev, 0);
215
+        u8g_SetAddress(u8g, dev, 0);           // instruction mode
216
+        u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_data_start_2_wire);
217
+        u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); // select current page
218
+        u8g_SetAddress(u8g, dev, 1);           // data mode
219
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
220
+        u8g_SetChipSelect(u8g, dev, 0);
221
+      }
222
+      break;
223
+    case U8G_DEV_MSG_SLEEP_ON:
224
+      return 1;
225
+    case U8G_DEV_MSG_SLEEP_OFF:
226
+      return 1;
227
+  }
228
+  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
229
+}
230
+
231
+
232
+uint8_t u8g_dev_ssd1306_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
233
+u8g_pb_t u8g_dev_ssd1306_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_ssd1306_128x64_2x_buf};
234
+u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c = { u8g_dev_ssd1306_128x64_2x_2_wire_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_I2C_HAL };
235
+
236
+
237
+uint8_t u8g_dev_ssd1306_128x64_2x_i2c_2_wire_buf[WIDTH*2] U8G_NOCOMMON ;
238
+u8g_pb_t u8g_dev_ssd1306_128x64_2x_i2c_2_wire_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_ssd1306_128x64_2x_i2c_2_wire_buf};
239
+u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c_2_wire = { u8g_dev_ssd1306_128x64_2x_2_wire_fn, &u8g_dev_ssd1306_128x64_2x_i2c_2_wire_pb, U8G_COM_SSD_I2C_HAL };
240
+
241
+
242
+/////////////////////////////////////////////////////////////////////////////////////////////
243
+
244
+// This routine adds the instruction byte in between the command bytes.  This makes the init
245
+// sequences a lot easier to read.
246
+
247
+#define I2C_CMD_MODE    0x080
248
+
249
+uint8_t u8g_WriteEscSeqP_2_wire(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq)
250
+{
251
+  uint8_t is_escape = 0;
252
+  uint8_t value;
253
+  for(;;)
254
+  {
255
+    value = u8g_pgm_read(esc_seq);
256
+    if ( is_escape == 0 )
257
+    {
258
+      if ( value != 255 )
259
+      {
260
+        if ( u8g_WriteByte(u8g, dev, value) == 0 )
261
+          return 0;
262
+        if ( u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
263
+          return 0;
264
+      }
265
+      else
266
+      {
267
+        is_escape = 1;
268
+      }
269
+    }
270
+    else
271
+    {
272
+      if ( value == 255 )
273
+      {
274
+        if ( u8g_WriteByte(u8g, dev, value) == 0 )
275
+          return 0;
276
+        if ( u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
277
+          return 0;
278
+      }
279
+      else if ( value == 254 )
280
+      {
281
+        break;
282
+      }
283
+      else if ( value >= 0x0f0 )
284
+      {
285
+        /* not yet used, do nothing */
286
+      }
287
+      else if ( value >= 0xe0  )
288
+      {
289
+        u8g_SetAddress(u8g, dev, value & 0x0f);
290
+      }
291
+      else if ( value >= 0xd0 )
292
+      {
293
+        u8g_SetChipSelect(u8g, dev, value & 0x0f);
294
+      }
295
+      else if ( value >= 0xc0 )
296
+      {
297
+        u8g_SetResetLow(u8g, dev);
298
+        value &= 0x0f;
299
+        value <<= 4;
300
+        value+=2;
301
+        u8g_Delay(value);
302
+        u8g_SetResetHigh(u8g, dev);
303
+        u8g_Delay(value);
304
+      }
305
+      else if ( value >= 0xbe )
306
+      {
307
+  /* not yet implemented */
308
+        /* u8g_SetVCC(u8g, dev, value & 0x01); */
309
+      }
310
+      else if ( value <= 127 )
311
+      {
312
+        u8g_Delay(value);
313
+      }
314
+      is_escape = 0;
315
+    }
316
+    esc_seq++;
317
+  }
318
+  return 1;
319
+}
320
+

+ 229
- 0
Marlin/src/lcd/dogm/u8g_dev_st7565_64128n_HAL.cpp View File

@@ -0,0 +1,229 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+
24
+/*
25
+
26
+  u8g_dev_st7565_64128n_HAL.c (Displaytech)
27
+
28
+  Universal 8bit Graphics Library
29
+
30
+  Copyright (c) 2011, olikraus@gmail.com
31
+  All rights reserved.
32
+
33
+  Redistribution and use in source and binary forms, with or without modification,
34
+  are permitted provided that the following conditions are met:
35
+
36
+  * Redistributions of source code must retain the above copyright notice, this list
37
+    of conditions and the following disclaimer.
38
+
39
+  * Redistributions in binary form must reproduce the above copyright notice, this
40
+    list of conditions and the following disclaimer in the documentation and/or other
41
+    materials provided with the distribution.
42
+
43
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
44
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
46
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
48
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+
57
+
58
+*/
59
+
60
+#include <lib/u8g.h>
61
+
62
+#include <src/lcd/dogm/HAL_LCD_com_defines.h>
63
+
64
+#define WIDTH 128
65
+#define HEIGHT 64
66
+#define PAGE_HEIGHT 8
67
+
68
+/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
69
+static const uint8_t u8g_dev_st7565_64128n_HAL_init_seq[] PROGMEM = {
70
+   U8G_ESC_CS(0),            /* disable chip */
71
+    U8G_ESC_ADR(0),          /* instruction mode */
72
+    U8G_ESC_CS(1),           /* enable chip */
73
+    U8G_ESC_RST(15),         /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
74
+
75
+    0x0A2,             /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
76
+    0x0A0,             /* Normal ADC Select (according to Displaytech 64128N datasheet) */
77
+
78
+    0x0c8,                   /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
79
+    0x040,               /* Display start line for Displaytech 64128N */
80
+
81
+    0x028 | 0x04,            /* power control: turn on voltage converter */
82
+    U8G_ESC_DLY(50),         /* delay 50 ms */
83
+
84
+    0x028 | 0x06,            /* power control: turn on voltage regulator */
85
+    U8G_ESC_DLY(50),         /* delay 50 ms */
86
+
87
+    0x028 | 0x07,            /* power control: turn on voltage follower */
88
+    U8G_ESC_DLY(50),         /* delay 50 ms */
89
+
90
+    0x010,                   /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
91
+
92
+    0x0a6,                   /* display normal, bit val 0: LCD pixel off. */
93
+
94
+    0x081,                   /* set contrast */
95
+    0x01e,                 /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
96
+
97
+
98
+    0x0af,               /* display on */
99
+
100
+    U8G_ESC_DLY(100),        /* delay 100 ms */
101
+    0x0a5,               /* display all points, ST7565 */
102
+    U8G_ESC_DLY(100),        /* delay 100 ms */
103
+    U8G_ESC_DLY(100),        /* delay 100 ms */
104
+    0x0a4,               /* normal display */
105
+    U8G_ESC_CS(0),           /* disable chip */
106
+    U8G_ESC_END              /* end of sequence */
107
+};
108
+
109
+static const uint8_t u8g_dev_st7565_64128n_HAL_data_start[] PROGMEM = {
110
+  U8G_ESC_ADR(0),           /* instruction mode */
111
+  U8G_ESC_CS(1),            /* enable chip */
112
+  0x010,                  /* set upper 4 bit of the col adr to 0x10 */
113
+  0x000,                /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
114
+  U8G_ESC_END               /* end of sequence */
115
+};
116
+
117
+static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_on[] PROGMEM = {
118
+  U8G_ESC_ADR(0),           /* instruction mode */
119
+  U8G_ESC_CS(1),             /* enable chip */
120
+  0x0ac,    /* static indicator off */
121
+  0x000,                    /* indicator register set (not sure if this is required) */
122
+  0x0ae,    /* display off */
123
+  0x0a5,    /* all points on */
124
+  U8G_ESC_CS(0),             /* disable chip, bugfix 12 nov 2014 */
125
+  U8G_ESC_END                /* end of sequence */
126
+  };
127
+
128
+static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_off[] PROGMEM = {
129
+  U8G_ESC_ADR(0),           /* instruction mode */
130
+  U8G_ESC_CS(1),             /* enable chip */
131
+  0x0a4,    /* all points off */
132
+  0x0af,    /* display on */
133
+  U8G_ESC_DLY(50),       /* delay 50 ms */
134
+  U8G_ESC_CS(0),             /* disable chip, bugfix 12 nov 2014 */
135
+  U8G_ESC_END                /* end of sequence */
136
+};
137
+
138
+uint8_t u8g_dev_st7565_64128n_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
139
+{
140
+  switch(msg)
141
+  {
142
+    case U8G_DEV_MSG_INIT:
143
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
144
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
145
+      break;
146
+    case U8G_DEV_MSG_STOP:
147
+      break;
148
+    case U8G_DEV_MSG_PAGE_NEXT:
149
+      {
150
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
151
+        u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
152
+        u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
153
+        u8g_SetAddress(u8g, dev, 1);           /* data mode */
154
+        if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
155
+          return 0;
156
+        u8g_SetChipSelect(u8g, dev, 0);
157
+      }
158
+      break;
159
+    case U8G_DEV_MSG_CONTRAST:
160
+      u8g_SetChipSelect(u8g, dev, 1);
161
+      u8g_SetAddress(u8g, dev, 0);          /* instruction mode */
162
+      u8g_WriteByte(u8g, dev, 0x081);
163
+      u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
164
+      u8g_SetChipSelect(u8g, dev, 0);
165
+      return 1;
166
+    case U8G_DEV_MSG_SLEEP_ON:
167
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_on);
168
+      return 1;
169
+    case U8G_DEV_MSG_SLEEP_OFF:
170
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_off);
171
+      return 1;
172
+  }
173
+  return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
174
+}
175
+
176
+uint8_t u8g_dev_st7565_64128n_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
177
+{
178
+  switch(msg)
179
+  {
180
+    case U8G_DEV_MSG_INIT:
181
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
182
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
183
+      break;
184
+    case U8G_DEV_MSG_STOP:
185
+      break;
186
+    case U8G_DEV_MSG_PAGE_NEXT:
187
+      {
188
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
189
+
190
+        u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
191
+        u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
192
+        u8g_SetAddress(u8g, dev, 1);           /* data mode */
193
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)pb->buf);
194
+        u8g_SetChipSelect(u8g, dev, 0);
195
+
196
+        u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
197
+        u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
198
+        u8g_SetAddress(u8g, dev, 1);           /* data mode */
199
+        u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
200
+        u8g_SetChipSelect(u8g, dev, 0);
201
+      }
202
+      break;
203
+    case U8G_DEV_MSG_CONTRAST:
204
+      u8g_SetChipSelect(u8g, dev, 1);
205
+      u8g_SetAddress(u8g, dev, 0);          /* instruction mode */
206
+      u8g_WriteByte(u8g, dev, 0x081);
207
+      u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
208
+      u8g_SetChipSelect(u8g, dev, 0);
209
+      return 1;
210
+    case U8G_DEV_MSG_SLEEP_ON:
211
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_on);
212
+      return 1;
213
+    case U8G_DEV_MSG_SLEEP_OFF:
214
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_off);
215
+      return 1;
216
+  }
217
+  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
218
+}
219
+
220
+
221
+U8G_PB_DEV(u8g_dev_st7565_64128n_HAL_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_HAL_fn, U8G_COM_HAL_SW_SPI_FN);
222
+
223
+uint8_t u8g_dev_st7565_64128n_HAL_2x_buf[WIDTH*2] U8G_NOCOMMON ;
224
+u8g_pb_t u8g_dev_st7565_64128n_HAL_2x_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7565_64128n_HAL_2x_buf};
225
+u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_sw_spi = { u8g_dev_st7565_64128n_HAL_2x_fn, &u8g_dev_st7565_64128n_HAL_2x_pb, U8G_COM_HAL_SW_SPI_FN };
226
+
227
+
228
+U8G_PB_DEV(u8g_dev_st7565_64128n_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_HAL_fn, U8G_COM_HAL_HW_SPI_FN);
229
+u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_hw_spi = { u8g_dev_st7565_64128n_HAL_2x_fn, &u8g_dev_st7565_64128n_HAL_2x_pb, U8G_COM_HAL_HW_SPI_FN };

+ 202
- 0
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp View File

@@ -0,0 +1,202 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+
25
+  u8g_dev_st7920_128x64_HAL.c
26
+
27
+  Universal 8bit Graphics Library
28
+
29
+  Copyright (c) 2011, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+
57
+*/
58
+
59
+#include <lib/u8g.h>
60
+
61
+#include <src/lcd/dogm/HAL_LCD_com_defines.h>
62
+
63
+#define WIDTH 128
64
+#define HEIGHT 64
65
+#define PAGE_HEIGHT 8
66
+
67
+
68
+/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
69
+static const uint8_t u8g_dev_st7920_128x64_HAL_init_seq[] PROGMEM = {
70
+  U8G_ESC_CS(0),             /* disable chip */
71
+  U8G_ESC_ADR(0),           /* instruction mode */
72
+  U8G_ESC_RST(15),           /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
73
+  U8G_ESC_DLY(100),         /* 8 Dez 2012: additional delay 100 ms because of reset*/
74
+  U8G_ESC_CS(1),             /* enable chip */
75
+  U8G_ESC_DLY(50),         /* delay 50 ms */
76
+
77
+  0x038,                                /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
78
+  0x00c,                                /* display on, cursor & blink off; 0x08: all off */
79
+  0x006,                                /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
80
+  0x002,                                /* disable scroll, enable CGRAM adress */
81
+  0x001,                                /* clear RAM, needs 1.6 ms */
82
+  U8G_ESC_DLY(100),               /* delay 100 ms */
83
+
84
+  U8G_ESC_CS(0),             /* disable chip */
85
+  U8G_ESC_END                /* end of sequence */
86
+};
87
+
88
+uint8_t u8g_dev_st7920_128x64_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
89
+{
90
+  switch(msg)
91
+  {
92
+    case U8G_DEV_MSG_INIT:
93
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
94
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
95
+      break;
96
+    case U8G_DEV_MSG_STOP:
97
+      break;
98
+    case U8G_DEV_MSG_PAGE_NEXT:
99
+      {
100
+        uint8_t y, i;
101
+        uint8_t *ptr;
102
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
103
+
104
+        u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
105
+        u8g_SetChipSelect(u8g, dev, 1);
106
+        y = pb->p.page_y0;
107
+        ptr = (uint8_t *)pb->buf;
108
+        for( i = 0; i < 8; i ++ )
109
+        {
110
+          u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
111
+          u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
112
+
113
+          if ( y < 32 )
114
+          {
115
+                  u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
116
+                  u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
117
+          }
118
+          else
119
+          {
120
+                  u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
121
+                  u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
122
+          }
123
+
124
+          u8g_SetAddress(u8g, dev, 1);                  /* data mode */
125
+          u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
126
+          ptr += WIDTH/8;
127
+          y++;
128
+        }
129
+        u8g_SetChipSelect(u8g, dev, 0);
130
+      }
131
+      break;
132
+  }
133
+  return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
134
+}
135
+
136
+uint8_t u8g_dev_st7920_128x64_HAL_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
137
+{
138
+  switch(msg)
139
+  {
140
+    case U8G_DEV_MSG_INIT:
141
+      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
142
+      u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
143
+      break;
144
+
145
+    case U8G_DEV_MSG_STOP:
146
+      break;
147
+
148
+    case U8G_DEV_MSG_PAGE_NEXT:
149
+      {
150
+        uint8_t y, i;
151
+        uint8_t *ptr;
152
+        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
153
+
154
+        u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
155
+        u8g_SetChipSelect(u8g, dev, 1);
156
+        y = pb->p.page_y0;
157
+        ptr = (uint8_t *)pb->buf;
158
+        for( i = 0; i < 32; i ++ )
159
+        {
160
+          u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
161
+          u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
162
+
163
+          if ( y < 32 )
164
+          {
165
+                  u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
166
+                  u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
167
+          }
168
+          else
169
+          {
170
+                  u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
171
+                  u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
172
+          }
173
+
174
+          u8g_SetAddress(u8g, dev, 1);                  /* data mode */
175
+          u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
176
+          ptr += WIDTH/8;
177
+          y++;
178
+        }
179
+        u8g_SetChipSelect(u8g, dev, 0);
180
+      }
181
+      break;
182
+  }
183
+  return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
184
+}
185
+
186
+U8G_PB_DEV(u8g_dev_st7920_128x64_HAL_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_HAL_fn, U8G_COM_ST7920_HAL_SW_SPI);
187
+
188
+#define QWIDTH (WIDTH*4)
189
+uint8_t u8g_dev_st7920_128x64_HAL_4x_buf[QWIDTH] U8G_NOCOMMON ;
190
+u8g_pb_t u8g_dev_st7920_128x64_HAL_4x_pb = { {32, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7920_128x64_HAL_4x_buf};
191
+u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_sw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_SW_SPI };
192
+
193
+
194
+U8G_PB_DEV(u8g_dev_st7920_128x64_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_HAL_fn, U8G_COM_ST7920_HAL_HW_SPI);
195
+u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_hw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_HW_SPI };
196
+
197
+
198
+#ifdef U8G_HAL_LINKS
199
+  // Also use this device for HAL version of rrd class. This results in the same device being used 
200
+  // for the ST7920 for HAL systems no matter what is selected in ultralcd_impl_DOGM.h.
201
+  u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_SW_SPI };
202
+#endif

+ 0
- 259
Marlin/src/lcd/dogm/ultralcd_st7565_u8glib_VIKI.h View File

@@ -1,259 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
- *
8
- * This program is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-#ifndef ULCDST7565_H
24
-#define ULCDST7565_H
25
-
26
-#include "../../Marlin.h"
27
-
28
-#if ENABLED(U8GLIB_ST7565_64128N)
29
-
30
-#define ST7565_CLK_PIN  DOGLCD_SCK
31
-#define ST7565_DAT_PIN  DOGLCD_MOSI
32
-#define ST7565_CS_PIN   DOGLCD_CS
33
-#define ST7565_A0_PIN   DOGLCD_A0
34
-
35
-#include <U8glib.h>
36
-
37
-#define WIDTH 128
38
-#define HEIGHT 64
39
-#define PAGE_HEIGHT 8
40
-
41
-//set optimization so ARDUINO optimizes this file
42
-#pragma GCC optimize (3)
43
-
44
-// If you want you can define your own set of delays in Configuration.h
45
-//#define ST7565_DELAY_1 DELAY_0_NOP
46
-//#define ST7565_DELAY_2 DELAY_0_NOP
47
-//#define ST7565_DELAY_3 DELAY_0_NOP
48
-
49
-/*
50
-#define ST7565_DELAY_1 u8g_10MicroDelay()
51
-#define ST7565_DELAY_2 u8g_10MicroDelay()
52
-#define ST7565_DELAY_3 u8g_10MicroDelay()
53
-*/
54
-
55
-#if F_CPU >= 20000000
56
-  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
57
-  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
58
-  #define CPU_ST7565_DELAY_3 DELAY_1_NOP
59
-#elif MB(3DRAG) || MB(K8200) || MB(K8400)
60
-  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
61
-  #define CPU_ST7565_DELAY_2 DELAY_3_NOP
62
-  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
63
-#elif MB(MINIRAMBO)
64
-  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
65
-  #define CPU_ST7565_DELAY_2 DELAY_4_NOP
66
-  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
67
-#elif MB(RAMBO)
68
-  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
69
-  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
70
-  #define CPU_ST7565_DELAY_3 DELAY_0_NOP
71
-#elif F_CPU == 16000000
72
-  #define CPU_ST7565_DELAY_1 DELAY_0_NOP
73
-  #define CPU_ST7565_DELAY_2 DELAY_0_NOP
74
-  #define CPU_ST7565_DELAY_3 DELAY_1_NOP
75
-#else
76
-  #error "No valid condition for delays in 'ultralcd_st7565_u8glib_VIKI.h'"
77
-#endif
78
-
79
-#ifndef ST7565_DELAY_1
80
-  #define ST7565_DELAY_1 CPU_ST7565_DELAY_1
81
-#endif
82
-#ifndef ST7565_DELAY_2
83
-  #define ST7565_DELAY_2 CPU_ST7565_DELAY_2
84
-#endif
85
-#ifndef ST7565_DELAY_3
86
-  #define ST7565_DELAY_3 CPU_ST7565_DELAY_3
87
-#endif
88
-
89
-#if ENABLED(SHARED_SPI)  // Re-ARM requires that the LCD and the SD card share a single SPI
90
-
91
-  #define ST7565_WRITE_BYTE(a)                 { spiSend((uint8_t)a); U8G_DELAY; }
92
-  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {spiSend( *ptr++);} DELAY_10US; }
93
-
94
-#else
95
-  #define ST7565_SND_BIT \
96
-    WRITE(ST7565_CLK_PIN, LOW);        ST7565_DELAY_1; \
97
-    WRITE(ST7565_DAT_PIN, val & 0x80); ST7565_DELAY_2; \
98
-    WRITE(ST7565_CLK_PIN, HIGH);       ST7565_DELAY_3; \
99
-    WRITE(ST7565_CLK_PIN, LOW);\
100
-    val <<= 1
101
-
102
-  static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
103
-    ST7565_SND_BIT; // 1
104
-    ST7565_SND_BIT; // 2
105
-    ST7565_SND_BIT; // 3
106
-    ST7565_SND_BIT; // 4
107
-    ST7565_SND_BIT; // 5
108
-    ST7565_SND_BIT; // 6
109
-    ST7565_SND_BIT; // 7
110
-    ST7565_SND_BIT; // 8
111
-  }
112
-
113
-  #define ST7565_WRITE_BYTE(a)                 { ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY; }
114
-  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {ST7565_SWSPI_SND_8BIT( *ptr++);} DELAY_10US; }
115
-#endif
116
-
117
-#if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
118
-  #define U8G_DELAY delayMicroseconds(DOGM_SPI_DELAY_US)
119
-#else
120
-  #define U8G_DELAY u8g_10MicroDelay()
121
-#endif
122
-
123
-#define ST7565_CS()                          { WRITE(ST7565_CS_PIN,1); U8G_DELAY; }
124
-#define ST7565_NCS()                         { WRITE(ST7565_CS_PIN,0); }
125
-#define ST7565_A0()                          { WRITE(ST7565_A0_PIN,1); U8G_DELAY; }
126
-#define ST7565_NA0()                         { WRITE(ST7565_A0_PIN,0); }
127
-
128
-
129
-uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
130
-  switch (msg) {
131
-    case U8G_DEV_MSG_INIT: {
132
-      OUT_WRITE(ST7565_CS_PIN, LOW);
133
-      #if ENABLED(SHARED_SPI)
134
-        u8g_Delay(250);
135
-        spiBegin();
136
-        #ifndef SPI_SPEED
137
-          #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
138
-        #endif
139
-        spiInit(SPI_SPEED);
140
-      #else
141
-        OUT_WRITE(ST7565_DAT_PIN, LOW);
142
-        OUT_WRITE(ST7565_CLK_PIN, LOW);
143
-      #endif
144
-      OUT_WRITE(ST7565_A0_PIN, LOW);
145
-
146
-      ST7565_CS();                      /* disable chip */
147
-      ST7565_NA0();                     /* instruction mode */
148
-      ST7565_NCS();                     /* enable chip */
149
-
150
-      ST7565_WRITE_BYTE(0x0A2);         /* 0x0A2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
151
-      ST7565_WRITE_BYTE(0x0A0);         /* Normal ADC Select (according to Displaytech 64128N datasheet) */
152
-
153
-      ST7565_WRITE_BYTE(0x0C8);         /* common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1 */
154
-      ST7565_WRITE_BYTE(0x040);         /* Display start line for Displaytech 64128N */
155
-
156
-      ST7565_WRITE_BYTE(0x028 | 0x04);  /* power control: turn on voltage converter */
157
-      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
158
-
159
-      ST7565_WRITE_BYTE(0x028 | 0x06);  /* power control: turn on voltage regulator */
160
-      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
161
-
162
-      ST7565_WRITE_BYTE(0x028 | 0x07);  /* power control: turn on voltage follower */
163
-      //U8G_ESC_DLY(50);                /* delay 50 ms - hangs after a reset if used */
164
-
165
-      ST7565_WRITE_BYTE(0x010);         /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
166
-
167
-      ST7565_WRITE_BYTE(0x0A6);         /* display normal, bit val 0: LCD pixel off. */
168
-
169
-      ST7565_WRITE_BYTE(0x081);         /* set contrast */
170
-      ST7565_WRITE_BYTE(0x01E);         /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
171
-
172
-      ST7565_WRITE_BYTE(0x0AF);         /* display on */
173
-
174
-      U8G_ESC_DLY(100);                 /* delay 100 ms */
175
-      ST7565_WRITE_BYTE(0x0A5);         /* display all points; ST7565 */
176
-      U8G_ESC_DLY(100);                 /* delay 100 ms */
177
-      U8G_ESC_DLY(100);                 /* delay 100 ms */
178
-      ST7565_WRITE_BYTE(0x0A4);         /* normal display */
179
-      ST7565_CS();                      /* disable chip */
180
-    }                                   /* end of sequence */
181
-    break;
182
-
183
-    case U8G_DEV_MSG_STOP: break;
184
-
185
-    case U8G_DEV_MSG_PAGE_NEXT: {
186
-      u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
187
-      ST7565_CS();                      /* disable chip */
188
-      ST7565_NA0();                     /* instruction mode */
189
-      ST7565_NCS();                     /* enable chip */
190
-      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
191
-      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
192
-                                        /* end of sequence */
193
-      ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page));; /* select current page (ST7565R) */
194
-      ST7565_A0();                      /* data mode */
195
-      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
196
-      ST7565_CS();                      /* disable chip */
197
-      ST7565_NA0();                     /* instruction mode */
198
-      ST7565_NCS();                     /* enable chip */
199
-      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
200
-      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
201
-                                        /* end of sequence */
202
-      ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
203
-      ST7565_A0();                      /* data mode */
204
-      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
205
-      ST7565_CS();                      /* disable chip */
206
-    }
207
-    break;
208
-
209
-    case U8G_DEV_MSG_CONTRAST:
210
-      ST7565_NCS();
211
-      ST7565_NA0();                     /* instruction mode */
212
-      ST7565_WRITE_BYTE(0x081);
213
-      ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
214
-      ST7565_CS();                      /* disable chip */
215
-      return 1;
216
-
217
-    case U8G_DEV_MSG_SLEEP_ON:
218
-      ST7565_NA0();                     /* instruction mode */
219
-      ST7565_NCS();                     /* enable chip */
220
-      ST7565_WRITE_BYTE(0x0AC);         /* static indicator off */
221
-      ST7565_WRITE_BYTE(0x000);         /* indicator register set (not sure if this is required) */
222
-      ST7565_WRITE_BYTE(0x0AE);         /* display off */
223
-      ST7565_WRITE_BYTE(0x0A5);         /* all points on */
224
-      ST7565_CS();                      /* disable chip , bugfix 12 nov 2014 */
225
-                                        /* end of sequence */
226
-      return 1;
227
-
228
-    case U8G_DEV_MSG_SLEEP_OFF:
229
-      ST7565_NA0();                     /* instruction mode */
230
-      ST7565_NCS();                     /* enable chip */
231
-      ST7565_WRITE_BYTE(0x0A4);         /* all points off */
232
-      ST7565_WRITE_BYTE(0x0AF);         /* display on */
233
-      U8G_ESC_DLY(50);                  /* delay 50 ms */
234
-      ST7565_CS();                      /* disable chip ,  bugfix 12 nov 2014 */
235
-                                        /* end of sequence */
236
-      return 1;
237
-  }
238
-  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
239
-}
240
-
241
-uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[WIDTH*2] U8G_NOCOMMON ;
242
-u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
243
-u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = { u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn};
244
-
245
-
246
-class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
247
-  public:
248
-  U8GLIB_ST7565_64128n_2x_VIKI(uint8_t dummy)
249
-    : U8GLIB(&u8g_dev_st7565_64128n_2x_VIKI_sw_spi)
250
-    {  }
251
-  U8GLIB_ST7565_64128n_2x_VIKI(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE)
252
-    : U8GLIB(&u8g_dev_st7565_64128n_2x_VIKI_sw_spi)
253
-    {  }
254
-};
255
-
256
-#pragma GCC reset_options
257
-
258
-#endif // U8GLIB_ST7565
259
-#endif // ULCDST7565_H

Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd.h → Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp View File

@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 4
  *
5 5
  * Based on Sprinter and grbl.
6 6
  * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
@@ -20,16 +20,25 @@
20 20
  *
21 21
  */
22 22
 
23
-#ifndef ULCDST7920_H
24
-#define ULCDST7920_H
23
+// NOTE - the HAL version of the rrd device uses a generic ST7920 device.  See the
24
+// file u8g_dev_st7920_128x64_HAL.cpp for the HAL version.
25 25
 
26
-#include "../../Marlin.h"
26
+#ifndef U8G_HAL_LINKS
27 27
 
28
-#if ENABLED(U8GLIB_ST7920)
28
+#include <src/Marlin.h>
29 29
 
30
+//#if ENABLED(U8GLIB_ST7920)
31
+//#if ( ENABLED(SHARED_SPI) || !ENABLED(SHARED_SPI) && (defined(LCD_PINS_D4) &&  LCD_PINS_D4 >= 0) &&  (defined(LCD_PINS_ENABLE) &&  LCD_PINS_ENABLE >= 0))
32
+
33
+#define ST7920_CLK_PIN  23
34
+#define ST7920_DAT_PIN  17
35
+#define ST7920_CS_PIN   16
36
+
37
+/*
30 38
 #define ST7920_CLK_PIN  LCD_PINS_D4
31 39
 #define ST7920_DAT_PIN  LCD_PINS_ENABLE
32 40
 #define ST7920_CS_PIN   LCD_PINS_RS
41
+*/
33 42
 
34 43
 //#define PAGE_HEIGHT 8   //128 byte framebuffer
35 44
 #define PAGE_HEIGHT 16  //256 byte framebuffer
@@ -52,15 +61,15 @@
52 61
   #define CPU_ST7920_DELAY_1 DELAY_0_NOP
53 62
   #define CPU_ST7920_DELAY_2 DELAY_0_NOP
54 63
   #define CPU_ST7920_DELAY_3 DELAY_1_NOP
55
-#elif MB(3DRAG) || MB(K8200) || MB(K8400) || MB(SILVER_GATE)
64
+#elif (MOTHERBOARD == BOARD_3DRAG) || (MOTHERBOARD == BOARD_K8200) || (MOTHERBOARD == BOARD_K8400)
56 65
   #define CPU_ST7920_DELAY_1 DELAY_0_NOP
57 66
   #define CPU_ST7920_DELAY_2 DELAY_3_NOP
58 67
   #define CPU_ST7920_DELAY_3 DELAY_0_NOP
59
-#elif MB(MINIRAMBO)
68
+#elif (MOTHERBOARD == BOARD_MINIRAMBO)
60 69
   #define CPU_ST7920_DELAY_1 DELAY_0_NOP
61 70
   #define CPU_ST7920_DELAY_2 DELAY_4_NOP
62 71
   #define CPU_ST7920_DELAY_3 DELAY_0_NOP
63
-#elif MB(RAMBO)
72
+#elif (MOTHERBOARD == BOARD_RAMBO)
64 73
   #define CPU_ST7920_DELAY_1 DELAY_0_NOP
65 74
   #define CPU_ST7920_DELAY_2 DELAY_0_NOP
66 75
   #define CPU_ST7920_DELAY_3 DELAY_0_NOP
@@ -88,37 +97,23 @@
88 97
   #define U8G_DELAY() u8g_10MicroDelay()
89 98
 #endif
90 99
 
91
-#if ENABLED(SHARED_SPI)   // Re-ARM requires that the LCD and the SD card share a single SPI
92 100
 
93
-  #define ST7920_SET_CMD()         { spiSend(0xF8); U8G_DELAY(); }
94
-  #define ST7920_SET_DAT()         { spiSend(0xFA); U8G_DELAY(); }
95
-  #define ST7920_WRITE_BYTE(a)     { spiSend((uint8_t)((a)&0xF0u)); U8G_DELAY(); spiSend((uint8_t)((a)<<4u)); U8G_DELAY(); }
96
-  #define ST7920_WRITE_BYTES(p,l)  { for (uint8_t i = l + 1; --i;) { spiSend(*p&0xF0); spiSend(*p<<4); p++; } U8G_DELAY(); }
97
-
98
-#else
99 101
 
100
-  #define ST7920_SND_BIT \
101
-    WRITE(ST7920_CLK_PIN, LOW);        ST7920_DELAY_1; \
102
-    WRITE(ST7920_DAT_PIN, val & 0x80); ST7920_DELAY_2; \
103
-    WRITE(ST7920_CLK_PIN, HIGH);       ST7920_DELAY_3; \
104
-    val <<= 1
105
-
106
-  static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
107
-    ST7920_SND_BIT; // 1
108
-    ST7920_SND_BIT; // 2
109
-    ST7920_SND_BIT; // 3
110
-    ST7920_SND_BIT; // 4
111
-    ST7920_SND_BIT; // 5
112
-    ST7920_SND_BIT; // 6
113
-    ST7920_SND_BIT; // 7
114
-    ST7920_SND_BIT; // 8
102
+static void ST7920_WRITE_BYTE(uint8_t val) {
103
+  for (uint8_t i = 0; i < 8; i++) {
104
+    WRITE(ST7920_DAT_PIN, val & 0x80);
105
+    WRITE(ST7920_CLK_PIN, HIGH);
106
+    WRITE(ST7920_CLK_PIN, LOW);
107
+    val = val << 1;
115 108
   }
109
+}
110
+
111
+
112
+#define ST7920_SET_CMD()         { ST7920_WRITE_BYTE(0xF8); U8G_DELAY(); }
113
+#define ST7920_SET_DAT()         { ST7920_WRITE_BYTE(0xFA); U8G_DELAY(); }
114
+#define ST7920_WRITE_NIBBLES(a)     { ST7920_WRITE_BYTE((uint8_t)((a)&0xF0u)); ST7920_WRITE_BYTE((uint8_t)((a)<<4u)); U8G_DELAY(); }
115
+#define ST7920_WRITE_NIBBLES_P(p,l)  { for (uint8_t i = l + 1; --i;) { ST7920_WRITE_BYTE(*p&0xF0); ST7920_WRITE_BYTE(*p<<4); p++; } U8G_DELAY(); }
116 116
 
117
-  #define ST7920_SET_CMD()         { ST7920_SWSPI_SND_8BIT(0xF8); U8G_DELAY(); }
118
-  #define ST7920_SET_DAT()         { ST7920_SWSPI_SND_8BIT(0xFA); U8G_DELAY(); }
119
-  #define ST7920_WRITE_BYTE(a)     { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); U8G_DELAY(); }
120
-  #define ST7920_WRITE_BYTES(p,l)  { for (uint8_t i = l + 1; --i;) { ST7920_SWSPI_SND_8BIT(*p&0xF0); ST7920_SWSPI_SND_8BIT(*p<<4); p++; } U8G_DELAY(); }
121
-#endif
122 117
 
123 118
 #define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }
124 119
 #define ST7920_NCS()             { WRITE(ST7920_CS_PIN,0); }
@@ -131,47 +126,35 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
131 126
     case U8G_DEV_MSG_INIT: {
132 127
       OUT_WRITE(ST7920_CS_PIN, LOW);
133 128
 
134
-      #if ENABLED(SHARED_SPI)
135
-        u8g_Delay(250);
136
-        spiBegin();
137
-        spiInit(SPI_EIGHTH_SPEED);  // run LCD at 1 MHz - garbled display if run at 2 MHz
138
-      #else
129
+
139 130
         OUT_WRITE(ST7920_DAT_PIN, LOW);
140
-        OUT_WRITE(ST7920_CLK_PIN, HIGH);
141
-      #endif
131
+        OUT_WRITE(ST7920_CLK_PIN, LOW);
142 132
 
143 133
       ST7920_CS();
144 134
       u8g_Delay(120);                 //initial delay for boot up
145 135
       ST7920_SET_CMD();
146
-      ST7920_WRITE_BYTE(0x08);       //display off, cursor+blink off
147
-      ST7920_WRITE_BYTE(0x01);       //clear CGRAM ram
136
+      ST7920_WRITE_NIBBLES(0x08);       //display off, cursor+blink off
137
+      ST7920_WRITE_NIBBLES(0x01);       //clear CGRAM ram
148 138
       u8g_Delay(15);                 //delay for CGRAM clear
149
-      ST7920_WRITE_BYTE(0x3E);       //extended mode + GDRAM active
139
+      ST7920_WRITE_NIBBLES(0x3E);       //extended mode + GDRAM active
150 140
       for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
151
-        ST7920_WRITE_BYTE(0x80 | y); //set y
152
-        ST7920_WRITE_BYTE(0x80);     //set x = 0
141
+        ST7920_WRITE_NIBBLES(0x80 | y); //set y
142
+        ST7920_WRITE_NIBBLES(0x80);     //set x = 0
153 143
         ST7920_SET_DAT();
154 144
         for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
155
-          ST7920_WRITE_BYTE(0);
145
+          ST7920_WRITE_NIBBLES(0);
156 146
         ST7920_SET_CMD();
157 147
       }
158 148
 
159
-      ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
160
-      #if ENABLED(SHARED_SPI)
161
-        #ifndef SPI_SPEED
162
-            #define SPI_SPEED SPI_FULL_SPEED  // switch SPI speed back to SD card speed
163
-        #endif
164
-        spiInit(SPI_SPEED);
165
-      #endif
149
+      ST7920_WRITE_NIBBLES(0x0C); //display on, cursor+blink off
150
+
166 151
       ST7920_NCS();
167 152
     }
168 153
     break;
169 154
     case U8G_DEV_MSG_STOP:
170 155
       break;
171 156
     case U8G_DEV_MSG_PAGE_NEXT: {
172
-      #if ENABLED(SHARED_SPI)
173
-        spiInit(SPI_EIGHTH_SPEED);  // run LCD at 1 MHz - garbled display if run at 2 MHz
174
-      #endif
157
+
175 158
       uint8_t* ptr;
176 159
       u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
177 160
       y = pb->p.page_y0;
@@ -181,20 +164,18 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
181 164
       for (i = 0; i < PAGE_HEIGHT; i ++) {
182 165
         ST7920_SET_CMD();
183 166
         if (y < 32) {
184
-          ST7920_WRITE_BYTE(0x80 | y);       //y
185
-          ST7920_WRITE_BYTE(0x80);           //x=0
167
+          ST7920_WRITE_NIBBLES(0x80 | y);       //y
168
+          ST7920_WRITE_NIBBLES(0x80);           //x=0
186 169
         }
187 170
         else {
188
-          ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
189
-          ST7920_WRITE_BYTE(0x80 | 8);       //x=64
171
+          ST7920_WRITE_NIBBLES(0x80 | (y - 32)); //y
172
+          ST7920_WRITE_NIBBLES(0x80 | 8);       //x=64
190 173
         }
191 174
         ST7920_SET_DAT();
192
-        ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
175
+        ST7920_WRITE_NIBBLES_P(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
193 176
         y++;
194 177
       }
195
-      #if ENABLED(SHARED_SPI)
196
-        spiInit(SPI_SPEED);   // switch SPI speed back to SD card speed
197
-      #endif
178
+
198 179
       ST7920_NCS();
199 180
     }
200 181
     break;
@@ -212,12 +193,8 @@ uint8_t   u8g_dev_st7920_128x64_rrd_buf[(LCD_PIXEL_WIDTH) * (PAGE_HEIGHT) / 8] U
212 193
 u8g_pb_t  u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7920_128x64_rrd_buf};
213 194
 u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = {u8g_dev_rrd_st7920_128x64_fn, &u8g_dev_st7920_128x64_rrd_pb, &u8g_com_null_fn};
214 195
 
215
-class U8GLIB_ST7920_128X64_RRD : public U8GLIB {
216
- public:
217
-  U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) { UNUSED(dummy); }
218
-};
219
-
220 196
 #pragma GCC reset_options
221 197
 
222
-#endif // U8GLIB_ST7920
223
-#endif // ULCDST7920_H
198
+//#endif //( ENABLED(SHARED_SPI) || !ENABLED(SHARED_SPI) && (defined(LCD_PINS_D4) &&  LCD_PINS_D4 >= 0) &&  (defined(LCD_PINS_ENABLE) &&  LCD_PINS_ENABLE >= 0))
199
+//#endif // U8GLIB_ST7920
200
+#endif // AVR

+ 5
- 0
Marlin/src/lcd/ultralcd.cpp View File

@@ -4758,6 +4758,11 @@ void lcd_update() {
4758 4758
 
4759 4759
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
4760 4760
         if (!drawing_screen) {
4761
+#if defined(TARGET_LPC1768)
4762
+digitalWrite(P1_4, !digitalRead(P1_4));  //re-arm (was 77 in the old system)
4763
+#else
4764
+digitalWrite(29, !digitalRead(29));  //2560
4765
+#endif           
4761 4766
           u8g.firstPage();
4762 4767
           drawing_screen = 1;
4763 4768
         }

+ 35
- 30
Marlin/src/lcd/ultralcd_impl_DOGM.h View File

@@ -44,11 +44,13 @@
44 44
  */
45 45
 #include "ultralcd.h"
46 46
 
47
+/*
47 48
 #if ENABLED(U8GLIB_ST7565_64128N)
48 49
   #include "dogm/ultralcd_st7565_u8glib_VIKI.h"
49 50
 #elif ENABLED(U8GLIB_ST7920)
50 51
   #include "dogm/ultralcd_st7920_u8glib_rrd.h"
51 52
 #endif
53
+*/
52 54
 
53 55
 #include "dogm/dogm_bitmaps.h"
54 56
 
@@ -57,6 +59,7 @@
57 59
 #endif
58 60
 
59 61
 #include <U8glib.h>
62
+#include <src/lcd/dogm/HAL_LCD_class_defines.h>
60 63
 
61 64
 #if ENABLED(AUTO_BED_LEVELING_UBL)
62 65
   #include "../feature/bedlevel/ubl/ubl.h"
@@ -161,53 +164,52 @@
161 164
 
162 165
 // LCD selection
163 166
 #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
164
-  U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes
165
-  // U8GLIB_ST7920_128X64 u8g(LCD_PINS_RS); // 8 stripes
166
-#elif ENABLED(U8GLIB_ST7920)
167
-  //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes
168
-                                                                            // No 4 stripe device available from u8glib.
169
-  //U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS);    // Original u8glib device. 8 stripes
170
-  U8GLIB_ST7920_128X64_RRD u8g(0); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
167
+    U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes, HW SPI
168
+    //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes, SW SPI
169
+#elif ENABLED(U8GLIB_ST7920) 
170
+  // RepRap Discount Full Graphics Smart Controller
171
+    //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes, HW SPI
172
+    //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes, SW SPI   
173
+    U8GLIB_ST7920_128X64_RRD u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
174
+                                                                           // AVR version ignores these pin settings  
175
+                                                                           // HAL version uses these pin settings
171 176
 #elif ENABLED(CARTESIO_UI)
172 177
   // The CartesioUI display
173
-  #if DOGLCD_MOSI != -1 && DOGLCD_SCK != -1
174
-    // using SW-SPI
175
-    //U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);  // 8 stripes
176
-    U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
177
-  #else
178
-    //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
178
+    //U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
179 179
     U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
180
-  #endif
180
+
181 181
 #elif ENABLED(U8GLIB_LM6059_AF)
182 182
   // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
183
-  //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
184
-  U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
183
+    //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
184
+    U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
185 185
 #elif ENABLED(U8GLIB_ST7565_64128N)
186 186
   // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller
187
-  //U8GLIB_ST7565_64128n_2x_VIKI u8g(0);  // using SW-SPI DOGLCD_MOSI != -1 && DOGLCD_SCK
188
-  U8GLIB_ST7565_64128n_2x_VIKI u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);  // using SW-SPI
189
-  //U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
190
-  //U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes  HWSPI
187
+    //U8GLIB_64128N_2X_HAL u8g(DOGLCD_CS, DOGLCD_A0);  // using HW-SPI
188
+    U8GLIB_64128N_2X_HAL u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);  // using SW-SPI
189
+
191 190
 #elif ENABLED(U8GLIB_SSD1306)
192 191
   // Generic support for SSD1306 OLED I2C LCDs
193
-  //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes
194
-  U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
192
+    //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes
193
+    U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE  u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes  
194
+    //U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
195
+
195 196
 #elif ENABLED(MKS_12864OLED)
196 197
   // MKS 128x64 (SH1106) OLED I2C LCD
197
-  U8GLIB_SH1106_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);      // 8 stripes
198
-  //U8GLIB_SH1106_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
198
+    U8GLIB_SH1106_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);      // 8 stripes
199
+    //U8GLIB_SH1106_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
199 200
 #elif ENABLED(U8GLIB_SH1106)
200 201
   // Generic support for SH1106 OLED I2C LCDs
201
-  //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes
202
-  U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
202
+    //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes
203
+    U8GLIB_SH1106_128X64_2X_I2C_2_WIRE  u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes  
204
+    //U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
203 205
 #elif ENABLED(MINIPANEL)
204 206
   // The MINIPanel display
205
-  //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
206
-  U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
207
+    //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
208
+    U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
207 209
 #else
208 210
   // for regular DOGM128 display with HW-SPI
209
-  //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0  // 8 stripes
210
-  U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0 // 4 stripes
211
+    //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0  // 8 stripes
212
+    U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0 // 4 stripes
211 213
 #endif
212 214
 
213 215
 #ifndef LCD_PIXEL_WIDTH
@@ -311,6 +313,8 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
311 313
     const uint8_t offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2,
312 314
                   txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
313 315
 
316
+    static bool show_bootscreen = true;
317
+
314 318
     u8g.firstPage();
315 319
     do {
316 320
       u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
@@ -354,6 +358,7 @@ static void lcd_implementation_init() {
354 358
   #elif ENABLED(LCD_SCREEN_ROT_270)
355 359
     u8g.setRot270();  // Rotate screen by 270°
356 360
   #endif
361
+
357 362
 }
358 363
 
359 364
 // The kill screen is displayed for unrecoverable conditions

+ 11
- 4
platformio.ini View File

@@ -19,13 +19,15 @@ env_default = megaatmega2560
19 19
 
20 20
 [common]
21 21
 lib_deps =
22
-  U8glib@1.19.1
22
+
23 23
   LiquidCrystal_I2C@1.1.2
24 24
   https://github.com/lincomatic/LiquidTWI2.git
25 25
   https://github.com/teemuatlut/TMC2130Stepper.git
26 26
   https://github.com/trinamic/TMC26XStepper.git
27 27
   https://github.com/adafruit/Adafruit_NeoPixel.git
28 28
   https://github.com/ameyer/Arduino-L6470.git
29
+  U8glib-HAL
30
+
29 31
 
30 32
 default_src_filter = +<src/*> -<src/config>
31 33
 
@@ -47,6 +49,7 @@ platform    = atmelavr
47 49
 framework   = arduino
48 50
 board       = megaatmega2560
49 51
 build_flags = -I $BUILDSRC_DIR
52
+  -fmax-errors=5
50 53
 board_f_cpu = 16000000L
51 54
 lib_deps    = ${common.lib_deps}
52 55
 src_filter  = ${common.default_src_filter}
@@ -145,11 +148,14 @@ src_filter  = ${common.default_src_filter}
145 148
 platform        = nxplpc
146 149
 board_f_cpu     = 100000000L
147 150
 build_flags     = !python Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
151
+  -DU8G_HAL_LINKS
148 152
 src_build_flags = -Wall
149 153
 build_unflags   = -Wall
150 154
 lib_ldf_mode    = off
151 155
 lib_extra_dirs  = frameworks
152
-lib_deps        = U8glib-ARM, CMSIS-LPC1768
156
+#lib_deps        = U8glib-ARM, CMSIS-LPC1768
157
+lib_deps        = CMSIS-LPC1768
158
+  U8glib-HAL
153 159
 extra_scripts   = Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
154 160
 src_filter      = ${common.default_src_filter}
155 161
 
@@ -163,9 +169,11 @@ platform       = nxplpc
163 169
 board          = lpc1768
164 170
 board_f_cpu    = 100000000L
165 171
 build_flags    = !python Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
172
+  -DU8G_HAL_LINKS
166 173
 lib_ldf_mode   = off
167 174
 lib_extra_dirs = frameworks
168
-lib_deps       = U8glib-ARM, CMSIS-LPC1768
175
+lib_deps       = CMSIS-LPC1768
176
+  U8glib-HAL
169 177
 src_filter     = ${common.default_src_filter}
170 178
 extra_scripts  =  Marlin/src/HAL/HAL_LPC1768/debug_extra_script.py, Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
171 179
 debug_tool     = custom
@@ -190,4 +198,3 @@ board       = genericSTM32F103RE
190 198
 build_flags = !python Marlin/src/HAL/HAL_STM32F1/stm32f1_flag_script.py
191 199
 lib_deps    = ${common.lib_deps}
192 200
 src_filter  = ${common.default_src_filter}
193
-

Loading…
Cancel
Save