66 lines
1.6 KiB
C
66 lines
1.6 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_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) {
|
|
while (! (UCSRA & (1 << UDRE)));
|
|
UDR = cmd;
|
|
}
|
|
|
|
/** @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 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 |