int htu21dSetup (const int pinBase) { int fd ; struct wiringPiNodeStruct *node ; uint8_t data ; int status ; if ((fd = wiringPiI2CSetup (I2C_ADDRESS)) < 0) return FALSE ; node = wiringPiNewNode (pinBase, 2) ; node->fd = fd ; node->analogRead = myAnalogRead ; // Send a reset code to it: data = 0xFE ; if (write (fd, &data, 1) != 1) return FALSE ; delay (15) ; // Read the status register to check it's really there status = wiringPiI2CReadReg8 (fd, 0xE7) ; return (status == 0x02) ? TRUE : FALSE ; }
int ds18b20Setup (const int pinBase, const char *deviceId) { int fd ; struct wiringPiNodeStruct *node ; char *fileName ; // Allocate space for the filename if ((fileName = malloc (strlen (W1_PREFIX) + strlen (W1_POSTFIX) + strlen (deviceId) + 1)) == NULL) return FALSE ; sprintf (fileName, "%s%s%s", W1_PREFIX, deviceId, W1_POSTFIX) ; fd = open (fileName, O_RDONLY) ; free (fileName) ; if (fd < 0) return FALSE ; // We'll keep the file open, to make access a little faster // although it's very slow reading these things anyway )-: node = wiringPiNewNode (pinBase, 1) ; node->fd = fd ; node->analogRead = myAnalogRead ; return TRUE ; }
int drcSetup (const int pinBase, const int numPins, const char *device) { int fd ; int ok, tries ; time_t then ; struct wiringPiNodeStruct *node ; if ((fd = serialOpen (device, 115200)) < 0) return wiringPiFailure (WPI_ALMOST, "Unable to open DRC device (%s): %s", device, strerror (errno)) ; delay (10) ; // May need longer if it's an Uno that reboots on the open... // Flush any pending input while (serialDataAvail (fd)) (void)serialGetchar (fd) ; ok = FALSE ; for (tries = 1 ; tries < 5 ; ++tries) { serialPutchar (fd, '@') ; then = time (NULL) + 2 ; while (time (NULL) < then) if (serialDataAvail (fd)) { if (serialGetchar (fd) == '@') { ok = TRUE ; break ; } } if (ok) break ; } if (!ok) { serialClose (fd) ; return wiringPiFailure (WPI_FATAL, "Unable to communidate with DRC device") ; } node = wiringPiNewNode (pinBase, numPins) ; node->fd = fd ; node->pinMode = myPinMode ; node->pullUpDnControl = myPullUpDnControl ; node->analogRead = myAnalogRead ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->pwmWrite = myPwmWrite ; return 0 ; }
int max31855Setup (const int pinBase, int spiChannel) { struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi return -1 ; node = wiringPiNewNode (pinBase, 4) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; return 0 ; }
int mcp3004Setup (const int pinBase, int spiChannel) { struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 1000000) < 0) return -1 ; node = wiringPiNewNode (pinBase, 8) ; node->fd = spiChannel ; node->analogRead = myAnalogRead ; return 0 ; }
int mcp4802Setup (const int pinBase, int spiChannel) { struct wiringPiNodeStruct *node ; if (wiringPiSPISetup (spiChannel, 1000000) < 0) return FALSE ; node = wiringPiNewNode (pinBase, 2) ; node->fd = spiChannel ; node->analogWrite = myAnalogWrite ; return TRUE ; }
int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return fd ; node = wiringPiNewNode (pinBase, 4) ; node->data0 = sampleRate ; node->data1 = gain ; node->analogRead = myAnalogRead ; return 0 ; }
int pcf8591Setup (const int pinBase, const int i2cAddress) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return fd ; node = wiringPiNewNode (pinBase, 4) ; node->fd = fd ; node->analogRead = myAnalogRead ; node->analogWrite = myAnalogWrite ; return 0 ; }
/* wiringPiNewNode * * Parameters: * - pinBase: int * - numPins: int * Return Type: struct wiringPiNodeStruct * */ mrb_value mrb_Pi_wiringPiNewNode(mrb_state* mrb, mrb_value self) { mrb_int native_pinBase; mrb_int native_numPins; /* Fetch the args */ mrb_get_args(mrb, "ii", &native_pinBase, &native_numPins); /* Invocation */ struct wiringPiNodeStruct * result = wiringPiNewNode(native_pinBase, native_numPins); /* Box the return value */ mrb_value return_value = (result == NULL ? mrb_nil_value() : mruby_box_wiringPiNodeStruct(mrb, result)); return return_value; }
int pcf8574Setup (const int pinBase, const int i2cAddress) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return fd ; node = wiringPiNewNode (pinBase, 8) ; node->fd = fd ; node->pinMode = myPinMode ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CRead (fd) ; return 0 ; }
int ads1115Setup (const int pinBase, int i2cAddr) { struct wiringPiNodeStruct *node ; int fd ; if ((fd = wiringPiI2CSetup (i2cAddr)) < 0) return FALSE ; node = wiringPiNewNode (pinBase, 8) ; node->fd = fd ; node->data0 = CONFIG_PGA_4_096V ; // Gain in data0 node->data1 = CONFIG_DR_128SPS ; // Samples/sec in data1 node->analogRead = myAnalogRead ; node->analogWrite = myAnalogWrite ; node->digitalWrite = myDigitalWrite ; return TRUE ; }
int mcp23008Setup (const int pinBase, const int i2cAddress) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return FALSE ; wiringPiI2CWriteReg8 (fd, MCP23x08_IOCON, IOCON_INIT) ; node = wiringPiNewNode (pinBase, 8) ; node->fd = fd ; node->pinMode = myPinMode ; node->pullUpDnControl = myPullUpDnControl ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CReadReg8 (fd, MCP23x08_OLAT) ; return TRUE ; }
int piFaceSetup (const int pinBase) { int x ; struct wiringPiNodeStruct *node ; if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0) return x ; // Setup the MCP23S17 writeByte (MCP23x17_IOCON, IOCON_INIT) ; writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs node = wiringPiNewNode (pinBase, 16) ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->pullUpDnControl = myPullUpDnControl ; return 0 ; }
int mcp23017Setup (const int pinBase, const int i2cAddress) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) return fd ; wiringPiI2CWriteReg8 (fd, MCP23x17_IOCON, IOCON_INIT) ; node = wiringPiNewNode (pinBase, 16) ; node->fd = fd ; node->pinMode = myPinMode ; node->pullUpDnControl = myPullUpDnControl ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->data2 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATA) ; node->data3 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATB) ; return 0 ; }
/** * initialize the Max7311 * @param portDirection1 default values of ports 0-7 (1 - input; 0 - output) * @param portDirection2 default values of ports 8-15 (1 - input; 0 - output) * @param timeoutFlag 1 enable Bus timeout, 0 disable Bus timeout */ void Max7312::init(unsigned char portDirection1, unsigned char portDirection2, unsigned char timeoutFlag) { initDataBuffers(); if ((fd = wiringPiI2CSetup (_chipAddress)) < 0) return; node = wiringPiNewNode (_pinBase, MAX7312_NUM_OF_PORTS) ; node->fd = fd ; node->pinMode = _configPortMax7312; node->digitalRead = _readPortMax7312; node->digitalWrite = _writePortMax7312; node->data1 = readPort1 () ; node->data2 = readPort2 () ; node->thisNode = this; configPort1(portDirection1); configPort2(portDirection2); configTimeout(timeoutFlag); }
int sn3218Setup (const int pinBase) { int fd ; struct wiringPiNodeStruct *node ; if ((fd = wiringPiI2CSetup (0x54)) < 0) return fd ; // Setup the chip - initialise all 18 LEDs to off //wiringPiI2CWriteReg8 (fd, 0x17, 0) ; // Reset wiringPiI2CWriteReg8 (fd, 0x00, 1) ; // Not Shutdown wiringPiI2CWriteReg8 (fd, 0x13, 0x3F) ; // Enable LEDs 0- 5 wiringPiI2CWriteReg8 (fd, 0x14, 0x3F) ; // Enable LEDs 6-11 wiringPiI2CWriteReg8 (fd, 0x15, 0x3F) ; // Enable LEDs 12-17 wiringPiI2CWriteReg8 (fd, 0x16, 0x00) ; // Update node = wiringPiNewNode (pinBase, 18) ; node->fd = fd ; node->analogWrite = myAnalogWrite ; return 0 ; }
int piFaceSetup (const int pinBase) { int i ; struct wiringPiNodeStruct *node ; // Create an mcp23s17 instance: mcp23s17Setup (pinBase + 16, 0, 0) ; // Set the direction bits for (i = 0 ; i < 8 ; ++i) { pinMode (pinBase + 16 + i, OUTPUT) ; // Port A is the outputs pinMode (pinBase + 16 + 8 + i, INPUT) ; // Port B inputs. } node = wiringPiNewNode (pinBase, 16) ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->pullUpDnControl = myPullUpDnControl ; return 0 ; }
int mcp23s17Setup (const int pinBase, const int spiPort, const int devId) { int x ; struct wiringPiNodeStruct *node ; if ((x = wiringPiSPISetup (spiPort, MCP_SPEED)) < 0) return x ; writeByte (spiPort, devId, MCP23x17_IOCON, IOCON_INIT | IOCON_HAEN) ; writeByte (spiPort, devId, MCP23x17_IOCONB, IOCON_INIT | IOCON_HAEN) ; node = wiringPiNewNode (pinBase, 16) ; node->data0 = spiPort ; node->data1 = devId ; node->pinMode = myPinMode ; node->pullUpDnControl = myPullUpDnControl ; node->digitalRead = myDigitalRead ; node->digitalWrite = myDigitalWrite ; node->data2 = readByte (spiPort, devId, MCP23x17_OLATA) ; node->data3 = readByte (spiPort, devId, MCP23x17_OLATB) ; return 0 ; }