четверг, 26 июля 2012 г.

ASF: RGB macros

Famouse RGB macros for R5G6B5 for ET0240006 (analogue of et024006_Color(R, G, B) in Atmel Software Framework):
#define GUI_RGB(R, G, B) ((((R) & 0xF8)<<8) | (((G) & 0xFC)<<3) | ((B)>>3))
may be used anywhere - where you need constant, not function call (initializer of structs members and so on)

понедельник, 16 июля 2012 г.

ASF, AVR32, ET024006: et024006_PutPixmap() and bitmap format

How to use bitmap on ET024006 with ASF (Atmel Software Framework)? Format of bitmap file, used in et024006_PutPixmap(), is the R5G6B5, you can create image in the GIMP, then export to 'C source file' (select 'save as RGB 565 16 bits', and uncheck 'Use Glib types') and get something like this:
/* GIMP RGBA C-Source image dump (appicon.c) */
#define GIMP_IMAGE_WIDTH (22)
#define GIMP_IMAGE_HEIGHT (22)
#define GIMP_IMAGE_BYTES_PER_PIXEL (4) /* 3:RGB, 4:RGBA */
#define GIMP_IMAGE_PIXEL_DATA ((unsigned char*) GIMP_IMAGE_pixel_data)
static const unsigned char GIMP_IMAGE_pixel_data[22 * 22 * 4 + 1] =
("\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
...
);
I change it to:
const unsigned char appmenu_icon[] =
 ("\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
...
);
And then call:
et024006_PutPixmap((et024006_color_t*)appmenu_icon,
     appmenu_icon_width,
     0, 0, x, y,
     appmenu_icon_width,
     appmenu_icon_height);
appmenu_icon_width and appmenu_icon_height may be #define's

вторник, 10 июля 2012 г.

VIM: aliases vim command on Windows

Considering, we have folder with Makefile, other useful files (tags file, some bat files and so on) and deep-deep folders with sources. We are working with make/gmake in top folder but need to change directory to another deep-deep folders to make something there, for example, run vim... ^) To do it, I use script:
@echo off
PATH = C:\Program Files\Atmel\Atmel Studio 6.0\avrdbg;C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.3.2.31\AVRToolchain\bin;C:\papps\PortableApps\MinGWPortable\App\MinGW\msys\1.0\bin;%PATH%
start /D %CD%\deep\deep\src /B cmd.exe
doskey myvim=c:\Vim\vim73\gvim.exe -c ":set tags=../../../tags" $*
You can see there set of PATH variable for new terminal, aliasing new command myvim with autoset tags file. You can also setup individual _vimrc (per project:), if you need.
Save this script as cli.bat, run it and call in terminal:
myvim some_src.c
No more long paths and pushd/popd/cd! :)

Two usefull C macroses

As for me, there are 2 very simple but usefull C macros for safe calling of function (or method - callback in struct member):
#define SAFE_CALL(F, ...) do { if ((F)) (*(F))(##__VA_ARGS__); } while(0)
#define MCALL(SELF, CB, ...) do { if((SELF)->CB) (*(SELF)->CB)(SELF, ##__VA_ARGS__); } while(0)
Note two '#' - this is the GNU GCC extension to avoid problem with comma in variadic macros - with they we can use or not var. args. Usage is simple too:
MCALL(my_struct_ptr, onpaint, area_t* area);
Something like this... :)