====== 8. Vstup a výstup na výukovém kitu MZ_APO ====== {{.:lekce08-mz_apo.pdf|PDF}} [[https://gitlab.fel.cvut.cz/b35apo/apo-slides/-/tree/main/08-mz_apo|TeX]] === Další materiály === {{..:..:en:lectures:08:b35apo_lecture08-mz_apo.pdf|Input/Output on MZ_APO Education Kit}} {{..:..:en:lectures:08:b35apo_lecture08-mz_apo.pdf|ODP}} rgb_led.c /******************************************************************* RGB and HSV colorspace conversion and led example (C) 2021 Petr Štěpán Part of study materisal of B35APO Computer Architectures course https://cw.fel.cvut.cz/wiki/courses/b35apo/start license: any combination of GPL, LGPL, MPL or BSD licenses *******************************************************************/ #define _POSIX_C_SOURCE 200112L #include #include #include #include #include #include "mzapo_parlcd.h" #include "mzapo_phys.h" #include "mzapo_regs.h" unsigned int hsv2rgb(int hue, int saturation, int value) { hue = (hue%360); float f = ((hue%60)/60.0); int p = (value*(255-saturation))/255; int q = (value*(255-(saturation*f)))/255; int t = (value*(255-(saturation*(1.0-f))))/255; unsigned int r,g,b; if (hue < 60){ r = value; g = t; b = p; } else if (hue < 120) { r = q; g = value; b = p; } else if (hue < 180) { r = p; g = value; b = t; } else if (hue < 240) { r = p; g = q; b = value; } else if (hue < 300) { r = t; g = p; b = value; } else { r = value; g = p; b = q; } return ((r<<16)|(g<<8)|b); } int main(int argc, char *argv[]) { unsigned char *mem_base; /* * Setup memory mapping which provides access to the peripheral * registers region of RGB LEDs, knobs and line of yellow LEDs. */ mem_base = map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0); /* If mapping fails exit with error code */ if (mem_base == NULL) exit(1); printf("Hello\n"); struct timespec loop_delay = {.tv_sec = 0, .tv_nsec = 20 * 1000 * 1000}; int hue, sat=256, val=10; for (hue=0; hue<360; hue+=15) { printf("Hue is: %i\n", hue); for (val=90; val>=0; val-=3) { uint32_t col = hsv2rgb(hue, sat, val); *(volatile uint32_t*)(mem_base + SPILED_REG_LED_RGB1_o) = col; clock_nanosleep(CLOCK_MONOTONIC, 0, &loop_delay, NULL); } } printf("Goodbye\n"); return 0; } flying_letters.c \\ Následující kód je ukázka implementace pro otestování a inspiraci, **není ale určený ke kopírování do semestrálních prací**. Je zjednodušený, řeší jen fonty s šířkou do 16 bodů. Přitom je účelem, aby si studenti vyzkoušeli napsat kód vlastní a vyzkoušeli si bitové operace a maskování. Pro běh v LS 2020/2021 bude kopie ještě tolerovaná, v **další bězích** bude tento kód vložený jako **nedovolený** vzor do systému detekce **plagiátů**. /******************************************************************* Flying letter example (C) 2021 Petr Štěpán Part of study materisal of B35APO Computer Architectures course https://cw.fel.cvut.cz/wiki/courses/b35apo/start This example is not intended to be included in students semester works. You can study it and inspire yourself, but actual implementation should be implemented from scratch. You can copy function names but never the bodies of the fuctions. license: any combination of GPL, LGPL, MPL or BSD licenses *******************************************************************/ #define _POSIX_C_SOURCE 200112L #include #include #include #include #include #include #include "mzapo_parlcd.h" #include "mzapo_phys.h" #include "mzapo_regs.h" #include "font_types.h" #define M_PI 3.1415 unsigned int hsv2rgb_lcd(int hue, int saturation, int value) { hue = (hue%360); float f = ((hue%60)/60.0); int p = (value*(255-saturation))/255; int q = (value*(255-(saturation*f)))/255; int t = (value*(255-(saturation*(1.0-f))))/255; unsigned int r,g,b; if (hue < 60){ r = value; g = t; b = p; } else if (hue < 120) { r = q; g = value; b = p; } else if (hue < 180) { r = p; g = value; b = t; } else if (hue < 240) { r = p; g = q; b = value; } else if (hue < 300) { r = t; g = p; b = value; } else { r = value; g = p; b = q; } r>>=3; g>>=2; b>>=3; return (((r&0x1f)<<11)|((g&0x3f)<<5)|(b&0x1f)); } unsigned short *fb; font_descriptor_t *fdes; int scale=4; void draw_pixel(int x, int y, unsigned short color) { if (x>=0 && x<480 && y>=0 && y<320) { fb[x+480*y] = color; } } void draw_pixel_big(int x, int y, unsigned short color) { int i,j; for (i=0; iwidth) { width = fdes->maxwidth; } else { width = fdes->width[ch-fdes->firstchar]; } return width; } void draw_char(int x, int y, char ch, unsigned short color) { int w = char_width(ch); const font_bits_t *ptr; if ((ch >= fdes->firstchar) && (ch-fdes->firstchar < fdes->size)) { if (fdes->offset) { ptr = &fdes->bits[fdes->offset[ch-fdes->firstchar]]; } else { int bw = (fdes->maxwidth+15)/16; ptr = &fdes->bits[(ch-fdes->firstchar)*bw*fdes->height]; } int i, j; for (i=0; iheight; i++) { font_bits_t val = *ptr; for (j=0; j0)) { for (ptr = 0; ptr < 320*480 ; ptr++) { fb[ptr]=0; } draw_char((int)x,250-(int)y, ch, col); x+=vx; y+=vy; vx = vx*0.97; vy = vy*0.97-g; parlcd_write_cmd(parlcd_mem_base, 0x2c); for (ptr = 0; ptr < 480*320 ; ptr++) { parlcd_write_data(parlcd_mem_base, fb[ptr]); } clock_nanosleep(CLOCK_MONOTONIC, 0, &loop_delay, NULL); } } ptr=0; parlcd_write_cmd(parlcd_mem_base, 0x2c); for (i = 0; i < 320 ; i++) { for (j = 0; j < 480 ; j++) { fb[ptr]=0; parlcd_write_data(parlcd_mem_base, fb[ptr++]); } } printf("Goodbye\n"); return 0; }