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
|
||||
build_flags = -D MCU_LEONARDO
|
||||
|
||||
[env:pico]
|
||||
platform = raspberrypi
|
||||
board = pico
|
||||
build_flags = -D MCU_PICO
|
||||
;[env:pico]
|
||||
;platform = raspberrypi
|
||||
;board = pico
|
||||
;build_flags = -D MCU_PICO
|
||||
;upload_port = /media/filip/RPI-RP2
|
||||
|
||||
[env:bluepill]
|
||||
platform = ststm32
|
||||
|
|
@ -55,3 +56,12 @@ platform = espressif32
|
|||
board = esp-wrover-kit
|
||||
build_flags = -D MCU_ESP32
|
||||
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)
|
||||
#define BOARD_CUSTOM_BLUEPILL
|
||||
#elif defined(MCU_PICO)
|
||||
#define BOARD_CUSTOM_PICO
|
||||
#define BOARD_SANGABOARDv5
|
||||
#elif defined(MCU_ESP32)
|
||||
#define BOARD_CUSTOM_ESP32
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// #define ENDSTOPS
|
||||
// #define LIGHT_SENSOR
|
||||
// #define STEPSTICK
|
||||
// #define ILLUMINATION
|
||||
#define ILLUMINATION
|
||||
|
||||
//module configs
|
||||
#ifdef STAGE
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@
|
|||
}
|
||||
#define CHECK_END_COMMAND(C) check_end_command(C)
|
||||
|
||||
//TODO: temporarily disabled for philhower compatibilty
|
||||
//extern arduino::UART PiSerial;
|
||||
|
||||
#ifdef BOARD_SANGABOARDv5
|
||||
extern arduino::UART PiSerial;
|
||||
#endif
|
||||
|
||||
struct Command
|
||||
|
|
|
|||
|
|
@ -7,35 +7,98 @@
|
|||
#include "dummyEEPROM.h"
|
||||
#endif
|
||||
|
||||
#define WIRING_PWM_LED_NUM 1
|
||||
#define PWM_NUM 1
|
||||
#define WIRING_PWM_LEDS {25}
|
||||
//TODO: implement some fancier features of TMC controllers
|
||||
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
|
||||
char * args[2];
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 2);
|
||||
if (atof(args[1]) < 0.001)
|
||||
{
|
||||
digitalWrite(pwm_led_pins[0], LOW);//start with motor disabled
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(pwm_led_pins[0], HIGH);
|
||||
}
|
||||
SERIAL_PORT.println("Illumination set");
|
||||
#ifdef MCU_PICO
|
||||
analogWriteFreq(atol(args[0]));//32khz seems sensible
|
||||
#else
|
||||
SERIAL_PORT.println("Feature not supported");
|
||||
#endif
|
||||
|
||||
SERIAL_PORT.println("Frequency set");
|
||||
free(args[0]);
|
||||
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()
|
||||
{
|
||||
#ifdef MCU_PICO
|
||||
analogWriteRange(65535);
|
||||
analogWriteFreq(32000);//32khz seems sensible
|
||||
#endif
|
||||
pinMode(pwm_led_pins[0], OUTPUT);
|
||||
pinMode(CC_EN_PIN, OUTPUT);
|
||||
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[] = {
|
||||
{"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};
|
||||
#endif
|
||||
|
|
@ -6,6 +6,13 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
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();
|
||||
extern const Command illumination_commands[];
|
||||
#define ILLUMINATION_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue