71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
#ifndef COMMS_H_
|
|
#define COMMS_H_
|
|
|
|
#include <avr/io.h>
|
|
#include <string.h>
|
|
|
|
/**
|
|
* 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_ADD_FILE, //! Adds a file to the list of files to display, data is 1 byte for ID, 1 byte for strlen, n bytes for string
|
|
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_command(comms_cmd_t cmd) {
|
|
while (! (UCSRA & (1 << UDRE)));
|
|
UDR = cmd;
|
|
}
|
|
|
|
/** @brief Adds a file to the list on the LCD side.
|
|
*/
|
|
inline void comms_add_file(uint8_t id, char* filename) {
|
|
uint8_t len = strlen(filename);
|
|
|
|
comms_send_command(COMMS_CMD_ADD_FILE);
|
|
comms_send_command((comms_cmd_t) id);
|
|
|
|
uint8_t i = 0;
|
|
while (i < len) {
|
|
comms_send_command((comms_cmd_t) filename[i]);
|
|
}
|
|
}
|
|
|
|
/** @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_command(COMMS_CMD_SELECT_FILE);
|
|
comms_send_command((comms_cmd_t) id);
|
|
}
|
|
|
|
/** @brief Clears the LCD list of files.
|
|
*/
|
|
inline void comms_clear() {
|
|
comms_send_command(COMMS_CMD_CLR);
|
|
}
|
|
|
|
/** @brief Starts playing song.
|
|
*/
|
|
inline void comms_play() {
|
|
comms_send_command(COMMS_CMD_PLAY);
|
|
}
|
|
|
|
/** @brief Pauses playing song.
|
|
*/
|
|
inline void comms_pause() {
|
|
comms_send_command(COMMS_CMD_PLAY);
|
|
}
|
|
|
|
#endif |