void system_setup(void) { clock_setup(); mco_setup(); usb_setup(); systick_setup(); rng_setup(); battery_setup(); speaker_setup(); jack_setup(); // setup pad and screen interface_setup(); // setup and reset SAM2695 sam2695_setup(); wait_ms(100); sam2695_reset(); usbmidi_setup(); // init gfx and fill screen gfx_init(ssd1306_drawpixel, SSD1306_WIDTH, SSD1306_HEIGHT, GFX_FONT_SMALL); gfx_setRotation(GFX_ROT_180); gfx_fillScreen(OLED_BLACK); gfx_setTextColor(OLED_WHITE, OLED_BLACK); // gfx_setTextWrap(1); gfx_setTextSize(1); ssd1306_display(); }
/* * This is the code for the simple DMA2D Demo * * Basically it lets you put display digits on the * screen manually or with the DMA2D peripheral. It * has various 'bling' levels, and it tracks performance * by measuring how long it takes to go from one frame * to the next. */ int main(void) { int i; uint32_t t1, t0; char buf[35]; char *scr_opt; int f_ndx = 0; float avg_frame; int can_switch; int opt, ds; /* Enable the clock to the DMA2D device */ rcc_periph_clock_enable(RCC_DMA2D); fprintf(stderr, "DMA2D Demo program : Digits Gone Wild\n"); printf("Generate background\n"); generate_background(); printf("Generate digits\n"); generate_digits(); gfx_init(lcd_draw_pixel, 800, 480, GFX_FONT_LARGE); opt = 0; /* screen clearing mode */ can_switch = 0; /* auto switching every 10 seconds */ t0 = mtime(); ds = 0; while (1) { switch (opt) { default: case 0: /* very slow way to clear the screen */ scr_opt = "manual clear"; gfx_fillScreen(0xffff); break; case 1: /* faster, using a tight loop */ scr_opt = "dedicated loop"; lcd_clear(0xff7f7f); break; case 2: /* fastest? Using DMA2D to fill screen */ scr_opt = "DMA 2D Fill"; dma2d_fill(0xff7fff7f); break; case 3: /* still fast, using DMA2D to pre-populate BG */ scr_opt = "DMA 2D Background"; dma2d_bgfill(); break; case 4: /* Now render all of the digits with DMA2D */ scr_opt = "DMA 2D Digits"; ds = 0; dma2d_bgfill(); break; case 5: /* still fast, using DMA2D to render drop shadows */ scr_opt = "DMA 2D Shadowed Digits"; ds = 1; dma2d_bgfill(); break; } /* This little state machine implements an automatic switch * every 10 seconds unless you've disabled it with the 'd' * command. */ if (((t0 / 1000) % 10 == 0) && (can_switch > 0)) { opt = (opt + 1) % MAX_OPTS; can_switch = 0; } else if (((t0 / 1000) % 10 != 0) && (can_switch == 0)) { can_switch = 1; } /* * The first four options (0, 1, 2, 3) all render the digits * in software every time, options 4 and 5 use the DMA2 * device to render the digits */ if (opt < 4) { display_clock(25, 20, mtime()); } else { dma2d_clock(25, 20, mtime(), ds); } for (i = 0; i < 10; i++) { if (opt < 4) { draw_digit(25 + i * (DISP_WIDTH + 8), 350, i, GFX_COLOR_GREEN, GFX_COLOR_BLACK); } else { if (ds) { dma2d_digit(35 + i * (DISP_WIDTH + 8), 360, i, SHADOW, SHADOW); } dma2d_digit(25 + i * (DISP_WIDTH + 8), 350, i, 0xff40c040, 0xff000000); } } /* In both cases we write the notes using the graphics library */ gfx_setTextColor(0, 0); gfx_setTextSize(3); gfx_setCursor(25, 30 + DISP_HEIGHT + gfx_getTextHeight() + 2); gfx_puts((unsigned char *)"Hello world for DMA2D!"); lcd_flip(te_lock); t1 = mtime(); /* this computes a running average of the last 10 frames */ frame_times[f_ndx] = t1 - t0; f_ndx = (f_ndx + 1) % N_FRAMES; for (i = 0, avg_frame = 0; i < N_FRAMES; i++) { avg_frame += frame_times[i]; } avg_frame = avg_frame / (float) N_FRAMES; snprintf(buf, 35, "FPS: %6.2f", 1000.0 / avg_frame); gfx_setCursor(25, 30 + DISP_HEIGHT + 2 * (gfx_getTextHeight() + 2)); gfx_puts((unsigned char *)buf); gfx_puts((unsigned char *)" "); gfx_setCursor(25, 30 + DISP_HEIGHT + 3 * (gfx_getTextHeight() + 2)); gfx_puts((unsigned char *)scr_opt); /* * The demo runs continuously but it watches for characters * typed at the console. There are a few options you can select. */ i = console_getc(0); switch (i) { case 's': opt = (opt + 1) % MAX_OPTS; printf("Switched to : %s\n", demo_options[opt]); break; case 'd': can_switch = -1; printf("Auto switching disabled\n"); break; case 'e': can_switch = 0; printf("Auto switching enabled\n"); break; case 't': te_lock = (te_lock == 0); printf("We are %s for the TE bit to be set\n", (te_lock) ? "WAITING" : "NOT WAITING"); break; default: printf("Options:\n"); printf("\ts - switch demo mode\n"); printf("\td - disable auto-switching of demo mode\n"); printf("\te - enable auto-switching of demo mode\n"); printf("\tt - enable/disable Tearing effect lock wait\n"); case 0: break; } t0 = t1; } }