void ArduiPi_OLED::sendData(uint8_t c) { // SPI if ( isSPI()) { // SPI // Setup D/C line to high to switch to data mode bcm2835_gpio_write(dc, HIGH); // write value fastSPIwrite(c); } // I2C else { char buff[2] ; // Setup D/C to switch to data mode buff[0] = SSD_Data_Mode; buff[1] = c; // Write on i2c fastI2Cwrite( buff, sizeof(buff)) ; } }
void ArduiPi_OLED::sendCommand(uint8_t c0, uint8_t c1, uint8_t c2) { char buff[4] ; buff[1] = c0; buff[2] = c1; buff[3] = c2; // Is SPI if (isSPI()) { // Setup D/C line to low to switch to command mode bcm2835_gpio_write(dc, LOW); // Write Data fastSPIwrite(&buff[1], 3); } // I2C else { // Clear D/C to switch to command mode buff[0] = SSD_Command_Mode; // Write Data on I2C fastI2Cwrite(buff, sizeof(buff)) ; } }
void SendPacketToSPI(BowlerPacket * Packet){ if(!isSPI(GetChannelMode(Packet->use.data[0]))){ println_I("channel is not SPI"); return; } SendPacketToSPIFromArray(Packet->use.head.DataLegnth-6,Packet->use.data+1); }
void StopSPI(BYTE pin){ if (isSPI(GetChannelMode(pin))){ CloseSPI2(); _RG6=1; _RG8=1; SDI_TRIS=INPUT; SDO_TRIS=INPUT; SCK_TRIS=INPUT; println_I("Clearing up SPI perpheral"); SetCoProcMode(0,IS_DI); SetCoProcMode(1,IS_DI); SetCoProcMode(2,IS_DI); } }
void ArduiPi_OLED::close(void) { // De-Allocate memory for OLED buffer if any if (poledbuff) free(poledbuff); poledbuff = NULL; // Release Raspberry SPI if ( isSPI() ) bcm2835_spi_end(); // Release Raspberry I2C if ( isI2C() ) bcm2835_i2c_end(); // Release Raspberry I/O control bcm2835_close(); }
void ArduiPi_OLED::sendCommand(uint8_t c) { // Is SPI if (isSPI()) { // Setup D/C line to low to switch to command mode bcm2835_gpio_write(dc, LOW); // Write Data on SPI fastSPIwrite(c); } // so I2C else { char buff[2] ; // Clear D/C to switch to command mode buff[0] = SSD_Command_Mode ; buff[1] = c; // Write Data on I2C fastI2Cwrite(buff, sizeof(buff)) ; } }
void ArduiPi_OLED::display(void) { #ifdef SEEED_I2C if (oled_type == OLED_SEEED_I2C_96x96 ) { sendCommand(SSD1327_Set_Row_Address , 0x00, 0x5F); sendCommand(SSD1327_Set_Column_Address, 0x08, 0x37); } else #endif { sendCommand(SSD1306_Set_Lower_Column_Start_Address | 0x0); // low col = 0 sendCommand(SSD1306_Set_Higher_Column_Start_Address | 0x0); // hi col = 0 sendCommand(SSD1306_Set_Start_Line | 0x0); // line #0 } uint16_t i=0 ; // pointer to OLED data buffer uint8_t * p = poledbuff; // SPI if ( isSPI()) { // Setup D/C line to high to switch to data mode bcm2835_gpio_write(dc, HIGH); // Send all data to OLED for ( i=0; i<oled_buff_size; i++) { fastSPIwrite(*p++); } // I wonder why we have to do this (check datasheet) if (oled_height == 32) { for (uint16_t i=0; i<oled_buff_size; i++) { fastSPIwrite(0); } } } // I2C else { char buff[17] ; uint8_t x ; // Setup D/C to switch to data mode buff[0] = SSD_Data_Mode; if (oled_type == OLED_SH1106_I2C_128x64) { for (uint8_t k=0; k<8; k++) { sendCommand(0xB0+k);//set page addressSSD_Data_Mode; sendCommand(0x02) ;//set lower column address sendCommand(0x10) ;//set higher column address for( i=0; i<8; i++) { for (x=1; x<=16; x++) buff[x] = *p++; fastI2Cwrite(buff, 17); } } } else { // loop trough all OLED buffer and // send a bunch of 16 data byte in one xmission for ( i=0; i<oled_buff_size; i+=16 ) { for (x=1; x<=16; x++) buff[x] = *p++; fastI2Cwrite(buff, 17); } } } }