|
@@ -1,254 +0,0 @@
|
1
|
|
-/**
|
2
|
|
- * Marlin 3D Printer Firmware
|
3
|
|
- * Copyright (c) 2019 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
|
|
- * Based on U8G2 code - u8x8_byte.c
|
25
|
|
- *
|
26
|
|
- * Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
27
|
|
- *
|
28
|
|
- * Copyright (c) 2016, olikraus@gmail.com
|
29
|
|
- * All rights reserved.
|
30
|
|
- *
|
31
|
|
- * Redistribution and use in source and binary forms, with or without modification,
|
32
|
|
- * are permitted provided that the following conditions are met:
|
33
|
|
- *
|
34
|
|
- * * Redistributions of source code must retain the above copyright notice, this list
|
35
|
|
- * of conditions and the following disclaimer.
|
36
|
|
- *
|
37
|
|
- * * Redistributions in binary form must reproduce the above copyright notice, this
|
38
|
|
- * list of conditions and the following disclaimer in the documentation and/or other
|
39
|
|
- * materials provided with the distribution.
|
40
|
|
- *
|
41
|
|
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
42
|
|
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
43
|
|
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
44
|
|
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
45
|
|
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
46
|
|
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47
|
|
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48
|
|
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49
|
|
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
50
|
|
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51
|
|
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52
|
|
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
53
|
|
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
54
|
|
- */
|
55
|
|
-
|
56
|
|
-/**
|
57
|
|
- * Software i2c,
|
58
|
|
- * ignores ACK response (which is anyway not provided by some displays)
|
59
|
|
- * also does not allow reading from the device
|
60
|
|
- */
|
61
|
|
-
|
62
|
|
-#ifdef TARGET_LPC1768
|
63
|
|
-
|
64
|
|
-#include "../../inc/MarlinConfigPre.h"
|
65
|
|
-
|
66
|
|
-#if HAS_GRAPHICAL_LCD
|
67
|
|
-
|
68
|
|
-#include <U8glib.h>
|
69
|
|
-
|
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
|
|
-// #define U8G_I2C_OPT_FAST 16
|
84
|
|
-
|
85
|
|
-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;
|
86
|
|
-
|
87
|
|
-#define SPI_SPEED 2 //20: 200KHz 5:750KHz 2:3-4MHz
|
88
|
|
-
|
89
|
|
-uint8_t u8g_i2c_send_byte_sw(uint8_t data) {
|
90
|
|
- for (uint8_t i = 0; i < 9; i++) { // 1 extra bit for the ack/nak
|
91
|
|
-
|
92
|
|
- if (val & 0x80)
|
93
|
|
- for (uint8_t j = 0; j < SPI_SPEED; j++) {
|
94
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
95
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
96
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
97
|
|
- }
|
98
|
|
- else
|
99
|
|
- for (uint8_t j = 0; j < SPI_SPEED; j++) {
|
100
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
101
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
102
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- for (uint8_t j = 0; j < SPI_SPEED; j++) {
|
106
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
107
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
108
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
109
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
110
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
111
|
|
- }
|
112
|
|
-
|
113
|
|
- for (uint8_t j = 0; j < SPI_SPEED; j++) {
|
114
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
115
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
116
|
|
- }
|
117
|
|
- val <<= 1;
|
118
|
|
- }
|
119
|
|
- return 1;
|
120
|
|
-}
|
121
|
|
-
|
122
|
|
-
|
123
|
|
-uint8_t u8g_i2c_start_sw(uint8_t sla) { // assert start condition and then send slave address with write bit
|
124
|
|
- /* send the start condition, both lines go from 1 to 0 */
|
125
|
|
-
|
126
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
127
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
128
|
|
- DELAY_US(2);
|
129
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
130
|
|
- DELAY_US(2);
|
131
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
132
|
|
- DELAY_US(2);
|
133
|
|
- LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
134
|
|
- DELAY_US(2);
|
135
|
|
- LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
136
|
|
-
|
137
|
|
- u8g_i2c_send_byte_sw(I2C_SLA); // send slave address with write bit
|
138
|
|
-}
|
139
|
|
-
|
140
|
|
-
|
141
|
|
-void u8g_i2c_stop_sw() { }
|
142
|
|
-
|
143
|
|
-void u8g_i2c_init_sw(uint8_t clock_option) { u8g_i2c_start(0); } // send slave address and write bit
|
144
|
|
-
|
145
|
|
-uint8_t u8g_com_ssd_I2C_start_sequence_sw(u8g_t *u8g) {
|
146
|
|
- /* are we requested to set the a0 state? */
|
147
|
|
- if (u8g->pin_list[U8G_PI_SET_A0] == 0) return 1;
|
148
|
|
-
|
149
|
|
- /* setup bus, might be a repeated start */
|
150
|
|
- if (u8g_i2c_start(I2C_SLA) == 0) return 0;
|
151
|
|
- if (u8g->pin_list[U8G_PI_A0_STATE] == 0) {
|
152
|
|
- if (u8g_i2c_send_byte(I2C_CMD_MODE) == 0) return 0;
|
153
|
|
- }
|
154
|
|
- else if (u8g_i2c_send_byte(I2C_DATA_MODE) == 0) return 0;
|
155
|
|
-
|
156
|
|
- u8g->pin_list[U8G_PI_SET_A0] = 0;
|
157
|
|
-
|
158
|
|
- return 1;
|
159
|
|
-}
|
160
|
|
-
|
161
|
|
-uint8_t u8g_com_HAL_LPC1768_ssd_sw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
|
162
|
|
- switch (msg) {
|
163
|
|
- case U8G_COM_MSG_INIT:
|
164
|
|
-
|
165
|
|
- #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
|
166
|
|
- #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
|
167
|
|
- SCL_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCL]);
|
168
|
|
- SCL_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCL]);
|
169
|
|
- SDA_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SDA]);
|
170
|
|
- SDA_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SDA]);
|
171
|
|
- // As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
|
172
|
|
- #define OUTPUT 0x1
|
173
|
|
- u8g_SetPIOutput(u8g, U8G_PI_SCL);
|
174
|
|
- u8g_SetPIOutput(u8g, U8G_PI_SDA);
|
175
|
|
- if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS]) u8g_SetPIOutput(u8g, U8G_PI_CS);
|
176
|
|
- if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_A0]) u8g_SetPIOutput(u8g, U8G_PI_A0);
|
177
|
|
- if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
178
|
|
-
|
179
|
|
- //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
|
180
|
|
- //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
|
181
|
|
- //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* initial RS state: unknown mode */
|
182
|
|
-
|
183
|
|
- u8g_i2c_init_sw(u8g->pin_list[U8G_PI_I2C_OPTION]);
|
184
|
|
- u8g_com_ssd_I2C_start_sequence_sw(u8g);
|
185
|
|
- break;
|
186
|
|
-
|
187
|
|
- case U8G_COM_MSG_STOP: break;
|
188
|
|
-
|
189
|
|
- case U8G_COM_MSG_RESET: break;
|
190
|
|
-
|
191
|
|
- case U8G_COM_MSG_CHIP_SELECT:
|
192
|
|
- u8g->pin_list[U8G_PI_A0_STATE] = 0;
|
193
|
|
- u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
|
194
|
|
- if (arg_val == 0) {
|
195
|
|
- /* disable chip, send stop condition */
|
196
|
|
- u8g_i2c_stop_sw();
|
197
|
|
- }
|
198
|
|
- else {
|
199
|
|
- /* enable, do nothing: any byte writing will trigger the i2c start */
|
200
|
|
- }
|
201
|
|
- break;
|
202
|
|
-
|
203
|
|
- case U8G_COM_MSG_WRITE_BYTE:
|
204
|
|
- //u8g->pin_list[U8G_PI_SET_A0] = 1;
|
205
|
|
- //if (u8g_com_arduino_ssd_start_sequence(u8g) == 0)
|
206
|
|
- // return u8g_i2c_stop(), 0;
|
207
|
|
- if (u8g_i2c_send_byte_sw(arg_val) == 0)
|
208
|
|
- return u8g_i2c_stop_sw(), 0;
|
209
|
|
- // u8g_i2c_stop();
|
210
|
|
- break;
|
211
|
|
-
|
212
|
|
- case U8G_COM_MSG_WRITE_SEQ: {
|
213
|
|
- //u8g->pin_list[U8G_PI_SET_A0] = 1;
|
214
|
|
- if (u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0)
|
215
|
|
- return u8g_i2c_stop_sw(), 0;
|
216
|
|
-
|
217
|
|
- uint8_t *ptr = (uint8_t *)arg_ptr;
|
218
|
|
- while (arg_val > 0) {
|
219
|
|
- if (u8g_i2c_send_byte_sw(*ptr++) == 0)
|
220
|
|
- return u8g_i2c_stop_sw(), 0;
|
221
|
|
- arg_val--;
|
222
|
|
- }
|
223
|
|
- }
|
224
|
|
- // u8g_i2c_stop();
|
225
|
|
- break;
|
226
|
|
-
|
227
|
|
- case U8G_COM_MSG_WRITE_SEQ_P: {
|
228
|
|
- //u8g->pin_list[U8G_PI_SET_A0] = 1;
|
229
|
|
- if (u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0)
|
230
|
|
- return u8g_i2c_stop_sw(), 0;
|
231
|
|
-
|
232
|
|
- uint8_t *ptr = (uint8_t *)arg_ptr;
|
233
|
|
- while (arg_val > 0) {
|
234
|
|
- if (u8g_i2c_send_byte_sw(u8g_pgm_read(ptr)) == 0) return 0;
|
235
|
|
- ptr++;
|
236
|
|
- arg_val--;
|
237
|
|
- }
|
238
|
|
- }
|
239
|
|
- // u8g_i2c_stop();
|
240
|
|
- break;
|
241
|
|
-
|
242
|
|
- case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
243
|
|
- u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
244
|
|
- u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
|
245
|
|
- u8g_i2c_start_sw(0); // send slave address and write bit
|
246
|
|
- u8g_i2c_send_byte_sw(arg_val ? 0x40 : 0x80); // Write to ? Graphics DRAM mode : Command mode
|
247
|
|
- break;
|
248
|
|
- }
|
249
|
|
- return 1;
|
250
|
|
-}
|
251
|
|
-
|
252
|
|
-#endif // HAS_GRAPHICAL_LCD
|
253
|
|
-
|
254
|
|
-#endif // TARGET_LPC1768
|