1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 04:43:21 +00:00

Fix and close #53. Start of implementation for #55

This commit is contained in:
Robert Wolterman
2017-01-24 05:23:04 +00:00
parent 962049299a
commit 8c3dab1ecc
8 changed files with 56 additions and 40 deletions

View File

@ -1,3 +1,8 @@
0.3.2
----
* Fixing issue #53 to handle the return values of the set functions in pwm_enable.
* Start of whole library debug for #55
0.3.1 0.3.1
---- ----
* Fixing issue #50 where I broke GPIO.cleanup() and SOFTPWM.cleanup() when no input is specified. * Fixing issue #50 where I broke GPIO.cleanup() and SOFTPWM.cleanup() when no input is specified.

View File

@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
'Topic :: System :: Hardware'] 'Topic :: System :: Hardware']
setup(name = 'CHIP_IO', setup(name = 'CHIP_IO',
version = '0.3.1', version = '0.3.2',
author = 'Robert Wolterman', author = 'Robert Wolterman',
author_email = 'robert.wolterman@gmail.com', author_email = 'robert.wolterman@gmail.com',
description = 'A module to control CHIP IO channels', description = 'A module to control CHIP IO channels',

View File

@ -47,9 +47,7 @@ SOFTWARE.
// Global variables // Global variables
int pwm_initialized = 0; int pwm_initialized = 0;
int DEBUG = 0; //int DEBUG = 0;
//int ENABLE = 1;
//int DISABLE = 0;
// pwm devices (future chip pro use) // pwm devices (future chip pro use)
struct pwm_dev struct pwm_dev
@ -150,17 +148,16 @@ int pwm_set_frequency(const char *key, float freq) {
period_ns = (unsigned long)(1e9 / freq); period_ns = (unsigned long)(1e9 / freq);
if (pwm->enable) { if (pwm->enable) {
if (DEBUG)
printf(" ** IN pwm_set_frequency: pwm_initialized = %d\n", pwm_initialized);
if (period_ns != pwm->period_ns) { if (period_ns != pwm->period_ns) {
pwm->period_ns = period_ns; pwm->period_ns = period_ns;
len = snprintf(buffer, sizeof(buffer), "%lu", period_ns); BUF2SMALL(buffer); len = snprintf(buffer, sizeof(buffer), "%lu", period_ns); BUF2SMALL(buffer);
if (DEBUG)
printf(" ** pwm_set_frequency: buffer: %s\n", buffer);
ssize_t s = write(pwm->period_fd, buffer, len); //ASSRT(s == len); ssize_t s = write(pwm->period_fd, buffer, len); //ASSRT(s == len);
if (DEBUG) if (DEBUG) {
printf(" ** IN pwm_set_frequency: pwm_initialized = %d\n", pwm_initialized);
printf(" ** pwm_set_frequency: buffer: %s\n", buffer);
printf(" ** IN pwm_set_frequency: s = %d, len = %d\n", s, len); printf(" ** IN pwm_set_frequency: s = %d, len = %d\n", s, len);
}
if (s != len) { if (s != len) {
rtnval = -1; rtnval = -1;
} else { } else {
@ -193,8 +190,6 @@ int pwm_set_polarity(const char *key, int polarity) {
} }
if (pwm->enable) { if (pwm->enable) {
if (DEBUG)
printf(" ** IN pwm_set_polarity: pwm_initialized = %d\n", pwm_initialized);
if (polarity == 0) { if (polarity == 0) {
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer); len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
} }
@ -202,11 +197,12 @@ int pwm_set_polarity(const char *key, int polarity) {
{ {
len = snprintf(buffer, sizeof(buffer), "%s", "inverted"); BUF2SMALL(buffer); len = snprintf(buffer, sizeof(buffer), "%s", "inverted"); BUF2SMALL(buffer);
} }
if (DEBUG)
printf(" ** pwm_set_poliarity: buffer: %s\n", buffer);
ssize_t s = write(pwm->polarity_fd, buffer, len); //ASSRT(s == len); ssize_t s = write(pwm->polarity_fd, buffer, len); //ASSRT(s == len);
if (DEBUG) if (DEBUG) {
printf(" ** IN pwm_set_polarity: pwm_initialized = %d\n", pwm_initialized);
printf(" ** pwm_set_poliarity: buffer: %s\n", buffer);
printf(" ** IN pwm_set_polarity: s = %d, len = %d\n", s, len); printf(" ** IN pwm_set_polarity: s = %d, len = %d\n", s, len);
}
if (s != len) { if (s != len) {
rtnval = -1; rtnval = -1;
} else { } else {
@ -237,14 +233,13 @@ int pwm_set_duty_cycle(const char *key, float duty) {
pwm->duty = (unsigned long)(pwm->period_ns * (duty / 100.0)); pwm->duty = (unsigned long)(pwm->period_ns * (duty / 100.0));
if (pwm->enable) { if (pwm->enable) {
if (DEBUG)
printf(" ** IN pwm_set_duty_cycle: pwm_initialized = %d\n", pwm_initialized);
len = snprintf(buffer, sizeof(buffer), "%lu", pwm->duty); BUF2SMALL(buffer); len = snprintf(buffer, sizeof(buffer), "%lu", pwm->duty); BUF2SMALL(buffer);
if (DEBUG)
printf(" ** pwm_set_duty_cycle: buffer: %s\n", buffer);
ssize_t s = write(pwm->duty_fd, buffer, len); //ASSRT(s == len); ssize_t s = write(pwm->duty_fd, buffer, len); //ASSRT(s == len);
if (DEBUG) if (DEBUG) {
printf(" ** IN pwm_set_duty_cycle: pwm_initialized = %d\n", pwm_initialized);
printf(" ** pwm_set_duty_cycle: buffer: %s\n", buffer);
printf(" ** IN pwm_set_duty_cycle: s = %d, len = %d\n", s, len); printf(" ** IN pwm_set_duty_cycle: s = %d, len = %d\n", s, len);
}
if (s != len) { if (s != len) {
rtnval = -1; rtnval = -1;
} else { } else {
@ -336,7 +331,7 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
printf(" ** IN pwm_start: enable_path: %s\n", enable_path); printf(" ** IN pwm_start: enable_path: %s\n", enable_path);
printf(" ** IN pwm_start: period_path: %s\n", period_path); printf(" ** IN pwm_start: period_path: %s\n", period_path);
printf(" ** IN pwm_start: duty_path: %s\n", duty_path); printf(" ** IN pwm_start: duty_path: %s\n", duty_path);
printf(" **IN pwm_start: polarity_path: %s\n", polarity_path); printf(" ** IN pwm_start: polarity_path: %s\n", polarity_path);
} }
//add period and duty fd to pwm list //add period and duty fd to pwm list
@ -393,13 +388,17 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
int rtnval = 0; int rtnval = 0;
rtnval = pwm_set_enable(key, ENABLE); rtnval = pwm_set_enable(key, ENABLE);
// Fix for issue #53
if (rtnval != -1) {
rtnval = 0; rtnval = 0;
rtnval = pwm_set_frequency(key, freq); rtnval = pwm_set_frequency(key, freq);
if (rtnval != -1) {
rtnval = 0; rtnval = 0;
//rtnval = pwm_set_polarity(key, polarity); //rtnval = pwm_set_polarity(key, polarity);
//rtnval = 0; //rtnval = 0;
rtnval = pwm_set_duty_cycle(key, duty); rtnval = pwm_set_duty_cycle(key, duty);
}
}
return rtnval; return rtnval;
} }
@ -433,6 +432,9 @@ int pwm_disable(const char *key)
{ {
if (strcmp(pwm->key, key) == 0) if (strcmp(pwm->key, key) == 0)
{ {
if (DEBUG) {
printf(" ** IN pwm_disable: unexporting %s\n", key);
}
//close the fd //close the fd
close(pwm->enable_fd); close(pwm->enable_fd);
close(pwm->period_fd); close(pwm->period_fd);
@ -464,11 +466,3 @@ void pwm_cleanup(void)
} }
} }
void pwm_toggle_debug(void)
{
if (DEBUG) {
DEBUG = 0;
} else {
DEBUG = 1;
}
}

View File

@ -35,4 +35,4 @@ int pwm_set_frequency(const char *key, float freq);
int pwm_set_duty_cycle(const char *key, float duty); int pwm_set_duty_cycle(const char *key, float duty);
int pwm_set_enable(const char *key, int enable); int pwm_set_enable(const char *key, int enable);
void pwm_cleanup(void); void pwm_cleanup(void);
void pwm_toggle_debug(void); //void pwm_toggle_debug(void);

View File

@ -49,6 +49,9 @@ SOFTWARE.
int setup_error = 0; int setup_error = 0;
int module_setup = 0; int module_setup = 0;
// Library Debug
int DEBUG = 0;
pins_t pins_info[] = { pins_t pins_info[] = {
{ "GND", "GND", "U13_1", -1, BASE_METHOD_AS_IS, -1, -1, SPWM_DISABLED}, { "GND", "GND", "U13_1", -1, BASE_METHOD_AS_IS, -1, -1, SPWM_DISABLED},
{ "CHG-IN", "CHG-IN", "U13_2", -1, BASE_METHOD_AS_IS, -1, -1, SPWM_DISABLED}, { "CHG-IN", "CHG-IN", "U13_2", -1, BASE_METHOD_AS_IS, -1, -1, SPWM_DISABLED},
@ -214,6 +217,14 @@ int get_xio_base(void)
return xio_base_address; return xio_base_address;
} /* get_xio_base */ } /* get_xio_base */
void toggle_debug(void)
{
if (DEBUG) {
DEBUG = 0;
} else {
DEBUG = 1;
}
}
int gpio_number(pins_t *pin) int gpio_number(pins_t *pin)
{ {
@ -351,12 +362,16 @@ int get_pwm_key_by_name(const char *name, char *key)
pins_t *p; pins_t *p;
for (p = pins_info; p->name != NULL; ++p) { for (p = pins_info; p->name != NULL; ++p) {
if (strcmp(p->name, name) == 0) { if (strcmp(p->name, name) == 0) {
printf("## FOUND PWM KEY, VALIDATING MUX MODE ##\n"); if (DEBUG) {
printf(" ** get_pwm_key_by_name: FOUND PWM KEY, VALIDATING MUX MODE **\n");
}
//validate it's a valid pwm pin //validate it's a valid pwm pin
if (p->pwm_mux_mode == -1) if (p->pwm_mux_mode == -1)
return 0; return 0;
printf("## PWM KEY IS VALID ##\n"); if (DEBUG) {
printf(" ** get_pwm_key_by_name: PWM KEY IS VALID ##\n");
}
strncpy(key, p->key, 7); strncpy(key, p->key, 7);
key[7] = '\0'; key[7] = '\0';
return 1; return 1;

View File

@ -86,6 +86,7 @@ typedef struct dyn_int_array_s dyn_int_array_t;
int setup_error; int setup_error;
int module_setup; int module_setup;
int DEBUG;
int get_xio_base(void); int get_xio_base(void);
int gpio_number(pins_t *pin); int gpio_number(pins_t *pin);
@ -110,3 +111,4 @@ void dyn_int_array_delete(dyn_int_array_t **in_array);
void clear_error_msg(void); void clear_error_msg(void);
char *get_error_msg(void); char *get_error_msg(void);
void add_error_msg(char *msg); void add_error_msg(char *msg);
void toggle_debug(void);

View File

@ -85,6 +85,6 @@ void define_constants(PyObject *module)
bcm = Py_BuildValue("i", BCM); bcm = Py_BuildValue("i", BCM);
PyModule_AddObject(module, "BCM", bcm); PyModule_AddObject(module, "BCM", bcm);
version = Py_BuildValue("s", "0.3.1"); version = Py_BuildValue("s", "0.3.2");
PyModule_AddObject(module, "VERSION", version); PyModule_AddObject(module, "VERSION", version);
} }

View File

@ -47,7 +47,7 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args)
static PyObject *py_toggle_debug(PyObject *self, PyObject *args) static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
{ {
// toggle debug printing // toggle debug printing
pwm_toggle_debug(); toggle_debug();
Py_RETURN_NONE; Py_RETURN_NONE;
} }