Project

General

Profile

Revision 378

Added by Jason knichel almost 15 years ago

fixed style problems

View differences:

trunk/code/projects/libdragonfly/dragonfly_lib.c
62 62
 * @see analog_init, usb_init, xbee_init, buzzer_init,
63 63
 * bom_init, orb_init, motors_init, lcd_init
64 64
 **/
65
void dragonfly_init(int config) 
66
{
67
		sei();
65
void dragonfly_init(int config) {
66
  sei();
68 67

  
69
	// Set directionality of various IO pins
70
	DDRG &= ~(_BV(PING0)|_BV(PING1));
71
	PORTG |= _BV(PING0)|_BV(PING1);
68
  // Set directionality of various IO pins
69
  DDRG &= ~(_BV(PING0)|_BV(PING1));
70
  PORTG |= _BV(PING0)|_BV(PING1);
72 71
	
73
	if(config & ANALOG)
74
		analog_init(ADC_START);
72
  if(config & ANALOG)
73
    analog_init(ADC_START);
75 74
	
76
	if(config & COMM)
77
	{
78
		//Defaults to 115200. Check serial.h for more information.
79
		usb_init();
80
		xbee_init();
81
	}
75
  if(config & COMM) {
76
    //Defaults to 115200. Check serial.h for more information.
77
    usb_init();
78
    xbee_init();
79
  }
82 80
	
83
	if(config & BUZZER)
84
	{
85
		sei();
86
		buzzer_init();
87
	}
81
  if(config & BUZZER) {
82
    sei();
83
    buzzer_init();
84
  }
88 85
	
89
	if(config & ORB)
90
	{
91
		sei();
92
		orb_init();
93
	}
86
  if(config & ORB) {
87
    sei();
88
    orb_init();
89
  }
94 90
	
95
	if(config & MOTORS)
96
		motors_init();
91
  if(config & MOTORS)
92
    motors_init();
97 93

  
98
	if(config & LCD)
99
		lcd_init();
94
  if(config & LCD)
95
    lcd_init();
100 96
	
101
	if(config & ORB)
102
	{
103
		sei();
104
		orb_init();
105
	}
97
  if(config & ORB) {
98
    sei();
99
    orb_init();
100
  }
106 101
	
107
	// delay a bit for stability
108
	_delay_ms(1);
102
  // delay a bit for stability
103
  _delay_ms(1);
109 104
}
110 105

  
111 106

  
trunk/code/projects/libdragonfly/lcd.c
54 54

  
55 55
//**************************************Old shit below!*****************
56 56
/*
57
FontLookup - a lookup table for all characters
57
  FontLookup - a lookup table for all characters
58 58
*/
59 59
static const unsigned char FontLookup [][5] =
60
{
60
  {
61 61
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
62 62
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
63 63
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
......
154 154
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
155 155
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
156 156
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
157
};
157
  };
158 158

  
159 159

  
160 160
/**
......
170 170
 * Initializes the LCD. Must be called before any other
171 171
 * LCD functions.
172 172
 **/
173
void lcd_init(void)
174
{
175
	LCDDDR |= (SCE | SDI | SCK);
176
	LCDRESETDDR |= (RST|D_C);
173
void lcd_init(void) {
174
  LCDDDR |= (SCE | SDI | SCK);
175
  LCDRESETDDR |= (RST|D_C);
177 176

  
178
	LCDPORT &= ~( SCE | SDI | SCK);
179
	LCDRESETPORT &=~(D_C);
177
  LCDPORT &= ~( SCE | SDI | SCK);
178
  LCDRESETPORT &=~(D_C);
180 179
  
181
	SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
182
	SPSR |= 0x01;       // a continuation of the above
180
  SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
181
  SPSR |= 0x01;       // a continuation of the above
183 182

  
184
	LCDRESETPORT |= RST;
185
	delay_ms(10);
186
	LCDRESETPORT &= (~RST);
187
	delay_ms(100);
188
	LCDRESETPORT |= RST;
183
  LCDRESETPORT |= RST;
184
  delay_ms(10);
185
  LCDRESETPORT &= (~RST);
186
  delay_ms(100);
187
  LCDRESETPORT |= RST;
189 188
	
190
	lcd_putbyte( 0x21 );  // LCD Extended Commands.
191
	lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
192
	lcd_putbyte( 0x06 );  // Set Temp coefficent.
193
	lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
194
	lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
195
	lcd_putbyte( 0x0C );  // LCD in normal mode.
189
  lcd_putbyte( 0x21 );  // LCD Extended Commands.
190
  lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
191
  lcd_putbyte( 0x06 );  // Set Temp coefficent.
192
  lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
193
  lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
194
  lcd_putbyte( 0x0C );  // LCD in normal mode.
196 195
	
197
	LCDRESETPORT |= D_C;		//put it in init instead of main
196
  LCDRESETPORT |= D_C;		//put it in init instead of main
198 197
	
199
	lcd_clear_screen();
198
  lcd_clear_screen();
200 199
}
201 200

  
202 201
/**
......
205 204
 * @see lcd_init
206 205
 **/
207 206
void lcd_clear_screen( void ) {
208
	int i;
209
	for (i = 0; i < 504; i++)
210
		lcd_putbyte(0x0);
207
  int i;
208
  for (i = 0; i < 504; i++)
209
    lcd_putbyte(0x0);
211 210
	
212
	lcd_gotoxy(0,0);
211
  lcd_gotoxy(0,0);
213 212
}
214 213

  
215 214
/**
......
220 219
 *
221 220
 * @see lcd_init
222 221
 **/
223
void lcd_putc(char c)
224
{
225
	int i;
222
void lcd_putc(char c) {
223
  int i;
226 224
	
227
	for (i = 0; i < 5; i++)
228
		lcd_putbyte(FontLookup[c-32][i]);
229
	lcd_putbyte(0);
225
  for (i = 0; i < 5; i++)
226
    lcd_putbyte(FontLookup[c-32][i]);
227
  lcd_putbyte(0);
230 228
}
231 229

  
232 230
/*
233
print an entire string to the lcd
231
  print an entire string to the lcd
234 232
*/
235
void lcd_puts(char *s)
236
{
237
	char *t = s;
238
	while (*t != 0)
239
	{
240
		lcd_putc(*t);
241
		t++;
242
	}
233
void lcd_puts(char *s) {
234
  char *t = s;
235
  while (*t != 0) {
236
    lcd_putc(*t);
237
    t++;
238
  }
243 239
}
244 240

  
245 241
/*
246
go to coordinate x, y
247
y: vertically - 1 char
248
x: horizontally - 1 pixel
242
  go to coordinate x, y
243
  y: vertically - 1 char
244
  x: horizontally - 1 pixel
249 245

  
250
multiply x by 6 if want to move 1 entire character
246
  multiply x by 6 if want to move 1 entire character
251 247

  
252
origin (0,0) is at top left corner of lcd screen
248
  origin (0,0) is at top left corner of lcd screen
253 249
*/
254 250

  
255 251
/**
......
261 257
 *
262 258
 * @see lcd_init
263 259
 **/
264
void lcd_gotoxy(int x, int y)
265
{
266
	LCDRESETPORT &= ~(D_C);
267
	lcd_putbyte(0x40 | (y & 0x07));
268
	lcd_putbyte(0x80 | (x & 0x7f));
269
	LCDRESETPORT |= D_C;
260
void lcd_gotoxy(int x, int y) {
261
  LCDRESETPORT &= ~(D_C);
262
  lcd_putbyte(0x40 | (y & 0x07));
263
  lcd_putbyte(0x80 | (x & 0x7f));
264
  LCDRESETPORT |= D_C;
270 265
}
271 266

  
272 267
/*
273
prints an int to the lcd
268
  prints an int to the lcd
274 269

  
275
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
270
  code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
276 271
*/
277 272

  
278 273
/**
......
283 278
 *
284 279
 * @see lcd_init
285 280
 **/
286
void lcd_puti(int value )
287
{
288
	unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
281
void lcd_puti(int value ) {
282
  unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
289 283

  
290
        /* convert int to ascii  */ 
291
        if(value<0) { lcd_putc('-'); value=-value; }    
292
        do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix;  } while(value); 
284
  /* convert int to ascii  */ 
285
  if(value<0) { 
286
    lcd_putc('-'); 
287
    value=-value; 
288
  }    
289
  do { 
290
    position--; 
291
    *(lcd_data+position)=(value%radix)+'0'; 
292
    value/=radix;  
293
  } while(value); 
293 294

  
294 295
    
295
        /* start displaying the number */
296
        for(;position<=(sizeof(lcd_data)-1);position++)
297
		lcd_putc(lcd_data[position]);
296
  /* start displaying the number */
297
  for(;position<=(sizeof(lcd_data)-1);position++)
298
    lcd_putc(lcd_data[position]);
298 299

  
299
	return;
300
  return;
300 301
}
301 302

  
302 303
/** @} **/ //end defgroup
303 304

  
304
void lcd_putbyte(unsigned char b)
305
{
306
	SPDR = b;
307
	while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
305
void lcd_putbyte(unsigned char b) {
306
  SPDR = b;
307
  while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
308 308
}
309

  
trunk/code/projects/libdragonfly/dio.c
72 72
 *
73 73
 * @return 1 or 0, depending on the value of the portpin.
74 74
 **/
75
int digital_input(int portpin){
75
int digital_input(int portpin) {
76 76
  int pin = portpin & 0x7;
77 77
  int pin_val = 0;
78 78
  
79
  switch(portpin >> 3){
79
  switch(portpin >> 3) {
80 80
  case _PORT_A:
81 81
    DDRA &= ~_BV(pin);
82 82
    pin_val = PINA;
......
98 98
    pin_val = PINE;
99 99
    return (pin_val >> pin) & 1;
100 100
  case _PORT_F:
101
    if(pin>=4){
101
    if(pin>=4) {
102 102
      MCUSR|=1<<7;
103 103
      MCUSR|=1<<7;
104 104
    }
......
194 194
      PORTG &= (0XFF - _BV(pins));
195 195
      break;
196 196
    }
197
  }else { /* ( val == 1) */ 
197
  } else { /* ( val == 1) */ 
198 198
    switch(portpin >> 3) {
199 199
    case _PORT_A:
200 200
      DDRA |= _BV(pins);
......
235 235
 *
236 236
 * @see button1_wait, button1_click
237 237
 **/
238
int button1_read( void )
239
{
240
	int pin_val;
241
	DDRG &= ~_BV(PING0);
242
	PORTG|= _BV(PING0);
243
    pin_val = PING;
244
	return !((pin_val & _BV(PING0)));
245
  
238
int button1_read( void ) {
239
  int pin_val;
240
  DDRG &= ~_BV(PING0);
241
  PORTG|= _BV(PING0);
242
  pin_val = PING;
243
  return !((pin_val & _BV(PING0)));
246 244
}
247 245

  
248 246
/**
......
250 248
 *
251 249
 * @see button1_read, button1_click
252 250
 **/
253
void button1_wait( void )
254
{
251
void button1_wait( void ) {
255 252
  while(!button1_read() ) {
256 253
    delay_ms(15);
257 254
  }
......
265 262
 *
266 263
 * @see button1_read, button1_wait
267 264
 **/
268
int button1_click()
269
{
270
  if(button1_read()){
265
int button1_click() {
266
  if(button1_read()) {
271 267
    while(button1_read());
272 268
    return 1;
273
  }else{
269
  } else {
274 270
    return 0;
275 271
  }
276 272
}
......
282 278
 *
283 279
 * @see button2_wait, button2_click
284 280
 **/
285
int button2_read( void )
286
{
287
	int pin_val;
288
	DDRG &= ~_BV(PING1);
289
	PORTG|= _BV(PING1);
290
    pin_val = PING;
291
	return !((pin_val & _BV(PING1)));
281
int button2_read( void ) {
282
  int pin_val;
283
  DDRG &= ~_BV(PING1);
284
  PORTG|= _BV(PING1);
285
  pin_val = PING;
286
  return !((pin_val & _BV(PING1)));
292 287
}
293 288

  
294 289
/**
......
296 291
 *
297 292
 * @see button2_read, button2_click
298 293
 **/
299
void button2_wait( void )
300
{
294
void button2_wait( void ) {
301 295
  while(!button2_read()){
302 296
    delay_ms(15);
303 297
  }
......
311 305
 *
312 306
 * @see button2_read, button2_wait
313 307
 **/
314
int button2_click()
315
{
316
	if(button2_read()){
308
int button2_click() {
309
  if(button2_read()) {
317 310
    while(button2_read());
318 311
    return 1;
319
  }else{
320
		return 0;
312
  } else {
313
    return 0;
321 314
  }
322 315
}
323 316

  

Also available in: Unified diff