Skip to content

Commit 150092e

Browse files
committed
Code cleanup
1 parent bc2bea8 commit 150092e

File tree

1 file changed

+147
-147
lines changed

1 file changed

+147
-147
lines changed

main.c

Lines changed: 147 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
ChibiCopter - https://github.com/grantmd/ChibiCopter
3-
A quadcopter platform running under ChibiOS/RT.
2+
ChibiCopter - https://github.com/grantmd/ChibiCopter
3+
A quadcopter platform running under ChibiOS/RT.
44
5-
Based on demo code from ChibiOS/RT
5+
Based on demo code from ChibiOS/RT
66
*/
77

88
#include <stdlib.h>
@@ -25,11 +25,11 @@ BaseChannel *chp; // debugging serial port
2525
* The slave select line is the pin GPIOE_CS_SPI on the port GPIOE.
2626
*/
2727
static const SPIConfig spi1cfg = {
28-
NULL,
29-
/* HW dependent part.*/
30-
GPIOE,
31-
GPIOE_CS_SPI,
32-
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA
28+
NULL,
29+
/* HW dependent part.*/
30+
GPIOE,
31+
GPIOE_CS_SPI,
32+
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA
3333
};
3434

3535
/*
@@ -38,161 +38,161 @@ static const SPIConfig spi1cfg = {
3838
static WORKING_AREA(BlinkWA, 128);
3939
static msg_t Blink(void *arg){
4040

41-
(void)arg;
42-
chRegSetThreadName("blinker");
43-
while (TRUE){
44-
//palSetPad(GPIOD, GPIOD_LED5); // red
45-
chThdSleepMilliseconds(100);
46-
//palClearPad(GPIOD, GPIOD_LED5); // red
47-
palSetPad(GPIOD, GPIOD_LED6); // blue
48-
chThdSleepMilliseconds(100);
49-
palClearPad(GPIOD, GPIOD_LED6); // blue
50-
//palSetPad(GPIOD, GPIOD_LED4); // green
51-
chThdSleepMilliseconds(100);
52-
//palClearPad(GPIOD, GPIOD_LED4); // green
53-
palSetPad(GPIOD, GPIOD_LED3); // orange
54-
chThdSleepMilliseconds(100);
55-
palClearPad(GPIOD, GPIOD_LED3); // orange
56-
}
57-
return 0;
41+
(void)arg;
42+
chRegSetThreadName("blinker");
43+
while (TRUE){
44+
//palSetPad(GPIOD, GPIOD_LED5); // red
45+
chThdSleepMilliseconds(100);
46+
//palClearPad(GPIOD, GPIOD_LED5); // red
47+
palSetPad(GPIOD, GPIOD_LED6); // blue
48+
chThdSleepMilliseconds(100);
49+
palClearPad(GPIOD, GPIOD_LED6); // blue
50+
//palSetPad(GPIOD, GPIOD_LED4); // green
51+
chThdSleepMilliseconds(100);
52+
//palClearPad(GPIOD, GPIOD_LED4); // green
53+
palSetPad(GPIOD, GPIOD_LED3); // orange
54+
chThdSleepMilliseconds(100);
55+
palClearPad(GPIOD, GPIOD_LED3); // orange
56+
}
57+
return 0;
5858
}
5959

6060
/*
6161
* GPS setup
6262
*/
6363
static const SerialConfig sd1cfg = {
64-
57600,
65-
0,
66-
USART_CR2_STOP1_BITS | USART_CR2_LINEN,
67-
0
64+
57600,
65+
0,
66+
USART_CR2_STOP1_BITS | USART_CR2_LINEN,
67+
0
6868
};
6969

7070
static WORKING_AREA(GPSWA, 128);
7171
static msg_t GPS(void *arg){
7272

73-
(void)arg;
74-
chRegSetThreadName("GPS");
75-
while (TRUE) {
76-
unsigned char newdata = 0;
77-
// Read a byte off the GPS
78-
uint8_t c = chIOGet((BaseChannel *)&SD1);
79-
if (TinyGPS_encode(c)){
80-
newdata = 1;
81-
//chprintf(chp, "Got GPS data.\r\n");
82-
}
83-
//chIOPut(chp, c);
84-
}
85-
return 0;
73+
(void)arg;
74+
chRegSetThreadName("GPS");
75+
while (TRUE){
76+
unsigned char newdata = 0;
77+
// Read a byte off the GPS
78+
uint8_t c = chIOGet((BaseChannel *)&SD1);
79+
if (TinyGPS_encode(c)){
80+
newdata = 1;
81+
//chprintf(chp, "Got GPS data.\r\n");
82+
}
83+
//chIOPut(chp, c);
84+
}
85+
return 0;
8686
}
8787

8888
/*
8989
* Application entry point.
9090
*/
9191
int main(void){
9292

93-
/*
94-
* System initializations.
95-
* - HAL initialization, this also initializes the configured device drivers
96-
* and performs the board-specific initializations.
97-
* - Kernel initialization, the main() function becomes a thread and the
98-
* RTOS is active.
99-
*/
100-
halInit();
101-
chSysInit();
102-
103-
/*
104-
* Activates the serial driver 2 using the driver default configuration.
105-
* PA2(TX) and PA3(RX) are routed to USART2.
106-
*/
107-
108-
sdStart(&SD2, NULL);
109-
chp = &SD2;
110-
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // yellow wire on the FTDI cable
111-
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); // orange wire on the FTDI cable
112-
chprintf(chp, "Hello, startup!\r\n");
113-
114-
chprintf(chp, "Configurating I/O.\r\n");
115-
116-
/*
117-
* Activates the serial driver 1 using the driver default configuration, but at 57600
118-
* PA9(TX) and PA10(RX) are routed to USART1.
119-
*/
120-
121-
chprintf(chp, "GPS...");
122-
sdStart(&SD1, &sd1cfg);
123-
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); // not currently connected
124-
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); // incoming data from the GPS
125-
//TinyGPS_init();
126-
chprintf(chp, "OK\r\n");
127-
128-
/*
129-
* SPI1 I/O pins setup.
130-
*/
131-
chprintf(chp, "SPI...");
132-
/*
133-
* Initializes the SPI driver 1 in order to access the MEMS. The signals
134-
* are initialized in the board file.
135-
* Several LIS302DL registers are then initialized.
136-
*/
137-
spiStart(&SPID1, &spi1cfg);
138-
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG1, 0x43);
139-
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG2, 0x00);
140-
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG3, 0x00);
141-
chprintf(chp, "OK\r\n");
142-
143-
/*
144-
* Receiver I/O
145-
*/
146-
chprintf(chp, "Receiver...");
147-
SpektrumInit();
148-
chprintf(chp, "OK\r\n");
149-
150-
/*
151-
* Motors I/O
152-
*/
153-
chprintf(chp, "Motors...");
154-
MotorsInit();
155-
chprintf(chp, "OK\r\n");
156-
157-
chprintf(chp, "I/O configured.\r\n");
158-
159-
/*
160-
* Creates the threads
161-
*/
162-
chprintf(chp, "Launching threads...");
163-
chThdCreateStatic(BlinkWA, sizeof(BlinkWA), NORMALPRIO, Blink, NULL);
164-
chThdCreateStatic(GPSWA, sizeof(GPSWA), NORMALPRIO, GPS, NULL);
165-
chprintf(chp, "OK\r\n");
166-
167-
/*
168-
* Normal main() thread activity
169-
*/
170-
171-
int speed = 0;
172-
while (TRUE){
173-
//chThdSleepMilliseconds(1000);
174-
175-
//long lat, lon;
176-
//unsigned long fix_age;
177-
//TinyGPS_get_position(&lat, &lon, &fix_age);
178-
//chprintf(chp, "GPS location: %d, %d, %d\r\n", lat, lon, fix_age);
179-
180-
//int year;
181-
//char month, day, hour, minute, second, hundredths;
182-
//TinyGPS_crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age);
183-
//chprintf(chp, "GPS date/time: %d/%d/%d, %d:%d:%d.%d, %d\r\n", year, month, day, hour, minute, second, fix_age);
184-
185-
//chprintf(chp, "Motor: %d.\r\n", MotorsGetSpeed(0));
186-
//chThdSleepMilliseconds(100);
187-
//chprintf(chp, "Throttle: %d.\r\n", ReceiverGetThrottle());
188-
//MotorsSetSpeed(0, ReceiverGetThrottle());
189-
190-
SpektrumRead();
191-
192-
chprintf(chp, "Setting motor speed to: %d\r\n", speed);
193-
MotorsSetSpeed(0, speed);
194-
speed += 100;
195-
if (speed > MAX_MOTOR_SPEED) speed = 0;
196-
chThdSleepMilliseconds(5000);
197-
}
93+
/*
94+
* System initializations.
95+
* - HAL initialization, this also initializes the configured device drivers
96+
* and performs the board-specific initializations.
97+
* - Kernel initialization, the main() function becomes a thread and the
98+
* RTOS is active.
99+
*/
100+
halInit();
101+
chSysInit();
102+
103+
/*
104+
* Activates the serial driver 2 using the driver default configuration.
105+
* PA2(TX) and PA3(RX) are routed to USART2.
106+
*/
107+
108+
sdStart(&SD2, NULL);
109+
chp = &SD2;
110+
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // yellow wire on the FTDI cable
111+
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); // orange wire on the FTDI cable
112+
chprintf(chp, "Hello, startup!\r\n");
113+
114+
chprintf(chp, "Configurating I/O.\r\n");
115+
116+
/*
117+
* Activates the serial driver 1 using the driver default configuration, but at 57600
118+
* PA9(TX) and PA10(RX) are routed to USART1.
119+
*/
120+
121+
chprintf(chp, "GPS...");
122+
sdStart(&SD1, &sd1cfg);
123+
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); // not currently connected
124+
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); // incoming data from the GPS
125+
//TinyGPS_init();
126+
chprintf(chp, "OK\r\n");
127+
128+
/*
129+
* SPI1 I/O pins setup.
130+
*/
131+
chprintf(chp, "SPI...");
132+
/*
133+
* Initializes the SPI driver 1 in order to access the MEMS. The signals
134+
* are initialized in the board file.
135+
* Several LIS302DL registers are then initialized.
136+
*/
137+
spiStart(&SPID1, &spi1cfg);
138+
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG1, 0x43);
139+
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG2, 0x00);
140+
lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG3, 0x00);
141+
chprintf(chp, "OK\r\n");
142+
143+
/*
144+
* Receiver I/O
145+
*/
146+
chprintf(chp, "Receiver...");
147+
SpektrumInit();
148+
chprintf(chp, "OK\r\n");
149+
150+
/*
151+
* Motors I/O
152+
*/
153+
chprintf(chp, "Motors...");
154+
MotorsInit();
155+
chprintf(chp, "OK\r\n");
156+
157+
chprintf(chp, "I/O configured.\r\n");
158+
159+
/*
160+
* Creates the threads
161+
*/
162+
chprintf(chp, "Launching threads...");
163+
chThdCreateStatic(BlinkWA, sizeof(BlinkWA), NORMALPRIO, Blink, NULL);
164+
chThdCreateStatic(GPSWA, sizeof(GPSWA), NORMALPRIO, GPS, NULL);
165+
chprintf(chp, "OK\r\n");
166+
167+
/*
168+
* Normal main() thread activity
169+
*/
170+
171+
int speed = 0;
172+
while (TRUE){
173+
//chThdSleepMilliseconds(1000);
174+
175+
//long lat, lon;
176+
//unsigned long fix_age;
177+
//TinyGPS_get_position(&lat, &lon, &fix_age);
178+
//chprintf(chp, "GPS location: %d, %d, %d\r\n", lat, lon, fix_age);
179+
180+
//int year;
181+
//char month, day, hour, minute, second, hundredths;
182+
//TinyGPS_crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age);
183+
//chprintf(chp, "GPS date/time: %d/%d/%d, %d:%d:%d.%d, %d\r\n", year, month, day, hour, minute, second, fix_age);
184+
185+
//chprintf(chp, "Motor: %d.\r\n", MotorsGetSpeed(0));
186+
//chThdSleepMilliseconds(100);
187+
//chprintf(chp, "Throttle: %d.\r\n", ReceiverGetThrottle());
188+
//MotorsSetSpeed(0, ReceiverGetThrottle());
189+
190+
SpektrumRead();
191+
192+
chprintf(chp, "Setting motor speed to: %d\r\n", speed);
193+
MotorsSetSpeed(0, speed);
194+
speed += 100;
195+
if (speed > MAX_MOTOR_SPEED) speed = 0;
196+
chThdSleepMilliseconds(5000);
197+
}
198198
}

0 commit comments

Comments
 (0)