-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.c
57 lines (50 loc) · 1.01 KB
/
serial.c
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
/*
* Copyright (c) 2020, Dermot Tynan / Kalopa Research. All rights
* reserved.
*
* See the LICENSE file for more info.
*
* ABSTRACT
* All serial I/O happens here.
*/
#include <stdio.h>
#include <avr/io.h>
#include <libavr.h>
#include "flight.h"
#define BAUDRATE 8 /* 115,200 baud @ 16Mhz */
/*
* Set up the serial I/O
*/
void
serial_init()
{
/*
* Set baud rate and configure the USART.
*/
UBRR0H = (BAUDRATE >> 8) & 0xf;
UBRR0L = (BAUDRATE & 0xff);
/*UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0);*/
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
(void )fdevopen(sio_putc, sio_getc);
}
/*
* Initialize the data we receive from the remote control.
*/
void
receiver_init(struct control *cp)
{
int i;
cp->rx_throttle = cp->rx_roll = cp->rx_pitch = cp->rx_yaw = cp->rx_gear = 1000;
for (i = 0; i < 7; i++)
cp->rx_aux[i] = 1000;
}
/*
*
*/
void
show_rx_data(struct control *cp)
{
printf("T:%dR:%dP:%dY:%d\n", cp->rx_throttle, cp->rx_roll, cp->rx_pitch, cp->rx_yaw);
PORTD |= 0x08;
}