forked from grblHAL/RP2040
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.h
287 lines (234 loc) · 6.81 KB
/
driver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
driver.h - driver code for RP2040 ARM processors
Part of grblHAL
Copyright (c) 2021-2022 Terje Io
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
//
// NOTE: do NOT change configuration here - edit my_machine.h instead!
//
#ifndef __DRIVER_H__
#define __DRIVER_H__
#include <stdbool.h>
#include <stdint.h>
#ifndef OVERRIDE_MY_MACHINE
#include "my_machine.h"
#endif
#include "grbl/driver_opts.h"
#define DIGITAL_IN(bit) (!!(sio_hw->gpio_in & bit))
#define DIGITAL_OUT(bit, on) { if(on) sio_hw->gpio_set = bit; else sio_hw->gpio_clr = bit; }
#define GPIO_IRQ_ALL (GPIO_IRQ_LEVEL_HIGH|GPIO_IRQ_LEVEL_LOW|GPIO_IRQ_EDGE_RISE|GPIO_IRQ_EDGE_FALL)
// Define GPIO mode options
#define GPIO_SHIFT0 0
#define GPIO_SHIFT1 1
#define GPIO_SHIFT2 2
#define GPIO_SHIFT3 3
#define GPIO_SHIFT4 4
#define GPIO_SHIFT5 5
#define GPIO_SHIFT6 6
#define GPIO_SHIFT7 7
#define GPIO_SHIFT8 8
#define GPIO_SHIFT9 9
#define GPIO_SHIFT10 10
#define GPIO_SHIFT11 11
#define GPIO_SHIFT12 12
#define GPIO_SHIFT13 13
#define GPIO_SHIFT14 14
#define GPIO_SHIFT15 15
#define GPIO_SHIFT16 16
#define GPIO_SHIFT17 17
#define GPIO_SHIFT18 18
#define GPIO_SHIFT19 19
#define GPIO_SHIFT20 20
#define GPIO_SHIFT21 21
#define GPIO_SHIFT22 22
#define GPIO_SHIFT23 23
#define GPIO_SHIFT24 24
#define GPIO_SHIFT25 25
#define GPIO_SHIFT26 26
#define GPIO_SHIFT27 27
#define GPIO_SHIFT28 28
#define GPIO_MAP 31
#define GPIO_DIRECT 33
#define GPIO_IOEXPAND 34
#define GPIO_INPUT 35
#define GPIO_OUTPUT 36
#define GPIO_PIO 37
#define GPIO_PIO_1 38
#define GPIO_SR8 39
#define GPIO_SR16 40
#define STEPPERS_ENABLE_PINMODE 0
// Define timer allocations.
/*
#define RPM_COUNTER_N 3
#define RPM_COUNTER timer(RPM_COUNTER_N)
#define RPM_COUNTER_IRQn timerINT(RPM_COUNTER_N)
#define RPM_COUNTER_IRQHandler timerHANDLER(RPM_COUNTER_N)
#define RPM_TIMER_N 2
#define RPM_TIMER timer(RPM_TIMER_N)
#define RPM_TIMER_IRQn timerINT(RPM_TIMER_N)
#define RPM_TIMER_IRQHandler timerHANDLER(RPM_TIMER_N)
#define PPI_TIMER_N 2
#define PPI_TIMER timer(PPI_TIMER_N)
#define PPI_TIMER_IRQn timerINT(PPI_TIMER_N)
#define PPI_TIMER_IRQHandler timerHANDLER(PPI_TIMER_N)
*/
#if WEBUI_ENABLE && LITTLEFS_ENABLE
#ifdef WEBUI_INFLASH
#undef WEBUI_INFLASH
#endif
#define WEBUI_INFLASH 1
#endif
#ifdef BOARD_CNC_BOOSTERPACK
#include "cnc_boosterpack_map.h"
#elif defined(BOARD_PICO_CNC)
#include "pico_cnc_map.h"
#elif defined(BOARD_PICOBOB)
#include "picobob_map.h"
#elif defined(BOARD_BTT_SKR_PICO_10)
#include "btt_skr_pico_10_map.h"
#elif defined BOARD_CITOH_CX6000
#include "citoh_cx6000_map.h"
#elif defined(BOARD_MY_MACHINE)
#include "my_machine_map.h"
#else // default board
#include "generic_map.h"
#endif
// Adjust STEP_PULSE_LATENCY to get accurate step pulse length when required, e.g if using high step rates.
// The default value is calibrated for 10 microseconds length.
// NOTE: step output mode, number of axes and compiler optimization settings may all affect this value.
#ifndef STEP_PULSE_LATENCY
#define STEP_PULSE_LATENCY 1.0f // microseconds
#endif
// End configuration
#if EEPROM_ENABLE == 0
#define FLASH_ENABLE 1
#else
#define FLASH_ENABLE 0
#endif
#ifdef IOEXPAND_ENABLE
#undef I2C_ENABLE
#define I2C_ENABLE 1
#endif
#if I2C_ENABLE && !defined(I2C_PORT)
#define I2C_PORT 1
#define I2C_SDA 26
#define I2C_SCL 27
#endif
#if TRINAMIC_ENABLE
#ifndef TRINAMIC_MIXED_DRIVERS
#define TRINAMIC_MIXED_DRIVERS 1
#endif
#include "motors/trinamic.h"
#endif
#if MODBUS_ENABLE
#define MODBUS_TEST 1
#else
#define MODBUS_TEST 0
#endif
#if KEYPAD_ENABLE == 2 && MPG_ENABLE == 0
#define KEYPAD_TEST 1
#else
#define KEYPAD_TEST 0
#endif
#if MPG_ENABLE
#define MPG_TEST 1
#else
#define MPG_TEST 0
#endif
#if MODBUS_TEST + KEYPAD_TEST + BLUETOOTH_ENABLE + TRINAMIC_UART_ENABLE + MPG_TEST > 1
#error "Only one option that uses the serial port can be enabled!"
#endif
#if MODBUS_TEST || KEYPAD_TEST || BLUETOOTH_ENABLE || TRINAMIC_UART_ENABLE || MPG_ENABLE
#define SERIAL2_MOD
#endif
#undef MODBUS_TEST
#undef KEYPAD_TEST
#undef MPG_TEST
// End configuration
#if MPG_MODE == 1 && !defined(MPG_MODE_PIN)
#error "MPG_MODE_PIN must be defined!"
#endif
#if KEYPAD_ENABLE == 1 && !defined(I2C_STROBE_PIN)
#error Keypad plugin not supported!
#endif
#if SDCARD_ENABLE && !defined(SD_CS_PIN)
#error SD card plugin not supported!
#endif
#ifndef STEP_PINMODE
#define STEP_PINMODE PINMODE_OUTPUT
#endif
#ifndef DIRECTION_PINMODE
#define DIRECTION_PINMODE PINMODE_OUTPUT
#endif
#ifndef STEPPERS_DISABLE_PINMODE
#define STEPPERS_DISABLE_PINMODE PINMODE_OUTPUT
#endif
typedef struct {
pin_function_t id;
pin_group_t group;
uint8_t pin;
uint32_t bit;
uint8_t port;
bool invert;
pin_irq_mode_t irq_mode;
volatile bool active;
volatile bool debounce;
pin_mode_t cap;
ioport_interrupt_callback_ptr interrupt_callback;
const char *description;
} input_signal_t;
typedef struct {
pin_function_t id;
pin_group_t group;
uint8_t pin;
uint32_t bit;
uint8_t port;
pin_mode_t mode;
const char *description;
} output_signal_t;
typedef struct {
uint8_t n_pins;
union {
input_signal_t *inputs;
output_signal_t *outputs;
} pins;
} pin_group_pins_t;
bool driver_init (void);
#if OUT_SHIFT_REGISTER
void board_init (pin_group_pins_t *aux_inputs, pin_group_pins_t *aux_outputs, output_sr_t *reg);
#else
void board_init (void);
#endif
void ioports_init (pin_group_pins_t *aux_inputs, pin_group_pins_t *aux_outputs);
void ioports_event (input_signal_t *input);
void pinEnableIRQ (const input_signal_t *input, pin_irq_mode_t irq_mode);
/**
\brief Enable IRQ Interrupts
\details Enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
// While waiting for CMSIS headers...:
static inline void __enable_irq(void)
{
__asm volatile ("cpsie i" : : : "memory");
}
/**
\brief Disable IRQ Interrupts
\details Disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
static inline void __disable_irq(void)
{
__asm volatile ("cpsid i" : : : "memory");
}
#endif // __DRIVER_H__