We start with a simple hello-world example.
/* * Copyright (C) 2004 BLADOX, s.r.o. All rights reserved. * * This file is part of an example program for Turbo. This example * program may be used, distributed and modified without limitation. * */ #include <config.h> #include <tprog/tprog.h> u8 PROGMEM hello[] = "helloworld!"; void turbo_handler (u8 action, USB_Data *data) { switch (action) { case 0x80: usb_send (NO_ERROR, sizeof (hello), hello); default: break; } }
You can see there is one function in this example:
This function is required for every application and has to be called turbo_handler().
Application structure
For more see Actions.
In our hello-world example we handle just one action 0x80. It responds with "helloworld!" string.
prog_apps # you get the application number list prog_apps -a app_nr -x 128 # send the 0x80 action to the application
Typical example of persistent data usage
typedef struct _My_Persistent_Data { u8 x; u16 y; u8 * p1; } My_Persistent_Data; u8 x; u16 y; u8 *p1; void turbo_handler (u8 action, void *data) { switch (action) { case ACTION_APP_REGISTER: { My_Persistent_Data *p = emalloc (sizeof (My_Persistent_Data)); wb (&p->x, 0); ww (&p->y, 0x1234); ww (&p->p1, NULL); reg_app_data (p); break; } case ACTION_APP_UNREGISTER: { My_Persistent_Data *p = app_data (); efree (rw (&p->p1)); efree (p); break; } case ACTION_APP_INIT: { My_Persistent_Data *p = app_data (); x = rb (&p->x); y = rw (&p->y); p1 = rw (&p->p1); break; } ... } }
Copyright © 2004 BLADOX | Turbo Programmer version 2.0
|