Illumination support, change core, breaks hw serial
HW serial temporarily broken due to the change in pico core. This core has a lot more features e.g. easily changing PWM frequency and supports both pico cores (currently unused)
This commit is contained in:
parent
fde7a90480
commit
351e5a6b7a
6 changed files with 102 additions and 20 deletions
|
|
@ -31,10 +31,11 @@ board = leonardo
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
build_flags = -D MCU_LEONARDO
|
build_flags = -D MCU_LEONARDO
|
||||||
|
|
||||||
[env:pico]
|
;[env:pico]
|
||||||
platform = raspberrypi
|
;platform = raspberrypi
|
||||||
board = pico
|
;board = pico
|
||||||
build_flags = -D MCU_PICO
|
;build_flags = -D MCU_PICO
|
||||||
|
;upload_port = /media/filip/RPI-RP2
|
||||||
|
|
||||||
[env:bluepill]
|
[env:bluepill]
|
||||||
platform = ststm32
|
platform = ststm32
|
||||||
|
|
@ -54,4 +55,13 @@ build_flags =
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp-wrover-kit
|
board = esp-wrover-kit
|
||||||
build_flags = -D MCU_ESP32
|
build_flags = -D MCU_ESP32
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
build_type = debug
|
||||||
|
|
||||||
|
[env:pico]
|
||||||
|
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||||
|
board = pico
|
||||||
|
framework = arduino
|
||||||
|
board_build.core = earlephilhower
|
||||||
|
upload_port = /media/filip/RPI-RP2
|
||||||
|
build_flags = -D MCU_PICO
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#elif defined(MCU_BLUEPILL)
|
#elif defined(MCU_BLUEPILL)
|
||||||
#define BOARD_CUSTOM_BLUEPILL
|
#define BOARD_CUSTOM_BLUEPILL
|
||||||
#elif defined(MCU_PICO)
|
#elif defined(MCU_PICO)
|
||||||
#define BOARD_CUSTOM_PICO
|
#define BOARD_SANGABOARDv5
|
||||||
#elif defined(MCU_ESP32)
|
#elif defined(MCU_ESP32)
|
||||||
#define BOARD_CUSTOM_ESP32
|
#define BOARD_CUSTOM_ESP32
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
// #define ENDSTOPS
|
// #define ENDSTOPS
|
||||||
// #define LIGHT_SENSOR
|
// #define LIGHT_SENSOR
|
||||||
// #define STEPSTICK
|
// #define STEPSTICK
|
||||||
// #define ILLUMINATION
|
#define ILLUMINATION
|
||||||
|
|
||||||
//module configs
|
//module configs
|
||||||
#ifdef STAGE
|
#ifdef STAGE
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@
|
||||||
}
|
}
|
||||||
#define CHECK_END_COMMAND(C) check_end_command(C)
|
#define CHECK_END_COMMAND(C) check_end_command(C)
|
||||||
|
|
||||||
|
//TODO: temporarily disabled for philhower compatibilty
|
||||||
|
//extern arduino::UART PiSerial;
|
||||||
|
|
||||||
#ifdef BOARD_SANGABOARDv5
|
#ifdef BOARD_SANGABOARDv5
|
||||||
extern arduino::UART PiSerial;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct Command
|
struct Command
|
||||||
|
|
|
||||||
|
|
@ -7,35 +7,98 @@
|
||||||
#include "dummyEEPROM.h"
|
#include "dummyEEPROM.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WIRING_PWM_LED_NUM 1
|
#define PWM_NUM 1
|
||||||
#define WIRING_PWM_LEDS {25}
|
#define WIRING_PWM_LEDS {25}
|
||||||
//TODO: implement some fancier features of TMC controllers
|
//TODO: implement some fancier features of TMC controllers
|
||||||
const uint8_t pwm_led_pins[] = WIRING_PWM_LEDS;
|
const uint8_t pwm_led_pins[] = WIRING_PWM_LEDS;
|
||||||
void illumination_pwm(String command)
|
void illumination_pwm_freq(String command)
|
||||||
{
|
{
|
||||||
//TODO: make this properly, this is just a test for hacked on/off
|
//TODO: make this properly, this is just a test for hacked on/off
|
||||||
char * args[2];
|
char * args[1];
|
||||||
parse_arguments(args, command, 2);
|
parse_arguments(args, command, 2);
|
||||||
if (atof(args[1]) < 0.001)
|
#ifdef MCU_PICO
|
||||||
{
|
analogWriteFreq(atol(args[0]));//32khz seems sensible
|
||||||
digitalWrite(pwm_led_pins[0], LOW);//start with motor disabled
|
#else
|
||||||
}
|
SERIAL_PORT.println("Feature not supported");
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
digitalWrite(pwm_led_pins[0], HIGH);
|
SERIAL_PORT.println("Frequency set");
|
||||||
}
|
|
||||||
SERIAL_PORT.println("Illumination set");
|
|
||||||
free(args[0]);
|
free(args[0]);
|
||||||
free(args[1]);
|
free(args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void illumination_pwm(String command)
|
||||||
|
{
|
||||||
|
#ifdef MCU_PICO
|
||||||
|
//PWM frequency is shared between both PWM outputs
|
||||||
|
char * args[2];
|
||||||
|
parse_arguments(args, command, 2);
|
||||||
|
uint8_t index = atoi(args[0]);
|
||||||
|
if (index >= PWM_NUM)
|
||||||
|
{
|
||||||
|
Serial.println("Invalid index");
|
||||||
|
}
|
||||||
|
float val = atof(args[1]);
|
||||||
|
|
||||||
|
if (val < 0.00001)
|
||||||
|
{
|
||||||
|
digitalWrite(pwm_led_pins[index], LOW);//start with motor disabled
|
||||||
|
}
|
||||||
|
#ifdef MCU_PICO
|
||||||
|
uint32_t pwm_val = val * 65535;
|
||||||
|
#else
|
||||||
|
uint8_t pwm_val = val*255;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
analogWrite(pwm_led_pins[index], pwm_val);
|
||||||
|
SERIAL_PORT.println("Illumination set");
|
||||||
|
free(args[0]);
|
||||||
|
free(args[1]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CC_EN_PIN 24 //TODO: Move to boards
|
||||||
void illumination_setup()
|
void illumination_setup()
|
||||||
{
|
{
|
||||||
|
#ifdef MCU_PICO
|
||||||
|
analogWriteRange(65535);
|
||||||
|
analogWriteFreq(32000);//32khz seems sensible
|
||||||
|
#endif
|
||||||
pinMode(pwm_led_pins[0], OUTPUT);
|
pinMode(pwm_led_pins[0], OUTPUT);
|
||||||
|
pinMode(CC_EN_PIN, OUTPUT);
|
||||||
register_module(illumination_commands, NULL);
|
register_module(illumination_commands, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cc_on(String command)
|
||||||
|
{
|
||||||
|
digitalWrite(CC_EN_PIN, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cc_off(String command)
|
||||||
|
{
|
||||||
|
digitalWrite(CC_EN_PIN, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cc_up(String command)
|
||||||
|
{
|
||||||
|
digitalWrite(CC_EN_PIN, LOW);
|
||||||
|
delayMicroseconds(30); //1-75us
|
||||||
|
digitalWrite(CC_EN_PIN, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cc_down(String command)
|
||||||
|
{
|
||||||
|
digitalWrite(CC_EN_PIN, LOW);
|
||||||
|
delayMicroseconds(240); //180-300us
|
||||||
|
digitalWrite(CC_EN_PIN, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
extern const Command illumination_commands[] = {
|
extern const Command illumination_commands[] = {
|
||||||
{"led_pwm", illumination_pwm},
|
{"led_pwm", illumination_pwm},
|
||||||
|
{"led_pwm_freq", illumination_pwm_freq},
|
||||||
|
{"led_cc_up", cc_up},
|
||||||
|
{"led_cc_down", cc_down},
|
||||||
|
{"led_cc_on", cc_down},
|
||||||
|
{"led_cc_off", cc_off},
|
||||||
END_COMMAND};
|
END_COMMAND};
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -6,6 +6,13 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
void illumination_pwm(String command);
|
void illumination_pwm(String command);
|
||||||
|
void illumination_pwm_freq(String command);
|
||||||
|
|
||||||
|
void cc_on(String command);
|
||||||
|
void cc_off(String command);
|
||||||
|
void cc_up(String command);
|
||||||
|
void cc_down(String command);
|
||||||
|
|
||||||
void illumination_setup();
|
void illumination_setup();
|
||||||
extern const Command illumination_commands[];
|
extern const Command illumination_commands[];
|
||||||
#define ILLUMINATION_H
|
#define ILLUMINATION_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue