[tuxdroid-svn] r357 - daemon/trunk/libs firmware/tuxdefs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-06-08 13:46:39
|
Author: jaguarondi Date: 2007-06-08 15:45:59 +0200 (Fri, 08 Jun 2007) New Revision: 357 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_command_tux.h daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h daemon/trunk/libs/USBDaemon_usb_readWrite.c firmware/tuxdefs/commands.h Log: * Added commands to handle ID connections and sleep mode. They are grouped in the TUX_CONNECTION_CMD category. The USB_TUX_CONNECTION commands are commands available on the dongle itself while TUX_CONNECTION commands are higher level functions made avalable to the clients. The daemon doesn't automatically connect to a tux at startup. The client should issue TUX_CONNECTION_CONNECT with the id of tux first. An updated firmware with id and sleep is required. * ATR2406 channels 0, 1, 93 and 94 are removed to meet FCC requirements. * Few naming and style corrections. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-06-08 13:45:59 UTC (rev 357) @@ -33,18 +33,28 @@ #include "USBDaemon_tcp_server.h" #include "USBDaemon_pidfile.h" +/*_____________________ D E F I N I T I O N S ______________________________*/ + +typedef union +{ + uint16_t w; + uint8_t b[2]; +} union_uint16_t; + /*_____________________ F U N C T I O N S __________________________________*/ -unsigned char connect_to_tux(uint16_t id); -unsigned char disconnect_from_tux(void); -unsigned char change_id(uint16_t id); -unsigned char wakeup_tux(void); -unsigned char free_wifi_channel(unsigned char wifi_channel); -unsigned char random_tux_connection(void); +void tux_connection(unsigned char const data[], unsigned char result[]); +int disconnect_from_tux(void); +int connect_to_tux(uint16_t id); +int id_request(uint16_t *id); +int id_lookup(uint16_t *id); +int change_id(uint16_t id); +int wakeup_tux(void); +int avoid_wifi_channel(unsigned char wifi_channel); +int random_tux_connection(void); + /************************************************************************** */ - /* COMMANDS FROM CLIENTS DISPATCHER */ - /************************************************************************** */ void commands_dispatcher(unsigned char client_id, /* Client source */ tcp_frame_t src_frame) /* Source frame */ @@ -142,7 +152,7 @@ /* B3----Data Type */ switch (src_frame[2]) { - /* Data type command */ + /* Data type command */ case DATA_TP_CMD: tcp_frame[2] = DATA_TP_ACK_CMD; tcp_frame[3] = src_frame[3]; @@ -163,7 +173,7 @@ break; } break; - /* Data type request */ + /* Data type request */ case DATA_TP_REQ: tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = src_frame[3]; @@ -184,6 +194,12 @@ break; } break; + /* USB connection command */ + case TUX_CONNECTION_CMD: + tcp_frame[2] = DATA_TP_RSP; + tcp_frame[3] = src_frame[3]; + tux_connection(data, result); + break; /* Unknowed data type */ default: ACK_DP = ACK_DP_UKN_DATA_TP; @@ -232,18 +248,14 @@ } /************************************************************************ */ - /* FOR Sub daemon */ - /************************************************************************ */ /******************************************************************** */ - /* sub_daemon_cmd_struct() */ - /******************************************************************** */ -void sub_daemon_cmd_struct(unsigned char data[], unsigned char result[], - int id_client) +void sub_daemon_cmd_struct(unsigned char const data[], unsigned char result[], + int const id_client) { switch (data[0]) { @@ -283,12 +295,10 @@ } /************************************************************************ */ - /* sub_daemon_req_info() */ - /************************************************************************ */ -void sub_daemon_req_info(unsigned char data[], unsigned char result[], - int id_client) +void sub_daemon_req_info(unsigned char const data[], unsigned char result[], + int const id_client) { unsigned char i; @@ -318,17 +328,13 @@ } /************************************************************************** */ - /* FOR Tux droid */ - /************************************************************************** */ /************************************************************************ */ - /* tux_cmd_raw() */ - /************************************************************************ */ -void tux_cmd_raw(unsigned char data[], unsigned char result[]) +void tux_cmd_raw(unsigned char const data[], unsigned char result[]) { unsigned char usb_send[5]; unsigned char i; @@ -340,11 +346,9 @@ } /************************************************************************ */ - /* tux_cmd_struct() */ - /************************************************************************ */ -void tux_cmd_struct(unsigned char data[], unsigned char result[]) +void tux_cmd_struct(unsigned char const data[], unsigned char result[]) { unsigned char ACK; @@ -516,11 +520,9 @@ } /************************************************************************ */ - /* tux_req_status() */ - /************************************************************************ */ -void tux_req_status(unsigned char data[], unsigned char result[]) +void tux_req_status(unsigned char const data[], unsigned char result[]) { result[0] = data[0]; switch (data[0]) @@ -784,12 +786,100 @@ } } +/** + * tux connection commands + */ +void tux_connection(unsigned char const data[], unsigned char result[]) +{ + result[0] = data[0]; + switch (data[0]) + { + case TUX_CONNECTION_DISCONNECT: + if (disconnect_from_tux() >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + case TUX_CONNECTION_CONNECT: + { + union_uint16_t id; + id.b[1] = data[1]; + id.b[0] = data[2]; + printf("coucou\n"); + if (connect_to_tux(id.w) >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + } + case TUX_CONNECTION_ID_REQUEST: + { + union_uint16_t id; + if (id_request((uint16_t *)&id) >= 0) + { + result[1] = TUX_CONNECTION_ACK; + result[2] = id.b[1]; /* MSB */ + result[3] = id.b[0]; /* LSB */ + } + else + result[1] = TUX_CONNECTION_NACK; + break; + } + case TUX_CONNECTION_ID_LOOKUP: + { + union_uint16_t id; + if (id_lookup((uint16_t *)&id) >= 0) + { + result[1] = TUX_CONNECTION_ACK; + result[2] = id.b[1]; /* MSB */ + result[3] = id.b[0]; /* LSB */ + } + else + result[1] = TUX_CONNECTION_NACK; + break; + } + case TUX_CONNECTION_CHANGE_ID: + { + union_uint16_t id; + id.b[0] = data[2]; /* LSB */ + id.b[1] = data[1]; /* MSB */ + if (change_id(id.w) >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + } + case TUX_CONNECTION_SLEEP: + if (send_usb_tux_cmd(SLEEP_CMD, 0, SLEEP_MODE, 0) == ACK_CMD_OK) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + case TUX_CONNECTION_WAKEUP: + if (wakeup_tux() >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + case TUX_CONNECTION_RANDOM: + if (random_tux_connection() >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + case TUX_CONNECTION_WIRELESS_CHANNEL: + if (avoid_wifi_channel(data[1]) >= 0) + result[1] = TUX_CONNECTION_ACK; + else + result[1] = TUX_CONNECTION_NACK; + break; + } +} + /************************************************************************ */ - /* tux_req_info() */ - /************************************************************************ */ -void tux_req_info(unsigned char data[], unsigned char result[]) +void tux_req_info(unsigned char const data[], unsigned char result[]) { result[0] = data[0]; @@ -810,15 +900,11 @@ } /************************************************************************** */ - /* TUX USB */ - /************************************************************************** */ /************************************************************************ */ - /* send_usb_tuxcmd() */ - /************************************************************************ */ unsigned char send_usb_tux_cmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3) @@ -834,12 +920,10 @@ } /************************************************************************ */ - /* send_usb_donglecmd() */ - /************************************************************************ */ -unsigned char send_usb_dongle_cmd(USB_DONGLE_COMMANDS cmd, unsigned char param1, - unsigned char param2, unsigned char param3) +unsigned char send_usb_dongle_cmd(usb_dongle_commands_t cmd, + unsigned char param1, unsigned char param2, unsigned char param3) { unsigned char data[TUX_SEND_LENGTH]; int ret; @@ -857,81 +941,208 @@ } /** - * \brief Connect to a tux by its ID + * Disconnect from tux + * + * The return value only tells whether the command has been sent successfully + * to the dongle. That does by no means tell anything about the actual RF + * connection with tux. Check RF_status for this. + * + * \return 0 if successful, -1 otherwise */ -unsigned char connect_to_tux(uint16_t id) +int disconnect_from_tux(void) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CONNECT, - (uint8_t)id, (uint8_t)(id>>8)); + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_DISCONNECT, 0, 0) == USB_FRAME_SIZE) + return 0; + else + return -1; } /** - * \brief Disconnect from tux + * Connect to a tux by its ID + * + * The return value only tells whether the command has been sent successfully + * to the dongle. That does by no means tell anything about the actual RF + * connection with tux. Check RF_status for this. + * + * \return 0 if successful, -1 otherwise */ -unsigned char disconnect_from_tux(void) +int connect_to_tux(const uint16_t id) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_DISCONNECT, - 0, 0); + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, USB_TUX_CONNECTION_CONNECT, + (uint8_t)(id>>8), (uint8_t)id) == USB_FRAME_SIZE) + return 0; + else + return -1; } /** - * \brief Get the ID of the first disconnected tux which is discoverred + * Connect to the first tux discovered * + * Catch any disconnected tux, request it's ID and connect to it. + * + * \return 0 if successful, -1 otherwise + */ +int random_tux_connection(void) +{ + uint16_t id; + if (id_lookup((uint16_t *)&id) < 0) + return -1; + + if (connect_to_tux(id) < 0) + return -1; + + return 0; +} + +/** + * Get the ID of tux currently connected + * + * \param *id pointer where the id should be returned + * \return 0 if successful, -1 otherwise + */ +#define ID_REQUEST_TIMEOUT 5 /* 100ms time unit */ +int id_request(uint16_t *id) +{ + int timeout_cnt = 0; + + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_ID_REQUEST, 0, 0) != USB_FRAME_SIZE) + return -1; + + /* usb_request_f flag is reset when the id is received in + * usb_get_status_TuxDroid() */ + connection_status.usb_request_f = 1; + while (connection_status.usb_request_f) + { + usleep(100000); + usb_get_status_TuxDroid(); + if (timeout_cnt++ == ID_REQUEST_TIMEOUT) + { + return -1; + } + } + /* At this time the id should be stored in connection_status.tux_id */ + *id = connection_status.tux_id; + + return 0; +} + +/** + * Get the ID of the first disconnected tux which is discoverred + * * The first disconnected tux that will detect this command will reply with * it's ID and disconnect immediately. You can then connect to that tux with * the ID you just got. * * In order to get the ID's of more than one disconnected tux, you have to * issue this command multiple times until you don't get any new ID. + * + * \param *id pointer where the id should be returned + * \return 0 if successful, -1 otherwise */ -#define ID_LOOKUP_TIMEOUT 20 /* 100ms time unit */ -unsigned char id_lookup(uint16_t *id) +#define ID_LOOKUP_TIMEOUT 50 /* 100ms time unit */ +int id_lookup(uint16_t *id) { - unsigned char ack; int timeout_cnt = 0; - ack = send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); - if (ack != 5) /* error when writing data on the USB */ - return 0; - connection_status.usb_request_f = 1; /* this flag is reset when the id is received in usb_get_status_TuxDroid */ + /* Disconnecting first is necessary in case tux is connected */ + if (disconnect_from_tux() < 0) + return -1; + + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_ID_LOOKUP, 0, 0) != USB_FRAME_SIZE) + return -1; + + /* usb_request_f flag is reset when the id is received in + * usb_get_status_TuxDroid() */ + connection_status.usb_request_f = 1; while (connection_status.usb_request_f) { - usleep(200000); + usleep(100000); usb_get_status_TuxDroid(); if (timeout_cnt++ == ID_LOOKUP_TIMEOUT) { - return 0; + return -1; } } /* At this time the id should be stored in connection_status.tux_id */ *id = connection_status.tux_id; - return 1; + + /* We need to disconnect after a lookup to reset the RF module */ + if (disconnect_from_tux() < 0) + return -1; + return 0; } /** - * \brief Changes the ID of a disconnected tux + * Changes the ID of a disconnected tux * - * You have to push on the head button of tux for XXX seconds while sending + * You have to push on the head button of tux for 5 seconds while sending * this command in order to validate the ID change request, this in order to * avoid stealing a tux too easily. + * + * \param id new id to set + * \return 0 if successful, -1 otherwise */ -unsigned char change_id(uint16_t id) +#define CHANGE_ID_TIMEOUT 70 +int change_id(uint16_t id) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, - (uint8_t)id, (uint8_t)(id>>8)); + int timeout_cnt = 0; + + /* Disconnecting first is necessary in case tux is connected */ + if (disconnect_from_tux() < 0) + return -1; + + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_CHANGE_ID, (uint8_t)(id>>8), (uint8_t)id) + != USB_FRAME_SIZE) + return -1; + + /* usb_request_f flag is reset when the id is received in + * usb_get_status_TuxDroid() */ + connection_status.usb_request_f = 1; + while (connection_status.usb_request_f) + { + usleep(100000); + usb_get_status_TuxDroid(); + if (timeout_cnt++ == CHANGE_ID_TIMEOUT) + { + /* This is the case when the hardware condition to change the id is + * not met */ + return -1; + } + } + + /* At this time the id should be stored in connection_status.tux_id, we + * check that it's the same as what we asked for */ + if (id != connection_status.tux_id) + return -1; + + /* We need to disconnect but as the id has been changed, we don't return an + * error if disconnection fails */ + if (disconnect_from_tux() < 0) + return 1; + + return 0; } /** - * \brief Wake-up a tux if it's in sleep mode. + * Wake-up a tux if it's in sleep mode. + * + * \return 0 if successful, -1 otherwise */ -unsigned char wakeup_tux(void) +int wakeup_tux(void) { - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, - 0, 0); + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_ID_LOOKUP, 0, 0) == USB_FRAME_SIZE) + return 0; + else + return -1; } /** - * \brief Configure the RF module to avoid a given wifi channel + * Configure the RF module to avoid a given wifi channel * * This sets the frequencies to avoid in the dongle. These settings only take * effect when a connection is initiated with a tux. This function should @@ -940,8 +1151,10 @@ * * Channels from 1 to 14 are valid wifi channels. Set the wifi channel to 0 to * disable channel avoidance and use the complete range of frequencies. + * + * \return 0 if successful, -1 otherwise */ -unsigned char free_wifi_channel(unsigned char wifi_channel) +int avoid_wifi_channel(unsigned char wifi_channel) { /* * Conversion of the lower and higher frequencies of a wifi channel into @@ -949,20 +1162,14 @@ * Channel 0 sends 0 as both low and high ATR channels. */ static const uint8_t lower_ATR_channel[15] = - {0, 0, 6, 12, 18, 24, 29, 35, 41, 47, 52, 58, 64, 70, 76}; + {92, 2, 6, 12, 18, 24, 29, 35, 41, 47, 52, 58, 64, 70, 76}; static const uint8_t higher_ATR_channel[15] = - {0, 26, 32, 38, 43, 49, 55, 61, 67, 72, 78, 84, 90, 94, 94}; + {2, 26, 32, 38, 43, 49, 55, 61, 67, 72, 78, 84, 90, 92, 92}; - return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, - lower_ATR_channel[wifi_channel], higher_ATR_channel[wifi_channel]); + if (send_usb_dongle_cmd(USB_TUX_CONNECTION_CMD, + USB_TUX_CONNECTION_CHANGE_ID, lower_ATR_channel[wifi_channel], + higher_ATR_channel[wifi_channel]) == USB_FRAME_SIZE) + return 0; + else + return -1; } - -/** - * \brief Connect to the first tux discovered - * - * Used to catch any disconnected tux, request it's ID and connect to it. - */ -unsigned char random_tux_connection(void) -{ - return 0; -} Modified: daemon/trunk/libs/USBDaemon_command_tux.h =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.h 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_command_tux.h 2007-06-08 13:45:59 UTC (rev 357) @@ -35,20 +35,20 @@ /* COMMANDS FROM CLIENTS DISPATCHER */ extern void commands_dispatcher(unsigned char client_id, unsigned char src_frame[16]); -extern void sub_daemon_cmd_struct(unsigned char data[], unsigned char result[], - int id_client); -extern void sub_daemon_req_info(unsigned char data[], unsigned char result[], - int id_client); -extern void tux_cmd_raw(unsigned char data[], unsigned char result[]); -extern void tux_cmd_struct(unsigned char data[], unsigned char result[]); -extern void tux_req_status(unsigned char data[], unsigned char result[]); -extern void tux_req_info(unsigned char data[], unsigned char result[]); +extern void sub_daemon_cmd_struct(unsigned char const data[], + unsigned char result[], int const id_client); +extern void sub_daemon_req_info(unsigned char const data[], + unsigned char result[], int const id_client); +extern void tux_cmd_raw(unsigned char const data[], unsigned char result[]); +extern void tux_cmd_struct(unsigned char const data[], unsigned char result[]); +extern void tux_req_status(unsigned char const data[], unsigned char result[]); +extern void tux_req_info(unsigned char const data[], unsigned char result[]); /* TUX PHYSICAL CHANGES */ extern unsigned char send_usb_tux_cmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3); -extern unsigned char send_usb_dongle_cmd(USB_DONGLE_COMMANDS cmd, +extern unsigned char send_usb_dongle_cmd(usb_dongle_commands_t cmd, unsigned char param1, unsigned char param2, unsigned char param3); @@ -73,6 +73,5 @@ unsigned char middle_add, unsigned char higher_add); extern unsigned char send_test_sound(); -unsigned char id_lookup(uint16_t *id); #endif Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-06-08 13:45:59 UTC (rev 357) @@ -68,9 +68,11 @@ switch (new_status[0]) { case STATUS_ID_CMD: - connection_status.usb_request_f = 0; /* the answer from the usb command has been received */ - printf("flag set: %i\n",connection_status.usb_request_f); + /* The answer from the usb_tux_connection command has been received */ + connection_status.usb_request_f = 0; connection_status.tux_id = (new_status[1] << 8) + new_status[2]; + log_debug("id retunred by tux: %i (0x%.2x%.2x)", + connection_status.tux_id, new_status[1], new_status[2]); break; case STATUS_PORTS_CMD: if (portb.Byte != new_status[1]) Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-06-08 13:45:59 UTC (rev 357) @@ -65,6 +65,7 @@ #define DATA_TP_RSP 0x03 #define DATA_TP_ACK_CMD 0x04 #define DATA_TP_ACK_DP 0x05 +#define TUX_CONNECTION_CMD 0x06 /* Sub data types */ #define SUBDATA_TP_RAW 0x01 @@ -176,6 +177,26 @@ #define DATA_STATUS_SOUND_COUNT 0x23 #define DATA_STATUS_PONG 0x24 +/* tux connection commands available on the usb dongle */ +typedef enum +{ + TUX_CONNECTION_DISCONNECT = 1, + TUX_CONNECTION_CONNECT = 2, + TUX_CONNECTION_RANDOM = 3, + TUX_CONNECTION_ID_REQUEST = 4, + TUX_CONNECTION_ID_LOOKUP = 5, + TUX_CONNECTION_CHANGE_ID = 6, + TUX_CONNECTION_SLEEP = 7, + TUX_CONNECTION_WAKEUP = 8, + TUX_CONNECTION_WIRELESS_CHANNEL = 9, +} tux_connection_t; + +typedef enum +{ + TUX_CONNECTION_NACK = 0, + TUX_CONNECTION_ACK = 1, + TUX_CONNECTION_NOTFOUND = 2, +} tux_connection_ack_t; /* ------------------ Daemon to Application, frame construction ----------------- */ /*_____________________ T Y P E _ D E F ____________________________________*/ Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-06-08 13:45:59 UTC (rev 357) @@ -36,7 +36,7 @@ /*_____________________ V A R I A B L E S __________________________________*/ usb_dev_handle *tux_handle; struct usb_device *tux_device; -TUX_USB_CONN_STATUS TUX_USB_STATUS = TUX_USB_DISCONNECTED; +usb_connection_status_t usb_connection_status = USB_DISCONNECTED; /*_____________________ F U N C T I O N S __________________________________*/ @@ -119,13 +119,16 @@ if (tux_device->descriptor.bcdDevice < 0x100) { log_error("Your dongle firmware is too old.\n" - "This version is not compatible with this daemon, please update\n" - "the firmware to version 1.00 or better.\n" - "Check http://www.tuxisalive.com/documentation/how-to/updating-the-firmware\n" - "for details."); + "This version is not compatible with this daemon, please \ + update\n" + "the firmware to version 1.00 or better.\n" + "Check http://www.tuxisalive.com/documentation/how-to/\ + updating-the-firmware\nfor details."); return 0; } + log_debug("Fux found on the USB bus"); + /* Get Device handle */ tux_handle = usb_open_TuxDroid(tux_device); if (tux_handle == NULL) @@ -133,12 +136,13 @@ log_error("You must load the daemon in root mode"); return 0; } + log_debug("Fux USB device opened"); - TUX_USB_STATUS = TUX_USB_CONNECTED; + usb_connection_status = USB_CONNECTED; /* Resets audio channel selection; there are 2 audio interfaces in the * dongle, the second is dedicated to TTS. */ - send_usb_dongle_cmd(USB_AUDIO_CMD, 0, 0, 0); /* select the first audio channel */ + send_usb_dongle_cmd(USB_AUDIO_CMD, 0, 0, 0); current_audio_channel = 0; return 1; Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-06-08 13:45:59 UTC (rev 357) @@ -29,41 +29,48 @@ /*_____________________ D E F I N E S ______________________________________*/ +#define USB_FRAME_SIZE 5 /*_____________________ E N U M S ______________________________________*/ typedef enum { - TUX_USB_DISCONNECTED = 0, - TUX_USB_CONNECTED = 1 -} TUX_USB_CONN_STATUS; + USB_DISCONNECTED = 0, + USB_CONNECTED = 1 +} usb_connection_status_t; typedef enum { USB_TUX_CMD = 0, USB_DONGLE_CMD = 1, USB_BOOTLOADER_CMD = 2, -} USB_HEADER_TYPE; +} usb_command_header_t; typedef enum { - USB_CONNECTION_CMD = 0, + USB_TUX_CONNECTION_CMD = 0, USB_STATUS_CMD = 1, USB_AUDIO_CMD = 2, USB_VERSION_CMD = 6, -} USB_DONGLE_COMMANDS; +} usb_dongle_commands_t; +/* tux connection commands available on the usb dongle + * + * These are of the following type: + * USB_DONGLE_CMD, USB_TUX_CONNECTION_CMD + */ typedef enum { - USB_CONNECTION_CONNECT = 1, - USB_CONNECTION_DISCONNECT = 2, - USB_CONNECTION_ID_LOOKUP = 3, - USB_CONNECTION_CHANGE_ID = 4, - USB_CONNECTION_WAKEUP = 5, - USB_CONNECTION_WIRELESS_CHANNEL = 6, -} USB_ID_PARAM1; + USB_TUX_CONNECTION_DISCONNECT = 1, + USB_TUX_CONNECTION_CONNECT = 2, + USB_TUX_CONNECTION_ID_REQUEST = 3, + USB_TUX_CONNECTION_ID_LOOKUP = 4, + USB_TUX_CONNECTION_CHANGE_ID = 5, + USB_TUX_CONNECTION_WAKEUP = 6, + USB_TUX_CONNECTION_WIRELESS_CHANNEL = 7, +} usb_tux_connection_t; /*_____________________ V A R I A B L E S __________________________________*/ extern usb_dev_handle *tux_handle; -extern TUX_USB_CONN_STATUS TUX_USB_STATUS; +extern usb_connection_status_t usb_connection_status; /*_____________________ F U N C T I O N S __________________________________*/ Modified: daemon/trunk/libs/USBDaemon_usb_readWrite.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-06-07 07:28:06 UTC (rev 356) +++ daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-06-08 13:45:59 UTC (rev 357) @@ -43,7 +43,7 @@ int idx; int i; - if (TUX_USB_CONNECTED != TUX_USB_STATUS) + if (usb_connection_status != USB_CONNECTED) return; for (i = 0; i < 5; i++) @@ -72,7 +72,7 @@ int idx; int num_frames, i; - if (TUX_USB_CONNECTED != TUX_USB_STATUS) + if (usb_connection_status != USB_CONNECTED) return; idx = usb_interrupt_write(tux_handle, TUX_WRITE_EP, (char *)cmd_send, @@ -119,7 +119,7 @@ unsigned char counter; unsigned char csf; - if (TUX_USB_CONNECTED != TUX_USB_STATUS) + if (usb_connection_status != USB_CONNECTED) return ACK_CMD_DONGLE_NOT_PRESENT; /* Send data */ Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2007-06-07 07:28:06 UTC (rev 356) +++ firmware/tuxdefs/commands.h 2007-06-08 13:45:59 UTC (rev 357) @@ -223,8 +223,11 @@ * Sleep commands */ #define SLEEP_CMD 0xB7 /* set the CPU in sleep mode */ -/* 1st parameter: type of sleep mode */ -/* 2nd parameter: reserved */ +/* 1st parameter: reserved */ +/* 2nd parameter: type of sleep mode */ +#define DEEPSLEEP_MODE 1 /* minimal power consumption, can't wake-up from this + mode */ +#define SLEEP_MODE 2 /* standard sleep mode */ #define SLEEP_ACK_CMD 0xF7 /* acknowledge of the sleep mode command */ /* 1st parameter: acknowledge of tuxcore */ /* 2nd parameter: acknowledge of tuxaudio */ @@ -311,6 +314,10 @@ /* 2nd parameter: undefined */ /* 3rd parameter: undefined */ +#define STATUS_ID_CMD 0xC6 +/* 1st parameter: Tux ID number (MSB) */ +/* 2nd parameter: Tux ID number (LSB) */ + /* * Special commands */ |