This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightMixer.c
153 lines (128 loc) · 4.89 KB
/
LightMixer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "LightMixer.h"
#include "hatch_switch.h"
#include "led_strip.h"
#include "millis.h"
#include "status_led.h"
/* Circular buffers to hold data to and from the USB and USART devices. */
//static RingBuffer_t USB_In_Buffer;
//static uint8_t USB_In_Buffer_Data[64];
//static RingBuffer_t USB_Out_Buffer;
//static uint8_t USB_Out_Buffer_Data[64];
//static RingBuffer_t USART_In_Buffer;
//static uint8_t USART_In_Buffer_Data[64];
//static RingBuffer_t USART_Out_Buffer;
//static uint8_t USART_Out_Buffer_Data[64];
/** LUFA CDC Class driver interface configuration and state information. This structure is
* passed to all CDC Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_CDC_Device_t LightMixer_CDC_Interface =
{
.Config =
{
.ControlInterfaceNumber = 0,
.DataINEndpoint =
{
.Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
{
.Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.NotificationEndpoint =
{
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
},
},
};
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
int main(void)
{
SetupHardware();
//RingBuffer_InitBuffer(&USB_In_Buffer, USB_In_Buffer_Data, sizeof(USB_In_Buffer_Data));
//RingBuffer_InitBuffer(&USB_Out_Buffer, USB_Out_Buffer_Data, sizeof(USB_Out_Buffer_Data));
//RingBuffer_InitBuffer(&USART_In_Buffer, USART_In_Buffer_Data, sizeof(USART_In_Buffer_Data));
//RingBuffer_InitBuffer(&USART_Out_Buffer, USART_Out_Buffer_Data, sizeof(USART_Out_Buffer_Data));
sei();
status_led_change_status(STATUS_IDLE);
millis_t now;
for (;;)
{
now = millis_get_millis();
status_led_update(now);
if (hatch_switch_get_value() == HATCH_VALUE_CLOSED) {
led_strip_off();
} else {
led_strip_on();
}
if (USB_DeviceState == DEVICE_STATE_Configured) {
uint16_t count = CDC_Device_BytesReceived(&LightMixer_CDC_Interface);
while(count > 0) {
uint16_t byte = CDC_Device_ReceiveByte(&LightMixer_CDC_Interface);
if (byte >= 0) {
CDC_Device_SendByte(&LightMixer_CDC_Interface, (uint8_t)byte);
}
count--;
}
}
CDC_Device_USBTask(&LightMixer_CDC_Interface);
USB_USBTask();
}
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();
/* Scale system clock down to 1 MHz */
clock_prescale_set(clock_div_16);
/* Setup elapsed time timer */
millis_init();
/* Init status LED */
status_led_init();
/* Init led strip outputs */
led_strip_init();
/* Init hatch switch */
hatch_switch_init();
/* Hardware Initialization */
USB_Init();
/* Configure unused pins as inputs with a pull-up */
DDRB &= ~((1 << DDB3) | (1 << DDB2) | (1 << DDB1) | (1 << DDB0));
PORTB |= (1 << PORTB3) | (1 << PORTB2) | (1 << PORTB1) | (1 << PORTB0);
DDRC = 0;
PORTC = (1 << PORTC7) | (1 << PORTC6);
DDRD &= ~((1 << DDD7) | (1 << DDD6) | (1 << DDD5) |
(1 << DDD4) | (1 << DDD1) | (1 << DDD0));
PORTD |= (1 << PORTD7) | (1 << PORTD6) | (1 << PORTD5) |
(1 << PORTD4) | (1 << PORTD1) | (1 << PORTD0);
DDRF = 0;
PORTF = (1 << PORTF7) | (1 << PORTF6) | (1 << PORTF5) |
(1 << PORTF4) | (1 << PORTF1) | (1 << PORTF0);
}
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
}
/** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void)
{
}
/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void)
{
CDC_Device_ConfigureEndpoints(&LightMixer_CDC_Interface);
}
/** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void)
{
CDC_Device_ProcessControlRequest(&LightMixer_CDC_Interface);
}