Implement USART with bot RX and TX interrupts

This commit is contained in:
2024-09-02 01:03:59 +02:00
parent 2423e0f060
commit 19983fb613
17 changed files with 168 additions and 440 deletions

View File

@@ -1,78 +1,28 @@
#include "common.h"
#include "serial.h"
#include "parser.h"
#include "bus/usart.h"
#include "bus/twi.h"
bool running;
#include <avr/interrupt.h>
#include <util/delay.h>
#define Sleep(ms) _delay_ms(ms)
int main(void)
int main(int argc, char **argv)
{
char ch;
unsigned long i = 1;
USART_Init();
Enable();
TWI_Init();
for (;;) {
// Process rx ring buffer
while ((ch = USART_GetChar())) {
CMD_Parse(ch);
}
sei();
Sleep(3000);
if (running) {
// TODO: Main program
if (i >= 99999) i = 1;
Info("Fetching sensors #%05lu...", i++);
}
}
Info("Initializing...");
Sleep(500);
// ADS1115 (ADC)
// PCA9546 (Multiplexer TWI)
// ATH20 (3x)
// BMP280 (3x)
UNUSED(argc);
UNUSED(argv);
return 0;
}
void Enable(void)
{
Info("Parsed 'CMD_RUN' token.");
if (running == true) {
Error("Already running.");
return;
}
running = true;
SetStateFlag(running);
Info("Program started.");
}
void Disable(void)
{
Info("Parsed 'CMD_STOP' token.");
if (running == false) {
Error("Already stopped.");
return;
}
running = false;
SetStateFlag(running);
Info("Program stopped.");
}
void SetTemp(long val)
{
Info("Parsed 'CMD_SET_TEMP', VAL='%ld'.", val);
if (val < 10) {
Error("Given temperature is too low.");
return;
} else if (val > 40) {
Error("Given temperature is too high.");
return;
}
}
void SetDewp(long val)
{
Info("Parsed 'CMD_SET_DEWP', VAL='%ld'.", val);
if (val < 10) {
Error("Given dew point is too low.");
return;
} else if (val > 80) {
Error("Given dew point is too high.");
return;
}
}