/// \method set_orientation(a) /// /// Set orientation to 0, 90, 180 or 270 degrees /// STATIC mp_obj_t pyb_ugfx_set_orientation(mp_obj_t self_in, mp_obj_t value) { // extract arguments //pyb_ugfx_obj_t *self = args[0]; int a = mp_obj_get_int(value); if (a == 0) gdispSetOrientation(GDISP_ROTATE_0); else if (a == 90) gdispSetOrientation(GDISP_ROTATE_90); else if (a == 180) gdispSetOrientation(GDISP_ROTATE_180); else if (a == 270) gdispSetOrientation(GDISP_ROTATE_270); return mp_const_none; }
void benchmark(void) { uint32_t i, pixels, ms, pps; char pps_str[25]; coord_t height, width, rx, ry, rcx, rcy; color_t random_color; font_t font; gdispSetOrientation(GDISP_ROTATE_90); width = gdispGetWidth(); height = gdispGetHeight(); font = gdispOpenFont("UI2 Double"); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); font = gdispOpenFont("UI2"); gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter); gfxSleepMilliseconds(3000); /* seed for the rand() */ srand(DWT_CYCCNT); pixels = 0; CPU_RESET_CYCLECOUNTER; for (i = 0; i < 5000; i++) { random_color = (rand() % 65535); rx = (rand() % (width-10)); ry = (rand() % (height-10)); rcx = (rand() % ((width-rx)-10))+10; rcy = (rand() % ((height-ry)-10))+10; gdispFillArea(rx, ry, rcx, rcy, random_color); pixels += (rcx+1)*(rcy+1); } ms = DWT_CYCCNT / 168000; pps = (float)pixels/((float)ms/1000.0f); memset (pps_str, 0, sizeof(pps_str)); uitoa(pps, pps_str, sizeof(pps_str)); strcat(pps_str, " Pixels/s"); font = gdispOpenFont("UI2 Double"); gdispClear(Black); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); gdispDrawStringBox(0, height/2, width, 30, pps_str, font, White, justifyCenter); //gdispDrawString(20, height/2, pps_str, font, White); }
int main(void) { color_t color = Black; uint16_t pen = 0; halInit(); chSysInit(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); while (TRUE) { ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) continue; /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }
int main(void) { float cx, cy; float zoom = 1.0f; halInit(); chSysInit(); gdispInit(); gdispSetOrientation(GDISP_ROTATE_270); /* where to zoom in */ cx = -0.086f; cy = 0.85f; while(TRUE) { mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy); zoom *= 0.7f; if(zoom <= 0.00001f) zoom = 1.0f; } }
int main(void) { halInit(); chSysInit(); gdispInit(); gdispSetOrientation(GDISP_ROTATE_90); gdispClear(Black); Graph G1 = { gdispGetWidth()/2, gdispGetHeight()/2, -150, 150, -110, 110, 21, 5, TRUE, TRUE, White, Grey, }; graphDrawSystem(&G1); uint16_t i; for(i = 0; i < 2500; i++) graphDrawDot(&G1, i-170, 80*sin(2*0.2*M_PI*i/180), 1, Blue); for(i = 0; i < 2500; i++) graphDrawDot(&G1, i/5-150, 95*sin(2*0.2*M_PI*i/180), 1, Green); while(TRUE) { chThdSleepMilliseconds(100); } }
bool_t ginputCalibrateMouse(uint16_t instance) { #if !GINPUT_MOUSE_NEED_CALIBRATION (void) instance; return FALSE; #else const coord_t height = gdispGetHeight(); const coord_t width = gdispGetWidth(); const MousePoint cross[] = {{(width / 4), (height / 4)}, {(width - (width / 4)) , (height / 4)}, {(width - (width / 4)) , (height - (height / 4))}, {(width / 2), (height / 2)}}; /* Check point */ MousePoint points[GINPUT_MOUSE_CALIBRATION_POINTS]; const MousePoint *pc; MousePoint *pt; int32_t px, py; unsigned i, j; font_t font1, font2; #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 unsigned err; #endif if (instance || (MouseConfig.flags & FLG_IN_CAL)) return FALSE; font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT); font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2); MouseConfig.flags |= FLG_IN_CAL; gtimerStop(&MouseTimer); MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED); #if GDISP_NEED_CONTROL gdispSetOrientation(GDISP_ROTATE_0); #endif #if GDISP_NEED_CLIP gdispSetClip(0, 0, width, height); #endif #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 while(1) { #endif gdispClear(Blue); gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { _tsDrawCross(pc); do { /* Wait for the mouse to be pressed */ while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT)) chThdSleepMilliseconds(20); /* Average all the samples while the mouse is down */ for(px = py = 0, j = 0; chThdSleepMilliseconds(20), /* Settling time between readings */ get_raw_reading(&MouseConfig.t), (MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT); j++) { px += MouseConfig.t.x; py += MouseConfig.t.y; } } while(!j); pt->x = px / j; pt->y = py / j; _tsClearCross(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); gdispFillArea(0, 35, width, 40, Blue); } } /* Apply 3 point calibration algorithm */ _tsDo3PointCalibration(cross, points, &MouseConfig.caldata); /* Verification of correctness of calibration (optional) : * See if the 4th point (Middle of the screen) coincides with the calibrated * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration * Else, start from the beginning. */ #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 /* Transform the co-ordinates */ MouseConfig.t.x = points[3].x; MouseConfig.t.y = points[3].y; _tsTransform(&MouseConfig.t, &MouseConfig.caldata); /* Calculate the delta */ err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) + (MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y); if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) break; gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); } #endif // Restart everything gdispCloseFont(font1); gdispCloseFont(font2); MouseConfig.flags |= FLG_CAL_OK; MouseConfig.last_buttons = 0; get_calibrated_reading(&MouseConfig.t); MouseConfig.flags &= ~FLG_IN_CAL; if ((MouseConfig.flags & FLG_INIT_DONE)) gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); // Save the calibration data (if possible) if (MouseConfig.fnsavecal) { MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); MouseConfig.flags |= FLG_CAL_SAVED; } return TRUE; #endif }
/* * Application entry point. */ int main(void) { color_t color = Black; uint16_t pen = 0; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); palSetPadMode(GPIOC, 7, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOC, 8, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL); /* * Creates the blinker thread. */ (void)chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (TRUE) { ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) { chThdSleepMicroseconds(500); // Senza questo sleep l'USB non parte continue; } /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }
/* * Application entry point. */ int main(void) { color_t color = Black; uint16_t pen = 0; Thread *shelltp = NULL; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) { chThdSleepMicroseconds(500); // Senza questo sleep l'USB non parte continue; } /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }