diff --git a/README.md b/README.md index 00e225bf7d98d0c1e65a6d3f0dcc9debe995f2be..37edeaa8a8ac613e1c5a94112d5ac94d936cc7ce 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Development Status Most of the framework is implemented. Most noticable is the missing analogWrite. While analogWrite is on it's way, there are a few other options that you can use: - 16 channels [LEDC](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.h) which is PWM -- 8 channels [SigmaDelta](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-sd.h) which uses SigmaDelta modulation +- 8 channels [SigmaDelta](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-sigmadelta.h) which uses SigmaDelta modulation - 2 channels [DAC](https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-dac.h) which gives real analog output ## Installation Instructions diff --git a/cores/esp32/esp32-hal-sd.c b/cores/esp32/esp32-hal-sigmadelta.c similarity index 71% rename from cores/esp32/esp32-hal-sd.c rename to cores/esp32/esp32-hal-sigmadelta.c index 6627f553c41dc536ee5524b7daaa3cda5d36bd36..78d8c40f6063e7c7a72346cd9374187e3830a518 100644 --- a/cores/esp32/esp32-hal-sd.c +++ b/cores/esp32/esp32-hal-sigmadelta.c @@ -31,53 +31,53 @@ xSemaphoreHandle _sd_sys_lock; #endif -uint32_t sdSetup(uint8_t channel, uint32_t freq) //chan 0-7 freq 1220-312500 +uint32_t sigmaDeltaSetup(uint8_t channel, uint32_t freq) //chan 0-7 freq 1220-312500 { if(channel > 7) { return 0; } +#if !CONFIG_DISABLE_HAL_LOCKS static bool tHasStarted = false; if(!tHasStarted) { tHasStarted = true; -#if !CONFIG_DISABLE_HAL_LOCKS _sd_sys_lock = xSemaphoreCreateMutex(); -#endif } - gpio_sd_dev_t * gpio_sd_dev = (volatile gpio_sd_dev_t *)(DR_REG_GPIO_SD_BASE); +#endif uint32_t prescale = (10000000/(freq*32)) - 1; if(prescale > 0xFF) { prescale = 0xFF; } SD_MUTEX_LOCK(); - gpio_sd_dev->channel[channel].prescale = prescale; - gpio_sd_dev->cg.clk_en = 0; - gpio_sd_dev->cg.clk_en = 1; + SIGMADELTA.channel[channel].prescale = prescale; + SIGMADELTA.cg.clk_en = 0; + SIGMADELTA.cg.clk_en = 1; SD_MUTEX_UNLOCK(); return 10000000/((prescale + 1) * 32); } -void sdWrite(uint8_t channel, uint8_t duty) //chan 0-7 duty 8 bit +void sigmaDeltaWrite(uint8_t channel, uint8_t duty) //chan 0-7 duty 8 bit { if(channel > 7) { return; } duty += 128; - gpio_sd_dev_t * gpio_sd_dev = (volatile gpio_sd_dev_t *)(DR_REG_GPIO_SD_BASE); SD_MUTEX_LOCK(); - gpio_sd_dev->channel[channel].duty = duty; + SIGMADELTA.channel[channel].duty = duty; SD_MUTEX_UNLOCK(); } -uint8_t sdRead(uint8_t channel) //chan 0-7 +uint8_t sigmaDeltaRead(uint8_t channel) //chan 0-7 { if(channel > 7) { return 0; } - gpio_sd_dev_t * gpio_sd_dev = (volatile gpio_sd_dev_t *)(DR_REG_GPIO_SD_BASE); - return gpio_sd_dev->channel[channel].duty - 128; + SD_MUTEX_LOCK(); + uint8_t duty = SIGMADELTA.channel[channel].duty - 128; + SD_MUTEX_UNLOCK(); + return duty; } -void sdAttachPin(uint8_t pin, uint8_t channel) //channel 0-7 +void sigmaDeltaAttachPin(uint8_t pin, uint8_t channel) //channel 0-7 { if(channel > 7) { return; @@ -86,7 +86,7 @@ void sdAttachPin(uint8_t pin, uint8_t channel) //channel 0-7 pinMatrixOutAttach(pin, GPIO_SD0_OUT_IDX + channel, false, false); } -void sdDetachPin(uint8_t pin) +void sigmaDeltaDetachPin(uint8_t pin) { pinMatrixOutDetach(pin, false, false); } diff --git a/cores/esp32/esp32-hal-sd.h b/cores/esp32/esp32-hal-sigmadelta.h similarity index 100% rename from cores/esp32/esp32-hal-sd.h rename to cores/esp32/esp32-hal-sigmadelta.h diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 2296bb2b2d3f998365ab5f22c6bd3ebd32e9ba04..c0072ca91fd3cc2ac2782cd3cc612084b7fb857d 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -56,7 +56,7 @@ void vPortYield( void ); #include "esp32-hal-spi.h" #include "esp32-hal-i2c.h" #include "esp32-hal-ledc.h" -#include "esp32-hal-sd.h" +#include "esp32-hal-sigmadelta.h" #include "esp32-hal-timer.h" #include "esp_system.h"