You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/12 22:34:49 UTC
[1/4] incubator-mynewt-core git commit: modified the hal_pwm API to
support the comments from the code review
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 9e1d390f6 -> fc78b273c
modified the hal_pwm API to support the comments from the code review
1) enable automatically
2) remove wave since its not useful to most
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/52118b14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/52118b14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/52118b14
Branch: refs/heads/develop
Commit: 52118b14f43c4640637f0a374b18b34cedd54da7
Parents: 35b4f23
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Tue Apr 5 17:06:49 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Fri Apr 8 10:48:00 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_pwm.h | 62 +++++++++++++----------------------
hw/hal/include/hal/hal_pwm_int.h | 14 ++++----
hw/hal/src/hal_pwm.c | 31 ++++++------------
hw/mcu/native/src/hal_pwm.c | 34 +++----------------
4 files changed, 46 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52118b14/hw/hal/include/hal/hal_pwm.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_pwm.h b/hw/hal/include/hal/hal_pwm.h
index ddbb994..8eabc70 100644
--- a/hw/hal/include/hal/hal_pwm.h
+++ b/hw/hal/include/hal/hal_pwm.h
@@ -29,58 +29,42 @@
struct hal_pwm;
/* Initialize a new PWM device with the given system id.
- * Returns negative on error, 0 on success*/
+ * Returns negative on error, 0 on success. */
struct hal_pwm*
hal_pwm_init(enum system_device_id sysid);
-/* enables the PWM corresponding to PWM *ppwm.*/
-int
-hal_pwm_on(struct hal_pwm *ppwm);
+/* gets the underlying clock driving the PWM output. Return value
+ * is in Hz. Returns negative on error */
+int
+hal_pwm_get_source_clock_freq(struct hal_pwm *ppwm);
-/* disables the PWM corresponding to PWM *ppwm.*/
+/* gets the resolution of the PWM in bits. An N-bit PWM can have
+ * on values between 0 and 2^bits - 1. Returns negative on error */
int
-hal_pwm_off(struct hal_pwm *ppwm);
+hal_pwm_get_resolution_bits(struct hal_pwm *ppwm);
-/* There are two APIs for setting the PWM waveform. You can use one
- * or both in your programs, but only the last one called will apply
- *
- * hal_pwm_set_duty_cycle -- sets the PWM waveform for a specific duty cycle
- * It uses a 255 clock period and sets the on and off time
- * according to the argument
- *
- * hal_pwm_set_waveform -- sets the PWM waveform for a specific on time
- * and period specified in PWM clocks. its intended for more
- * fine-grained control of the PWM waveform.
- *
- */
+/* turns off the PWM channel */
+int
+hal_pwm_disable(struct hal_pwm *ppwm);
-/* sets the duty cycle of the PWM output. This duty cycle is
- * a fractional duty cycle where 0 == off, 255 = on, and
+/* enables the PWM with duty cycle specified. This duty cycle is
+ * a fractional duty cycle where 0 == off, 65535=on, and
* any value in between is on for fraction clocks and off
- * for 255-fraction clocks.
- * When you are looking for more fine-grained control over
- * the PWM, use the API set_waveform below.
+ * for 65535-fraction clocks.
*/
int
-hal_pwm_set_duty_cycle(struct hal_pwm *ppwm, uint8_t fraction);
+hal_pwm_enable_duty_cycle(struct hal_pwm *ppwm, uint16_t fraction);
-
-/* Sets the pwm waveform period and on-time in units of the PWM clock
- (see below). Period_clocks and on_clocks cannot exceed the
- * 2^N-1 where N is the resolution of the PWM channel */
+/*
+ * This frequency must be between 1/2 the clock frequency and
+ * the clock divided by the resolution. NOTE: This may affect
+ * other PWM channels.
+ */
int
-hal_pwm_set_waveform(struct hal_pwm *ppwm, uint32_t period_clocks, uint32_t on_clocks);
-
-
-/* gets the underlying clock driving the PWM output. Return value
- * is in Hz. Returns negative on error */
-int
-hal_pwm_get_clock_freq(struct hal_pwm *ppwm);
+hal_pwm_set_frequency(struct hal_pwm *ppwm, uint32_t freq_hz);
-/* gets the resolution of the PWM in bits. An N-bit PWM can have
- * period and on values between 0 and 2^bits - 1. Returns negative on error */
-int
-hal_pwm_get_resolution_bits(struct hal_pwm *ppwm);
+/* NOTE: If you know the resolution and clock frequency, you can
+ * compute the period of the PWM Its 2^resolution/clock_freq */
#endif /* _HAL_HAL_PWM_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52118b14/hw/hal/include/hal/hal_pwm_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_pwm_int.h b/hw/hal/include/hal/hal_pwm_int.h
index 3570484..f47233c 100644
--- a/hw/hal/include/hal/hal_pwm_int.h
+++ b/hw/hal/include/hal/hal_pwm_int.h
@@ -31,12 +31,14 @@ struct hal_pwm;
struct hal_pwm_funcs
{
- int (*hpwm_on) (struct hal_pwm *ppwm);
- int (*hpwm_off) (struct hal_pwm *ppwm);
- int (*hpwm_get_bits) (struct hal_pwm *ppwm);
- int (*hpwm_get_clk) (struct hal_pwm *ppwm);
- int (*hpwm_set_duty) (struct hal_pwm *ppwm, uint8_t frac_duty);
- int (*hpwm_set_wave) (struct hal_pwm *ppwm, uint32_t period, uint32_t on);
+
+ /* the low level hal API */
+ int (*hpwm_get_bits) (struct hal_pwm *ppwm);
+ int (*hpwm_get_clk) (struct hal_pwm *ppwm);
+ int (*hpwm_disable) (struct hal_pwm *ppwm);
+ int (*hpwm_ena_duty) (struct hal_pwm *ppwm, uint16_t frac_duty);
+ int (*hpwm_set_freq) (struct hal_pwm *ppwm, uint32_t freq_hz);
+
};
struct hal_pwm
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52118b14/hw/hal/src/hal_pwm.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_pwm.c b/hw/hal/src/hal_pwm.c
index 34c30fa..b20b2e0 100644
--- a/hw/hal/src/hal_pwm.c
+++ b/hw/hal/src/hal_pwm.c
@@ -26,40 +26,31 @@ hal_pwm_init(enum system_device_id sysid)
return bsp_get_hal_pwm_driver(sysid);
}
-int
-hal_pwm_on(struct hal_pwm *ppwm)
-{
- if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_on )
- {
- return ppwm->driver_api->hpwm_on(ppwm);
- }
- return -1;
-}
int
-hal_pwm_off(struct hal_pwm *ppwm)
+hal_pwm_disable(struct hal_pwm *ppwm)
{
- if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_off )
+ if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_disable )
{
- return ppwm->driver_api->hpwm_off(ppwm);
+ return ppwm->driver_api->hpwm_disable(ppwm);
}
return -1;
}
int
-hal_pwm_set_duty_cycle(struct hal_pwm *ppwm, uint8_t fraction) {
- if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_set_duty )
+hal_pwm_enable_duty_cycle(struct hal_pwm *ppwm, uint16_t fraction) {
+ if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_ena_duty )
{
- return ppwm->driver_api->hpwm_set_duty(ppwm, fraction);
+ return ppwm->driver_api->hpwm_ena_duty(ppwm, fraction);
}
return -1;
}
int
-hal_pwm_set_waveform(struct hal_pwm *ppwm, uint32_t period_clocks, uint32_t on_clocks) {
- if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_set_wave )
+hal_pwm_set_frequency(struct hal_pwm *ppwm, uint32_t freq_hz) {
+ if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_set_freq)
{
- return ppwm->driver_api->hpwm_set_wave(ppwm, period_clocks, on_clocks);
+ return ppwm->driver_api->hpwm_set_freq(ppwm, freq_hz);
}
return -1;
}
@@ -73,8 +64,6 @@ hal_pwm_get_clock_freq(struct hal_pwm *ppwm) {
return -1;
}
-/* gets the resolution of the PWM in bits. An N-bit PWM can have
- * period and on values between 0 and 2^bits - 1 */
int
hal_pwm_get_resolution_bits(struct hal_pwm *ppwm) {
if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_get_bits )
@@ -82,4 +71,4 @@ hal_pwm_get_resolution_bits(struct hal_pwm *ppwm) {
return ppwm->driver_api->hpwm_get_bits(ppwm);
}
return -1;
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52118b14/hw/mcu/native/src/hal_pwm.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_pwm.c b/hw/mcu/native/src/hal_pwm.c
index 36951d2..5d0688b 100644
--- a/hw/mcu/native/src/hal_pwm.c
+++ b/hw/mcu/native/src/hal_pwm.c
@@ -37,9 +37,7 @@ struct native_pwm_drv {
};
static int native_pwm_off(struct hal_pwm *ppwm);
-static int native_pwm_on(struct hal_pwm *ppwm);
-static int native_pwm_set_wave(struct hal_pwm *ppwm, uint32_t period, uint32_t on);
-static int native_pwm_set_duty(struct hal_pwm *ppwm, uint8_t frac_duty);
+static int native_pwm_enable_duty(struct hal_pwm *ppwm, uint16_t frac_duty);
static int native_pwm_get_bits(struct hal_pwm *ppwm);
static int native_pwm_get_clock(struct hal_pwm *ppwm);
@@ -48,10 +46,8 @@ static const struct hal_pwm_funcs native_pwm_funcs =
{
.hpwm_get_bits = &native_pwm_get_bits,
.hpwm_get_clk = &native_pwm_get_clock,
- .hpwm_off = &native_pwm_off,
- .hpwm_on = &native_pwm_on,
- .hpwm_set_duty = &native_pwm_set_duty,
- .hpwm_set_wave = &native_pwm_set_wave,
+ .hpwm_disable = &native_pwm_off,
+ .hpwm_ena_duty = &native_pwm_enable_duty,
};
struct hal_pwm *
@@ -122,36 +118,16 @@ static int native_pwm_get_clock(struct hal_pwm *ppwm) {
}
int
-native_pwm_set_duty(struct hal_pwm *ppwm, uint8_t fraction)
+native_pwm_enable_duty(struct hal_pwm *ppwm, uint16_t fraction)
{
struct native_pwm_drv *pn = (struct native_pwm_drv *) ppwm;
if(pn)
{
- pn->period_ticks = 255;
+ pn->period_ticks = 65535;
pn->on_ticks = fraction;
return 0;
}
return -2;
}
-int
-native_pwm_set_wave(struct hal_pwm *ppwm, uint32_t period, uint32_t on)
-{
- struct native_pwm_drv *pn = (struct native_pwm_drv *) ppwm;
-
- if(pn)
- {
- if(period > ((1 << NATIVE_PWM_BITS) - 1)) {
- return -2;
- }
- if(on > ((1 << NATIVE_PWM_BITS) - 1)) {
- return -3;
- }
- pn->period_ticks = period;
- pn->on_ticks = on;
- return 0;
- }
- return -4;
-}
-
[4/4] incubator-mynewt-core git commit: Merge remote-tracking branch
'paulfdietrich/dac_review' into develop
Posted by cc...@apache.org.
Merge remote-tracking branch 'paulfdietrich/dac_review' into develop
This closes #39.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fc78b273
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fc78b273
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fc78b273
Branch: refs/heads/develop
Commit: fc78b273c7a6fd5897b11ff2cb554ec0f1662c5a
Parents: 92a9256 18324c8
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Apr 12 13:33:20 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Apr 12 13:33:20 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_dac.h | 26 ++++++++++++++++----------
hw/hal/include/hal/hal_dac_int.h | 8 +++++---
hw/hal/src/hal_dac.c | 10 +++++++++-
3 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
[2/4] incubator-mynewt-core git commit: added a disable API for
hal_dac
Posted by cc...@apache.org.
added a disable API for hal_dac
Also fixed code to better match coding standard
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/18324c89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/18324c89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/18324c89
Branch: refs/heads/develop
Commit: 18324c89dc63ecb7afefaae9261fca9756ecdb0e
Parents: 9e1d390
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Sat Apr 9 17:33:20 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Tue Apr 12 12:16:56 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_dac.h | 26 ++++++++++++++++----------
hw/hal/include/hal/hal_dac_int.h | 8 +++++---
hw/hal/src/hal_dac.c | 10 +++++++++-
3 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18324c89/hw/hal/include/hal/hal_dac.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_dac.h b/hw/hal/include/hal/hal_dac.h
index ab765de..5ae3f94 100644
--- a/hw/hal/include/hal/hal_dac.h
+++ b/hw/hal/include/hal/hal_dac.h
@@ -40,38 +40,44 @@ struct hal_dac *
hal_dac_init(enum system_device_id sysid);
/*
- * write the DAC corresponding to sysid in your system.
- * Return 0 on success negative on failures. If you
- * write a value larger than the DAC size, it will
- * get truncated to the maximum DAC value but the write
- * will succeed.
+ * write the DAC corresponding to sysid in your system
+ * and enables the DAC. Return 0 on success negative on failures. If you
+ * write a value larger than the DAC size, it will get truncated to the
+ * maximum DAC value but the write will succeed.
*/
int
hal_dac_write(struct hal_dac *pdac, int val);
-/* gets the current value that is output on the DAC .
+/*
+ * Gets the current value that is output on the DAC .
* Return the current value on success negative on failures.
*/
int
hal_dac_get_current(struct hal_dac *pdac);
-/* returns the number of bit of resolution in this DAC.
+/*
+ * Returns the number of bit of resolution in this DAC.
* For example if the system has an 8-bit DAC reporting
* values from 0= to 255 (2^8-1), this function would return
* the value 8. returns negative or zero on error */
int
hal_dac_get_bits(struct hal_dac *pdac);
-/* Returns the positive reference voltage for a maximum DAC reading.
+/*
+ * Returns the positive reference voltage for a maximum DAC reading.
* This API assumes the negative reference voltage is zero volt.
* Returns negative or zero on error.
*/
int
hal_dac_get_ref_mv(struct hal_dac *pdac);
+/* turns the DAC off. Re-enable with hal_dac_write */
+int
+hal_dac_disable(struct hal_dac *pdac);
+
+
/* Converts a value in millivolts to a DAC value for this DAC */
int
hal_dac_to_val(struct hal_dac *pdac, int mvolts);
-
-#endif /* HAL_DAC_H */
\ No newline at end of file
+#endif /* HAL_DAC_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18324c89/hw/hal/include/hal/hal_dac_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_dac_int.h b/hw/hal/include/hal/hal_dac_int.h
index fa679d7..dcb0c31 100644
--- a/hw/hal/include/hal/hal_dac_int.h
+++ b/hw/hal/include/hal/hal_dac_int.h
@@ -20,7 +20,6 @@
#ifndef HAL_DAC_INT_H
#define HAL_DAC_INT_H
-#include <inttypes.h>
#include <bsp/bsp_sysid.h>
@@ -28,9 +27,11 @@ struct hal_dac;
/* These functions make up the driver API for DAC devices. All
* DAC devices with Mynewt support implement this interface */
-struct hal_dac_funcs {
+struct hal_dac_funcs
+{
int (*hdac_write) (struct hal_dac *pdac, int val);
int (*hdac_current) (struct hal_dac *pdac);
+ int (*hdac_disable) (struct hal_dac *pdac);
int (*hdac_get_bits) (struct hal_dac *pdac);
int (*hdac_get_ref_mv) (struct hal_dac *pdac);
};
@@ -51,7 +52,8 @@ struct hal_dac_funcs {
*
* See the native MCU and BSP for examples
*/
-struct hal_dac {
+struct hal_dac
+{
const struct hal_dac_funcs *driver_api;
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18324c89/hw/hal/src/hal_dac.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_dac.c b/hw/hal/src/hal_dac.c
index 3e334a3..c083a75 100644
--- a/hw/hal/src/hal_dac.c
+++ b/hw/hal/src/hal_dac.c
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include <inttypes.h>
#include <hal/hal_dac.h>
#include <hal/hal_dac_int.h>
@@ -86,3 +85,12 @@ hal_dac_to_val(struct hal_dac *pdac, int mvolts)
}
return rc;
}
+
+int
+hal_dac_disable(struct hal_dac *pdac)
+{
+ if (pdac && pdac->driver_api && pdac->driver_api->hdac_disable) {
+ return pdac->driver_api->hdac_disable(pdac);
+ }
+ return -1;
+}
[3/4] incubator-mynewt-core git commit: Merge remote-tracking branch
'paulfdietrich/hal_pwm_arduino' into develop
Posted by cc...@apache.org.
Merge remote-tracking branch 'paulfdietrich/hal_pwm_arduino' into develop
This closes #35.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/92a92565
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/92a92565
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/92a92565
Branch: refs/heads/develop
Commit: 92a925650a555be8e821293320fe397cfc51a6ad
Parents: 9e1d390 52118b1
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Apr 12 13:32:02 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Apr 12 13:32:02 2016 -0700
----------------------------------------------------------------------
----------------------------------------------------------------------