uint8_t RTC_DS1307_SS::isrunning(void) { Wire.beginTransmission(DS1307_ADDRESS); Wire.write(i); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 1); uint8_t ss = Wire.read(); return !(ss>>7); }
void RTC_DS1307_SS::adjust(const DateTime& dt) { Wire.beginTransmission(DS1307_ADDRESS); Wire.write(i); Wire.write(bin2bcd(dt.second())); Wire.write(bin2bcd(dt.minute())); Wire.write(bin2bcd(dt.hour())); Wire.write(bin2bcd(0)); Wire.write(bin2bcd(dt.day())); Wire.write(bin2bcd(dt.month())); Wire.write(bin2bcd(dt.year() - 2000)); Wire.write(i); Wire.endTransmission(); }
void Adafruit_SSD1306::display(void) { ssd1306_command(SSD1306_COLUMNADDR); ssd1306_command(0); // Column start address (0 = reset) ssd1306_command(127); // Column end address (127 = reset) ssd1306_command(SSD1306_PAGEADDR); ssd1306_command(0); // Page start address (0 = reset) ssd1306_command((SSD1306_LCDHEIGHT == 64) ? 7 : 3); // Page end address if (sid != -1) { // SPI *csport |= cspinmask; *dcport |= dcpinmask; *csport &= ~cspinmask; for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { fastSPIwrite(buffer[i]); //ssd1306_data(buffer[i]); } *csport |= cspinmask; } else { // save I2C bitrate #ifdef __AVR__ uint8_t twbrbackup = TWBR; TWBR = 12; // upgrade to 400KHz! #endif //Serial.println(TWBR, DEC); //Serial.println(TWSR & 0x3, DEC); // I2C for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { // send a bunch of data in one xmission Wire.beginTransmission(_i2caddr); Wire.write(0x40); for (uint8_t x=0; x<16; x++) { Wire.write(buffer[i]); i++; } i--; Wire.endTransmission(); } #ifdef __AVR__ TWBR = twbrbackup; #endif } }
DateTime RTC_DS1307_SS::now() { Wire.beginTransmission(DS1307_ADDRESS); Wire.write(i); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 7); uint8_t ss = bcd2bin(Wire.read() & 0x7F); uint8_t mm = bcd2bin(Wire.read()); uint8_t hh = bcd2bin(Wire.read()); Wire.read(); uint8_t d = bcd2bin(Wire.read()); uint8_t m = bcd2bin(Wire.read()); uint16_t y = bcd2bin(Wire.read()) + 2000; return DateTime (y, m, d, hh, mm, ss); }
void Adafruit_SSD1306::ssd1306_data(uint8_t c) { if (sid != -1) { // SPI //digitalWrite(cs, HIGH); *csport |= cspinmask; //digitalWrite(dc, HIGH); *dcport |= dcpinmask; //digitalWrite(cs, LOW); *csport &= ~cspinmask; fastSPIwrite(c); //digitalWrite(cs, HIGH); *csport |= cspinmask; } else { // I2C uint8_t control = 0x40; // Co = 0, D/C = 1 Wire.beginTransmission(_i2caddr); Wire.write(control); Wire.write(c); Wire.endTransmission(); } }
void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr) { _vccstate = vccstate; _i2caddr = i2caddr; // set pin directions if (sid != -1){ pinMode(dc, OUTPUT); pinMode(cs, OUTPUT); csport = portOutputRegister(digitalPinToPort(cs)); cspinmask = digitalPinToBitMask(cs); dcport = portOutputRegister(digitalPinToPort(dc)); dcpinmask = digitalPinToBitMask(dc); if (!hwSPI){ // set pins for software-SPI pinMode(sid, OUTPUT); pinMode(sclk, OUTPUT); clkport = portOutputRegister(digitalPinToPort(sclk)); clkpinmask = digitalPinToBitMask(sclk); mosiport = portOutputRegister(digitalPinToPort(sid)); mosipinmask = digitalPinToBitMask(sid); } if (hwSPI){ // SPI.begin (); #ifdef __SAM3X8E__ SPI.setClockDivider (9); // 9.3 MHz #else SPI.setClockDivider (SPI_CLOCK_DIV2); // 8 MHz #endif } } else { // I2C Init if(hwI2C) { Wire.begin(); #ifdef __SAM3X8E__ // Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL) TWI1->TWI_CWGR = 0; TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101; #endif } if(!hwI2C) { Wire.config(sda, sclk); Wire.setClock(i2c_hz); Wire.begin(); } } // Setup reset pin direction (used by both SPI and I2C) pinMode(rst, OUTPUT); digitalWrite(rst, HIGH); // VDD (3.3V) goes high at start, lets just chill for a ms delay(1); // bring reset low digitalWrite(rst, LOW); // wait 10ms delay(10); // bring out of reset digitalWrite(rst, HIGH); // turn on VCC (9V?) #if defined SSD1306_128_32 // Init sequence for 128x32 OLED module ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 ssd1306_command(0x80); // the suggested ratio 0x80 ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 ssd1306_command(0x1F); ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 ssd1306_command(0x0); // no offset ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D if (vccstate == SSD1306_EXTERNALVCC) { ssd1306_command(0x10); } else { ssd1306_command(0x14); } ssd1306_command(SSD1306_MEMORYMODE); // 0x20 ssd1306_command(0x00); // 0x0 act like ks0108 ssd1306_command(SSD1306_SEGREMAP | 0x1); ssd1306_command(SSD1306_COMSCANDEC); ssd1306_command(SSD1306_SETCOMPINS); // 0xDA ssd1306_command(0x02); ssd1306_command(SSD1306_SETCONTRAST); // 0x81 ssd1306_command(0x8F); ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 if (vccstate == SSD1306_EXTERNALVCC) { ssd1306_command(0x22); } else { ssd1306_command(0xF1); } ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB ssd1306_command(0x40); ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 #endif #if defined SSD1306_128_64 // Init sequence for 128x64 OLED module ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 ssd1306_command(0x80); // the suggested ratio 0x80 ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 ssd1306_command(0x3F); ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 ssd1306_command(0x0); // no offset ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D if (vccstate == SSD1306_EXTERNALVCC) { ssd1306_command(0x10); } else { ssd1306_command(0x14); } ssd1306_command(SSD1306_MEMORYMODE); // 0x20 ssd1306_command(0x00); // 0x0 act like ks0108 ssd1306_command(SSD1306_SEGREMAP | 0x1); ssd1306_command(SSD1306_COMSCANDEC); ssd1306_command(SSD1306_SETCOMPINS); // 0xDA ssd1306_command(0x12); ssd1306_command(SSD1306_SETCONTRAST); // 0x81 if (vccstate == SSD1306_EXTERNALVCC) { ssd1306_command(0x9F); } else { ssd1306_command(0xCF); } ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 if (vccstate == SSD1306_EXTERNALVCC) { ssd1306_command(0x22); } else { ssd1306_command(0xF1); } ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB ssd1306_command(0x40); ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 #endif ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel }