grblHAL core  20251111
plugins.h
Go to the documentation of this file.
1 /*
2  plugins.h - An embedded CNC Controller with rs274/ngc (g-code) support
3 
4  Some data structures and function declarations for plugins that require driver code
5 
6  These are NOT referenced in the core grbl code
7 
8  Part of grblHAL
9 
10  Copyright (c) 2020-2025 Terje Io
11 
12  grblHAL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  grblHAL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #ifndef _PLUGINS_H_
27 #define _PLUGINS_H_
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 
32 #include "nvs.h"
33 
34 // Jogging
35 
36 typedef struct {
37  float fast_speed;
38  float slow_speed;
39  float step_speed;
44 
45 // Networking
46 
47 typedef enum {
52 
53 typedef union {
54  uint8_t mask;
55  struct {
56  uint8_t telnet :1,
58  http :1,
59  ftp :1,
60  dns :1,
61  mdns :1,
62  ssdp :1,
63  webdav :1;
64  };
66 
67 typedef char ssid_t[65];
68 typedef uint8_t bssid_t[6];
69 typedef char username_t[33];
70 typedef char password_t[33];
71 typedef char hostname_t[33];
72 typedef char uri_t[65];
73 
74 typedef struct {
75  char ip[16];
76  uint16_t port;
80 
81 typedef struct {
82  char ip[16];
83  char gateway[16];
84  char mask[16];
86  uint16_t telnet_port;
87  uint16_t websocket_port;
88  uint16_t http_port;
89  uint16_t ftp_port;
92 #if MQTT_ENABLE
93  mqtt_settings_t mqtt;
94 #endif
95 #if defined(_WIZCHIP_) || defined(HAS_MAC_SETTING)
96  uint8_t mac[6];
97 #endif
99 
100 typedef enum {
106 
107 #ifdef WIN32
108 #undef interface
109 #endif
110 
111 typedef struct {
112  const char *interface;
114  bool link_up;
115  uint16_t mbps;
116  char mac[18];
117  char mqtt_client_id[18];
121 
122 typedef struct {
126  char country[4];
127  uint8_t channel;
130 
131 typedef struct {
136 
137 typedef struct {
138  char device_name[33];
139  char service_name[33];
141 
142 #define MODBUS_TCP_SETTINGS_INCREMENT 5
143 
144 typedef enum {
147  Setting_ModbusId = 2
149 
150 typedef struct {
151  char ip[16];
152  uint16_t port;
153  uint8_t id;
155 
156 // Quadrature encoder interface
157 
158 typedef enum {
172 
173 typedef enum {
179 
180 typedef union {
181  uint8_t events;
182  struct {
183  uint8_t position_changed :1,
185  click :1,
189  unused :2;
190  };
192 
193 typedef union {
194  uint8_t flags;
195  uint8_t value;
196  struct {
198  };
200 
201 typedef struct {
203  uint32_t cpr;
204  uint32_t cpd;
205  uint32_t dbl_click_window;
208 
209 typedef struct {
211  uint_fast8_t id;
212  uint_fast8_t axis;
213  int32_t position;
214  uint32_t velocity;
217 } encoder_t;
218 
219 // DISPLAYS:
220 
221 // Interfaces
222 #define DISPLAY_I2C (1<<0)
223 #define DISPLAY_SPI (1<<1)
224 #define DISPLAY_UART (1<<2)
225 
226 // Plugins
227 #define DISPLAY_I2C_INTERFACE ((1<<3)|DISPLAY_I2C)
228 #define DISPLAY_I2C_LEDS ((1<<4)|DISPLAY_I2C)
229 #define DISPLAY_I2C_OLED_1 ((1<<5)|DISPLAY_I2C)
230 
231 // Driver chips
232 
233 #define DISPLAY_DRIVER_SH1106 1
234 #define DISPLAY_DRIVER_SSD1306 2
235 #define DISPLAY_DRIVER_SSD1331 3
236 #define DISPLAY_DRIVER_ILI9340 4
237 #define DISPLAY_DRIVER_ILI9341 5
238 #define DISPLAY_DRIVER_ILI9486 6
239 
240 // I2C interface:
241 
242 typedef void (*keycode_callback_ptr)(const char c);
243 
244 typedef uint_fast16_t i2c_address_t;
245 
246 typedef struct {
248  union {
249  struct {
250  uint8_t cmd_bytes;
251  uint16_t cmd;
252  };
253  struct {
255  uint16_t word_addr;
256  };
257  };
258  uint_fast16_t count;
259  bool no_block;
260  uint8_t *data;
262 
263 typedef union {
264  uint8_t ok;
265  struct {
266  uint8_t started :1,
268  tx_dma :1,
270  };
271 } i2c_cap_t;
272 
273 extern i2c_cap_t i2c_start (void);
274 extern bool i2c_probe (i2c_address_t i2c_address);
275 extern bool i2c_send (i2c_address_t i2c_address, uint8_t *data, size_t size, bool block);
276 extern bool i2c_receive (i2c_address_t i2cAddr, uint8_t *buf, size_t size, bool block);
277 extern bool i2c_get_keycode (i2c_address_t i2c_address, keycode_callback_ptr callback);
278 extern bool i2c_transfer (i2c_transfer_t *i2c, bool read);
279 
280 // SPI interface:
281 
282 /*
283 typedef void (*spi_cs_ptr)(const char c);
284 
285 typedef struct {
286  spi_cs_ptr cs;
287  uint32_t f_clk;
288 } spi_cfg_t;
289 
290 typedef union {
291  uint8_t ok;
292  struct {
293  uint8_t started :1,
294  tx_non_blocking :1,
295  tx_dma :1,
296  unassigned :5;
297  };
298 } spi_cap_t;
299 
300 extern spi_cap_t spi_start (spi_cfg_t *cfg);
301 extern uint32_t spi_set_speed (uint32_t prescaler);
302 extern uint8_t spi_get_byte (void);
303 extern uint8_t spi_put_byte (uint8_t byte);
304 extern void spi_write (uint8_t *data, size_t size);
305 extern void spi_read (uint8_t *data, size_t size);
306 extern void spi_write (uint8_t *data, size_t size);
307 */
308 
309 // EEPROM/FRAM:
310 
312 #define i2c_nvs_transfer(i2c, rd) i2c_transfer(i2c, rd)
313 
315 #define NVS_TransferResult_OK true
316 
317 #endif
uint32_t size
Definition: nvs_buffer.c:46
bool i2c_receive(i2c_address_t i2cAddr, uint8_t *buf, size_t size, bool block)
bool nvs_transfer_result_t
Definition: plugins.h:314
char hostname_t[33]
Definition: plugins.h:71
i2c_transfer_t nvs_transfer_t
Definition: plugins.h:311
char password_t[33]
Definition: plugins.h:70
char uri_t[65]
Definition: plugins.h:72
bool i2c_get_keycode(i2c_address_t i2c_address, keycode_callback_ptr callback)
uint8_t bssid_t[6]
Definition: plugins.h:68
ip_mode_t
Definition: plugins.h:47
@ IpMode_Static
Definition: plugins.h:48
@ IpMode_DHCP
Definition: plugins.h:49
@ IpMode_AutoIP
Definition: plugins.h:50
encoder_setting_id_t
Definition: plugins.h:173
@ Setting_EncoderCPR
Count Per Revolution.
Definition: plugins.h:175
@ Setting_EncoderCPD
Count Per Detent.
Definition: plugins.h:176
@ Setting_EncoderMode
Definition: plugins.h:174
@ Setting_EncoderDblClickWindow
Definition: plugins.h:177
grbl_wifi_mode_t
Definition: plugins.h:100
@ WiFiMode_APSTA
Definition: plugins.h:104
@ WiFiMode_STA
Definition: plugins.h:102
@ WiFiMode_AP
Definition: plugins.h:103
@ WiFiMode_NULL
Definition: plugins.h:101
bool i2c_transfer(i2c_transfer_t *i2c, bool read)
char username_t[33]
Definition: plugins.h:69
i2c_cap_t i2c_start(void)
bool i2c_send(i2c_address_t i2c_address, uint8_t *data, size_t size, bool block)
encoder_mode_t
Definition: plugins.h:158
@ Encoder_MPG_A
Definition: plugins.h:167
@ Encoder_MPG_Z
Definition: plugins.h:166
@ Encoder_MPG
Definition: plugins.h:163
@ Encoder_MPG_Y
Definition: plugins.h:165
@ Encoder_MPG_C
Definition: plugins.h:169
@ Encoder_MPG_X
Definition: plugins.h:164
@ Encoder_FeedRate
Definition: plugins.h:160
@ Encoder_Universal
Definition: plugins.h:159
@ Encoder_RapidRate
Definition: plugins.h:161
@ Encoder_Spindle_Position
Definition: plugins.h:170
@ Encoder_MPG_B
Definition: plugins.h:168
@ Encoder_Spindle_RPM
Definition: plugins.h:162
bool i2c_probe(i2c_address_t i2c_address)
void(* keycode_callback_ptr)(const char c)
Definition: plugins.h:242
char ssid_t[65]
Definition: plugins.h:67
uint_fast16_t i2c_address_t
Definition: plugins.h:244
modbus_tcp_setting_id_t
Definition: plugins.h:144
@ Setting_ModbusId
Definition: plugins.h:147
@ Setting_ModbusPort
Definition: plugins.h:146
@ Setting_ModbusIpAddress
Definition: plugins.h:145
Definition: plugins.h:137
Definition: plugins.h:201
uint32_t dbl_click_window
ms.
Definition: plugins.h:205
uint32_t cpr
Count per revolution.
Definition: plugins.h:203
uint32_t cpd
Count per detent.
Definition: plugins.h:204
encoder_mode_t mode
Definition: plugins.h:202
encoder_flags_t flags
Definition: plugins.h:206
Definition: plugins.h:209
encoder_mode_t mode
Definition: plugins.h:210
uint_fast8_t id
Definition: plugins.h:211
int32_t position
Definition: plugins.h:213
encoder_event_t event
Definition: plugins.h:215
uint_fast8_t axis
Axis index for MPG encoders, 0xFF for others.
Definition: plugins.h:212
uint32_t velocity
Definition: plugins.h:214
encoder_settings_t * settings
Definition: plugins.h:216
Definition: plugins.h:246
uint8_t word_addr_bytes
Definition: plugins.h:254
uint8_t cmd_bytes
Definition: plugins.h:250
uint16_t cmd
Definition: plugins.h:251
i2c_address_t address
Definition: plugins.h:247
uint16_t word_addr
Definition: plugins.h:255
uint_fast16_t count
Definition: plugins.h:258
uint8_t * data
Definition: plugins.h:260
bool no_block
Definition: plugins.h:259
Definition: plugins.h:36
float step_speed
Definition: plugins.h:39
float fast_distance
Definition: plugins.h:40
float step_distance
Definition: plugins.h:42
float slow_speed
Definition: plugins.h:38
float slow_distance
Definition: plugins.h:41
float fast_speed
Definition: plugins.h:37
Definition: plugins.h:150
uint8_t id
Definition: plugins.h:153
uint16_t port
Definition: plugins.h:152
Definition: plugins.h:74
uint16_t port
Definition: plugins.h:76
username_t user
Definition: plugins.h:77
password_t password
Definition: plugins.h:78
Definition: plugins.h:111
network_settings_t status
Definition: plugins.h:119
const char * interface
Definition: plugins.h:112
bool link_up
Definition: plugins.h:114
uint16_t mbps
Definition: plugins.h:115
bool is_ethernet
Definition: plugins.h:113
grbl_wifi_mode_t wifi_mode
Definition: plugins.h:118
Definition: plugins.h:81
hostname_t hostname
Definition: plugins.h:85
uint16_t websocket_port
Definition: plugins.h:87
uint16_t telnet_port
Definition: plugins.h:86
uint16_t ftp_port
Definition: plugins.h:89
ip_mode_t ip_mode
Definition: plugins.h:90
network_services_t services
Definition: plugins.h:91
uint16_t http_port
Definition: plugins.h:88
Definition: plugins.h:122
ssid_t ssid
Definition: plugins.h:123
uint8_t channel
Definition: plugins.h:127
bssid_t bssid
Definition: plugins.h:124
password_t password
Definition: plugins.h:125
network_settings_t network
Definition: plugins.h:128
Definition: plugins.h:131
ssid_t ssid
Definition: plugins.h:132
password_t password
Definition: plugins.h:133
network_settings_t network
Definition: plugins.h:134
Definition: plugins.h:180
uint8_t direction_changed
Definition: plugins.h:184
uint8_t index_pulse
Definition: plugins.h:188
uint8_t click
Definition: plugins.h:185
uint8_t long_click
Definition: plugins.h:187
uint8_t position_changed
Definition: plugins.h:183
uint8_t events
Definition: plugins.h:181
uint8_t dbl_click
Definition: plugins.h:186
uint8_t unused
Definition: plugins.h:189
Definition: plugins.h:193
uint8_t value
Definition: plugins.h:195
uint8_t single_count_per_detent
Definition: plugins.h:197
uint8_t flags
Definition: plugins.h:194
Definition: plugins.h:263
uint8_t unassigned
Definition: plugins.h:269
uint8_t ok
Definition: plugins.h:264
uint8_t started
Definition: plugins.h:266
uint8_t tx_non_blocking
Definition: plugins.h:267
uint8_t tx_dma
Definition: plugins.h:268
Definition: plugins.h:53
uint8_t mdns
Definition: plugins.h:61
uint8_t ftp
Definition: plugins.h:59
uint8_t telnet
Definition: plugins.h:56
uint8_t websocket
Definition: plugins.h:57
uint8_t dns
Definition: plugins.h:60
uint8_t mask
Definition: plugins.h:54
uint8_t http
Definition: plugins.h:58
uint8_t webdav
Definition: plugins.h:63
uint8_t ssdp
Definition: plugins.h:62