xyControl  0.1
Quadrotor Flight Controller on AVR Basis
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Data Structures | Enumerations | Functions | Variables
xyControl Hardware

Controls xyControl On-Board Hardware like LEDs. More...

Files

file  xycontrol.h
 xyControl API Header.
 
file  xycontrol.c
 xyControl API Implementation.
 

Data Structures

struct  Vector3f
 The global 3-Dimensional Floating Point Vector. More...
 

Enumerations

enum  LED {
  LED_RED0 = 0, LED_RED1 = 1, LED_GREEN0 = 2, LED_GREEN1 = 3,
  LED_ALL = 4, LED_BITMAP = 5, LED_RED = 6, LED_GREEN = 7
}
 Methods of addressing the LEDs. More...
 
enum  LEDState { LED_OFF = 0, LED_ON = 1, LED_TOGGLE = 2 }
 Possible states of the LEDs. More...
 

Functions

void xyInit (void)
 Initialize the xyControl Hardware. More...
 
void xyLed (LED l, LEDState v)
 Set the LEDs. More...
 
double getVoltage (void)
 Calculate and return the Battery Voltage. More...
 
void xySelfReset (void)
 Use the Watchdog to reset yourself after 15ms. More...
 
int64_t map (int64_t value, int64_t oldMin, int64_t oldMax, int64_t newMin, int64_t newMax)
 Map an Integer from one range to another range. More...
 
int uartoutput (char c, FILE *f)
 Method used to write to stdout and stderr. More...
 
int uartinput (FILE *f)
 Method used to read from stdin. More...
 
void xyLedInternal (uint8_t v, volatile uint8_t *port, uint8_t pin)
 Internal LED Manipulation function. More...
 

Variables

char PROGMEM helpText [] = "Print this Help"
 UART Menu Help Text. More...
 
char PROGMEM resetText [] = "Reset MCU"
 UART Menu Reset Text. More...
 
FILE inFile
 FILE for stdin. More...
 
FILE outFile
 FILE for stdout and stderr. More...
 

Detailed Description

Controls xyControl On-Board Hardware like LEDs.

Enumeration Type Documentation

enum LED

Methods of addressing the LEDs.

Enumerator
LED_RED0 

First red LED.

LED_RED1 

Second red LED.

LED_GREEN0 

First green LED.

LED_GREEN1 

Second green LED.

LED_ALL 

All LEDs.

LED_BITMAP 

LEDs as Bitmap (R0, R1, G0, G1)

LED_RED 

Both red LEDs.

LED_GREEN 

Both green LEDs.

Definition at line 44 of file xycontrol.h.

44  {
45  LED_RED0 = 0,
46  LED_RED1 = 1,
47  LED_GREEN0 = 2,
48  LED_GREEN1 = 3,
49  LED_ALL = 4,
50  LED_BITMAP = 5,
51  LED_RED = 6,
52  LED_GREEN = 7
53 } LED;
enum LEDState

Possible states of the LEDs.

Enumerator
LED_OFF 

LED Off.

LED_ON 

LED On.

LED_TOGGLE 

Toggle the LED.

Definition at line 56 of file xycontrol.h.

56  {
57  LED_OFF = 0,
58  LED_ON = 1,
59  LED_TOGGLE = 2
60 } LEDState;

Function Documentation

double getVoltage ( void  )

Calculate and return the Battery Voltage.

Returns
Current Battery Voltage
Examples:
hardwareTest.c, and uartFlight.c.

Definition at line 172 of file xycontrol.c.

References adcGet(), adcReady(), adcStart(), BATT_CHANNEL, and BATT_MAX.

172  {
174  while(!adcReady());
175  uint16_t v = adcGet(0) * BATT_MAX;
176  return ((double)v / 1024.0);
177 }
int64_t map ( int64_t  value,
int64_t  oldMin,
int64_t  oldMax,
int64_t  newMin,
int64_t  newMax 
)

Map an Integer from one range to another range.

Parameters
valueInteger to operate on
oldMinLower Limit of Input range
oldMaxUpper Limit of Input range
newMinLower Limit of Output range
newMaxUpper Limit of Output range
Returns
Value in new range

Definition at line 184 of file xycontrol.c.

184  {
185  return (value - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin;
186 }
int uartinput ( FILE *  f)

Method used to read from stdin.

Definition at line 81 of file xycontrol.c.

References serialAvailable(), serialGet(), and serialHasChar().

Referenced by xyInit().

81  {
82  for (;;) {
83  for (uint8_t i = 0; i < serialAvailable(); i++) {
84  if (serialHasChar(i)) {
85  return serialGet(i);
86  }
87  }
88  }
89 }
int uartoutput ( char  c,
FILE *  f 
)

Method used to write to stdout and stderr.

Definition at line 66 of file xycontrol.c.

References serialAvailable(), and serialWrite().

Referenced by xyInit().

66  {
67  // Inject CR here, instead of in the serial library,
68  // so we can still do binary transfers with serialWrite()...
69  if (c == '\n') {
70  for (uint8_t i = 0; i < serialAvailable(); i++)
71  serialWrite(i, '\r');
72  }
73  if (c != '\r') {
74  for (uint8_t i = 0; i < serialAvailable(); i++)
75  serialWrite(i, c);
76  }
77  return 0;
78 }
void xyInit ( void  )

Initialize the xyControl Hardware.

Initializes LEDs, Timer, UART, I2C, SPI, ADC, the UART Menu and prepares stdin and stdout.

Examples:
hardwareTest.c, test.c, and uartFlight.c.

Definition at line 91 of file xycontrol.c.

References adcInit(), addMenuCommand(), addTask(), AVCC, BAUD, helpText, inFile, initSystemTimer(), LED0DDR, LED0PIN, LED1DDR, LED1PIN, LED2DDR, LED2PIN, LED3DDR, LED3PIN, MODE_0, outFile, resetText, serialAvailable(), serialInit(), SPEED_2, spiInit(), twiInit(), uartinput(), uartMenuPrintHelp(), uartMenuTask(), uartoutput(), xmemInit(), xyLed(), and xySelfReset().

91  {
92  xmemInit(); // Most important!
93 
94  // LEDs
95  LED0DDR |= (1 << LED0PIN);
96  LED1DDR |= (1 << LED1PIN);
97  LED2DDR |= (1 << LED2PIN);
98  LED3DDR |= (1 << LED3PIN);
99  xyLed(4, 1);
100 
101  initSystemTimer();
102  for (uint8_t i = 0; i < serialAvailable(); i++) {
103  serialInit(i, BAUD(38400, F_CPU));
104  }
105  twiInit();
107  adcInit(AVCC);
108 
112 
113  // fdevopen() is using malloc, so printf in a different
114  // memory bank will not work!
115  // fdevopen(&uartoutput, NULL); // stdout & stderr
116  // fdevopen(NULL, &uartinput); // stdin
117  // Instead we have the FILE structs as static variables
118  // and assign them to stdin, stdout and stderr
119 
120  fdev_setup_stream(&outFile, &uartoutput, NULL, _FDEV_SETUP_WRITE);
121  fdev_setup_stream(&inFile, NULL, &uartinput, _FDEV_SETUP_READ);
122  stdin = &inFile;
123  stdout = &outFile;
124  stderr = &outFile;
125 
126  sei();
127 }
void xyLed ( LED  l,
LEDState  v 
)

Set the LEDs.

Parameters
lLEDs to set
vNew LED State
Examples:
hardwareTest.c, test.c, and uartFlight.c.

Referenced by xyInit().

void xyLedInternal ( uint8_t  v,
volatile uint8_t *  port,
uint8_t  pin 
)

Internal LED Manipulation function.

Parameters
vNew LED State (Off, On, Toggle)
portThe Corresponding Output Port
pinThe LED Pin

Definition at line 134 of file xycontrol.c.

134  {
135  if (v == 0) {
136  *port &= ~(1 << pin);
137  } else if (v == 1) {
138  *port |= (1 << pin);
139  } else {
140  *port ^= (1 << pin);
141  }
142 }
void xySelfReset ( void  )

Use the Watchdog to reset yourself after 15ms.

Definition at line 179 of file xycontrol.c.

Referenced by orientationTask(), and xyInit().

179  {
180  wdt_enable(WDTO_15MS);
181  for(;;);
182 }

Variable Documentation

char PROGMEM helpText[] = "Print this Help"

UART Menu Help Text.

Definition at line 59 of file xycontrol.c.

Referenced by xyInit().

FILE inFile

FILE for stdin.

Definition at line 62 of file xycontrol.c.

Referenced by xyInit().

FILE outFile

FILE for stdout and stderr.

Definition at line 63 of file xycontrol.c.

Referenced by xyInit().

char PROGMEM resetText[] = "Reset MCU"

UART Menu Reset Text.

Definition at line 60 of file xycontrol.c.

Referenced by xyInit().