Skip to content

Commit

Permalink
initial check in
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Feb 22, 2021
0 parents commit 308d3cb
Show file tree
Hide file tree
Showing 20 changed files with 2,598 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Auto detect text files and perform LF normalization
* text=auto eol=lf


# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# Subversion folders

.svn

# grblHAL core and plugin folders

grbl
EEPROM
sdcard

# Build folder

build

#
# =========================
# Operating System Files
# =========================

.vscode/settings.json
.vscode/c_cpp_properties.json
1 change: 1 addition & 0 deletions .vscode/.cortex-debug.peripherals.state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions .vscode/.cortex-debug.registers.state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug",
"cwd": "${workspaceRoot}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
// This may need to be arm-none-eabi-gdb depending on your system
"gdbPath" : "gdb-multiarch",
"device": "RP2040",
"configFiles": [
"interface/raspberrypi-swd.cfg",
"target/rp2040.cfg"
],
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
"runToMain": true,
// Work around for stopping at main on restart
"postRestartCommands": [
"break main",
"continue"
]
}
]
}
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(grblHAL)

pico_sdk_init()


add_executable(grblHAL
main.c
driver.c
serial.c
i2c.c
PCA9654E.c
eeprom/eeprom_24AAxxx.c
eeprom/eeprom_24LC16B.c
grbl/grbllib.c
grbl/coolant_control.c
grbl/nvs_buffer.c
grbl/gcode.c
grbl/limits.c
grbl/motion_control.c
grbl/my_plugin.c
grbl/nuts_bolts.c
grbl/override.c
grbl/planner.c
grbl/protocol.c
grbl/report.c
grbl/settings.c
grbl/sleep.c
grbl/spindle_control.c
grbl/state_machine.c
grbl/stepper.c
grbl/system.c
grbl/tool_change.c
grbl/my_plugin.c
)

pico_generate_pio_header(grblHAL ${CMAKE_CURRENT_LIST_DIR}/driverPIO.pio)

target_sources(grblHAL PRIVATE driver.c)

# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(grblHAL PRIVATE pico_stdlib hardware_uart hardware_pio hardware_i2c hardware_gpio hardware_pwm hardware_clocks)

# create map/bin/hex file etc.
pico_add_extra_outputs(grblHAL)
78 changes: 78 additions & 0 deletions PCA9654E.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
PCA9654E.c - driver code for RP2040 ARM processor
I2C I/O expander, PCA9654
Part of grblHAL
Copyright (c) 2018-2021 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/>.
*/

#include "driver.h"

#if IOEXPAND_ENABLE == 1

#include "ioexpand.h"
#include "i2c.h"

#define IOEX_ADDRESS (0x40 >> 1)
#define READ_INPUT 0
#define RW_OUTPUT 1
#define RW_INVERSION 2
#define RW_CONFIG 3

void ioexpand_init (void)
{
uint8_t cmd[2];

// 0 = output, 1 = input
// TODO: move to driver.h?
const ioexpand_t cfg = {0};

cmd[0] = RW_CONFIG;
cmd[1] = cfg.mask;
I2C_Send(IOEX_ADDRESS, cmd, 2, true);

cmd[0] = RW_INVERSION;
cmd[1] = 0;
I2C_Send(IOEX_ADDRESS, cmd, 2, true);
}

void ioexpand_out (ioexpand_t pins)
{
uint8_t cmd[2];

cmd[0] = RW_OUTPUT;
cmd[1] = pins.mask;

I2C_Send(IOEX_ADDRESS, cmd, 2, true);
}

ioexpand_t ioexpand_in (void)
{
ioexpand_t pins = {0};
uint8_t cmd[2];

cmd[0] = READ_INPUT;
cmd[1] = 0;
I2C_ReadRegister(IOEX_ADDRESS, cmd, 1, true);

return (ioexpand_t)cmd[0];
}

#endif
109 changes: 109 additions & 0 deletions cnc_boosterpack_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
cnc_boosterpack_map.h - driver code for RP2040 ARM processors
Part of grblHAL
Copyright (c) 2021 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/>.
*/

#if TRINAMIC_ENABLE
#error Trinamic plugin not supported!
#endif

#define BOARD_NAME "CNC BoosterPack"

#define IOEXPAND_ENABLE 1

#undef EEPROM_ENABLE
#define EEPROM_ENABLE 1

// Define step pulse output pins.
#define STEP_PINS_BASE 2 // N_AXIS number of consecutive pins are used by PIO

// Define step direction output pins.
#define X_DIRECTION_PIN 5
#define Y_DIRECTION_PIN 6
#define Z_DIRECTION_PIN 7
#define X_DIRECTION_BIT (1<<X_DIRECTION_PIN)
#define Y_DIRECTION_BIT (1<<Y_DIRECTION_PIN)
#define Z_DIRECTION_BIT (1<<Z_DIRECTION_PIN)
#define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT)
#define DIRECTION_OUTMODE GPIO_SHIFT5

// Define stepper driver enable/disable output pin.
#define STEPPERS_DISABLEX_PIN 6
#define STEPPERS_DISABLEZ_PIN 0
#define STEPPERS_DISABLE_OUTMODE GPIO_IOEXPAND

// Define homing/hard limit switch input pins.
#define LIMIT_PORT GPIO_IN
#define X_LIMIT_PIN 8
#define Y_LIMIT_PIN 9
#define Z_LIMIT_PIN 10
#define X_LIMIT_BIT (1<<X_LIMIT_PIN)
#define Y_LIMIT_BIT (1<<Y_LIMIT_PIN)
#define Z_LIMIT_BIT (1<<Z_LIMIT_PIN)
#define LIMIT_MASK (X_LIMIT_BIT|Y_LIMIT_BIT|Z_LIMIT_BIT)
#define LIMIT_INMODE GPIO_OE

// Define spindle enable and spindle direction output pins.
#define SPINDLE_ENABLE_PIN 0
#define SPINDLE_DIRECTION_PIN 5
#define SPINDLE_OUTMODE GPIO_IOEXPAND

// Define spindle PWM output pin.
#define SPINDLE_PWM_PIN 11
#define SPINDLE_PWM_BIT (1<<SPINDLE_PWM_PIN)

// Define flood and mist coolant enable output pins.
#define COOLANT_FLOOD_PIN 2
#define COOLANT_MIST_PIN 3
#define COOLANT_OUTMODE GPIO_IOEXPAND

// Define user-control controls (cycle start, reset, feed hold) input pins.
#define CONTROL_RESET_PIN 12
#define CONTROL_RESET_BIT (1<<CONTROL_RESET_PIN)
#define CONTROL_FEED_HOLD_PIN 13
#define CONTROL_FEED_HOLD_BIT (1<<CONTROL_FEED_HOLD_PIN)
#define CONTROL_CYCLE_START_PIN 14
#define CONTROL_CYCLE_START_BIT (1<<CONTROL_CYCLE_START_PIN)
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
#define CONTROL_SAFETY_DOOR_PIN 15
#define CONTROL_SAFETY_DOOR_BIT (1<<CONTROL_SAFETY_DOOR_PIN)
#define CONTROL_MASK (CONTROL_RESET_BIT|CONTROL_FEED_HOLD_BIT|CONTROL_CYCLE_START_BIT|CONTROL_SAFETY_DOOR_BIT)
#else
#define CONTROL_MASK (CONTROL_RESET_BIT|CONTROL_FEED_HOLD_BIT|CONTROL_CYCLE_START_BIT)
#endif
#define CONTROL_INMODE GPIO_OE

// Define probe switch input pin.
#define PROBE_PORT GPIO_IN
#define PROBE_PIN 16
#define PROBE_BIT (1<<PROBE_PIN)

#if KEYPAD_ENABLE
#define KEYPAD_STROBE_PIN 17
#define KEYPAD_STROBE_BIT (1<<KEYPAD_STROBE_PIN)
#endif

#if SDCARD_ENABLE
#define SD_CS_PIN 17
#define SD_CS_BIT (1<<SD_CS_PIN)
#define SPI_PORT 1 // SPI0, SCK_PIN = 18, MISO_PIN = 16, MOSI_PIN = 19
#endif

//I2C: 26,27
//Free: 21,21,22,28
Loading

0 comments on commit 308d3cb

Please sign in to comment.