Skip to content

Commit bd36644

Browse files
committed
πŸ§‘β€πŸ’» Move U8G defines to HALs
1 parent c485f51 commit bd36644

30 files changed

+376
-164
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 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 <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* AVR LCD-specific defines
26+
*/
27+
28+
uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29+
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_AVR_sw_sp_fn
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 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 <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* DUE (SAM3X8E) LCD-specific defines
26+
*/
27+
28+
uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29+
uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
30+
uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
31+
32+
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_DUE_sw_spi_fn
33+
#define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_DUE_shared_hw_spi_fn
34+
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_DUE_ST7920_sw_spi_fn

β€ŽMarlin/src/HAL/ESP32/inc/Conditionals_LCD.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
*
2121
*/
2222
#pragma once
23+
24+
#if ANY(MKS_MINI_12864, FYSETC_MINI_12864_2_1)
25+
#define U8G_HW_SPI_ESP32 1
26+
#endif
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 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 <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* ESP32 LCD-specific defines
26+
*/
27+
28+
uint8_t u8g_esp32_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29+
#define U8G_COM_HAL_HW_SPI_FN u8g_esp32_hw_spi_fn

β€ŽMarlin/src/HAL/ESP32/u8g_esp32_spi.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "../../inc/MarlinConfig.h"
2727

28-
#if ANY(MKS_MINI_12864, FYSETC_MINI_12864_2_1)
28+
#if U8G_HW_SPI_ESP32
2929

3030
#include <U8glib-HAL.h>
3131
#include "../shared/HAL_SPI.h"
@@ -41,7 +41,6 @@
4141

4242
static SPISettings spiConfig;
4343

44-
4544
#ifndef LCD_SPI_SPEED
4645
#ifdef SD_SPI_SPEED
4746
#define LCD_SPI_SPEED SD_SPI_SPEED // Assume SPI speed shared with SD
@@ -50,7 +49,7 @@ static SPISettings spiConfig;
5049
#endif
5150
#endif
5251

53-
uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
52+
uint8_t u8g_esp32_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
5453
static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
5554

5655
#if ENABLED(PAUSE_LCD_FOR_BUSY_SD)
@@ -101,6 +100,5 @@ uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_pt
101100
return 1;
102101
}
103102

104-
#endif // MKS_MINI_12864 || FYSETC_MINI_12864_2_1
105-
103+
#endif // U8G_HW_SPI_ESP32
106104
#endif // ARDUINO_ARCH_ESP32
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 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 <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* HC32 LCD-specific defines
26+
*/
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 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 <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* Linux LCD-specific defines
26+
*/

β€ŽMarlin/src/HAL/LPC1768/Servo.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* License along with this library; if not, write to the Free Software
4040
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4141
*/
42-
#pragma once
4342

4443
/**
4544
* Based on "servo.h - Interrupt driven Servo library for Arduino using 16 bit timers -

β€ŽMarlin/src/HAL/LPC1768/u8g/LCD_defines.h

+15-18
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,22 @@
2525
* LPC1768 LCD-specific defines
2626
*/
2727

28-
// The following are optional depending on the platform.
28+
#ifndef U8G_HAL_LINKS
2929

30-
// definitions of HAL specific com and device drivers.
31-
uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
32-
uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
33-
uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
34-
uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
35-
uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
30+
#define U8G_COM_SSD_I2C_HAL u8g_com_arduino_ssd_i2c_fn // See U8glib-HAL
3631

32+
#else
3733

38-
// connect U8g com generic com names to the desired driver
39-
#define U8G_COM_HW_SPI u8g_com_HAL_LPC1768_hw_spi_fn // use LPC1768 specific hardware SPI routine
40-
#define U8G_COM_SW_SPI u8g_com_HAL_LPC1768_sw_spi_fn // use LPC1768 specific software SPI routine
41-
#define U8G_COM_ST7920_HW_SPI u8g_com_HAL_LPC1768_ST7920_hw_spi_fn
42-
#define U8G_COM_ST7920_SW_SPI u8g_com_HAL_LPC1768_ST7920_sw_spi_fn
43-
#define U8G_COM_SSD_I2C u8g_com_HAL_LPC1768_ssd_hw_i2c_fn
34+
uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
35+
uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
36+
uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
37+
uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
38+
uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
4439

45-
// let these default for now
46-
#define U8G_COM_PARALLEL u8g_com_null_fn
47-
#define U8G_COM_T6963 u8g_com_null_fn
48-
#define U8G_COM_FAST_PARALLEL u8g_com_null_fn
49-
#define U8G_COM_UC_I2C u8g_com_null_fn
40+
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_LPC1768_sw_spi_fn
41+
#define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_LPC1768_hw_spi_fn
42+
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_LPC1768_ST7920_sw_spi_fn
43+
#define U8G_COM_ST7920_HAL_HW_SPI u8g_com_HAL_LPC1768_ST7920_hw_spi_fn
44+
#define U8G_COM_SSD_I2C_HAL u8g_com_HAL_LPC1768_ssd_hw_i2c_fn
45+
46+
#endif

β€ŽMarlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,4 @@ uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
125125
}
126126

127127
#endif // HAS_MARLINUI_U8GLIB
128-
129128
#endif // TARGET_LPC1768

β€ŽMarlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,4 @@ uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_v
194194
}
195195

196196
#endif // HAS_MARLINUI_U8GLIB
197-
198197
#endif // TARGET_LPC1768

β€ŽMarlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,4 @@ uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t ar
134134
}
135135

136136
#endif // HAS_MARLINUI_U8GLIB
137-
138137
#endif // TARGET_LPC1768

β€ŽMarlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
131131

132132
static uint8_t SPI_speed = 0;
133133

134-
static void u8g_sw_spi_HAL_LPC1768_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
134+
static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
135135
#if ANY(FYSETC_MINI_12864, MKS_MINI_12864)
136136
swSpiTransfer_mode_3(val, SPI_speed, clockPin, -1, dataPin);
137137
#else
@@ -176,13 +176,13 @@ uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
176176
break;
177177

178178
case U8G_COM_MSG_WRITE_BYTE:
179-
u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
179+
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
180180
break;
181181

182182
case U8G_COM_MSG_WRITE_SEQ: {
183183
uint8_t *ptr = (uint8_t *)arg_ptr;
184184
while (arg_val > 0) {
185-
u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
185+
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
186186
arg_val--;
187187
}
188188
}
@@ -191,7 +191,7 @@ uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
191191
case U8G_COM_MSG_WRITE_SEQ_P: {
192192
uint8_t *ptr = (uint8_t *)arg_ptr;
193193
while (arg_val > 0) {
194-
u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
194+
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
195195
ptr++;
196196
arg_val--;
197197
}

β€ŽMarlin/src/HAL/NATIVE_SIM/u8g/LCD_defines.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,14 @@
2121
*/
2222
#pragma once
2323

24+
/**
25+
* Native/Simulator LCD-specific defines
26+
*/
27+
2428
void usleep(uint64_t microsec);
25-
// The following are optional depending on the platform.
2629

27-
// definitions of HAL specific com and device drivers.
2830
uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
2931
uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
3032

31-
// connect U8g com generic com names to the desired driver
32-
#define U8G_COM_SW_SPI u8g_com_sw_spi_fn
33-
#define U8G_COM_ST7920_SW_SPI u8g_com_ST7920_sw_spi_fn
34-
35-
// let these default for now
36-
#define U8G_COM_HW_SPI u8g_com_null_fn
37-
#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
38-
#define U8G_COM_SSD_I2C u8g_com_null_fn
39-
#define U8G_COM_PARALLEL u8g_com_null_fn
40-
#define U8G_COM_T6963 u8g_com_null_fn
41-
#define U8G_COM_FAST_PARALLEL u8g_com_null_fn
42-
#define U8G_COM_UC_I2C u8g_com_null_fn
33+
#define U8G_COM_HAL_SW_SPI_FN u8g_com_sw_spi_fn
34+
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_ST7920_sw_spi_fn

β€ŽMarlin/src/HAL/NATIVE_SIM/u8g/u8g_com_st7920_sw_spi.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static void u8g_com_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
100100
swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
101101
swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
102102
}
103+
103104
#ifdef __cplusplus
104105
extern "C" {
105106
#endif
@@ -128,7 +129,7 @@ uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
128129
break;
129130

130131
case U8G_COM_MSG_RESET:
131-
if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
132+
if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
132133
break;
133134

134135
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
@@ -163,6 +164,7 @@ uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
163164
}
164165
return 1;
165166
}
167+
166168
#ifdef __cplusplus
167169
}
168170
#endif

β€ŽMarlin/src/HAL/SAMD21/u8g/LCD_defines.h

+1-13
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,11 @@
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
23-
/**
24-
* SAMD21 HAL developed by Bart Meijer (brupje)
25-
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
26-
*/
2722
#pragma once
2823

2924
/**
3025
* SAMD21 LCD-specific defines
3126
*/
3227

33-
// The following are optional depending on the platform.
34-
35-
// definitions of HAL specific com and device drivers.
36-
uint8_t u8g_com_samd21_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
3728
uint8_t u8g_com_samd21_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
38-
39-
// connect U8g com generic com names to the desired driver
40-
#define U8G_COM_HW_SPI u8g_com_samd21_st7920_hw_spi_fn // use SAMD21 specific hardware SPI routine
41-
#define U8G_COM_ST7920_HW_SPI u8g_com_samd21_st7920_hw_spi_fn
29+
#define U8G_COM_ST7920_HAL_HW_SPI u8g_com_samd21_st7920_hw_spi_fn

0 commit comments

Comments
Β (0)