add
This commit is contained in:
parent
b3f658bdbf
commit
b982a132ae
5 changed files with 98 additions and 0 deletions
3
examples/pcf8591/Makefile
Normal file
3
examples/pcf8591/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
PROGRAM = pcf8591
|
||||||
|
EXTRA_COMPONENTS = extras/i2c extras/pcf8591
|
||||||
|
include ../../common.mk
|
43
examples/pcf8591/main.c
Normal file
43
examples/pcf8591/main.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Example of using PCA9685 PWM driver
|
||||||
|
*
|
||||||
|
* Part of esp-open-rtos
|
||||||
|
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
|
||||||
|
* Public domain
|
||||||
|
*/
|
||||||
|
#include <esp/uart.h>
|
||||||
|
#include <espressif/esp_common.h>
|
||||||
|
#include <i2c/i2c.h>
|
||||||
|
#include <pca9685/pca9685.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define ADDR 0x40
|
||||||
|
|
||||||
|
#define SCL_PIN 5
|
||||||
|
#define SDA_PIN 4
|
||||||
|
|
||||||
|
#define PWM_FREQ 500
|
||||||
|
|
||||||
|
void user_init(void)
|
||||||
|
{
|
||||||
|
uart_set_baud(0, 115200);
|
||||||
|
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||||
|
|
||||||
|
i2c_init(SCL_PIN, SDA_PIN);
|
||||||
|
|
||||||
|
pca9685_init(ADDR);
|
||||||
|
|
||||||
|
pca9685_set_pwm_frequency(ADDR, 1000);
|
||||||
|
printf("Freq 1000Hz, real %d\n", pca9685_get_pwm_frequency(ADDR));
|
||||||
|
|
||||||
|
uint16_t val = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
printf("Set ch0 to %d, ch4 to %d\n", val, 4096 - val);
|
||||||
|
pca9685_set_pwm_value(ADDR, 0, val);
|
||||||
|
pca9685_set_pwm_value(ADDR, 4, 4096 - val);
|
||||||
|
|
||||||
|
if (val++ == 4096)
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
|
}
|
6
extras/pcf8591/component.mk
Normal file
6
extras/pcf8591/component.mk
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# Component makefile for extras/pcf8591
|
||||||
|
|
||||||
|
INC_DIRS += $(pcf8591_ROOT)..
|
||||||
|
pcf8591_SRC_DIR = $(pcf8591_ROOT)
|
||||||
|
|
||||||
|
$(eval $(call component_compile_rules,pcf8591))
|
15
extras/pcf8591/pcf8591.c
Normal file
15
extras/pcf8591/pcf8591.c
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <i2c/i2c.h>
|
||||||
|
#include "pcf8591.h"
|
||||||
|
|
||||||
|
static uint8_t mAddress = PCF8591_DEFAULT_ADDRESS;
|
||||||
|
static float mVoltage = 3.3f;
|
||||||
|
|
||||||
|
void
|
||||||
|
pcf8591_set_address(uint8_t addr)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
31
extras/pcf8591/pcf8591.h
Normal file
31
extras/pcf8591/pcf8591.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* Driver for 8-bit analog-to-digital conversion and
|
||||||
|
* an 8-bit digital-to-analog conversion PCF8591
|
||||||
|
*
|
||||||
|
* Part of esp-open-rtos
|
||||||
|
* Copyright (C) 2017 Pham Ngoc Thanh <pnt239@gmail.com>
|
||||||
|
* BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
#ifndef _EXTRAS_PCF8591_H_
|
||||||
|
#define _EXTRAS_PCF8591_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PCF8591_DEFAULT_ADDRESS 0x90
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set new sensor address for switching another.
|
||||||
|
* @param[in] addr Pointer to device
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
void pcf8591_set_address(uint8_t addr);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _EXTRAS_PCF8591_H_ */
|
Loading…
Reference in a new issue