grblHAL core  20260411
expanders_init.h
Go to the documentation of this file.
1 /*
2  expanders_init.h - An embedded CNC Controller with rs274/ngc (g-code) support
3 
4  Calls the init function of enabled expanders, this file is typically included early in driver.h
5  io_expanders_init() should be called at the end of the drivers driver_init() implementation,
6  just before the driver claims ports.
7 
8  These are NOT referenced in the core grblHAL code
9 
10  Part of grblHAL
11 
12  Copyright (c) 2025-2026 Terje Io
13 
14  grblHAL is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  grblHAL is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #pragma once
29 
30 extern void board_ports_init (void); // default is a weak function
31 
32 // I2C expanders
33 
34 #if PCA9654E_ENABLE || MCP3221_ENABLE || MCP4725_ENABLE || FLEXGPIO_ENABLE
35 
36 #if defined(I2C_ENABLE) && !I2C_ENABLE
37 #undef I2C_ENABLE
38 #endif
39 
40 #ifndef I2C_ENABLE
41 #define I2C_ENABLE 1
42 #endif
43 
44 #if MCP3221_ENABLE
45 extern void mcp3221_init (void);
46 #endif
47 
48 #if MCP4725_ENABLE
49 extern void mcp4725_init (void);
50 #endif
51 
52 #if PCA9654E_ENABLE
53 extern void pca9654e_init (void);
54 #endif
55 
56 // Third party I2C expander plugins goes after this line
57 
58 #if FLEXGPIO_ENABLE
59 extern void flexgpio_init (void);
60 #endif
61 
62 #endif // I2C expanders
63 
64 // SPI expanders
65 
66 #if HC595_ENABLE
67 
68 #if defined(SPI_ENABLE) && !SPI_ENABLE
69 #undef SPI_ENABLE
70 #endif
71 
72 #ifndef SPI_ENABLE
73 #define SPI_ENABLE 1
74 #endif
75 
76 #endif
77 
78 #if HC595_ENABLE
79 extern void hc595_init (void);
80 #endif
81 
82 //
83 
84 // ModBus expanders
85 
86 #if PICOHAL_IO_ENABLE || R4SLS08_ENABLE
87 
88 #if !defined(MODBUS_ENABLE) || !(MODBUS_ENABLE & MODBUS_RTU_ENABLED)
89 #error "Enabled IO expander(s) require Modbus RTU!"
90 #endif
91 
92 #if R4SLS08_ENABLE
93 extern void r4sls08_init (void);
94 #endif
95 
96 // Third party Modbus expander plugins goes after this line
97 
98 #if PICOHAL_IO_ENABLE
99 extern void picohal_io_init (void);
100 #endif
101 
102 #endif // ModBus expanders
103 
104 // CANBus expanders
105 
106 //
107 
108 // Other expanders
109 
110 #if THCAD2_ENABLE
111  extern void thcad2_init (void);
112 #endif
113 
114 #if FNC_EXPANDER_ENABLE
115  void fnc_expander_init (void);
116 #endif
117 
118 //
119 
120 static inline void io_expanders_init (void)
121 {
122  board_ports_init(); // can be implemented by board specific code
123 
124 #if HC595_ENABLE
125  hc595_init();
126 #endif
127 
128 #if MCP3221_ENABLE
129  mcp3221_init();
130 #endif
131 
132 #if MCP4725_ENABLE
133  mcp4725_init();
134 #endif
135 
136 #if R4SLS08_ENABLE
137  r4sls08_init();
138 #endif
139 
140 #if PCA9654E_ENABLE
141  pca9654e_init();
142 #endif
143 
144 #if FLEXGPIO_ENABLE
145  flexgpio_init();
146 #endif
147 
148 #if PICOHAL_IO_ENABLE
149  picohal_io_init();
150 #endif
151 
152 #if FNC_EXPANDER_ENABLE
153  fnc_expander_init();
154 #endif
155 
156 #if THCAD2_ENABLE
157  thcad2_init();
158 #endif
159 }
void board_ports_init(void)
Definition: grbllib.c:110