rename the lib

This commit is contained in:
Zaltora 2018-04-16 15:42:43 +02:00
parent bdfc9cb6e9
commit 11dc6da5b8
6 changed files with 154 additions and 160 deletions

9
extras/dsm/component.mk Normal file
View file

@ -0,0 +1,9 @@
# Component makefile for private/dsm
INC_DIRS += $(ROOT)private/dsm
# args for passing into compile rule generation
private/dsm_INC_DIR = $(ROOT)private/dsm
private/dsm_SRC_DIR = $(ROOT)private/dsm
$(eval $(call component_compile_rules,private/dsm))

115
extras/dsm/dsm.c Normal file
View file

@ -0,0 +1,115 @@
/* Implementation of Delta-Sigma modulator support.
*
* Part of esp-open-rtos
* Copyright (C) 2018 ourairquality (https://github.com/ourairquality)
* Copyright (C) 2018 Zaltora (https://github.com/Zaltora)
* BSD Licensed as described in the file LICENSE
*/
#include "dsm.h"
#include <espressif/esp_common.h>
#include <esp8266.h>
#ifdef DSM_DEBUG
#define debug(fmt, ...) printf("%s: " fmt "\n", "DSM", ## __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif
typedef struct dsmInfoDefinition
{
uint8_t running;
uint8_t preScale;
uint8_t dutyCycle;
bool output;
/* private */
uint8_t usedPins;
uint8_t pins[8];
} DSMInfo;
static DSMInfo dsmInfo;
void dsm_init(uint8_t npins, const uint8_t* pins)
{
/* Assert number of pins is correct */
if (npins > MAX_DSM_PINS)
{
debug("Incorrect number of PWM pins (%d)\n", npins);
return;
}
/* Save pins information */
dsmInfo.usedPins = npins;
for (uint8_t i = 0 ; i < npins; ++i)
{
dsmInfo.pins[i] = pins[i];
/* configure GPIOs */
gpio_enable(pins[i], GPIO_OUTPUT);
}
/* Set output to LOW */
dsm_stop();
/* Flag not running */
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
dsmInfo.preScale = 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.dutyCycle = target;
if (target == 0 || target == UINT8_MAX)
{
dsmInfo.output = (target == UINT8_MAX);
}
debug("Duty set at %u",dsmInfo.dutyCycle);
if (dsmInfo.running)
{
dsm_start();
}
}
void dsm_start()
{
if (dsmInfo.dutyCycle > 0 && dsmInfo.dutyCycle < UINT8_MAX)
{
for (uint8_t i = 0; i < dsmInfo.usedPins; ++i)
{
SET_MASK_BITS(GPIO.CONF[dsmInfo.pins[i]], GPIO_CONF_SOURCE_PWM);
}
GPIO.PWM = GPIO_PWM_ENABLE | (dsmInfo.preScale << 8) | dsmInfo.dutyCycle;
}
else
{
for (uint8_t i = 0; i < dsmInfo.usedPins; ++i)
{
gpio_write(dsmInfo.pins[i], dsmInfo.output );
}
}
debug("start");
dsmInfo.running = 1;
}
void dsm_stop()
{
for (uint8_t i = 0; i < dsmInfo.usedPins; ++i)
{
CLEAR_MASK_BITS(GPIO.CONF[dsmInfo.pins[i]], GPIO_CONF_SOURCE_PWM);
gpio_write(dsmInfo.pins[i], false);
}
debug("stop");
dsmInfo.running = 0;
}

30
extras/dsm/dsm.h Normal file
View file

@ -0,0 +1,30 @@
/* Implementation of Delta-Sigma modulator support.
*
* Part of esp-open-rtos
* Copyright (C) 2018 ourairquality (https://github.com/ourairquality)
* Copyright (C) 2018 Zaltora (https://github.com/Zaltora)
* BSD Licensed as described in the file LICENSE
*/
#ifndef EXTRAS_DSM_H_
#define EXTRAS_DSM_H_
#include <stdint.h>
#define MAX_DSM_PINS 8
#ifdef __cplusplus
extern "C" {
#endif
void dsm_init(uint8_t npins, const uint8_t* pins);
void dsm_set_prescale(uint8_t prescale);
void dsm_set_target(uint8_t target);
void dsm_start();
void dsm_stop();
#ifdef __cplusplus
}
#endif
#endif /* EXTRAS_DSM_H_ */

View file

@ -1,9 +0,0 @@
# Component makefile for private/hw_pwm
INC_DIRS += $(ROOT)private/hw_pwm
# args for passing into compile rule generation
private/hw_pwm_INC_DIR = $(ROOT)private/hw_pwm
private/hw_pwm_SRC_DIR = $(ROOT)private/hw_pwm
$(eval $(call component_compile_rules,private/hw_pwm))

View file

@ -1,120 +0,0 @@
/* Implementation of HW PWM support.
*
* Part of esp-open-rtos
* Copyright (C) 2018 ourairquality (https://github.com/ourairquality)
* Copyright (C) 2018 Zaltora (https://github.com/Zaltora)
* BSD Licensed as described in the file LICENSE
*/
#include "pwm.h"
#include <espressif/esp_common.h>
#include <esp8266.h>
#ifdef PWM_DEBUG
#define debug(fmt, ...) printf("%s: " fmt "\n", "HW_PWM", ## __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif
typedef struct pwmInfoDefinition
{
uint8_t running;
uint8_t preScale;
uint8_t dutyCycle;
bool output;
/* private */
uint8_t usedPins;
uint8_t pins[8];
} PWMInfo;
static PWMInfo pwmInfo;
void hw_pwm_init(uint8_t npins, const uint8_t* pins)
{
/* Assert number of pins is correct */
if (npins > MAX_PWM_PINS)
{
debug("Incorrect number of PWM pins (%d)\n", npins);
return;
}
/* Save pins information */
pwmInfo.usedPins = npins;
for (uint8_t i = 0 ; i < npins; ++i)
{
pwmInfo.pins[i] = pins[i];
/* configure GPIOs */
gpio_enable(pins[i], GPIO_OUTPUT);
}
/* Set output to LOW */
hw_pwm_stop();
/* Flag not running */
pwmInfo.running = 0;
}
//FIXME: Need Confirmation
// Freq = (80,000,000/prescale) * (target / 256) HZ (0 < target < 128)
// Freq = (80,000,000/prescale) * ((256 - target) / 256) HZ (128 < target < 256)
void hw_pwm_set_prescale(uint8_t prescale)
{
//TODO: Add a freq/prescale converter
pwmInfo.preScale = prescale;
debug("Set Prescale: %u",pwmInfo.preScale);
}
void hw_pwm_set_duty(uint8_t duty)
{
pwmInfo.dutyCycle = duty;
if (duty == 0 || duty == UINT8_MAX)
{
pwmInfo.output = (duty == UINT8_MAX);
}
debug("Duty set at %u",pwmInfo.dutyCycle);
hw_pwm_restart();
}
void hw_pwm_restart()
{
if (pwmInfo.running)
{
hw_pwm_stop();
hw_pwm_start();
}
}
void hw_pwm_start()
{
if (pwmInfo.dutyCycle > 0 && pwmInfo.dutyCycle < UINT8_MAX)
{
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{
SET_MASK_BITS(GPIO.CONF[pwmInfo.pins[i]], GPIO_CONF_SOURCE_PWM);
}
GPIO.PWM = GPIO_PWM_ENABLE | (pwmInfo.preScale << 8) | pwmInfo.dutyCycle;
}
else
{
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{
gpio_write(pwmInfo.pins[i], pwmInfo.output );
}
}
debug("start");
pwmInfo.running = 1;
}
void hw_pwm_stop()
{
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{
CLEAR_MASK_BITS(GPIO.CONF[pwmInfo.pins[i]], GPIO_CONF_SOURCE_PWM);
gpio_write(pwmInfo.pins[i], false);
}
debug("stop");
pwmInfo.running = 0;
}

View file

@ -1,31 +0,0 @@
/* Implementation of HW PWM support.
*
* Part of esp-open-rtos
* Copyright (C) 2018 ourairquality (https://github.com/ourairquality)
* Copyright (C) 2018 Zaltora (https://github.com/Zaltora)
* BSD Licensed as described in the file LICENSE
*/
#ifndef EXTRAS_HW_PWM_H_
#define EXTRAS_HW_PWM_H_
#include <stdint.h>
#define MAX_PWM_PINS 8
#ifdef __cplusplus
extern "C" {
#endif
void hw_pwm_init(uint8_t npins, const uint8_t* pins);
void hw_pwm_set_prescale(uint8_t prescale);
void hw_pwm_set_duty(uint8_t duty);
void hw_pwm_restart();
void hw_pwm_start();
void hw_pwm_stop();
#ifdef __cplusplus
}
#endif
#endif /* EXTRAS_HW_PWM_H_ */