diff --git a/platformio.ini b/platformio.ini index e578319..8656613 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 @@ -54,4 +55,13 @@ build_flags = platform = espressif32 board = esp-wrover-kit build_flags = -D MCU_ESP32 -monitor_filters = esp32_exception_decoder \ No newline at end of file +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 \ No newline at end of file diff --git a/src/boards.h b/src/boards.h index 5d8db48..0ade14f 100644 --- a/src/boards.h +++ b/src/boards.h @@ -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 diff --git a/src/config.h b/src/config.h index bbeba30..5fb4fed 100644 --- a/src/config.h +++ b/src/config.h @@ -27,7 +27,7 @@ // #define ENDSTOPS // #define LIGHT_SENSOR // #define STEPSTICK - // #define ILLUMINATION + #define ILLUMINATION //module configs #ifdef STAGE diff --git a/src/main.h b/src/main.h index 5f561c4..e09d56f 100644 --- a/src/main.h +++ b/src/main.h @@ -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 diff --git a/src/modules/illumination/illumination.cpp b/src/modules/illumination/illumination.cpp index d718604..c9ab59a 100644 --- a/src/modules/illumination/illumination.cpp +++ b/src/modules/illumination/illumination.cpp @@ -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 \ No newline at end of file diff --git a/src/modules/illumination/illumination.h b/src/modules/illumination/illumination.h index 23f3c9b..46e865b 100644 --- a/src/modules/illumination/illumination.h +++ b/src/modules/illumination/illumination.h @@ -6,6 +6,13 @@ #include 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