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
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue