add example and fix makefile
This commit is contained in:
parent
a0a0cbf2da
commit
a02af3f279
5 changed files with 87 additions and 14 deletions
4
examples/dsm_test/Makefile
Normal file
4
examples/dsm_test/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Simple makefile for simple example
|
||||||
|
PROGRAM=dsm_test
|
||||||
|
EXTRA_COMPONENTS = extras/dsm
|
||||||
|
include ../../common.mk
|
||||||
67
examples/dsm_test/dsm_test.c
Normal file
67
examples/dsm_test/dsm_test.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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
|
# args for passing into compile rule generation
|
||||||
private/dsm_INC_DIR = $(ROOT)private/dsm
|
extras/dsm_INC_DIR = $(ROOT)extras/dsm
|
||||||
private/dsm_SRC_DIR = $(ROOT)private/dsm
|
extras/dsm_SRC_DIR = $(ROOT)extras/dsm
|
||||||
|
|
||||||
$(eval $(call component_compile_rules,private/dsm))
|
$(eval $(call component_compile_rules,extras/dsm))
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <esp8266.h>
|
#include <esp8266.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef DSM_DEBUG
|
#if (DSM_DEBUG)
|
||||||
#define debug(fmt, ...) printf("%s: " fmt "\n", "DSM", ## __VA_ARGS__)
|
#define debug(fmt, ...) printf("%s: " fmt "\n", "DSM", ## __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define debug(fmt, ...)
|
#define debug(fmt, ...)
|
||||||
|
|
@ -57,8 +57,6 @@ void dsm_init(uint8_t npins, const uint8_t* pins)
|
||||||
dsmInfo.running = 0;
|
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)
|
void dsm_set_prescale(uint8_t prescale)
|
||||||
{
|
{
|
||||||
//TODO: Add a freq/prescale converter
|
//TODO: Add a freq/prescale converter
|
||||||
|
|
@ -66,8 +64,6 @@ void dsm_set_prescale(uint8_t prescale)
|
||||||
debug("Set Prescale: %u",dsmInfo.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)
|
void dsm_set_target(uint8_t target)
|
||||||
{
|
{
|
||||||
dsmInfo.target = target;
|
dsmInfo.target = target;
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,20 @@
|
||||||
#ifndef EXTRAS_DSM_H_
|
#ifndef EXTRAS_DSM_H_
|
||||||
#define EXTRAS_DSM_H_
|
#define EXTRAS_DSM_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define MAX_DSM_PINS 8
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#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_init(uint8_t npins, const uint8_t* pins);
|
||||||
void dsm_set_prescale(uint8_t prescale);
|
void dsm_set_prescale(uint8_t prescale);
|
||||||
void dsm_set_target(uint8_t target);
|
void dsm_set_target(uint8_t target);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue