///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // clear LCD screen MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("for details "); // send delay min/max changes to MIOS terminal while( 1 ) { if( print_message ) { MIOS32_IRQ_Disable(); u32 c_total_delay = total_delay; u32 c_midi_clock_ctr = midi_clock_ctr; delay_t c_d_tick = d_tick; delay_t c_d_beat = d_beat; print_message = 0; MIOS32_IRQ_Enable(); u32 bpm = 60000000 / c_d_beat.delay_last; u32 avg = c_midi_clock_ctr ? (c_total_delay / c_midi_clock_ctr) : 0; MIOS32_MIDI_SendDebugMessage("BPM %d.%d - tick min/avg/max = %d.%03d/%d.%03d/%d.%03d\n", bpm / 1000, bpm % 1000, c_d_tick.delay_min / 1000, c_d_tick.delay_min % 1000, avg / 1000, avg % 1000, c_d_tick.delay_max / 1000, c_d_tick.delay_max % 1000); } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { const char root_name[12*2] = "C C#D D#E F F#G G#A A#B "; // init LCD MIOS32_LCD_Clear(); // endless loop while( 1 ) { // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); if( display_update ) { display_update = 0; MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("Root: "); char *selected_root_name = (char *)&root_name[2*selected_root]; MIOS32_LCD_PrintChar(*selected_root_name++); MIOS32_LCD_PrintChar(*selected_root_name); MIOS32_LCD_CursorSet(0, 1); if( selected_scale == 0 ) { MIOS32_LCD_PrintString("No Scale "); } else { MIOS32_LCD_PrintString(SCALE_NameGet(selected_scale-1)); } } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { int i; struct ntp_tm tm; const char *month_names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char *weekday_names[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; mios32_sys_time_t t; char timestring[64]; // clear LCD screen MIOS32_LCD_Clear(); // endless loop: print status information on LCD while( 1 ) { // new message requested? // TODO: add FreeRTOS specific queue handling! u8 new_msg = PRINT_MSG_NONE; portENTER_CRITICAL(); // port specific FreeRTOS function to disable tasks (nested) if( print_msg ) { new_msg = print_msg; print_msg = PRINT_MSG_NONE; // clear request } portEXIT_CRITICAL(); // port specific FreeRTOS function to enable tasks (nested) switch( new_msg ) { case PRINT_MSG_INIT: MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("for details "); break; case PRINT_MSG_STATUS: { MIOS32_LCD_CursorSet(0, 0); // request status screen again (will stop once a new screen is requested by another task) print_msg = PRINT_MSG_STATUS; } break; } t = MIOS32_SYS_TimeGet(); // convert ntp seconds since 1900 into useful time structure ntp_tmtime(t.seconds, &tm); // honour dailight savings ntp_dst(&tm); MIOS32_LCD_FontInit((u8 *)GLCD_FONT_SMALL); MIOS32_LCD_CursorSet(15, 12); MIOS32_LCD_PrintFormattedString("%s %02d %s %04d %02d:%02d:%02d", weekday_names[tm.weekday], tm.day, month_names[tm.month-1], tm.year,tm.hour, tm.minute, tm.second); } }
///////////////////////////////////////////////////////////////////////////// // Customized HardFault Handler which prints out debugging informations ///////////////////////////////////////////////////////////////////////////// void HardFault_Handler_c(unsigned int * hardfault_args) { // from the book: "The definiteve guide to the ARM Cortex-M3" volatile unsigned int stacked_r0; volatile unsigned int stacked_r1; volatile unsigned int stacked_r2; volatile unsigned int stacked_r3; volatile unsigned int stacked_r12; volatile unsigned int stacked_lr; volatile unsigned int stacked_pc; volatile unsigned int stacked_psr; stacked_r0 = ((unsigned long) hardfault_args[0]); stacked_r1 = ((unsigned long) hardfault_args[1]); stacked_r2 = ((unsigned long) hardfault_args[2]); stacked_r3 = ((unsigned long) hardfault_args[3]); stacked_r12 = ((unsigned long) hardfault_args[4]); stacked_lr = ((unsigned long) hardfault_args[5]); stacked_pc = ((unsigned long) hardfault_args[6]); stacked_psr = ((unsigned long) hardfault_args[7]); MIOS32_MIDI_SendDebugMessage("Hard Fault PC = %08x\n", stacked_pc); // ensure that at least the PC will be sent MIOS32_MIDI_SendDebugMessage("==================\n"); MIOS32_MIDI_SendDebugMessage("!!! HARD FAULT !!!\n"); MIOS32_MIDI_SendDebugMessage("==================\n"); MIOS32_MIDI_SendDebugMessage("R0 = %08x\n", stacked_r0); MIOS32_MIDI_SendDebugMessage("R1 = %08x\n", stacked_r1); MIOS32_MIDI_SendDebugMessage("R2 = %08x\n", stacked_r2); MIOS32_MIDI_SendDebugMessage("R3 = %08x\n", stacked_r3); MIOS32_MIDI_SendDebugMessage("R12 = %08x\n", stacked_r12); MIOS32_MIDI_SendDebugMessage("LR = %08x\n", stacked_lr); MIOS32_MIDI_SendDebugMessage("PC = %08x\n", stacked_pc); MIOS32_MIDI_SendDebugMessage("PSR = %08x\n", stacked_psr); MIOS32_MIDI_SendDebugMessage("BFAR = %08x\n", (*((volatile unsigned long *)(0xE000ED38)))); MIOS32_MIDI_SendDebugMessage("CFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED28)))); MIOS32_MIDI_SendDebugMessage("HFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED2C)))); MIOS32_MIDI_SendDebugMessage("DFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED30)))); MIOS32_MIDI_SendDebugMessage("AFSR = %08x\n", (*((volatile unsigned long *)(0xE000ED3C)))); #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("!! HARD FAULT !!"); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("at PC=0x%08x", stacked_pc); #endif _abort(); }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // init LCD MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("for details "); // endless loop while( 1 ) { // do nothing } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // clear LCD MIOS32_LCD_Clear(); // print text MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("READY."); // endless loop while( 1 ) { // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // clear LCD screen MIOS32_LCD_Clear(); // endless loop: print status information on LCD while( 1 ) { // new message requested? // TODO: add FreeRTOS specific queue handling! u8 new_msg = PRINT_MSG_NONE; portENTER_CRITICAL(); // port specific FreeRTOS function to disable tasks (nested) if( print_msg ) { new_msg = print_msg; print_msg = PRINT_MSG_NONE; // clear request } portEXIT_CRITICAL(); // port specific FreeRTOS function to enable tasks (nested) switch( new_msg ) { case PRINT_MSG_INIT: MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("for details "); break; case PRINT_MSG_STATUS: { MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintFormattedString("A%3d M%3d D%3d", seq_midi_out_allocated, seq_midi_out_max_allocated, seq_midi_out_dropouts); MIOS32_LCD_CursorSet(0, 1); if( benchmark_cycles == 0xffffffff ) MIOS32_LCD_PrintFormattedString("Time: overrun "); else MIOS32_LCD_PrintFormattedString("Time: %5d.%d mS ", benchmark_cycles/10, benchmark_cycles%10); // request status screen again (will stop once a new screen is requested by another task) print_msg = PRINT_MSG_STATUS; } break; } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // print static screen MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); // clear LCD MIOS32_LCD_Clear(); u8 last_touchpanel_x = 0; u8 last_touchpanel_y = 0; // endless loop - LED will flicker on each iteration while( 1 ) { // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); // check for X/Y coordinate changes if( touchpanel_x != last_touchpanel_x || touchpanel_y != last_touchpanel_y ) { // clear marker at last position MIOS32_LCD_GCursorSet(last_touchpanel_x, last_touchpanel_y / 2); MIOS32_LCD_PrintChar(' '); // clear coordinate at the left/right side if required if( (last_touchpanel_x < 64 && touchpanel_x >= 64) || (last_touchpanel_x >= 64 && touchpanel_x < 64) ) { MIOS32_LCD_GCursorSet((last_touchpanel_x < 64) ? 128-5*6 : 0, 0*8); MIOS32_LCD_PrintString(" "); MIOS32_LCD_GCursorSet((last_touchpanel_x < 64) ? 128-5*6 : 0, 1*8); MIOS32_LCD_PrintString(" "); } // set marker at new position MIOS32_LCD_GCursorSet(touchpanel_x, touchpanel_y / 2); MIOS32_LCD_PrintChar('x'); // print new coordinates MIOS32_LCD_GCursorSet((touchpanel_x < 64) ? 128-5*6 : 0, 0*8); MIOS32_LCD_PrintFormattedString("X:%3d", touchpanel_x); MIOS32_LCD_GCursorSet((touchpanel_x < 64) ? 128-5*6 : 0, 1*8); MIOS32_LCD_PrintFormattedString("Y:%3d", touchpanel_y); // store new position last_touchpanel_x = touchpanel_x; last_touchpanel_y = touchpanel_y; } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // init LCD MIOS32_LCD_Clear(); // endless loop: print status information on LCD while( 1 ) { // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); // print text on LCD screen MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintFormattedString("DIN Pin #%3d %c", last_din_pin, last_din_value ? 'o' : '*'); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("Enc. #%2d (%s)", last_enc, last_enc_dir ? "Right" : "Left "); } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // init LCD MIOS32_LCD_Clear(); // endless loop: print status information on LCD while( 1 ) { // new message requested? // TODO: add FreeRTOS specific queue handling! u8 new_msg = PRINT_MSG_NONE; portENTER_CRITICAL(); // port specific FreeRTOS function to disable IRQs (nested) if( print_msg ) { new_msg = print_msg; print_msg = PRINT_MSG_NONE; // clear request } portEXIT_CRITICAL(); // port specific FreeRTOS function to enable IRQs (nested) switch( new_msg ) { case PRINT_MSG_INIT: MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintFormattedString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("for details "); break; case PRINT_MSG_SELECTIONS: { // waveform names const u8 waveform_name[SYNTH_NUM_WAVEFORMS][4] = { "Tri", "Saw", "Pul", "Sin" }; MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintFormattedString(" L R "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString(" %s %s ", waveform_name[SYNTH_WaveformGet(0)], waveform_name[SYNTH_WaveformGet(1)]); } break; } } }
///////////////////////////////////////////////////////////////////////////// //! Initializes LCD driver //! \param[in] mode currently only mode 0 supported //! \return < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 MIOS32_LCD_Init(u32 mode) { s32 ret; // currently only mode 0 supported if( mode != 0 ) return -1; // unsupported mode // fetch config from BSL info range MIOS32_LCD_ParametersFetchFromBslInfoRange(); // disable font bitmap font_bitmap.width = 0; // set initial cursor map for character LCDs u8 cursor_map[] = {0x00, 0x40, 0x14, 0x54}; // offset line 0/1/2/3 MIOS32_LCD_CursorMapSet(cursor_map); // note: this has to be done before APP_LCD_Init() is called, so that // the driver is able to modify the default cursor mapping // usage example: "dog" LCDs #if !defined(MIOS32_FAMILY_EMULATION) // initial delay - some LCDs need this! MIOS32_DELAY_Wait_uS(50000); #endif // call application specific init function if( (ret=APP_LCD_Init(mode)) < 0 ) return ret; // clear screen MIOS32_LCD_Clear(); // set character and graphical cursor to initial position MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_GCursorSet(0, 0); return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // print static screen MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); // clear LCD MIOS32_LCD_Clear(); // endless loop - LED will flicker on each iteration while( 1 ) { // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); // X/Y "position" of displays (see also comments in $MIOS32_PATH/modules/app_lcd/pcd8544/README.txt) const u8 lcd_x[8] = {0, 1, 2, 0, 1, 2, 0, 1}; // CS#0..7 const u8 lcd_y[8] = {0, 0, 0, 1, 1, 1, 2, 2}; u8 i; for(i=0; i<8; ++i) { u8 x_offset = 84*lcd_x[i]; u8 y_offset = 6*8*lcd_y[i]; // print text MIOS32_LCD_GCursorSet(x_offset + 0, y_offset + 0*8); MIOS32_LCD_PrintFormattedString(" PCD8544 #%d", i+1); MIOS32_LCD_GCursorSet(x_offset + 0, y_offset + 2*8); MIOS32_LCD_PrintString(" powered by "); MIOS32_LCD_FontInit((u8 *)GLCD_FONT_BIG); MIOS32_LCD_GCursorSet(x_offset + 0, y_offset + 3*8); MIOS32_LCD_PrintString("MIOS"); MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_GCursorSet(x_offset + 64, y_offset + 4*8); MIOS32_LCD_PrintString("32"); } } }
///////////////////////////////////////////////////////////////////////////// // enabled in FreeRTOSConfig.h ///////////////////////////////////////////////////////////////////////////// void vApplicationMallocFailedHook(void) { #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("FATAL: FreeRTOS "); // 16 chars MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("Malloc Error!!! "); // 16 chars #endif #ifndef MIOS32_DONT_USE_MIDI // Note: message won't be sent if MIDI task cannot be created! MIOS32_MIDI_SendDebugMessage("FATAL: FreeRTOS Malloc Error!!!\n"); #endif _abort(); }
///////////////////////////////////////////////////////////////////////////// // _exit() for newer newlib versions ///////////////////////////////////////////////////////////////////////////// void exit(int par) { #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("Goodbye!"); #endif #ifndef MIOS32_DONT_USE_MIDI // Note: message won't be sent if MIDI task cannot be created! MIOS32_MIDI_SendDebugMessage("Goodbye!\n"); #endif // pro forma: since this is a noreturn function, loop endless and call _abort (which will never exit) while( 1 ) _abort(); }
void vApplicationStackOverflowHook(xTaskHandle xTask, signed portCHAR *pcTaskName) { MIOS32_MIDI_SendDebugMessage("======================\n"); MIOS32_MIDI_SendDebugMessage("!!! STACK OVERFLOW !!!\n"); MIOS32_MIDI_SendDebugMessage("======================\n"); MIOS32_MIDI_SendDebugMessage("Function: %s\n", pcTaskName); #ifndef MIOS32_DONT_USE_LCD // TODO: here we should select the normal font - but only if available! // MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); MIOS32_LCD_DeviceSet(0); MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("!! STACK OVERFLOW !!"); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("in Task %s", pcTaskName); #endif _abort(); }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // clear LCD screen MIOS32_LCD_Clear(); // endless loop: print status information on LCD while( 1 ) { // new message requested? // TODO: add FreeRTOS specific queue handling! u8 new_msg = PRINT_MSG_NONE; portENTER_CRITICAL(); // port specific FreeRTOS function to disable tasks (nested) if( print_msg ) { new_msg = print_msg; print_msg = PRINT_MSG_NONE; // clear request } portEXIT_CRITICAL(); // port specific FreeRTOS function to enable tasks (nested) switch( new_msg ) { case PRINT_MSG_INIT: MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintString("see README.txt "); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintString("for details "); break; case PRINT_MSG_STATUS: { MIOS32_LCD_CursorSet(0, 0); // request status screen again (will stop once a new screen is requested by another task) print_msg = PRINT_MSG_STATUS; } break; } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { int num_lcds = mios32_lcd_parameters.num_x * mios32_lcd_parameters.num_y; // print configured LCD parameters MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("Multi-CLCD Demo started."); MIOS32_MIDI_SendDebugMessage("Configured LCD Parameters in MIOS32 Bootloader Info Range:\n"); MIOS32_MIDI_SendDebugMessage("lcd_type: 0x%02x (%s)\n", mios32_lcd_parameters.lcd_type, MIOS32_LCD_LcdTypeName(mios32_lcd_parameters.lcd_type)); MIOS32_MIDI_SendDebugMessage("num_x: %4d\n", mios32_lcd_parameters.num_x); MIOS32_MIDI_SendDebugMessage("num_y: %4d\n", mios32_lcd_parameters.num_y); MIOS32_MIDI_SendDebugMessage("width: %4d\n", mios32_lcd_parameters.width); MIOS32_MIDI_SendDebugMessage("height: %4d\n", mios32_lcd_parameters.height); if( mios32_lcd_parameters.lcd_type != MIOS32_LCD_TYPE_CLCD && mios32_lcd_parameters.lcd_type != MIOS32_LCD_TYPE_CLCD_DOG ) { // print warning if correct LCD hasn't been selected MIOS32_MIDI_SendDebugMessage("WARNING: your core module hasn't been configured for CLCD or CLCD_DOG!\n"); MIOS32_MIDI_SendDebugMessage("Please do this with the bootloader update application!\n"); } // initialize all LCDs (although programming_models/traditional/main.c will only initialize the first two) int lcd; for(lcd=0; lcd<num_lcds; ++lcd) { MIOS32_MIDI_SendDebugMessage("Initialize LCD #%d\n", lcd+1); MIOS32_LCD_DeviceSet(lcd); if( MIOS32_LCD_Init(0) < 0 ) { MIOS32_MIDI_SendDebugMessage("Failed - no response from LCD #%d.%d\n", (lcd % mios32_lcd_parameters.num_x) + 1, (lcd / mios32_lcd_parameters.num_x) + 1); } } // init special characters for all LCDs for(lcd=0; lcd<num_lcds; ++lcd) { MIOS32_LCD_DeviceSet(lcd); MIOS32_LCD_SpecialCharsInit((u8 *)charset_vert_bars); MIOS32_LCD_Clear(); } // print text on all LCDs for(lcd=0; lcd<num_lcds; ++lcd) { MIOS32_LCD_DeviceSet(lcd); MIOS32_LCD_CursorSet(0, 0); MIOS32_LCD_PrintFormattedString("LCD #%d.%d", (lcd % mios32_lcd_parameters.num_x) + 1, (lcd / mios32_lcd_parameters.num_x) + 1); MIOS32_LCD_CursorSet(0, 1); MIOS32_LCD_PrintFormattedString("READY."); } // print animated vertical bar while( 1 ) { int i, j; for(i=0; i<8; ++i) { // print vertical bars depending on i for(lcd=0; lcd<num_lcds; ++lcd) { MIOS32_LCD_DeviceSet(lcd); MIOS32_LCD_CursorSet(12, 0); for(j=0; j<8; ++j) { u8 c = (i + j) % 8; MIOS32_LCD_PrintChar(c); } } // wait for 100 mS for(j=0; j<100; ++j) MIOS32_DELAY_Wait_uS(1000); } } }
static void TASK_Display(void *pvParameters){ char * err_on; s32 msg_countdown = 0; while(1){ switch(phase){ case BS_CHECK_PHASE_STARTWAIT: if(msg_countdown != -phase){ MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0,0); MIOS32_LCD_PrintString("Bankstick check"); MIOS32_LCD_CursorSet(0,1); MIOS32_LCD_PrintString("Push a button/key.."); MIOS32_MIDI_SendDebugMessage("Push any button or MIDI-key to start the check.."); msg_countdown = -phase; } break; case BS_CHECK_PHASE_START: msg_countdown = -phase; phase = BS_CHECK_PHASE_INIT; break; case BS_CHECK_PHASE_WRITE: MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0,0); MIOS32_LCD_PrintFormattedString("Write blocks 0x%04X",block); MIOS32_LCD_CursorSet(0,1); MIOS32_LCD_PrintFormattedString("Bankstick %d, Run %d",bs,run+1); if(msg_countdown <= 0){ MIOS32_MIDI_SendDebugMessage("Write blocks 0x%04X (bankstick %d, run %d)",block,bs,run+1); msg_countdown = 0;// restart message countdown if it was disabled } break; case BS_CHECK_PHASE_READ: MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0,0); MIOS32_LCD_PrintFormattedString("Read blocks 0x%04X",block); MIOS32_LCD_CursorSet(0,1); MIOS32_LCD_PrintFormattedString("Bankstick %d, Run %d",bs,run+1); if(msg_countdown <= 0){ MIOS32_MIDI_SendDebugMessage("Read blocks 0x%04X (bankstick %d, run %d)",block,bs,run+1); msg_countdown = 0;// restart message countdown if it was disabled } break; case BS_CHECK_PHASE_FINISHED: if(msg_countdown != -phase){// was this stuff already printed/ sent do debug condsole? msg_countdown = -phase;// disable further message output in this phase MIOS32_LCD_Clear(); MIOS32_LCD_CursorSet(0,0); if(last_error){ switch(last_error){ case BS_CHECK_ERROR_AVAILABLE: err_on = "available"; break; case BS_CHECK_ERROR_INIT: err_on = "init"; break; case BS_CHECK_ERROR_WRITE: err_on = "write"; break; case BS_CHECK_ERROR_CHECK_WRITE_FINISHED: err_on = "write wait"; break; case BS_CHECK_ERROR_READ: err_on = "read"; break; case BS_CHECK_ERROR_COMPARE: err_on = "compare"; break; } MIOS32_LCD_PrintFormattedString("Err: %s %d",err_on,last_error_code); MIOS32_LCD_CursorSet(0,1); MIOS32_LCD_PrintFormattedString("BS:%d B:0x%04x R:%d",bs,block,run); MIOS32_MIDI_SendDebugMessage("Error on %s, Error code %d, Bankstick %d, Block %d, Run %d", err_on,last_error_code,bs,block,run); } else{ MIOS32_LCD_PrintFormattedString("Bankstick check"); MIOS32_LCD_CursorSet(0,1); MIOS32_LCD_PrintFormattedString("success (%d runs)",BS_CHECK_NUM_RUNS); MIOS32_MIDI_SendDebugMessage("Banstick check finished successfully (%d runs)!",BS_CHECK_NUM_RUNS); } MIOS32_MIDI_SendDebugMessage("Push any button or MIDI-key to re-start the check.."); } break; } // if msg_countdown is < 0, don't change it (used to stop further message output by phase) if(msg_countdown >= 0) msg_countdown = msg_countdown ? msg_countdown - 1 : DISPLAY_TASK_MSG_COUNTDOWN_STARTVALUE; // wait DISPLAY_TASK_DELAY mS vTaskDelay(DISPLAY_TASK_DELAYMS / portTICK_RATE_MS); } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { // print static screen MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0x000000); MIOS32_LCD_FColourSet(0xffffff); // clear LCD MIOS32_LCD_Clear(); // print text MIOS32_LCD_CursorSet(3, 3); MIOS32_LCD_PrintString("ST7637 LCD"); MIOS32_LCD_CursorSet(7, 5); MIOS32_LCD_PrintString("powered by"); // endless loop: print animations u8 mios_r = 0; u8 mios_g = 0; u8 mios_b = 0; u8 dir = 1; u8 knob_icon_ctr[4] = {0, 3, 6, 9}; // memo: 12 icons u8 knob_icon_delay_ctr[4] = {0, 2, 4, 6}; const u8 knob_icon_x[4] = {0, 100, 0, 100}; // memo: icon width 28 const u8 knob_icon_y[4] = {0, 0, 104, 104}; // memo: icon height 24 u8 vmeter_icon_ctr[2] = {0, 5}; // memo: 28 icons (14 used) u8 vmeter_icon_dir[2] = {1, 1}; u8 vmeter_icon_delay_ctr[2] = {1, 4}; const u8 vmeter_icon_x[2] = {0, 120}; // memo: icon width 8 const u8 vmeter_icon_y[2] = {48, 48}; // memo: icon height 32 u8 hmeter_icon_ctr[2] = {6, 11}; // memo: 28 icons (14 used) u8 hmeter_icon_dir[2] = {1, 0}; u8 hmeter_icon_delay_ctr[2] = {4, 2}; const u8 hmeter_icon_x[2] = {50, 50}; // memo: icon width 28 const u8 hmeter_icon_y[2] = {0, 120}; // memo: icon height 8 while( 1 ) { s32 i; // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); // colour-cycle "MIOS32" up and down :-) // ST7637 supports 5bit r, 6bit g and 5bit b if( dir ) { if( mios_r < 0x1f ) ++mios_r; else if( mios_g < 0x3f ) ++mios_g; else if( mios_b < 0x1f ) ++mios_b; else dir = 0; } else { if( mios_r > 0x00 ) --mios_r; else if( mios_g > 0x00 ) --mios_g; else if( mios_b > 0x00 ) --mios_b; else dir = 1; } // set new colour MIOS32_LCD_FColourSet((mios_r << 16) | (mios_g << 8) | mios_b); // print "MIOS32" MIOS32_LCD_FontInit((u8 *)GLCD_FONT_BIG); MIOS32_LCD_GCursorSet(16, 52); MIOS32_LCD_PrintString("MIOS32"); // icons with different colour MIOS32_LCD_FColourSet(((dir?mios_r:~mios_r) << 16) | (~mios_g << 8) | (dir?mios_b:~mios_b)); // print turning Knob icons at all edges MIOS32_LCD_FontInit((u8 *)GLCD_FONT_KNOB_ICONS); // memo: 12 icons, icon size: 28x24 for(i=0; i<4; ++i) { if( ++knob_icon_delay_ctr[i] > 10 ) { knob_icon_delay_ctr[i] = 0; if( ++knob_icon_ctr[i] >= 12 ) knob_icon_ctr[i] = 0; } MIOS32_LCD_GCursorSet(knob_icon_x[i], knob_icon_y[i]); MIOS32_LCD_PrintChar(knob_icon_ctr[i]); } // print vmeter icons MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_V); // memo: 28 icons, 14 used, icon size: 8x32 for(i=0; i<2; ++i) { if( ++vmeter_icon_delay_ctr[i] > 5 ) { vmeter_icon_delay_ctr[i] = 0; if( vmeter_icon_dir[i] ) { if( ++vmeter_icon_ctr[i] >= 13 ) vmeter_icon_dir[i] = 0; } else { if( --vmeter_icon_ctr[i] < 1 ) vmeter_icon_dir[i] = 1; } } MIOS32_LCD_GCursorSet(vmeter_icon_x[i], vmeter_icon_y[i]); MIOS32_LCD_PrintChar(vmeter_icon_ctr[i]); } // print hmeter icons MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_H); // memo: 28 icons, 14 used, icon size: 28x8 for(i=0; i<2; ++i) { if( ++hmeter_icon_delay_ctr[i] > 7 ) { hmeter_icon_delay_ctr[i] = 0; if( hmeter_icon_dir[i] ) { if( ++hmeter_icon_ctr[i] >= 13 ) hmeter_icon_dir[i] = 0; } else { if( --hmeter_icon_ctr[i] < 1 ) hmeter_icon_dir[i] = 1; } } MIOS32_LCD_GCursorSet(hmeter_icon_x[i], hmeter_icon_y[i]); MIOS32_LCD_PrintChar(hmeter_icon_ctr[i]); } } }
///////////////////////////////////////////////////////////////////////////// // This task handles the control surface ///////////////////////////////////////////////////////////////////////////// static void TASK_Period_1mS_LP(void *pvParameters) { u16 sdcard_check_ctr = 0; MIOS32_LCD_Clear(); while( 1 ) { vTaskDelay(1 / portTICK_RATE_MS); // call SCS handler SCS_Tick(); // each second: check if SD Card (still) available if( ++sdcard_check_ctr >= 1000 ) { sdcard_check_ctr = 0; MUTEX_SDCARD_TAKE; s32 status = FILE_CheckSDCard(); if( status == 1 ) { DEBUG_MSG("SD Card connected: %s\n", FILE_VolumeLabel()); // load all file infos SYNTH_FILE_LoadAllFiles(1); // including HW info } else if( status == 2 ) { DEBUG_MSG("SD Card disconnected\n"); // invalidate all file infos SYNTH_FILE_UnloadAllFiles(); // change status SYNTH_FILE_StatusMsgSet("No SD Card"); } else if( status == 3 ) { if( !FILE_SDCardAvailable() ) { DEBUG_MSG("SD Card not found\n"); SYNTH_FILE_StatusMsgSet("No SD Card"); } else if( !FILE_VolumeAvailable() ) { DEBUG_MSG("ERROR: SD Card contains invalid FAT!\n"); SYNTH_FILE_StatusMsgSet("No FAT"); } else { int bank; for(bank=0; bank<SYNTH_FILE_B_NUM_BANKS; ++bank) { u8 numPatches = SYNTH_FILE_B_NumPatches(bank); if( numPatches ) { DEBUG_MSG("Bank #%d contains %d patches\n", bank+1, numPatches); } else { DEBUG_MSG("Bank #%d not found - creating new one\n", bank+1); if( (status=SYNTH_FILE_B_Create(bank)) < 0 ) { DEBUG_MSG("Failed to create Bank #%d (status: %d)\n", bank+1, status); } else { DEBUG_MSG("Bank #%d successfully created!\n", bank+1); int numPatches = SYNTH_FILE_B_NumPatches(bank); int patch; for(patch=0; patch<numPatches; ++patch) { DEBUG_MSG("Writing Bank %d Patch #%d\n", bank+1, patch+1); MIOS32_LCD_CursorSet(0, 0); // TMP - use message system later MIOS32_LCD_PrintFormattedString("Write Patch %d.%03d ", bank+1, patch+1); MIOS32_LCD_CursorSet(0, 1); // TMP - use message system later MIOS32_LCD_PrintFormattedString("Please wait... "); u8 sourceGroup = 0; u8 rename_if_empty_name = 0; if( (status=SYNTH_FILE_B_PatchWrite(bank, patch, sourceGroup, rename_if_empty_name)) < 0 ) { DEBUG_MSG("Failed to write patch #%d into bank #%d (status: %d)\n", patch+1, bank+1, status); } } SCS_DisplayUpdateRequest(); } } } // disable status message and print patch SYNTH_FILE_StatusMsgSet(NULL); status = SYNTH_FILE_UnloadAllFiles(); status = SYNTH_FILE_LoadAllFiles(1); if( status < 0 ) { DEBUG_MSG("Failed to load the newly created files!\n"); } else { u8 initialBank = 0; u8 initialPatch = 0; u8 targetGroup = 0; if( (status=SYNTH_FILE_B_PatchRead(initialBank, initialPatch, targetGroup)) < 0 ) { char buffer[100]; sprintf(buffer, "Patch %c%03d", 'A'+initialBank, initialPatch+1); SCS_Msg(SCS_MSG_ERROR_L, 1000, "Failed to read", buffer); } else { // char buffer[100]; // sprintf(buffer, "Patch %c%03d", 'A'+initialBank, initialPatch+1); // SCS_Msg(SCS_MSG_L, 1000, buffer, "read!"); } } } } MUTEX_SDCARD_GIVE; } } }
///////////////////////////////////////////////////////////////////////////// // This task is running endless in background ///////////////////////////////////////////////////////////////////////////// void APP_Background(void) { #define MAX_LCDS 16 int num_lcds = mios32_lcd_parameters.num_x * mios32_lcd_parameters.num_y; if( num_lcds > MAX_LCDS ) { MIOS32_MIDI_SendDebugMessage("WARNING: this application only supports up to 16 displays!\n"); num_lcds = MAX_LCDS; } // clear LCDs { u8 n; for(n=0; n<num_lcds; ++n) { MIOS32_LCD_DeviceSet(n); MIOS32_LCD_Clear(); } } u8 vmeter_icon_ctr[MAX_LCDS][2] = {{0,5},{3,14},{7,1},{3,9},{13,6},{10,2},{1,4},{6,2},{13,6},{10,2},{1,4},{6,2},{1,2},{13,14},{5,5},{6,1}}; // memo: 28 icons (14 used) u8 vmeter_icon_dir[MAX_LCDS][2] = {{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,1}}; u8 vmeter_icon_delay_ctr[MAX_LCDS][2] = {{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4},{1,4}}; const u8 vmeter_icon_x[2] = {0, 120}; // memo: icon width 8 const u8 vmeter_icon_y[2] = {12, 12}; // memo: icon height 32 u8 hmeter_icon_ctr[MAX_LCDS][2] = {{6,11},{2,27},{23,1},{15,6},{18,9},{10,12},{3,25},{26,7},{18,9},{10,12},{3,25},{26,7},{6,9},{18,18},{20,10},{3,10}}; // memo: 28 icons (14 used) u8 hmeter_icon_dir[MAX_LCDS][2] = {{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0}}; u8 hmeter_icon_delay_ctr[MAX_LCDS][2] = {{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2},{4,2}}; const u8 hmeter_icon_x[2] = {20, 80}; // memo: icon width 28 const u8 hmeter_icon_y[2] = {60, 60}; // memo: icon height 8 // print configured LCD parameters MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("SSD1306 Demo started."); MIOS32_MIDI_SendDebugMessage("Configured LCD Parameters in MIOS32 Bootloader Info Range:\n"); MIOS32_MIDI_SendDebugMessage("lcd_type: 0x%02x (%s)\n", mios32_lcd_parameters.lcd_type, MIOS32_LCD_LcdTypeName(mios32_lcd_parameters.lcd_type)); MIOS32_MIDI_SendDebugMessage("num_x: %4d\n", mios32_lcd_parameters.num_x); MIOS32_MIDI_SendDebugMessage("num_y: %4d\n", mios32_lcd_parameters.num_y); MIOS32_MIDI_SendDebugMessage("width: %4d\n", mios32_lcd_parameters.width); MIOS32_MIDI_SendDebugMessage("height: %4d\n", mios32_lcd_parameters.height); MIOS32_MIDI_SendDebugMessage("Testing %d LCDs\n", num_lcds); if( mios32_lcd_parameters.lcd_type != MIOS32_LCD_TYPE_GLCD_SSD1306 && mios32_lcd_parameters.lcd_type != MIOS32_LCD_TYPE_GLCD_SSD1306_ROTATED ) { // print warning if correct LCD hasn't been selected MIOS32_MIDI_SendDebugMessage("WARNING: your core module hasn't been configured for the SSD1306 GLCD!\n"); MIOS32_MIDI_SendDebugMessage("Please do this with the bootloader update application!\n"); } // print static screen MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); // endless loop - LED will flicker on each iteration while( 1 ) { // wait some mS MIOS32_DELAY_Wait_uS(10000); // toggle the state of all LEDs (allows to measure the execution speed with a scope) MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get()); u8 n; for(n=0; n<num_lcds; ++n) { int i; #if 0 // X/Y "position" of displays const u8 lcd_x[MAX_LCDS] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; // CS#0..7 const u8 lcd_y[MAX_LCDS] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // X/Y "position" of displays u8 x_offset = 128*lcd_x[n]; u8 y_offset = 64*lcd_y[n]; #else // TK: expired! LCDs now addressed via MIOS32_LCD_DeviceSet() u8 x_offset = 0; u8 y_offset = 0; MIOS32_LCD_DeviceSet(n); #endif // print text MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_GCursorSet(x_offset + 6*6, y_offset + 1*8); MIOS32_LCD_PrintFormattedString("SSD1306 #%d", n+1); MIOS32_LCD_GCursorSet(x_offset + 6*6, y_offset + 2*8); MIOS32_LCD_PrintString("powered by "); MIOS32_LCD_FontInit((u8 *)GLCD_FONT_BIG); MIOS32_LCD_GCursorSet(x_offset + 3*6, y_offset + 3*8); MIOS32_LCD_PrintString("MIOS32"); // print vmeter icons MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_V); // memo: 28 icons, 14 used, icon size: 8x32 for(i=0; i<2; ++i) { if( ++vmeter_icon_delay_ctr[n][i] ) { vmeter_icon_delay_ctr[n][i] = 0; if( vmeter_icon_dir[n][i] ) { if( ++vmeter_icon_ctr[n][i] >= 13 ) vmeter_icon_dir[n][i] = 0; } else { if( --vmeter_icon_ctr[n][i] < 1 ) vmeter_icon_dir[n][i] = 1; } } MIOS32_LCD_GCursorSet(vmeter_icon_x[i]+x_offset, vmeter_icon_y[i]+y_offset); MIOS32_LCD_PrintChar(vmeter_icon_ctr[n][i]); } // print hmeter icons for(i=0; i<2; ++i) { MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_H); // memo: 28 icons, 14 used, icon size: 28x8 if( ++hmeter_icon_delay_ctr[n][i] > 7 ) { hmeter_icon_delay_ctr[n][i] = 0; if( hmeter_icon_dir[n][i] ) { if( ++hmeter_icon_ctr[n][i] >= 13 ) hmeter_icon_dir[n][i] = 0; } else { if( --hmeter_icon_ctr[n][i] < 1 ) hmeter_icon_dir[n][i] = 1; } } MIOS32_LCD_GCursorSet(hmeter_icon_x[i]+x_offset, hmeter_icon_y[i]+y_offset); MIOS32_LCD_PrintChar(hmeter_icon_ctr[n][i]); MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); if( i == 0 ) { MIOS32_LCD_GCursorSet(0+x_offset, hmeter_icon_y[i]+y_offset); MIOS32_LCD_PrintFormattedString("%d", hmeter_icon_ctr[n][i]*4); } else { MIOS32_LCD_GCursorSet(128-3*6+x_offset, hmeter_icon_y[i]+y_offset); MIOS32_LCD_PrintFormattedString("%3d", hmeter_icon_ctr[n][i]*4); } } } } }