Project

General

Profile

Revision 863

BOM1.5 Driver complete, test case is in template. Next step is to merge with trunk, which could have issues since the trunk functions are different now.

View differences:

branches/rbom/code/projects/template/main.c
1 1
#include <dragonfly_lib.h>
2 2

  
3 3
int main(void) {
4
	dragonfly_init(ALL_ON);
4
	dragonfly_init(ALL_ON /*| BOM_15*/);
5 5
	orb_init();
6 6
	orb_enable();
7
	bom_on();
8 7
	orb1_set_color(RED);
9
	char l0, l1, h0, h1, on;
10
	int mask;
8
	char temp, on, i=0;
9
	int mask = 0;
10
	usb_puts("init dones\n");
11
	on = 0;
11 12
	while(1)
12 13
	{
13
		l0 = usb_getc()&0xf;
14
		l1 = usb_getc()&0xf;
15
		h0 = usb_getc()&0xf;
16
		h1 = usb_getc()&0xf;
17
		on = usb_getc();
18
		mask = l0|(l1<<4)|(h0<<8)|(h1<<12);
19
		usb_puti(mask);
20
		usb_putc('\n');
21
		bom_set_leds(mask);
22
		if(on == 'o')
14
		if(on&1)
23 15
			bom_on();
24 16
		else
25 17
			bom_off();
18
			
19
		if(button1_click())
20
			on ^= 1;
21
			
22
		if(!usb_getc_nb(&temp))
23
		{
24
			if(temp >= '0' && temp <= '9')
25
				temp = temp - '0';
26
			else
27
				temp = temp - 'a' + 10;
28
			mask += temp << (4*(3-i));
29
			if(++i == 4)
30
			{
31
				i = 0;
32
				usb_puti(mask);
33
				usb_putc('\n');
34
				bom_set_leds(mask);
35
				mask = 0;
36
			}
37
		}	
26 38
	}
27 39
	return 0;
28 40
}
branches/rbom/code/projects/template/Makefile
8 8
endif
9 9

  
10 10
# Target file name (without extension).
11
TARGET = template
11
TARGET = main
12 12

  
13 13
# Uncomment this to use the wireless library
14 14
# USE_WIRELESS = 1
15 15

  
16 16
# com1 = serial port. Use lpt1 to connect to parallel port.
17
AVRDUDE_PORT = com5
17
AVRDUDE_PORT = com4
18 18
#
19 19
#
20 20
###################################
branches/rbom/code/projects/libdragonfly/bom.c
36 36
#include <dragonfly_lib.h>
37 37
#include "bom.h"
38 38
#include "dio.h"
39
#include "serial.h"
39 40
#include "analog.h"
40 41

  
41 42
//On the original BOM1.0, the emmitter angular order does not match the analog mux order
......
78 79
#define MONK3 _PIN_E6     //blue
79 80
#define MONK2 _PIN_E7     //white
80 81

  
81
#define BOM_VALUE_THRESHOLD 200
82
#define BOM_VALUE_THRESHOLD 200

82 83
#define NUM_BOM_LEDS 16
83 84

  
84 85
/*
......
91 92
#define BOM_DATA	_PIN_A0 //servo0
92 93
#define BOM_CLOCK	_PIN_A1	//servo1
93 94

  
94
#define BOM_S0		_PIN_E6	//dio3
95
#define BOM_S1		_PIN_E7	//dio2
96
#define BOM_S2		_PIN_E4	//dio1
97
#define BOM_S3		_PIN_E5	//dio0
95
#define BOM_S0		_PIN_E5	//dio3
96
#define BOM_S1		_PIN_E4	//dio2
97
#define BOM_S2		_PIN_E6	//dio4
98
#define BOM_S3		_PIN_E7	//dio5
98 99
#define BOM_OUT		PF0		//analog(yellow)
99 100

  
100 101
/**
......
110 111
 * Include bom.h to access these functions.
111 112
 *
112 113
 * @{
113
 **/
114

  
115
static unsigned int bom_val[NUM_BOM_LEDS];
116
static char bom_type = BOM;
117
static int select_pins[4];
114
 **/

115

  
116
static unsigned int bom_val[NUM_BOM_LEDS];

117
static volatile char bom_type = BOM;
118
static int select_pins[4];

118 119
static int analog_pin;
119

  
120
/**
121
 * Initializes the BOM.
122
 * Call bom_init before reading bom values or turning bom leds.
123
 *
120

  
121
/**

122
 * Initializes the BOM.

123
 * Call bom_init before reading bom values or turning bom leds.

124
 *

124 125
 * @bugs INCOMPLETE - No utilization of BOM1.5 RSSI capability. Probably leave this out
125
 * until Cornell and Pras return
126
 * 
127
 * @see bom_refresh, bom_leds_on, bom_leds_off
128
 **/
129
void bom_init(char type) {
130
    bom_type = type;
131
    
132
    switch(bom_type) {
126
 * until Cornell and Pras return

127
 * 

128
 * @see bom_refresh, bom_leds_on, bom_leds_off

129
 **/

130
void bom_init(char type) {

131
    bom_type = type;

132
    
133
    switch(bom_type) {

133 134
    case BOM:
134 135
		select_pins[0] = MONK0; 
135 136
		select_pins[1] = MONK1;
136 137
		select_pins[2] = MONK2;
137 138
		select_pins[3] = MONK3;
138
		analog_pin = MONKI;
139
        break;
140
    case BOM15:
141
        //Sets BOM1.5 to normal [BOM] mode
139
		analog_pin = MONKI;

140
        break;

141
    case BOM15:

142
        //Sets BOM1.5 to normal [BOM] mode

142 143
        digital_output(BOM_MODE, 0);
143 144
		select_pins[0] = BOM_S0; 
144 145
		select_pins[1] = BOM_S1;
145 146
		select_pins[2] = BOM_S2;
146 147
		select_pins[3] = BOM_S3;
147 148
		bom_set_leds(BOM_ALL);
148
		analog_pin = BOM_OUT;
149
        break;
150
    case RBOM:
151
        break;
152
    //default:
153
    }
154
}
155

  
156
/**
157
 * Iterates through each bit in the bit_field. For each set bit, sets the corresponding bom select bits
158
 *    and updates the corresponding bom value with an analog_get8 reading.  analog_init and bom_init
159
 *    must be called for this to work.
160
 *
161
 *
162
 * @param bit_field specifies which elements in bom_val[] should be updated. Use BOM_ALL to refresh all values.
163
 *    Ex. if 0x0003 is passed, bom_val[0] and bom_val[1] will be updated.
164
 *
165
 * @see bom_get
166
 **/
167
void bom_refresh(int bit_field) {
168
    int i;
169
    
170
    analog_stop_loop();
171
    
172
    for(i = 0; i < NUM_BOM_LEDS; i++) {
173
        if(bit_field & 0x1) {
174
            bom_select(i);
175
            bom_val[i] = analog_get8(analog_pin);
176
        }
177
        bit_field = bit_field >> 1;
178
    }
179
    
180
    analog_start_loop();
181
}
182

  
183
/**
184
 * Gets the bom reading from bom_val[which].  Call bom_refresh beforehand to read new bom values.
185
 *
186
 * @param which which bom value to return
187
 *
188
 * @return the bom value
189
 *
190
 * see bom_refresh
191
 **/
192
int bom_get(int which) {
193
    return bom_val[which];
194
}
195

  
196
/** 
197
 * Compares all the values in bom_val[] and returns the index to the lowest (max) value element.
198
 *
199
 * @return index to the lowest (max) bom value element.  -1 if no value is lower than
200
 *    BOM_VALUE_THRESHOLD
201
 **/
202
int bom_get_max(void) {
203
    int i, lowest_val, lowest_i;
204
    lowest_i = -1;
149
		analog_pin = BOM_OUT;

150
        break;

151
    case RBOM:

152
        break;

153
    //default:

154
    }

155
}

156

  
157
/**

158
 * Iterates through each bit in the bit_field. For each set bit, sets the corresponding bom select bits

159
 *    and updates the corresponding bom value with an analog_get8 reading.  analog_init and bom_init

160
 *    must be called for this to work.

161
 *

162
 *

163
 * @param bit_field specifies which elements in bom_val[] should be updated. Use BOM_ALL to refresh all values.

164
 *    Ex. if 0x0003 is passed, bom_val[0] and bom_val[1] will be updated.

165
 *

166
 * @see bom_get

167
 **/

168
void bom_refresh(int bit_field) {

169
    int i;

170
    
171
    analog_stop_loop();

172
    
173
    for(i = 0; i < NUM_BOM_LEDS; i++) {

174
        if(bit_field & 0x1) {

175
            bom_select(i);

176
            bom_val[i] = analog_get8(analog_pin);

177
        }

178
        bit_field = bit_field >> 1;

179
    }

180
    
181
    analog_start_loop();

182
}

183

  
184
/**

185
 * Gets the bom reading from bom_val[which].  Call bom_refresh beforehand to read new bom values.

186
 *

187
 * @param which which bom value to return

188
 *

189
 * @return the bom value

190
 *

191
 * see bom_refresh

192
 **/

193
int bom_get(int which) {

194
    return bom_val[which];

195
}

196

  
197
/** 

198
 * Compares all the values in bom_val[] and returns the index to the lowest (max) value element.

199
 *

200
 * @return index to the lowest (max) bom value element.  -1 if no value is lower than

201
 *    BOM_VALUE_THRESHOLD

202
 **/

203
int bom_get_max(void) {

204
    int i, lowest_val, lowest_i;

205
    lowest_i = -1;

205 206
    lowest_val = 255;
206 207
    for(i = 0; i < NUM_BOM_LEDS; i++) {
207
        if(bom_val[i] < lowest_val) {
208
            lowest_val = bom_val[i];
209
            lowest_i = i;
210
        }
211
    }
212
    
213
    if(lowest_val < BOM_VALUE_THRESHOLD)
214
        return lowest_i;
215
    else
216
        return -1;
217
}
218

  
219
/**
208
        if(bom_val[i] < lowest_val) {

209
            lowest_val = bom_val[i];

210
            lowest_i = i;

211
        }

212
    }

213
    
214
    if(lowest_val < BOM_VALUE_THRESHOLD)

215
        return lowest_i;

216
    else

217
        return -1;

218
}

219

  
220
/**

220 221
 * Iterates through each bit in the bit_field. If the bit is set, the corresponding emitter will
221
 *    be enabled to turn on when bom_on() is called.
222
 *    bom_init must be called for this to work.
223
 *
224
 * @param bit_field specifies which leds should be turned on.  Use BOM_ALL to turn on all bom leds.
225
 *    Ex. if 0x0005 is passed, leds 0 and 2 will be turned on.
226
 **/
222
 *    be enabled to turn on when bom_on() is called.

223
 *    bom_init must be called for this to work.

224
 *

225
 * @param bit_field specifies which leds should be turned on.  Use BOM_ALL to turn on all bom leds.

226
 *    Ex. if 0x0005 is passed, leds 0 and 2 will be turned on.

227
 **/

227 228
void bom_set_leds(int bit_field) {
228 229
    int i;
229 230
	unsigned int mask = 1<<(NUM_BOM_LEDS-1);
230
	switch(bom_type) {
231
    case BOM:
232
        if(bit_field == BOM_ALL)
233
            digital_output(MONKL, 1);
231
	switch(bom_type) {

232
    case BOM:

233
        if(bit_field == BOM_ALL)

234
            digital_output(MONKL, 1);

234 235
        break;
235
		
236
		
236 237
    case BOM15:
237 238
	    for(i=NUM_BOM_LEDS; i>0; i--)
238 239
	    {
......
242 243
		    digital_output(BOM_CLOCK, 1);
243 244
		    digital_output(BOM_CLOCK, 0);
244 245
			mask = mask>>1;
245
	    }
246
	    }

246 247
        break;
247
		
248
    case RBOM:
249
        //add rbom code here
250
        break;
248
		
249
    case RBOM:

250
        //add rbom code here

251
        break;

251 252
    }
252
}
253
}

253 254

  
254 255

  
255 256
/**
......
311 312

  
312 313
/** @} **/ //end group
313 314

  
314
//select a detector to read
+//select a detector to read
315 315
static void bom_select(char which) {
316 316
	if(bom_type == BOM)
317 317
	  which = lookup[(int)which];
318
	
318
	
319 319
    if (which&8)
320 320
      digital_output(select_pins[3], 1);
321 321
    else
......
335 336
      digital_output(select_pins[0], 1);
336 337
    else
337 338
      digital_output(select_pins[0], 0);
338
	
339
}
339
	
340
}

Also available in: Unified diff