Hi, about extending python with C and SWIG

Cesar Lopez clopez at abo.fi
Tue Mar 14 06:38:31 EST 2000


I need to run call a C function from a Python program, so now I´m using
SWIG to get the wrap file and build this interface. Here is my header,
code and interface files:

//led.h

int Setup(int state); // state = 1 --> ON ; state = 0 --> OFF
int _state;
// Defining communication with the device, Port, Adress, configuration
registers and so  on ...

#define PBIOR (*(volatile short int *) (0x5ffffc6))
#define PBCR1 (*(volatile short int *) (0x5ffffcc))
#define PBCR2 (*(volatile short int *) (0x5ffffce))
#define PBDR (*(volatile short int *) (0x5ffffc2))

//led.c
#include "led.h"

int
Setup(int state)
{
PBIOR |= 0x8000;      // Set the bit for output
PBCR1 &= ~0xc000;     // Make it a normal I/0

        switch (state){
            case 1:{
              PBDR |= 0x8000; // Set the LED on
             _state=1; // to read the state of the led
                return 0;
                }
            case 0:{
              PBDR &= 0x0000; // Set the LED off
                            _state=0;
                return 0;
                }
            default: return -1;  // Error: Invalid code
            } //switch
}


//led.i
%module led
%{
#include "led.h"
%}
extern int Setup(int state);
extern int _state;


IT IS CORRECT THIS INTERFACE FILE? Or How can I do to wrap my "#define
...." includes in led.h


Thanks.

    Cesar Lopez






More information about the Python-list mailing list