//==================================================================================== void ImageDemo(void) { memset(DisplayBuffer, 0, sizeof(DisplayBuffer)); DrawTextToBuffer(3, " IMAGE DEMO ", DisplayBuffer); WriteBufferToDisplay(DisplayBuffer); MsDelay(1000); DisplayImage(BR_LOGO_LCD); MsDelay(2000); }
void LcdWrite(int mode, char hex) { BitWrPortI(PBDR, &PBDRShadow, mode, RSADDR); // Choose command or data mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode WrPortI(PADR, &PADRShadow, hex); // Set LCD command on port A MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data MsDelay(1); // Wait 1 ms for LCD to receive BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission MsDelay(1); // Wait 1 ms until next write }
void LcdCommandWr(char hex) { BitWrPortI(PBDR, &PBDRShadow, 0, RSADDR); // Set LCD command mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode WrPortI(PADR, &PADRShadow, hex); // Set LCD command on port A MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission MsDelay(1); // Wait 1 ms until next write }
void LcdPutChar(char displayChar) { char * lcdChar; lcdChar = AsciiCharLookup(displayChar); if(lcdChar==NULL) return; BitWrPortI(PBDR, &PBDRShadow, 1, RSADDR); // Set LCD data mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode WrPortI(PADR, &PADRShadow, *lcdChar); // Set the display data on port A MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission MsDelay(1); }
void Lcd_Init() { LcdCommandWr(0x30); // Send init sequence, 3x 0x30 MsDelay(4); LcdCommandWr(0x30); LcdCommandWr(0x30); LcdCommandWr(0x38); // Send cmd 8bit, 2 lines, 5x7 font }
//==================================================================================== void AnimationDemo(void) { uint32_t frame_index; // Splash screen memset(DisplayBuffer, 0, sizeof(DisplayBuffer)); DrawTextToBuffer(3, " ANIMATION DEMO ", DisplayBuffer); WriteBufferToDisplay(DisplayBuffer); MsDelay(1000); for(frame_index = 0; frame_index < FRAME_COUNT; frame_index++) { MsDelay(FRAME_DEALY); DisplayImage((unsigned char*)BR_LOGO_ANIM[frame_index]); } MsDelay(2000); }
LcdCommandWr(char hex) { int cmdbits[8]; BitWrPortI(PBDR, &PBDRShadow, 0, RSADDR); // Set LCD command mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode // we need to split the 8 bits in half and transmit upper 4 bits, // then the lower 4 bits. ByteSplit(hex, cmdbits); BitWrPortI(PADR, &PADRShadow, cmdbits[3], 4); // Set port A bit 4 BitWrPortI(PADR, &PADRShadow, cmdbits[2], 5); // Set port A bit 5 BitWrPortI(PADR, &PADRShadow, cmdbits[1], 6); // Set port A bit 6 BitWrPortI(PADR, &PADRShadow, cmdbits[0], 7); // Set port A bit 7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(1); BitWrPortI(PADR, &PADRShadow, cmdbits[7], 4); // Set port A bit 4 BitWrPortI(PADR, &PADRShadow, cmdbits[6], 5); // Set port A bit 5 BitWrPortI(PADR, &PADRShadow, cmdbits[5], 6); // Set port A bit 6 BitWrPortI(PADR, &PADRShadow, cmdbits[4], 7); // Set port A bit 7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data lower 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission lower 4 bit MsDelay(1); }
void LcdPutChar(char displayChar) { char * lcdChar; int databits[8]; lcdChar = AsciiCharLookup(displayChar); if(lcdChar==NULL) return; BitWrPortI(PBDR, &PBDRShadow, 1, RSADDR); // Set LCD data mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode // we need to split the 8 bits in half and transmit upper 4 bits, // then the lower 4 bits. ByteSplit(*lcdChar, databits); BitWrPortI(PADR, &PADRShadow, databits[3], 4); // Set port A bit 4 BitWrPortI(PADR, &PADRShadow, databits[2], 5); // Set port A bit 5 BitWrPortI(PADR, &PADRShadow, databits[1], 6); // Set port A bit 6 BitWrPortI(PADR, &PADRShadow, databits[0], 7); // Set port A bit 7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(1); BitWrPortI(PADR, &PADRShadow, databits[7], 4); // Set port A bit 4 BitWrPortI(PADR, &PADRShadow, databits[6], 5); // Set port A bit 5 BitWrPortI(PADR, &PADRShadow, databits[5], 6); // Set port A bit 6 BitWrPortI(PADR, &PADRShadow, databits[4], 7); // Set port A bit 7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data lower 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission lower 4 bit MsDelay(1); }
//==================================================================================== void TextDemo(void) { uint32_t row = 0, col = 0, i; memset(DisplayBuffer, 0, sizeof(DisplayBuffer)); DrawTextToBuffer(3, " TEXT DEMO ", DisplayBuffer); WriteBufferToDisplay(DisplayBuffer); MsDelay(1000); memset(DisplayBuffer, 0, sizeof(DisplayBuffer)); for(i = 0; i <= 96; i++) { DrawChar(33 + i, row, col++, DisplayBuffer); if(col >= TEXT_CHARACTERS_PER_ROW) { row++; col = 0; } } WriteBufferToDisplay(DisplayBuffer); MsDelay(2000); }
//==================================================================================== void SplashScreen(void) { memset(DisplayBuffer, 0, sizeof(DisplayBuffer)); DrawTextToBuffer(0, " 0.96\" OLED Display ", DisplayBuffer); DrawTextToBuffer(2, " BLACK RAM ", DisplayBuffer); DrawTextToBuffer(3, " ELECTRONICS ", DisplayBuffer); DrawTextToBuffer(5, "Dev Boards & Displays ", DisplayBuffer); DrawTextToBuffer(6, " With ", DisplayBuffer); DrawTextToBuffer(7, "Examples & Tutorials ", DisplayBuffer); WriteBufferToDisplay(DisplayBuffer); MsDelay(3000); }
void CTimer::TuneMsDelay (void) { unsigned nTicks = GetTicks (); MsDelay (1000); nTicks = GetTicks () - nTicks; unsigned nFactor = 100 * HZ / nTicks; m_nMsDelay = m_nMsDelay * nFactor / 100; m_nusDelay = (m_nMsDelay + 500) / 1000; CLogger::Get ()->Write ("timer", LogNotice, "SpeedFactor is %u.%02u", nFactor / 100, nFactor % 100); }
void main() { void brdInit(); // Enable development board WrPortI(SPCR, NULL, 0x84); // Set Rabbit port A to output WrPortI(PADR, &PADRShadow, 0x0); // Zero out all bits of port A WrPortI(PBDDR, &PBDDRShadow, 0xFF); // Set port B to output LcdWrite(0, 0x30); MsDelay(4); LcdWrite(0, 0x30); LcdWrite(0, 0x30); LcdWrite(0, 0x38); // Send cmd "8bit, 2 lines, 5x7 font" LcdWrite(0, 0x06); // Send cmd "Entry mode, increment move" LcdWrite(0, 0x10); // Send cmd "display and cursor shift" LcdWrite(0, 0x0E); // Send cmd "display and cursor on" LcdWrite(0, 0x01); // Send cmd "LCD clear, jump to zero LcdWrite(1, 0x48); // Send data 'H' LcdWrite(1, 0x69); // Send data 'i' }
void ErrorDisplayMessage(const char *message, unsigned int blocking) { uint32_t x; uint32_t y; // First, put some aggressive color for(y = 0; y < 160; ++y) for(x = 0; x < 240*2; ++x) FBPutColor(x, y, 0xFF0000FF); ConsolePrint(1, 1, message); FBCopyDoubleBuffer(); if(blocking) for(;;); #ifndef NO_USB else MsDelay(2500); #endif }
void main() { void brdInit(); // Enable development board SetPortAOut(); // Set port A as output port WrPortI(PBDDR, &PBDDRShadow, 0xFF); // Set port B as output port Lcd_Config(); pause(5); LcdWriteStr(1,"Rabbit-RCM4010:"); pause(5); LcdWriteStr(2,"[\"Hello World!\"]"); pause(10); Lcd_Clear(); Lcd_noCursor_On(); LcdWriteStr(1,"LCD off in 5 sec"); LcdCommandWr(0xA8); MsDelay(300); LcdPutChar('5'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('4'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('3'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('2'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('1'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('.'); MsDelay(300); LcdPutChar('0'); MsDelay(300); Lcd_Off(); }
boolean USBStandardHubEnumeratePorts (TUSBStandardHub *pThis) { assert (pThis != 0); TUSBHostController *pHost = USBDeviceGetHost (&pThis->m_USBDevice); assert (pHost != 0); TUSBEndpoint *pEndpoint0 = USBDeviceGetEndpoint0 (&pThis->m_USBDevice); assert (pEndpoint0 != 0); assert (pThis->m_nPorts > 0); // first power on all ports for (unsigned nPort = 0; nPort < pThis->m_nPorts; nPort++) { if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_OTHER, SET_FEATURE, PORT_POWER, nPort+1, 0, 0) < 0) { LogWrite (FromHub, LOG_ERROR, "Cannot power port %u", nPort+1); return FALSE; } } // pThis->m_pHubDesc->bPwrOn2PwrGood delay seems to be not enough // for some low speed devices, so we use the maximum here MsDelay (510); // now detect devices, reset and initialize them for (unsigned nPort = 0; nPort < pThis->m_nPorts; nPort++) { assert (pThis->m_pStatus[nPort] == 0); pThis->m_pStatus[nPort] = malloc (sizeof (TUSBPortStatus)); assert (pThis->m_pStatus[nPort] != 0); if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_IN | REQUEST_CLASS | REQUEST_TO_OTHER, GET_STATUS, 0, nPort+1, pThis->m_pStatus[nPort], 4) != 4) { LogWrite (FromHub, LOG_ERROR, "Cannot get status of port %u", nPort+1); continue; } assert (pThis->m_pStatus[nPort]->wPortStatus & PORT_POWER__MASK); if (!(pThis->m_pStatus[nPort]->wPortStatus & PORT_CONNECTION__MASK)) { continue; } if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_OTHER, SET_FEATURE, PORT_RESET, nPort+1, 0, 0) < 0) { LogWrite (FromHub, LOG_ERROR, "Cannot reset port %u", nPort+1); continue; } MsDelay (100); if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_IN | REQUEST_CLASS | REQUEST_TO_OTHER, GET_STATUS, 0, nPort+1, pThis->m_pStatus[nPort], 4) != 4) { return FALSE; } //LogWrite (FromHub, LOG_DEBUG, "Port %u status is 0x%04X", nPort+1, (unsigned) pThis->m_pStatus[nPort]->wPortStatus); if (!(pThis->m_pStatus[nPort]->wPortStatus & PORT_ENABLE__MASK)) { LogWrite (FromHub, LOG_ERROR, "Port %u is not enabled", nPort+1); continue; } // check for over-current if (pThis->m_pStatus[nPort]->wPortStatus & PORT_OVER_CURRENT__MASK) { DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_OTHER, CLEAR_FEATURE, PORT_POWER, nPort+1, 0, 0); LogWrite (FromHub, LOG_ERROR, "Over-current condition on port %u", nPort+1); return FALSE; } TUSBSpeed Speed = USBSpeedUnknown; if (pThis->m_pStatus[nPort]->wPortStatus & PORT_LOW_SPEED__MASK) { Speed = USBSpeedLow; } else if (pThis->m_pStatus[nPort]->wPortStatus & PORT_HIGH_SPEED__MASK) { Speed = USBSpeedHigh; } else { Speed = USBSpeedFull; } // first create default device assert (pThis->m_pDevice[nPort] == 0); pThis->m_pDevice[nPort] = malloc (sizeof (TUSBDevice)); assert (pThis->m_pDevice[nPort] != 0); USBDevice (pThis->m_pDevice[nPort], pHost, Speed, USBDeviceGetAddress (&pThis->m_USBDevice), nPort+1); if (!USBDeviceInitialize (pThis->m_pDevice[nPort])) { _USBDevice (pThis->m_pDevice[nPort]); free (pThis->m_pDevice[nPort]); pThis->m_pDevice[nPort] = 0; continue; } TString *pNames = USBStandardHubGetDeviceNames (pThis->m_pDevice[nPort]); assert (pNames != 0); LogWrite (FromHub, LOG_NOTICE, "Port %u: Device %s found", nPort+1, StringGet (pNames)); _String (pNames); free (pNames); } // now configure devices for (unsigned nPort = 0; nPort < pThis->m_nPorts; nPort++) { if (pThis->m_pDevice[nPort] == 0) { continue; } // now create specific device from default device TUSBDevice *pChild = USBDeviceFactoryGetDevice (pThis->m_pDevice[nPort]); if (pChild != 0) { _USBDevice (pThis->m_pDevice[nPort]); // delete default device free (pThis->m_pDevice[nPort]); pThis->m_pDevice[nPort] = pChild; // assign specific device if (!(*pThis->m_pDevice[nPort]->Configure) (pThis->m_pDevice[nPort])) { LogWrite (FromHub, LOG_ERROR, "Port %u: Cannot configure device", nPort+1); continue; } LogWrite (FromHub, LOG_DEBUG, "Port %u: Device configured", nPort+1); } else { LogWrite (FromHub, LOG_NOTICE, "Port %u: Device is not supported", nPort+1); _USBDevice (pThis->m_pDevice[nPort]); free (pThis->m_pDevice[nPort]); pThis->m_pDevice[nPort] = 0; } } // again check for over-current TUSBHubStatus *pHubStatus = malloc (sizeof (TUSBHubStatus)); assert (pHubStatus != 0); if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_IN | REQUEST_CLASS, GET_STATUS, 0, 0, pHubStatus, sizeof *pHubStatus) != (int) sizeof *pHubStatus) { LogWrite (FromHub, LOG_ERROR, "Cannot get hub status"); free (pHubStatus); return FALSE; } if (pHubStatus->wHubStatus & HUB_OVER_CURRENT__MASK) { for (unsigned nPort = 0; nPort < pThis->m_nPorts; nPort++) { DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_OTHER, CLEAR_FEATURE, PORT_POWER, nPort+1, 0, 0); } LogWrite (FromHub, LOG_ERROR, "Hub over-current condition"); free (pHubStatus); return FALSE; } free (pHubStatus); pHubStatus = 0; boolean bResult = TRUE; for (unsigned nPort = 0; nPort < pThis->m_nPorts; nPort++) { if (DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_IN | REQUEST_CLASS | REQUEST_TO_OTHER, GET_STATUS, 0, nPort+1, pThis->m_pStatus[nPort], 4) != 4) { continue; } if (pThis->m_pStatus[nPort]->wPortStatus & PORT_OVER_CURRENT__MASK) { DWHCIDeviceControlMessage (pHost, pEndpoint0, REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_OTHER, CLEAR_FEATURE, PORT_POWER, nPort+1, 0, 0); LogWrite (FromHub, LOG_ERROR, "Over-current condition on port %u", nPort+1); bResult = FALSE; } } return bResult; }
void pause(unsigned long seconds) { MsDelay(seconds*1000); // multiply sec with 1000 for ms }
Lcd4bitInit() { BitWrPortI(PBDR, &PBDRShadow, 0, RSADDR); // Set command mode BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR); // Set LCD write mode BitWrPortI(PADR, &PADRShadow, 1, 4); // Set port A-4 BitWrPortI(PADR, &PADRShadow, 1, 5); // Set port A-5 BitWrPortI(PADR, &PADRShadow, 0, 6); // Set port A-6 BitWrPortI(PADR, &PADRShadow, 0, 7); // Set port A-7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(5); BitWrPortI(PADR, &PADRShadow, 1, 4); // Set port A-4 BitWrPortI(PADR, &PADRShadow, 1, 5); // Set port A-5 BitWrPortI(PADR, &PADRShadow, 0, 6); // Set port A-6 BitWrPortI(PADR, &PADRShadow, 0, 7); // Set port A-7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(1); BitWrPortI(PADR, &PADRShadow, 1, 4); // Set port A-4 BitWrPortI(PADR, &PADRShadow, 1, 5); // Set port A-5 BitWrPortI(PADR, &PADRShadow, 0, 6); // Set port A-6 BitWrPortI(PADR, &PADRShadow, 0, 7); // Set port A-7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(1); BitWrPortI(PADR, &PADRShadow, 0, 4); // Set port A-4 BitWrPortI(PADR, &PADRShadow, 1, 5); // Set port A-5 BitWrPortI(PADR, &PADRShadow, 0, 6); // Set port A-6 BitWrPortI(PADR, &PADRShadow, 0, 7); // Set port A-7 MsDelay(1); BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR); // Start sending data upper 4 bit MsDelay(1); // Wait 1 ms for LCD to read BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR); // Finish transmission upper 4 bit MsDelay(1); }