/** Write an arbitrary glyph to the display */ void lcdWriteGlyph(int x, int y, const uint8_t *glyph, int width, int height, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Do the write writeGlyph(x, y, glyph, width, height, invert); // Deselect the display pinWrite(g_sel, true); }
/** Clear the display */ void lcdClear(bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Set the position sendCommand(0x80); sendCommand(0x40); // Fill in the whole display for(int index = 0; index < (WIDTH * LINES); index++) sendData(invert?0xff:0x00); // Deselect the display pinWrite(g_sel, true); }
int spiOpen(char* busDevice, int mode, int speed, int bitsPerWord, int lsbFirst) { int fd; int ret; if ((fd = open (busDevice, O_RDWR)) < 0) { errorMessage("open failed: %s", strerror(errno)); return -1; } if(spiConfig(fd, mode, speed, bitsPerWord, lsbFirst) < 0) { errorMessage("open failed: %s", strerror(errno)); return -1; } return fd; }
void main(void) { // setup WDTCTL = WDTPW + WDTHOLD; clockConfig(); pinConfig(); spiConfig(); // program execution loop while (1) { setPotValue(potLevel); __delay_cycles(100000); // I know, there are better ways... } }
/** Write a character to the display */ void lcdWriteCh(int x, int y, char ch, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Make sure the character is valid if((ch<0x20)||(ch>0x7f)) ch = 0x20; // Set the position sendCommand(0x80 | (x % WIDTH)); sendCommand(0x40 | (y % LINES)); // Write the character sendData(invert?0xff:0x00); writeGlyph(x + 1, y, BASE_FONT + (ch - 0x20) * (FONT_WIDTH - 2), FONT_WIDTH - 2, 1, invert); sendData(invert?0xff:0x00); // Deselect the display pinWrite(g_sel, true); }
/** Clear a region of the display */ void lcdClearRect(int y, int height, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Do the clear while(height) { // Set the position sendCommand(0x80); sendCommand(0x40 | (y % LINES)); // Fill the line for(int index=0; index<WIDTH; index++) sendData(invert?0xff:0x00); // Step to the next line height--; } // Deselect the display pinWrite(g_sel, true); }
void rfInit( void ) { spiConfig( &pygmyRFSPI, RF_CS, RF_SCK, RF_MISO, RF_MOSI, 0 ); pinConfig( RF_EN, OUT ); RF_EN_LOW; pinConfig( RF_IRQ, PULLUP ); pinInterrupt( rfRX, RF_IRQ, TRIGGER_FALLING, 3 ); //spiPutChar( &pygmyRFSPI, RF_WRITE|RF_REG_SETUP_RETR, 0x0F ); RF_CS_LOW; spiWriteByte( &pygmyRFSPI, RF_WRITE|RF_REG_SETUP_RETR ); spiWriteByte( &pygmyRFSPI, 0x0F ); // 15 retries, 250 microsec delay between tries RF_CS_HIGH; //rfSetTXPower( RF_2MBPS, 0 ); //spiPutChar( &pygmyRFSPI, RF_WRITE|RF_REG_ENRXADDR, BIT0 ); RF_CS_LOW; spiWriteByte( &pygmyRFSPI, RF_WRITE|RF_REG_ENRXADDR ); spiWriteByte( &pygmyRFSPI, BIT0 ); RF_CS_HIGH; //spiPutChar( &pygmyRFSPI, RF_WRITE|RF_REG_DYNPD, BIT0 ); RF_CS_LOW; spiWriteByte( &pygmyRFSPI, RF_WRITE|RF_REG_DYNPD ); spiWriteByte( &pygmyRFSPI, BIT0 ); RF_CS_HIGH; //spiPutChar( &pygmyRFSPI, RF_WRITE|RF_REG_FEATURE, RF_REG_FEATURE_EN_DPL ); RF_CS_LOW; spiWriteByte( &pygmyRFSPI, RF_WRITE|RF_REG_FEATURE ); spiWriteByte( &pygmyRFSPI, RF_REG_FEATURE_EN_DPL ); RF_CS_HIGH; //spiPutChar( &pygmyRFSPI, RF_WRITE|RF_REG_ENAA, BIT0 ); RF_CS_LOW; spiWriteByte( &pygmyRFSPI, RF_WRITE|RF_REG_ENAA ); spiWriteByte( &pygmyRFSPI, BIT0 ); RF_CS_HIGH; rfFlushTX(); rfFlushRX(); rfWriteAddress( RF_REG_TXADDR, (u8*)ucAddrP0 ); rfWriteAddress( RF_REG_RXADDR_P0, (u8*)ucAddrP0 ); rfSetRX(); }
void lcdInit( void ) { spiConfig( &pygmyLCD, LCD_CS, LCD_SCK, NONE, LCD_MOSI ); pinConfig( LCD_RESET, OUT ); // We will use USART1_RTS as CS pinConfig( LCD_A0, OUT ); pinSet( LCD_RESET, LOW ); delay( 2000 ); // microseconds pinSet( LCD_RESET, HIGH ); delay( 2000 ); // microseconds lcdWriteCommand( LCD_FUNCSET | LCD_FUNCSET_H ); lcdWriteCommand( LCD_SETVOP | 55 ); lcdWriteCommand( LCD_TEMPCONTROL ); lcdWriteCommand( LCD_BIAS | LCD_BIAS_BS1|LCD_BIAS_BS0 ); lcdWriteCommand( LCD_FUNCSET ); lcdWriteCommand( LCD_DISPCONTROL | LCD_DISPCONTROL_D ); lcdSetBPP( PYGMY_PBM_1BPP ); lcdSetColor( 0xFF, 0xFF, 0xFF ); lcdBackColor( 0x00, 0x00, 0x00 ); lcdClear(); drawAll(); }
/** Initialise the LCD display * * @param dc the comand/data pin * @param reset the reset pin * @param sel device select pin */ void lcdInit(PIN dc, PIN reset, PIN sel) { // Save the pins pinConfig(dc, DIGITAL_OUTPUT, 0); g_dc = dc; pinConfig(reset, DIGITAL_OUTPUT, 0); g_reset = reset; pinConfig(sel, DIGITAL_OUTPUT, 1); g_sel = sel; // Reset the LCD pinWrite(g_reset, true); // Initialise the LCD spiConfig(false, true, true); pinWrite(g_sel, false); sendCommand(0x21); // LCD Extended Commands. sendCommand(0xB1); // Set LCD Vop (Contrast) 0xB1/0xA1. sendCommand(0x04); // Set Temp coefficent. //0x04 sendCommand(0x14); // LCD bias mode 1:48. //0x13 sendCommand(0x0C); // Normal display, horizontal addressing sendCommand(0x20); // LCD Normal commands sendCommand(0x0C); // Normal display, horizontal addressing // Deselect the display pinWrite(g_sel, true); }
/** Write a string to the display */ void lcdWriteStr(int x, int y, const char *str, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); while (*str) { // Make sure the character is valid char ch = *str; if((ch<0x20)||(ch>0x7f)) ch = 0x20; // Set the position sendCommand(0x80 | (x % WIDTH)); sendCommand(0x40 | (y % LINES)); // Write the character sendData(invert?0xff:0x00); writeGlyph(x + 1, y, BASE_FONT + (ch - 0x20) * (FONT_WIDTH - 2), FONT_WIDTH - 2, 1, invert); sendData(invert?0xff:0x00); // Move to the next character (and position) str++; x += FONT_WIDTH; } // Deselect the display pinWrite(g_sel, true); }
/* * Class: io_silverspoon_bulldog_linux_jni_NativeSpi * Method: spiOpen * Signature: (Ljava/lang/String;III)I */ JNIEXPORT jint JNICALL Java_io_silverspoon_bulldog_linux_jni_NativeSpi_spiConfig (JNIEnv * env, jclass clazz, jint fileDescriptor, jint mode, jint speed, jint bitsPerWord, jboolean lsbFirst) { return spiConfig(fileDescriptor, mode, speed, bitsPerWord, lsbFirst == JNI_TRUE ? 1 : 0); }