summaryrefslogtreecommitdiff
path: root/df10ch_usb_proto.h
blob: bbda480977d323f8c865a047a73a50aee8cb8408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2010 Andreas Auras
 *
 * This file is part of the DF10CH Atmolight controller project.
 *
 * DF10CH Atmolight controller is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * DF10CH Atmolight controller is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 */

/* ---
 * Communication protocol related defines for DF10CH Atmolight Controller.
 */

#define REQ_USB_START			0							// Start of usb controller requests
#define REQ_USB_BL_START	64						// Start of usb controller boot loader requests
#define REQ_PWM_START			128						// Start of pwm controller requests
#define REQ_PWM_BL_START	192						// Start of pwm controller boot loader requests

enum
{
		// usb controller requests
	REQ_START_BOOTLOADER = REQ_USB_START,	// start boot loader of usb controller
	REQ_READ_EE_DATA,											// read eeprom data (wLength: number of bytes, wIndex: eeprom start address)
	REQ_WRITE_EE_DATA,										// write eeprom data (wLength: number of bytes, wIndex: eeprom start address)

	REQ_STOP_PWM_CTRL,										// stop PWM controller
	REQ_RESET_PWM_CTRL,										// reset PWM controller
	REQ_BOOTLOADER_RESET_PWM_CTRL,				// reset PWM controller and signal bootloader start

	REQ_SET_REPLY_TIMEOUT,								// set reply timeout values (wValue: start timeout [ms], wIndex: timeout [ms])

	REQ_GET_REPLY_ERR_STATUS,		  				// get reply error status (COMM_ERR_...)

		// usb controller boot loader requests
	BL_REQ_WRITE_PAGE = REQ_USB_BL_START,		// write flash page
	BL_REQ_LEAVE_BOOT,											// leave boot loader and start application
	BL_REQ_GET_PAGE_SIZE,										// return flash page size of device
	BL_REQ_READ_FLASH,											// return flash contents

		// pwm controller requests
  PWM_REQ_GET_VERSION = REQ_PWM_START,		// Get firmware version (returns 1 byte)
	PWM_REQ_SET_BRIGHTNESS,									// Set channel brightness values (wLenght: number of bytes, wIndex: start channel)
	PWM_REQ_SET_BRIGHTNESS_SYNCED,					// Same as above but wait until buffer flip
	PWM_REQ_GET_BRIGHTNESS,

	PWM_REQ_SET_CHANNEL_MAP,								// Set channel to port mapping (wLength: number of bytes, wIndex: start channel)
	PWM_REQ_GET_CHANNEL_MAP,

	PWM_REQ_SET_COMMON_PWM,									// Set common pwm value (wValue.low: pwm value)
	PWM_REQ_GET_COMMON_PWM,

	PWM_REQ_STORE_SETUP,										// Store actual calibration values
	PWM_REQ_RESET_SETUP,										// Reset calibration values to default

	PWM_REQ_GET_REQUEST_ERR_STATUS,					// Get request error status (COMM_ERR_...)

	PWM_REQ_GET_MAX_PWM,										// Get maximum internal PWM value

	PWM_REQ_SET_PWM_FREQ,										// Set pwm frequency (wValue: frequency [hz])
	PWM_REQ_GET_PWM_FREQ,										// Get pwm frequency (returns word)

	PWM_REQ_ECHO_TEST,											// Reply 8 byte header

		// pwm controller boot loader requests
	BL_PWM_REQ_WRITE_PAGE = REQ_PWM_BL_START,		// write flash page
	BL_PWM_REQ_GET_PAGE_SIZE,								// return flash page size of device
	BL_PWM_REQ_READ_FLASH,									// return flash contents
	BL_PWM_REQ_GET_REQUEST_ERR_STATUS				// Get request error status (COMM_ERR_...)
};

// Data payload related
#define MAX_REQ_PAYLOAD_SIZE		128
#define MAX_REPLY_PAYLOAD_SIZE	128

// Error flag definition for communication error's of usb and pwm controller
#define COMM_ERR_OVERRUN	0
#define COMM_ERR_FRAME		1
#define COMM_ERR_TIMEOUT	2
#define COMM_ERR_START		3
#define COMM_ERR_OVERFLOW	4
#define COMM_ERR_CRC			5
#define COMM_ERR_DUPLICATE 6
#define COMM_ERR_DEBUG		7

// Port channel mapping related
#define NCHANNELS 30				// Number of supported Channels

#define NPORTS	4
#define PA_IDX	0
#define PB_IDX	1
#define PC_IDX	2
#define PD_IDX	3

#define CM_CODE(port, channel)	(((channel) << 2) | (port))
#define CM_CHANNEL(code)				((code) >> 2)
#define CM_PORT(code)						((code) & 0x03)

// PWM frequency related
#define MIN_PWM_FREQ	50
#define MAX_PWM_FREQ	400

// PWM controller version request related
#define PWM_VERS_APPL	0		// Is application firmware
#define PWM_VERS_BOOT	1		// Is bootloader firmware