Hi, about extending python with C and SWIG

Cesar Lopez clopez at abo.fi
Tue Mar 14 12:38:31 CET 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:


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))

#include "led.h"

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
                return 0;
            default: return -1;  // Error: Invalid code
            } //switch

%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


    Cesar Lopez

More information about the Python-list mailing list