Added testing app
This commit is contained in:
parent
a1de5eafb6
commit
51dd44c00c
@ -5,12 +5,19 @@
|
||||
},
|
||||
{
|
||||
"path": "lcd_disp"
|
||||
},
|
||||
{
|
||||
"path": "testing"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"io.h": "c",
|
||||
"interrupt.h": "c"
|
||||
"interrupt.h": "c",
|
||||
"periph.h": "c",
|
||||
"comms.h": "c",
|
||||
"string.h": "c",
|
||||
"main.h": "c"
|
||||
}
|
||||
}
|
||||
}
|
19
final_project/testing/.vscode/c_cpp_properties.json
vendored
Normal file
19
final_project/testing/.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"intelliSenseMode": "gcc-x64",
|
||||
"compilerPath": "/usr/lib/ccache/avr-gcc",
|
||||
"cStandard": "c99",
|
||||
"cppStandard": "c++17",
|
||||
"compilerArgs": [
|
||||
"-Wall", "-pedantic", "-mmcu=atmega328"
|
||||
],
|
||||
"defines": [
|
||||
"F_CPU=16000000",
|
||||
"__"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
3
final_project/testing/.vscode/settings.json
vendored
Normal file
3
final_project/testing/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "Tag Parser"
|
||||
}
|
19
final_project/testing/.vscode/tasks.json
vendored
Normal file
19
final_project/testing/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "make",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
52
final_project/testing/Makefile
Normal file
52
final_project/testing/Makefile
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
NAME := sd-reader
|
||||
HEX := $(NAME).hex
|
||||
OUT := $(NAME).out
|
||||
MAP := $(NAME).map
|
||||
SOURCES := $(wildcard *.c)
|
||||
HEADERS := $(wildcard *.h)
|
||||
OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
|
||||
|
||||
MCU := atmega328
|
||||
MCU_AVRDUDE := m328
|
||||
MCU_FREQ := 8000000UL
|
||||
|
||||
CC := avr-gcc
|
||||
OBJCOPY := avr-objcopy
|
||||
SIZE := avr-size -A
|
||||
DOXYGEN := doxygen
|
||||
|
||||
CFLAGS := -Werror -Wall -pedantic -mmcu=$(MCU) -std=c99 -g -Os -DF_CPU=$(MCU_FREQ)
|
||||
|
||||
all: $(HEX)
|
||||
|
||||
clean:
|
||||
rm -f $(HEX) $(OUT) $(MAP) $(OBJECTS)
|
||||
rm -rf doc/html
|
||||
|
||||
flash: $(HEX)
|
||||
avrdude -y -c avr910 -p $(MCU_AVRDUDE) -U flash:w:$(HEX)
|
||||
|
||||
$(HEX): $(OUT)
|
||||
$(OBJCOPY) -R .eeprom -O ihex $< $@
|
||||
|
||||
$(OUT): $(OBJECTS)
|
||||
$(CC) $(CFLAGS) -o $@ -Wl,-Map,$(MAP) $^
|
||||
@echo
|
||||
@$(SIZE) $@
|
||||
@echo
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
%.pp: %.c
|
||||
$(CC) $(CFLAGS) -E -o $@ $<
|
||||
|
||||
%.ppo: %.c
|
||||
$(CC) $(CFLAGS) -E $<
|
||||
|
||||
doc: $(HEADERS) $(SOURCES) Doxyfile
|
||||
$(DOXYGEN) Doxyfile
|
||||
|
||||
.PHONY: all clean flash doc
|
||||
|
97
final_project/testing/comms.h
Normal file
97
final_project/testing/comms.h
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef COMMS_H_
|
||||
#define COMMS_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __AVR_ATmega328P__
|
||||
#define MEGA328
|
||||
#endif
|
||||
#ifdef __AVR_ATtiny2313__
|
||||
#define TINY2313
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Our format goes like this:
|
||||
*
|
||||
* 1 byte command, with data after
|
||||
*/
|
||||
|
||||
|
||||
typedef enum {
|
||||
COMMS_CMD_CLR = 0U, //! Clears LCD and all file names
|
||||
COMMS_CMD_NUM, //! sends the total number of songs to choose from
|
||||
COMMS_CMD_QUERY_NAME, //! Queries for the name of a given song ID
|
||||
COMMS_CMD_REPLY_NAME, //! Responds with the name of the given song ID
|
||||
COMMS_CMD_SELECT_FILE, //! selects a file from the given list to play, data is 1 byte for id
|
||||
COMMS_CMD_PLAY, //! Starts playing file
|
||||
COMMS_CMD_PAUSE //! pauses playing file
|
||||
} comms_cmd_t;
|
||||
|
||||
/** @brief Inline function to send commands and values.
|
||||
*/
|
||||
inline void comms_send(comms_cmd_t cmd) {
|
||||
#ifdef MEGA328
|
||||
while (! (UCSR0A & (1 << TXC0)));
|
||||
UDR0 = cmd;
|
||||
#elif defined(TINY2313)
|
||||
while (! (UCSRA) & (1 << TXC))
|
||||
UDR = cmd;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @brief Sends the number of songs to play
|
||||
*/
|
||||
inline void comms_send_num(uint8_t num) {
|
||||
comms_send(COMMS_CMD_NUM);
|
||||
comms_send(num);
|
||||
}
|
||||
|
||||
/** @brief Selects a file from the list on the DAC side.
|
||||
*
|
||||
* If another song is playing, this will stop
|
||||
* that song from playing and select the new one.
|
||||
*/
|
||||
inline void comms_select_file(uint8_t id) {
|
||||
comms_send(COMMS_CMD_SELECT_FILE);
|
||||
comms_send((comms_cmd_t) id);
|
||||
}
|
||||
|
||||
/** @brief Queries for the name of the given song ID.
|
||||
*/
|
||||
inline void comms_query_name(uint8_t id) {
|
||||
comms_send(COMMS_CMD_QUERY_NAME);
|
||||
comms_send(id);
|
||||
}
|
||||
|
||||
/** @brief Replies with name of song
|
||||
*/
|
||||
inline void comms_reply_name(char* name) {
|
||||
comms_send(COMMS_CMD_REPLY_NAME);
|
||||
|
||||
uint8_t len = strlen(name);
|
||||
comms_send(len);
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
comms_send(name[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Clears the LCD list of files.
|
||||
*/
|
||||
inline void comms_clear() {
|
||||
comms_send(COMMS_CMD_CLR);
|
||||
}
|
||||
|
||||
/** @brief Starts playing song.
|
||||
*/
|
||||
inline void comms_play() {
|
||||
comms_send(COMMS_CMD_PLAY);
|
||||
}
|
||||
|
||||
/** @brief Pauses playing song.
|
||||
*/
|
||||
inline void comms_pause() {
|
||||
comms_send(COMMS_CMD_PLAY);
|
||||
}
|
||||
|
||||
#endif
|
42
final_project/testing/main.c
Normal file
42
final_project/testing/main.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "comms.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
|
||||
#define USART_BAUDRATE 9600 //! USART baudrate, change this to set it.
|
||||
#define UBRR_VALUE (((F_CPU/(USART_BAUDRATE*16UL)))-1)
|
||||
|
||||
char* song_names[3] = {
|
||||
"baila.wav",
|
||||
"giorno.wav",
|
||||
"nevergonnagiveyo"
|
||||
};
|
||||
|
||||
int main() {
|
||||
// initialize USART
|
||||
UBRR0L = UBRR_VALUE & 255;
|
||||
UBRR0H = UBRR_VALUE >> 8;
|
||||
UCSR0B = (1 << TXEN0) | (1 << RXEN0); // fire-up USART
|
||||
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // fire-up USART
|
||||
|
||||
while(1) {
|
||||
// Send a clear command
|
||||
comms_clear();
|
||||
_delay_ms(1000);
|
||||
|
||||
// send a number of songs
|
||||
comms_send_num(3);
|
||||
|
||||
// Wait for request, get song num, then send song info 3 times
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
while(! (UCSR0A & (1 << TXC0)));
|
||||
uint8_t in_song = UDR0;
|
||||
while(! (UCSR0A & (1 << TXC0)));
|
||||
in_song = UDR0;
|
||||
comms_reply_name(song_names[in_song]);
|
||||
}
|
||||
|
||||
// wait a while
|
||||
_delay_ms(20000);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user