IOPIN (JSAPI_IOPIN) ABSTRACTION

JSAPI_IOPIN encapsulates the concept of a single I/O pin. There is no predefined object of this type, as you must define one and then initialize it with the MakeIOPin call, for example:

extern JSAPI_GPIO porta;

JSAPI_IOPIN led1;

led1.Make(&porta, 5);

 

JSAPI_IOPIN is useful for creating variables that represent a hardware feature, e.g. an LED, that is controlled by a single I/O pin.

The SysTick timer is used for the “Jiggle” functions, so it must be set up to accommodate the time delay resolution.

Make an IOPin. Must have initialized the JSAPI_GPIO object and pin prior to calling this.

void MakeIOPin(

    JSAPI_GPIO *gpio,

    unsigned pin_no

);

Read the value of an input pin

unsigned Read(void);

Write a value to an output pin

void Write(bool state);

Set (write a “1”) to an output pin

void Set(void);

Clear (write a “0”) to an output pin

void Clear(void);

Toggle the value of an output pin

void Toggle(void);

Is the pin set?

bool isSet(void);

Is the pin clear?

bool isClear(void);

Assuming the current pin out is high/1, write a "0" to an output pin

void JiggleLow(unsigned millisecs_delay);

Assuming the current pin out is low/0, write a "1" to an output pin

void JiggleHigh(unsigned millisecs_delay);

 

How to Use

To use the JumpStart IOPIN API:

1.       Define a JSAPI_IOPIN object, e.g.

JSAPI_IOPIN led1;

2.       Initialize the port and pin using one of the JSAPI_GPIO Make… functions. This must be done prior to the next step!

3.       Call the MakeIOPIN method of the JSAPI_IOPIN object to initialize the GPIO port and pin number.

Example

Here is essentially the same example as the one for JSAPI_GPIO, except this uses the JSAPI_IOPIN class.

// blink an LED connected to PORTA.5

porta.MakeOutput(5, OSPEED_LOW);

JSAPI_IOPIN led1;

led1.MakeIOPin(&porta, 5);

while (1)

      {

led1.Set();

      DelayMilliseconds(500);

led1.Clear();

DelayMillisecons(700);

}