Skip to content

Commit

Permalink
Revised pin mappings for BTT SKR Pico board. Added misc. plugins to c…
Browse files Browse the repository at this point in the history
…ompilation.
  • Loading branch information
terjeio committed Sep 7, 2024
1 parent 6c52c61 commit 0ffb27e
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 70 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(spindle/CMakeLists.txt)
include(keypad/CMakeLists.txt)
include(embroidery/CMakeLists.txt)
include(laser/CMakeLists.txt)
include(plugins/CMakeLists.txt)
%include_libraries%

project(grblHAL)
Expand Down Expand Up @@ -186,9 +187,11 @@ target_link_libraries(grblHAL PRIVATE
spindle
keypad
laser
misc_plugins
embroidery
tinyusb_device_unmarked
pico_stdlib
pico_unique_id
hardware_dma
hardware_uart
hardware_pio
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include(fans/CMakeLists.txt)
include(bluetooth/CMakeLists.txt)
include(embroidery/CMakeLists.txt)
include(laser/CMakeLists.txt)
include(plugins/CMakeLists.txt)
if(ADD_HPGL)
include(hpgl/CMakeLists.txt)
endif()
Expand Down Expand Up @@ -195,6 +196,7 @@ target_link_libraries(grblHAL PRIVATE
laser
bluetooth
eeprom
misc_plugins
embroidery
tinyusb_device_unmarked
pico_stdlib
Expand Down
67 changes: 29 additions & 38 deletions boards/btt_skr_pico_10_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#error "Wireless networking is not supported!"
#endif

#define AUX_CONTROLS_OUT

#define BOARD_NAME "BTT SKR Pico 1.0"
#define BOARD_URL "https://github.com/bigtreetech/SKR-Pico"

Expand Down Expand Up @@ -67,71 +69,60 @@
#define M3_DIRECTION_PIN 13
#define M3_ENABLE_PIN 15
#define M3_LIMIT_PIN 16
#else
#define RESET_PIN 16 // E0 limit
#endif

// Define homing/hard limit switch input pins.
#define X_LIMIT_PIN 4
#define Y_LIMIT_PIN 3
#define Z_LIMIT_PIN 25

#define AUXOUTPUT0_PORT GPIO_OUTPUT
#define AUXOUTPUT0_PIN 20
#define AUXOUTPUT1_PORT GPIO_OUTPUT
#define AUXOUTPUT1_PIN 18
#define AUXOUTPUT2_PORT GPIO_OUTPUT
#define AUXOUTPUT2_PIN 17

// Define driver spindle pins

#if DRIVER_SPINDLE_PWM_ENABLE
#define SPINDLE_PWM_PORT GPIO_OUTPUT
#define SPINDLE_PWM_PIN 20
#else
#define AUXOUTPUT0_PORT GPIO_OUTPUT
#define AUXOUTPUT0_PIN 20
#define SPINDLE_PWM_PORT AUXOUTPUT0_PORT
#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN
#endif

#if DRIVER_SPINDLE_DIR_ENABLE
#define SPINDLE_PORT GPIO_OUTPUT
#define SPINDLE_DIRECTION_PIN 18
#else
#define AUXOUTPUT1_PORT GPIO_OUTPUT
#define AUXOUTPUT1_PIN 18
#define SPINDLE_PORT AUXOUTPUT1_PORT
#define SPINDLE_DIRECTION_PORT AUXOUTPUT1_PORT
#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN
#endif

#if DRIVER_SPINDLE_ENABLE
#ifndef SPINDLE_PORT
#define SPINDLE_PORT GPIO_OUTPUT
#define SPINDLE_PORT AUXOUTPUT2_PORT
#endif
#define SPINDLE_ENABLE_PIN 17
#else
#define AUXOUTPUT2_PORT GPIO_OUTPUT
#define AUXOUTPUT2_PIN 17
#define SPINDLE_ENABLE_PORT AUXOUTPUT2_PORT
#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN
#endif

// Define flood and mist coolant enable output pins.
/*
#define COOLANT_PORT GPIO_OUTPUT
#define COOLANT_FLOOD_PIN 2
#define COOLANT_MIST_PIN 3
*/

#if N_ABC_MOTORS == 0

#define AUXINPUT0_PIN 15
#define COOLANT_PORT GPIO_OUTPUT
#define COOLANT_FLOOD_PIN 21 // HB PWM
#define COOLANT_MIST_PIN 23 // HE PWM

// Define user-control controls (cycle start, reset, feed hold) input pins.
#define RESET_PIN 16
#define FEED_HOLD_PIN 13
#define CYCLE_START_PIN 14
#define AUXINPUT0_PIN 22 // Probe
#define AUXOUTPUT0_PWM_PIN 29 // Servo

#if SAFETY_DOOR_ENABLE
#define SAFETY_DOOR_PIN AUXINPUT0_PIN
#elif MOTOR_FAULT_ENABLE
#define MOTOR_FAULT_PIN AUXINPUT0_PIN
#if PROBE_ENABLE
#define PROBE_PIN AUXINPUT0_PIN
#endif

#endif // N_ABC_MOTORS == 0

#define AUXINPUT1_PIN 22 // Probe

#if PROBE_ENABLE
#define PROBE_PIN AUXINPUT1_PIN
#if RGB_LED_ENABLE
#define NEOPIXELS_PIN 24
#endif

#if MODBUS_ENABLE
#define MODBUS_SERIAL_PORT 0
#define MODBUS_RTU_STREAM 0
#endif
17 changes: 10 additions & 7 deletions boards/pico_cnc_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,19 @@ typedef union {
#else
#define SPI_CS_PIN AUX_IO4_PIN
#endif
#define SPI_IRQ_PIN 26
#define SPI_RST_PORT GPIO_SR16
#define SPI_IRQ_PIN 26
#define SPI_RST_PORT GPIO_SR16
#else
#define AUXINPUT5_PIN 26
#define AUXOUTPUT7_PORT GPIO_OUTPUT
#define AUXOUTPUT7_PIN AUX_IO4_PIN
#define AUXINPUT5_PIN 26
#if RGB_LED_ENABLE
#define NEOPIXELS_PIN AUX_IO4_PIN
#else
#define AUXOUTPUT7_PORT GPIO_OUTPUT
#define AUXOUTPUT7_PIN AUX_IO4_PIN
#endif
#endif

#if !(WIFI_ENABLE || BLUETOOTH_ENABLE == 1)
//#define LED_PIN 25
#if !(WIFI_ENABLE || BLUETOOTH_ENABLE == 1 || defined(NEOPIXELS_PIN))
#define LED_G_PIN 25
#endif

Expand Down
90 changes: 65 additions & 25 deletions driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static uint c_step_sm;
#ifdef NEOPIXELS_PIN

#ifndef NEOPIXELS_NUM
#define NEOPIXELS_NUM 1
#define NEOPIXELS_NUM 0
#endif

static PIO neop_pio;
Expand Down Expand Up @@ -450,7 +450,7 @@ static output_signal_t outputpin[] = {
{ .id = Output_StepperEnable, .port = ENABLE_PORT, .pin = STEPPERS_ENABLE_PIN, .group = PinGroup_StepperEnable, .mode = { STEPPERS_ENABLE_PINMODE } },
#endif
#endif // !(TRINAMIC_ENABLE && TRINAMIC_I2C)
#ifdef SPINDLE_PWM_PIN
#if defined(SPINDLE_PWM_PORT) && !defined(AUX_CONTROLS_OUT)
{ .id = Output_SpindlePWM, .port = SPINDLE_PWM_PORT, .pin = SPINDLE_PWM_PIN, .group = PinGroup_SpindlePWM },
#endif
#ifdef RTS_PIN
Expand All @@ -465,13 +465,31 @@ static output_signal_t outputpin[] = {
#ifdef SPI_RST_PIN
{ .id = Output_SPIRST, .port = SPI_RST_PORT, .pin = SPI_RST_PIN, .group = PinGroup_SPI },
#endif
#ifndef SD_SHIFT_REGISTER
#ifdef SD_SHIFT_REGISTER // SD_SHIFT_REGISTER pin definitions - for $pins command only
{ .id = Output_SpindleOn, .port = GPIO_SR16, .pin = 4, .group = PinGroup_SpindleControl },
{ .id = Output_SpindleDir, .port = GPIO_SR16, .pin = 5, .group = PinGroup_SpindleControl },
{ .id = Output_CoolantFlood, .port = GPIO_SR16, .pin = 6, .group = PinGroup_Coolant },
{ .id = Output_CoolantMist, .port = GPIO_SR16, .pin = 7, .group = PinGroup_Coolant },
{ .id = Output_Aux0, .port = GPIO_SR16, .pin = 8, .group = PinGroup_AuxOutput },
{ .id = Output_Aux1, .port = GPIO_SR16, .pin = 9, .group = PinGroup_AuxOutput },
{ .id = Output_Aux2, .port = GPIO_SR16, .pin = 10, .group = PinGroup_AuxOutput },
{ .id = Output_Aux3, .port = GPIO_SR16, .pin = 11, .group = PinGroup_AuxOutput },
{ .id = Output_Aux4, .port = GPIO_SR16, .pin = 12, .group = PinGroup_AuxOutput },
{ .id = Output_Aux5, .port = GPIO_SR16, .pin = 13, .group = PinGroup_AuxOutput },
{ .id = Output_Aux6, .port = GPIO_SR16, .pin = 14, .group = PinGroup_AuxOutput },
#ifdef AUXOUTPUT7_PORT
{ .id = Output_Aux7, .port = AUXOUTPUT7_PORT, .pin = AUXOUTPUT7_PIN, .group = PinGroup_AuxOutput},
#endif
{ .id = Output_SPIRST, .port = GPIO_SR16, .pin = 15, .group = PinGroup_SPI },
#else // !SD_SHIFT_REGISTER
#ifndef AUX_CONTROLS_OUT
#ifdef SPINDLE_ENABLE_PIN
{ .id = Output_SpindleOn, .port = SPINDLE_PORT, .pin = SPINDLE_ENABLE_PIN, .group = PinGroup_SpindleControl},
#endif
#ifdef SPINDLE_DIRECTION_PIN
{ .id = Output_SpindleDir, .port = SPINDLE_PORT, .pin = SPINDLE_DIRECTION_PIN, .group = PinGroup_SpindleControl},
#endif
#endif // AUX_CONTROLS_OUT
#ifdef COOLANT_FLOOD_PIN
{ .id = Output_CoolantFlood, .port = COOLANT_PORT, .pin = COOLANT_FLOOD_PIN, .group = PinGroup_Coolant},
#endif
Expand Down Expand Up @@ -517,23 +535,7 @@ static output_signal_t outputpin[] = {
#ifdef AUXOUTPUT7_PORT
{ .id = Output_Aux7, .port = AUXOUTPUT7_PORT, .pin = AUXOUTPUT7_PIN, .group = PinGroup_AuxOutput},
#endif
#else // SD_SHIFT_REGISTER pin definitions - for $pins command only
{ .id = Output_SpindleOn, .port = GPIO_SR16, .pin = 4, .group = PinGroup_SpindleControl },
{ .id = Output_SpindleDir, .port = GPIO_SR16, .pin = 5, .group = PinGroup_SpindleControl },
{ .id = Output_CoolantFlood, .port = GPIO_SR16, .pin = 6, .group = PinGroup_Coolant },
{ .id = Output_CoolantMist, .port = GPIO_SR16, .pin = 7, .group = PinGroup_Coolant },
{ .id = Output_Aux0, .port = GPIO_SR16, .pin = 8, .group = PinGroup_AuxOutput },
{ .id = Output_Aux1, .port = GPIO_SR16, .pin = 9, .group = PinGroup_AuxOutput },
{ .id = Output_Aux2, .port = GPIO_SR16, .pin = 10, .group = PinGroup_AuxOutput },
{ .id = Output_Aux3, .port = GPIO_SR16, .pin = 11, .group = PinGroup_AuxOutput },
{ .id = Output_Aux4, .port = GPIO_SR16, .pin = 12, .group = PinGroup_AuxOutput },
{ .id = Output_Aux5, .port = GPIO_SR16, .pin = 13, .group = PinGroup_AuxOutput },
{ .id = Output_Aux6, .port = GPIO_SR16, .pin = 14, .group = PinGroup_AuxOutput },
#ifdef AUXOUTPUT7_PORT
{ .id = Output_Aux7, .port = AUXOUTPUT7_PORT, .pin = AUXOUTPUT7_PIN, .group = PinGroup_AuxOutput},
#endif
{ .id = Output_SPIRST, .port = GPIO_SR16, .pin = 15, .group = PinGroup_SPI },
#endif // SD_SHIFT_REGISTER
#ifdef AUXOUTPUT0_PWM_PIN
{ .id = Output_Analog_Aux0, .port = GPIO_OUTPUT, .pin = AUXOUTPUT0_PWM_PIN, .group = PinGroup_AuxOutputAnalog, .mode = { PINMODE_PWM } },
#endif
Expand Down Expand Up @@ -1392,6 +1394,25 @@ static bool aux_claim_explicit (aux_ctrl_t *aux_ctrl)

#endif // AUX_CONTROLS_ENABLED

#ifdef AUX_CONTROLS_OUT

bool aux_out_claim_explicit (aux_ctrl_out_t *aux_ctrl)
{
if(ioport_claim(Port_Digital, Port_Output, &aux_ctrl->aux_port, NULL)) {
if(aux_ctrl->function == Output_SpindlePWM || aux_ctrl->function == Output_Spindle1PWM) {
gpio_init(aux_ctrl->pin);
gpio_set_dir_out_masked(1 << aux_ctrl->pin);
gpio_set_function(aux_ctrl->pin, GPIO_FUNC_PWM);
}
ioport_assign_out_function(aux_ctrl, &((output_signal_t *)aux_ctrl->output)->id);
} else
aux_ctrl->aux_port = 0xFF;

return aux_ctrl->aux_port != 0xFF;
}

#endif // AUX_CONTROLS_OUT

//************************* SPINDLE *************************//

#if DRIVER_SPINDLE_ENABLE
Expand Down Expand Up @@ -2141,7 +2162,7 @@ void setPeriphPinDescription (const pin_function_t function, const pin_group_t g

#ifdef NEOPIXELS_PIN

static void neopixels_write (void)
static void _write (void)
{
// 50 us delay if busy? DMA?
uint32_t *led = (uint32_t *)neopixel.leds;
Expand All @@ -2154,6 +2175,12 @@ static void neopixels_write (void)
pio_sm_put_blocking(neop_pio, neop_sm, *led++);
}

static void neopixels_write (void)
{
if(neopixel.num_leds > 1)
_write();
}

static void neopixel_out_masked (uint16_t device, rgb_color_t color, rgb_color_mask_t mask)
{
if(neopixel.num_leds && device < neopixel.num_leds) {
Expand All @@ -2176,7 +2203,7 @@ static void neopixel_out_masked (uint16_t device, rgb_color_t color, rgb_color_m
*led = color.G;

if(neopixel.num_leds == 1)
neopixels_write();
_write();
}
}

Expand Down Expand Up @@ -2218,7 +2245,8 @@ static uint8_t neopixels_set_intensity (uint8_t intensity)
neopixel_out(device, color);
} while(device);

// neopixels_write();
if(neopixel.num_leds > 1)
_write();
}
}

Expand Down Expand Up @@ -2264,6 +2292,9 @@ static bool driver_setup (settings_t *settings)
if(outputpin[i].port == GPIO_OUTPUT && outputpin[i].group != PinGroup_AuxOutputAnalog) {
outputpin[i].bit = 1 << outputpin[i].pin;

if(gpio_get_function(outputpin[i].pin) == GPIO_FUNC_PWM)
continue;

gpio_init(outputpin[i].pin);
if(outputpin[i].id == PinGroup_StepperEnable || outputpin[i].id == Output_SdCardCS)
DIGITAL_OUT(outputpin[i].bit, 1);
Expand Down Expand Up @@ -2383,7 +2414,7 @@ bool driver_init (void)
systick_hw->csr = M0PLUS_SYST_CSR_TICKINT_BITS | M0PLUS_SYST_CSR_ENABLE_BITS;

hal.info = "RP2040";
hal.driver_version = "240827";
hal.driver_version = "240907";
hal.driver_options = "SDK_" PICO_SDK_VERSION_STRING;
hal.driver_url = GRBL_URL "/RP2040";
#ifdef BOARD_NAME
Expand Down Expand Up @@ -2582,7 +2613,11 @@ bool driver_init (void)
if(output->group == PinGroup_AuxOutput) {
if(aux_outputs.pins.outputs == NULL)
aux_outputs.pins.outputs = output;
output->id = Output_Aux0 + aux_outputs.n_pins++;
output->id = Output_Aux0 + aux_outputs.n_pins;
#ifdef AUX_CONTROLS_OUT
aux_out_remap_explicit((void *)output->port, output->pin, aux_outputs.n_pins, output);
#endif
aux_outputs.n_pins++;
} else if(output->group == PinGroup_AuxOutputAnalog) {
if(aux_outputs_analog.pins.outputs == NULL)
aux_outputs_analog.pins.outputs = output;
Expand All @@ -2596,6 +2631,10 @@ bool driver_init (void)
ioports_init(&aux_inputs, &aux_outputs);
#endif

#ifdef AUX_CONTROLS_OUT
aux_ctrl_claim_out_ports(aux_out_claim_explicit, NULL);
#endif

#ifdef HAS_BOARD_INIT
#if OUT_SHIFT_REGISTER
board_init(&aux_inputs, &aux_outputs, &out_sr);
Expand Down Expand Up @@ -2727,9 +2766,10 @@ bool driver_init (void)
neop_sm = (uint)nsm;
hal.rgb0.out = neopixel_out;
hal.rgb0.out_masked = neopixel_out_masked;
hal.rgb0.write = neopixels_write;
hal.rgb0.set_intensity = neopixels_set_intensity;
hal.rgb0.write = neopixels_write;
hal.rgb0.num_devices = NEOPIXELS_NUM;
hal.rgb0.flags = (rgb_properties_t){ .is_blocking = On, .is_strip = On };
hal.rgb0.cap = (rgb_color_t){ .R = 255, .G = 255, .B = 255 };

pio_offset = pio_add_program(neop_pio, &ws2812_program);
Expand Down
2 changes: 2 additions & 0 deletions ioports_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static bool init_pwm (xbar_t *output, pwm_config_t *config, bool persistent)
pwm_config_set_clkdiv_int(&pwm_config, prescaler);
pwm_config_set_wrap(&pwm_config, pwm_data->period);

gpio_init(output->pin);
gpio_set_dir_out_masked(1 << output->pin);
gpio_set_function(output->pin, GPIO_FUNC_PWM);
pwm_set_gpio_level(output->pin, pwm_data->off_value);

Expand Down
7 changes: 7 additions & 0 deletions my_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
//#define EEPROM_ENABLE 16 // I2C EEPROM/FRAM support. Set to 16 for 2K, 32 for 4K, 64 for 8K, 128 for 16K and 256 for 16K capacity.
//#define EEPROM_IS_FRAM 1 // Uncomment when EEPROM is enabled and chip is FRAM, this to remove write delay.
//#define STEP_INJECT_ENABLE 1
//#define MCP3221_ENABLE 0x4D // Enable MCP3221 I2C ADC input with address 0x4D (0b01001101).
//#define RGB_LED_ENABLE 2 // Set to 1 to enable strip length settings $536 and $537, set to 2 to also enable M150 LED strip control.
//#define PWM_SERVO_ENABLE 1 // Enable PWM servo support, requires at least one PWM capable auxillary output.
//#define BLTOUCH_ENABLE 1 // Enable BLTouch support. Requires and claims one PWM servo output.
//#define EVENTOUT_ENABLE 1 // Enable binding events (triggers) to control auxillary outputs.


// Optional control signals:
// These will be assigned to aux input pins. Use the $pins command to check which pins are assigned.
// NOTE: If not enough pins are available assignment will silently fail.
Expand Down

0 comments on commit 0ffb27e

Please sign in to comment.