static int doModuleMcp23008 (char *progName, int pinBase, char *params) { int i2c ; // Extract the I2C address: if (*params != ':') { fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ; return FALSE ; } ++params ; if (!isdigit (*params)) { fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ; return FALSE ; } i2c = strtol (params, NULL, 0) ; if ((i2c < 0x03) || (i2c > 0x77)) { fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ; return FALSE ; } mcp23008Setup (pinBase, i2c) ; return TRUE ; }
static int doExtensionMcp23008 (char *progName, int pinBase, char *params) { int i2c ; if ((params = extractInt (progName, params, &i2c)) == NULL) return FALSE ; if ((i2c < 0x01) || (i2c > 0x77)) { verbError ("%s: i2c address (0x%X) out of range", progName, i2c) ; return FALSE ; } mcp23008Setup (pinBase, i2c) ; return TRUE ; }
int init_zyncoder() { int i,j; for (i=0;i<MAX_NUM_ZYNSWITCHES;i++) { zynswitches[i].enabled=0; zynswitches[i].midi_cc=0; } for (i=0;i<MAX_NUM_ZYNCODERS;i++) { zyncoders[i].enabled=0; for (j=0;j<ZYNCODER_TICKS_PER_RETENT;j++) zyncoders[i].dtus[j]=0; } wiringPiSetup(); #ifdef MCP23017_ENCODERS uint8_t reg; mcp23017Setup(MCP23017_BASE_PIN, 0x20); // get the node cooresponding to our mcp23017 so we can do direct writes mcp23017_node = wiringPiFindNode(MCP23017_BASE_PIN); // setup all the pins on the banks as inputs and disable pullups on // the zyncoder input reg = 0xff; wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRA, reg); wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRB, reg); // enable pullups on the unused pins (high two bits on each bank) reg = 0xff; //reg = 0xc0; //reg = 0x60; wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUA, reg); wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUB, reg); // disable polarity inversion reg = 0; wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLA, reg); wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLB, reg); // disable the comparison to DEFVAL register reg = 0; wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONA, reg); wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONB, reg); // configure the interrupt behavior for bank A uint8_t ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCON); bitWrite(ioconf_value, 6, 0); // banks are not mirrored bitWrite(ioconf_value, 2, 0); // interrupt pin is not floating bitWrite(ioconf_value, 1, 1); // interrupt is signaled by high wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCON, ioconf_value); // configure the interrupt behavior for bank B ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCONB); bitWrite(ioconf_value, 6, 0); // banks are not mirrored bitWrite(ioconf_value, 2, 0); // interrupt pin is not floating bitWrite(ioconf_value, 1, 1); // interrupt is signaled by high wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCONB, ioconf_value); // finally, enable the interrupt pins for banks a and b // enable interrupts on all pins reg = 0xff; wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENA, reg); wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENB, reg); // pi ISRs for the 23017 // bank A wiringPiISR(MCP23017_INTA_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[0]); // bank B wiringPiISR(MCP23017_INTB_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[1]); #ifdef DEBUG printf("MCP23017 initialized: INTA %d, INTB %d\n",MCP23017_INTA_PIN,MCP23017_INTB_PIN); #endif #else mcp23008Setup (100, 0x20); init_poll_zynswitches(); #endif return 1; }