static int doChip(const sensors_chip_name *chip, int action) { int ret = 0; if (action == DO_SET) { ret = setChip(chip); } else { int index0, chipindex = -1; for (index0 = 0; knownChips[index0].features; ++index0) { /* * Trick: we compare addresses here. We know it works * because both pointers were returned by * sensors_get_detected_chips(), so they refer to * libsensors internal structures, which do not move. */ if (knownChips[index0].name == chip) { chipindex = index0; break; } } if (chipindex >= 0) { ret = doKnownChip(chip, &knownChips[chipindex], action); } } return ret; }
//1/2 chip with software SPI GPIO (3 wire) LiquidCrystalNew_SSPI::LiquidCrystalNew_SSPI(const byte mosiPin,const byte clockPin,const byte csPin,const byte chip,const byte adrs){ if (chip == 0 || chip == 255){ _en2 = 255; _multipleChip = 0; } else { _en2 = (1 << LCDPIN_EN2); _multipleChip = 1; } _cs = csPin; _clk = clockPin; _mosi = mosiPin; _en1 = (1 << LCDPIN_EN); _adrs = adrs; _scroll_count = 0; //to fix the bug if we scroll and then setCursor w/o home() or clear() _x = 0; _y = 0; _setCursFlag = 0; _direction = LCD_Right; setChip(0); #if defined(BACKGND_LGHTINV) _backLight = 0; #else _backLight = 1; #endif //settings the offsets _row_offsets[0] = 00; // DDRAM addresses inside the HD44780 are strange: 0-nColumns-1 on line 0 _row_offsets[1] = 0x40; // 64-(63+nColumns) for line 1 _row_offsets[2] = 0x14; // 20- (19+nColumns) for line 2 --- NOTHING FROM 40-63 ! _row_offsets[3] = 0x54; // 84 - (83+nColumns) for line 3 -- so 80 characters tops out at #103 ! _theData = 0b00000000;// main data of the GPIO DATA PORT, better start with all 0,s }
Chip::Chip(int chipID) { //set defaults in case invalid ID was given name = "N/A"; damage = 0; ID = 0; chipClass = "N/A"; setChip(chipID); }
void LiquidCrystalNew_SSPI::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { pinMode(_cs,OUTPUT); pinMode(_clk,OUTPUT); pinMode(_mosi,OUTPUT); #if defined(__FASTSWRITE2__) BLOCK_IRQS(); sclkport = digitalPinToPort(_clk); sclkpin = digitalPinToBitMask(_clk); mosiport = digitalPinToPort(_mosi); mosipin = digitalPinToBitMask(_mosi); csport = digitalPinToPort(_cs); cspin = digitalPinToBitMask(_cs); *portOutputRegister(csport) |= cspin;//hi ENABLE_IRQS(); #else digitalWrite(_cs, HIGH); #endif // ---- now prepare GPIO chip and initialize it if (_adrs > 0 && _adrs < 255){ writeByte(0x05,0b00101000);//HAEN -> ON (IOCON) } else { writeByte(0x05,0b00100000);//use dedicated CS pin (not shared) _adrs = 0x20;//default chip adrs when not using HAEN } writeByte(0x00,0x00);//first, set all GPIO's pin as outs (IODIR) writeByte(0x09,0b00000000);//finally, set all GPIO's out as LOW _lcd_cols = cols; //there is an implied lack of trust; the private version can't be munged up by the user. _lcd_lines = lines; _row_offsets[2] = _lcd_cols + _row_offsets[0]; //should auto-adjust for 16/20 or whatever columns now _row_offsets[3] = _lcd_cols + _row_offsets[1]; initChip(dotsize,_en1); //manage second chip if exists if (_multipleChip) { _row_offsets[2] = 0; _row_offsets[3] = 0x40; //each line gets its own little 40 char section of DDRAM--would be fine if there were a 4x32, I suppose setChip(2); initChip(dotsize,_en2);//initialize the second HD44780 chip } }
void LiquidCrystalNew_T3TWI::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { #if defined(__TEENSY3X__) const i2c_pins temp3[2] = {I2C_PINS_18_19,I2C_PINS_16_17}; const i2c_pullup temp4[2] = {I2C_PULLUP_EXT,I2C_PULLUP_INT}; const i2c_rate temp5[11] = {I2C_RATE_100,I2C_RATE_200,I2C_RATE_300,I2C_RATE_400,I2C_RATE_600,I2C_RATE_800,I2C_RATE_1000,I2C_RATE_1200,I2C_RATE_1500,I2C_RATE_2000,I2C_RATE_2400}; Wire.begin(I2C_MASTER,0x00,temp3[_pins],temp4[_pullup],temp5[_rate]); #else #if !defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific Wire.begin(); #if ARDUINO >= 157 Wire.setClock(400000UL); // Set I2C frequency to 400kHz #else TWBR = ((F_CPU / 400000UL) - 16) / 2; // Set I2C frequency to 400kHz //TWBR = 12; #endif #else Wire.setModule(3); Wire.begin(); #endif #endif delay(100); if (!_chipType) writeByte(0x05,0b00100000);//use dedicated cs //MCP23008 writeByte(0x00,0x00);//set as out (IODIR) writeByte(0x09,0b00000000);//write all low to GPIO _lcd_cols = cols; //there is an implied lack of trust; the private version can't be munged up by the user. _lcd_lines = lines; _row_offsets[2] = _lcd_cols + _row_offsets[0]; //should autoadjust for 16/20 or whatever columns now _row_offsets[3] = _lcd_cols + _row_offsets[1]; initChip(dotsize,_en1); //manage second chip if exists if (_multipleChip) { _row_offsets[2] = 0; _row_offsets[3] = 0x40; //each line gets its own little 40 char section of DDRAM--would be fine if there were a 4x32, I suppose setChip(2); initChip(dotsize,_en2);//initialize the second HD44780 chip } }
//1/2 chip with software SPI GPIO (3 wire) LiquidCrystalNew_T3TWI::LiquidCrystalNew_T3TWI(const byte adrs,byte pins,byte pullup,byte rate,const byte chip,const byte chipType){ if (pins > 1) pins = 0; if (pullup > 1) pullup = 0; if (rate > 10) rate = 0; _pins = pins; _pullup = pullup; _rate = rate; if (chip == 0 || chip == 255){ _en2 = 255; _multipleChip = 0; } else { _en2 = (1 << LCDPIN_EN2); _multipleChip = 1; } _en1 = (1 << LCDPIN_EN); _adrs = adrs; _chipType = chipType; if ((chipType == PCF8574A) && (adrs < 0x38)) _adrs = 0x38; _scroll_count = 0; //to fix the bug if we scroll and then setCursor w/o home() or clear() _x = 0; _y = 0; _setCursFlag = 0; _direction = LCD_Right; setChip(0); #ifdef BACKGND_LGHTINV _backLight = 0; #else _backLight = 1; #endif //settings the offsets _row_offsets[0] = 00; // DDRAM addresses inside the HD44780 are strange: 0-nColumns-1 on line 0 _row_offsets[1] = 0x40; // 64-(63+nColumns) for line 1 _row_offsets[2] = 0x14; // 20- (19+nColumns) for line 2 --- NOTHING FROM 40-63 ! _row_offsets[3] = 0x54; // 84 - (83+nColumns) for line 3 -- so 80 characters tops out at #103 ! _theData = 0b00000000;// main data of the GPIO DATA PORT, better start with all 0,s }
void Chip::setRandom() { setChip(rand()%306+1); }