diff --git a/examples/dsm_test/Makefile b/examples/dsm_test/Makefile new file mode 100644 index 0000000..8438f41 --- /dev/null +++ b/examples/dsm_test/Makefile @@ -0,0 +1,4 @@ +# Simple makefile for simple example +PROGRAM=dsm_test +EXTRA_COMPONENTS = extras/dsm +include ../../common.mk diff --git a/examples/dsm_test/dsm_test.c b/examples/dsm_test/dsm_test.c new file mode 100644 index 0000000..234a66b --- /dev/null +++ b/examples/dsm_test/dsm_test.c @@ -0,0 +1,67 @@ +/* Very basic example to test the dsm library + * Led intensity from module will change over time. + * + * Part of esp-open-rtos + * Copyright (C) 2018 zaltora (https://github.com/Zaltora) + * BSD Licensed as described in the file LICENSE + */ +#include "espressif/esp_common.h" +#include "esp/uart.h" +#include "FreeRTOS.h" +#include "task.h" +#include "dsm.h" + +#define TEST_WITH_160MHZ (0) +#define DSM_PIN (2) + +void task1(void *pvParameters) +{ + uint32_t const init_count = 0; + uint32_t count = init_count; + while(1) + { + vTaskDelay(100/portTICK_PERIOD_MS); + printf("Target set to %3u, ", count); + //Freq = (80,000,000/prescale) * (target / 256) HZ (0 < target < 128) + //Freq = (80,000,000/prescale) * ((256 - target) / 256) HZ (128 < target < 256) + if (count < 128) + { + printf("Freqency: %.1f Hz\r\n", (80000000.0/255.0 * (count/ 256.0))); + } + else + { + printf("Freqency: %.1f Hz\r\n", 80000000.0/255.0 * ((256.0-count)/ 256.0)); + } + dsm_set_target(count); + count++; + if (count > UINT8_MAX) + count = init_count; + } +} + +void user_init(void) +{ + uint8_t pins[1]; + uart_set_baud(0, 115200); + +#if (TEST_WITH_160MHZ) + sdk_system_update_cpu_freq(160); +#endif + + printf("SDK version:%s\r\n", sdk_system_get_sdk_version()); + + pins[0] = DSM_PIN; + + /* register pin to use with DSM */ + dsm_init(1, pins); + /* Set prescale to FF to get a proper signal */ + dsm_set_prescale(0xFF); + /* Target initial */ + dsm_set_target(0); + /* start dsm to pin */ + dsm_start(); + + printf("dsm start\r\n"); + + xTaskCreate(task1, "tsk1", 256, NULL, 2, NULL); +} diff --git a/extras/dsm/component.mk b/extras/dsm/component.mk index fcf0ed4..06e56b1 100644 --- a/extras/dsm/component.mk +++ b/extras/dsm/component.mk @@ -1,9 +1,9 @@ -# Component makefile for private/dsm +# Component makefile for extras/dsm -INC_DIRS += $(ROOT)private/dsm +INC_DIRS += $(ROOT)extras/dsm # args for passing into compile rule generation -private/dsm_INC_DIR = $(ROOT)private/dsm -private/dsm_SRC_DIR = $(ROOT)private/dsm +extras/dsm_INC_DIR = $(ROOT)extras/dsm +extras/dsm_SRC_DIR = $(ROOT)extras/dsm -$(eval $(call component_compile_rules,private/dsm)) +$(eval $(call component_compile_rules,extras/dsm)) diff --git a/extras/dsm/dsm.c b/extras/dsm/dsm.c index f232a93..dd54fc4 100644 --- a/extras/dsm/dsm.c +++ b/extras/dsm/dsm.c @@ -11,7 +11,7 @@ #include -#ifdef DSM_DEBUG +#if (DSM_DEBUG) #define debug(fmt, ...) printf("%s: " fmt "\n", "DSM", ## __VA_ARGS__) #else #define debug(fmt, ...) @@ -57,8 +57,6 @@ void dsm_init(uint8_t npins, const uint8_t* pins) dsmInfo.running = 0; } -// Freq = (80,000,000/prescale) * (target / 256) HZ (0 < target < 128) -// Freq = (80,000,000/prescale) * ((256 - target) / 256) HZ (128 < target < 256) void dsm_set_prescale(uint8_t prescale) { //TODO: Add a freq/prescale converter @@ -66,8 +64,6 @@ void dsm_set_prescale(uint8_t prescale) debug("Set Prescale: %u",dsmInfo.preScale); } -// Freq = (80,000,000/prescale) * (target / 256) HZ (0 < target < 128) -// Freq = (80,000,000/prescale) * ((256 - target) / 256) HZ (128 < target < 256) void dsm_set_target(uint8_t target) { dsmInfo.target = target; diff --git a/extras/dsm/dsm.h b/extras/dsm/dsm.h index 49c5436..8190f7e 100644 --- a/extras/dsm/dsm.h +++ b/extras/dsm/dsm.h @@ -8,14 +8,20 @@ #ifndef EXTRAS_DSM_H_ #define EXTRAS_DSM_H_ -#include - -#define MAX_DSM_PINS 8 - #ifdef __cplusplus extern "C" { #endif +#include + +#define MAX_DSM_PINS (8) +#define DSM_DEBUG (0) + +/* + * Freq = (80,000,000/prescale) * (target / 256) HZ (0 < target < 128) + * Freq = (80,000,000/prescale) * ((256 - target) / 256) HZ (128 < target < 256) + */ + void dsm_init(uint8_t npins, const uint8_t* pins); void dsm_set_prescale(uint8_t prescale); void dsm_set_target(uint8_t target);