static void LcdDelay(u_char xt) { if (during_init) { NutDelay(xt); } else { #if defined(LCD_RW_BIT) while (LcdReadCmd() & (1 << LCD_BUSY)) LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; LCD_DELAY; #elif defined(NUT_CPU_FREQ) NutSleep(xt); #else NutDelay(xt); #endif } }
void displayStreamInfo(){ LcdBackLight(LCD_BACKLIGHT_ON); char offset = getScrollOffset(); if (offset == 0) (*write_display_ptr[1])(" ", 17); (*write_display_ptr[0])(" Station Info ", 17); //char* streamInfo = getStreamInfo(); // I have to copy the StreamInfo buffer, I kept overwriting it. char streamInfo[48] = " No info "; char* streamInfoPtr = &streamInfo[0]; strncpy(streamInfo, getStreamInfo(), 48); // copy the streamInfo buffer. streamInfo[48] = '\0'; // To be sure... if (offset >= 0) streamInfoPtr += offset; streamInfoPtr[16] = '\0'; (*write_display_ptr[1])(streamInfoPtr, 17); incrementScrollOffset(); NutDelay(500); }
void printString(char* str) { int i, j; int rest; if (strlen(str) <= 16) { for (i = 0; i < strlen(str); i++) { LcdChar(str[i]); } } else { rest = strlen(str) - 16; for (j = 0; j <= rest; j++) { clearScreen(); for (i = 0 + j; i<strlen(str); i++) { LcdChar(str[i]); } NutDelay(250); } NutSleep(1000); } }
/** * Clears the LCD display and sets the cursor to [0][0] */ void lcd_clear() { LcdWriteByte(WRITE_COMMAND, 0x01); // Display clear command. NutDelay(2); lcd_cursor_home(); }
/*! * \brief Write byte to the target's flash memory. * * The target must have been erased by a previous call * to SpiFlashErase(). * * \param high Must be 0 to write the low byte or 8 to * write the high byte. * \param addr Word address to write to. * \param data Byte value to write. * * \return 0 on success, -1 otherwise. */ int SpiFlashWriteByte(u_char high, u_short addr, u_char data) { u_char d; if (data != 0xff) { SpiByte(0x40 | high); SpiByte(addr >> 8); SpiByte(addr & 0xFF); SpiByte(data); /* * During programming a value of 0x7F appears at the memory location. * If we are programming this value, we delay execution by 10 ms. * Otherwise we poll the memory location until we read back the * programmed value. */ if (data == 0x7f) NutDelay(10); else { for (d = 0; d < 255; d++) { /* * Read program flash byte. */ SpiByte(0x20 | high); SpiByte(addr >> 8); SpiByte(addr & 0xFF); if (SpiByte(0xFF) == data) break; } if (d == 255) return -1; } }
/*! * \brief Wait until MMU is ready. * * Poll the MMU command register until \ref MMUCR_BUSY * is cleared. * * \param tmo Timeout in milliseconds. * * \return 0 on success or -1 on timeout. */ static INLINE int NicMmuWait(phantom_device_t * dev, u_int16_t tmo) { while (tmo--) { if ((nic_inlb(NIC_MMUCR) & MMUCR_BUSY) == 0) break; NutDelay(1); } return tmo ? 0 : -1; }
THREAD(T1, arg) { for (;;) { //NutSleep(1000); LogMsg_P(LOG_INFO, PSTR("T1")); printf("Yello"); NutDelay(100); } }
int main(void) { tm gmt; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------")); CardInit(); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit() == AT45DB041B) { } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt NutThreadSetPriority(1); NutTimerInit(); sei(); printf("\nreading EEPROM\n"); NutSleep(1000); readEEPROM(); printf("UTC: %d\n",IMCconfig.UTC); NutSleep(1000); IMCconfig.UTC++; printf("na ophoging UTC: %d\n",IMCconfig.UTC); saveEEPROM(); NutSleep(1000); readEEPROM(); printf("na saving en reading UTC: %d\n",IMCconfig.UTC); printf("\nResetting EEPROM\n"); NutSleep(1000); resetEEPROM(); NutSleep(1000); readEEPROM(); for (;;) { } return(0); // never reached, but 'main()' returns a non-void, so..... }
void NtpWriteTimeToEeprom(tm time_struct){ Eeprom_tm eeprom_tm_struct; eeprom_tm_struct.len = sizeof(eeprom_tm_struct); eeprom_tm_struct.tm_struct = time_struct; int success = NutNvMemSave(256, &eeprom_tm_struct, sizeof(eeprom_tm_struct)); if (success == 0){ puts("NtpWriteTimeToEeprom: Time succesfully written to eeprom \n"); } NutDelay(100); }
/*! * \brief Reset the Ethernet controller. * * \return 0 on success, -1 otherwise. */ static int NicReset(phantom_device_t * dev) { #ifdef LANC111_RESET_BIT sbi(LANC111_RESET_DDR, LANC111_RESET_BIT); sbi(LANC111_RESET_PORT, LANC111_RESET_BIT); NutDelay(WAIT100); cbi(LANC111_RESET_PORT, LANC111_RESET_BIT); NutDelay(WAIT250); NutDelay(WAIT250); #endif /* Disable all interrupts. */ nic_outlb(NIC_MSK, 0); /* MAC and PHY software reset. */ nic_bs(0); nic_outw(NIC_RCR, RCR_SOFT_RST); /* Enable Ethernet protocol handler. */ nic_bs(1); nic_outw(NIC_CR, CR_EPH_EN); NutDelay(10); /* Disable transmit and receive. */ nic_bs(0); nic_outw(NIC_RCR, 0); nic_outw(NIC_TCR, 0); /* Enable auto release. */ nic_bs(1); nic_outw(NIC_CTR, CTR_AUTO_RELEASE); /* Reset MMU. */ nic_bs(2); nic_outlb(NIC_MMUCR, MMU_RST); if (NicMmuWait(dev,1000)) return -1; return 0; }
/* ����������������������������������������������������������������������� */ void LcdLowLevelInit() { u_char i; NutDelay(140); // wait for more than 140 ms after Vdd rises to 2.7 V for (i=0; i<3; ++i) { LcdWriteNibble(WRITE_COMMAND, 0x33); // function set: 8-bit mode; necessary to guarantee that NutDelay(4); // SIR starts up always in 5x10 dot mode } LcdWriteNibble(WRITE_COMMAND, 0x22); // function set: 4-bit mode; necessary because KS0070 doesn't NutDelay(1); // accept combined 4-bit mode & 5x10 dot mode programming //LcdWriteByte(WRITE_COMMAND, 0x24); // function set: 4-bit mode, 5x10 dot mode, 1-line LcdWriteByte(WRITE_COMMAND, 0x28); // function set: 4-bit mode, 5x7 dot mode, 2-lines NutDelay(5); LcdWriteByte(WRITE_COMMAND, 0x0C); // display ON/OFF: display ON, cursor OFF, blink OFF NutDelay(5); LcdWriteByte(WRITE_COMMAND, 0x01); // display clear NutDelay(5); LcdWriteByte(WRITE_COMMAND, 0x06); // entry mode set: increment mode, entire shift OFF LcdWriteByte(WRITE_COMMAND, 0x80); // DD-RAM address counter (cursor pos) to '0' }
void NtpWriteTimeToEeprom(tm time_struct){ Eeprom_tm eeprom_tm_struct; eeprom_tm_struct.len = sizeof(eeprom_tm_struct); eeprom_tm_struct.tm_struct = time_struct; printf("uren: %d, minuten: %d, seconden: %d\n", time_struct.tm_hour, time_struct.tm_min, time_struct.tm_sec); int success = NutNvMemSave(100, &time_struct.tm_hour, sizeof(time_struct.tm_hour)); if (success == 0){ puts("NtpWriteTimeToEeprom: hours succesfully written to eeprom \n"); } success = NutNvMemSave(105, &time_struct.tm_min, sizeof(time_struct.tm_min)); if (success == 0){ puts("NtpWriteTimeToEeprom: mins succesfully written to eeprom \n"); } success = NutNvMemSave(110, &time_struct.tm_sec, sizeof(time_struct.tm_sec)); if (success == 0){ puts("NtpWriteTimeToEeprom: secs succesfully written to eeprom \n"); } NutDelay(100); }
int main(void) { tm gmt; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------")); CardInit(); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit() == AT45DB041B) { } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt initMenu(); sei(); NutTimerInit(); NutThreadSetPriority(1); int keyvalue = KbGetKey(); int old; LcdBackLight(LCD_BACKLIGHT_ON); if(NutRegisterDevice(&DEV_ETHER, 0x8300, 5))printf("Error: No LAN device\n"); else printf("Lan device initialized\n"); for (;;) { keyvalue = KbGetKey(); if(old != keyvalue){ stateMenu(keyvalue); old = keyvalue; } NutSleep(100); WatchDogRestart(); } return(0); // never reached, but 'main()' returns a non-void, so..... }
int NtpSync(void){ /* Ophalen van pool.ntp.org */ isSyncing = true; setTimeZone(50); httpGet("/gettimezone.php", parsetimezone); _daylight = 0; printf("Timezone is: %d", TIME_ZONE); if(TIME_ZONE == 50) { return 0; } NutDelay(100); //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)"); timeserver = inet_addr("213.154.229.24"); for (;;) { if (NutSNTPGetTime(×erver, &ntp_time) == 0) { break; } else { NutSleep(400); puts("Fout bij het ontvangen van de tijd"); } } //puts("Opgehaald.\n"); ntp_datetime = localtime(&ntp_time); printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec); printf("NTP date is: %02d.%02d.%02d\n\n", ntp_datetime->tm_mday, (ntp_datetime->tm_mon + 1), (ntp_datetime->tm_year + 1900)); X12RtcSetClock(ntp_datetime); NtpWriteTimeToEeprom(*ntp_datetime); isSyncing = false; validTime = true; return 1; }
int main(void) { struct _tm timeCheck; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); X12Init(); VsPlayerInit(); NtpInit(); NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024); NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500); NutThreadCreate("BackgroundThread", AlarmCheck, NULL, 256); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs heartbeat interrupt /* * Increase our priority so we can feed the watchdog. */ NutThreadSetPriority(1); /* Enable global interrupts */ sei(); LcdBackLight(LCD_BACKLIGHT_ON); setCurrentDisplay(DISPLAY_DateTime, 5); X12RtcGetClock(&timeCheck); int hours; int mins; int secs; if(!NutNvMemLoad(100, &hours, sizeof(hours))) { printf("uren: %d", hours); } if(!NutNvMemLoad(105, &mins, sizeof(mins))) { printf(" minuten: %d", mins); } if(!NutNvMemLoad(110, &secs, sizeof(secs))) { printf(" seconden %d", secs); } printf("Welcome to Saltyradio.\nI'm using mac address: %s\n\n\n", getMacAdress()); for (;;) { //Key detecten if(KbGetKey() == KEY_01){ setCurrentDisplay(DISPLAY_DateTime, 5); } else if(KbGetKey() == KEY_OK) { if(getCurrentDisplay() == DISPLAY_MainMenu) { clickOk(); } else if(getCurrentDisplay() == DISPLAY_SettingsMenu) { clickOkSettings(); } else if(getCurrentDisplay() == DISPLAY_Play || getCurrentDisplay() == DISPLAY_Song) { clickOkPlay(); } else { setCurrentDisplay(DISPLAY_MainMenu, 10000); } } else if(KbGetKey() == KEY_LEFT) { switchLeft(); } else if(KbGetKey() == KEY_RIGHT) { switchItem(); } else if(KbGetKey() == KEY_DOWN){ setCurrentDisplay(DISPLAY_Volume, 5); volumeDown(); }else if(KbGetKey() == KEY_UP) { setCurrentDisplay(DISPLAY_Volume, 5); volumeUp(); } refreshScreen(); WatchDogRestart(); NutSleep(100); } return(0); }
int main(void) { WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); LcdBackLight(1); PrintStr("Starting System"); Uart0DriverInit(); Uart0DriverStart(); LogInit(); CardInit(); char custom[48] = ALL; LoadCustomChars(custom, 6); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit()==AT45DB041B) { // ...... } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt ClearLcdScreen(); //Nieuwe threads aanmaken NutThreadCreate("t01", Thread1, NULL, 512); NutThreadCreate("time", TimeUpdater, NULL, 512); //Start netwerk int i = initNetworkDHCP(); LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i); //Haal Internet tijd op pgmt = getNTPTime(); X12RtcSetClock(&pgmt); //LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); /* * Increase our priority so we can feed the watchdog. */ NutThreadSetPriority(1); /* Enable global interrupts */ sei(); /******************NETWERK**TEST*****************************************************/ //Maak nieuwe socket TCPSOCKET *sock; sock = NutTcpCreateSocket(); //Connect met google.nl LogMsg_P(LOG_INFO, PSTR("Connecting client")); clientConnect(sock); //Zend http req clientSend(sock,buffer,sizeof(buffer)); //Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram) char rcvbuffer [500]; int rec; rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer)); LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec); //0 terminate buffer(string) //rcvbuffer[499] = 0; //Print buffer(http response enz) LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer); //Sluit connectie clientClose(sock); /***********************************************************************************/ //Main gui besturing?? for (;;) { NutSleep(100); WatchDogRestart(); } return(0); }
/* * \return 0 on success or 2 in case of an I/O error. */ static int NutChatSendString(int fd, char *str) { int rc = 0; uint8_t eol = 1; uint8_t skip; char ch; #ifdef NUTDEBUG if (__chat_trf) { static prog_char dbgfmt[] = "Send '%s'\n"; fprintf_P(__chat_trs, dbgfmt, str); } #endif /* Flush input buffer. */ _read(fd, 0, 0); while (*str && eol && rc == 0) { ch = *str++; skip = 0; if (ch == '^') { ch = *str++; ch &= 0x1f; } else if (ch == '\\') { ch = *str++; switch (ch) { case 'b': ch = '\b'; break; case 'c': eol = 0; skip = 1; break; case 'd': NutSleep(1000); skip = 1; break; case 'n': ch = '\n'; break; case 'N': ch = 0; break; case 'p': NutDelay(100); skip = 1; break; case 'r': ch = '\r'; break; case 's': ch = ' '; break; case 't': ch = '\t'; break; default: if (ch >= '0' && ch <= '7') { ch &= 0x07; if (*str >= '0' && *str <= '7') { ch <<= 3; ch |= *str++ & 0x07; if (*str >= '0' && *str <= '7') { ch <<= 3; ch |= *str++ & 0x07; } } } break; } } if (skip) skip = 0; else { NutDelay(10); if (_write(fd, &ch, 1) != 1) rc = 2; else _write(fd, 0, 0); } } if (eol && rc == 0 && _write(fd, "\r", 1) != 1) rc = 2; else _write(fd, 0, 0); return rc; }
void ili9325_24_0_init() { // set global information drv_convert_touch_coordinates = ili9325_24_0_convert_touch_coordinates; drv_address_set = ili9325_24_0_address_set; drv_lcd_rotate = ili9325_24_0_rotate; // Return used resolution screen_max_x = 319; // X screen_max_y = 239; // Y main_W_com_data(0xE3, 0x3008); main_W_com_data(0xE7, 0x0012); main_W_com_data(0xEF, 0x1231); main_W_com_data(TS_INS_START_OSC, 0x0001); //start oscillator NutDelay(50); main_W_com_data(TS_INS_DRIV_OUT_CTRL, 0x0000); //set SS, SM main_W_com_data(TS_INS_DRIV_WAV_CTRL, 0x0700); //set 1 line inversion main_W_com_data(TS_INS_ENTRY_MOD, TS_VAL_ENTRY_MOD); //set GRAM write direction, BGR=0 main_W_com_data(TS_INS_RESIZE_CTRL, 0x0000); //no resizing main_W_com_data(TS_INS_DISP_CTRL2, 0x0202); //front & back porch periods = 2 main_W_com_data(TS_INS_DISP_CTRL3, 0x0000); main_W_com_data(TS_INS_DISP_CTRL4, 0x0000); main_W_com_data(TS_INS_RGB_DISP_IF_CTRL1, 0x0000); //select system interface main_W_com_data(TS_INS_FRM_MARKER_POS, 0x0000); main_W_com_data(TS_INS_RGB_DISP_IF_CTRL2, 0x0000); main_W_com_data(TS_INS_POW_CTRL1, 0x0000); main_W_com_data(TS_INS_POW_CTRL2, 0x0007); main_W_com_data(TS_INS_POW_CTRL3, 0x0000); main_W_com_data(TS_INS_POW_CTRL4, 0x0000); NutDelay(200); main_W_com_data(TS_INS_POW_CTRL1, 0x1690); main_W_com_data(TS_INS_POW_CTRL2, 0x0227); NutDelay(50); main_W_com_data(TS_INS_POW_CTRL3, 0x001A); NutDelay(50); main_W_com_data(TS_INS_POW_CTRL4, 0x1800); main_W_com_data(TS_INS_POW_CTRL7, 0x002A); NutDelay(50); main_W_com_data(TS_INS_GRAM_HOR_AD, 0x0000); main_W_com_data(TS_INS_GRAM_VER_AD, 0x0000); main_W_com_data(TS_INS_GAMMA_CTRL1, 0x0007); main_W_com_data(TS_INS_GAMMA_CTRL2, 0x0605); main_W_com_data(TS_INS_GAMMA_CTRL3, 0x0106); main_W_com_data(TS_INS_GAMMA_CTRL4, 0x0206); main_W_com_data(TS_INS_GAMMA_CTRL5, 0x0808); main_W_com_data(TS_INS_GAMMA_CTRL6, 0x0007); main_W_com_data(TS_INS_GAMMA_CTRL7, 0x0201); main_W_com_data(TS_INS_GAMMA_CTRL8, 0x0007); main_W_com_data(TS_INS_GAMMA_CTRL9, 0x0602); main_W_com_data(TS_INS_GAMMA_CTRL10, 0x0808); main_W_com_data(TS_INS_HOR_START_AD, 0x0000); main_W_com_data(TS_INS_HOR_END_AD, 0x00EF); main_W_com_data(TS_INS_VER_START_AD, 0x0000); main_W_com_data(TS_INS_VER_END_AD, 0x013F); main_W_com_data(TS_INS_GATE_SCAN_CTRL1, 0xA700); main_W_com_data(TS_INS_GATE_SCAN_CTRL2, 0x0001); main_W_com_data(TS_INS_GATE_SCAN_CTRL3, 0x0000); main_W_com_data(TS_INS_PART_IMG1_DISP_POS, 0x0000); main_W_com_data(TS_INS_PART_IMG1_START_AD, 0x0000); main_W_com_data(TS_INS_PART_IMG1_END_AD, 0x0000); main_W_com_data(TS_INS_PART_IMG2_DISP_POS, 0x0000); main_W_com_data(TS_INS_PART_IMG2_START_AD, 0x0000); main_W_com_data(TS_INS_PART_IMG2_END_AD, 0x0000); main_W_com_data(TS_INS_PANEL_IF_CTRL1, 0x0010); main_W_com_data(TS_INS_PANEL_IF_CTRL2, 0x0000); main_W_com_data(TS_INS_PANEL_IF_CTRL3, 0x0003); main_W_com_data(TS_INS_PANEL_IF_CTRL4, 0x0110); main_W_com_data(TS_INS_PANEL_IF_CTRL5, 0x0000); main_W_com_data(TS_INS_PANEL_IF_CTRL6, 0x0000); main_W_com_data(TS_INS_DISP_CTRL1, 0x0133); }
int main(void) { //audioInit(); //setVolume(254); WatchDogDisable(); //disable watchdog NutDelay(100); //wait for it to disable SysInitIO(); //initialise input and output SPIinit(); //initialise SPI-registers (speed, mode) LedInit(); //initialise led initLCD(); //initialise lcd Uart0DriverInit(); //initialise Universal asynchronous receiver/transmitter Uart0DriverStart(); //start Uart printf("\n\n\n\nHardware initialization done\n\n"); LogInit(); //initialise ability to log CardInit(); //initialise cardreader printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n"); if (NutSegBufInit(8192) == 0) { puts("NutSegBufInit: Fatal error"); } /* * Initialize the MP3 decoder hardware. */ if (VsPlayerInit() || VsPlayerReset(0)) { puts("VsPlayer: Fatal error"); } if(X12Init() == -1){ printf("error initializing RTC"); //initialise X12RTC } tm gmt; if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec); } if (At45dbInit() == AT45DB041B) { // ...... } RcInit(); //Initialise the Remote Control module KbInit(); //Initialise keyboard initMenu(); //Initialise menu NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512); //create thread to handle button presses printf("\nInitialization done.\n"); initAlarms(); SysControlMainBeat(ON); //enable 4.4 msecs heartbeat interrupt printf("Heartbeat on.\n"); NutThreadSetPriority(1); //Increase our priority so we can feed the watchdog. sei(); //enable global interrupts NutThreadCreate("Bg", TimeSyncThread, NULL, 512); NutThreadCreate("Bq", RefreshSceenThread, NULL, 512); NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512); printf("\nEntering main loop.\n"); LcdBackLight(LCD_BACKLIGHT_ON); for(;;){ NutSleep(100); WatchDogRestart(); //restart watchdog } return(0); }
void clearScreen() { LcdWriteByte(WRITE_COMMAND, 0x01); NutDelay(5); }