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

Some (not all) of the changes for the new XIO base addr

This commit is contained in:
fordsfords
2016-06-21 17:40:00 -05:00
parent 0f89ae462c
commit 34167a9574
3 changed files with 142 additions and 121 deletions

View File

@ -36,6 +36,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "stdlib.h"
#include "Python.h"
#include "constants.h"
#include "common.h"
@ -43,6 +44,9 @@ SOFTWARE.
static int gpio_warnings = 1;
int max_gpio = -1;
int *gpio_direction = NULL;
struct py_callback
{
char channel[32];
@ -58,7 +62,9 @@ static int init_module(void)
{
int i;
for (i=0; i<430; i++)
max_gpio = 1024;
gpio_direction = (int *)malloc(max_gpio * sizeof(int));
for (i=0; i<max_gpio; i++)
gpio_direction[i] = -1;
module_setup = 1;
@ -66,6 +72,16 @@ static int init_module(void)
return 0;
}
static void set_gpio_direction(int gpio, int direction)
{
if (gpio >= max_gpio) { /* Does gpio_direction need to be expanded? */
max_gpio = gpio + (gpio / 2);
gpio_direction = (int *)realloc(gpio_direction, max_gpio * sizeof(int));
}
gpio_direction[gpio] = direction;
}
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
@ -121,7 +137,7 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
}
}
gpio_direction[gpio] = direction;
set_gpio_direction(gpio, direction);
Py_RETURN_NONE;
}