@@ -54,7 +54,7 @@ void write_spi_bytes_16_prim(int times, uint32_t color) {
54
54
}
55
55
56
56
#define NUM_PRIMITIVES 0
57
- #define NUM_PRIMITIVES_ARDUINO 33
57
+ #define NUM_PRIMITIVES_ARDUINO 36
58
58
59
59
#define ALL_PRIMITIVES (NUM_PRIMITIVES + NUM_PRIMITIVES_ARDUINO)
60
60
@@ -487,6 +487,40 @@ def_prim(clear_pixels, NoneToNoneU32) {
487
487
return true ;
488
488
}
489
489
490
+ // Temporary Primitives needed for analogWrite in ESP32
491
+ def_prim (chip_ledc_analog_write, threeToNoneU32) {
492
+ uint8_t channel = arg2.uint32 ;
493
+ uint32_t value = arg1.uint32 ;
494
+ uint32_t maxValue = arg0.uint32 ;
495
+
496
+ // printf("chip_ledc_analog_write(%u, %u, %u)\n", channel, value, maxValue);
497
+ // calculate duty, 4095 from 2 ^ 12 - 1
498
+ uint32_t duty = (4095 / maxValue) * min (value, maxValue);
499
+
500
+ ledcWrite (channel, duty);
501
+ pop_args (3 );
502
+ return true ;
503
+ }
504
+
505
+ def_prim (chip_ledc_setup, threeToNoneU32) {
506
+ uint32_t channel = arg2.uint32 ;
507
+ uint32_t freq = arg1.uint32 ;
508
+ uint32_t ledc_timer = arg0.uint32 ;
509
+ // printf("chip_ledc_setup(%u, %u, %u)\n", channel, freq, ledc_timer);
510
+ ledcSetup (channel, freq, ledc_timer);
511
+ pop_args (3 );
512
+ return true ;
513
+ }
514
+
515
+ def_prim (chip_ledc_attach_pin, twoToNoneU32) {
516
+ uint32_t pin = arg1.uint32 ;
517
+ uint32_t channel = arg0.uint32 ;
518
+ // printf("chip_ledc_attach_pin(%u,%u)\n", pin, channel);
519
+ ledcAttachPin (pin, channel);
520
+ pop_args (2 );
521
+ return true ;
522
+ }
523
+
490
524
// INTERRUPTS
491
525
492
526
class Interrupt {
@@ -857,6 +891,11 @@ void install_primitives() {
857
891
install_primitive (set_pixel_color);
858
892
install_primitive (clear_pixels);
859
893
install_primitive (show_pixels);
894
+
895
+ // temporary primitives needed for analogWrite in ESP32
896
+ install_primitive (chip_ledc_analog_write);
897
+ install_primitive (chip_ledc_setup);
898
+ install_primitive (chip_ledc_attach_pin);
860
899
}
861
900
862
901
// ------------------------------------------------------
0 commit comments