Go Down

Topic: Firmata and Mystery Arduino directives (Read 1 time) previous topic - next topic


We are trying to improve the Simulator for Arduino program and while it is mostly going well, there are some unknown language structures which are proving difficult.

The first is IO_REG_TYPE which is found in the <OneWire.h> library. We searched the Playground for this but there was no mention.

The Firmata library has some unknown commands such as IS_PIN_DIGITAL() and PIN_TO_DIGITAL():

Code: [Select]

void setup()
  byte i, port, status;

  Firmata.setFirmwareVersion(0, 1);

  for(pin = 0; pin < TOTAL_PINS; pin++) {
    if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);

  for (port=0; port<TOTAL_PORTS; port++) {
    status = 0;
    for (i=0; i<8; i++) {
      if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
    portStatus[port] = status;

Any help would be much appreciated.




Look in Boards.h in the Firmata library directory.

Code: [Select]
#define IS_PIN_DIGITAL(p)       ((p) >= 2 && (p) <= 19)
#define IS_PIN_ANALOG(p)        ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
#define IS_PIN_PWM(p)           digitalPinHasPWM(p)
#define IS_PIN_SERVO(p)         (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p)           ((p) == 18 || (p) == 19)
#define PIN_TO_DIGITAL(p)       (p)
#define PIN_TO_ANALOG(p)        ((p) - 14)
#define PIN_TO_PWM(p)           PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p)         ((p) - 2)


Cool, Thanks - We only looked in the Firmata.h file. Any ideas about the IO_REG_TYPE ?

Btw, Google just alerted about this link


In OneWire.h:
Code: [Select]
// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__PIC32MX__)
#include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#error "Please define I/O register types here"

Come on guys, that really wasn't hard to find.

Go Up